[SM07] Make combine subtype configurable from Settings am: 1e30781571 am: 28255c9992
Change-Id: I138ae4305d68b78323c2af9bfc081f42e661cdd9
This commit is contained in:
@@ -40,13 +40,6 @@ import java.util.Objects;
|
||||
public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
private static final String TAG = "NetworkIdentity";
|
||||
|
||||
/**
|
||||
* When enabled, combine all {@link #mSubType} together under
|
||||
* {@link #SUBTYPE_COMBINED}.
|
||||
*/
|
||||
// TODO: make this flag configurable through settings. See http://b/146415925
|
||||
public static final boolean COMBINE_SUBTYPE_ENABLED = false;
|
||||
|
||||
public static final int SUBTYPE_COMBINED = -1;
|
||||
|
||||
final int mType;
|
||||
@@ -61,7 +54,7 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
int type, int subType, String subscriberId, String networkId, boolean roaming,
|
||||
boolean metered, boolean defaultNetwork) {
|
||||
mType = type;
|
||||
mSubType = COMBINE_SUBTYPE_ENABLED ? SUBTYPE_COMBINED : subType;
|
||||
mSubType = subType;
|
||||
mSubscriberId = subscriberId;
|
||||
mNetworkId = networkId;
|
||||
mRoaming = roaming;
|
||||
@@ -93,7 +86,7 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
final StringBuilder builder = new StringBuilder("{");
|
||||
builder.append("type=").append(getNetworkTypeName(mType));
|
||||
builder.append(", subType=");
|
||||
if (COMBINE_SUBTYPE_ENABLED) {
|
||||
if (mSubType == SUBTYPE_COMBINED) {
|
||||
builder.append("COMBINED");
|
||||
} else {
|
||||
builder.append(mSubType);
|
||||
|
||||
@@ -27,7 +27,6 @@ import static android.content.Intent.EXTRA_UID;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
import static android.net.ConnectivityManager.ACTION_TETHER_STATE_CHANGED;
|
||||
import static android.net.ConnectivityManager.isNetworkTypeMobile;
|
||||
import static android.net.NetworkIdentity.COMBINE_SUBTYPE_ENABLED;
|
||||
import static android.net.NetworkIdentity.SUBTYPE_COMBINED;
|
||||
import static android.net.NetworkStack.checkNetworkStackPermission;
|
||||
import static android.net.NetworkStats.DEFAULT_NETWORK_ALL;
|
||||
@@ -52,6 +51,7 @@ import static android.net.TrafficStats.KB_IN_BYTES;
|
||||
import static android.net.TrafficStats.MB_IN_BYTES;
|
||||
import static android.os.Trace.TRACE_TAG_NETWORK;
|
||||
import static android.provider.Settings.Global.NETSTATS_AUGMENT_ENABLED;
|
||||
import static android.provider.Settings.Global.NETSTATS_COMBINE_SUBTYPE_ENABLED;
|
||||
import static android.provider.Settings.Global.NETSTATS_DEV_BUCKET_DURATION;
|
||||
import static android.provider.Settings.Global.NETSTATS_DEV_DELETE_AGE;
|
||||
import static android.provider.Settings.Global.NETSTATS_DEV_PERSIST_BYTES;
|
||||
@@ -240,12 +240,20 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
* Settings that can be changed externally.
|
||||
*/
|
||||
public interface NetworkStatsSettings {
|
||||
public long getPollInterval();
|
||||
public long getPollDelay();
|
||||
public boolean getSampleEnabled();
|
||||
public boolean getAugmentEnabled();
|
||||
long getPollInterval();
|
||||
long getPollDelay();
|
||||
boolean getSampleEnabled();
|
||||
boolean getAugmentEnabled();
|
||||
/**
|
||||
* When enabled, all mobile data is reported under {@link NetworkIdentity#SUBTYPE_COMBINED}.
|
||||
* When disabled, mobile data is broken down by a granular subtype representative of the
|
||||
* actual subtype. {@see NetworkTemplate#getCollapsedRatType}.
|
||||
* Enabling this decreases the level of detail but saves performance, disk space and
|
||||
* amount of data logged.
|
||||
*/
|
||||
boolean getCombineSubtypeEnabled();
|
||||
|
||||
public static class Config {
|
||||
class Config {
|
||||
public final long bucketDuration;
|
||||
public final long rotateAgeMillis;
|
||||
public final long deleteAgeMillis;
|
||||
@@ -257,16 +265,16 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
public Config getDevConfig();
|
||||
public Config getXtConfig();
|
||||
public Config getUidConfig();
|
||||
public Config getUidTagConfig();
|
||||
Config getDevConfig();
|
||||
Config getXtConfig();
|
||||
Config getUidConfig();
|
||||
Config getUidTagConfig();
|
||||
|
||||
public long getGlobalAlertBytes(long def);
|
||||
public long getDevPersistBytes(long def);
|
||||
public long getXtPersistBytes(long def);
|
||||
public long getUidPersistBytes(long def);
|
||||
public long getUidTagPersistBytes(long def);
|
||||
long getGlobalAlertBytes(long def);
|
||||
long getDevPersistBytes(long def);
|
||||
long getXtPersistBytes(long def);
|
||||
long getUidPersistBytes(long def);
|
||||
long getUidTagPersistBytes(long def);
|
||||
}
|
||||
|
||||
private final Object mStatsLock = new Object();
|
||||
@@ -509,9 +517,10 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
mAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, currentRealtime,
|
||||
mSettings.getPollInterval(), pollIntent);
|
||||
|
||||
// TODO: listen to changes from all subscriptions.
|
||||
// TODO: 1. listen to changes from all subscriptions.
|
||||
// 2. listen to settings changed to support dynamically enable/disable.
|
||||
// watch for networkType changes
|
||||
if (!COMBINE_SUBTYPE_ENABLED) {
|
||||
if (!mSettings.getCombineSubtypeEnabled()) {
|
||||
mTeleManager.listen(mPhoneListener, LISTEN_SERVICE_STATE);
|
||||
}
|
||||
|
||||
@@ -535,9 +544,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
mContext.unregisterReceiver(mUserReceiver);
|
||||
mContext.unregisterReceiver(mShutdownReceiver);
|
||||
|
||||
if (!COMBINE_SUBTYPE_ENABLED) {
|
||||
mTeleManager.listen(mPhoneListener, LISTEN_NONE);
|
||||
}
|
||||
|
||||
final long currentTime = mClock.millis();
|
||||
|
||||
@@ -1265,12 +1272,14 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
|
||||
mLastNetworkStates = states;
|
||||
|
||||
final boolean combineSubtypeEnabled = mSettings.getCombineSubtypeEnabled();
|
||||
final ArraySet<String> mobileIfaces = new ArraySet<>();
|
||||
for (NetworkState state : states) {
|
||||
if (state.networkInfo.isConnected()) {
|
||||
final boolean isMobile = isNetworkTypeMobile(state.networkInfo.getType());
|
||||
final boolean isDefault = ArrayUtils.contains(mDefaultNetworks, state.network);
|
||||
final int subType = getSubTypeForState(state);
|
||||
final int subType = combineSubtypeEnabled ? SUBTYPE_COMBINED
|
||||
: getSubTypeForState(state);
|
||||
final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state,
|
||||
isDefault, subType);
|
||||
|
||||
@@ -1334,13 +1343,11 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
}
|
||||
|
||||
/**
|
||||
* If combine subtype is not enabled. For networks with {@code TRANSPORT_CELLULAR}, get
|
||||
* subType that obtained through {@link PhoneStateListener}. Otherwise, return 0 given that
|
||||
* other networks with different transport types do not actually fill this value.
|
||||
* For networks with {@code TRANSPORT_CELLULAR}, get subType that was obtained through
|
||||
* {@link PhoneStateListener}. Otherwise, return 0 given that other networks with different
|
||||
* transport types do not actually fill this value.
|
||||
*/
|
||||
private int getSubTypeForState(@NonNull NetworkState state) {
|
||||
if (COMBINE_SUBTYPE_ENABLED) return SUBTYPE_COMBINED;
|
||||
|
||||
if (!state.networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -1702,6 +1709,12 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
return;
|
||||
}
|
||||
|
||||
pw.println("Configs:");
|
||||
pw.increaseIndent();
|
||||
pw.printPair(NETSTATS_COMBINE_SUBTYPE_ENABLED, mSettings.getCombineSubtypeEnabled());
|
||||
pw.println();
|
||||
pw.decreaseIndent();
|
||||
|
||||
pw.println("Active interfaces:");
|
||||
pw.increaseIndent();
|
||||
for (int i = 0; i < mActiveIfaces.size(); i++) {
|
||||
@@ -2130,6 +2143,10 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
return getGlobalBoolean(NETSTATS_AUGMENT_ENABLED, true);
|
||||
}
|
||||
@Override
|
||||
public boolean getCombineSubtypeEnabled() {
|
||||
return getGlobalBoolean(NETSTATS_COMBINE_SUBTYPE_ENABLED, false);
|
||||
}
|
||||
@Override
|
||||
public Config getDevConfig() {
|
||||
return new Config(getGlobalLong(NETSTATS_DEV_BUCKET_DURATION, HOUR_IN_MILLIS),
|
||||
getGlobalLong(NETSTATS_DEV_ROTATE_AGE, 15 * DAY_IN_MILLIS),
|
||||
|
||||
Reference in New Issue
Block a user