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: {
final boolean restrictBackground = !item.isChecked();
if (restrictBackground) {
if (hasLimitedNetworks()) {
ConfirmRestrictFragment.show(this);
} else {
DeniedRestrictFragment.show(this);
}
ConfirmRestrictFragment.show(this);
} else {
// no confirmation to drop restriction
setRestrictBackground(false);
@@ -764,13 +760,8 @@ public class DataUsageSummary extends Fragment {
&& !getRestrictBackground() && isBandwidthControlEnabled()
&& hasMobileRadio(context)) {
setPreferenceTitle(mAppRestrictView, R.string.data_usage_app_restrict_background);
if (hasLimitedNetworks()) {
setPreferenceSummary(mAppRestrictView,
getString(R.string.data_usage_app_restrict_background_summary));
} else {
setPreferenceSummary(mAppRestrictView,
getString(R.string.data_usage_app_restrict_background_summary_disabled));
}
setPreferenceSummary(mAppRestrictView,
getString(R.string.data_usage_app_restrict_background_summary));
mAppRestrictView.setVisibility(View.VISIBLE);
mAppRestrict.setChecked(getAppRestrictBackground());
@@ -1037,16 +1028,10 @@ public class DataUsageSummary extends Fragment {
final boolean restrictBackground = !mAppRestrict.isChecked();
if (restrictBackground) {
if (hasLimitedNetworks()) {
// enabling restriction; show confirmation dialog which
// eventually calls setRestrictBackground() once user
// confirms.
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);
}
// enabling restriction; show confirmation dialog which
// eventually calls setRestrictBackground() once user
// confirms.
ConfirmAppRestrictFragment.show(DataUsageSummary.this);
} else {
setAppRestrictBackground(false);
}

View File

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