Search in sources :

Example 41 with DataUsageController

use of com.android.settingslib.net.DataUsageController in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DataUsagePreferenceController method init.

public void init(int subId) {
    mSubId = subId;
    if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
        mTemplate = DataUsageUtils.getDefaultTemplate(mContext, mSubId);
        boolean showDailyDataUsage = Settings.System.getInt(mContext.getContentResolver(), Settings.System.DATA_USAGE_PERIOD, 1) == 0;
        final DataUsageController controller = new DataUsageController(mContext);
        controller.setSubscriptionId(mSubId);
        mDataUsageInfo = showDailyDataUsage ? controller.getDailyDataUsageInfo(mTemplate) : controller.getDataUsageInfo(mTemplate);
        mIntent = new Intent(Settings.ACTION_MOBILE_DATA_USAGE);
        mIntent.putExtra(Settings.EXTRA_NETWORK_TEMPLATE, mTemplate);
        mIntent.putExtra(Settings.EXTRA_SUB_ID, mSubId);
    }
}
Also used : DataUsageController(com.android.settingslib.net.DataUsageController) Intent(android.content.Intent)

Example 42 with DataUsageController

use of com.android.settingslib.net.DataUsageController in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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 43 with DataUsageController

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

the class DataUsagePreference method setTemplate.

@Override
public void setTemplate(NetworkTemplate template, int subId, NetworkServices services) {
    mTemplate = template;
    mSubId = subId;
    final DataUsageController controller = getDataUsageController();
    if (mTemplate.isMatchRuleMobile()) {
        setTitle(R.string.app_cellular_data_usage);
    } else {
        final DataUsageController.DataUsageInfo usageInfo = controller.getDataUsageInfo(mTemplate);
        setTitle(mTitleRes);
        setSummary(getContext().getString(R.string.data_usage_template, DataUsageUtils.formatDataUsage(getContext(), usageInfo.usageLevel), usageInfo.period));
    }
    final long usageLevel = controller.getHistoricalUsageLevel(template);
    if (usageLevel > 0L) {
        setIntent(getIntent());
    } else {
        setIntent(null);
        setEnabled(false);
    }
}
Also used : DataUsageController(com.android.settingslib.net.DataUsageController)

Example 44 with DataUsageController

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

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