Search in sources :

Example 21 with NetworkPolicyManager

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);
}
Also used : Context(android.content.Context) NetworkPolicyEditor(com.android.settingslib.NetworkPolicyEditor) NetworkPolicyManager(android.net.NetworkPolicyManager) DataUsageController(com.android.settingslib.net.DataUsageController)

Example 22 with NetworkPolicyManager

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));
}
Also used : RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) AppItem(com.android.settingslib.AppItem) NetworkPolicyManager(android.net.NetworkPolicyManager) EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin) Test(org.junit.Test)

Example 23 with NetworkPolicyManager

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));
}
Also used : RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) AppItem(com.android.settingslib.AppItem) NetworkPolicyManager(android.net.NetworkPolicyManager) EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin) Test(org.junit.Test)

Example 24 with NetworkPolicyManager

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);
    }
}
Also used : NetworkPolicyEditor(com.android.settingslib.NetworkPolicyEditor) NetworkPolicyManager(android.net.NetworkPolicyManager) INetworkPolicyManager(android.net.INetworkPolicyManager) DataUsageController(com.android.settingslib.net.DataUsageController)

Aggregations

NetworkPolicyManager (android.net.NetworkPolicyManager)24 NetworkPolicyEditor (com.android.settingslib.NetworkPolicyEditor)12 DataUsageController (com.android.settingslib.net.DataUsageController)12 Context (android.content.Context)11 NetworkPolicy (android.net.NetworkPolicy)10 IOException (java.io.IOException)10 SubscriptionInfo (android.telephony.SubscriptionInfo)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 DataInputStream (java.io.DataInputStream)5 DataOutputStream (java.io.DataOutputStream)5 AppItem (com.android.settingslib.AppItem)2 EnforcedAdmin (com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)2 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)2 Test (org.junit.Test)2 INetworkPolicyManager (android.net.INetworkPolicyManager)1