Search in sources :

Example 16 with DataUsageController

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

the class DataUsageSlice method getSlice.

@Override
public Slice getSlice() {
    final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.ic_settings_data_usage);
    final String title = mContext.getString(R.string.data_usage_summary_title);
    final SliceAction primaryAction = SliceAction.createDeeplink(getPrimaryAction(), icon, ListBuilder.ICON_IMAGE, title);
    DataUsageController dataUsageController = new DataUsageController(mContext);
    DataUsageController.DataUsageInfo info = null;
    SubscriptionManager subscriptionManager = (SubscriptionManager) mContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
    int defaultSubId = subscriptionManager.getDefaultDataSubscriptionId();
    boolean showDailyDataUsage = Settings.System.getInt(mContext.getContentResolver(), Settings.System.DATA_USAGE_PERIOD, 1) == 0;
    if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
        info = dataUsageController.getDataUsageInfo();
    } else {
        info = showDailyDataUsage ? dataUsageController.getDailyDataUsageInfo(DataUsageUtils.getMobileTemplate(mContext, defaultSubId)) : dataUsageController.getDataUsageInfo(DataUsageUtils.getMobileTemplate(mContext, defaultSubId));
    }
    final ListBuilder listBuilder = new ListBuilder(mContext, CustomSliceRegistry.DATA_USAGE_SLICE_URI, ListBuilder.INFINITY).setAccentColor(Utils.getColorAccentDefaultColor(mContext)).setHeader(new ListBuilder.HeaderBuilder().setTitle(title));
    if (DataUsageUtils.hasSim(mContext)) {
        listBuilder.addRow(new ListBuilder.RowBuilder().setTitle(getDataUsageText(info)).setSubtitle(getCycleTime(info)).setPrimaryAction(primaryAction));
    } else {
        listBuilder.addRow(new ListBuilder.RowBuilder().setTitle(mContext.getText(R.string.no_sim_card)).setPrimaryAction(primaryAction));
    }
    return listBuilder.build();
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) DataUsageController(com.android.settingslib.net.DataUsageController) SliceAction(androidx.slice.builders.SliceAction) ListBuilder(androidx.slice.builders.ListBuilder) SpannableString(android.text.SpannableString) SubscriptionManager(android.telephony.SubscriptionManager)

Example 17 with DataUsageController

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

the class DataUsagePreferenceController method updateState.

@Override
public void updateState(Preference preference) {
    super.updateState(preference);
    if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
        preference.setEnabled(false);
        return;
    }
    long usageLevel = mDataUsageInfo.usageLevel;
    if (usageLevel <= 0L) {
        final DataUsageController controller = new DataUsageController(mContext);
        usageLevel = controller.getHistoricalUsageLevel(mTemplate);
    }
    final boolean enabled = usageLevel > 0L;
    preference.setEnabled(enabled);
    if (enabled) {
        preference.setSummary(mContext.getString(R.string.data_usage_template, DataUsageUtils.formatDataUsage(mContext, mDataUsageInfo.usageLevel), mDataUsageInfo.period));
    }
}
Also used : DataUsageController(com.android.settingslib.net.DataUsageController)

Example 18 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() 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 19 with DataUsageController

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

the class BillingCycleSettings method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    final Context context = getContext();
    mDataUsageController = new DataUsageController(context);
    Bundle args = getArguments();
    mNetworkTemplate = args.getParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE);
    if (mNetworkTemplate == null) {
        mNetworkTemplate = DataUsageUtils.getDefaultTemplate(context, DataUsageUtils.getDefaultSubscriptionId(context));
    }
    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 : Context(android.content.Context) Bundle(android.os.Bundle) DataUsageController(com.android.settingslib.net.DataUsageController)

Example 20 with DataUsageController

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

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