From dbc3d8dd1238b5c7dbef9579904f02895b2745b5 Mon Sep 17 00:00:00 2001 From: Hemant Gupta Date: Fri, 12 May 2017 21:14:44 +0530 Subject: [PATCH] Bluetooth: Add support for PBAP UI preference Usecase: 1) Connect with carkit that supports PBAP/MAP 2) Try to uncheck the checkbox for contact sharing from device sub settings menu Expected Result: 1) DUT should display "Connected (No Media or Phone)" 1) Should be able to disconnect when checkbox moves from selected->unselected, and carkit should be able to connect when checkbox is selected again Observation: 1) No UI updates when PBAP/MAP are connected. 2) On unchecking Contact sharing checkbox nothing happens. PBAP connection remains active and user is not asked to disconnect profile level connection. Fix: Add support for PBAP UI preference in SettingsLib. Also Fix issues related to MAP profile addition/removal. Test: Connect from carkit, try disconnecting from sub settings menu by unchecking Contact Sharing checkbox and check if PBAP is successfully disconnected. Bug: 35014213 Change-Id: I283a0cb65cb132931010fb2f8c977bea20a67951 --- .../bluetooth/CachedBluetoothDevice.java | 3 ++- .../bluetooth/LocalBluetoothProfileManager.java | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) mode change 100755 => 100644 packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java index bfa8de9e963b1..448057c7ee700 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java @@ -132,7 +132,8 @@ public class CachedBluetoothDevice implements Comparable if (newProfileState == BluetoothProfile.STATE_CONNECTED) { if (profile instanceof MapProfile) { profile.setPreferred(mDevice, true); - } else if (!mProfiles.contains(profile)) { + } + if (!mProfiles.contains(profile)) { mRemovedProfiles.remove(profile); mProfiles.add(profile); if (profile instanceof PanProfile && diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java old mode 100755 new mode 100644 index 9cda669379ddc..991d9221c796c --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java @@ -25,6 +25,7 @@ import android.bluetooth.BluetoothHidHost; import android.bluetooth.BluetoothMap; import android.bluetooth.BluetoothMapClient; import android.bluetooth.BluetoothPan; +import android.bluetooth.BluetoothPbap; import android.bluetooth.BluetoothPbapClient; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothUuid; @@ -140,9 +141,11 @@ public class LocalBluetoothProfileManager { BluetoothMap.ACTION_CONNECTION_STATE_CHANGED); } - //Create PBAP server profile, but do not add it to list of profiles - // as we do not need to monitor the profile as part of profile list + //Create PBAP server profile + if(DEBUG) Log.d(TAG, "Adding local PBAP profile"); mPbapProfile = new PbapServerProfile(context); + addProfile(mPbapProfile, PbapServerProfile.NAME, + BluetoothPbap.ACTION_CONNECTION_STATE_CHANGED); if (DEBUG) Log.d(TAG, "LocalBluetoothProfileManager construction complete"); } @@ -495,6 +498,13 @@ public class LocalBluetoothProfileManager { mMapProfile.setPreferred(device, true); } + if ((mPbapProfile != null) && + (mPbapProfile.getConnectionStatus(device) == BluetoothProfile.STATE_CONNECTED)) { + profiles.add(mPbapProfile); + removedProfiles.remove(mPbapProfile); + mPbapProfile.setPreferred(device, true); + } + if (mMapClientProfile != null) { profiles.add(mMapClientProfile); removedProfiles.remove(mMapClientProfile); @@ -503,8 +513,6 @@ public class LocalBluetoothProfileManager { if (mUsePbapPce) { profiles.add(mPbapClientProfile); removedProfiles.remove(mPbapClientProfile); - profiles.remove(mPbapProfile); - removedProfiles.add(mPbapProfile); } if (DEBUG) {