3434import static android .net .NetworkTemplate .buildTemplateMobileAll ;
3535import static android .net .NetworkTemplate .buildTemplateWifi ;
3636import static android .net .TrafficStats .UID_REMOVED ;
37+ import static android .provider .Settings .Secure .NETSTATS_FORCE_COMPLETE_POLL ;
3738import static android .provider .Settings .Secure .NETSTATS_NETWORK_BUCKET_DURATION ;
3839import static android .provider .Settings .Secure .NETSTATS_NETWORK_MAX_HISTORY ;
3940import 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}
0 commit comments