Fall back to Wi-Fi data display in data usage screen with no SIM.
Bug: 70950124 Test: manual Test: make RunSettingsRoboTests Change-Id: I06bf78e54119819be87e15baca7e5b6a241958cb Merged-In: I06bf78e54119819be87e15baca7e5b6a241958cb
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.android.settings.datausage;
|
||||
|
||||
import android.util.Log;
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
@@ -85,8 +86,7 @@ public class DataUsageSummary extends DataUsageBaseFragment implements Indexable
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
final Context context = getContext();
|
||||
Context context = getContext();
|
||||
|
||||
boolean hasMobileData = DataUsageUtils.hasMobileData(context);
|
||||
|
||||
@@ -100,18 +100,21 @@ public class DataUsageSummary extends DataUsageBaseFragment implements Indexable
|
||||
if (!hasMobileData || !isAdmin()) {
|
||||
removePreference(KEY_RESTRICT_BACKGROUND);
|
||||
}
|
||||
if (hasMobileData) {
|
||||
SubscriptionInfo subInfo
|
||||
= services.mSubscriptionManager.getDefaultDataSubscriptionInfo();
|
||||
if (subInfo != null) {
|
||||
addMobileSection(subInfo.getSubscriptionId());
|
||||
}
|
||||
}
|
||||
boolean hasWifiRadio = DataUsageUtils.hasWifiRadio(context);
|
||||
if (hasWifiRadio) {
|
||||
if (hasMobileData) {
|
||||
addMobileSection(defaultSubId);
|
||||
if (DataUsageUtils.hasSim(context) && hasWifiRadio) {
|
||||
// If the device has a SIM installed, the data usage section shows usage for mobile,
|
||||
// and the WiFi section is added if there is a WiFi radio - legacy behavior.
|
||||
addWifiSection();
|
||||
}
|
||||
// Do not add the WiFi section if either there is no WiFi radio (obviously) or if no
|
||||
// SIM is installed. In the latter case the data usage section will show WiFi usage and
|
||||
// there should be no explicit WiFi section added.
|
||||
} else if (hasWifiRadio) {
|
||||
addWifiSection();
|
||||
}
|
||||
if (hasEthernet(context)) {
|
||||
if (DataUsageUtils.hasEthernet(context)) {
|
||||
addEthernetSection();
|
||||
}
|
||||
setHasOptionsMenu(true);
|
||||
@@ -161,7 +164,8 @@ public class DataUsageSummary extends DataUsageBaseFragment implements Indexable
|
||||
return controllers;
|
||||
}
|
||||
|
||||
private void addMobileSection(int subId) {
|
||||
@VisibleForTesting
|
||||
void addMobileSection(int subId) {
|
||||
addMobileSection(subId, null);
|
||||
}
|
||||
|
||||
@@ -176,7 +180,8 @@ public class DataUsageSummary extends DataUsageBaseFragment implements Indexable
|
||||
}
|
||||
}
|
||||
|
||||
private void addWifiSection() {
|
||||
@VisibleForTesting
|
||||
void addWifiSection() {
|
||||
TemplatePreferenceCategory category = (TemplatePreferenceCategory)
|
||||
inflatePreferences(R.xml.data_usage_wifi);
|
||||
category.setTemplate(NetworkTemplate.buildTemplateWifiWildcard(), 0, services);
|
||||
@@ -289,17 +294,25 @@ public class DataUsageSummary extends DataUsageBaseFragment implements Indexable
|
||||
@Override
|
||||
public void setListening(boolean listening) {
|
||||
if (listening) {
|
||||
TelephonyManager telephonyManager = (TelephonyManager) mActivity
|
||||
.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
final int simState = telephonyManager.getSimState();
|
||||
// Note that pulling the SIM card returns UNKNOWN, not ABSENT.
|
||||
if (simState == TelephonyManager.SIM_STATE_ABSENT
|
||||
|| simState == TelephonyManager.SIM_STATE_UNKNOWN) {
|
||||
mSummaryLoader.setSummary(this, null);
|
||||
} else {
|
||||
if (DataUsageUtils.hasSim(mActivity)) {
|
||||
mSummaryLoader.setSummary(this,
|
||||
mActivity.getString(R.string.data_usage_summary_format,
|
||||
formatUsedData()));
|
||||
} else {
|
||||
final DataUsageController.DataUsageInfo info =
|
||||
mDataController
|
||||
.getDataUsageInfo(NetworkTemplate.buildTemplateWifiWildcard());
|
||||
|
||||
if (info == null) {
|
||||
mSummaryLoader.setSummary(this, null);
|
||||
} else {
|
||||
final CharSequence wifiFormat = mActivity
|
||||
.getText(R.string.data_usage_wifi_format);
|
||||
final CharSequence sizeText =
|
||||
Formatter.formatFileSize(mActivity, info.usageLevel);
|
||||
mSummaryLoader.setSummary(this,
|
||||
TextUtils.expandTemplate(wifiFormat, sizeText));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user