NetworkPolicyManager.java revision d5cdd597b895a48ffa9a8e39f8a2504cd9b905c4
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.net;
18
19import android.os.RemoteException;
20
21/**
22 * Manager for creating and modifying network policy rules.
23 *
24 * {@hide}
25 */
26public class NetworkPolicyManager {
27
28    /** No specific network policy, use system default. */
29    public static final int POLICY_NONE = 0x0;
30    /** Reject network usage when application in background. */
31    public static final int POLICY_REJECT_BACKGROUND = 0x1;
32    /** Reject network usage on paid network connections. */
33    public static final int POLICY_REJECT_PAID = 0x2;
34    /** Application should conserve data. */
35    public static final int POLICY_CONSERVE_DATA = 0x4;
36
37    private INetworkPolicyManager mService;
38
39    public NetworkPolicyManager(INetworkPolicyManager service) {
40        if (service == null) {
41            throw new IllegalArgumentException("missing INetworkPolicyManager");
42        }
43        mService = service;
44    }
45
46    /**
47     * Set policy flags for specific UID.
48     *
49     * @param policy {@link #POLICY_NONE} or combination of
50     *            {@link #POLICY_REJECT_BACKGROUND}, {@link #POLICY_REJECT_PAID},
51     *            or {@link #POLICY_CONSERVE_DATA}.
52     */
53    public void setUidPolicy(int uid, int policy) {
54        try {
55            mService.setUidPolicy(uid, policy);
56        } catch (RemoteException e) {
57        }
58    }
59
60    public int getUidPolicy(int uid) {
61        try {
62            return mService.getUidPolicy(uid);
63        } catch (RemoteException e) {
64            return POLICY_NONE;
65        }
66    }
67
68}
69