From 58e574ea2cafa19ce276944e6cc9a0d3573641e9 Mon Sep 17 00:00:00 2001 From: Himanshu Rawat Date: Tue, 19 Jul 2022 06:08:44 +0000 Subject: [PATCH 1/2] Don't cancel passkey entry pairing autonomously Bluetooth pairing is cancelled if the pairing popup is closed without explicitly accepting the pairing. However there is no way to explicitly accept the pairing when the local device displays for the passkey entry or pin key entry pairing method. As a result all passkey entry and pin key entry pairings, where the local device is displaying the value, are cancelled after the pairing is successful. If the BT stack has not completed the SDP search when the pairing is cancelled after successful pairing, it may result in removal of the bond information. Bug: 237757124 Test: Pair with BT HID keyboard; adb logcat | grep "BTPairingController: Pairing dialog canceled" Change-Id: Ifdb98c16084dd811eed68469e7df5d1913c6ace8 (cherry picked from commit aa1950fd801afc9502cbd482981d34079065e743) Merged-In: Ifdb98c16084dd811eed68469e7df5d1913c6ace8 (cherry picked from commit d668a888f048164f3a573313b35170621fb7b4b4) Merged-In: Ifdb98c16084dd811eed68469e7df5d1913c6ace8 --- .../bluetooth/BluetoothPairingDialogFragment.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java b/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java index 650267a4757..8dd00b389ed 100644 --- a/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java +++ b/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java @@ -86,8 +86,12 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i @Override public void onDestroy() { super.onDestroy(); - if (!mPositiveClicked) { - mPairingController.onCancel(); + if (mPairingController.getDialogType() + != BluetoothPairingController.DISPLAY_PASSKEY_DIALOG) { + /* Cancel pairing unless explicitly accepted by user */ + if (!mPositiveClicked) { + mPairingController.onCancel(); + } } } From de334805834ce032758118cd69d86169c77aecee Mon Sep 17 00:00:00 2001 From: Tsung-Mao Fang Date: Thu, 11 Aug 2022 13:18:23 +0800 Subject: [PATCH 2/2] Wi-Fi panel doesn't need to check permission Prior to this cl, we use #getPackagesForUid() to get a list of calling package names and pick up 1st package name in the list as target calling package. And then go to check the Wi-Fi permission. This implementation is ok for most apps without sharing system uid. However, this may not work if the package is set with sharing system ui. In this case, we get a list of packages and we don't know which one is caller. So, if we decide to choose the 1st package as our calling package, then it could fail to pass permission check since that package could be not a correct calling package. In this cl, we skip permission check for those packages running with system uid. So, it can resolve Wi-Fi Panel problem since Wi-Fi panel runs on settings process(with system uid). Test: 1. adb shell am start -a android.settings.panel.action.WIFI 2. Verify on assistant app and system ui launcher and search app. Bug: 240531998 Change-Id: Ia825853dde2e966e3d390cecfbe1a99f6439d31e Merged-In: Ia825853dde2e966e3d390cecfbe1a99f6439d31e (cherry picked from commit 5e785a2d99a5d3410c9a8049225e17df4c7790d3) Merged-In: Ia825853dde2e966e3d390cecfbe1a99f6439d31e --- res/values/config.xml | 6 ++++++ .../android/settings/wifi/slice/WifiSlice.java | 17 ++++++++++++++++- .../wifi/slice/ContextualWifiSliceTest.java | 1 + .../settings/wifi/slice/WifiSliceTest.java | 4 ++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/res/values/config.xml b/res/values/config.xml index c7ef595e3ae..d7528c63bd0 100755 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -617,4 +617,10 @@ false + + + + @string/config_settingsintelligence_package_name + android.uid.system:1000 + diff --git a/src/com/android/settings/wifi/slice/WifiSlice.java b/src/com/android/settings/wifi/slice/WifiSlice.java index 76dfab8491b..8417d8b63a5 100644 --- a/src/com/android/settings/wifi/slice/WifiSlice.java +++ b/src/com/android/settings/wifi/slice/WifiSlice.java @@ -98,7 +98,7 @@ public class WifiSlice implements CustomSliceable { public Slice getSlice() { // If external calling package doesn't have Wi-Fi permission. final boolean isPermissionGranted = - Utils.isSettingsIntelligence(mContext) || isPermissionGranted(mContext); + isCallerExemptUid(mContext) || isPermissionGranted(mContext); final boolean isWifiEnabled = isWifiEnabled(); ListBuilder listBuilder = getListBuilder(isWifiEnabled, null /* wifiSliceItem */, isPermissionGranted); @@ -139,6 +139,21 @@ public class WifiSlice implements CustomSliceable { return listBuilder.build(); } + private boolean isCallerExemptUid(Context context) { + final String[] allowedUidNames = context.getResources().getStringArray( + R.array.config_exempt_wifi_permission_uid_name); + final String uidName = + context.getPackageManager().getNameForUid(Binder.getCallingUid()); + Log.d(TAG, "calling uid name : " + uidName); + + for (String allowedUidName : allowedUidNames) { + if (TextUtils.equals(uidName, allowedUidName)) { + return true; + } + } + return false; + } + private static boolean isPermissionGranted(Context settingsContext) { final int callingUid = Binder.getCallingUid(); final String callingPackage = settingsContext.getPackageManager() diff --git a/tests/robotests/src/com/android/settings/wifi/slice/ContextualWifiSliceTest.java b/tests/robotests/src/com/android/settings/wifi/slice/ContextualWifiSliceTest.java index 52dcb5282da..d9c726ab058 100644 --- a/tests/robotests/src/com/android/settings/wifi/slice/ContextualWifiSliceTest.java +++ b/tests/robotests/src/com/android/settings/wifi/slice/ContextualWifiSliceTest.java @@ -103,6 +103,7 @@ public class ContextualWifiSliceTest { mContext.getString(R.string.config_settingsintelligence_package_name); ShadowBinder.setCallingUid(1); when(mPackageManager.getPackagesForUid(1)).thenReturn(new String[]{siPackageName}); + when(mPackageManager.getNameForUid(1)).thenReturn(siPackageName); ShadowWifiSlice.setWifiPermissible(true); mWifiSlice = new ContextualWifiSlice(mContext); } diff --git a/tests/robotests/src/com/android/settings/wifi/slice/WifiSliceTest.java b/tests/robotests/src/com/android/settings/wifi/slice/WifiSliceTest.java index 8e42fcd225a..67ab7b49825 100644 --- a/tests/robotests/src/com/android/settings/wifi/slice/WifiSliceTest.java +++ b/tests/robotests/src/com/android/settings/wifi/slice/WifiSliceTest.java @@ -109,6 +109,7 @@ public class WifiSliceTest { mSIPackageName = mContext.getString(R.string.config_settingsintelligence_package_name); ShadowBinder.setCallingUid(USER_ID); when(mPackageManager.getPackagesForUid(USER_ID)).thenReturn(new String[]{mSIPackageName}); + when(mPackageManager.getNameForUid(USER_ID)).thenReturn(mSIPackageName); ShadowWifiSlice.setWifiPermissible(true); mWifiSlice = new WifiSlice(mContext, mWifiRestriction); } @@ -116,6 +117,7 @@ public class WifiSliceTest { @Test public void getWifiSlice_fromSIPackage_shouldHaveTitleAndToggle() { when(mPackageManager.getPackagesForUid(USER_ID)).thenReturn(new String[]{mSIPackageName}); + when(mPackageManager.getNameForUid(USER_ID)).thenReturn(mSIPackageName); ShadowWifiSlice.setWifiPermissible(false); final Slice wifiSlice = mWifiSlice.getSlice(); @@ -131,6 +133,7 @@ public class WifiSliceTest { @Test public void getWifiSlice_notFromSIPackageAndWithWifiPermission_shouldHaveTitleAndToggle() { when(mPackageManager.getPackagesForUid(USER_ID)).thenReturn(new String[]{"com.test"}); + when(mPackageManager.getNameForUid(USER_ID)).thenReturn("com.test"); ShadowWifiSlice.setWifiPermissible(true); final Slice wifiSlice = mWifiSlice.getSlice(); @@ -145,6 +148,7 @@ public class WifiSliceTest { @Test public void getWifiSlice_notFromSIPackageAndWithoutWifiPermission_shouldReturnNoToggle() { when(mPackageManager.getPackagesForUid(USER_ID)).thenReturn(new String[]{"com.test"}); + when(mPackageManager.getNameForUid(USER_ID)).thenReturn("com.test"); ShadowWifiSlice.setWifiPermissible(false); final Slice wifiSlice = mWifiSlice.getSlice();