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
diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java
index 46d6c65..f33c11f 100644
--- a/src/com/android/settings/DataUsageSummary.java
+++ b/src/com/android/settings/DataUsageSummary.java
@@ -474,11 +474,7 @@
             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 @@
                 && !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 @@
             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);
             }
diff --git a/src/com/android/settings/net/NetworkPolicyEditor.java b/src/com/android/settings/net/NetworkPolicyEditor.java
index 5ba8ca4..c9407ce 100644
--- a/src/com/android/settings/net/NetworkPolicyEditor.java
+++ b/src/com/android/settings/net/NetworkPolicyEditor.java
@@ -146,7 +146,7 @@
         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 @@
             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 @@
             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;