NetworkTemplate refactoring for data stats.
To match framework changes.
Change-Id: I0f648ae5753149f9774c8096540834451ba41279
diff --git a/src/com/android/settings/DataUsageAppDetail.java b/src/com/android/settings/DataUsageAppDetail.java
index 0d15dac..a683561 100644
--- a/src/com/android/settings/DataUsageAppDetail.java
+++ b/src/com/android/settings/DataUsageAppDetail.java
@@ -18,7 +18,6 @@
import static android.net.NetworkPolicyManager.POLICY_NONE;
import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
-import static android.net.TrafficStats.TEMPLATE_MOBILE_ALL;
import static com.android.settings.DataUsageSummary.getHistoryBounds;
import android.app.AlertDialog;
@@ -34,6 +33,7 @@
import android.net.INetworkStatsService;
import android.net.NetworkPolicyManager;
import android.net.NetworkStatsHistory;
+import android.net.NetworkTemplate;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -58,7 +58,12 @@
private static final String TAG = "DataUsage";
private static final boolean LOGD = true;
+ public static final String EXTRA_UID = "uid";
+ public static final String EXTRA_NETWORK_TEMPLATE = "networkTemplate";
+
private int mUid;
+ private NetworkTemplate mTemplate;
+
private Intent mAppSettingsIntent;
private static final String TAG_CONFIRM_RESTRICT = "confirmRestrict";
@@ -133,7 +138,9 @@
private void updateBody() {
final PackageManager pm = getActivity().getPackageManager();
- mUid = getArguments().getInt(Intent.EXTRA_UID);
+ mUid = getArguments().getInt(EXTRA_UID);
+ mTemplate = getArguments().getParcelable(EXTRA_NETWORK_TEMPLATE);
+
mTitle.setText(pm.getNameForUid(mUid));
// enable settings button when package provides it
@@ -155,7 +162,7 @@
try {
// load stats for current uid and template
// TODO: read template from extras
- mHistory = mStatsService.getHistoryForUid(mUid, TEMPLATE_MOBILE_ALL);
+ mHistory = mStatsService.getHistoryForUid(mTemplate, mUid);
} catch (RemoteException e) {
// since we can't do much without history, and we don't want to
// leave with half-baked UI, we bail hard.
diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java
index 087525c..83dd78e 100644
--- a/src/com/android/settings/DataUsageSummary.java
+++ b/src/com/android/settings/DataUsageSummary.java
@@ -21,10 +21,10 @@
import static android.net.NetworkPolicyManager.EXTRA_NETWORK_TEMPLATE;
import static android.net.NetworkPolicyManager.computeLastCycleBoundary;
import static android.net.NetworkPolicyManager.computeNextCycleBoundary;
-import static android.net.TrafficStats.TEMPLATE_MOBILE_3G_LOWER;
-import static android.net.TrafficStats.TEMPLATE_MOBILE_4G;
-import static android.net.TrafficStats.TEMPLATE_MOBILE_ALL;
-import static android.net.TrafficStats.TEMPLATE_WIFI;
+import static android.net.NetworkTemplate.MATCH_MOBILE_3G_LOWER;
+import static android.net.NetworkTemplate.MATCH_MOBILE_4G;
+import static android.net.NetworkTemplate.MATCH_MOBILE_ALL;
+import static android.net.NetworkTemplate.MATCH_WIFI;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import android.app.AlertDialog;
@@ -44,6 +44,7 @@
import android.net.NetworkPolicyManager;
import android.net.NetworkStats;
import android.net.NetworkStatsHistory;
+import android.net.NetworkTemplate;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.RemoteException;
@@ -82,7 +83,7 @@
import android.widget.TabWidget;
import android.widget.TextView;
-import com.android.settings.net.NetworkPolicyModifier;
+import com.android.settings.net.NetworkPolicyEditor;
import com.android.settings.widget.DataUsageChartView;
import com.android.settings.widget.DataUsageChartView.DataUsageChartListener;
import com.google.android.collect.Lists;
@@ -135,9 +136,9 @@
// TODO: persist show wifi flag
private boolean mShowWifi = false;
- private int mTemplate = TEMPLATE_INVALID;
+ private NetworkTemplate mTemplate = null;
- private NetworkPolicyModifier mPolicyModifier;
+ private NetworkPolicyEditor mPolicyEditor;
private NetworkStatsHistory mHistory;
private String mIntentTab = null;
@@ -151,10 +152,8 @@
mPolicyService = INetworkPolicyManager.Stub.asInterface(
ServiceManager.getService(Context.NETWORK_POLICY_SERVICE));
- final Context context = getActivity();
- final String subscriberId = getActiveSubscriberId(context);
- mPolicyModifier = new NetworkPolicyModifier(mPolicyService, subscriberId);
- mPolicyModifier.read();
+ mPolicyEditor = new NetworkPolicyEditor(mPolicyService);
+ mPolicyEditor.read();
setHasOptionsMenu(true);
}
@@ -237,7 +236,7 @@
@Override
public void onPrepareOptionsMenu(Menu menu) {
final MenuItem split4g = menu.findItem(R.id.action_split_4g);
- split4g.setChecked(mPolicyModifier.isMobilePolicySplit());
+ split4g.setChecked(isMobilePolicySplit());
}
@Override
@@ -245,8 +244,8 @@
switch (item.getItemId()) {
case R.id.action_split_4g: {
final boolean mobileSplit = !item.isChecked();
- mPolicyModifier.setMobilePolicySplit(mobileSplit);
- item.setChecked(mPolicyModifier.isMobilePolicySplit());
+ setMobilePolicySplit(mobileSplit);
+ item.setChecked(isMobilePolicySplit());
updateTabs();
return true;
}
@@ -269,12 +268,12 @@
}
/**
- * Rebuild all tabs based on {@link NetworkPolicyModifier} and
+ * Rebuild all tabs based on {@link NetworkPolicyEditor} and
* {@link #mShowWifi}, hiding the tabs entirely when applicable. Selects
* first tab, and kicks off a full rebind of body contents.
*/
private void updateTabs() {
- final boolean mobileSplit = mPolicyModifier.isMobilePolicySplit();
+ final boolean mobileSplit = isMobilePolicySplit();
final boolean tabsVisible = mobileSplit || mShowWifi;
mTabWidget.setVisibility(tabsVisible ? View.VISIBLE : View.GONE);
mTabHost.clearAllTabs();
@@ -344,13 +343,16 @@
final String tabTag = mTabHost.getCurrentTabTag();
final String currentTab = tabTag != null ? tabTag : TAB_MOBILE;
+ final Context context = getActivity();
+ final String subscriberId = getActiveSubscriberId(context);
+
if (LOGD) Log.d(TAG, "updateBody() with currentTab=" + currentTab);
if (TAB_WIFI.equals(currentTab)) {
// wifi doesn't have any controls
mDataEnabledView.setVisibility(View.GONE);
mDisableAtLimitView.setVisibility(View.GONE);
- mTemplate = TEMPLATE_WIFI;
+ mTemplate = new NetworkTemplate(MATCH_WIFI, null);
} else {
// make sure we show for non-wifi
@@ -361,17 +363,17 @@
if (TAB_MOBILE.equals(currentTab)) {
mDataEnabled.setTitle(R.string.data_usage_enable_mobile);
mDisableAtLimit.setTitle(R.string.data_usage_disable_mobile_limit);
- mTemplate = TEMPLATE_MOBILE_ALL;
+ mTemplate = new NetworkTemplate(MATCH_MOBILE_ALL, subscriberId);
} else if (TAB_3G.equals(currentTab)) {
mDataEnabled.setTitle(R.string.data_usage_enable_3g);
mDisableAtLimit.setTitle(R.string.data_usage_disable_3g_limit);
- mTemplate = TEMPLATE_MOBILE_3G_LOWER;
+ mTemplate = new NetworkTemplate(MATCH_MOBILE_3G_LOWER, subscriberId);
} else if (TAB_4G.equals(currentTab)) {
mDataEnabled.setTitle(R.string.data_usage_enable_4g);
mDisableAtLimit.setTitle(R.string.data_usage_disable_4g_limit);
- mTemplate = TEMPLATE_MOBILE_4G;
+ mTemplate = new NetworkTemplate(MATCH_MOBILE_4G, subscriberId);
}
@@ -401,19 +403,19 @@
private void setPolicyCycleDay(int cycleDay) {
if (LOGD) Log.d(TAG, "setPolicyCycleDay()");
- mPolicyModifier.setPolicyCycleDay(mTemplate, cycleDay);
+ mPolicyEditor.setPolicyCycleDay(mTemplate, cycleDay);
updatePolicy(true);
}
private void setPolicyWarningBytes(long warningBytes) {
if (LOGD) Log.d(TAG, "setPolicyWarningBytes()");
- mPolicyModifier.setPolicyWarningBytes(mTemplate, warningBytes);
+ mPolicyEditor.setPolicyWarningBytes(mTemplate, warningBytes);
updatePolicy(false);
}
private void setPolicyLimitBytes(long limitBytes) {
if (LOGD) Log.d(TAG, "setPolicyLimitBytes()");
- mPolicyModifier.setPolicyLimitBytes(mTemplate, limitBytes);
+ mPolicyEditor.setPolicyLimitBytes(mTemplate, limitBytes);
updatePolicy(false);
}
@@ -422,7 +424,7 @@
* current {@link #mTemplate}.
*/
private void updatePolicy(boolean refreshCycle) {
- final NetworkPolicy policy = mPolicyModifier.getPolicy(mTemplate);
+ final NetworkPolicy policy = mPolicyEditor.getPolicy(mTemplate);
// reflect policy limit in checkbox
mDisableAtLimit.setChecked(policy != null && policy.limitBytes != LIMIT_DISABLED);
@@ -542,7 +544,8 @@
final AppUsageItem app = (AppUsageItem) parent.getItemAtPosition(position);
final Bundle args = new Bundle();
- args.putInt(Intent.EXTRA_UID, app.uid);
+ args.putParcelable(DataUsageAppDetail.EXTRA_NETWORK_TEMPLATE, mTemplate);
+ args.putInt(DataUsageAppDetail.EXTRA_UID, app.uid);
final PreferenceActivity activity = (PreferenceActivity) getActivity();
activity.startPreferencePanel(DataUsageAppDetail.class.getName(), args,
@@ -595,7 +598,7 @@
protected NetworkStats doInBackground(Void... params) {
try {
final long[] range = mChart.getInspectRange();
- return mStatsService.getSummaryForAllUid(range[0], range[1], mTemplate);
+ return mStatsService.getSummaryForAllUid(mTemplate, range[0], range[1]);
} catch (RemoteException e) {
Log.w(TAG, "problem reading stats");
}
@@ -611,6 +614,16 @@
}.execute();
}
+ private boolean isMobilePolicySplit() {
+ final String subscriberId = getActiveSubscriberId(getActivity());
+ return mPolicyEditor.isMobilePolicySplit(subscriberId);
+ }
+
+ private void setMobilePolicySplit(boolean split) {
+ final String subscriberId = getActiveSubscriberId(getActivity());
+ mPolicyEditor.setMobilePolicySplit(subscriberId, split);
+ }
+
private static String getActiveSubscriberId(Context context) {
final TelephonyManager telephony = (TelephonyManager) context.getSystemService(
Context.TELEPHONY_SERVICE);
@@ -772,18 +785,18 @@
final Bundle args = new Bundle();
// TODO: customize default limits based on network template
- switch (parent.mTemplate) {
- case TEMPLATE_MOBILE_3G_LOWER: {
+ switch (parent.mTemplate.getMatchRule()) {
+ case MATCH_MOBILE_3G_LOWER: {
args.putInt(EXTRA_MESSAGE_ID, R.string.data_usage_limit_dialog_3g);
args.putLong(EXTRA_LIMIT_BYTES, 5 * GB_IN_BYTES);
break;
}
- case TEMPLATE_MOBILE_4G: {
+ case MATCH_MOBILE_4G: {
args.putInt(EXTRA_MESSAGE_ID, R.string.data_usage_limit_dialog_4g);
args.putLong(EXTRA_LIMIT_BYTES, 5 * GB_IN_BYTES);
break;
}
- case TEMPLATE_MOBILE_ALL: {
+ case MATCH_MOBILE_ALL: {
args.putInt(EXTRA_MESSAGE_ID, R.string.data_usage_limit_dialog_mobile);
args.putLong(EXTRA_LIMIT_BYTES, 5 * GB_IN_BYTES);
break;
@@ -827,7 +840,7 @@
public static final String EXTRA_CYCLE_DAY = "cycleDay";
public static void show(DataUsageSummary parent) {
- final NetworkPolicy policy = parent.mPolicyModifier.getPolicy(parent.mTemplate);
+ final NetworkPolicy policy = parent.mPolicyEditor.getPolicy(parent.mTemplate);
final Bundle args = new Bundle();
args.putInt(CycleEditorFragment.EXTRA_CYCLE_DAY, policy.cycleDay);
@@ -882,16 +895,16 @@
public static void show(DataUsageSummary parent) {
final Bundle args = new Bundle();
- switch (parent.mTemplate) {
- case TEMPLATE_MOBILE_3G_LOWER: {
+ switch (parent.mTemplate.getMatchRule()) {
+ case MATCH_MOBILE_3G_LOWER: {
args.putInt(EXTRA_TITLE_ID, R.string.data_usage_disabled_dialog_3g_title);
break;
}
- case TEMPLATE_MOBILE_4G: {
+ case MATCH_MOBILE_4G: {
args.putInt(EXTRA_TITLE_ID, R.string.data_usage_disabled_dialog_4g_title);
break;
}
- case TEMPLATE_MOBILE_ALL: {
+ case MATCH_MOBILE_ALL: {
args.putInt(EXTRA_TITLE_ID, R.string.data_usage_disabled_dialog_mobile_title);
break;
}
@@ -937,13 +950,13 @@
private static String computeTabFromIntent(Intent intent) {
final int networkTemplate = intent.getIntExtra(EXTRA_NETWORK_TEMPLATE, TEMPLATE_INVALID);
switch (networkTemplate) {
- case TEMPLATE_MOBILE_3G_LOWER:
+ case MATCH_MOBILE_3G_LOWER:
return TAB_3G;
- case TEMPLATE_MOBILE_4G:
+ case MATCH_MOBILE_4G:
return TAB_4G;
- case TEMPLATE_MOBILE_ALL:
+ case MATCH_MOBILE_ALL:
return TAB_MOBILE;
- case TEMPLATE_WIFI:
+ case MATCH_WIFI:
return TAB_WIFI;
default:
return null;
diff --git a/src/com/android/settings/net/NetworkPolicyEditor.java b/src/com/android/settings/net/NetworkPolicyEditor.java
new file mode 100644
index 0000000..c50a490
--- /dev/null
+++ b/src/com/android/settings/net/NetworkPolicyEditor.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.net;
+
+import static android.net.NetworkTemplate.MATCH_MOBILE_3G_LOWER;
+import static android.net.NetworkTemplate.MATCH_MOBILE_4G;
+import static android.net.NetworkTemplate.MATCH_MOBILE_ALL;
+import static com.android.internal.util.Preconditions.checkNotNull;
+
+import android.net.INetworkPolicyManager;
+import android.net.NetworkPolicy;
+import android.net.NetworkTemplate;
+import android.os.AsyncTask;
+import android.os.RemoteException;
+
+import com.android.internal.util.Objects;
+import com.google.android.collect.Lists;
+
+import java.util.ArrayList;
+
+/**
+ * Utility class to modify list of {@link NetworkPolicy}. Specifically knows
+ * about which policies can coexist.
+ */
+public class NetworkPolicyEditor {
+ // TODO: be more robust when missing policies from service
+
+ private INetworkPolicyManager mPolicyService;
+ private ArrayList<NetworkPolicy> mPolicies = Lists.newArrayList();
+
+ public NetworkPolicyEditor(INetworkPolicyManager policyService) {
+ mPolicyService = checkNotNull(policyService);
+ }
+
+ public void read() {
+ try {
+ final NetworkPolicy[] policies = mPolicyService.getNetworkPolicies();
+ mPolicies.clear();
+ for (NetworkPolicy policy : policies) {
+ mPolicies.add(policy);
+ }
+ } catch (RemoteException e) {
+ throw new RuntimeException("problem reading policies", e);
+ }
+ }
+
+ public void writeAsync() {
+ // TODO: consider making more robust by passing through service
+ new AsyncTask<Void, Void, Void>() {
+ @Override
+ protected Void doInBackground(Void... params) {
+ write();
+ return null;
+ }
+ }.execute();
+ }
+
+ public void write() {
+ try {
+ final NetworkPolicy[] policies = mPolicies.toArray(new NetworkPolicy[mPolicies.size()]);
+ mPolicyService.setNetworkPolicies(policies);
+ } catch (RemoteException e) {
+ throw new RuntimeException("problem reading policies", e);
+ }
+ }
+
+ public NetworkPolicy getPolicy(NetworkTemplate template) {
+ for (NetworkPolicy policy : mPolicies) {
+ if (policy.template.equals(template)) {
+ return policy;
+ }
+ }
+ return null;
+ }
+
+ public void setPolicyCycleDay(NetworkTemplate template, int cycleDay) {
+ getPolicy(template).cycleDay = cycleDay;
+ writeAsync();
+ }
+
+ public void setPolicyWarningBytes(NetworkTemplate template, long warningBytes) {
+ getPolicy(template).warningBytes = warningBytes;
+ writeAsync();
+ }
+
+ public void setPolicyLimitBytes(NetworkTemplate template, long limitBytes) {
+ getPolicy(template).limitBytes = limitBytes;
+ writeAsync();
+ }
+
+ public boolean isMobilePolicySplit(String subscriberId) {
+ boolean has3g = false;
+ boolean has4g = false;
+ for (NetworkPolicy policy : mPolicies) {
+ final NetworkTemplate template = policy.template;
+ if (Objects.equal(subscriberId, template.getSubscriberId())) {
+ switch (template.getMatchRule()) {
+ case MATCH_MOBILE_3G_LOWER:
+ has3g = true;
+ break;
+ case MATCH_MOBILE_4G:
+ has4g = true;
+ break;
+ }
+ }
+ }
+ return has3g && has4g;
+ }
+
+ public void setMobilePolicySplit(String subscriberId, boolean split) {
+ final boolean beforeSplit = isMobilePolicySplit(subscriberId);
+
+ final NetworkTemplate template3g = new NetworkTemplate(MATCH_MOBILE_3G_LOWER, subscriberId);
+ final NetworkTemplate template4g = new NetworkTemplate(MATCH_MOBILE_4G, subscriberId);
+ final NetworkTemplate templateAll = new NetworkTemplate(MATCH_MOBILE_ALL, subscriberId);
+
+ if (split == beforeSplit) {
+ // already in requested state; skip
+ return;
+
+ } else if (beforeSplit && !split) {
+ // combine, picking most restrictive policy
+ final NetworkPolicy policy3g = getPolicy(template3g);
+ final NetworkPolicy policy4g = getPolicy(template4g);
+
+ final NetworkPolicy restrictive = policy3g.compareTo(policy4g) < 0 ? policy3g
+ : policy4g;
+ mPolicies.remove(policy3g);
+ mPolicies.remove(policy4g);
+ mPolicies.add(
+ new NetworkPolicy(templateAll, restrictive.cycleDay, restrictive.warningBytes,
+ restrictive.limitBytes));
+ writeAsync();
+
+ } else if (!beforeSplit && split) {
+ // duplicate existing policy into two rules
+ final NetworkPolicy policyAll = getPolicy(templateAll);
+ mPolicies.remove(policyAll);
+ mPolicies.add(new NetworkPolicy(
+ template3g, policyAll.cycleDay, policyAll.warningBytes, policyAll.limitBytes));
+ mPolicies.add(new NetworkPolicy(
+ template4g, policyAll.cycleDay, policyAll.warningBytes, policyAll.limitBytes));
+ writeAsync();
+
+ }
+ }
+
+}
diff --git a/src/com/android/settings/net/NetworkPolicyModifier.java b/src/com/android/settings/net/NetworkPolicyModifier.java
deleted file mode 100644
index d90609e..0000000
--- a/src/com/android/settings/net/NetworkPolicyModifier.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.net;
-
-import static android.net.TrafficStats.TEMPLATE_MOBILE_3G_LOWER;
-import static android.net.TrafficStats.TEMPLATE_MOBILE_4G;
-import static android.net.TrafficStats.TEMPLATE_MOBILE_ALL;
-import static com.android.internal.util.Preconditions.checkNotNull;
-
-import android.net.INetworkPolicyManager;
-import android.net.NetworkPolicy;
-import android.os.AsyncTask;
-import android.os.RemoteException;
-
-import com.android.internal.util.Objects;
-import com.google.android.collect.Lists;
-
-import java.util.ArrayList;
-
-/**
- * Utility class to modify list of {@link NetworkPolicy}. Specifically knows
- * about which policies can coexist.
- */
-public class NetworkPolicyModifier {
- // TODO: refactor to "Editor"
- // TODO: be more robust when missing policies from service
-
- private INetworkPolicyManager mPolicyService;
- private String mSubscriberId;
-
- private ArrayList<NetworkPolicy> mPolicies = Lists.newArrayList();
-
- public NetworkPolicyModifier(INetworkPolicyManager policyService, String subscriberId) {
- mPolicyService = checkNotNull(policyService);
- mSubscriberId = subscriberId;
- }
-
- public void read() {
- try {
- final NetworkPolicy[] policies = mPolicyService.getNetworkPolicies();
- mPolicies.clear();
- for (NetworkPolicy policy : policies) {
- mPolicies.add(policy);
- }
- } catch (RemoteException e) {
- throw new RuntimeException("problem reading policies", e);
- }
- }
-
- public void writeAsync() {
- // TODO: consider making more robust by passing through service
- new AsyncTask<Void, Void, Void>() {
- @Override
- protected Void doInBackground(Void... params) {
- write();
- return null;
- }
- }.execute();
- }
-
- public void write() {
- try {
- final NetworkPolicy[] policies = mPolicies.toArray(new NetworkPolicy[mPolicies.size()]);
- mPolicyService.setNetworkPolicies(policies);
- } catch (RemoteException e) {
- throw new RuntimeException("problem reading policies", e);
- }
- }
-
- public NetworkPolicy getPolicy(int networkTemplate) {
- for (NetworkPolicy policy : mPolicies) {
- if (policy.networkTemplate == networkTemplate
- && Objects.equal(policy.subscriberId, mSubscriberId)) {
- return policy;
- }
- }
- return null;
- }
-
- public void setPolicyCycleDay(int networkTemplate, int cycleDay) {
- getPolicy(networkTemplate).cycleDay = cycleDay;
- writeAsync();
- }
-
- public void setPolicyWarningBytes(int networkTemplate, long warningBytes) {
- getPolicy(networkTemplate).warningBytes = warningBytes;
- writeAsync();
- }
-
- public void setPolicyLimitBytes(int networkTemplate, long limitBytes) {
- getPolicy(networkTemplate).limitBytes = limitBytes;
- writeAsync();
- }
-
- public boolean isMobilePolicySplit() {
- return getPolicy(TEMPLATE_MOBILE_3G_LOWER) != null && getPolicy(TEMPLATE_MOBILE_4G) != null;
- }
-
- public void setMobilePolicySplit(boolean split) {
- final boolean beforeSplit = isMobilePolicySplit();
- if (split == beforeSplit) {
- // already in requested state; skip
- return;
-
- } else if (beforeSplit && !split) {
- // combine, picking most restrictive policy
- final NetworkPolicy policy3g = getPolicy(TEMPLATE_MOBILE_3G_LOWER);
- final NetworkPolicy policy4g = getPolicy(TEMPLATE_MOBILE_4G);
-
- final NetworkPolicy restrictive = policy3g.compareTo(policy4g) < 0 ? policy3g
- : policy4g;
- mPolicies.remove(policy3g);
- mPolicies.remove(policy4g);
- mPolicies.add(new NetworkPolicy(TEMPLATE_MOBILE_ALL, restrictive.subscriberId,
- restrictive.cycleDay, restrictive.warningBytes, restrictive.limitBytes));
- writeAsync();
-
- } else if (!beforeSplit && split) {
- // duplicate existing policy into two rules
- final NetworkPolicy policyAll = getPolicy(TEMPLATE_MOBILE_ALL);
- mPolicies.remove(policyAll);
- mPolicies.add(
- new NetworkPolicy(TEMPLATE_MOBILE_3G_LOWER, policyAll.subscriberId,
- policyAll.cycleDay, policyAll.warningBytes, policyAll.limitBytes));
- mPolicies.add(
- new NetworkPolicy(TEMPLATE_MOBILE_4G, policyAll.subscriberId,
- policyAll.cycleDay, policyAll.warningBytes, policyAll.limitBytes));
- writeAsync();
-
- }
- }
-
-}