diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2019-09-21 23:19:16 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2019-09-21 23:19:16 +0000 |
commit | c3f362215cfe2b62bb3d14c6f0bd3dce6c119e45 (patch) | |
tree | 7f21746a02f0da4c1675c8935933e38931d75541 | |
parent | f4009135bf26d87316789fb18dbe83686ba59d9a (diff) | |
parent | 7957387b5d459386191cf45ca90e45446ed13f93 (diff) | |
download | android_frameworks_opt_net_wifi-c3f362215cfe2b62bb3d14c6f0bd3dce6c119e45.tar.gz android_frameworks_opt_net_wifi-c3f362215cfe2b62bb3d14c6f0bd3dce6c119e45.tar.bz2 android_frameworks_opt_net_wifi-c3f362215cfe2b62bb3d14c6f0bd3dce6c119e45.zip |
Snap for 5892339 from 7957387b5d459386191cf45ca90e45446ed13f93 to qt-qpr1-release
Change-Id: I7ffee391536f95c11fc2da947df10eb2b9444295
14 files changed, 96 insertions, 81 deletions
diff --git a/service/java/com/android/server/wifi/DeviceConfigFacade.java b/service/java/com/android/server/wifi/DeviceConfigFacade.java index a9889f424..947261b8a 100644 --- a/service/java/com/android/server/wifi/DeviceConfigFacade.java +++ b/service/java/com/android/server/wifi/DeviceConfigFacade.java @@ -31,10 +31,10 @@ public class DeviceConfigFacade { // Default duration for evaluating Wifi condition to trigger a data stall // measured in milliseconds public static final int DEFAULT_DATA_STALL_DURATION_MS = 1500; - // Default threshold of Tx throughput below which to trigger a data stall measured in Mbps - public static final int DEFAULT_DATA_STALL_TX_TPUT_THR_MBPS = 2; - // Default threshold of Rx throughput below which to trigger a data stall measured in Mbps - public static final int DEFAULT_DATA_STALL_RX_TPUT_THR_MBPS = 2; + // Default threshold of Tx throughput below which to trigger a data stall measured in Kbps + public static final int DEFAULT_DATA_STALL_TX_TPUT_THR_KBPS = 2000; + // Default threshold of Rx throughput below which to trigger a data stall measured in Kbps + public static final int DEFAULT_DATA_STALL_RX_TPUT_THR_KBPS = 2000; // Default threshold of Tx packet error rate above which to trigger a data stall in percentage public static final int DEFAULT_DATA_STALL_TX_PER_THR = 90; // Default threshold of CCA level above which to trigger a data stall in percentage @@ -77,17 +77,17 @@ public class DeviceConfigFacade { /** * Gets the threshold of Tx throughput below which to trigger a data stall. */ - public int getDataStallTxTputThrMbps() { - return DeviceConfig.getInt(NAMESPACE, "data_stall_tx_tput_thr_mbps", - DEFAULT_DATA_STALL_TX_TPUT_THR_MBPS); + public int getDataStallTxTputThrKbps() { + return DeviceConfig.getInt(NAMESPACE, "data_stall_tx_tput_thr_kbps", + DEFAULT_DATA_STALL_TX_TPUT_THR_KBPS); } /** * Gets the threshold of Rx throughput below which to trigger a data stall. */ - public int getDataStallRxTputThrMbps() { - return DeviceConfig.getInt(NAMESPACE, "data_stall_rx_tput_thr_mbps", - DEFAULT_DATA_STALL_RX_TPUT_THR_MBPS); + public int getDataStallRxTputThrKbps() { + return DeviceConfig.getInt(NAMESPACE, "data_stall_rx_tput_thr_kbps", + DEFAULT_DATA_STALL_RX_TPUT_THR_KBPS); } /** diff --git a/service/java/com/android/server/wifi/WifiDataStall.java b/service/java/com/android/server/wifi/WifiDataStall.java index 6eb3b41e5..a7931febe 100644 --- a/service/java/com/android/server/wifi/WifiDataStall.java +++ b/service/java/com/android/server/wifi/WifiDataStall.java @@ -52,8 +52,8 @@ public class WifiDataStall { private int mMinTxBad; private int mMinTxSuccessWithoutRx; private int mDataStallDurationMs; - private int mDataStallTxTputThrMbps; - private int mDataStallRxTputThrMbps; + private int mDataStallTxTputThrKbps; + private int mDataStallRxTputThrKbps; private int mDataStallTxPerThr; private int mDataStallCcaLevelThr; private int mLastFrequency = -1; @@ -156,12 +156,12 @@ public class WifiDataStall { boolean isTxTputLow = false; boolean isRxTputLow = false; if (txLinkSpeed > 0) { - int txTput = txLinkSpeed * (100 - txPer) * (100 - ccaLevel); - isTxTputLow = txTput < mDataStallTxTputThrMbps * 100 * 100; + int txTputKbps = txLinkSpeed * 1000 * (100 - txPer) * (100 - ccaLevel); + isTxTputLow = txTputKbps < mDataStallTxTputThrKbps * 100 * 100; } if (rxLinkSpeed > 0) { - int rxTput = rxLinkSpeed * (100 - ccaLevel); - isRxTputLow = rxTput < mDataStallRxTputThrMbps * 100; + int rxTputKbps = rxLinkSpeed * 1000 * (100 - ccaLevel); + isRxTputLow = rxTputKbps < mDataStallRxTputThrKbps * 100; } boolean dataStallTx = isTxTputLow || ccaLevel >= mDataStallCcaLevelThr @@ -255,14 +255,14 @@ public class WifiDataStall { private void updateUsabilityDataCollectionFlags() { mDataStallDurationMs = mDeviceConfigFacade.getDataStallDurationMs(); - mDataStallTxTputThrMbps = mDeviceConfigFacade.getDataStallTxTputThrMbps(); - mDataStallRxTputThrMbps = mDeviceConfigFacade.getDataStallRxTputThrMbps(); + mDataStallTxTputThrKbps = mDeviceConfigFacade.getDataStallTxTputThrKbps(); + mDataStallRxTputThrKbps = mDeviceConfigFacade.getDataStallRxTputThrKbps(); mDataStallTxPerThr = mDeviceConfigFacade.getDataStallTxPerThr(); mDataStallCcaLevelThr = mDeviceConfigFacade.getDataStallCcaLevelThr(); mWifiMetrics.setDataStallDurationMs(mDataStallDurationMs); - mWifiMetrics.setDataStallTxTputThrMbps(mDataStallTxTputThrMbps); - mWifiMetrics.setDataStallRxTputThrMbps(mDataStallRxTputThrMbps); + mWifiMetrics.setDataStallTxTputThrKbps(mDataStallTxTputThrKbps); + mWifiMetrics.setDataStallRxTputThrKbps(mDataStallRxTputThrKbps); mWifiMetrics.setDataStallTxPerThr(mDataStallTxPerThr); mWifiMetrics.setDataStallCcaLevelThr(mDataStallCcaLevelThr); } diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index 1b7e8cdb3..54a0be66d 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -2784,10 +2784,10 @@ public class WifiMetrics { + mExperimentValues.linkSpeedCountsLoggingEnabled); pw.println("mExperimentValues.dataStallDurationMs=" + mExperimentValues.dataStallDurationMs); - pw.println("mExperimentValues.dataStallTxTputThrMbps=" - + mExperimentValues.dataStallTxTputThrMbps); - pw.println("mExperimentValues.dataStallRxTputThrMbps=" - + mExperimentValues.dataStallRxTputThrMbps); + pw.println("mExperimentValues.dataStallTxTputThrKbps=" + + mExperimentValues.dataStallTxTputThrKbps); + pw.println("mExperimentValues.dataStallRxTputThrKbps=" + + mExperimentValues.dataStallRxTputThrKbps); pw.println("mExperimentValues.dataStallTxPerThr=" + mExperimentValues.dataStallTxPerThr); pw.println("mExperimentValues.dataStallCcaLevelThr=" @@ -5214,18 +5214,18 @@ public class WifiMetrics { /** * Sets the threshold of Tx throughput below which to trigger a data stall */ - public void setDataStallTxTputThrMbps(int txTputThr) { + public void setDataStallTxTputThrKbps(int txTputThr) { synchronized (mLock) { - mExperimentValues.dataStallTxTputThrMbps = txTputThr; + mExperimentValues.dataStallTxTputThrKbps = txTputThr; } } /** * Sets the threshold of Rx throughput below which to trigger a data stall */ - public void setDataStallRxTputThrMbps(int rxTputThr) { + public void setDataStallRxTputThrKbps(int rxTputThr) { synchronized (mLock) { - mExperimentValues.dataStallRxTputThrMbps = rxTputThr; + mExperimentValues.dataStallRxTputThrKbps = rxTputThr; } } diff --git a/service/java/com/android/server/wifi/WifiNetworkFactory.java b/service/java/com/android/server/wifi/WifiNetworkFactory.java index 1f060cf73..c375e9f59 100644 --- a/service/java/com/android/server/wifi/WifiNetworkFactory.java +++ b/service/java/com/android/server/wifi/WifiNetworkFactory.java @@ -1141,10 +1141,11 @@ public class WifiNetworkFactory extends NetworkFactory { mConnectionTimeoutSet = true; } - private @NonNull CharSequence getAppName(@NonNull String packageName) { + private @NonNull CharSequence getAppName(@NonNull String packageName, int uid) { ApplicationInfo applicationInfo = null; try { - applicationInfo = mContext.getPackageManager().getApplicationInfo(packageName, 0); + applicationInfo = mContext.getPackageManager().getApplicationInfoAsUser( + packageName, 0, UserHandle.getUserId(uid)); } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Failed to find app name for " + packageName); return ""; @@ -1159,7 +1160,8 @@ public class WifiNetworkFactory extends NetworkFactory { intent.addCategory(UI_START_INTENT_CATEGORY); intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(UI_START_INTENT_EXTRA_APP_NAME, - getAppName(mActiveSpecificNetworkRequestSpecifier.requestorPackageName)); + getAppName(mActiveSpecificNetworkRequestSpecifier.requestorPackageName, + mActiveSpecificNetworkRequestSpecifier.requestorUid)); intent.putExtra(UI_START_INTENT_EXTRA_REQUEST_IS_FOR_SINGLE_NETWORK, isActiveRequestForSingleNetwork()); mContext.startActivityAsUser(intent, UserHandle.getUserHandleForUid( diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java index 972d1c93f..644eb6523 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java +++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java @@ -761,10 +761,11 @@ public class WifiNetworkSuggestionsManager { PendingIntent.FLAG_UPDATE_CURRENT); } - private @NonNull CharSequence getAppName(@NonNull String packageName) { + private @NonNull CharSequence getAppName(@NonNull String packageName, int uid) { ApplicationInfo applicationInfo = null; try { - applicationInfo = mPackageManager.getApplicationInfo(packageName, 0); + applicationInfo = mContext.getPackageManager().getApplicationInfoAsUser( + packageName, 0, UserHandle.getUserId(uid)); } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Failed to find app name for " + packageName); return ""; @@ -787,7 +788,7 @@ public class WifiNetworkSuggestionsManager { packageName, uid)) .build(); - CharSequence appName = getAppName(packageName); + CharSequence appName = getAppName(packageName, uid); Notification notification = new Notification.Builder( mContext, SystemNotificationChannels.NETWORK_STATUS) .setSmallIcon(R.drawable.stat_notify_wifi_in_range) diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index be75f96b3..2d15af53c 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -755,10 +755,11 @@ public class WifiServiceImpl extends BaseWifiService { } // Helper method to check if the entity initiating the binder call is a system app. - private boolean isSystem(String packageName) { + private boolean isSystem(String packageName, int uid) { long ident = Binder.clearCallingIdentity(); try { - ApplicationInfo info = mContext.getPackageManager().getApplicationInfo(packageName, 0); + ApplicationInfo info = mContext.getPackageManager().getApplicationInfoAsUser( + packageName, 0, UserHandle.getUserId(uid)); return info.isSystemApp() || info.isUpdatedSystemApp(); } catch (PackageManager.NameNotFoundException e) { // In case of exception, assume unknown app (more strict checking) @@ -853,12 +854,12 @@ public class WifiServiceImpl extends BaseWifiService { * Note: Invoke mAppOps.checkPackage(uid, packageName) before to ensure correct package name. */ private boolean isTargetSdkLessThanQOrPrivileged(String packageName, int pid, int uid) { - return mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q) + return mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q, uid) || isPrivileged(pid, uid) // DO/PO apps should be able to add/modify saved networks. || isDeviceOrProfileOwner(uid) // TODO: Remove this system app bypass once Q is released. - || isSystem(packageName) + || isSystem(packageName, uid) || mWifiPermissionsUtil.checkSystemAlertWindowPermission(uid, packageName); } @@ -875,8 +876,9 @@ public class WifiServiceImpl extends BaseWifiService { } boolean isPrivileged = isPrivileged(Binder.getCallingPid(), Binder.getCallingUid()); if (!isPrivileged && !isDeviceOrProfileOwner(Binder.getCallingUid()) - && !mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q) - && !isSystem(packageName)) { + && !mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q, + Binder.getCallingUid()) + && !isSystem(packageName, Binder.getCallingUid())) { mLog.info("setWifiEnabled not allowed for uid=%") .c(Binder.getCallingUid()).flush(); return false; @@ -2309,7 +2311,7 @@ public class WifiServiceImpl extends BaseWifiService { final int uid = Binder.getCallingUid(); if (!mWifiPermissionsUtil.checkNetworkSettingsPermission(uid) && !mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(uid)) { - if (mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q)) { + if (mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q, uid)) { return false; } throw new SecurityException(TAG + ": Permission denied"); @@ -2334,7 +2336,7 @@ public class WifiServiceImpl extends BaseWifiService { mAppOps.checkPackage(uid, packageName); if (!mWifiPermissionsUtil.checkNetworkSettingsPermission(uid) && !mWifiPermissionsUtil.checkNetworkSetupWizardPermission(uid)) { - if (mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q)) { + if (mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q, uid)) { return new ArrayList<>(); } throw new SecurityException(TAG + ": Permission denied"); diff --git a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java index 1ac73aef8..5832ee898 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java @@ -1286,7 +1286,7 @@ public class WifiAwareDataPathStateManager { // Note: checks are done on the manager. This is a backup for apps which bypass the // check. if (!allowNdpResponderFromAnyOverride && !wifiPermissionsUtil.isTargetSdkLessThan( - client.getCallingPackage(), Build.VERSION_CODES.P)) { + client.getCallingPackage(), Build.VERSION_CODES.P, uid)) { if (ns.type != WifiAwareNetworkSpecifier.NETWORK_SPECIFIER_TYPE_IB && ns.type != WifiAwareNetworkSpecifier.NETWORK_SPECIFIER_TYPE_OOB) { Log.e(TAG, "processNetworkSpecifier: networkSpecifier=" + ns diff --git a/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java b/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java index 2834ad765..b1ceaf37a 100644 --- a/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java +++ b/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java @@ -124,10 +124,11 @@ public class WifiPermissionsUtil { /** * Checks whether than the target SDK of the package is less than the specified version code. */ - public boolean isTargetSdkLessThan(String packageName, int versionCode) { + public boolean isTargetSdkLessThan(String packageName, int versionCode, int callingUid) { long ident = Binder.clearCallingIdentity(); try { - if (mContext.getPackageManager().getApplicationInfo(packageName, 0).targetSdkVersion + if (mContext.getPackageManager().getApplicationInfoAsUser( + packageName, 0, UserHandle.getUserId(callingUid)).targetSdkVersion < versionCode) { return true; } @@ -153,7 +154,7 @@ public class WifiPermissionsUtil { */ public boolean checkCallersLocationPermission(String pkgName, int uid, boolean coarseForTargetSdkLessThanQ) { - boolean isTargetSdkLessThanQ = isTargetSdkLessThan(pkgName, Build.VERSION_CODES.Q); + boolean isTargetSdkLessThanQ = isTargetSdkLessThan(pkgName, Build.VERSION_CODES.Q, uid); String permissionType = Manifest.permission.ACCESS_FINE_LOCATION; if (coarseForTargetSdkLessThanQ && isTargetSdkLessThanQ) { diff --git a/tests/wifitests/src/com/android/server/wifi/WifiDataStallTest.java b/tests/wifitests/src/com/android/server/wifi/WifiDataStallTest.java index 71b658923..6ac18361c 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiDataStallTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiDataStallTest.java @@ -76,10 +76,10 @@ public class WifiDataStallTest { .thenReturn(WifiDataStall.MIN_TX_SUCCESS_WITHOUT_RX_DEFAULT); when(mDeviceConfigFacade.getDataStallDurationMs()).thenReturn( DeviceConfigFacade.DEFAULT_DATA_STALL_DURATION_MS); - when(mDeviceConfigFacade.getDataStallTxTputThrMbps()).thenReturn( - DeviceConfigFacade.DEFAULT_DATA_STALL_TX_TPUT_THR_MBPS); - when(mDeviceConfigFacade.getDataStallRxTputThrMbps()).thenReturn( - DeviceConfigFacade.DEFAULT_DATA_STALL_RX_TPUT_THR_MBPS); + when(mDeviceConfigFacade.getDataStallTxTputThrKbps()).thenReturn( + DeviceConfigFacade.DEFAULT_DATA_STALL_TX_TPUT_THR_KBPS); + when(mDeviceConfigFacade.getDataStallRxTputThrKbps()).thenReturn( + DeviceConfigFacade.DEFAULT_DATA_STALL_RX_TPUT_THR_KBPS); when(mDeviceConfigFacade.getDataStallTxPerThr()).thenReturn( DeviceConfigFacade.DEFAULT_DATA_STALL_TX_PER_THR); when(mDeviceConfigFacade.getDataStallCcaLevelThr()).thenReturn( diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java index 968527a8d..63cc8bf60 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java @@ -173,7 +173,8 @@ public class WifiNetworkFactoryTest { .thenReturn(mConnectivityManager); when(mPackageManager.getNameForUid(TEST_UID_1)).thenReturn(TEST_PACKAGE_NAME_1); when(mPackageManager.getNameForUid(TEST_UID_2)).thenReturn(TEST_PACKAGE_NAME_2); - when(mPackageManager.getApplicationInfo(any(), anyInt())).thenReturn(new ApplicationInfo()); + when(mPackageManager.getApplicationInfoAsUser(any(), anyInt(), anyInt())) + .thenReturn(new ApplicationInfo()); when(mPackageManager.getApplicationLabel(any())).thenReturn(TEST_APP_NAME); when(mActivityManager.getPackageImportance(TEST_PACKAGE_NAME_1)) .thenReturn(IMPORTANCE_FOREGROUND_SERVICE); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java index ae4da66d6..612fdf575 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java @@ -150,10 +150,12 @@ public class WifiNetworkSuggestionsManagerTest { when(mContext.getApplicationInfo()).thenReturn(ourAppInfo); // test app info ApplicationInfo appInfO1 = new ApplicationInfo(); - when(mPackageManager.getApplicationInfo(TEST_PACKAGE_1, 0)).thenReturn(appInfO1); + when(mPackageManager.getApplicationInfoAsUser(eq(TEST_PACKAGE_1), eq(0), anyInt())) + .thenReturn(appInfO1); when(mPackageManager.getApplicationLabel(appInfO1)).thenReturn(TEST_APP_NAME_1); ApplicationInfo appInfO2 = new ApplicationInfo(); - when(mPackageManager.getApplicationInfo(TEST_PACKAGE_2, 0)).thenReturn(appInfO2); + when(mPackageManager.getApplicationInfoAsUser(eq(TEST_PACKAGE_2), eq(0), anyInt())) + .thenReturn(appInfO2); when(mPackageManager.getApplicationLabel(appInfO2)).thenReturn(TEST_APP_NAME_2); mWifiNetworkSuggestionsManager = diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index 4f0ddc036..9a3bd75be 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -349,7 +349,8 @@ public class WifiServiceImplTest { when(mContext.getResources()).thenReturn(mResources); when(mContext.getContentResolver()).thenReturn(mContentResolver); when(mContext.getPackageManager()).thenReturn(mPackageManager); - when(mPackageManager.getApplicationInfo(any(), anyInt())).thenReturn(mApplicationInfo); + when(mPackageManager.getApplicationInfoAsUser(any(), anyInt(), anyInt())) + .thenReturn(mApplicationInfo); when(mWifiInjector.getWifiApConfigStore()).thenReturn(mWifiApConfigStore); doNothing().when(mFrameworkFacade).registerContentObserver(eq(mContext), any(), anyBoolean(), any()); @@ -544,7 +545,7 @@ public class WifiServiceImplTest { doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(true); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true); when(mSettingsStore.handleWifiToggled(anyBoolean())).thenReturn(true); when(mSettingsStore.isAirplaneModeOn()).thenReturn(false); @@ -563,7 +564,7 @@ public class WifiServiceImplTest { doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(false); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(false); when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true); when(mSettingsStore.isAirplaneModeOn()).thenReturn(false); @@ -607,7 +608,7 @@ public class WifiServiceImplTest { doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(false); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(false); when(mDevicePolicyManagerInternal.isActiveAdminWithPolicy( Process.myUid(), DeviceAdminInfo.USES_POLICY_DEVICE_OWNER)) .thenReturn(true); @@ -627,7 +628,7 @@ public class WifiServiceImplTest { doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(false); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(false); mApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM; when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true); @@ -645,7 +646,7 @@ public class WifiServiceImplTest { doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(true); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true); when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true); when(mSettingsStore.isAirplaneModeOn()).thenReturn(false); @@ -676,7 +677,7 @@ public class WifiServiceImplTest { doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(false); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(false); when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true); when(mSettingsStore.isAirplaneModeOn()).thenReturn(false); @@ -693,7 +694,7 @@ public class WifiServiceImplTest { doThrow(new SecurityException()).when(mAppOpsManager) .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(true); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true); when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true); try { mWifiServiceImpl.setWifiEnabled(TEST_PACKAGE_NAME, true); @@ -713,7 +714,7 @@ public class WifiServiceImplTest { doReturn(AppOpsManager.MODE_IGNORED).when(mAppOpsManager) .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(true); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true); when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true); mWifiServiceImpl.setWifiEnabled(TEST_PACKAGE_NAME, true); @@ -745,7 +746,7 @@ public class WifiServiceImplTest { doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(true); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true); when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true); when(mSettingsStore.isAirplaneModeOn()).thenReturn(true); when(mContext.checkPermission( @@ -789,7 +790,7 @@ public class WifiServiceImplTest { doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(true); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); @@ -871,7 +872,7 @@ public class WifiServiceImplTest { doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(false); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(false); when(mDevicePolicyManagerInternal.isActiveAdminWithPolicy( Process.myUid(), DeviceAdminInfo.USES_POLICY_PROFILE_OWNER)) .thenReturn(true); @@ -891,7 +892,7 @@ public class WifiServiceImplTest { doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(false); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(false); mApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM; when(mSettingsStore.handleWifiToggled(eq(false))).thenReturn(true); @@ -910,7 +911,7 @@ public class WifiServiceImplTest { doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(true); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true); when(mSettingsStore.handleWifiToggled(eq(false))).thenReturn(true); when(mSettingsStore.isAirplaneModeOn()).thenReturn(false); @@ -941,7 +942,7 @@ public class WifiServiceImplTest { doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(false); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(false); when(mSettingsStore.handleWifiToggled(eq(false))).thenReturn(true); when(mSettingsStore.isAirplaneModeOn()).thenReturn(false); @@ -2658,9 +2659,9 @@ public class WifiServiceImplTest { PackageManager pm = mock(PackageManager.class); when(pm.hasSystemFeature(PackageManager.FEATURE_WIFI_PASSPOINT)).thenReturn(true); when(mContext.getPackageManager()).thenReturn(pm); - when(pm.getApplicationInfo(any(), anyInt())).thenReturn(mApplicationInfo); + when(pm.getApplicationInfoAsUser(any(), anyInt(), anyInt())).thenReturn(mApplicationInfo); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(true); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true); when(mClientModeImpl.syncAddOrUpdatePasspointConfig(any(), any(PasspointConfiguration.class), anyInt(), eq(TEST_PACKAGE_NAME))).thenReturn( @@ -2822,7 +2823,7 @@ public class WifiServiceImplTest { when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(false); when(mWifiPermissionsUtil.checkNetworkSetupWizardPermission(anyInt())).thenReturn(false); when(mWifiPermissionsUtil.isTargetSdkLessThan(eq(TEST_PACKAGE_NAME), - eq(Build.VERSION_CODES.Q))).thenReturn(true); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true); List<PasspointConfiguration> result = mWifiServiceImpl.getPasspointConfigurations( TEST_PACKAGE_NAME); @@ -2855,7 +2856,7 @@ public class WifiServiceImplTest { when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())).thenReturn( false); when(mWifiPermissionsUtil.isTargetSdkLessThan(isNull(), - eq(Build.VERSION_CODES.Q))).thenReturn(true); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true); assertFalse(mWifiServiceImpl.removePasspointConfiguration(null, null)); } @@ -3733,7 +3734,7 @@ public class WifiServiceImplTest { .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); when(mClientModeImpl.syncAddOrUpdateNetwork(any(), any())).thenReturn(0); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(true); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true); WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork(); assertEquals(0, mWifiServiceImpl.addOrUpdateNetwork(config, TEST_PACKAGE_NAME)); @@ -3876,7 +3877,7 @@ public class WifiServiceImplTest { doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), - eq(Build.VERSION_CODES.Q))).thenReturn(true); + eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true); mWifiServiceImpl.enableNetwork(TEST_NETWORK_ID, true, TEST_PACKAGE_NAME); diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java index f2cc45fef..35916d2f6 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java @@ -161,7 +161,8 @@ public class WifiAwareDataPathStateManagerTest { // by default pretend to be an old API: i.e. allow Responders configured as *ANY*. This // allows older (more extrensive) tests to run. - when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), anyInt())).thenReturn(true); + when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), anyInt(), anyInt())) + .thenReturn(true); when(mWifiPermissionsUtil.isLocationModeEnabled()).thenReturn(true); mDut = new WifiAwareStateManager(); @@ -1017,7 +1018,8 @@ public class WifiAwareDataPathStateManagerTest { */ @Test public void testDataPathResonderMacPassphraseNoPeerIdSuccessNonLegacy() throws Exception { - when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), anyInt())).thenReturn(false); + when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), anyInt(), anyInt())) + .thenReturn(false); testDataPathResponderUtility(false, false, false, true, true); } @@ -1028,7 +1030,8 @@ public class WifiAwareDataPathStateManagerTest { @Test public void testDataPathResonderMacOpenNoPeerIdNoPmkPassphraseSuccessNonLegacy() throws Exception { - when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), anyInt())).thenReturn(false); + when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), anyInt(), anyInt())) + .thenReturn(false); testDataPathResponderUtility(false, false, false, false, true); } @@ -1074,7 +1077,8 @@ public class WifiAwareDataPathStateManagerTest { */ @Test public void testDataPathResonderDirectNoMacPassphraseSuccessNonLegacy() throws Exception { - when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), anyInt())).thenReturn(false); + when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), anyInt(), anyInt())) + .thenReturn(false); testDataPathResponderUtility(true, false, false, true, true); } @@ -1084,7 +1088,8 @@ public class WifiAwareDataPathStateManagerTest { */ @Test public void testDataPathResonderDirectNoMacNoPmkPassphraseSuccessNonLegacy() throws Exception { - when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), anyInt())).thenReturn(false); + when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), anyInt(), anyInt())) + .thenReturn(false); testDataPathResponderUtility(true, false, false, false, true); } @@ -1473,7 +1478,7 @@ public class WifiAwareDataPathStateManagerTest { InOrder inOrderM = inOrder(mAwareMetricsMock); boolean isLegacy = mWifiPermissionsUtil.isTargetSdkLessThan("anything", - Build.VERSION_CODES.P); + Build.VERSION_CODES.P, 0); if (providePmk) { when(mPermissionsWrapperMock.getUidPermission( 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 8baacf615..0c9ed26b7 100644 --- a/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java +++ b/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java @@ -1148,7 +1148,7 @@ public class WifiPermissionsUtilTest { } private void setupMocks() throws Exception { - when(mMockPkgMgr.getApplicationInfo(TEST_PACKAGE_NAME, 0)) + when(mMockPkgMgr.getApplicationInfoAsUser(eq(TEST_PACKAGE_NAME), eq(0), anyInt())) .thenReturn(mMockApplInfo); when(mMockContext.getPackageManager()).thenReturn(mMockPkgMgr); when(mMockAppOps.noteOp(AppOpsManager.OP_WIFI_SCAN, mUid, TEST_PACKAGE_NAME)) |