summaryrefslogtreecommitdiffstats
path: root/services/java/com/android/server/NetworkManagementService.java
diff options
context:
space:
mode:
Diffstat (limited to 'services/java/com/android/server/NetworkManagementService.java')
-rw-r--r--services/java/com/android/server/NetworkManagementService.java62
1 files changed, 46 insertions, 16 deletions
diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java
index 06077dd..85d8cece 100644
--- a/services/java/com/android/server/NetworkManagementService.java
+++ b/services/java/com/android/server/NetworkManagementService.java
@@ -16,6 +16,7 @@
package com.android.server;
+import static android.Manifest.permission.DUMP;
import static android.Manifest.permission.MANAGE_NETWORK_POLICY;
import static android.net.NetworkStats.IFACE_ALL;
import static android.net.NetworkStats.SET_DEFAULT;
@@ -51,10 +52,12 @@ import com.google.android.collect.Sets;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
+import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.io.PrintWriter;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.util.ArrayList;
@@ -69,7 +72,8 @@ import libcore.io.IoUtils;
/**
* @hide
*/
-class NetworkManagementService extends INetworkManagementService.Stub implements Watchdog.Monitor {
+public class NetworkManagementService extends INetworkManagementService.Stub
+ implements Watchdog.Monitor {
private static final String TAG = "NetworkManagementService";
private static final boolean DBG = false;
private static final String NETD_TAG = "NetdConnector";
@@ -87,6 +91,12 @@ class NetworkManagementService extends INetworkManagementService.Stub implements
/** Path to {@code /proc/net/xt_qtaguid/iface_stat}. */
private final File mStatsXtIface;
+ /**
+ * Name representing {@link #setGlobalAlert(long)} limit when delivered to
+ * {@link INetworkManagementEventObserver#limitReached(String, String)}.
+ */
+ public static final String LIMIT_GLOBAL_ALERT = "globalAlert";
+
/** {@link #mStatsXtUid} headers. */
private static final String KEY_IFACE = "iface";
private static final String KEY_UID = "uid_tag_int";
@@ -281,7 +291,6 @@ class NetworkManagementService extends INetworkManagementService.Stub implements
for (INetworkManagementEventObserver obs : mObservers) {
try {
obs.limitReached(limitName, iface);
- Slog.d(TAG, "Observer notified limit reached for " + limitName + " " + iface);
} catch (Exception ex) {
Slog.w(TAG, "Observer notifier failed", ex);
}
@@ -1024,7 +1033,6 @@ class NetworkManagementService extends INetworkManagementService.Stub implements
final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 6);
final NetworkStats.Entry entry = new NetworkStats.Entry();
- final HashSet<String> activeIfaces = Sets.newHashSet();
final ArrayList<String> values = Lists.newArrayList();
BufferedReader reader = null;
@@ -1050,26 +1058,24 @@ class NetworkManagementService extends INetworkManagementService.Stub implements
entry.txBytes = Long.parseLong(values.get(9));
entry.txPackets = Long.parseLong(values.get(10));
- activeIfaces.add(entry.iface);
stats.addValues(entry);
} catch (NumberFormatException e) {
Slog.w(TAG, "problem parsing stats row '" + line + "': " + e);
}
}
+ } catch (NullPointerException e) {
+ throw new IllegalStateException("problem parsing stats: " + e);
+ } catch (NumberFormatException e) {
+ throw new IllegalStateException("problem parsing stats: " + e);
} catch (IOException e) {
- Slog.w(TAG, "problem parsing stats: " + e);
+ throw new IllegalStateException("problem parsing stats: " + e);
} finally {
IoUtils.closeQuietly(reader);
}
- if (DBG) Slog.d(TAG, "recorded active stats from " + activeIfaces);
-
- // splice in stats from any disabled ifaces
+ // splice in historical stats not reflected in mStatsIface
if (mBandwidthControlEnabled) {
- final HashSet<String> xtIfaces = Sets.newHashSet(fileListWithoutNull(mStatsXtIface));
- xtIfaces.removeAll(activeIfaces);
-
- for (String iface : xtIfaces) {
+ for (String iface : fileListWithoutNull(mStatsXtIface)) {
final File ifacePath = new File(mStatsXtIface, iface);
entry.iface = iface;
@@ -1081,10 +1087,8 @@ class NetworkManagementService extends INetworkManagementService.Stub implements
entry.txBytes = readSingleLongFromFile(new File(ifacePath, "tx_bytes"));
entry.txPackets = readSingleLongFromFile(new File(ifacePath, "tx_packets"));
- stats.addValues(entry);
+ stats.combineValues(entry);
}
-
- if (DBG) Slog.d(TAG, "recorded stale stats from " + xtIfaces);
}
return stats;
@@ -1338,8 +1342,12 @@ class NetworkManagementService extends INetworkManagementService.Stub implements
Slog.w(TAG, "problem parsing stats row '" + line + "': " + e);
}
}
+ } catch (NullPointerException e) {
+ throw new IllegalStateException("problem parsing stats: " + e);
+ } catch (NumberFormatException e) {
+ throw new IllegalStateException("problem parsing stats: " + e);
} catch (IOException e) {
- Slog.w(TAG, "problem parsing stats: " + e);
+ throw new IllegalStateException("problem parsing stats: " + e);
} finally {
IoUtils.closeQuietly(reader);
}
@@ -1568,4 +1576,26 @@ class NetworkManagementService extends INetworkManagementService.Stub implements
mConnector.monitor();
}
}
+
+ @Override
+ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+ mContext.enforceCallingOrSelfPermission(DUMP, TAG);
+
+ pw.print("Bandwidth control enabled: "); pw.println(mBandwidthControlEnabled);
+
+ synchronized (mQuotaLock) {
+ pw.print("Active quota ifaces: "); pw.println(mActiveQuotaIfaces.toString());
+ pw.print("Active alert ifaces: "); pw.println(mActiveAlertIfaces.toString());
+ }
+
+ synchronized (mUidRejectOnQuota) {
+ pw.print("UID reject on quota ifaces: [");
+ final int size = mUidRejectOnQuota.size();
+ for (int i = 0; i < size; i++) {
+ pw.print(mUidRejectOnQuota.keyAt(i));
+ if (i < size - 1) pw.print(",");
+ }
+ pw.println("]");
+ }
+ }
}