use of com.android.settingslib.net.DataUsageController in project android_packages_apps_Settings by omnirom.
the class SettingsDumpService method dumpDataUsage.
private JSONObject dumpDataUsage() throws JSONException {
JSONObject obj = new JSONObject();
DataUsageController controller = new DataUsageController(this);
SubscriptionManager manager = this.getSystemService(SubscriptionManager.class);
TelephonyManager telephonyManager = this.getSystemService(TelephonyManager.class);
final PackageManager packageManager = this.getPackageManager();
if (telephonyManager.isDataCapable()) {
JSONArray array = new JSONArray();
for (SubscriptionInfo info : manager.getAvailableSubscriptionInfoList()) {
telephonyManager = telephonyManager.createForSubscriptionId(info.getSubscriptionId());
String subscriberId = telephonyManager.getSubscriberId();
// The null subscriberId means that no any mobile/carrier network will be matched.
// Using old API: buildTemplateMobileAll for the null subscriberId to avoid NPE.
NetworkTemplate template = subscriberId != null ? NetworkTemplate.buildTemplateCarrierMetered(subscriberId) : NetworkTemplate.buildTemplateMobileAll(subscriberId);
final JSONObject usage = dumpDataUsage(template, controller);
usage.put("subId", info.getSubscriptionId());
array.put(usage);
}
obj.put("cell", array);
}
if (packageManager.hasSystemFeature(FEATURE_WIFI)) {
obj.put("wifi", dumpDataUsage(NetworkTemplate.buildTemplateWifi(NetworkTemplate.WIFI_NETWORKID_ALL, null), controller));
}
if (packageManager.hasSystemFeature(FEATURE_ETHERNET)) {
obj.put("ethernet", dumpDataUsage(NetworkTemplate.buildTemplateEthernet(), controller));
}
return obj;
}
use of com.android.settingslib.net.DataUsageController in project android_packages_apps_Settings by omnirom.
the class DataUsagePreferenceController method getDataUsageSummary.
private CharSequence getDataUsageSummary(Context context, int subId) {
final DataUsageController controller = new DataUsageController(context);
controller.setSubscriptionId(subId);
mHistoricalUsageLevel = ThreadUtils.postOnBackgroundThread(() -> controller.getHistoricalUsageLevel(getNetworkTemplate()));
final DataUsageController.DataUsageInfo usageInfo = getDataUsageInfo(controller);
long usageLevel = usageInfo.usageLevel;
if (usageLevel <= 0L) {
try {
usageLevel = mHistoricalUsageLevel.get();
} catch (Exception exception) {
}
}
if (usageLevel <= 0L) {
return null;
}
return context.getString(R.string.data_usage_template, DataUsageUtils.formatDataUsage(context, usageLevel), usageInfo.period);
}
use of com.android.settingslib.net.DataUsageController in project android_packages_apps_Settings by LineageOS.
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;
}
use of com.android.settingslib.net.DataUsageController in project android_packages_apps_Settings by LineageOS.
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);
}
use of com.android.settingslib.net.DataUsageController in project android_packages_apps_Settings by LineageOS.
the class DataUsagePreference method setTemplate.
@Override
public void setTemplate(NetworkTemplate template, int subId, NetworkServices services) {
mTemplate = template;
mSubId = subId;
DataUsageController controller = new DataUsageController(getContext());
DataUsageController.DataUsageInfo usageInfo = controller.getDataUsageInfo(mTemplate);
setSummary(getContext().getString(R.string.data_usage_template, Formatter.formatFileSize(getContext(), usageInfo.usageLevel), usageInfo.period));
setIntent(getIntent());
}
Aggregations