Search in sources :

Example 21 with NetworkPolicyEditor

use of com.android.settingslib.NetworkPolicyEditor in project android_packages_apps_Settings by LineageOS.

the class DataUsageMeteredSettings method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    final Context context = getActivity();
    mPolicyManager = NetworkPolicyManager.from(context);
    mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    mPolicyEditor = new NetworkPolicyEditor(mPolicyManager);
    mPolicyEditor.read();
    addPreferencesFromResource(R.xml.data_usage_metered_prefs);
    mMobileCategory = (PreferenceCategory) findPreference("mobile");
    mWifiCategory = (PreferenceCategory) findPreference("wifi");
    mWifiDisabled = findPreference("wifi_disabled");
    updateNetworks(context);
}
Also used : Context(android.content.Context) NetworkPolicyEditor(com.android.settingslib.NetworkPolicyEditor)

Example 22 with NetworkPolicyEditor

use of com.android.settingslib.NetworkPolicyEditor in project android_packages_apps_Settings by LineageOS.

the class DataUsageSummary method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    final Context context = getContext();
    NetworkPolicyManager policyManager = NetworkPolicyManager.from(context);
    mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    mPolicyEditor = new NetworkPolicyEditor(policyManager);
    boolean hasMobileData = DataUsageUtils.hasMobileData(context);
    mDataUsageController = new DataUsageController(context);
    mDataInfoController = new DataUsageInfoController();
    addPreferencesFromResource(R.xml.data_usage);
    int defaultSubId = DataUsageUtils.getDefaultSubscriptionId(context);
    if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
        hasMobileData = false;
    }
    mDefaultTemplate = DataUsageUtils.getDefaultTemplate(context, defaultSubId);
    mSummaryPreference = (SummaryPreference) findPreference(KEY_STATUS_HEADER);
    if (!hasMobileData || !isAdmin()) {
        removePreference(KEY_RESTRICT_BACKGROUND);
    }
    if (hasMobileData) {
        mLimitPreference = findPreference(KEY_LIMIT_SUMMARY);
        List<SubscriptionInfo> subscriptions = services.mSubscriptionManager.getActiveSubscriptionInfoList();
        if (subscriptions == null || subscriptions.size() == 0) {
            addMobileSection(defaultSubId);
        }
        for (int i = 0; subscriptions != null && i < subscriptions.size(); i++) {
            SubscriptionInfo subInfo = subscriptions.get(i);
            if (subscriptions.size() > 1) {
                addMobileSection(subInfo.getSubscriptionId(), subInfo);
            } else {
                addMobileSection(subInfo.getSubscriptionId());
            }
        }
        mSummaryPreference.setSelectable(true);
    } else {
        removePreference(KEY_LIMIT_SUMMARY);
        mSummaryPreference.setSelectable(false);
    }
    boolean hasWifiRadio = DataUsageUtils.hasWifiRadio(context);
    if (hasWifiRadio) {
        addWifiSection();
    }
    if (hasEthernet(context)) {
        addEthernetSection();
    }
    mDataUsageTemplate = hasMobileData ? R.string.cell_data_template : hasWifiRadio ? R.string.wifi_data_template : R.string.ethernet_data_template;
    setHasOptionsMenu(true);
}
Also used : Context(android.content.Context) NetworkPolicyEditor(com.android.settingslib.NetworkPolicyEditor) NetworkPolicyManager(android.net.NetworkPolicyManager) DataUsageController(com.android.settingslib.net.DataUsageController) SubscriptionInfo(android.telephony.SubscriptionInfo)

Example 23 with NetworkPolicyEditor

use of com.android.settingslib.NetworkPolicyEditor in project android_packages_apps_Settings by LineageOS.

the class DataUsageSummaryTest method testUpdateNetworkRestrictionSummary_shouldSetSummary.

@Test
public void testUpdateNetworkRestrictionSummary_shouldSetSummary() {
    final DataUsageSummary dataUsageSummary = spy(new DataUsageSummary());
    final NetworkRestrictionsPreference preference = mock(NetworkRestrictionsPreference.class);
    final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
    final WifiManager wifiManager = mock(WifiManager.class);
    ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
    ReflectionHelpers.setField(dataUsageSummary, "mWifiManager", wifiManager);
    when(wifiManager.getConfiguredNetworks()).thenReturn(new ArrayList<WifiConfiguration>());
    doReturn(mContext.getResources()).when(dataUsageSummary).getResources();
    dataUsageSummary.updateNetworkRestrictionSummary(preference);
    verify(preference).setSummary(mContext.getResources().getQuantityString(R.plurals.network_restrictions_summary, 0, 0));
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration) NetworkPolicyEditor(com.android.settingslib.NetworkPolicyEditor) Test(org.junit.Test)

Example 24 with NetworkPolicyEditor

use of com.android.settingslib.NetworkPolicyEditor in project android_packages_apps_Settings by omnirom.

the class DataUsageMeteredSettings method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    final Context context = getActivity();
    mPolicyManager = NetworkPolicyManager.from(context);
    mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    mPolicyEditor = new NetworkPolicyEditor(mPolicyManager);
    mPolicyEditor.read();
    addPreferencesFromResource(R.xml.data_usage_metered_prefs);
    mMobileCategory = (PreferenceCategory) findPreference("mobile");
    mWifiCategory = (PreferenceCategory) findPreference("wifi");
    mWifiDisabled = findPreference("wifi_disabled");
    updateNetworks(context);
}
Also used : Context(android.content.Context) NetworkPolicyEditor(com.android.settingslib.NetworkPolicyEditor)

Example 25 with NetworkPolicyEditor

use of com.android.settingslib.NetworkPolicyEditor in project android_packages_apps_Settings by omnirom.

the class DataUsageSummaryTest method testUpdateNetworkRestrictionSummary_shouldSetSummary.

@Test
public void testUpdateNetworkRestrictionSummary_shouldSetSummary() {
    final DataUsageSummary dataUsageSummary = spy(new DataUsageSummary());
    final NetworkRestrictionsPreference preference = mock(NetworkRestrictionsPreference.class);
    final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
    final WifiManager wifiManager = mock(WifiManager.class);
    ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
    ReflectionHelpers.setField(dataUsageSummary, "mWifiManager", wifiManager);
    when(wifiManager.getConfiguredNetworks()).thenReturn(new ArrayList<WifiConfiguration>());
    doReturn(mContext.getResources()).when(dataUsageSummary).getResources();
    dataUsageSummary.updateNetworkRestrictionSummary(preference);
    verify(preference).setSummary(mContext.getResources().getQuantityString(R.plurals.network_restrictions_summary, 0, 0));
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration) NetworkPolicyEditor(com.android.settingslib.NetworkPolicyEditor) Test(org.junit.Test)

Aggregations

NetworkPolicyEditor (com.android.settingslib.NetworkPolicyEditor)34 Context (android.content.Context)27 NetworkPolicyManager (android.net.NetworkPolicyManager)13 DataUsageController (com.android.settingslib.net.DataUsageController)12 WifiConfiguration (android.net.wifi.WifiConfiguration)6 WifiManager (android.net.wifi.WifiManager)6 SubscriptionInfo (android.telephony.SubscriptionInfo)6 Test (org.junit.Test)6 NetworkTemplate (android.net.NetworkTemplate)1 UserManager (android.os.UserManager)1 SubscriptionManager (android.telephony.SubscriptionManager)1 TelephonyManager (android.telephony.TelephonyManager)1