Skip to content

Commit fc0ab4c

Browse files
jsharkeyAndroid (Google) Code Review
authored andcommitted
Merge "Network stats flag to force complete poll."
2 parents 93578af + 991d1b1 commit fc0ab4c

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

core/java/android/provider/Settings.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4031,6 +4031,8 @@ public static final String getBluetoothInputDevicePriorityKey(String address) {
40314031
public static final String NETSTATS_UID_MAX_HISTORY = "netstats_uid_max_history";
40324032
/** {@hide} */
40334033
public static final String NETSTATS_TAG_MAX_HISTORY = "netstats_tag_max_history";
4034+
/** {@hide} */
4035+
public static final String NETSTATS_FORCE_COMPLETE_POLL = "netstats_force_complete_poll";
40344036

40354037
/** Preferred NTP server. {@hide} */
40364038
public static final String NTP_SERVER = "ntp_server";

services/java/com/android/server/net/NetworkStatsService.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import static android.net.NetworkTemplate.buildTemplateMobileAll;
3535
import static android.net.NetworkTemplate.buildTemplateWifi;
3636
import static android.net.TrafficStats.UID_REMOVED;
37+
import static android.provider.Settings.Secure.NETSTATS_FORCE_COMPLETE_POLL;
3738
import static android.provider.Settings.Secure.NETSTATS_NETWORK_BUCKET_DURATION;
3839
import static android.provider.Settings.Secure.NETSTATS_NETWORK_MAX_HISTORY;
3940
import static android.provider.Settings.Secure.NETSTATS_PERSIST_THRESHOLD;
@@ -176,6 +177,7 @@ public interface NetworkStatsSettings {
176177
public long getUidMaxHistory();
177178
public long getTagMaxHistory();
178179
public long getTimeCacheMaxAge();
180+
public boolean getForceCompletePoll();
179181
}
180182

181183
private final Object mStatsLock = new Object();
@@ -682,8 +684,16 @@ private void performPollLocked(int flags) {
682684
if (LOGV) Slog.v(TAG, "performPollLocked(flags=0x" + Integer.toHexString(flags) + ")");
683685
final long startRealtime = SystemClock.elapsedRealtime();
684686

685-
final boolean pollNetwork = (flags & FLAG_POLL_NETWORK) != 0;
686-
final boolean pollUid = (flags & FLAG_POLL_UID) != 0;
687+
boolean pollNetwork = (flags & FLAG_POLL_NETWORK) != 0;
688+
boolean pollUid = (flags & FLAG_POLL_UID) != 0;
689+
690+
// when complete poll requested, any partial poll enables everything
691+
final boolean forceCompletePoll = mSettings.getForceCompletePoll();
692+
if (forceCompletePoll && (pollNetwork || pollUid)) {
693+
pollNetwork = true;
694+
pollUid = true;
695+
}
696+
687697
final boolean persistNetwork = (flags & FLAG_PERSIST_NETWORK) != 0;
688698
final boolean persistUid = (flags & FLAG_PERSIST_UID) != 0;
689699
final boolean forcePersist = (flags & FLAG_FORCE_PERSIST) != 0;
@@ -1360,6 +1370,10 @@ public DefaultNetworkStatsSettings(Context context) {
13601370
private long getSecureLong(String name, long def) {
13611371
return Settings.Secure.getLong(mResolver, name, def);
13621372
}
1373+
private boolean getSecureBoolean(String name, boolean def) {
1374+
final int defInt = def ? 1 : 0;
1375+
return Settings.Secure.getInt(mResolver, name, defInt) != 0;
1376+
}
13631377

13641378
public long getPollInterval() {
13651379
return getSecureLong(NETSTATS_POLL_INTERVAL, 30 * MINUTE_IN_MILLIS);
@@ -1385,5 +1399,8 @@ public long getTagMaxHistory() {
13851399
public long getTimeCacheMaxAge() {
13861400
return DAY_IN_MILLIS;
13871401
}
1402+
public boolean getForceCompletePoll() {
1403+
return getSecureBoolean(NETSTATS_FORCE_COMPLETE_POLL, false);
1404+
}
13881405
}
13891406
}

services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ private void expectSettings(long persistThreshold, long bucketDuration, long max
758758
expect(mSettings.getUidMaxHistory()).andReturn(maxHistory).anyTimes();
759759
expect(mSettings.getTagMaxHistory()).andReturn(maxHistory).anyTimes();
760760
expect(mSettings.getTimeCacheMaxAge()).andReturn(DAY_IN_MILLIS).anyTimes();
761+
expect(mSettings.getForceCompletePoll()).andReturn(false).anyTimes();
761762
}
762763

763764
private void expectCurrentTime() throws Exception {

0 commit comments

Comments
 (0)