NetworkTemplate refactoring for data stats.
To match framework changes. Change-Id: I0f648ae5753149f9774c8096540834451ba41279
This commit is contained in:
@@ -18,7 +18,6 @@ package com.android.settings;
|
|||||||
|
|
||||||
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;
|
||||||
import static android.net.TrafficStats.TEMPLATE_MOBILE_ALL;
|
|
||||||
import static com.android.settings.DataUsageSummary.getHistoryBounds;
|
import static com.android.settings.DataUsageSummary.getHistoryBounds;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@@ -34,6 +33,7 @@ import android.net.INetworkPolicyManager;
|
|||||||
import android.net.INetworkStatsService;
|
import android.net.INetworkStatsService;
|
||||||
import android.net.NetworkPolicyManager;
|
import android.net.NetworkPolicyManager;
|
||||||
import android.net.NetworkStatsHistory;
|
import android.net.NetworkStatsHistory;
|
||||||
|
import android.net.NetworkTemplate;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
@@ -58,7 +58,12 @@ public class DataUsageAppDetail extends Fragment {
|
|||||||
private static final String TAG = "DataUsage";
|
private static final String TAG = "DataUsage";
|
||||||
private static final boolean LOGD = true;
|
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 int mUid;
|
||||||
|
private NetworkTemplate mTemplate;
|
||||||
|
|
||||||
private Intent mAppSettingsIntent;
|
private Intent mAppSettingsIntent;
|
||||||
|
|
||||||
private static final String TAG_CONFIRM_RESTRICT = "confirmRestrict";
|
private static final String TAG_CONFIRM_RESTRICT = "confirmRestrict";
|
||||||
@@ -133,7 +138,9 @@ public class DataUsageAppDetail extends Fragment {
|
|||||||
private void updateBody() {
|
private void updateBody() {
|
||||||
final PackageManager pm = getActivity().getPackageManager();
|
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));
|
mTitle.setText(pm.getNameForUid(mUid));
|
||||||
|
|
||||||
// enable settings button when package provides it
|
// enable settings button when package provides it
|
||||||
@@ -155,7 +162,7 @@ public class DataUsageAppDetail extends Fragment {
|
|||||||
try {
|
try {
|
||||||
// load stats for current uid and template
|
// load stats for current uid and template
|
||||||
// TODO: read template from extras
|
// TODO: read template from extras
|
||||||
mHistory = mStatsService.getHistoryForUid(mUid, TEMPLATE_MOBILE_ALL);
|
mHistory = mStatsService.getHistoryForUid(mTemplate, mUid);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// since we can't do much without history, and we don't want to
|
// since we can't do much without history, and we don't want to
|
||||||
// leave with half-baked UI, we bail hard.
|
// leave with half-baked UI, we bail hard.
|
||||||
|
@@ -21,10 +21,10 @@ 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.computeLastCycleBoundary;
|
import static android.net.NetworkPolicyManager.computeLastCycleBoundary;
|
||||||
import static android.net.NetworkPolicyManager.computeNextCycleBoundary;
|
import static android.net.NetworkPolicyManager.computeNextCycleBoundary;
|
||||||
import static android.net.TrafficStats.TEMPLATE_MOBILE_3G_LOWER;
|
import static android.net.NetworkTemplate.MATCH_MOBILE_3G_LOWER;
|
||||||
import static android.net.TrafficStats.TEMPLATE_MOBILE_4G;
|
import static android.net.NetworkTemplate.MATCH_MOBILE_4G;
|
||||||
import static android.net.TrafficStats.TEMPLATE_MOBILE_ALL;
|
import static android.net.NetworkTemplate.MATCH_MOBILE_ALL;
|
||||||
import static android.net.TrafficStats.TEMPLATE_WIFI;
|
import static android.net.NetworkTemplate.MATCH_WIFI;
|
||||||
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@@ -44,6 +44,7 @@ import android.net.NetworkPolicy;
|
|||||||
import android.net.NetworkPolicyManager;
|
import android.net.NetworkPolicyManager;
|
||||||
import android.net.NetworkStats;
|
import android.net.NetworkStats;
|
||||||
import android.net.NetworkStatsHistory;
|
import android.net.NetworkStatsHistory;
|
||||||
|
import android.net.NetworkTemplate;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
@@ -82,7 +83,7 @@ import android.widget.TabHost.TabSpec;
|
|||||||
import android.widget.TabWidget;
|
import android.widget.TabWidget;
|
||||||
import android.widget.TextView;
|
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;
|
||||||
import com.android.settings.widget.DataUsageChartView.DataUsageChartListener;
|
import com.android.settings.widget.DataUsageChartView.DataUsageChartListener;
|
||||||
import com.google.android.collect.Lists;
|
import com.google.android.collect.Lists;
|
||||||
@@ -135,9 +136,9 @@ public class DataUsageSummary extends Fragment {
|
|||||||
// TODO: persist show wifi flag
|
// TODO: persist show wifi flag
|
||||||
private boolean mShowWifi = false;
|
private boolean mShowWifi = false;
|
||||||
|
|
||||||
private int mTemplate = TEMPLATE_INVALID;
|
private NetworkTemplate mTemplate = null;
|
||||||
|
|
||||||
private NetworkPolicyModifier mPolicyModifier;
|
private NetworkPolicyEditor mPolicyEditor;
|
||||||
private NetworkStatsHistory mHistory;
|
private NetworkStatsHistory mHistory;
|
||||||
|
|
||||||
private String mIntentTab = null;
|
private String mIntentTab = null;
|
||||||
@@ -151,10 +152,8 @@ public class DataUsageSummary extends Fragment {
|
|||||||
mPolicyService = INetworkPolicyManager.Stub.asInterface(
|
mPolicyService = INetworkPolicyManager.Stub.asInterface(
|
||||||
ServiceManager.getService(Context.NETWORK_POLICY_SERVICE));
|
ServiceManager.getService(Context.NETWORK_POLICY_SERVICE));
|
||||||
|
|
||||||
final Context context = getActivity();
|
mPolicyEditor = new NetworkPolicyEditor(mPolicyService);
|
||||||
final String subscriberId = getActiveSubscriberId(context);
|
mPolicyEditor.read();
|
||||||
mPolicyModifier = new NetworkPolicyModifier(mPolicyService, subscriberId);
|
|
||||||
mPolicyModifier.read();
|
|
||||||
|
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
@@ -237,7 +236,7 @@ public class DataUsageSummary extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onPrepareOptionsMenu(Menu menu) {
|
public void onPrepareOptionsMenu(Menu menu) {
|
||||||
final MenuItem split4g = menu.findItem(R.id.action_split_4g);
|
final MenuItem split4g = menu.findItem(R.id.action_split_4g);
|
||||||
split4g.setChecked(mPolicyModifier.isMobilePolicySplit());
|
split4g.setChecked(isMobilePolicySplit());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -245,8 +244,8 @@ public class DataUsageSummary extends Fragment {
|
|||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_split_4g: {
|
case R.id.action_split_4g: {
|
||||||
final boolean mobileSplit = !item.isChecked();
|
final boolean mobileSplit = !item.isChecked();
|
||||||
mPolicyModifier.setMobilePolicySplit(mobileSplit);
|
setMobilePolicySplit(mobileSplit);
|
||||||
item.setChecked(mPolicyModifier.isMobilePolicySplit());
|
item.setChecked(isMobilePolicySplit());
|
||||||
updateTabs();
|
updateTabs();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -269,12 +268,12 @@ public class DataUsageSummary extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* {@link #mShowWifi}, hiding the tabs entirely when applicable. Selects
|
||||||
* first tab, and kicks off a full rebind of body contents.
|
* first tab, and kicks off a full rebind of body contents.
|
||||||
*/
|
*/
|
||||||
private void updateTabs() {
|
private void updateTabs() {
|
||||||
final boolean mobileSplit = mPolicyModifier.isMobilePolicySplit();
|
final boolean mobileSplit = isMobilePolicySplit();
|
||||||
final boolean tabsVisible = mobileSplit || mShowWifi;
|
final boolean tabsVisible = mobileSplit || mShowWifi;
|
||||||
mTabWidget.setVisibility(tabsVisible ? View.VISIBLE : View.GONE);
|
mTabWidget.setVisibility(tabsVisible ? View.VISIBLE : View.GONE);
|
||||||
mTabHost.clearAllTabs();
|
mTabHost.clearAllTabs();
|
||||||
@@ -344,13 +343,16 @@ public class DataUsageSummary extends Fragment {
|
|||||||
final String tabTag = mTabHost.getCurrentTabTag();
|
final String tabTag = mTabHost.getCurrentTabTag();
|
||||||
final String currentTab = tabTag != null ? tabTag : TAB_MOBILE;
|
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 (LOGD) Log.d(TAG, "updateBody() with currentTab=" + currentTab);
|
||||||
|
|
||||||
if (TAB_WIFI.equals(currentTab)) {
|
if (TAB_WIFI.equals(currentTab)) {
|
||||||
// wifi doesn't have any controls
|
// wifi doesn't have any controls
|
||||||
mDataEnabledView.setVisibility(View.GONE);
|
mDataEnabledView.setVisibility(View.GONE);
|
||||||
mDisableAtLimitView.setVisibility(View.GONE);
|
mDisableAtLimitView.setVisibility(View.GONE);
|
||||||
mTemplate = TEMPLATE_WIFI;
|
mTemplate = new NetworkTemplate(MATCH_WIFI, null);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// make sure we show for non-wifi
|
// make sure we show for non-wifi
|
||||||
@@ -361,17 +363,17 @@ public class DataUsageSummary extends Fragment {
|
|||||||
if (TAB_MOBILE.equals(currentTab)) {
|
if (TAB_MOBILE.equals(currentTab)) {
|
||||||
mDataEnabled.setTitle(R.string.data_usage_enable_mobile);
|
mDataEnabled.setTitle(R.string.data_usage_enable_mobile);
|
||||||
mDisableAtLimit.setTitle(R.string.data_usage_disable_mobile_limit);
|
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)) {
|
} else if (TAB_3G.equals(currentTab)) {
|
||||||
mDataEnabled.setTitle(R.string.data_usage_enable_3g);
|
mDataEnabled.setTitle(R.string.data_usage_enable_3g);
|
||||||
mDisableAtLimit.setTitle(R.string.data_usage_disable_3g_limit);
|
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)) {
|
} else if (TAB_4G.equals(currentTab)) {
|
||||||
mDataEnabled.setTitle(R.string.data_usage_enable_4g);
|
mDataEnabled.setTitle(R.string.data_usage_enable_4g);
|
||||||
mDisableAtLimit.setTitle(R.string.data_usage_disable_4g_limit);
|
mDisableAtLimit.setTitle(R.string.data_usage_disable_4g_limit);
|
||||||
mTemplate = TEMPLATE_MOBILE_4G;
|
mTemplate = new NetworkTemplate(MATCH_MOBILE_4G, subscriberId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,19 +403,19 @@ public class DataUsageSummary extends Fragment {
|
|||||||
|
|
||||||
private void setPolicyCycleDay(int cycleDay) {
|
private void setPolicyCycleDay(int cycleDay) {
|
||||||
if (LOGD) Log.d(TAG, "setPolicyCycleDay()");
|
if (LOGD) Log.d(TAG, "setPolicyCycleDay()");
|
||||||
mPolicyModifier.setPolicyCycleDay(mTemplate, cycleDay);
|
mPolicyEditor.setPolicyCycleDay(mTemplate, cycleDay);
|
||||||
updatePolicy(true);
|
updatePolicy(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPolicyWarningBytes(long warningBytes) {
|
private void setPolicyWarningBytes(long warningBytes) {
|
||||||
if (LOGD) Log.d(TAG, "setPolicyWarningBytes()");
|
if (LOGD) Log.d(TAG, "setPolicyWarningBytes()");
|
||||||
mPolicyModifier.setPolicyWarningBytes(mTemplate, warningBytes);
|
mPolicyEditor.setPolicyWarningBytes(mTemplate, warningBytes);
|
||||||
updatePolicy(false);
|
updatePolicy(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPolicyLimitBytes(long limitBytes) {
|
private void setPolicyLimitBytes(long limitBytes) {
|
||||||
if (LOGD) Log.d(TAG, "setPolicyLimitBytes()");
|
if (LOGD) Log.d(TAG, "setPolicyLimitBytes()");
|
||||||
mPolicyModifier.setPolicyLimitBytes(mTemplate, limitBytes);
|
mPolicyEditor.setPolicyLimitBytes(mTemplate, limitBytes);
|
||||||
updatePolicy(false);
|
updatePolicy(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,7 +424,7 @@ public class DataUsageSummary extends Fragment {
|
|||||||
* current {@link #mTemplate}.
|
* current {@link #mTemplate}.
|
||||||
*/
|
*/
|
||||||
private void updatePolicy(boolean refreshCycle) {
|
private void updatePolicy(boolean refreshCycle) {
|
||||||
final NetworkPolicy policy = mPolicyModifier.getPolicy(mTemplate);
|
final NetworkPolicy policy = mPolicyEditor.getPolicy(mTemplate);
|
||||||
|
|
||||||
// reflect policy limit in checkbox
|
// reflect policy limit in checkbox
|
||||||
mDisableAtLimit.setChecked(policy != null && policy.limitBytes != LIMIT_DISABLED);
|
mDisableAtLimit.setChecked(policy != null && policy.limitBytes != LIMIT_DISABLED);
|
||||||
@@ -542,7 +544,8 @@ public class DataUsageSummary extends Fragment {
|
|||||||
final AppUsageItem app = (AppUsageItem) parent.getItemAtPosition(position);
|
final AppUsageItem app = (AppUsageItem) parent.getItemAtPosition(position);
|
||||||
|
|
||||||
final Bundle args = new Bundle();
|
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();
|
final PreferenceActivity activity = (PreferenceActivity) getActivity();
|
||||||
activity.startPreferencePanel(DataUsageAppDetail.class.getName(), args,
|
activity.startPreferencePanel(DataUsageAppDetail.class.getName(), args,
|
||||||
@@ -595,7 +598,7 @@ public class DataUsageSummary extends Fragment {
|
|||||||
protected NetworkStats doInBackground(Void... params) {
|
protected NetworkStats doInBackground(Void... params) {
|
||||||
try {
|
try {
|
||||||
final long[] range = mChart.getInspectRange();
|
final long[] range = mChart.getInspectRange();
|
||||||
return mStatsService.getSummaryForAllUid(range[0], range[1], mTemplate);
|
return mStatsService.getSummaryForAllUid(mTemplate, range[0], range[1]);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.w(TAG, "problem reading stats");
|
Log.w(TAG, "problem reading stats");
|
||||||
}
|
}
|
||||||
@@ -611,6 +614,16 @@ public class DataUsageSummary extends Fragment {
|
|||||||
}.execute();
|
}.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) {
|
private static String getActiveSubscriberId(Context context) {
|
||||||
final TelephonyManager telephony = (TelephonyManager) context.getSystemService(
|
final TelephonyManager telephony = (TelephonyManager) context.getSystemService(
|
||||||
Context.TELEPHONY_SERVICE);
|
Context.TELEPHONY_SERVICE);
|
||||||
@@ -772,18 +785,18 @@ public class DataUsageSummary extends Fragment {
|
|||||||
final Bundle args = new Bundle();
|
final Bundle args = new Bundle();
|
||||||
|
|
||||||
// TODO: customize default limits based on network template
|
// TODO: customize default limits based on network template
|
||||||
switch (parent.mTemplate) {
|
switch (parent.mTemplate.getMatchRule()) {
|
||||||
case TEMPLATE_MOBILE_3G_LOWER: {
|
case MATCH_MOBILE_3G_LOWER: {
|
||||||
args.putInt(EXTRA_MESSAGE_ID, R.string.data_usage_limit_dialog_3g);
|
args.putInt(EXTRA_MESSAGE_ID, R.string.data_usage_limit_dialog_3g);
|
||||||
args.putLong(EXTRA_LIMIT_BYTES, 5 * GB_IN_BYTES);
|
args.putLong(EXTRA_LIMIT_BYTES, 5 * GB_IN_BYTES);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TEMPLATE_MOBILE_4G: {
|
case MATCH_MOBILE_4G: {
|
||||||
args.putInt(EXTRA_MESSAGE_ID, R.string.data_usage_limit_dialog_4g);
|
args.putInt(EXTRA_MESSAGE_ID, R.string.data_usage_limit_dialog_4g);
|
||||||
args.putLong(EXTRA_LIMIT_BYTES, 5 * GB_IN_BYTES);
|
args.putLong(EXTRA_LIMIT_BYTES, 5 * GB_IN_BYTES);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TEMPLATE_MOBILE_ALL: {
|
case MATCH_MOBILE_ALL: {
|
||||||
args.putInt(EXTRA_MESSAGE_ID, R.string.data_usage_limit_dialog_mobile);
|
args.putInt(EXTRA_MESSAGE_ID, R.string.data_usage_limit_dialog_mobile);
|
||||||
args.putLong(EXTRA_LIMIT_BYTES, 5 * GB_IN_BYTES);
|
args.putLong(EXTRA_LIMIT_BYTES, 5 * GB_IN_BYTES);
|
||||||
break;
|
break;
|
||||||
@@ -827,7 +840,7 @@ public class DataUsageSummary extends Fragment {
|
|||||||
public static final String EXTRA_CYCLE_DAY = "cycleDay";
|
public static final String EXTRA_CYCLE_DAY = "cycleDay";
|
||||||
|
|
||||||
public static void show(DataUsageSummary parent) {
|
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();
|
final Bundle args = new Bundle();
|
||||||
args.putInt(CycleEditorFragment.EXTRA_CYCLE_DAY, policy.cycleDay);
|
args.putInt(CycleEditorFragment.EXTRA_CYCLE_DAY, policy.cycleDay);
|
||||||
|
|
||||||
@@ -882,16 +895,16 @@ public class DataUsageSummary extends Fragment {
|
|||||||
public static void show(DataUsageSummary parent) {
|
public static void show(DataUsageSummary parent) {
|
||||||
final Bundle args = new Bundle();
|
final Bundle args = new Bundle();
|
||||||
|
|
||||||
switch (parent.mTemplate) {
|
switch (parent.mTemplate.getMatchRule()) {
|
||||||
case TEMPLATE_MOBILE_3G_LOWER: {
|
case MATCH_MOBILE_3G_LOWER: {
|
||||||
args.putInt(EXTRA_TITLE_ID, R.string.data_usage_disabled_dialog_3g_title);
|
args.putInt(EXTRA_TITLE_ID, R.string.data_usage_disabled_dialog_3g_title);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TEMPLATE_MOBILE_4G: {
|
case MATCH_MOBILE_4G: {
|
||||||
args.putInt(EXTRA_TITLE_ID, R.string.data_usage_disabled_dialog_4g_title);
|
args.putInt(EXTRA_TITLE_ID, R.string.data_usage_disabled_dialog_4g_title);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TEMPLATE_MOBILE_ALL: {
|
case MATCH_MOBILE_ALL: {
|
||||||
args.putInt(EXTRA_TITLE_ID, R.string.data_usage_disabled_dialog_mobile_title);
|
args.putInt(EXTRA_TITLE_ID, R.string.data_usage_disabled_dialog_mobile_title);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -937,13 +950,13 @@ public class DataUsageSummary extends Fragment {
|
|||||||
private static String computeTabFromIntent(Intent intent) {
|
private static String computeTabFromIntent(Intent intent) {
|
||||||
final int networkTemplate = intent.getIntExtra(EXTRA_NETWORK_TEMPLATE, TEMPLATE_INVALID);
|
final int networkTemplate = intent.getIntExtra(EXTRA_NETWORK_TEMPLATE, TEMPLATE_INVALID);
|
||||||
switch (networkTemplate) {
|
switch (networkTemplate) {
|
||||||
case TEMPLATE_MOBILE_3G_LOWER:
|
case MATCH_MOBILE_3G_LOWER:
|
||||||
return TAB_3G;
|
return TAB_3G;
|
||||||
case TEMPLATE_MOBILE_4G:
|
case MATCH_MOBILE_4G:
|
||||||
return TAB_4G;
|
return TAB_4G;
|
||||||
case TEMPLATE_MOBILE_ALL:
|
case MATCH_MOBILE_ALL:
|
||||||
return TAB_MOBILE;
|
return TAB_MOBILE;
|
||||||
case TEMPLATE_WIFI:
|
case MATCH_WIFI:
|
||||||
return TAB_WIFI;
|
return TAB_WIFI;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
|
@@ -16,13 +16,14 @@
|
|||||||
|
|
||||||
package com.android.settings.net;
|
package com.android.settings.net;
|
||||||
|
|
||||||
import static android.net.TrafficStats.TEMPLATE_MOBILE_3G_LOWER;
|
import static android.net.NetworkTemplate.MATCH_MOBILE_3G_LOWER;
|
||||||
import static android.net.TrafficStats.TEMPLATE_MOBILE_4G;
|
import static android.net.NetworkTemplate.MATCH_MOBILE_4G;
|
||||||
import static android.net.TrafficStats.TEMPLATE_MOBILE_ALL;
|
import static android.net.NetworkTemplate.MATCH_MOBILE_ALL;
|
||||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import android.net.INetworkPolicyManager;
|
import android.net.INetworkPolicyManager;
|
||||||
import android.net.NetworkPolicy;
|
import android.net.NetworkPolicy;
|
||||||
|
import android.net.NetworkTemplate;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
|
||||||
@@ -35,18 +36,14 @@ import java.util.ArrayList;
|
|||||||
* Utility class to modify list of {@link NetworkPolicy}. Specifically knows
|
* Utility class to modify list of {@link NetworkPolicy}. Specifically knows
|
||||||
* about which policies can coexist.
|
* about which policies can coexist.
|
||||||
*/
|
*/
|
||||||
public class NetworkPolicyModifier {
|
public class NetworkPolicyEditor {
|
||||||
// TODO: refactor to "Editor"
|
|
||||||
// TODO: be more robust when missing policies from service
|
// TODO: be more robust when missing policies from service
|
||||||
|
|
||||||
private INetworkPolicyManager mPolicyService;
|
private INetworkPolicyManager mPolicyService;
|
||||||
private String mSubscriberId;
|
|
||||||
|
|
||||||
private ArrayList<NetworkPolicy> mPolicies = Lists.newArrayList();
|
private ArrayList<NetworkPolicy> mPolicies = Lists.newArrayList();
|
||||||
|
|
||||||
public NetworkPolicyModifier(INetworkPolicyManager policyService, String subscriberId) {
|
public NetworkPolicyEditor(INetworkPolicyManager policyService) {
|
||||||
mPolicyService = checkNotNull(policyService);
|
mPolicyService = checkNotNull(policyService);
|
||||||
mSubscriberId = subscriberId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read() {
|
public void read() {
|
||||||
@@ -81,64 +78,82 @@ public class NetworkPolicyModifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkPolicy getPolicy(int networkTemplate) {
|
public NetworkPolicy getPolicy(NetworkTemplate template) {
|
||||||
for (NetworkPolicy policy : mPolicies) {
|
for (NetworkPolicy policy : mPolicies) {
|
||||||
if (policy.networkTemplate == networkTemplate
|
if (policy.template.equals(template)) {
|
||||||
&& Objects.equal(policy.subscriberId, mSubscriberId)) {
|
|
||||||
return policy;
|
return policy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPolicyCycleDay(int networkTemplate, int cycleDay) {
|
public void setPolicyCycleDay(NetworkTemplate template, int cycleDay) {
|
||||||
getPolicy(networkTemplate).cycleDay = cycleDay;
|
getPolicy(template).cycleDay = cycleDay;
|
||||||
writeAsync();
|
writeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPolicyWarningBytes(int networkTemplate, long warningBytes) {
|
public void setPolicyWarningBytes(NetworkTemplate template, long warningBytes) {
|
||||||
getPolicy(networkTemplate).warningBytes = warningBytes;
|
getPolicy(template).warningBytes = warningBytes;
|
||||||
writeAsync();
|
writeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPolicyLimitBytes(int networkTemplate, long limitBytes) {
|
public void setPolicyLimitBytes(NetworkTemplate template, long limitBytes) {
|
||||||
getPolicy(networkTemplate).limitBytes = limitBytes;
|
getPolicy(template).limitBytes = limitBytes;
|
||||||
writeAsync();
|
writeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMobilePolicySplit() {
|
public boolean isMobilePolicySplit(String subscriberId) {
|
||||||
return getPolicy(TEMPLATE_MOBILE_3G_LOWER) != null && getPolicy(TEMPLATE_MOBILE_4G) != null;
|
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(boolean split) {
|
public void setMobilePolicySplit(String subscriberId, boolean split) {
|
||||||
final boolean beforeSplit = isMobilePolicySplit();
|
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) {
|
if (split == beforeSplit) {
|
||||||
// already in requested state; skip
|
// already in requested state; skip
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} else if (beforeSplit && !split) {
|
} else if (beforeSplit && !split) {
|
||||||
// combine, picking most restrictive policy
|
// combine, picking most restrictive policy
|
||||||
final NetworkPolicy policy3g = getPolicy(TEMPLATE_MOBILE_3G_LOWER);
|
final NetworkPolicy policy3g = getPolicy(template3g);
|
||||||
final NetworkPolicy policy4g = getPolicy(TEMPLATE_MOBILE_4G);
|
final NetworkPolicy policy4g = getPolicy(template4g);
|
||||||
|
|
||||||
final NetworkPolicy restrictive = policy3g.compareTo(policy4g) < 0 ? policy3g
|
final NetworkPolicy restrictive = policy3g.compareTo(policy4g) < 0 ? policy3g
|
||||||
: policy4g;
|
: policy4g;
|
||||||
mPolicies.remove(policy3g);
|
mPolicies.remove(policy3g);
|
||||||
mPolicies.remove(policy4g);
|
mPolicies.remove(policy4g);
|
||||||
mPolicies.add(new NetworkPolicy(TEMPLATE_MOBILE_ALL, restrictive.subscriberId,
|
mPolicies.add(
|
||||||
restrictive.cycleDay, restrictive.warningBytes, restrictive.limitBytes));
|
new NetworkPolicy(templateAll, restrictive.cycleDay, restrictive.warningBytes,
|
||||||
|
restrictive.limitBytes));
|
||||||
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(TEMPLATE_MOBILE_ALL);
|
final NetworkPolicy policyAll = getPolicy(templateAll);
|
||||||
mPolicies.remove(policyAll);
|
mPolicies.remove(policyAll);
|
||||||
mPolicies.add(
|
mPolicies.add(new NetworkPolicy(
|
||||||
new NetworkPolicy(TEMPLATE_MOBILE_3G_LOWER, policyAll.subscriberId,
|
template3g, policyAll.cycleDay, policyAll.warningBytes, policyAll.limitBytes));
|
||||||
policyAll.cycleDay, policyAll.warningBytes, policyAll.limitBytes));
|
mPolicies.add(new NetworkPolicy(
|
||||||
mPolicies.add(
|
template4g, policyAll.cycleDay, policyAll.warningBytes, policyAll.limitBytes));
|
||||||
new NetworkPolicy(TEMPLATE_MOBILE_4G, policyAll.subscriberId,
|
|
||||||
policyAll.cycleDay, policyAll.warningBytes, policyAll.limitBytes));
|
|
||||||
writeAsync();
|
writeAsync();
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user