use of com.android.settingslib.net.DataUsageController in project platform_packages_apps_Settings by BlissRoms.
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());
}
use of com.android.settingslib.net.DataUsageController in project platform_packages_apps_Settings by BlissRoms.
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);
}
use of com.android.settingslib.net.DataUsageController in project platform_packages_apps_Settings by BlissRoms.
the class DataPlanUsageSummary method onCreate.
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
final Context context = getContext();
NetworkPolicyManager policyManager = NetworkPolicyManager.from(context);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mPolicyEditor = new NetworkPolicyEditor(policyManager);
mDataUsageController = new DataUsageController(context);
mDataInfoController = new DataUsageInfoController();
int defaultSubId = DataUsageUtils.getDefaultSubscriptionId(context);
boolean hasMobileData = DataUsageUtils.hasMobileData(context);
if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
hasMobileData = false;
}
mDefaultTemplate = DataUsageUtils.getDefaultTemplate(context, defaultSubId);
if (hasMobileData) {
addDataPlanSection(defaultSubId);
}
if (DataUsageUtils.hasWifiRadio(context)) {
addWifiSection();
}
if (hasEthernet(context)) {
addEthernetSection();
}
setHasOptionsMenu(true);
}
use of com.android.settingslib.net.DataUsageController in project platform_packages_apps_Settings by BlissRoms.
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 Resurrection_packages_apps_Settings by ResurrectionRemix.
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 {
boolean showDailyDataUsage = Settings.System.getInt(getContext().getContentResolver(), Settings.System.DATA_USAGE_PERIOD, 1) == 0;
final DataUsageController.DataUsageInfo usageInfo = showDailyDataUsage ? controller.getDailyDataUsageInfo(mTemplate) : 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);
}
}
Aggregations