summaryrefslogtreecommitdiffstats
path: root/services/java/com
diff options
context:
space:
mode:
authorJP Abgrall <jpa@google.com>2011-07-14 18:09:22 -0700
committerJP Abgrall <jpa@google.com>2011-07-14 18:09:22 -0700
commit12b933d0d9252decaae9fee2456bb1e1cd94c085 (patch)
tree8193447d4ce0aa1471db61960ced595c20db2ecf /services/java/com
parent5f81f1bcd9cdb15411bd4bb036b75ee6e822b8bf (diff)
downloadframeworks_base-12b933d0d9252decaae9fee2456bb1e1cd94c085.zip
frameworks_base-12b933d0d9252decaae9fee2456bb1e1cd94c085.tar.gz
frameworks_base-12b933d0d9252decaae9fee2456bb1e1cd94c085.tar.bz2
NetworkManagementService: receive bandwidth controller events
This is a 1st pass at receiving events that indicate some quota has been reached e.g. warning quota, data collection quota, cutoff quota,... It needs: - new kernel with quota2 logging support - new net:bandwidthcontroller that supports . quota2, . setting alerts. - new NetlinkEvent/NetlinkManager/NetlinkHandler to process NETLINK NFLOG messages. Change-Id: Ibfbb13512c5350cdee0e544ec14caa6f59812409
Diffstat (limited to 'services/java/com')
-rw-r--r--services/java/com/android/server/NetworkManagementService.java85
-rw-r--r--services/java/com/android/server/ThrottleService.java1
-rw-r--r--services/java/com/android/server/connectivity/Tethering.java2
-rw-r--r--services/java/com/android/server/connectivity/Vpn.java2
4 files changed, 65 insertions, 25 deletions
diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java
index 41e8a31..2366fcb 100644
--- a/services/java/com/android/server/NetworkManagementService.java
+++ b/services/java/com/android/server/NetworkManagementService.java
@@ -93,6 +93,7 @@ class NetworkManagementService extends INetworkManagementService.Stub {
private static final String KEY_TX = "tx_bytes";
class NetdResponseCode {
+ /* Keep in sync with system/netd/ResponseCode.h */
public static final int InterfaceListResult = 110;
public static final int TetherInterfaceListResult = 111;
public static final int TetherDnsFwdTgtListResult = 112;
@@ -108,6 +109,7 @@ class NetworkManagementService extends INetworkManagementService.Stub {
public static final int InterfaceTxThrottleResult = 219;
public static final int InterfaceChange = 600;
+ public static final int BandwidthControl = 601;
}
/**
@@ -265,6 +267,20 @@ class NetworkManagementService extends INetworkManagementService.Stub {
}
/**
+ * Notify our observers of a limit reached.
+ */
+ private void notifyLimitReached(String limitName, String iface) {
+ 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);
+ }
+ }
+ }
+
+ /**
* Let us know the daemon is connected
*/
protected void onConnected() {
@@ -286,33 +302,52 @@ class NetworkManagementService extends INetworkManagementService.Stub {
}.start();
}
public boolean onEvent(int code, String raw, String[] cooked) {
- if (code == NetdResponseCode.InterfaceChange) {
- /*
- * a network interface change occured
- * Format: "NNN Iface added <name>"
- * "NNN Iface removed <name>"
- * "NNN Iface changed <name> <up/down>"
- * "NNN Iface linkstatus <name> <up/down>"
- */
- if (cooked.length < 4 || !cooked[1].equals("Iface")) {
+ switch (code) {
+ case NetdResponseCode.InterfaceChange:
+ /*
+ * a network interface change occured
+ * Format: "NNN Iface added <name>"
+ * "NNN Iface removed <name>"
+ * "NNN Iface changed <name> <up/down>"
+ * "NNN Iface linkstatus <name> <up/down>"
+ */
+ if (cooked.length < 4 || !cooked[1].equals("Iface")) {
+ throw new IllegalStateException(
+ String.format("Invalid event from daemon (%s)", raw));
+ }
+ if (cooked[2].equals("added")) {
+ notifyInterfaceAdded(cooked[3]);
+ return true;
+ } else if (cooked[2].equals("removed")) {
+ notifyInterfaceRemoved(cooked[3]);
+ return true;
+ } else if (cooked[2].equals("changed") && cooked.length == 5) {
+ notifyInterfaceStatusChanged(cooked[3], cooked[4].equals("up"));
+ return true;
+ } else if (cooked[2].equals("linkstate") && cooked.length == 5) {
+ notifyInterfaceLinkStateChanged(cooked[3], cooked[4].equals("up"));
+ return true;
+ }
throw new IllegalStateException(
String.format("Invalid event from daemon (%s)", raw));
- }
- if (cooked[2].equals("added")) {
- notifyInterfaceAdded(cooked[3]);
- return true;
- } else if (cooked[2].equals("removed")) {
- notifyInterfaceRemoved(cooked[3]);
- return true;
- } else if (cooked[2].equals("changed") && cooked.length == 5) {
- notifyInterfaceStatusChanged(cooked[3], cooked[4].equals("up"));
- return true;
- } else if (cooked[2].equals("linkstate") && cooked.length == 5) {
- notifyInterfaceLinkStateChanged(cooked[3], cooked[4].equals("up"));
- return true;
- }
- throw new IllegalStateException(
- String.format("Invalid event from daemon (%s)", raw));
+ // break;
+ case NetdResponseCode.BandwidthControl:
+ /*
+ * Bandwidth control needs some attention
+ * Format: "NNN limit alert <alertName> <ifaceName>"
+ */
+ if (cooked.length < 5 || !cooked[1].equals("limit")) {
+ throw new IllegalStateException(
+ String.format("Invalid event from daemon (%s)", raw));
+ }
+ if (cooked[2].equals("alert")) {
+ notifyLimitReached(cooked[3], cooked[4]);
+ return true;
+ }
+ throw new IllegalStateException(
+ String.format("Invalid event from daemon (%s)", raw));
+ // break;
+ default: break;
}
return false;
}
diff --git a/services/java/com/android/server/ThrottleService.java b/services/java/com/android/server/ThrottleService.java
index b8890aa..cd649ce 100644
--- a/services/java/com/android/server/ThrottleService.java
+++ b/services/java/com/android/server/ThrottleService.java
@@ -194,6 +194,7 @@ public class ThrottleService extends IThrottleManager.Stub {
}
public void interfaceRemoved(String iface) {}
+ public void limitReached(String limitName, String iface) {}
}
diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java
index d7d4b03..82bc505 100644
--- a/services/java/com/android/server/connectivity/Tethering.java
+++ b/services/java/com/android/server/connectivity/Tethering.java
@@ -288,6 +288,8 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
}
}
+ public void limitReached(String limitName, String iface) {}
+
public int tether(String iface) {
Log.d(TAG, "Tethering " + iface);
TetherInterfaceSM sm = null;
diff --git a/services/java/com/android/server/connectivity/Vpn.java b/services/java/com/android/server/connectivity/Vpn.java
index c185012..f972e6e 100644
--- a/services/java/com/android/server/connectivity/Vpn.java
+++ b/services/java/com/android/server/connectivity/Vpn.java
@@ -242,6 +242,8 @@ public class Vpn extends INetworkManagementEventObserver.Stub {
}
}
+ public void limitReached(String limitName, String iface) {}
+
private void showNotification(VpnConfig config, String label, Bitmap icon) {
NotificationManager nm = (NotificationManager)
mContext.getSystemService(Context.NOTIFICATION_SERVICE);