Loading core/java/android/net/NetworkIdentity.java +2 −9 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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); Loading core/java/android/provider/Settings.java +2 −0 Original line number Diff line number Diff line Loading @@ -9718,6 +9718,8 @@ public final class Settings { public static final String NETSTATS_SAMPLE_ENABLED = "netstats_sample_enabled"; /** {@hide} */ public static final String NETSTATS_AUGMENT_ENABLED = "netstats_augment_enabled"; /** {@hide} */ public static final String NETSTATS_COMBINE_SUBTYPE_ENABLED = "netstats_combine_subtype_enabled"; /** {@hide} */ public static final String NETSTATS_DEV_BUCKET_DURATION = "netstats_dev_bucket_duration"; Loading packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -355,6 +355,7 @@ public class SettingsBackupTest { Settings.Global.NETSTATS_POLL_INTERVAL, Settings.Global.NETSTATS_SAMPLE_ENABLED, Settings.Global.NETSTATS_AUGMENT_ENABLED, Settings.Global.NETSTATS_COMBINE_SUBTYPE_ENABLED, Settings.Global.NETSTATS_TIME_CACHE_MAX_AGE, Settings.Global.NETSTATS_UID_BUCKET_DURATION, Settings.Global.NETSTATS_UID_DELETE_AGE, Loading services/core/java/com/android/server/net/NetworkStatsService.java +43 −26 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading @@ -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(); Loading Loading @@ -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); } Loading @@ -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(); Loading Loading @@ -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); Loading Loading @@ -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; } Loading Loading @@ -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++) { Loading Loading @@ -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), Loading tests/net/java/com/android/server/net/NetworkStatsServiceTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -1294,6 +1294,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest { when(mSettings.getPollInterval()).thenReturn(HOUR_IN_MILLIS); when(mSettings.getPollDelay()).thenReturn(0L); when(mSettings.getSampleEnabled()).thenReturn(true); when(mSettings.getCombineSubtypeEnabled()).thenReturn(false); final Config config = new Config(bucketDuration, deleteAge, deleteAge); when(mSettings.getDevConfig()).thenReturn(config); Loading Loading
core/java/android/net/NetworkIdentity.java +2 −9 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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); Loading
core/java/android/provider/Settings.java +2 −0 Original line number Diff line number Diff line Loading @@ -9718,6 +9718,8 @@ public final class Settings { public static final String NETSTATS_SAMPLE_ENABLED = "netstats_sample_enabled"; /** {@hide} */ public static final String NETSTATS_AUGMENT_ENABLED = "netstats_augment_enabled"; /** {@hide} */ public static final String NETSTATS_COMBINE_SUBTYPE_ENABLED = "netstats_combine_subtype_enabled"; /** {@hide} */ public static final String NETSTATS_DEV_BUCKET_DURATION = "netstats_dev_bucket_duration"; Loading
packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -355,6 +355,7 @@ public class SettingsBackupTest { Settings.Global.NETSTATS_POLL_INTERVAL, Settings.Global.NETSTATS_SAMPLE_ENABLED, Settings.Global.NETSTATS_AUGMENT_ENABLED, Settings.Global.NETSTATS_COMBINE_SUBTYPE_ENABLED, Settings.Global.NETSTATS_TIME_CACHE_MAX_AGE, Settings.Global.NETSTATS_UID_BUCKET_DURATION, Settings.Global.NETSTATS_UID_DELETE_AGE, Loading
services/core/java/com/android/server/net/NetworkStatsService.java +43 −26 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading @@ -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(); Loading Loading @@ -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); } Loading @@ -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(); Loading Loading @@ -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); Loading Loading @@ -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; } Loading Loading @@ -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++) { Loading Loading @@ -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), Loading
tests/net/java/com/android/server/net/NetworkStatsServiceTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -1294,6 +1294,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest { when(mSettings.getPollInterval()).thenReturn(HOUR_IN_MILLIS); when(mSettings.getPollDelay()).thenReturn(0L); when(mSettings.getSampleEnabled()).thenReturn(true); when(mSettings.getCombineSubtypeEnabled()).thenReturn(false); final Config config = new Config(bucketDuration, deleteAge, deleteAge); when(mSettings.getDevConfig()).thenReturn(config); Loading