blob: 5ab34e9aa6e8a6537e7b7349377be5f4dfc65edc [file] [log] [blame]
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -07001/*
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
Jeff Sharkey4414cea2011-06-24 17:05:24 -070019import static android.content.pm.PackageManager.GET_SIGNATURES;
Jeff Sharkeycd2ca402011-06-10 15:14:07 -070020
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060021import android.annotation.SystemService;
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010022import android.annotation.UnsupportedAppUsage;
Sudheer Shankae359c3d2017-02-22 18:41:29 -080023import android.app.ActivityManager;
Jeff Sharkeyeedcb952011-05-17 14:55:15 -070024import android.content.Context;
Jeff Sharkey14711eb2011-06-15 10:29:17 -070025import android.content.Intent;
Jeff Sharkey4414cea2011-06-24 17:05:24 -070026import android.content.pm.PackageManager;
27import android.content.pm.PackageManager.NameNotFoundException;
28import android.content.pm.Signature;
Jeff Sharkey43d2a172017-07-12 10:50:42 -060029import android.net.wifi.WifiConfiguration;
30import android.net.wifi.WifiInfo;
Mathew Inwood31755f92018-12-20 13:53:36 +000031import android.os.Build;
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -070032import android.os.RemoteException;
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -070033import android.os.UserHandle;
Felipe Leme46c4fc32016-05-04 09:21:43 -070034import android.util.DebugUtils;
Jeff Sharkey53313d72017-07-13 16:47:32 -060035import android.util.Pair;
Jeff Sharkey0fc6d032018-03-30 16:25:11 -060036import android.util.Range;
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -070037
Jeff Sharkey4414cea2011-06-24 17:05:24 -070038import com.google.android.collect.Sets;
39
Jeff Sharkey53313d72017-07-13 16:47:32 -060040import java.time.ZonedDateTime;
Jeff Sharkey4414cea2011-06-24 17:05:24 -070041import java.util.HashSet;
Jeff Sharkey53313d72017-07-13 16:47:32 -060042import java.util.Iterator;
Jeff Sharkey1b861272011-05-22 00:34:52 -070043
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -070044/**
45 * Manager for creating and modifying network policy rules.
46 *
47 * {@hide}
48 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060049@SystemService(Context.NETWORK_POLICY_SERVICE)
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -070050public class NetworkPolicyManager {
51
Felipe Leme46b451f2016-08-19 08:46:17 -070052 /* POLICY_* are masks and can be ORed, although currently they are not.*/
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -070053 /** No specific network policy, use system default. */
54 public static final int POLICY_NONE = 0x0;
Jeff Sharkeyfdfef572011-06-16 15:07:48 -070055 /** Reject network usage on metered networks when application in background. */
56 public static final int POLICY_REJECT_METERED_BACKGROUND = 0x1;
Felipe Leme46b451f2016-08-19 08:46:17 -070057 /** Allow metered network use in the background even when in data usage save mode. */
58 public static final int POLICY_ALLOW_METERED_BACKGROUND = 0x4;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070059
Felipe Leme46c4fc32016-05-04 09:21:43 -070060 /*
61 * Rules defining whether an uid has access to a network given its type (metered / non-metered).
62 *
63 * These rules are bits and can be used in bitmask operations; in particular:
64 * - rule & RULE_MASK_METERED: returns the metered-networks status.
65 * - rule & RULE_MASK_ALL: returns the all-networks status.
66 *
67 * The RULE_xxx_ALL rules applies to all networks (metered or non-metered), but on
68 * metered networks, the RULE_xxx_METERED rules should be checked first. For example,
69 * if the device is on Battery Saver Mode and Data Saver Mode simulatenously, and a uid
70 * is whitelisted for the former but not the latter, its status would be
71 * RULE_REJECT_METERED | RULE_ALLOW_ALL, meaning it could have access to non-metered
72 * networks but not to metered networks.
73 *
74 * See network-policy-restrictions.md for more info.
75 */
76 /** No specific rule was set */
77 public static final int RULE_NONE = 0;
Felipe Leme70c57c22016-03-29 10:45:13 -070078 /** Allow traffic on metered networks. */
Felipe Leme46c4fc32016-05-04 09:21:43 -070079 public static final int RULE_ALLOW_METERED = 1 << 0;
Felipe Leme70c57c22016-03-29 10:45:13 -070080 /** Temporarily allow traffic on metered networks because app is on foreground. */
Felipe Leme46c4fc32016-05-04 09:21:43 -070081 public static final int RULE_TEMPORARY_ALLOW_METERED = 1 << 1;
82 /** Reject traffic on metered networks. */
83 public static final int RULE_REJECT_METERED = 1 << 2;
84 /** Network traffic should be allowed on all networks (metered or non-metered), although
85 * metered-network restrictions could still apply. */
86 public static final int RULE_ALLOW_ALL = 1 << 5;
87 /** Reject traffic on all networks. */
88 public static final int RULE_REJECT_ALL = 1 << 6;
89 /** Mask used to get the {@code RULE_xxx_METERED} rules */
90 public static final int MASK_METERED_NETWORKS = 0b00001111;
91 /** Mask used to get the {@code RULE_xxx_ALL} rules */
92 public static final int MASK_ALL_NETWORKS = 0b11110000;
Amith Yamasani15e472352015-04-24 19:06:07 -070093
94 public static final int FIREWALL_RULE_DEFAULT = 0;
Luke Huanga241db92018-07-31 20:15:24 +080095 public static final int FIREWALL_RULE_ALLOW = INetd.FIREWALL_RULE_ALLOW;
96 public static final int FIREWALL_RULE_DENY = INetd.FIREWALL_RULE_DENY;
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -070097
Luke Huanga241db92018-07-31 20:15:24 +080098 public static final int FIREWALL_TYPE_WHITELIST = INetd.FIREWALL_WHITELIST;
99 public static final int FIREWALL_TYPE_BLACKLIST = INetd.FIREWALL_BLACKLIST;
Xiaohui Chenb41c9f72015-06-17 15:55:37 -0700100
Luke Huanga241db92018-07-31 20:15:24 +0800101 public static final int FIREWALL_CHAIN_NONE = INetd.FIREWALL_CHAIN_NONE;
102 public static final int FIREWALL_CHAIN_DOZABLE = INetd.FIREWALL_CHAIN_DOZABLE;
103 public static final int FIREWALL_CHAIN_STANDBY = INetd.FIREWALL_CHAIN_STANDBY;
104 public static final int FIREWALL_CHAIN_POWERSAVE = INetd.FIREWALL_CHAIN_POWERSAVE;
Xiaohui Chenb41c9f72015-06-17 15:55:37 -0700105
106 public static final String FIREWALL_CHAIN_NAME_NONE = "none";
107 public static final String FIREWALL_CHAIN_NAME_DOZABLE = "dozable";
108 public static final String FIREWALL_CHAIN_NAME_STANDBY = "standby";
Felipe Leme011b98f2016-02-10 17:28:31 -0800109 public static final String FIREWALL_CHAIN_NAME_POWERSAVE = "powersave";
Xiaohui Chenb41c9f72015-06-17 15:55:37 -0700110
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -0700111 private static final boolean ALLOW_PLATFORM_APP_POLICY = true;
112
Sudheer Shankad993dcf2018-02-11 12:22:16 -0800113 public static final int FOREGROUND_THRESHOLD_STATE =
114 ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
115
Jeff Sharkey14711eb2011-06-15 10:29:17 -0700116 /**
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -0700117 * {@link Intent} extra that indicates which {@link NetworkTemplate} rule it
118 * applies to.
Jeff Sharkey14711eb2011-06-15 10:29:17 -0700119 */
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -0700120 public static final String EXTRA_NETWORK_TEMPLATE = "android.net.NETWORK_TEMPLATE";
Jeff Sharkey14711eb2011-06-15 10:29:17 -0700121
Jeff Sharkey75d31892018-01-18 22:01:59 +0900122 public static final int OVERRIDE_UNMETERED = 1 << 0;
123 public static final int OVERRIDE_CONGESTED = 1 << 1;
124
Svet Ganov16a16892015-04-16 10:32:04 -0700125 private final Context mContext;
Mathew Inwoodfa3a7462018-08-08 14:52:47 +0100126 @UnsupportedAppUsage
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700127 private INetworkPolicyManager mService;
128
Svet Ganov16a16892015-04-16 10:32:04 -0700129 public NetworkPolicyManager(Context context, INetworkPolicyManager service) {
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700130 if (service == null) {
131 throw new IllegalArgumentException("missing INetworkPolicyManager");
132 }
Svet Ganov16a16892015-04-16 10:32:04 -0700133 mContext = context;
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700134 mService = service;
135 }
136
Mathew Inwoodfa3a7462018-08-08 14:52:47 +0100137 @UnsupportedAppUsage
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700138 public static NetworkPolicyManager from(Context context) {
Jeff Sharkeyeedcb952011-05-17 14:55:15 -0700139 return (NetworkPolicyManager) context.getSystemService(Context.NETWORK_POLICY_SERVICE);
140 }
141
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700142 /**
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -0700143 * Set policy flags for specific UID.
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700144 *
Felipe Leme8546a442016-08-23 09:38:20 -0700145 * @param policy should be {@link #POLICY_NONE} or any combination of {@code POLICY_} flags,
146 * although it is not validated.
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700147 */
Mathew Inwoodfa3a7462018-08-08 14:52:47 +0100148 @UnsupportedAppUsage
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -0700149 public void setUidPolicy(int uid, int policy) {
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700150 try {
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -0700151 mService.setUidPolicy(uid, policy);
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700152 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700153 throw e.rethrowFromSystemServer();
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700154 }
155 }
156
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700157 /**
Felipe Leme8546a442016-08-23 09:38:20 -0700158 * Add policy flags for specific UID.
159 *
160 * <p>The given policy bits will be set for the uid.
161 *
162 * @param policy should be {@link #POLICY_NONE} or any combination of {@code POLICY_} flags,
163 * although it is not validated.
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700164 */
165 public void addUidPolicy(int uid, int policy) {
166 try {
167 mService.addUidPolicy(uid, policy);
168 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700169 throw e.rethrowFromSystemServer();
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700170 }
171 }
172
173 /**
Felipe Leme8546a442016-08-23 09:38:20 -0700174 * Clear/remove policy flags for specific UID.
175 *
176 * <p>The given policy bits will be set for the uid.
177 *
178 * @param policy should be {@link #POLICY_NONE} or any combination of {@code POLICY_} flags,
179 * although it is not validated.
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700180 */
181 public void removeUidPolicy(int uid, int policy) {
182 try {
183 mService.removeUidPolicy(uid, policy);
184 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700185 throw e.rethrowFromSystemServer();
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700186 }
187 }
188
Mathew Inwoodfa3a7462018-08-08 14:52:47 +0100189 @UnsupportedAppUsage
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -0700190 public int getUidPolicy(int uid) {
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700191 try {
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -0700192 return mService.getUidPolicy(uid);
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700193 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700194 throw e.rethrowFromSystemServer();
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700195 }
196 }
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700197
Mathew Inwoodfa3a7462018-08-08 14:52:47 +0100198 @UnsupportedAppUsage
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -0700199 public int[] getUidsWithPolicy(int policy) {
Jeff Sharkey854b2b12012-04-13 16:03:40 -0700200 try {
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -0700201 return mService.getUidsWithPolicy(policy);
Jeff Sharkey854b2b12012-04-13 16:03:40 -0700202 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700203 throw e.rethrowFromSystemServer();
Jeff Sharkey854b2b12012-04-13 16:03:40 -0700204 }
205 }
206
Mathew Inwood31755f92018-12-20 13:53:36 +0000207 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Jeff Sharkey1a303952011-06-16 13:04:20 -0700208 public void registerListener(INetworkPolicyListener listener) {
209 try {
210 mService.registerListener(listener);
211 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700212 throw e.rethrowFromSystemServer();
Jeff Sharkey1a303952011-06-16 13:04:20 -0700213 }
214 }
215
Mathew Inwood31755f92018-12-20 13:53:36 +0000216 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Jeff Sharkey1a303952011-06-16 13:04:20 -0700217 public void unregisterListener(INetworkPolicyListener listener) {
218 try {
219 mService.unregisterListener(listener);
220 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700221 throw e.rethrowFromSystemServer();
Jeff Sharkey1a303952011-06-16 13:04:20 -0700222 }
223 }
224
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700225 public void setNetworkPolicies(NetworkPolicy[] policies) {
226 try {
227 mService.setNetworkPolicies(policies);
228 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700229 throw e.rethrowFromSystemServer();
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700230 }
231 }
232
Mathew Inwoodfa3a7462018-08-08 14:52:47 +0100233 @UnsupportedAppUsage
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700234 public NetworkPolicy[] getNetworkPolicies() {
235 try {
Svet Ganov16a16892015-04-16 10:32:04 -0700236 return mService.getNetworkPolicies(mContext.getOpPackageName());
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700237 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700238 throw e.rethrowFromSystemServer();
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700239 }
240 }
241
Mathew Inwoodfa3a7462018-08-08 14:52:47 +0100242 @UnsupportedAppUsage
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700243 public void setRestrictBackground(boolean restrictBackground) {
244 try {
245 mService.setRestrictBackground(restrictBackground);
246 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700247 throw e.rethrowFromSystemServer();
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700248 }
249 }
250
Mathew Inwoodfa3a7462018-08-08 14:52:47 +0100251 @UnsupportedAppUsage
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700252 public boolean getRestrictBackground() {
253 try {
254 return mService.getRestrictBackground();
255 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700256 throw e.rethrowFromSystemServer();
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700257 }
258 }
259
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700260 /**
Stuart Scott984dc852015-03-30 13:17:11 -0700261 * Resets network policy settings back to factory defaults.
262 *
263 * @hide
264 */
265 public void factoryReset(String subscriber) {
Stuart Scottf1fb3972015-04-02 18:00:02 -0700266 try {
267 mService.factoryReset(subscriber);
268 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700269 throw e.rethrowFromSystemServer();
Stuart Scott984dc852015-03-30 13:17:11 -0700270 }
271 }
272
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700273 /** {@hide} */
Jeff Sharkey0fc6d032018-03-30 16:25:11 -0600274 @Deprecated
Jeff Sharkey53313d72017-07-13 16:47:32 -0600275 public static Iterator<Pair<ZonedDateTime, ZonedDateTime>> cycleIterator(NetworkPolicy policy) {
Jeff Sharkey0fc6d032018-03-30 16:25:11 -0600276 final Iterator<Range<ZonedDateTime>> it = policy.cycleIterator();
277 return new Iterator<Pair<ZonedDateTime, ZonedDateTime>>() {
278 @Override
279 public boolean hasNext() {
280 return it.hasNext();
281 }
282
283 @Override
284 public Pair<ZonedDateTime, ZonedDateTime> next() {
Jeff Sharkeye67463d2018-04-13 14:38:01 -0600285 if (hasNext()) {
286 final Range<ZonedDateTime> r = it.next();
287 return Pair.create(r.getLower(), r.getUpper());
288 } else {
289 return Pair.create(null, null);
290 }
Jeff Sharkey0fc6d032018-03-30 16:25:11 -0600291 }
292 };
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700293 }
294
Jeff Sharkey497e4432011-06-14 17:27:29 -0700295 /**
296 * Check if given UID can have a {@link #setUidPolicy(int, int)} defined,
297 * usually to protect critical system services.
298 */
Jeff Sharkey8a8b5812012-03-21 18:13:36 -0700299 @Deprecated
Jeff Sharkey497e4432011-06-14 17:27:29 -0700300 public static boolean isUidValidForPolicy(Context context, int uid) {
Jeff Sharkey4414cea2011-06-24 17:05:24 -0700301 // first, quick-reject non-applications
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -0700302 if (!UserHandle.isApp(uid)) {
Jeff Sharkey4414cea2011-06-24 17:05:24 -0700303 return false;
304 }
305
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -0700306 if (!ALLOW_PLATFORM_APP_POLICY) {
307 final PackageManager pm = context.getPackageManager();
308 final HashSet<Signature> systemSignature;
309 try {
310 systemSignature = Sets.newHashSet(
311 pm.getPackageInfo("android", GET_SIGNATURES).signatures);
312 } catch (NameNotFoundException e) {
313 throw new RuntimeException("problem finding system signature", e);
Jeff Sharkey4414cea2011-06-24 17:05:24 -0700314 }
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -0700315
316 try {
317 // reject apps signed with platform cert
318 for (String packageName : pm.getPackagesForUid(uid)) {
319 final HashSet<Signature> packageSignature = Sets.newHashSet(
320 pm.getPackageInfo(packageName, GET_SIGNATURES).signatures);
321 if (packageSignature.containsAll(systemSignature)) {
322 return false;
323 }
324 }
325 } catch (NameNotFoundException e) {
326 }
Jeff Sharkey4414cea2011-06-24 17:05:24 -0700327 }
328
329 // nothing found above; we can apply policy to UID
330 return true;
Jeff Sharkey497e4432011-06-14 17:27:29 -0700331 }
Felipe Leme46c4fc32016-05-04 09:21:43 -0700332
Felipe Lemeb146f762016-08-19 09:52:16 -0700333 /**
Felipe Leme46c4fc32016-05-04 09:21:43 -0700334 * @hide
335 */
336 public static String uidRulesToString(int uidRules) {
337 final StringBuilder string = new StringBuilder().append(uidRules).append(" (");
338 if (uidRules == RULE_NONE) {
339 string.append("NONE");
340 } else {
341 string.append(DebugUtils.flagsToString(NetworkPolicyManager.class, "RULE_", uidRules));
342 }
343 string.append(")");
344 return string.toString();
345 }
Felipe Lemeb146f762016-08-19 09:52:16 -0700346
347 /**
348 * @hide
349 */
350 public static String uidPoliciesToString(int uidPolicies) {
351 final StringBuilder string = new StringBuilder().append(uidPolicies).append(" (");
352 if (uidPolicies == POLICY_NONE) {
353 string.append("NONE");
354 } else {
355 string.append(DebugUtils.flagsToString(NetworkPolicyManager.class,
356 "POLICY_", uidPolicies));
357 }
358 string.append(")");
359 return string.toString();
360 }
Sudheer Shankae359c3d2017-02-22 18:41:29 -0800361
362 /**
363 * Returns true if {@param procState} is considered foreground and as such will be allowed
364 * to access network when the device is idle or in battery saver mode. Otherwise, false.
365 */
366 public static boolean isProcStateAllowedWhileIdleOrPowerSaveMode(int procState) {
Sudheer Shankad993dcf2018-02-11 12:22:16 -0800367 return procState <= FOREGROUND_THRESHOLD_STATE;
Sudheer Shankae359c3d2017-02-22 18:41:29 -0800368 }
369
370 /**
371 * Returns true if {@param procState} is considered foreground and as such will be allowed
372 * to access network when the device is in data saver mode. Otherwise, false.
373 */
374 public static boolean isProcStateAllowedWhileOnRestrictBackground(int procState) {
Sudheer Shankad993dcf2018-02-11 12:22:16 -0800375 return procState <= FOREGROUND_THRESHOLD_STATE;
Sudheer Shankae359c3d2017-02-22 18:41:29 -0800376 }
Jeff Sharkey43d2a172017-07-12 10:50:42 -0600377
378 public static String resolveNetworkId(WifiConfiguration config) {
379 return WifiInfo.removeDoubleQuotes(config.isPasspoint()
380 ? config.providerFriendlyName : config.SSID);
381 }
382
383 public static String resolveNetworkId(String ssid) {
384 return WifiInfo.removeDoubleQuotes(ssid);
385 }
Jeff Sharkey75d31892018-01-18 22:01:59 +0900386
387 /** {@hide} */
388 public static class Listener extends INetworkPolicyListener.Stub {
389 @Override public void onUidRulesChanged(int uid, int uidRules) { }
390 @Override public void onMeteredIfacesChanged(String[] meteredIfaces) { }
391 @Override public void onRestrictBackgroundChanged(boolean restrictBackground) { }
392 @Override public void onUidPoliciesChanged(int uid, int uidPolicies) { }
393 @Override public void onSubscriptionOverride(int subId, int overrideMask, int overrideValue) { }
394 }
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700395}