Restrict app data on metered networks.

Paired with framework change that no longer requires NetworkPolicy
to have limit when restricting apps.

Bug: 5571454
Change-Id: I2a5d8446a9278afb183e13d0f41f436ccb3bc9e8
This commit is contained in:
Jeff Sharkey
2011-11-30 15:37:51 -08:00
parent 459a531da4
commit 3038c52de4
2 changed files with 11 additions and 26 deletions

View File

@@ -474,11 +474,7 @@ public class DataUsageSummary extends Fragment {
case R.id.data_usage_menu_restrict_background: { case R.id.data_usage_menu_restrict_background: {
final boolean restrictBackground = !item.isChecked(); final boolean restrictBackground = !item.isChecked();
if (restrictBackground) { if (restrictBackground) {
if (hasLimitedNetworks()) {
ConfirmRestrictFragment.show(this); ConfirmRestrictFragment.show(this);
} else {
DeniedRestrictFragment.show(this);
}
} else { } else {
// no confirmation to drop restriction // no confirmation to drop restriction
setRestrictBackground(false); setRestrictBackground(false);
@@ -764,13 +760,8 @@ public class DataUsageSummary extends Fragment {
&& !getRestrictBackground() && isBandwidthControlEnabled() && !getRestrictBackground() && isBandwidthControlEnabled()
&& hasMobileRadio(context)) { && hasMobileRadio(context)) {
setPreferenceTitle(mAppRestrictView, R.string.data_usage_app_restrict_background); setPreferenceTitle(mAppRestrictView, R.string.data_usage_app_restrict_background);
if (hasLimitedNetworks()) {
setPreferenceSummary(mAppRestrictView, setPreferenceSummary(mAppRestrictView,
getString(R.string.data_usage_app_restrict_background_summary)); getString(R.string.data_usage_app_restrict_background_summary));
} else {
setPreferenceSummary(mAppRestrictView,
getString(R.string.data_usage_app_restrict_background_summary_disabled));
}
mAppRestrictView.setVisibility(View.VISIBLE); mAppRestrictView.setVisibility(View.VISIBLE);
mAppRestrict.setChecked(getAppRestrictBackground()); mAppRestrict.setChecked(getAppRestrictBackground());
@@ -1037,16 +1028,10 @@ public class DataUsageSummary extends Fragment {
final boolean restrictBackground = !mAppRestrict.isChecked(); final boolean restrictBackground = !mAppRestrict.isChecked();
if (restrictBackground) { if (restrictBackground) {
if (hasLimitedNetworks()) {
// enabling restriction; show confirmation dialog which // enabling restriction; show confirmation dialog which
// eventually calls setRestrictBackground() once user // eventually calls setRestrictBackground() once user
// confirms. // confirms.
ConfirmAppRestrictFragment.show(DataUsageSummary.this); ConfirmAppRestrictFragment.show(DataUsageSummary.this);
} else {
// no limited networks; show dialog to guide user towards
// setting a network limit. doesn't mutate restrict state.
DeniedRestrictFragment.show(DataUsageSummary.this);
}
} else { } else {
setAppRestrictBackground(false); setAppRestrictBackground(false);
} }

View File

@@ -146,7 +146,7 @@ public class NetworkPolicyEditor {
final int cycleDay = time.monthDay; final int cycleDay = time.monthDay;
return new NetworkPolicy( return new NetworkPolicy(
template, cycleDay, WARNING_DISABLED, LIMIT_DISABLED, SNOOZE_NEVER); template, cycleDay, WARNING_DISABLED, LIMIT_DISABLED, SNOOZE_NEVER, true);
} }
public int getPolicyCycleDay(NetworkTemplate template) { public int getPolicyCycleDay(NetworkTemplate template) {
@@ -251,7 +251,7 @@ 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, SNOOZE_NEVER)); restrictive.limitBytes, SNOOZE_NEVER, restrictive.metered));
return true; return true;
} else if (!beforeSplit && split) { } else if (!beforeSplit && split) {
@@ -260,10 +260,10 @@ public class NetworkPolicyEditor {
mPolicies.remove(policyAll); mPolicies.remove(policyAll);
mPolicies.add( mPolicies.add(
new NetworkPolicy(template3g, policyAll.cycleDay, policyAll.warningBytes, new NetworkPolicy(template3g, policyAll.cycleDay, policyAll.warningBytes,
policyAll.limitBytes, SNOOZE_NEVER)); policyAll.limitBytes, SNOOZE_NEVER, policyAll.metered));
mPolicies.add( mPolicies.add(
new NetworkPolicy(template4g, policyAll.cycleDay, policyAll.warningBytes, new NetworkPolicy(template4g, policyAll.cycleDay, policyAll.warningBytes,
policyAll.limitBytes, SNOOZE_NEVER)); policyAll.limitBytes, SNOOZE_NEVER, policyAll.metered));
return true; return true;
} else { } else {
return false; return false;