• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 
17 package com.android.server.net;
18 
19 import static com.android.server.net.NetworkPolicyManagerService.isUidNetworkingBlockedInternal;
20 
21 import android.net.Network;
22 import android.net.NetworkTemplate;
23 import android.telephony.SubscriptionPlan;
24 
25 import java.util.Set;
26 
27 /**
28  * Network Policy Manager local system service interface.
29  *
30  * @hide Only for use within the system server.
31  */
32 public abstract class NetworkPolicyManagerInternal {
33 
34     /**
35      * Resets all policies associated with a given user.
36      */
resetUserState(int userId)37     public abstract void resetUserState(int userId);
38 
39     /**
40      * @return true if the given uid is restricted from doing networking on metered networks.
41      */
isUidRestrictedOnMeteredNetworks(int uid)42     public abstract boolean isUidRestrictedOnMeteredNetworks(int uid);
43 
44     /**
45      * @return true if networking is blocked on the given interface for the given uid according
46      * to current networking policies.
47      */
isUidNetworkingBlocked(int uid, String ifname)48     public abstract boolean isUidNetworkingBlocked(int uid, String ifname);
49 
50     /**
51      * Figure out if networking is blocked for a given set of conditions.
52      *
53      * This is used by ConnectivityService via passing stale copies of conditions, so it must not
54      * take any locks.
55      *
56      * @param uid The target uid.
57      * @param uidRules The uid rules which are obtained from NetworkPolicyManagerService.
58      * @param isNetworkMetered True if the network is metered.
59      * @param isBackgroundRestricted True if data saver is enabled.
60      *
61      * @return true if networking is blocked for the UID under the specified conditions.
62      */
isUidNetworkingBlocked(int uid, int uidRules, boolean isNetworkMetered, boolean isBackgroundRestricted)63     public static boolean isUidNetworkingBlocked(int uid, int uidRules, boolean isNetworkMetered,
64             boolean isBackgroundRestricted) {
65         // Log of invoking internal function is disabled because it will be called very
66         // frequently. And metrics are unlikely needed on this method because the callers are
67         // external and this method doesn't take any locks or perform expensive operations.
68         return isUidNetworkingBlockedInternal(uid, uidRules, isNetworkMetered,
69                 isBackgroundRestricted, null);
70     }
71 
72     /**
73      * Informs that an appId has been added or removed from the temp-powersave-whitelist so that
74      * that network rules for that appId can be updated.
75      *
76      * @param appId The appId which has been updated in the whitelist.
77      * @param added Denotes whether the {@param appId} has been added or removed from the whitelist.
78      */
onTempPowerSaveWhitelistChange(int appId, boolean added)79     public abstract void onTempPowerSaveWhitelistChange(int appId, boolean added);
80 
81     /**
82      * Return the active {@link SubscriptionPlan} for the given network.
83      */
getSubscriptionPlan(Network network)84     public abstract SubscriptionPlan getSubscriptionPlan(Network network);
85 
86     /**
87      * Return the active {@link SubscriptionPlan} for the given template.
88      */
getSubscriptionPlan(NetworkTemplate template)89     public abstract SubscriptionPlan getSubscriptionPlan(NetworkTemplate template);
90 
91     public static final int QUOTA_TYPE_JOBS = 1;
92     public static final int QUOTA_TYPE_MULTIPATH = 2;
93 
94     /**
95      * Return the daily quota (in bytes) that can be opportunistically used on
96      * the given network to improve the end user experience. It's called
97      * "opportunistic" because it's traffic that would typically not use the
98      * given network.
99      */
getSubscriptionOpportunisticQuota(Network network, int quotaType)100     public abstract long getSubscriptionOpportunisticQuota(Network network, int quotaType);
101 
102     /**
103      * Informs that admin data is loaded and available.
104      */
onAdminDataAvailable()105     public abstract void onAdminDataAvailable();
106 
107     /**
108      * Control if a UID should be whitelisted even if it's in app idle mode. Other restrictions may
109      * still be in effect.
110      */
setAppIdleWhitelist(int uid, boolean shouldWhitelist)111     public abstract void setAppIdleWhitelist(int uid, boolean shouldWhitelist);
112 
113     /**
114      * Sets a list of packages which are restricted by admin from accessing metered data.
115      *
116      * @param packageNames the list of restricted packages.
117      * @param userId the userId in which {@param packagesNames} are restricted.
118      */
setMeteredRestrictedPackages( Set<String> packageNames, int userId)119     public abstract void setMeteredRestrictedPackages(
120             Set<String> packageNames, int userId);
121 
122 
123     /**
124      * Similar to {@link #setMeteredRestrictedPackages(Set, int)} but updates the restricted
125      * packages list asynchronously.
126      */
setMeteredRestrictedPackagesAsync( Set<String> packageNames, int userId)127     public abstract void setMeteredRestrictedPackagesAsync(
128             Set<String> packageNames, int userId);
129 }
130