Search in sources :

Example 26 with DataUsageController

use of com.android.settingslib.net.DataUsageController 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 27 with DataUsageController

use of com.android.settingslib.net.DataUsageController in project android_packages_apps_Settings by DirtyUnicorns.

the class SettingsDumpService method dumpDataUsage.

private JSONObject dumpDataUsage(NetworkTemplate template, DataUsageController controller) throws JSONException {
    JSONObject obj = new JSONObject();
    DataUsageController.DataUsageInfo usage = controller.getDataUsageInfo(template);
    obj.put("carrier", usage.carrier);
    obj.put("start", usage.startDate);
    obj.put("usage", usage.usageLevel);
    obj.put("warning", usage.warningLevel);
    obj.put("limit", usage.limitLevel);
    return obj;
}
Also used : JSONObject(org.json.JSONObject) DataUsageController(com.android.settingslib.net.DataUsageController)

Example 28 with DataUsageController

use of com.android.settingslib.net.DataUsageController in project android_packages_apps_Settings by DirtyUnicorns.

the class SettingsDumpService method dumpDataUsage.

private JSONObject dumpDataUsage() throws JSONException {
    JSONObject obj = new JSONObject();
    DataUsageController controller = new DataUsageController(this);
    ConnectivityManager connectivityManager = getSystemService(ConnectivityManager.class);
    SubscriptionManager manager = SubscriptionManager.from(this);
    TelephonyManager telephonyManager = TelephonyManager.from(this);
    if (connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) {
        JSONArray array = new JSONArray();
        for (SubscriptionInfo info : manager.getAllSubscriptionInfoList()) {
            NetworkTemplate mobileAll = NetworkTemplate.buildTemplateMobileAll(telephonyManager.getSubscriberId(info.getSubscriptionId()));
            final JSONObject usage = dumpDataUsage(mobileAll, controller);
            usage.put("subId", info.getSubscriptionId());
            array.put(usage);
        }
        obj.put("cell", array);
    }
    if (connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_WIFI)) {
        obj.put("wifi", dumpDataUsage(NetworkTemplate.buildTemplateWifiWildcard(), controller));
    }
    if (connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_ETHERNET)) {
        obj.put("ethernet", dumpDataUsage(NetworkTemplate.buildTemplateEthernet(), controller));
    }
    return obj;
}
Also used : NetworkTemplate(android.net.NetworkTemplate) JSONObject(org.json.JSONObject) TelephonyManager(android.telephony.TelephonyManager) ConnectivityManager(android.net.ConnectivityManager) DataUsageController(com.android.settingslib.net.DataUsageController) JSONArray(org.json.JSONArray) SubscriptionInfo(android.telephony.SubscriptionInfo) SubscriptionManager(android.telephony.SubscriptionManager)

Example 29 with DataUsageController

use of com.android.settingslib.net.DataUsageController in project android_packages_apps_Settings by DirtyUnicorns.

the class BillingCycleSettings method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    mDataUsageController = new DataUsageController(getContext());
    Bundle args = getArguments();
    mNetworkTemplate = args.getParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE);
    addPreferencesFromResource(R.xml.billing_cycle);
    mBillingCycle = findPreference(KEY_BILLING_CYCLE);
    mEnableDataWarning = (SwitchPreference) findPreference(KEY_SET_DATA_WARNING);
    mEnableDataWarning.setOnPreferenceChangeListener(this);
    mDataWarning = findPreference(KEY_DATA_WARNING);
    mEnableDataLimit = (SwitchPreference) findPreference(KEY_SET_DATA_LIMIT);
    mEnableDataLimit.setOnPreferenceChangeListener(this);
    mDataLimit = findPreference(KEY_DATA_LIMIT);
}
Also used : Bundle(android.os.Bundle) DataUsageController(com.android.settingslib.net.DataUsageController)

Example 30 with DataUsageController

use of com.android.settingslib.net.DataUsageController in project android_packages_apps_Settings by crdroidandroid.

the class SettingsDumpService method dumpDataUsage.

private JSONObject dumpDataUsage(NetworkTemplate template, DataUsageController controller) throws JSONException {
    JSONObject obj = new JSONObject();
    DataUsageController.DataUsageInfo usage = controller.getDataUsageInfo(template);
    obj.put("carrier", usage.carrier);
    obj.put("start", usage.startDate);
    obj.put("usage", usage.usageLevel);
    obj.put("warning", usage.warningLevel);
    obj.put("limit", usage.limitLevel);
    return obj;
}
Also used : JSONObject(org.json.JSONObject) DataUsageController(com.android.settingslib.net.DataUsageController)

Aggregations

DataUsageController (com.android.settingslib.net.DataUsageController)44 JSONObject (org.json.JSONObject)14 Context (android.content.Context)13 NetworkPolicyManager (android.net.NetworkPolicyManager)12 SubscriptionInfo (android.telephony.SubscriptionInfo)12 NetworkPolicyEditor (com.android.settingslib.NetworkPolicyEditor)12 SubscriptionManager (android.telephony.SubscriptionManager)8 NetworkTemplate (android.net.NetworkTemplate)7 Bundle (android.os.Bundle)7 TelephonyManager (android.telephony.TelephonyManager)7 JSONArray (org.json.JSONArray)7 ConnectivityManager (android.net.ConnectivityManager)6 Intent (android.content.Intent)1 PackageManager (android.content.pm.PackageManager)1 INetworkPolicyManager (android.net.INetworkPolicyManager)1 SpannableString (android.text.SpannableString)1 IconCompat (androidx.core.graphics.drawable.IconCompat)1 ListBuilder (androidx.slice.builders.ListBuilder)1 SliceAction (androidx.slice.builders.SliceAction)1 ExecutionException (java.util.concurrent.ExecutionException)1