Data usage disabled state, smaller parcels.
Hide policy controls when low-level bandwidth controls are disabled or when radio is disabled. Only request byte counters from history to reduce parcel size by about 60%. Bug: 5096903, 5096752 Change-Id: I407b7a01bf60b7105994052cc6e3262054f51184
This commit is contained in:
@@ -25,6 +25,9 @@ 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.NetworkPolicyManager.computeLastCycleBoundary;
|
import static android.net.NetworkPolicyManager.computeLastCycleBoundary;
|
||||||
import static android.net.NetworkPolicyManager.computeNextCycleBoundary;
|
import static android.net.NetworkPolicyManager.computeNextCycleBoundary;
|
||||||
|
import static android.net.NetworkStats.TAG_NONE;
|
||||||
|
import static android.net.NetworkStatsHistory.FIELD_RX_BYTES;
|
||||||
|
import static android.net.NetworkStatsHistory.FIELD_TX_BYTES;
|
||||||
import static android.net.NetworkTemplate.MATCH_MOBILE_3G_LOWER;
|
import static android.net.NetworkTemplate.MATCH_MOBILE_3G_LOWER;
|
||||||
import static android.net.NetworkTemplate.MATCH_MOBILE_4G;
|
import static android.net.NetworkTemplate.MATCH_MOBILE_4G;
|
||||||
import static android.net.NetworkTemplate.MATCH_MOBILE_ALL;
|
import static android.net.NetworkTemplate.MATCH_MOBILE_ALL;
|
||||||
@@ -65,6 +68,7 @@ import android.net.NetworkTemplate;
|
|||||||
import android.net.TrafficStats;
|
import android.net.TrafficStats;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.INetworkManagementService;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
@@ -151,6 +155,7 @@ public class DataUsageSummary extends Fragment {
|
|||||||
private static final long MB_IN_BYTES = KB_IN_BYTES * 1024;
|
private static final long MB_IN_BYTES = KB_IN_BYTES * 1024;
|
||||||
private static final long GB_IN_BYTES = MB_IN_BYTES * 1024;
|
private static final long GB_IN_BYTES = MB_IN_BYTES * 1024;
|
||||||
|
|
||||||
|
private INetworkManagementService mNetworkService;
|
||||||
private INetworkStatsService mStatsService;
|
private INetworkStatsService mStatsService;
|
||||||
private INetworkPolicyManager mPolicyService;
|
private INetworkPolicyManager mPolicyService;
|
||||||
private ConnectivityManager mConnService;
|
private ConnectivityManager mConnService;
|
||||||
@@ -221,6 +226,8 @@ public class DataUsageSummary extends Fragment {
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
mNetworkService = INetworkManagementService.Stub.asInterface(
|
||||||
|
ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
|
||||||
mStatsService = INetworkStatsService.Stub.asInterface(
|
mStatsService = INetworkStatsService.Stub.asInterface(
|
||||||
ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
|
ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
|
||||||
mPolicyService = INetworkPolicyManager.Stub.asInterface(
|
mPolicyService = INetworkPolicyManager.Stub.asInterface(
|
||||||
@@ -606,7 +613,8 @@ public class DataUsageSummary extends Fragment {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// load stats for current template
|
// load stats for current template
|
||||||
mHistory = mStatsService.getHistoryForNetwork(mTemplate);
|
mHistory = mStatsService.getHistoryForNetwork(
|
||||||
|
mTemplate, FIELD_RX_BYTES | FIELD_TX_BYTES);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// since we can't do much without policy or history, and we don't
|
// since we can't do much without policy or history, and we don't
|
||||||
// want to leave with half-baked UI, we bail hard.
|
// want to leave with half-baked UI, we bail hard.
|
||||||
@@ -672,7 +680,8 @@ public class DataUsageSummary 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
|
||||||
mDetailHistory = mStatsService.getHistoryForUid(mTemplate, mUid, NetworkStats.TAG_NONE);
|
mDetailHistory = mStatsService.getHistoryForUid(
|
||||||
|
mTemplate, mUid, TAG_NONE, FIELD_RX_BYTES | FIELD_TX_BYTES);
|
||||||
} 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.
|
||||||
@@ -685,7 +694,8 @@ public class DataUsageSummary extends Fragment {
|
|||||||
updateDetailData();
|
updateDetailData();
|
||||||
|
|
||||||
final Context context = getActivity();
|
final Context context = getActivity();
|
||||||
if (NetworkPolicyManager.isUidValidForPolicy(context, mUid) && !getRestrictBackground()) {
|
if (NetworkPolicyManager.isUidValidForPolicy(context, mUid) && !getRestrictBackground()
|
||||||
|
&& isBandwidthControlEnabled()) {
|
||||||
mAppRestrictView.setVisibility(View.VISIBLE);
|
mAppRestrictView.setVisibility(View.VISIBLE);
|
||||||
mAppRestrict.setChecked(getAppRestrictBackground());
|
mAppRestrict.setChecked(getAppRestrictBackground());
|
||||||
|
|
||||||
@@ -713,6 +723,19 @@ public class DataUsageSummary extends Fragment {
|
|||||||
updatePolicy(false);
|
updatePolicy(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isNetworkPolicyModifiable() {
|
||||||
|
return isBandwidthControlEnabled() && mDataEnabled.isChecked();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBandwidthControlEnabled() {
|
||||||
|
try {
|
||||||
|
return mNetworkService.isBandwidthControlEnabled();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.w(TAG, "problem talking with INetworkManagementService: " + e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean getDataRoaming() {
|
private boolean getDataRoaming() {
|
||||||
final ContentResolver resolver = getActivity().getContentResolver();
|
final ContentResolver resolver = getActivity().getContentResolver();
|
||||||
return Settings.Secure.getInt(resolver, Settings.Secure.DATA_ROAMING, 0) != 0;
|
return Settings.Secure.getInt(resolver, Settings.Secure.DATA_ROAMING, 0) != 0;
|
||||||
@@ -788,11 +811,17 @@ public class DataUsageSummary extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final NetworkPolicy policy = mPolicyEditor.getPolicy(mTemplate);
|
final NetworkPolicy policy = mPolicyEditor.getPolicy(mTemplate);
|
||||||
|
if (isNetworkPolicyModifiable()) {
|
||||||
// reflect policy limit in checkbox
|
mDisableAtLimitView.setVisibility(View.VISIBLE);
|
||||||
mDisableAtLimit.setChecked(policy != null && policy.limitBytes != LIMIT_DISABLED);
|
mDisableAtLimit.setChecked(policy != null && policy.limitBytes != LIMIT_DISABLED);
|
||||||
mChart.bindNetworkPolicy(policy);
|
mChart.bindNetworkPolicy(policy);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// controls are disabled; don't bind warning/limit sweeps
|
||||||
|
mDisableAtLimitView.setVisibility(View.GONE);
|
||||||
|
mChart.bindNetworkPolicy(null);
|
||||||
|
}
|
||||||
|
|
||||||
if (refreshCycle) {
|
if (refreshCycle) {
|
||||||
// generate cycle list based on policy and available history
|
// generate cycle list based on policy and available history
|
||||||
updateCycleList(policy);
|
updateCycleList(policy);
|
||||||
@@ -840,7 +869,7 @@ public class DataUsageSummary extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// one last cycle entry to modify policy cycle day
|
// one last cycle entry to modify policy cycle day
|
||||||
mCycleAdapter.setChangePossible(true);
|
mCycleAdapter.setChangePossible(isNetworkPolicyModifiable());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasCycles) {
|
if (!hasCycles) {
|
||||||
@@ -867,6 +896,9 @@ public class DataUsageSummary extends Fragment {
|
|||||||
if (TAB_MOBILE.equals(currentTab)) {
|
if (TAB_MOBILE.equals(currentTab)) {
|
||||||
mConnService.setMobileDataEnabled(dataEnabled);
|
mConnService.setMobileDataEnabled(dataEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// rebind policy to match radio state
|
||||||
|
updatePolicy(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user