Merge "[DU05]Remove the android.provider.Settings.Global in NetworkStatsService"
This commit is contained in:
@@ -47,23 +47,6 @@ import static android.net.TrafficStats.MB_IN_BYTES;
|
|||||||
import static android.net.TrafficStats.UID_TETHERING;
|
import static android.net.TrafficStats.UID_TETHERING;
|
||||||
import static android.net.TrafficStats.UNSUPPORTED;
|
import static android.net.TrafficStats.UNSUPPORTED;
|
||||||
import static android.os.Trace.TRACE_TAG_NETWORK;
|
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;
|
|
||||||
import static android.provider.Settings.Global.NETSTATS_DEV_ROTATE_AGE;
|
|
||||||
import static android.provider.Settings.Global.NETSTATS_GLOBAL_ALERT_BYTES;
|
|
||||||
import static android.provider.Settings.Global.NETSTATS_POLL_INTERVAL;
|
|
||||||
import static android.provider.Settings.Global.NETSTATS_SAMPLE_ENABLED;
|
|
||||||
import static android.provider.Settings.Global.NETSTATS_UID_BUCKET_DURATION;
|
|
||||||
import static android.provider.Settings.Global.NETSTATS_UID_DELETE_AGE;
|
|
||||||
import static android.provider.Settings.Global.NETSTATS_UID_PERSIST_BYTES;
|
|
||||||
import static android.provider.Settings.Global.NETSTATS_UID_ROTATE_AGE;
|
|
||||||
import static android.provider.Settings.Global.NETSTATS_UID_TAG_BUCKET_DURATION;
|
|
||||||
import static android.provider.Settings.Global.NETSTATS_UID_TAG_DELETE_AGE;
|
|
||||||
import static android.provider.Settings.Global.NETSTATS_UID_TAG_PERSIST_BYTES;
|
|
||||||
import static android.provider.Settings.Global.NETSTATS_UID_TAG_ROTATE_AGE;
|
|
||||||
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
import static android.text.format.DateUtils.DAY_IN_MILLIS;
|
import static android.text.format.DateUtils.DAY_IN_MILLIS;
|
||||||
import static android.text.format.DateUtils.HOUR_IN_MILLIS;
|
import static android.text.format.DateUtils.HOUR_IN_MILLIS;
|
||||||
@@ -217,6 +200,10 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
private static final int LOG_TAG_NETSTATS_MOBILE_SAMPLE = 51100;
|
private static final int LOG_TAG_NETSTATS_MOBILE_SAMPLE = 51100;
|
||||||
private static final int LOG_TAG_NETSTATS_WIFI_SAMPLE = 51101;
|
private static final int LOG_TAG_NETSTATS_WIFI_SAMPLE = 51101;
|
||||||
|
|
||||||
|
// TODO: Replace the hardcoded string and move it into ConnectivitySettingsManager.
|
||||||
|
private static final String NETSTATS_COMBINE_SUBTYPE_ENABLED =
|
||||||
|
"netstats_combine_subtype_enabled";
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final NetworkStatsFactory mStatsFactory;
|
private final NetworkStatsFactory mStatsFactory;
|
||||||
private final AlarmManager mAlarmManager;
|
private final AlarmManager mAlarmManager;
|
||||||
@@ -431,7 +418,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
final NetworkStatsService service = new NetworkStatsService(context,
|
final NetworkStatsService service = new NetworkStatsService(context,
|
||||||
INetd.Stub.asInterface((IBinder) context.getSystemService(Context.NETD_SERVICE)),
|
INetd.Stub.asInterface((IBinder) context.getSystemService(Context.NETD_SERVICE)),
|
||||||
alarmManager, wakeLock, getDefaultClock(),
|
alarmManager, wakeLock, getDefaultClock(),
|
||||||
new DefaultNetworkStatsSettings(context), new NetworkStatsFactory(netd),
|
new DefaultNetworkStatsSettings(), new NetworkStatsFactory(netd),
|
||||||
new NetworkStatsObservers(), getDefaultSystemDir(), getDefaultBaseDir(),
|
new NetworkStatsObservers(), getDefaultSystemDir(), getDefaultBaseDir(),
|
||||||
new Dependencies());
|
new Dependencies());
|
||||||
|
|
||||||
@@ -602,13 +589,13 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
mSettings.getPollInterval(), pollIntent);
|
mSettings.getPollInterval(), pollIntent);
|
||||||
|
|
||||||
mContentResolver.registerContentObserver(Settings.Global
|
mContentResolver.registerContentObserver(Settings.Global
|
||||||
.getUriFor(Settings.Global.NETSTATS_COMBINE_SUBTYPE_ENABLED),
|
.getUriFor(NETSTATS_COMBINE_SUBTYPE_ENABLED),
|
||||||
false /* notifyForDescendants */, mContentObserver);
|
false /* notifyForDescendants */, mContentObserver);
|
||||||
|
|
||||||
// Post a runnable on handler thread to call onChange(). It's for getting current value of
|
// Post a runnable on handler thread to call onChange(). It's for getting current value of
|
||||||
// NETSTATS_COMBINE_SUBTYPE_ENABLED to decide start or stop monitoring RAT type changes.
|
// NETSTATS_COMBINE_SUBTYPE_ENABLED to decide start or stop monitoring RAT type changes.
|
||||||
mHandler.post(() -> mContentObserver.onChange(false, Settings.Global
|
mHandler.post(() -> mContentObserver.onChange(false, Settings.Global
|
||||||
.getUriFor(Settings.Global.NETSTATS_COMBINE_SUBTYPE_ENABLED)));
|
.getUriFor(NETSTATS_COMBINE_SUBTYPE_ENABLED)));
|
||||||
|
|
||||||
registerGlobalAlert();
|
registerGlobalAlert();
|
||||||
}
|
}
|
||||||
@@ -2243,24 +2230,11 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
* {@link android.provider.Settings.Global}.
|
* {@link android.provider.Settings.Global}.
|
||||||
*/
|
*/
|
||||||
private static class DefaultNetworkStatsSettings implements NetworkStatsSettings {
|
private static class DefaultNetworkStatsSettings implements NetworkStatsSettings {
|
||||||
private final ContentResolver mResolver;
|
DefaultNetworkStatsSettings() {}
|
||||||
|
|
||||||
public DefaultNetworkStatsSettings(Context context) {
|
|
||||||
mResolver = Objects.requireNonNull(context.getContentResolver());
|
|
||||||
// TODO: adjust these timings for production builds
|
|
||||||
}
|
|
||||||
|
|
||||||
private long getGlobalLong(String name, long def) {
|
|
||||||
return Settings.Global.getLong(mResolver, name, def);
|
|
||||||
}
|
|
||||||
private boolean getGlobalBoolean(String name, boolean def) {
|
|
||||||
final int defInt = def ? 1 : 0;
|
|
||||||
return Settings.Global.getInt(mResolver, name, defInt) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getPollInterval() {
|
public long getPollInterval() {
|
||||||
return getGlobalLong(NETSTATS_POLL_INTERVAL, 30 * MINUTE_IN_MILLIS);
|
return 30 * MINUTE_IN_MILLIS;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public long getPollDelay() {
|
public long getPollDelay() {
|
||||||
@@ -2268,25 +2242,23 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public long getGlobalAlertBytes(long def) {
|
public long getGlobalAlertBytes(long def) {
|
||||||
return getGlobalLong(NETSTATS_GLOBAL_ALERT_BYTES, def);
|
return def;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean getSampleEnabled() {
|
public boolean getSampleEnabled() {
|
||||||
return getGlobalBoolean(NETSTATS_SAMPLE_ENABLED, true);
|
return true;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean getAugmentEnabled() {
|
public boolean getAugmentEnabled() {
|
||||||
return getGlobalBoolean(NETSTATS_AUGMENT_ENABLED, true);
|
return true;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean getCombineSubtypeEnabled() {
|
public boolean getCombineSubtypeEnabled() {
|
||||||
return getGlobalBoolean(NETSTATS_COMBINE_SUBTYPE_ENABLED, false);
|
return false;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Config getDevConfig() {
|
public Config getDevConfig() {
|
||||||
return new Config(getGlobalLong(NETSTATS_DEV_BUCKET_DURATION, HOUR_IN_MILLIS),
|
return new Config(HOUR_IN_MILLIS, 15 * DAY_IN_MILLIS, 90 * DAY_IN_MILLIS);
|
||||||
getGlobalLong(NETSTATS_DEV_ROTATE_AGE, 15 * DAY_IN_MILLIS),
|
|
||||||
getGlobalLong(NETSTATS_DEV_DELETE_AGE, 90 * DAY_IN_MILLIS));
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Config getXtConfig() {
|
public Config getXtConfig() {
|
||||||
@@ -2294,31 +2266,27 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Config getUidConfig() {
|
public Config getUidConfig() {
|
||||||
return new Config(getGlobalLong(NETSTATS_UID_BUCKET_DURATION, 2 * HOUR_IN_MILLIS),
|
return new Config(2 * HOUR_IN_MILLIS, 15 * DAY_IN_MILLIS, 90 * DAY_IN_MILLIS);
|
||||||
getGlobalLong(NETSTATS_UID_ROTATE_AGE, 15 * DAY_IN_MILLIS),
|
|
||||||
getGlobalLong(NETSTATS_UID_DELETE_AGE, 90 * DAY_IN_MILLIS));
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Config getUidTagConfig() {
|
public Config getUidTagConfig() {
|
||||||
return new Config(getGlobalLong(NETSTATS_UID_TAG_BUCKET_DURATION, 2 * HOUR_IN_MILLIS),
|
return new Config(2 * HOUR_IN_MILLIS, 5 * DAY_IN_MILLIS, 15 * DAY_IN_MILLIS);
|
||||||
getGlobalLong(NETSTATS_UID_TAG_ROTATE_AGE, 5 * DAY_IN_MILLIS),
|
|
||||||
getGlobalLong(NETSTATS_UID_TAG_DELETE_AGE, 15 * DAY_IN_MILLIS));
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public long getDevPersistBytes(long def) {
|
public long getDevPersistBytes(long def) {
|
||||||
return getGlobalLong(NETSTATS_DEV_PERSIST_BYTES, def);
|
return def;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public long getXtPersistBytes(long def) {
|
public long getXtPersistBytes(long def) {
|
||||||
return getDevPersistBytes(def);
|
return def;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public long getUidPersistBytes(long def) {
|
public long getUidPersistBytes(long def) {
|
||||||
return getGlobalLong(NETSTATS_UID_PERSIST_BYTES, def);
|
return def;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public long getUidTagPersistBytes(long def) {
|
public long getUidTagPersistBytes(long def) {
|
||||||
return getGlobalLong(NETSTATS_UID_TAG_PERSIST_BYTES, def);
|
return def;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user