Move data over-limit dialog, reset policy snooze.
Moved over-limit dialog to SystemUI, and followed Intent changes to read full NetworkTemplate. When mutating NetworkPolicy, always reset any snooze. Bug: 5057979, 4723336 Change-Id: I9a975eb4ced2f4020c2fe74af67625541cbfcd85
This commit is contained in:
@@ -1180,12 +1180,6 @@
|
|||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<intent-filter>
|
|
||||||
<!-- actions from NetworkPolicyManager notifications -->
|
|
||||||
<action android:name="android.intent.action.DATA_USAGE_WARNING" />
|
|
||||||
<action android:name="android.intent.action.DATA_USAGE_LIMIT" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||||
android:value="com.android.settings.DataUsageSummary" />
|
android:value="com.android.settings.DataUsageSummary" />
|
||||||
<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
|
<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
|
||||||
|
@@ -3450,17 +3450,6 @@ found in the list of installed applications.</string>
|
|||||||
<!-- Body of dialog shown before user limits 4G data usage. [CHAR LIMIT=NONE] -->
|
<!-- Body of dialog shown before user limits 4G data usage. [CHAR LIMIT=NONE] -->
|
||||||
<string name="data_usage_limit_dialog_4g">Your 4G data connection will be disabled when the specified limit is reached.\n\nTo avoid overage charges, consider using a reduced limit, as device and carrier accounting methods may vary.</string>
|
<string name="data_usage_limit_dialog_4g">Your 4G data connection will be disabled when the specified limit is reached.\n\nTo avoid overage charges, consider using a reduced limit, as device and carrier accounting methods may vary.</string>
|
||||||
|
|
||||||
<!-- Title of dialog shown when 2G-3G data usage has exceeded limit and has been disabled. [CHAR LIMIT=48] -->
|
|
||||||
<string name="data_usage_disabled_dialog_3g_title">2G-3G data disabled</string>
|
|
||||||
<!-- Title of dialog shown when 4G data usage has exceeded limit and has been disabled. [CHAR LIMIT=48] -->
|
|
||||||
<string name="data_usage_disabled_dialog_4g_title">4G data disabled</string>
|
|
||||||
<!-- Title of dialog shown when mobile data usage has exceeded limit and has been disabled. [CHAR LIMIT=48] -->
|
|
||||||
<string name="data_usage_disabled_dialog_mobile_title">Mobile data disabled</string>
|
|
||||||
<!-- Body of dialog shown when data usage has exceeded limit and has been disabled. [CHAR LIMIT=NONE] -->
|
|
||||||
<string name="data_usage_disabled_dialog">The specified data usage limit has been reached.\n\nAdditional data use may incur carrier charges.</string>
|
|
||||||
<!-- Dialog button indicating that data connection should be re-enabled. [CHAR LIMIT=28] -->
|
|
||||||
<string name="data_usage_disabled_dialog_enable">Re-enable data</string>
|
|
||||||
|
|
||||||
<!-- Title of dialog shown before user restricts background data usage. [CHAR LIMIT=48] -->
|
<!-- Title of dialog shown before user restricts background data usage. [CHAR LIMIT=48] -->
|
||||||
<string name="data_usage_restrict_background_title">Restricting background data</string>
|
<string name="data_usage_restrict_background_title">Restricting background data</string>
|
||||||
<!-- Body of dialog shown before user restricts background data usage. [CHAR LIMIT=NONE] -->
|
<!-- Body of dialog shown before user restricts background data usage. [CHAR LIMIT=NONE] -->
|
||||||
|
@@ -20,7 +20,6 @@ import static android.net.ConnectivityManager.TYPE_ETHERNET;
|
|||||||
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||||
import static android.net.ConnectivityManager.TYPE_WIMAX;
|
import static android.net.ConnectivityManager.TYPE_WIMAX;
|
||||||
import static android.net.NetworkPolicy.LIMIT_DISABLED;
|
import static android.net.NetworkPolicy.LIMIT_DISABLED;
|
||||||
import static android.net.NetworkPolicyManager.ACTION_DATA_USAGE_LIMIT;
|
|
||||||
import static android.net.NetworkPolicyManager.EXTRA_NETWORK_TEMPLATE;
|
import static android.net.NetworkPolicyManager.EXTRA_NETWORK_TEMPLATE;
|
||||||
import static android.net.NetworkPolicyManager.POLICY_NONE;
|
import static android.net.NetworkPolicyManager.POLICY_NONE;
|
||||||
import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
|
import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
|
||||||
@@ -141,7 +140,6 @@ public class DataUsageSummary extends Fragment {
|
|||||||
private static final String TAG_CONFIRM_ROAMING = "confirmRoaming";
|
private static final String TAG_CONFIRM_ROAMING = "confirmRoaming";
|
||||||
private static final String TAG_CONFIRM_LIMIT = "confirmLimit";
|
private static final String TAG_CONFIRM_LIMIT = "confirmLimit";
|
||||||
private static final String TAG_CYCLE_EDITOR = "cycleEditor";
|
private static final String TAG_CYCLE_EDITOR = "cycleEditor";
|
||||||
private static final String TAG_POLICY_LIMIT = "policyLimit";
|
|
||||||
private static final String TAG_CONFIRM_RESTRICT = "confirmRestrict";
|
private static final String TAG_CONFIRM_RESTRICT = "confirmRestrict";
|
||||||
private static final String TAG_CONFIRM_APP_RESTRICT = "confirmAppRestrict";
|
private static final String TAG_CONFIRM_APP_RESTRICT = "confirmAppRestrict";
|
||||||
private static final String TAG_APP_DETAILS = "appDetails";
|
private static final String TAG_APP_DETAILS = "appDetails";
|
||||||
@@ -324,12 +322,6 @@ public class DataUsageSummary extends Fragment {
|
|||||||
// selected network, and binds chart, cycles and detail list.
|
// selected network, and binds chart, cycles and detail list.
|
||||||
updateTabs();
|
updateTabs();
|
||||||
|
|
||||||
// template and tab has been selected; show dialog if limit passed
|
|
||||||
final String action = intent.getAction();
|
|
||||||
if (ACTION_DATA_USAGE_LIMIT.equals(action)) {
|
|
||||||
PolicyLimitFragment.show(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// kick off background task to update stats
|
// kick off background task to update stats
|
||||||
new AsyncTask<Void, Void, Void>() {
|
new AsyncTask<Void, Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -1337,58 +1329,6 @@ public class DataUsageSummary extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Dialog explaining that {@link NetworkPolicy#limitBytes} has been passed,
|
|
||||||
* and giving the user an option to bypass.
|
|
||||||
*/
|
|
||||||
public static class PolicyLimitFragment extends DialogFragment {
|
|
||||||
private static final String EXTRA_TITLE_ID = "titleId";
|
|
||||||
|
|
||||||
public static void show(DataUsageSummary parent) {
|
|
||||||
final Bundle args = new Bundle();
|
|
||||||
|
|
||||||
final String currentTab = parent.mCurrentTab;
|
|
||||||
if (TAB_3G.equals(currentTab)) {
|
|
||||||
args.putInt(EXTRA_TITLE_ID, R.string.data_usage_disabled_dialog_3g_title);
|
|
||||||
} else if (TAB_4G.equals(currentTab)) {
|
|
||||||
args.putInt(EXTRA_TITLE_ID, R.string.data_usage_disabled_dialog_4g_title);
|
|
||||||
} else if (TAB_MOBILE.equals(currentTab)) {
|
|
||||||
args.putInt(EXTRA_TITLE_ID, R.string.data_usage_disabled_dialog_mobile_title);
|
|
||||||
}
|
|
||||||
|
|
||||||
final PolicyLimitFragment dialog = new PolicyLimitFragment();
|
|
||||||
dialog.setArguments(args);
|
|
||||||
dialog.setTargetFragment(parent, 0);
|
|
||||||
dialog.show(parent.getFragmentManager(), TAG_POLICY_LIMIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
||||||
final Context context = getActivity();
|
|
||||||
|
|
||||||
final int titleId = getArguments().getInt(EXTRA_TITLE_ID);
|
|
||||||
|
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
||||||
builder.setTitle(titleId);
|
|
||||||
builder.setMessage(R.string.data_usage_disabled_dialog);
|
|
||||||
|
|
||||||
builder.setPositiveButton(android.R.string.ok, null);
|
|
||||||
builder.setNegativeButton(R.string.data_usage_disabled_dialog_enable,
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
final DataUsageSummary target = (DataUsageSummary) getTargetFragment();
|
|
||||||
if (target != null) {
|
|
||||||
// TODO: consider "allow 100mb more data", or
|
|
||||||
// only bypass limit for current cycle.
|
|
||||||
target.setPolicyLimitBytes(LIMIT_DISABLED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return builder.create();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dialog to request user confirmation before setting
|
* Dialog to request user confirmation before setting
|
||||||
* {@link Settings.Secure#DATA_ROAMING}.
|
* {@link Settings.Secure#DATA_ROAMING}.
|
||||||
@@ -1497,8 +1437,10 @@ public class DataUsageSummary extends Fragment {
|
|||||||
* {@link NetworkPolicyManager#EXTRA_NETWORK_TEMPLATE} extra.
|
* {@link NetworkPolicyManager#EXTRA_NETWORK_TEMPLATE} extra.
|
||||||
*/
|
*/
|
||||||
private static String computeTabFromIntent(Intent intent) {
|
private static String computeTabFromIntent(Intent intent) {
|
||||||
final int networkTemplate = intent.getIntExtra(EXTRA_NETWORK_TEMPLATE, MATCH_MOBILE_ALL);
|
final NetworkTemplate template = intent.getParcelableExtra(EXTRA_NETWORK_TEMPLATE);
|
||||||
switch (networkTemplate) {
|
if (template == null) return null;
|
||||||
|
|
||||||
|
switch (template.getMatchRule()) {
|
||||||
case MATCH_MOBILE_3G_LOWER:
|
case MATCH_MOBILE_3G_LOWER:
|
||||||
return TAB_3G;
|
return TAB_3G;
|
||||||
case MATCH_MOBILE_4G:
|
case MATCH_MOBILE_4G:
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.net;
|
package com.android.settings.net;
|
||||||
|
|
||||||
import static android.net.NetworkPolicy.LIMIT_DISABLED;
|
import static android.net.NetworkPolicy.LIMIT_DISABLED;
|
||||||
|
import static android.net.NetworkPolicy.SNOOZE_NEVER;
|
||||||
import static android.net.NetworkPolicy.WARNING_DISABLED;
|
import static android.net.NetworkPolicy.WARNING_DISABLED;
|
||||||
import static android.net.NetworkTemplate.MATCH_MOBILE_3G_LOWER;
|
import static android.net.NetworkTemplate.MATCH_MOBILE_3G_LOWER;
|
||||||
import static android.net.NetworkTemplate.MATCH_MOBILE_4G;
|
import static android.net.NetworkTemplate.MATCH_MOBILE_4G;
|
||||||
@@ -100,17 +101,23 @@ public class NetworkPolicyEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setPolicyCycleDay(NetworkTemplate template, int cycleDay) {
|
public void setPolicyCycleDay(NetworkTemplate template, int cycleDay) {
|
||||||
getPolicy(template).cycleDay = cycleDay;
|
final NetworkPolicy policy = getPolicy(template);
|
||||||
|
policy.cycleDay = cycleDay;
|
||||||
|
policy.lastSnooze = SNOOZE_NEVER;
|
||||||
writeAsync();
|
writeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPolicyWarningBytes(NetworkTemplate template, long warningBytes) {
|
public void setPolicyWarningBytes(NetworkTemplate template, long warningBytes) {
|
||||||
getPolicy(template).warningBytes = warningBytes;
|
final NetworkPolicy policy = getPolicy(template);
|
||||||
|
policy.warningBytes = warningBytes;
|
||||||
|
policy.lastSnooze = SNOOZE_NEVER;
|
||||||
writeAsync();
|
writeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPolicyLimitBytes(NetworkTemplate template, long limitBytes) {
|
public void setPolicyLimitBytes(NetworkTemplate template, long limitBytes) {
|
||||||
getPolicy(template).limitBytes = limitBytes;
|
final NetworkPolicy policy = getPolicy(template);
|
||||||
|
policy.limitBytes = limitBytes;
|
||||||
|
policy.lastSnooze = SNOOZE_NEVER;
|
||||||
writeAsync();
|
writeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,17 +162,19 @@ public class NetworkPolicyEditor {
|
|||||||
mPolicies.remove(policy4g);
|
mPolicies.remove(policy4g);
|
||||||
mPolicies.add(
|
mPolicies.add(
|
||||||
new NetworkPolicy(templateAll, restrictive.cycleDay, restrictive.warningBytes,
|
new NetworkPolicy(templateAll, restrictive.cycleDay, restrictive.warningBytes,
|
||||||
restrictive.limitBytes));
|
restrictive.limitBytes, SNOOZE_NEVER));
|
||||||
writeAsync();
|
writeAsync();
|
||||||
|
|
||||||
} else if (!beforeSplit && split) {
|
} else if (!beforeSplit && split) {
|
||||||
// duplicate existing policy into two rules
|
// duplicate existing policy into two rules
|
||||||
final NetworkPolicy policyAll = getPolicy(templateAll);
|
final NetworkPolicy policyAll = getPolicy(templateAll);
|
||||||
mPolicies.remove(policyAll);
|
mPolicies.remove(policyAll);
|
||||||
mPolicies.add(new NetworkPolicy(
|
mPolicies.add(
|
||||||
template3g, policyAll.cycleDay, policyAll.warningBytes, policyAll.limitBytes));
|
new NetworkPolicy(template3g, policyAll.cycleDay, policyAll.warningBytes,
|
||||||
mPolicies.add(new NetworkPolicy(
|
policyAll.limitBytes, SNOOZE_NEVER));
|
||||||
template4g, policyAll.cycleDay, policyAll.warningBytes, policyAll.limitBytes));
|
mPolicies.add(
|
||||||
|
new NetworkPolicy(template4g, policyAll.cycleDay, policyAll.warningBytes,
|
||||||
|
policyAll.limitBytes, SNOOZE_NEVER));
|
||||||
writeAsync();
|
writeAsync();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user