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();
}
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));
}
}
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;
}
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);
}
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;
}
Aggregations