diff options
author | Roshan Pius <rpius@google.com> | 2019-10-16 20:20:08 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2019-10-17 06:04:02 -0700 |
commit | 0268bc435193597359037650ff51ffd7a3793aa0 (patch) | |
tree | 1dd29469cee8e38ad06e71c9cf13b575e542a235 | |
parent | 439060b1ac7be35caa44c4d652c19469a43d3ea7 (diff) |
WifiStack: Use public API to get UserManager
Bug: 142024973
Test: atest com.android.server.wifi
Change-Id: I1694c0c03f513a9087a3210b3aaa2efaae65f0a7
4 files changed, 8 insertions, 21 deletions
diff --git a/service/java/com/android/server/wifi/AvailableNetworkNotifier.java b/service/java/com/android/server/wifi/AvailableNetworkNotifier.java index add8e023f..7af22934f 100644 --- a/service/java/com/android/server/wifi/AvailableNetworkNotifier.java +++ b/service/java/com/android/server/wifi/AvailableNetworkNotifier.java @@ -259,7 +259,7 @@ public class AvailableNetworkNotifier { } private boolean isControllerEnabled() { - return mSettingEnabled && !UserManager.get(mContext) + return mSettingEnabled && !mContext.getSystemService(UserManager.class) // TODO (b/142234604): This will not work on multi-user device scenarios. .hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI, UserHandle.CURRENT_OR_SELF); } diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index 424294b48..851c89fa8 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -82,6 +82,7 @@ public class WifiInjector { private final Context mContext; private final FrameworkFacade mFrameworkFacade = new FrameworkFacade(); private final DeviceConfigFacade mDeviceConfigFacade; + private final UserManager mUserManager; private final HandlerThread mAsyncChannelHandlerThread; private final HandlerThread mWifiHandlerThread; private final HandlerThread mWifiP2pServiceHandlerThread; @@ -176,8 +177,9 @@ public class WifiInjector { mWifiNetworkScoreCache = new WifiNetworkScoreCache(mContext); mNetworkScoreManager.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mWifiNetworkScoreCache, NetworkScoreManager.CACHE_FILTER_NONE); + mUserManager = mContext.getSystemService(UserManager.class); mWifiPermissionsUtil = new WifiPermissionsUtil(mWifiPermissionsWrapper, mContext, - UserManager.get(mContext), this); + mUserManager, this); mWifiBackupRestore = new WifiBackupRestore(mWifiPermissionsUtil); mBatteryStats = IBatteryStats.Stub.asInterface(mFrameworkFacade.getService( BatteryStats.SERVICE_NAME)); @@ -245,7 +247,7 @@ public class WifiInjector { mContext.getSystemService(SubscriptionManager.class); // Config Manager mWifiConfigManager = new WifiConfigManager(mContext, mClock, - UserManager.get(mContext), makeTelephonyManager(), + mUserManager, makeTelephonyManager(), mWifiKeyStore, mWifiConfigStore, mWifiPermissionsUtil, mWifiPermissionsWrapper, this, new NetworkListSharedStoreData(mContext), new NetworkListUserStoreData(mContext), @@ -303,7 +305,7 @@ public class WifiInjector { mLinkProbeManager = new LinkProbeManager(mClock, mWifiNative, mWifiMetrics, mFrameworkFacade, wifiHandler, mContext); mClientModeImpl = new ClientModeImpl(mContext, mFrameworkFacade, - wifiLooper, UserManager.get(mContext), + wifiLooper, mUserManager, this, mBackupManagerProxy, mCountryCode, mWifiNative, new WrongPasswordNotifier(mContext, mFrameworkFacade), mSarManager, mWifiTrafficPoller, mLinkProbeManager); @@ -370,7 +372,7 @@ public class WifiInjector { } public UserManager getUserManager() { - return UserManager.get(mContext); + return mUserManager; } public WifiMetrics getWifiMetrics() { diff --git a/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java b/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java index 3021c1991..e47a18269 100644 --- a/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java +++ b/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java @@ -107,7 +107,7 @@ public class OpenNetworkNotifierTest extends WifiBaseTest { when(mFrameworkFacade.getIntegerSetting(mContext, Settings.Global.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY, DEFAULT_REPEAT_DELAY_SEC)) .thenReturn(DEFAULT_REPEAT_DELAY_SEC); - when(mContext.getSystemService(Context.USER_SERVICE)) + when(mContext.getSystemService(UserManager.class)) .thenReturn(mUserManager); when(mContext.getResources()).thenReturn(mResources); mDummyNetwork = new ScanResult(); diff --git a/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java index 3ac587c64..d262514f1 100644 --- a/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java +++ b/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java @@ -37,7 +37,6 @@ import android.content.ContentResolver; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; -import android.content.pm.UserInfo; import android.location.LocationManager; import android.net.NetworkStack; import android.os.Build; @@ -61,7 +60,6 @@ import org.mockito.Spy; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import java.util.Arrays; import java.util.HashMap; /** Unit tests for {@link WifiPermissionsUtil}. */ @@ -76,7 +74,6 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { @Mock private PackageManager mMockPkgMgr; @Mock private ApplicationInfo mMockApplInfo; @Mock private AppOpsManager mMockAppOps; - @Mock private UserInfo mMockUserInfo; @Mock private UserManager mMockUserManager; @Mock private ContentResolver mMockContentResolver; @Mock private WifiInjector mWifiInjector; @@ -94,7 +91,6 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { private static final boolean DONT_HIDE_FROM_APP_OPS = false; private static final boolean HIDE_FROM_APP_OPS = true; - private final int mCallingUser = UserHandle.USER_SYSTEM; private final String mMacAddressPermission = "android.permission.PEERS_MAC_ADDRESS"; private final String mInteractAcrossUsersFullPermission = "android.permission.INTERACT_ACROSS_USERS_FULL"; @@ -113,7 +109,6 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { private int mFineLocationPermission; private int mAllowFineLocationApps; private int mHardwareLocationPermission; - private String mPkgNameOfTopActivity; private int mCurrentUser; private boolean mIsLocationEnabled; private boolean mThrowSecurityException; @@ -200,7 +195,6 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { mUid = MANAGED_PROFILE_UID; mPermissionsList.put(mMacAddressPermission, mUid); mWifiScanAllowApps = AppOpsManager.MODE_ALLOWED; - mMockUserInfo.id = mCallingUser; mIsLocationEnabled = true; setupTestCase(); WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, @@ -287,7 +281,6 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { public void testLegacyForegroundAppWithOtherPermissionsDenied() throws Exception { mThrowSecurityException = false; mMockApplInfo.targetSdkVersion = Build.VERSION_CODES.GINGERBREAD; - mPkgNameOfTopActivity = TEST_PACKAGE_NAME; mWifiScanAllowApps = AppOpsManager.MODE_ALLOWED; mUid = MANAGED_PROFILE_UID; mCurrentUser = UserHandle.USER_SYSTEM; @@ -318,7 +311,6 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { mAllowCoarseLocationApps = AppOpsManager.MODE_ALLOWED; mWifiScanAllowApps = AppOpsManager.MODE_ALLOWED; mUid = MANAGED_PROFILE_UID; - mMockUserInfo.id = mCallingUser; setupTestCase(); WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); @@ -703,7 +695,6 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { mAllowCoarseLocationApps = AppOpsManager.MODE_ALLOWED; mWifiScanAllowApps = AppOpsManager.MODE_ALLOWED; mUid = MANAGED_PROFILE_UID; - mMockUserInfo.id = mCallingUser; setupTestCase(); WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); @@ -727,7 +718,6 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { mAllowFineLocationApps = AppOpsManager.MODE_ALLOWED; mWifiScanAllowApps = AppOpsManager.MODE_ALLOWED; mUid = MANAGED_PROFILE_UID; - mMockUserInfo.id = mCallingUser; setupTestCase(); WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); @@ -751,7 +741,6 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { mAllowFineLocationApps = AppOpsManager.MODE_ERRORED; mWifiScanAllowApps = AppOpsManager.MODE_ALLOWED; mUid = MANAGED_PROFILE_UID; - mMockUserInfo.id = mCallingUser; setupTestCase(); WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); @@ -1243,8 +1232,6 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { } when(mMockContext.getSystemService(Context.APP_OPS_SERVICE)) .thenReturn(mMockAppOps); - when(mMockUserManager.getProfiles(mCurrentUser)) - .thenReturn(Arrays.asList(mMockUserInfo)); when(mMockContext.getContentResolver()).thenReturn(mMockContentResolver); when(mMockContext.getSystemService(Context.USER_SERVICE)) .thenReturn(mMockUserManager); @@ -1259,9 +1246,7 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { mWifiScanAllowApps = AppOpsManager.MODE_ERRORED; mUid = OTHER_USER_UID; mThrowSecurityException = true; - mMockUserInfo.id = UserHandle.USER_NULL; mMockApplInfo.targetSdkVersion = Build.VERSION_CODES.M; - mPkgNameOfTopActivity = INVALID_PACKAGE; mIsLocationEnabled = false; mCurrentUser = UserHandle.USER_SYSTEM; mCoarseLocationPermission = PackageManager.PERMISSION_DENIED; |