10fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski/* 20fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * Copyright (C) 2016 The Android Open Source Project 30fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * 40fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * Licensed under the Apache License, Version 2.0 (the "License"); 50fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * you may not use this file except in compliance with the License. 60fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * You may obtain a copy of the License at 70fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * 80fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * http://www.apache.org/licenses/LICENSE-2.0 90fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * 100fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * Unless required by applicable law or agreed to in writing, software 110fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * distributed under the License is distributed on an "AS IS" BASIS, 120fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * See the License for the specific language governing permissions and 140fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * limitations under the License. 150fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski */ 160fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski 170fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowskipackage com.android.server.wifi; 180fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski 190fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowskiimport android.content.pm.UserInfo; 200fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowskiimport android.net.wifi.WifiConfiguration; 210fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowskiimport android.os.UserHandle; 220fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski 230fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowskiimport java.util.List; 240fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski 250fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski/** 260fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * Helper for working with {@link android.net.wifi.WifiConfiguration} objects. 270fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski */ 280fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowskipublic class WifiConfigurationUtil { 290fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski /** 300fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * Check whether a network configuration is visible to a user or any of its managed profiles. 310fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * @param config the network configuration whose visibility should be checked 320fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * @param profiles the user IDs of the user itself and all its managed profiles (can be obtained 330fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * via {@link android.os.UserManager.getProfiles}) 340fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * @return whether the network configuration is visible to the user or any of its managed 350fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski * profiles 360fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski */ 370fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski public static boolean isVisibleToAnyProfile(WifiConfiguration config, List<UserInfo> profiles) { 380fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski if (config.shared) { 390fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski return true; 400fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski } 410fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski final int creatorUserId = UserHandle.getUserId(config.creatorUid); 420fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski for (UserInfo profile : profiles) { 430fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski if (profile.id == creatorUserId) { 440fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski return true; 450fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski } 460fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski } 470fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski return false; 480fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski } 490fb9cf43830d67894b519c9a6271320c4842a5c0Bartosz Fabianowski} 50