Do not perform SDP during pairing
As a result of commit 7de119c (ag/591931), SDP is performed when the
pairing dialog pops up. There are multiple problems with this. On badly
behaved devices an SDP request might trigger pairing from the remote
side, other devices (like Logitech keyboards) will close the connection
once SDP disconnects, causing the pairing to fail.
Further more, fetchUuidsWithSdk() is an asynchronous call. The code that
was added does not wait for SDP to complete. Thus the check for the PBAP
UUID will always fail and cause the permission check to still be
displayed.
With this change, SDP is not performed when the dialog is popped up and
PBAP permission is granted after bonding and subsequent service
discovery in accordance with final consensus in bug 16964116.
Bug: 18948640
Change-Id: I149afa8ae59b63f59ba579c12f97c3ea3d70112c
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
index be031ea..6f5c136 100755
--- a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
@@ -113,7 +113,6 @@
mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
mType = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.ERROR);
- mDevice.fetchUuidsWithSdp();
switch (mType) {
case BluetoothDevice.PAIRING_VARIANT_PIN:
@@ -321,23 +320,7 @@
}
}
- private void processPhonebookAccess() {
- CachedBluetoothDevice cachedDevice = mCachedDeviceManager.findDevice(mDevice);
- if (cachedDevice == null) {
- cachedDevice = mCachedDeviceManager.addDevice(
- mBluetoothManager.getBluetoothAdapter(),
- mBluetoothManager.getProfileManager(),
- mDevice);
- }
- ParcelUuid[] uuids = mDevice.getUuids();
- if (BluetoothUuid.containsAnyUuid(uuids, PbapServerProfile.PBAB_CLIENT_UUIDS)) {
- cachedDevice.setPhonebookPermissionChoice(CachedBluetoothDevice.ACCESS_ALLOWED);
- }
- }
-
private void onPair(String value) {
- processPhonebookAccess();
-
switch (mType) {
case BluetoothDevice.PAIRING_VARIANT_PIN:
byte[] pinBytes = BluetoothDevice.convertPinToBytes(value);
diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
index e61b3fd..f33f4db 100755
--- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
+++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
@@ -19,6 +19,7 @@
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
+import android.bluetooth.BluetoothUuid;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.ParcelUuid;
@@ -487,6 +488,11 @@
ParcelUuid[] localUuids = mLocalAdapter.getUuids();
if (localUuids == null) return false;
+ /**
+ * Now we know if the device supports PBAP, update permissions...
+ */
+ processPhonebookAccess();
+
mProfileManager.updateProfiles(uuids, localUuids, mProfiles, mRemovedProfiles,
mLocalNapRoleConnected, mDevice);
@@ -767,4 +773,15 @@
}
editor.commit();
}
+
+ private void processPhonebookAccess() {
+ if (mDevice.getBondState() != BluetoothDevice.BOND_BONDED) return;
+
+ ParcelUuid[] uuids = mDevice.getUuids();
+ if (BluetoothUuid.containsAnyUuid(uuids, PbapServerProfile.PBAB_CLIENT_UUIDS)) {
+ // The pairing dialog now warns of phone-book access for paired devices.
+ // No separate prompt is displayed after pairing.
+ setPhonebookPermissionChoice(CachedBluetoothDevice.ACCESS_ALLOWED);
+ }
+ }
}