Migrate bandwidth control to NMS, omit history.

Both stats and policy make NMS calls that depend on bandwidth control
being enabled, so move enable/disable into NMS and drop calls when
disabled.  This avoids throwing heavy ISE exceptions when disabled.

Only include recent data when writing NetworkStatsHistory as part of
dumpsys call.  Introduce manual poll event for Settings UI.

Bug: 4982115, 4770435, 4515856
Change-Id: I257820b057af2f0f99c736fb4f61e55b9fdc3e66
This commit is contained in:
Jeff Sharkey
2011-06-29 10:45:16 -07:00
parent b05f41c97f
commit 830d546f6b
3 changed files with 26 additions and 29 deletions

View File

@@ -33,4 +33,7 @@ interface INetworkStatsService {
/** Return usage summary per UID for traffic that matches template. */ /** Return usage summary per UID for traffic that matches template. */
NetworkStats getSummaryForAllUid(in NetworkTemplate template, long start, long end, boolean includeTags); NetworkStats getSummaryForAllUid(in NetworkTemplate template, long start, long end, boolean includeTags);
/** Force update of statistics. */
void forceUpdate();
} }

View File

@@ -279,10 +279,17 @@ public class NetworkStatsHistory implements Parcelable {
return (long) (start + (r.nextFloat() * (end - start))); return (long) (start + (r.nextFloat() * (end - start)));
} }
public void dump(String prefix, PrintWriter pw) { public void dump(String prefix, PrintWriter pw, boolean fullHistory) {
pw.print(prefix); pw.print(prefix);
pw.print("NetworkStatsHistory: bucketDuration="); pw.println(bucketDuration); pw.print("NetworkStatsHistory: bucketDuration="); pw.println(bucketDuration);
for (int i = 0; i < bucketCount; i++) {
final int start = fullHistory ? 0 : Math.max(0, bucketCount - 32);
if (start > 0) {
pw.print(prefix);
pw.print(" (omitting "); pw.print(start); pw.println(" buckets)");
}
for (int i = start; i < bucketCount; i++) {
pw.print(prefix); pw.print(prefix);
pw.print(" bucketStart="); pw.print(bucketStart[i]); pw.print(" bucketStart="); pw.print(bucketStart[i]);
pw.print(" rx="); pw.print(rx[i]); pw.print(" rx="); pw.print(rx[i]);
@@ -293,7 +300,7 @@ public class NetworkStatsHistory implements Parcelable {
@Override @Override
public String toString() { public String toString() {
final CharArrayWriter writer = new CharArrayWriter(); final CharArrayWriter writer = new CharArrayWriter();
dump("", new PrintWriter(writer)); dump("", new PrintWriter(writer), false);
return writer.toString(); return writer.toString();
} }

View File

@@ -134,7 +134,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
* Settings that can be changed externally. * Settings that can be changed externally.
*/ */
public interface NetworkStatsSettings { public interface NetworkStatsSettings {
public boolean getEnabled();
public long getPollInterval(); public long getPollInterval();
public long getPersistThreshold(); public long getPersistThreshold();
public long getNetworkBucketDuration(); public long getNetworkBucketDuration();
@@ -207,20 +206,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
} }
public void systemReady() { public void systemReady() {
if (mSettings.getEnabled()) {
try {
// enable low-level bandwidth stats and control
// TODO: consider shipping with this enabled by default
mNetworkManager.setBandwidthControlEnabled(true);
} catch (RemoteException e) {
Slog.e(TAG, "problem talking to netd while enabling bandwidth controls", e);
} catch (NativeDaemonConnectorException ndce) {
Slog.e(TAG, "problem enabling bandwidth controls", ndce);
}
} else {
Slog.w(TAG, "detailed network stats disabled");
}
synchronized (mStatsLock) { synchronized (mStatsLock) {
// read historical network stats from disk, since policy service // read historical network stats from disk, since policy service
// might need them right away. we delay loading detailed UID stats // might need them right away. we delay loading detailed UID stats
@@ -389,6 +374,15 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
} }
} }
@Override
public void forceUpdate() {
mContext.enforceCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY, TAG);
synchronized (mStatsLock) {
performPollLocked(true, false);
}
}
/** /**
* Receiver that watches for {@link IConnectivityManager} to claim network * Receiver that watches for {@link IConnectivityManager} to claim network
* interfaces. Used to associate {@link TelephonyManager#getSubscriberId()} * interfaces. Used to associate {@link TelephonyManager#getSubscriberId()}
@@ -905,6 +899,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
argSet.add(arg); argSet.add(arg);
} }
final boolean fullHistory = argSet.contains("full");
synchronized (mStatsLock) { synchronized (mStatsLock) {
// TODO: remove this testing code, since it corrupts stats // TODO: remove this testing code, since it corrupts stats
if (argSet.contains("generate")) { if (argSet.contains("generate")) {
@@ -930,7 +926,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
for (NetworkIdentitySet ident : mNetworkStats.keySet()) { for (NetworkIdentitySet ident : mNetworkStats.keySet()) {
final NetworkStatsHistory history = mNetworkStats.get(ident); final NetworkStatsHistory history = mNetworkStats.get(ident);
pw.print(" ident="); pw.println(ident.toString()); pw.print(" ident="); pw.println(ident.toString());
history.dump(" ", pw); history.dump(" ", pw, fullHistory);
} }
if (argSet.contains("detail")) { if (argSet.contains("detail")) {
@@ -950,7 +946,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
final NetworkStatsHistory history = uidStats.valueAt(i); final NetworkStatsHistory history = uidStats.valueAt(i);
pw.print(" UID="); pw.print(uid); pw.print(" UID="); pw.print(uid);
pw.print(" tag="); pw.println(tag); pw.print(" tag="); pw.println(tag);
history.dump(" ", pw); history.dump(" ", pw, fullHistory);
} }
} }
} }
@@ -1058,15 +1054,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
return Settings.Secure.getLong(mResolver, name, def); return Settings.Secure.getLong(mResolver, name, def);
} }
public boolean getEnabled() {
if (!new File("/proc/net/xt_qtaguid/ctrl").exists()) {
Slog.w(TAG, "kernel does not support bandwidth control");
return false;
}
// TODO: once things stabilize, enable by default.
// For now: ./vendor/google/tools/override-gservices secure:netstats_enabled=1
return Settings.Secure.getInt(mResolver, NETSTATS_ENABLED, 0) != 0;
}
public long getPollInterval() { public long getPollInterval() {
return getSecureLong(NETSTATS_POLL_INTERVAL, 15 * MINUTE_IN_MILLIS); return getSecureLong(NETSTATS_POLL_INTERVAL, 15 * MINUTE_IN_MILLIS);
} }