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/net/NetworkPolicyManager.java | |
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/net/NetworkPolicyManager.java')
-rw-r--r-- | core/java/android/net/NetworkPolicyManager.java | 68 |
1 files changed, 68 insertions, 0 deletions
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; + } + } + +} |