Observe screen on/off events in NetworkPolicy.

The POLICY_REJECT_BACKGROUND policy requires that network traffic be
blocked when a UID goes into the background.  Even if the UID has an
activity in the foreground, it's considered "background" if the screen
is turned off.

This changes watches for SCREEN_ON/OFF broadcasts, and rule generation
now observes screen state.  It also introduces an observer pattern so
that ActivityManager doesn't directly know about NetworkPolicy, and
moves the service management into SystemServer.

Change-Id: Ie7a84929d3ca60ae4578d47e19d5a8da10fd8d58
This commit is contained in:
Jeff Sharkey
2011-05-20 15:29:23 -07:00
parent 442fa21e98
commit a462079303
8 changed files with 275 additions and 73 deletions

View File

@ -18,6 +18,7 @@ package com.android.server;
import com.android.server.accessibility.AccessibilityManagerService;
import com.android.server.am.ActivityManagerService;
import com.android.server.net.NetworkPolicyManagerService;
import com.android.server.pm.PackageManagerService;
import com.android.server.usb.UsbService;
import com.android.server.wm.WindowManagerService;
@ -119,6 +120,7 @@ class ServerThread extends Thread {
LightsService lights = null;
PowerManagerService power = null;
BatteryService battery = null;
NetworkPolicyManagerService networkPolicy = null;
ConnectivityService connectivity = null;
IPackageManager pm = null;
Context context = null;
@ -281,6 +283,15 @@ class ServerThread extends Thread {
Slog.e(TAG, "Failure starting NetStat Service", e);
}
try {
Slog.i(TAG, "NetworkPolicy Service");
networkPolicy = new NetworkPolicyManagerService(
context, ActivityManagerService.self(), power);
ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
} catch (Throwable e) {
Slog.e(TAG, "Failure starting Connectivity Service", e);
}
try {
Slog.i(TAG, "NetworkManagement Service");
ServiceManager.addService(
@ -528,6 +539,7 @@ class ServerThread extends Thread {
// These are needed to propagate to the runnable below.
final Context contextF = context;
final BatteryService batteryF = battery;
final NetworkPolicyManagerService networkPolicyF = networkPolicy;
final ConnectivityService connectivityF = connectivity;
final DockObserver dockF = dock;
final UsbService usbF = usb;
@ -553,6 +565,7 @@ class ServerThread extends Thread {
startSystemUi(contextF);
if (batteryF != null) batteryF.systemReady();
if (networkPolicyF != null) networkPolicyF.systemReady();
if (connectivityF != null) connectivityF.systemReady();
if (dockF != null) dockF.systemReady();
if (usbF != null) usbF.systemReady();