diff options
author | Mitchell Wills <mwills@google.com> | 2016-02-11 18:00:02 +0000 |
---|---|---|
committer | Android Partner Code Review <android-gerrit-partner@google.com> | 2016-02-11 18:00:03 +0000 |
commit | 4086badffeb97f4c87b2bed3fcaa49b731a6670e (patch) | |
tree | a99d9c1a9fbb7eb17e01ffeb5d6b42cfff533e99 /service | |
parent | 6eb121431c67b98d8b14242a34c28b205a42b119 (diff) | |
parent | 9f8586ea6d640e86560efd9a2d9c1909b08a3ef4 (diff) |
Merge "Revert "Allow managed profile to modify networks"" into mm-wireless-dev
Diffstat (limited to 'service')
6 files changed, 22 insertions, 116 deletions
diff --git a/service/java/com/android/server/wifi/ConfigurationMap.java b/service/java/com/android/server/wifi/ConfigurationMap.java index e84aafdfd..809952014 100644 --- a/service/java/com/android/server/wifi/ConfigurationMap.java +++ b/service/java/com/android/server/wifi/ConfigurationMap.java @@ -1,10 +1,7 @@ package com.android.server.wifi; -import android.content.Context; -import android.content.pm.UserInfo; import android.net.wifi.WifiConfiguration; import android.os.UserHandle; -import android.os.UserManager; import java.util.ArrayList; import java.util.Collection; @@ -20,20 +17,13 @@ public class ConfigurationMap { private final Map<Integer, WifiConfiguration> mPerIDForCurrentUser = new HashMap<>(); private final Map<String, WifiConfiguration> mPerFQDNForCurrentUser = new HashMap<>(); - private final UserManager mUserManager; - private int mCurrentUserId = UserHandle.USER_SYSTEM; - ConfigurationMap(Context context) { - mUserManager = UserManager.get(context); - } - // RW methods: public WifiConfiguration put(WifiConfiguration config) { final WifiConfiguration current = mPerID.put(config.networkId, config); mPerConfigKey.put(config.configKey().hashCode(), config); // This is ridiculous... - if (WifiConfigurationUtil.isVisibleToAnyProfile(config, - mUserManager.getProfiles(mCurrentUserId))) { + if (config.isVisibleToUser(mCurrentUserId)) { mPerIDForCurrentUser.put(config.networkId, config); if (config.FQDN != null && config.FQDN.length() > 0) { mPerFQDNForCurrentUser.put(config.FQDN, config); @@ -80,19 +70,18 @@ public class ConfigurationMap { mPerIDForCurrentUser.clear(); mPerFQDNForCurrentUser.clear(); - final List<UserInfo> previousUserProfiles = mUserManager.getProfiles(mCurrentUserId); + final int previousUserId = mCurrentUserId; mCurrentUserId = userId; - final List<UserInfo> currentUserProfiles = mUserManager.getProfiles(mCurrentUserId); final List<WifiConfiguration> hiddenConfigurations = new ArrayList<>(); for (Map.Entry<Integer, WifiConfiguration> entry : mPerID.entrySet()) { final WifiConfiguration config = entry.getValue(); - if (WifiConfigurationUtil.isVisibleToAnyProfile(config, currentUserProfiles)) { + if (config.isVisibleToUser(mCurrentUserId)) { mPerIDForCurrentUser.put(entry.getKey(), config); if (config.FQDN != null && config.FQDN.length() > 0) { mPerFQDNForCurrentUser.put(config.FQDN, config); } - } else if (WifiConfigurationUtil.isVisibleToAnyProfile(config, previousUserProfiles)) { + } else if (config.isVisibleToUser(previousUserId)) { hiddenConfigurations.add(config); } } diff --git a/service/java/com/android/server/wifi/FrameworkFacade.java b/service/java/com/android/server/wifi/FrameworkFacade.java index ef7d91dab..2ecfe07cc 100644 --- a/service/java/com/android/server/wifi/FrameworkFacade.java +++ b/service/java/com/android/server/wifi/FrameworkFacade.java @@ -1,7 +1,6 @@ package com.android.server.wifi; -import android.app.AppGlobals; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; @@ -9,7 +8,6 @@ import android.net.TrafficStats; import android.net.ip.IpManager; import android.os.Handler; import android.os.IBinder; -import android.os.RemoteException; import android.os.ServiceManager; import android.provider.Settings; @@ -68,15 +66,5 @@ public class FrameworkFacade { Context context, String iface, IpManager.Callback callback) { return new IpManager(context, iface, callback); } - - /** - * Checks whether the given uid has been granted the given permission. - * @param permName the permission to check - * @param uid The uid to check - * @return {@link PackageManager.PERMISSION_GRANTED} if the permission has been granted and - * {@link PackageManager.PERMISSION_DENIED} otherwise - */ - public int checkUidPermission(String permName, int uid) throws RemoteException { - return AppGlobals.getPackageManager().checkUidPermission(permName, uid); - } } + diff --git a/service/java/com/android/server/wifi/WifiConfigStore.java b/service/java/com/android/server/wifi/WifiConfigStore.java index 031d3bf1f..cc9e5068f 100644 --- a/service/java/com/android/server/wifi/WifiConfigStore.java +++ b/service/java/com/android/server/wifi/WifiConfigStore.java @@ -18,6 +18,7 @@ package com.android.server.wifi; import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID; +import android.app.AppGlobals; import android.app.admin.DeviceAdminInfo; import android.app.admin.DevicePolicyManagerInternal; import android.content.ContentResolver; @@ -175,7 +176,7 @@ public class WifiConfigStore extends IpConfigStore { private static final String PPS_FILE = "/data/misc/wifi/PerProviderSubscription.conf"; /* configured networks with network id as the key */ - private final ConfigurationMap mConfiguredNetworks; + private final ConfigurationMap mConfiguredNetworks = new ConfigurationMap(); /* A network id is a unique identifier for a network configured in the * supplicant. Network ids are generated when the supplicant reads @@ -680,7 +681,6 @@ public class WifiConfigStore extends IpConfigStore { boolean hs2on = mContext.getResources().getBoolean(R.bool.config_wifi_hotspot2_enabled); Log.d(Utils.hs2LogTag(getClass()), "Passpoint is " + (hs2on ? "enabled" : "disabled")); - mConfiguredNetworks = new ConfigurationMap(mContext); mMOManager = new PasspointManagementObjectManager(new File(PPS_FILE), hs2on); mEnableOsuQueries = true; mAnqpCache = new AnqpCache(); @@ -972,8 +972,7 @@ public class WifiConfigStore extends IpConfigStore { boolean selectNetwork(WifiConfiguration config, boolean updatePriorities, int uid) { if (VDBG) localLogNetwork("selectNetwork", config.networkId); if (config.networkId == INVALID_NETWORK_ID) return false; - if (!WifiConfigurationUtil.isVisibleToAnyProfile(config, - mWifiStateMachine.getCurrentUserProfiles())) { + if (!config.isVisibleToUser(mWifiStateMachine.getCurrentUserId())) { loge("selectNetwork " + Integer.toString(config.networkId) + ": Network config is not " + "visible to current user."); return false; @@ -1049,8 +1048,7 @@ public class WifiConfigStore extends IpConfigStore { return new NetworkUpdateResult(INVALID_NETWORK_ID); } - if (!WifiConfigurationUtil.isVisibleToAnyProfile(config, - mWifiStateMachine.getCurrentUserProfiles())) { + if (!config.isVisibleToUser(mWifiStateMachine.getCurrentUserId())) { return new NetworkUpdateResult(INVALID_NETWORK_ID); } @@ -1269,8 +1267,7 @@ public class WifiConfigStore extends IpConfigStore { * @return network Id */ int addOrUpdateNetwork(WifiConfiguration config, int uid) { - if (config == null || !WifiConfigurationUtil.isVisibleToAnyProfile(config, - mWifiStateMachine.getCurrentUserProfiles())) { + if (config == null || !config.isVisibleToUser(mWifiStateMachine.getCurrentUserId())) { return WifiConfiguration.INVALID_NETWORK_ID; } @@ -3396,8 +3393,7 @@ public class WifiConfigStore extends IpConfigStore { * @param config */ public void linkConfiguration(WifiConfiguration config) { - if (!WifiConfigurationUtil.isVisibleToAnyProfile(config, - mWifiStateMachine.getCurrentUserProfiles())) { + if (!config.isVisibleToUser(mWifiStateMachine.getCurrentUserId())) { loge("linkConfiguration: Attempting to link config " + config.configKey() + " that is not visible to the current user."); return; @@ -4615,7 +4611,7 @@ public class WifiConfigStore extends IpConfigStore { boolean checkConfigOverridePermission(int uid) { try { - return (mFacade.checkUidPermission( + return (AppGlobals.getPackageManager().checkUidPermission( android.Manifest.permission.OVERRIDE_WIFI_CONFIG, uid) == PackageManager.PERMISSION_GRANTED); } catch (RemoteException e) { diff --git a/service/java/com/android/server/wifi/WifiConfigurationUtil.java b/service/java/com/android/server/wifi/WifiConfigurationUtil.java deleted file mode 100644 index 7d0fb3cb3..000000000 --- a/service/java/com/android/server/wifi/WifiConfigurationUtil.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.wifi; - -import android.content.pm.UserInfo; -import android.net.wifi.WifiConfiguration; -import android.os.UserHandle; - -import java.util.List; - -/** - * Helper for working with {@link android.net.wifi.WifiConfiguration} objects. - */ -public class WifiConfigurationUtil { - /** - * Check whether a network configuration is visible to a user or any of its managed profiles. - * @param config the network configuration whose visibility should be checked - * @param profiles the user IDs of the user itself and all its managed profiles (can be obtained - * via {@link android.os.UserManager.getProfiles}) - * @return whether the network configuration is visible to the user or any of its managed - * profiles - */ - public static boolean isVisibleToAnyProfile(WifiConfiguration config, List<UserInfo> profiles) { - if (config.shared) { - return true; - } - final int creatorUserId = UserHandle.getUserId(config.creatorUid); - for (UserInfo profile : profiles) { - if (profile.id == creatorUserId) { - return true; - } - } - return false; - } -} diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 0bc8bb38a..d752182c0 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -313,14 +313,13 @@ public class WifiServiceImpl extends IWifiManager.Stub { mWifiMetrics = new WifiMetrics(); mTrafficPoller = new WifiTrafficPoller(mContext, wifiThread.getLooper(), WifiNative.getWlanNativeInterface().getInterfaceName()); - mUserManager = UserManager.get(mContext); - mWifiStateMachine = new WifiStateMachine(mContext, mTrafficPoller, facade, mWifiMetrics, - mUserManager); + mWifiStateMachine = new WifiStateMachine(mContext, mTrafficPoller, facade, mWifiMetrics); mSettingsStore = new WifiSettingsStore(mContext); mWifiStateMachine.enableRssiPolling(true); mBatteryStats = BatteryStatsService.getService(); mPowerManager = context.getSystemService(PowerManager.class); mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE); + mUserManager = UserManager.get(mContext); mNotificationController = new WifiNotificationController(mContext, mWifiStateMachine); diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 12a8ecd69..959ab19bd 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -40,7 +40,6 @@ import android.content.IntentFilter; import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager; import android.content.pm.PackageManager; -import android.content.pm.UserInfo; import android.database.ContentObserver; import android.net.ConnectivityManager; import android.net.DhcpResults; @@ -91,7 +90,6 @@ import android.os.RemoteException; import android.os.SystemClock; import android.os.SystemProperties; import android.os.UserHandle; -import android.os.UserManager; import android.os.WorkSource; import android.provider.Settings; import android.telephony.TelephonyManager; @@ -201,7 +199,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno private final AtomicBoolean mP2pConnected = new AtomicBoolean(false); private boolean mTemporarilyDisconnectWifi = false; private final String mPrimaryDeviceType; - private final UserManager mUserManager; /* Scan results handling */ private List<ScanDetail> mScanResults = new ArrayList<>(); @@ -1151,13 +1148,11 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno private FrameworkFacade mFacade; public WifiStateMachine(Context context, WifiTrafficPoller trafficPoller, - FrameworkFacade facade, WifiMetrics wifiMetrics, - UserManager userManager) { + FrameworkFacade facade, WifiMetrics wifiMetrics) { super("WifiStateMachine"); mWifiMetrics = wifiMetrics; mContext = context; mFacade = facade; - mUserManager = userManager; mWifiNative = WifiNative.getWlanNativeInterface(); // TODO refactor WifiNative use of context out into it's own class @@ -7044,7 +7039,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno break; case CMD_ADD_OR_UPDATE_NETWORK: // Only the current foreground user can modify networks. - if (!isCurrentUserProfile(UserHandle.getUserId(message.sendingUid))) { + if (UserHandle.getUserId(message.sendingUid) != mCurrentUserId) { loge("Only the current foreground user can modify networks " + " currentUserId=" + mCurrentUserId + " sendingUserId=" + UserHandle.getUserId(message.sendingUid)); @@ -7095,7 +7090,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno break; case CMD_REMOVE_NETWORK: // Only the current foreground user can modify networks. - if (!isCurrentUserProfile(UserHandle.getUserId(message.sendingUid))) { + if (UserHandle.getUserId(message.sendingUid) != mCurrentUserId) { loge("Only the current foreground user can modify networks " + " currentUserId=" + mCurrentUserId + " sendingUserId=" + UserHandle.getUserId(message.sendingUid)); @@ -7121,7 +7116,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno break; case CMD_ENABLE_NETWORK: // Only the current foreground user can modify networks. - if (!isCurrentUserProfile(UserHandle.getUserId(message.sendingUid))) { + if (UserHandle.getUserId(message.sendingUid) != mCurrentUserId) { loge("Only the current foreground user can modify networks " + " currentUserId=" + mCurrentUserId + " sendingUserId=" + UserHandle.getUserId(message.sendingUid)); @@ -7390,7 +7385,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno // lastConnectUid on a per-user basis. int lastConnectUid = WifiConfiguration.UNKNOWN_UID; if (mWifiConfigStore.isLastSelectedConfiguration(config) - && isCurrentUserProfile(UserHandle.getUserId(config.lastConnectUid))) { + && UserHandle.getUserId(config.lastConnectUid) == mCurrentUserId) { lastConnectUid = config.lastConnectUid; } mWifiMetrics.startConnectionEvent(mWifiInfo, config, @@ -7456,7 +7451,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno break; case WifiManager.CONNECT_NETWORK: // Only the current foreground user can modify networks. - if (!isCurrentUserProfile(UserHandle.getUserId(message.sendingUid))) { + if (UserHandle.getUserId(message.sendingUid) != mCurrentUserId) { loge("Only the current foreground user can modify networks " + " currentUserId=" + mCurrentUserId + " sendingUserId=" + UserHandle.getUserId(message.sendingUid)); @@ -7604,7 +7599,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno // Fall thru case WifiStateMachine.CMD_AUTO_SAVE_NETWORK: // Only the current foreground user can modify networks. - if (!isCurrentUserProfile(UserHandle.getUserId(message.sendingUid))) { + if (UserHandle.getUserId(message.sendingUid) != mCurrentUserId) { loge("Only the current foreground user can modify networks " + " currentUserId=" + mCurrentUserId + " sendingUserId=" + UserHandle.getUserId(message.sendingUid)); @@ -7703,7 +7698,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno break; case WifiManager.FORGET_NETWORK: // Only the current foreground user can modify networks. - if (!isCurrentUserProfile(UserHandle.getUserId(message.sendingUid))) { + if (UserHandle.getUserId(message.sendingUid) != mCurrentUserId) { loge("Only the current foreground user can modify networks " + " currentUserId=" + mCurrentUserId + " sendingUserId=" + UserHandle.getUserId(message.sendingUid)); @@ -10056,18 +10051,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno return mCurrentUserId; } - private boolean isCurrentUserProfile(int userId) { - if (userId == mCurrentUserId) { - return true; - } - final UserInfo parent = mUserManager.getProfileParent(userId); - return parent != null && parent.id == mCurrentUserId; - } - - public List<UserInfo> getCurrentUserProfiles() { - return mUserManager.getProfiles(mCurrentUserId); - } - /** * @param reason reason code from supplicant on network disconnected event * @return true if this is a suspicious disconnect |