Merge "Network stats flag to force complete poll."

This commit is contained in:
Jeff Sharkey
2011-09-14 21:44:19 -07:00
committed by Android (Google) Code Review
3 changed files with 22 additions and 2 deletions

View File

@ -4031,6 +4031,8 @@ public final class Settings {
public static final String NETSTATS_UID_MAX_HISTORY = "netstats_uid_max_history";
/** {@hide} */
public static final String NETSTATS_TAG_MAX_HISTORY = "netstats_tag_max_history";
/** {@hide} */
public static final String NETSTATS_FORCE_COMPLETE_POLL = "netstats_force_complete_poll";
/** Preferred NTP server. {@hide} */
public static final String NTP_SERVER = "ntp_server";

View File

@ -34,6 +34,7 @@ import static android.net.NetworkStats.UID_ALL;
import static android.net.NetworkTemplate.buildTemplateMobileAll;
import static android.net.NetworkTemplate.buildTemplateWifi;
import static android.net.TrafficStats.UID_REMOVED;
import static android.provider.Settings.Secure.NETSTATS_FORCE_COMPLETE_POLL;
import static android.provider.Settings.Secure.NETSTATS_NETWORK_BUCKET_DURATION;
import static android.provider.Settings.Secure.NETSTATS_NETWORK_MAX_HISTORY;
import static android.provider.Settings.Secure.NETSTATS_PERSIST_THRESHOLD;
@ -176,6 +177,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
public long getUidMaxHistory();
public long getTagMaxHistory();
public long getTimeCacheMaxAge();
public boolean getForceCompletePoll();
}
private final Object mStatsLock = new Object();
@ -682,8 +684,16 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
if (LOGV) Slog.v(TAG, "performPollLocked(flags=0x" + Integer.toHexString(flags) + ")");
final long startRealtime = SystemClock.elapsedRealtime();
final boolean pollNetwork = (flags & FLAG_POLL_NETWORK) != 0;
final boolean pollUid = (flags & FLAG_POLL_UID) != 0;
boolean pollNetwork = (flags & FLAG_POLL_NETWORK) != 0;
boolean pollUid = (flags & FLAG_POLL_UID) != 0;
// when complete poll requested, any partial poll enables everything
final boolean forceCompletePoll = mSettings.getForceCompletePoll();
if (forceCompletePoll && (pollNetwork || pollUid)) {
pollNetwork = true;
pollUid = true;
}
final boolean persistNetwork = (flags & FLAG_PERSIST_NETWORK) != 0;
final boolean persistUid = (flags & FLAG_PERSIST_UID) != 0;
final boolean forcePersist = (flags & FLAG_FORCE_PERSIST) != 0;
@ -1360,6 +1370,10 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
private long getSecureLong(String name, long def) {
return Settings.Secure.getLong(mResolver, name, def);
}
private boolean getSecureBoolean(String name, boolean def) {
final int defInt = def ? 1 : 0;
return Settings.Secure.getInt(mResolver, name, defInt) != 0;
}
public long getPollInterval() {
return getSecureLong(NETSTATS_POLL_INTERVAL, 30 * MINUTE_IN_MILLIS);
@ -1385,5 +1399,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
public long getTimeCacheMaxAge() {
return DAY_IN_MILLIS;
}
public boolean getForceCompletePoll() {
return getSecureBoolean(NETSTATS_FORCE_COMPLETE_POLL, false);
}
}
}

View File

@ -758,6 +758,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
expect(mSettings.getUidMaxHistory()).andReturn(maxHistory).anyTimes();
expect(mSettings.getTagMaxHistory()).andReturn(maxHistory).anyTimes();
expect(mSettings.getTimeCacheMaxAge()).andReturn(DAY_IN_MILLIS).anyTimes();
expect(mSettings.getForceCompletePoll()).andReturn(false).anyTimes();
}
private void expectCurrentTime() throws Exception {