diff options
author | Jeff Sharkey <jsharkey@android.com> | 2011-05-03 20:27:17 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2011-05-13 16:20:21 -0700 |
commit | d5cdd597b895a48ffa9a8e39f8a2504cd9b905c4 (patch) | |
tree | 4c35c0c334ff2961093461b8b4b5f0ccfa1422f7 /core/java/android | |
parent | 674b595fa5299d138e068b2b786027d6d6225394 (diff) | |
download | frameworks_base-d5cdd597b895a48ffa9a8e39f8a2504cd9b905c4.zip frameworks_base-d5cdd597b895a48ffa9a8e39f8a2504cd9b905c4.tar.gz frameworks_base-d5cdd597b895a48ffa9a8e39f8a2504cd9b905c4.tar.bz2 |
First pass at NetworkPolicy and activity tracking.
New system service that maintains low-level network policy rules and
collects statistics to drive those rules. Will eventually connect to
netfilter kernel module through NetworkManagementService and "netd".
Begin tracking foreground activities in ActivityManagerService, which
is updated as part of OOM adjustment. Eventually a network policy of
POLICY_REJECT_BACKGROUND will reject network traffic from background
processes.
Change-Id: I5ffbbaee1b9628e9c3eff6b9cb2145fc5316e64d
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/net/INetworkPolicyManager.aidl | 34 | ||||
-rw-r--r-- | core/java/android/net/NetworkPolicyManager.java | 68 |
2 files changed, 102 insertions, 0 deletions
diff --git a/core/java/android/net/INetworkPolicyManager.aidl b/core/java/android/net/INetworkPolicyManager.aidl new file mode 100644 index 0000000..fa6eae5 --- /dev/null +++ b/core/java/android/net/INetworkPolicyManager.aidl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net; + +/** + * Interface that creates and modifies network policy rules. + * + * {@hide} + */ +interface INetworkPolicyManager { + + void onForegroundActivitiesChanged(int uid, int pid, boolean foregroundActivities); + void onProcessDied(int uid, int pid); + + void setUidPolicy(int uid, int policy); + int getUidPolicy(int uid); + + // TODO: build API to surface stats details for settings UI + +} diff --git a/core/java/android/net/NetworkPolicyManager.java b/core/java/android/net/NetworkPolicyManager.java new file mode 100644 index 0000000..2312bd9 --- /dev/null +++ b/core/java/android/net/NetworkPolicyManager.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net; + +import android.os.RemoteException; + +/** + * Manager for creating and modifying network policy rules. + * + * {@hide} + */ +public class NetworkPolicyManager { + + /** No specific network policy, use system default. */ + public static final int POLICY_NONE = 0x0; + /** Reject network usage when application in background. */ + public static final int POLICY_REJECT_BACKGROUND = 0x1; + /** Reject network usage on paid network connections. */ + public static final int POLICY_REJECT_PAID = 0x2; + /** Application should conserve data. */ + public static final int POLICY_CONSERVE_DATA = 0x4; + + private INetworkPolicyManager mService; + + public NetworkPolicyManager(INetworkPolicyManager service) { + if (service == null) { + throw new IllegalArgumentException("missing INetworkPolicyManager"); + } + mService = service; + } + + /** + * Set policy flags for specific UID. + * + * @param policy {@link #POLICY_NONE} or combination of + * {@link #POLICY_REJECT_BACKGROUND}, {@link #POLICY_REJECT_PAID}, + * or {@link #POLICY_CONSERVE_DATA}. + */ + public void setUidPolicy(int uid, int policy) { + try { + mService.setUidPolicy(uid, policy); + } catch (RemoteException e) { + } + } + + public int getUidPolicy(int uid) { + try { + return mService.getUidPolicy(uid); + } catch (RemoteException e) { + return POLICY_NONE; + } + } + +} |