use of android.net.NetworkPolicyManager in project platform_packages_apps_Settings by BlissRoms.
the class DataPlanUsageSummary method onCreate.
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
final Context context = getContext();
NetworkPolicyManager policyManager = NetworkPolicyManager.from(context);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mPolicyEditor = new NetworkPolicyEditor(policyManager);
mDataUsageController = new DataUsageController(context);
mDataInfoController = new DataUsageInfoController();
int defaultSubId = DataUsageUtils.getDefaultSubscriptionId(context);
boolean hasMobileData = DataUsageUtils.hasMobileData(context);
if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
hasMobileData = false;
}
mDefaultTemplate = DataUsageUtils.getDefaultTemplate(context, defaultSubId);
if (hasMobileData) {
addDataPlanSection(defaultSubId);
}
if (DataUsageUtils.hasWifiRadio(context)) {
addWifiSection();
}
if (hasEthernet(context)) {
addEthernetSection();
}
setHasOptionsMenu(true);
}
use of android.net.NetworkPolicyManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AppDataUsageTest method updatePrefs_restrictedByAdmin_shouldDisablePreference.
@Test
public void updatePrefs_restrictedByAdmin_shouldDisablePreference() {
mFragment = spy(new AppDataUsage());
final int testUid = 123123;
final AppItem appItem = new AppItem(testUid);
final RestrictedSwitchPreference restrictBackgroundPref = mock(RestrictedSwitchPreference.class);
final RestrictedSwitchPreference unrestrictedDataPref = mock(RestrictedSwitchPreference.class);
final DataSaverBackend dataSaverBackend = mock(DataSaverBackend.class);
final NetworkPolicyManager networkPolicyManager = mock(NetworkPolicyManager.class);
ReflectionHelpers.setField(mFragment, "mAppItem", appItem);
ReflectionHelpers.setField(mFragment, "mRestrictBackground", restrictBackgroundPref);
ReflectionHelpers.setField(mFragment, "mUnrestrictedData", unrestrictedDataPref);
ReflectionHelpers.setField(mFragment, "mDataSaverBackend", dataSaverBackend);
ReflectionHelpers.setField(mFragment.services, "mPolicyManager", networkPolicyManager);
ShadowRestrictedLockUtilsInternal.setRestricted(true);
doReturn(NetworkPolicyManager.POLICY_NONE).when(networkPolicyManager).getUidPolicy(testUid);
mFragment.updatePrefs();
verify(restrictBackgroundPref).setDisabledByAdmin(any(EnforcedAdmin.class));
verify(unrestrictedDataPref).setDisabledByAdmin(any(EnforcedAdmin.class));
}
use of android.net.NetworkPolicyManager in project android_packages_apps_Settings by omnirom.
the class AppDataUsageTest method updatePrefs_restrictedByAdmin_shouldDisablePreference.
@Test
public void updatePrefs_restrictedByAdmin_shouldDisablePreference() {
mFragment = spy(new AppDataUsage());
final int testUid = 123123;
final AppItem appItem = new AppItem(testUid);
final RestrictedSwitchPreference restrictBackgroundPref = mock(RestrictedSwitchPreference.class);
final RestrictedSwitchPreference unrestrictedDataPref = mock(RestrictedSwitchPreference.class);
final DataSaverBackend dataSaverBackend = mock(DataSaverBackend.class);
final NetworkPolicyManager networkPolicyManager = mock(NetworkPolicyManager.class);
ReflectionHelpers.setField(mFragment, "mAppItem", appItem);
ReflectionHelpers.setField(mFragment, "mRestrictBackground", restrictBackgroundPref);
ReflectionHelpers.setField(mFragment, "mUnrestrictedData", unrestrictedDataPref);
ReflectionHelpers.setField(mFragment, "mDataSaverBackend", dataSaverBackend);
ReflectionHelpers.setField(mFragment.services, "mPolicyManager", networkPolicyManager);
ShadowRestrictedLockUtilsInternal.setRestricted(true);
doReturn(NetworkPolicyManager.POLICY_NONE).when(networkPolicyManager).getUidPolicy(testUid);
mFragment.updatePrefs();
verify(restrictBackgroundPref).setDisabledByAdmin(any(EnforcedAdmin.class));
verify(unrestrictedDataPref).setDisabledByAdmin(any(EnforcedAdmin.class));
}
use of android.net.NetworkPolicyManager in project android_packages_apps_Settings by omnirom.
the class DataUsageSummaryPreferenceController method updateConfiguration.
private void updateConfiguration(Context context, int subscriptionId, SubscriptionInfo subInfo) {
final NetworkPolicyManager policyManager = context.getSystemService(NetworkPolicyManager.class);
mPolicyEditor = new NetworkPolicyEditor(policyManager);
mDataUsageController = new DataUsageController(context);
mDataUsageController.setSubscriptionId(subscriptionId);
mDataInfoController = new DataUsageInfoController();
if (subInfo != null) {
mDataUsageTemplate = R.string.cell_data_template;
mDefaultTemplate = DataUsageLib.getMobileTemplate(context, subscriptionId);
} else if (DataUsageUtils.hasWifiRadio(context)) {
mDataUsageTemplate = R.string.wifi_data_template;
mDefaultTemplate = NetworkTemplate.buildTemplateWifi(NetworkTemplate.WIFI_NETWORKID_ALL, null);
} else {
mDataUsageTemplate = R.string.ethernet_data_template;
mDefaultTemplate = DataUsageUtils.getDefaultTemplate(context, subscriptionId);
}
}
Aggregations