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.wifi;
18 
19 import android.content.pm.UserInfo;
20 import android.net.wifi.WifiConfiguration;
21 import android.os.UserHandle;
22 
23 import java.util.List;
24 
25 /**
26  * Helper for working with {@link android.net.wifi.WifiConfiguration} objects.
27  */
28 public class WifiConfigurationUtil {
29     /**
30      * Check whether a network configuration is visible to a user or any of its managed profiles.
31      * @param config the network configuration whose visibility should be checked
32      * @param profiles the user IDs of the user itself and all its managed profiles (can be obtained
33      *         via {@link android.os.UserManager.getProfiles})
34      * @return whether the network configuration is visible to the user or any of its managed
35      *         profiles
36      */
isVisibleToAnyProfile(WifiConfiguration config, List<UserInfo> profiles)37     public static boolean isVisibleToAnyProfile(WifiConfiguration config, List<UserInfo> profiles) {
38         if (config.shared) {
39             return true;
40         }
41         final int creatorUserId = UserHandle.getUserId(config.creatorUid);
42         for (UserInfo profile : profiles) {
43             if (profile.id == creatorUserId) {
44                 return true;
45             }
46         }
47         return false;
48     }
49 }
50