blob: fc96004e7dcb9733a7f97244907a7bb7c3d2decf [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 Sharkey8fc27e82012-04-04 20:40:58 -070020import static android.net.NetworkPolicy.CYCLE_NONE;
Jeff Sharkeycd2ca402011-06-10 15:14:07 -070021
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060022import android.annotation.SystemService;
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;
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -070031import android.os.RemoteException;
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -070032import android.os.UserHandle;
Felipe Leme46c4fc32016-05-04 09:21:43 -070033import android.util.DebugUtils;
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -070034
Jeff Sharkey4414cea2011-06-24 17:05:24 -070035import com.google.android.collect.Sets;
36
Jeff Sharkeyf2bead52016-07-06 17:11:48 -060037import java.util.Calendar;
Jeff Sharkey4414cea2011-06-24 17:05:24 -070038import java.util.HashSet;
Jeff Sharkeyf2bead52016-07-06 17:11:48 -060039import java.util.TimeZone;
Jeff Sharkey1b861272011-05-22 00:34:52 -070040
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -070041/**
42 * Manager for creating and modifying network policy rules.
43 *
44 * {@hide}
45 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060046@SystemService(Context.NETWORK_POLICY_SERVICE)
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -070047public class NetworkPolicyManager {
48
Felipe Leme46b451f2016-08-19 08:46:17 -070049 /* POLICY_* are masks and can be ORed, although currently they are not.*/
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -070050 /** No specific network policy, use system default. */
51 public static final int POLICY_NONE = 0x0;
Jeff Sharkeyfdfef572011-06-16 15:07:48 -070052 /** Reject network usage on metered networks when application in background. */
53 public static final int POLICY_REJECT_METERED_BACKGROUND = 0x1;
Felipe Leme46b451f2016-08-19 08:46:17 -070054 /** Allow metered network use in the background even when in data usage save mode. */
55 public static final int POLICY_ALLOW_METERED_BACKGROUND = 0x4;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070056
Felipe Leme46c4fc32016-05-04 09:21:43 -070057 /*
58 * Rules defining whether an uid has access to a network given its type (metered / non-metered).
59 *
60 * These rules are bits and can be used in bitmask operations; in particular:
61 * - rule & RULE_MASK_METERED: returns the metered-networks status.
62 * - rule & RULE_MASK_ALL: returns the all-networks status.
63 *
64 * The RULE_xxx_ALL rules applies to all networks (metered or non-metered), but on
65 * metered networks, the RULE_xxx_METERED rules should be checked first. For example,
66 * if the device is on Battery Saver Mode and Data Saver Mode simulatenously, and a uid
67 * is whitelisted for the former but not the latter, its status would be
68 * RULE_REJECT_METERED | RULE_ALLOW_ALL, meaning it could have access to non-metered
69 * networks but not to metered networks.
70 *
71 * See network-policy-restrictions.md for more info.
72 */
73 /** No specific rule was set */
74 public static final int RULE_NONE = 0;
Felipe Leme70c57c22016-03-29 10:45:13 -070075 /** Allow traffic on metered networks. */
Felipe Leme46c4fc32016-05-04 09:21:43 -070076 public static final int RULE_ALLOW_METERED = 1 << 0;
Felipe Leme70c57c22016-03-29 10:45:13 -070077 /** Temporarily allow traffic on metered networks because app is on foreground. */
Felipe Leme46c4fc32016-05-04 09:21:43 -070078 public static final int RULE_TEMPORARY_ALLOW_METERED = 1 << 1;
79 /** Reject traffic on metered networks. */
80 public static final int RULE_REJECT_METERED = 1 << 2;
81 /** Network traffic should be allowed on all networks (metered or non-metered), although
82 * metered-network restrictions could still apply. */
83 public static final int RULE_ALLOW_ALL = 1 << 5;
84 /** Reject traffic on all networks. */
85 public static final int RULE_REJECT_ALL = 1 << 6;
86 /** Mask used to get the {@code RULE_xxx_METERED} rules */
87 public static final int MASK_METERED_NETWORKS = 0b00001111;
88 /** Mask used to get the {@code RULE_xxx_ALL} rules */
89 public static final int MASK_ALL_NETWORKS = 0b11110000;
Amith Yamasani15e472352015-04-24 19:06:07 -070090
91 public static final int FIREWALL_RULE_DEFAULT = 0;
92 public static final int FIREWALL_RULE_ALLOW = 1;
93 public static final int FIREWALL_RULE_DENY = 2;
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -070094
Xiaohui Chenb41c9f72015-06-17 15:55:37 -070095 public static final int FIREWALL_TYPE_WHITELIST = 0;
96 public static final int FIREWALL_TYPE_BLACKLIST = 1;
97
98 public static final int FIREWALL_CHAIN_NONE = 0;
99 public static final int FIREWALL_CHAIN_DOZABLE = 1;
100 public static final int FIREWALL_CHAIN_STANDBY = 2;
Felipe Leme011b98f2016-02-10 17:28:31 -0800101 public static final int FIREWALL_CHAIN_POWERSAVE = 3;
Xiaohui Chenb41c9f72015-06-17 15:55:37 -0700102
103 public static final String FIREWALL_CHAIN_NAME_NONE = "none";
104 public static final String FIREWALL_CHAIN_NAME_DOZABLE = "dozable";
105 public static final String FIREWALL_CHAIN_NAME_STANDBY = "standby";
Felipe Leme011b98f2016-02-10 17:28:31 -0800106 public static final String FIREWALL_CHAIN_NAME_POWERSAVE = "powersave";
Xiaohui Chenb41c9f72015-06-17 15:55:37 -0700107
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -0700108 private static final boolean ALLOW_PLATFORM_APP_POLICY = true;
109
Jeff Sharkey14711eb2011-06-15 10:29:17 -0700110 /**
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -0700111 * {@link Intent} extra that indicates which {@link NetworkTemplate} rule it
112 * applies to.
Jeff Sharkey14711eb2011-06-15 10:29:17 -0700113 */
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -0700114 public static final String EXTRA_NETWORK_TEMPLATE = "android.net.NETWORK_TEMPLATE";
Jeff Sharkey14711eb2011-06-15 10:29:17 -0700115
Svet Ganov16a16892015-04-16 10:32:04 -0700116 private final Context mContext;
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700117 private INetworkPolicyManager mService;
118
Svet Ganov16a16892015-04-16 10:32:04 -0700119 public NetworkPolicyManager(Context context, INetworkPolicyManager service) {
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700120 if (service == null) {
121 throw new IllegalArgumentException("missing INetworkPolicyManager");
122 }
Svet Ganov16a16892015-04-16 10:32:04 -0700123 mContext = context;
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700124 mService = service;
125 }
126
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700127 public static NetworkPolicyManager from(Context context) {
Jeff Sharkeyeedcb952011-05-17 14:55:15 -0700128 return (NetworkPolicyManager) context.getSystemService(Context.NETWORK_POLICY_SERVICE);
129 }
130
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700131 /**
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -0700132 * Set policy flags for specific UID.
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700133 *
Felipe Leme8546a442016-08-23 09:38:20 -0700134 * @param policy should be {@link #POLICY_NONE} or any combination of {@code POLICY_} flags,
135 * although it is not validated.
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700136 */
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -0700137 public void setUidPolicy(int uid, int policy) {
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700138 try {
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -0700139 mService.setUidPolicy(uid, policy);
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700140 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700141 throw e.rethrowFromSystemServer();
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700142 }
143 }
144
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700145 /**
Felipe Leme8546a442016-08-23 09:38:20 -0700146 * Add policy flags for specific UID.
147 *
148 * <p>The given policy bits will be set for the uid.
149 *
150 * @param policy should be {@link #POLICY_NONE} or any combination of {@code POLICY_} flags,
151 * although it is not validated.
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700152 */
153 public void addUidPolicy(int uid, int policy) {
154 try {
155 mService.addUidPolicy(uid, policy);
156 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700157 throw e.rethrowFromSystemServer();
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700158 }
159 }
160
161 /**
Felipe Leme8546a442016-08-23 09:38:20 -0700162 * Clear/remove policy flags for specific UID.
163 *
164 * <p>The given policy bits will be set for the uid.
165 *
166 * @param policy should be {@link #POLICY_NONE} or any combination of {@code POLICY_} flags,
167 * although it is not validated.
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700168 */
169 public void removeUidPolicy(int uid, int policy) {
170 try {
171 mService.removeUidPolicy(uid, policy);
172 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700173 throw e.rethrowFromSystemServer();
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700174 }
175 }
176
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -0700177 public int getUidPolicy(int uid) {
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700178 try {
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -0700179 return mService.getUidPolicy(uid);
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700180 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700181 throw e.rethrowFromSystemServer();
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700182 }
183 }
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700184
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -0700185 public int[] getUidsWithPolicy(int policy) {
Jeff Sharkey854b2b12012-04-13 16:03:40 -0700186 try {
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -0700187 return mService.getUidsWithPolicy(policy);
Jeff Sharkey854b2b12012-04-13 16:03:40 -0700188 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700189 throw e.rethrowFromSystemServer();
Jeff Sharkey854b2b12012-04-13 16:03:40 -0700190 }
191 }
192
Jeff Sharkey1a303952011-06-16 13:04:20 -0700193 public void registerListener(INetworkPolicyListener listener) {
194 try {
195 mService.registerListener(listener);
196 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700197 throw e.rethrowFromSystemServer();
Jeff Sharkey1a303952011-06-16 13:04:20 -0700198 }
199 }
200
201 public void unregisterListener(INetworkPolicyListener listener) {
202 try {
203 mService.unregisterListener(listener);
204 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700205 throw e.rethrowFromSystemServer();
Jeff Sharkey1a303952011-06-16 13:04:20 -0700206 }
207 }
208
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700209 public void setNetworkPolicies(NetworkPolicy[] policies) {
210 try {
211 mService.setNetworkPolicies(policies);
212 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700213 throw e.rethrowFromSystemServer();
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700214 }
215 }
216
217 public NetworkPolicy[] getNetworkPolicies() {
218 try {
Svet Ganov16a16892015-04-16 10:32:04 -0700219 return mService.getNetworkPolicies(mContext.getOpPackageName());
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700220 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700221 throw e.rethrowFromSystemServer();
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700222 }
223 }
224
225 public void setRestrictBackground(boolean restrictBackground) {
226 try {
227 mService.setRestrictBackground(restrictBackground);
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
233 public boolean getRestrictBackground() {
234 try {
235 return mService.getRestrictBackground();
236 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700237 throw e.rethrowFromSystemServer();
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700238 }
239 }
240
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700241 /**
Stuart Scott984dc852015-03-30 13:17:11 -0700242 * Resets network policy settings back to factory defaults.
243 *
244 * @hide
245 */
246 public void factoryReset(String subscriber) {
Stuart Scottf1fb3972015-04-02 18:00:02 -0700247 try {
248 mService.factoryReset(subscriber);
249 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700250 throw e.rethrowFromSystemServer();
Stuart Scott984dc852015-03-30 13:17:11 -0700251 }
252 }
253
254 /**
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700255 * Compute the last cycle boundary for the given {@link NetworkPolicy}. For
256 * example, if cycle day is 20th, and today is June 15th, it will return May
257 * 20th. When cycle day doesn't exist in current month, it snaps to the 1st
258 * of following month.
259 *
260 * @hide
261 */
262 public static long computeLastCycleBoundary(long currentTime, NetworkPolicy policy) {
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700263 if (policy.cycleDay == CYCLE_NONE) {
264 throw new IllegalArgumentException("Unable to compute boundary without cycleDay");
265 }
266
Jeff Sharkeyf2bead52016-07-06 17:11:48 -0600267 final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(policy.cycleTimezone));
268 cal.setTimeInMillis(currentTime);
269 snapToCycleDay(cal, policy.cycleDay);
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700270
Jeff Sharkeyf2bead52016-07-06 17:11:48 -0600271 if (cal.getTimeInMillis() >= currentTime) {
272 // Cycle boundary is beyond now, use last cycle boundary
273 cal.set(Calendar.DAY_OF_MONTH, 1);
274 cal.add(Calendar.MONTH, -1);
275 snapToCycleDay(cal, policy.cycleDay);
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700276 }
277
Jeff Sharkeyf2bead52016-07-06 17:11:48 -0600278 return cal.getTimeInMillis();
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700279 }
280
281 /** {@hide} */
282 public static long computeNextCycleBoundary(long currentTime, NetworkPolicy policy) {
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700283 if (policy.cycleDay == CYCLE_NONE) {
284 throw new IllegalArgumentException("Unable to compute boundary without cycleDay");
285 }
286
Jeff Sharkeyf2bead52016-07-06 17:11:48 -0600287 final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(policy.cycleTimezone));
288 cal.setTimeInMillis(currentTime);
289 snapToCycleDay(cal, policy.cycleDay);
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700290
Jeff Sharkeyf2bead52016-07-06 17:11:48 -0600291 if (cal.getTimeInMillis() <= currentTime) {
292 // Cycle boundary is before now, use next cycle boundary
293 cal.set(Calendar.DAY_OF_MONTH, 1);
294 cal.add(Calendar.MONTH, 1);
295 snapToCycleDay(cal, policy.cycleDay);
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700296 }
297
Jeff Sharkeyf2bead52016-07-06 17:11:48 -0600298 return cal.getTimeInMillis();
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700299 }
300
301 /**
302 * Snap to the cycle day for the current month given; when cycle day doesn't
Jeff Sharkey9bf31502012-03-09 17:07:21 -0800303 * exist, it snaps to last second of current month.
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700304 *
305 * @hide
306 */
Jeff Sharkeyf2bead52016-07-06 17:11:48 -0600307 public static void snapToCycleDay(Calendar cal, int cycleDay) {
308 cal.set(Calendar.HOUR_OF_DAY, 0);
309 cal.set(Calendar.MINUTE, 0);
310 cal.set(Calendar.SECOND, 0);
311 if (cycleDay > cal.getActualMaximum(Calendar.DAY_OF_MONTH)) {
Jeff Sharkeyf2bead52016-07-06 17:11:48 -0600312 cal.add(Calendar.MONTH, 1);
Shunta Satod18ffd82016-10-25 17:42:58 +0900313 cal.set(Calendar.DAY_OF_MONTH, 1);
314 cal.set(Calendar.HOUR_OF_DAY, 0);
315 cal.set(Calendar.MINUTE, 0);
316 cal.set(Calendar.SECOND, 0);
Jeff Sharkeyf2bead52016-07-06 17:11:48 -0600317 cal.add(Calendar.SECOND, -1);
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700318 } else {
Jeff Sharkeyf2bead52016-07-06 17:11:48 -0600319 cal.set(Calendar.DAY_OF_MONTH, cycleDay);
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700320 }
Jeff Sharkeycd2ca402011-06-10 15:14:07 -0700321 }
322
Jeff Sharkey497e4432011-06-14 17:27:29 -0700323 /**
324 * Check if given UID can have a {@link #setUidPolicy(int, int)} defined,
325 * usually to protect critical system services.
326 */
Jeff Sharkey8a8b5812012-03-21 18:13:36 -0700327 @Deprecated
Jeff Sharkey497e4432011-06-14 17:27:29 -0700328 public static boolean isUidValidForPolicy(Context context, int uid) {
Jeff Sharkey4414cea2011-06-24 17:05:24 -0700329 // first, quick-reject non-applications
Jeff Sharkeyd0c6ccb2012-09-14 16:26:37 -0700330 if (!UserHandle.isApp(uid)) {
Jeff Sharkey4414cea2011-06-24 17:05:24 -0700331 return false;
332 }
333
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -0700334 if (!ALLOW_PLATFORM_APP_POLICY) {
335 final PackageManager pm = context.getPackageManager();
336 final HashSet<Signature> systemSignature;
337 try {
338 systemSignature = Sets.newHashSet(
339 pm.getPackageInfo("android", GET_SIGNATURES).signatures);
340 } catch (NameNotFoundException e) {
341 throw new RuntimeException("problem finding system signature", e);
Jeff Sharkey4414cea2011-06-24 17:05:24 -0700342 }
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -0700343
344 try {
345 // reject apps signed with platform cert
346 for (String packageName : pm.getPackagesForUid(uid)) {
347 final HashSet<Signature> packageSignature = Sets.newHashSet(
348 pm.getPackageInfo(packageName, GET_SIGNATURES).signatures);
349 if (packageSignature.containsAll(systemSignature)) {
350 return false;
351 }
352 }
353 } catch (NameNotFoundException e) {
354 }
Jeff Sharkey4414cea2011-06-24 17:05:24 -0700355 }
356
357 // nothing found above; we can apply policy to UID
358 return true;
Jeff Sharkey497e4432011-06-14 17:27:29 -0700359 }
Felipe Leme46c4fc32016-05-04 09:21:43 -0700360
Felipe Lemeb146f762016-08-19 09:52:16 -0700361 /**
Felipe Leme46c4fc32016-05-04 09:21:43 -0700362 * @hide
363 */
364 public static String uidRulesToString(int uidRules) {
365 final StringBuilder string = new StringBuilder().append(uidRules).append(" (");
366 if (uidRules == RULE_NONE) {
367 string.append("NONE");
368 } else {
369 string.append(DebugUtils.flagsToString(NetworkPolicyManager.class, "RULE_", uidRules));
370 }
371 string.append(")");
372 return string.toString();
373 }
Felipe Lemeb146f762016-08-19 09:52:16 -0700374
375 /**
376 * @hide
377 */
378 public static String uidPoliciesToString(int uidPolicies) {
379 final StringBuilder string = new StringBuilder().append(uidPolicies).append(" (");
380 if (uidPolicies == POLICY_NONE) {
381 string.append("NONE");
382 } else {
383 string.append(DebugUtils.flagsToString(NetworkPolicyManager.class,
384 "POLICY_", uidPolicies));
385 }
386 string.append(")");
387 return string.toString();
388 }
Sudheer Shankae359c3d2017-02-22 18:41:29 -0800389
390 /**
391 * Returns true if {@param procState} is considered foreground and as such will be allowed
392 * to access network when the device is idle or in battery saver mode. Otherwise, false.
393 */
394 public static boolean isProcStateAllowedWhileIdleOrPowerSaveMode(int procState) {
395 return procState <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE;
396 }
397
398 /**
399 * Returns true if {@param procState} is considered foreground and as such will be allowed
400 * to access network when the device is in data saver mode. Otherwise, false.
401 */
402 public static boolean isProcStateAllowedWhileOnRestrictBackground(int procState) {
403 return procState <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE;
404 }
Jeff Sharkey43d2a172017-07-12 10:50:42 -0600405
406 public static String resolveNetworkId(WifiConfiguration config) {
407 return WifiInfo.removeDoubleQuotes(config.isPasspoint()
408 ? config.providerFriendlyName : config.SSID);
409 }
410
411 public static String resolveNetworkId(String ssid) {
412 return WifiInfo.removeDoubleQuotes(ssid);
413 }
Jeff Sharkeyd5cdd592011-05-03 20:27:17 -0700414}