Search in sources :

Example 26 with NetworkPolicyEditor

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

the class DataUsageBase method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    final Context context = getActivity();
    services.mNetworkService = INetworkManagementService.Stub.asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
    services.mStatsService = INetworkStatsService.Stub.asInterface(ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
    services.mPolicyManager = NetworkPolicyManager.from(context);
    services.mPolicyEditor = new NetworkPolicyEditor(services.mPolicyManager);
    services.mTelephonyManager = TelephonyManager.from(context);
    services.mSubscriptionManager = SubscriptionManager.from(context);
    services.mUserManager = UserManager.get(context);
}
Also used : Context(android.content.Context) NetworkPolicyEditor(com.android.settingslib.NetworkPolicyEditor)

Example 27 with NetworkPolicyEditor

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

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 28 with NetworkPolicyEditor

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

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 29 with NetworkPolicyEditor

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

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 30 with NetworkPolicyEditor

use of com.android.settingslib.NetworkPolicyEditor in project platform_packages_apps_Settings by BlissRoms.

the class DataUsageBase method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    final Context context = getActivity();
    services.mNetworkService = INetworkManagementService.Stub.asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
    services.mStatsService = INetworkStatsService.Stub.asInterface(ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
    services.mPolicyManager = NetworkPolicyManager.from(context);
    services.mPolicyEditor = new NetworkPolicyEditor(services.mPolicyManager);
    services.mTelephonyManager = TelephonyManager.from(context);
    services.mSubscriptionManager = SubscriptionManager.from(context);
    services.mUserManager = UserManager.get(context);
}
Also used : Context(android.content.Context) NetworkPolicyEditor(com.android.settingslib.NetworkPolicyEditor)

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