Data Usage summary creates a dialog to change data warning level

Clicking the Data usage summary preference will open the same dialog
that billing cycle does to modify data warning level. The Dialog
was abstracted to be used outside of the Billing Cycle settings
fragment.

Test: Robo tests in next cherry-pick.

Change-Id: I70398d4656b6da4233b2bfa0da6ffa7402ead69b
Fixes: 26932938
(cherry picked from commit 9fad289ca9)
This commit is contained in:
Matthew Fritze
2016-08-12 09:37:43 -07:00
parent ed765a4817
commit 25437d7c61
3 changed files with 115 additions and 28 deletions

View File

@@ -20,6 +20,7 @@ import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.INetworkStatsSession;
import android.net.NetworkPolicy;
import android.net.NetworkTemplate;
import android.net.TrafficStats;
import android.os.Bundle;
@@ -48,6 +49,7 @@ import com.android.settings.Utils;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.NetworkPolicyEditor;
import com.android.settingslib.net.DataUsageController;
import java.util.ArrayList;
@@ -56,7 +58,7 @@ import java.util.List;
import static android.net.ConnectivityManager.TYPE_ETHERNET;
import static android.net.ConnectivityManager.TYPE_WIFI;
public class DataUsageSummary extends DataUsageBase implements Indexable {
public class DataUsageSummary extends DataUsageBase implements Indexable, DataUsageEditController {
private static final String TAG = "DataUsageSummary";
static final boolean LOGD = false;
@@ -87,15 +89,13 @@ public class DataUsageSummary extends DataUsageBase implements Indexable {
hasMobileData = false;
}
mDefaultTemplate = getDefaultTemplate(getContext(), defaultSubId);
if (hasMobileData) {
mLimitPreference = findPreference(KEY_LIMIT_SUMMARY);
} else {
removePreference(KEY_LIMIT_SUMMARY);
}
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) {
@@ -104,6 +104,10 @@ public class DataUsageSummary extends DataUsageBase implements Indexable {
for (int i = 0; subscriptions != null && i < subscriptions.size(); i++) {
addMobileSection(subscriptions.get(i).getSubscriptionId());
}
mSummaryPreference.setSelectable(true);
} else {
removePreference(KEY_LIMIT_SUMMARY);
mSummaryPreference.setSelectable(false);
}
boolean hasWifiRadio = hasWifiRadio(getContext());
if (hasWifiRadio) {
@@ -116,7 +120,6 @@ public class DataUsageSummary extends DataUsageBase implements Indexable {
: hasWifiRadio ? R.string.wifi_data_template
: R.string.ethernet_data_template;
mSummaryPreference = (SummaryPreference) findPreference(KEY_STATUS_HEADER);
setHasOptionsMenu(true);
}
@@ -142,6 +145,15 @@ public class DataUsageSummary extends DataUsageBase implements Indexable {
return false;
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (preference == findPreference(KEY_STATUS_HEADER)) {
BillingCycleSettings.BytesEditorFragment.show(this, false);
return false;
}
return super.onPreferenceTreeClick(preference);
}
private void addMobileSection(int subId) {
TemplatePreferenceCategory category = (TemplatePreferenceCategory)
inflatePreferences(R.xml.data_usage_cellular);
@@ -224,6 +236,8 @@ public class DataUsageSummary extends DataUsageBase implements Indexable {
DataUsageController.DataUsageInfo info = mDataUsageController.getDataUsageInfo(
mDefaultTemplate);
Context context = getContext();
NetworkPolicy policy = services.mPolicyEditor.getPolicy(mDefaultTemplate);
info.warningLevel = policy.warningBytes;
if (mSummaryPreference != null) {
mSummaryPreference.setTitle(
formatTitle(context, getString(mDataUsageTemplate), info.usageLevel));
@@ -258,6 +272,21 @@ public class DataUsageSummary extends DataUsageBase implements Indexable {
return MetricsEvent.DATA_USAGE_SUMMARY;
}
@Override
public NetworkPolicyEditor getNetworkPolicyEditor() {
return services.mPolicyEditor;
}
@Override
public NetworkTemplate getNetworkTemplate() {
return mDefaultTemplate;
}
@Override
public void updateDataUsage() {
updateState();
}
/**
* Test if device has an ethernet network connection.
*/