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: I4981aa063b2541b58ce1d36e3576578cbeb02acc
This commit is contained in:
Hemant Gupta
2015-11-04 16:38:15 +05:30
parent cb1056f9b4
commit 13197bcc1e

View File

@@ -172,7 +172,11 @@ public final class DeviceProfilesSettings extends InstrumentedDialogFragment imp
mProfileContainer.removeAllViews(); mProfileContainer.removeAllViews();
for (LocalBluetoothProfile profile : mCachedDevice.getConnectableProfiles()) { for (LocalBluetoothProfile profile : mCachedDevice.getConnectableProfiles()) {
CheckBox pref = createProfilePreference(profile); CheckBox pref = createProfilePreference(profile);
mProfileContainer.addView(pref); // MAP and PBAP profiles would be added based on permission access
if (!((profile instanceof PbapServerProfile) ||
(profile instanceof MapProfile))) {
mProfileContainer.addView(pref);
}
if (profile instanceof A2dpProfile) { if (profile instanceof A2dpProfile) {
BluetoothDevice device = mCachedDevice.getDevice(); BluetoothDevice device = mCachedDevice.getDevice();
@@ -191,6 +195,7 @@ public final class DeviceProfilesSettings extends InstrumentedDialogFragment imp
} }
final int pbapPermission = mCachedDevice.getPhonebookPermissionChoice(); final int pbapPermission = mCachedDevice.getPhonebookPermissionChoice();
Log.d(TAG, "addPreferencesForProfiles: pbapPermission = " + pbapPermission);
// Only provide PBAP cabability if the client device has requested PBAP. // Only provide PBAP cabability if the client device has requested PBAP.
if (pbapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) { if (pbapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) {
final PbapServerProfile psp = mManager.getProfileManager().getPbapProfile(); final PbapServerProfile psp = mManager.getProfileManager().getPbapProfile();
@@ -200,6 +205,7 @@ public final class DeviceProfilesSettings extends InstrumentedDialogFragment imp
final MapProfile mapProfile = mManager.getProfileManager().getMapProfile(); final MapProfile mapProfile = mManager.getProfileManager().getMapProfile();
final int mapPermission = mCachedDevice.getMessagePermissionChoice(); final int mapPermission = mCachedDevice.getMessagePermissionChoice();
Log.d(TAG, "addPreferencesForProfiles: mapPermission = " + mapPermission);
if (mapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) { if (mapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) {
CheckBox mapPreference = createProfilePreference(mapProfile); CheckBox mapPreference = createProfilePreference(mapProfile);
mProfileContainer.addView(mapPreference); mProfileContainer.addView(mapPreference);
@@ -251,15 +257,6 @@ public final class DeviceProfilesSettings extends InstrumentedDialogFragment imp
private void onProfileClicked(LocalBluetoothProfile profile, CheckBox profilePref) { private void onProfileClicked(LocalBluetoothProfile profile, CheckBox profilePref) {
BluetoothDevice device = mCachedDevice.getDevice(); BluetoothDevice device = mCachedDevice.getDevice();
if (KEY_PBAP_SERVER.equals(profilePref.getTag())) {
final int newPermission = mCachedDevice.getPhonebookPermissionChoice()
== CachedBluetoothDevice.ACCESS_ALLOWED ? CachedBluetoothDevice.ACCESS_REJECTED
: CachedBluetoothDevice.ACCESS_ALLOWED;
mCachedDevice.setPhonebookPermissionChoice(newPermission);
profilePref.setChecked(newPermission == CachedBluetoothDevice.ACCESS_ALLOWED);
return;
}
if (!profilePref.isChecked()) { if (!profilePref.isChecked()) {
// Recheck it, until the dialog is done. // Recheck it, until the dialog is done.
profilePref.setChecked(true); profilePref.setChecked(true);
@@ -268,6 +265,12 @@ public final class DeviceProfilesSettings extends InstrumentedDialogFragment imp
if (profile instanceof MapProfile) { if (profile instanceof MapProfile) {
mCachedDevice.setMessagePermissionChoice(BluetoothDevice.ACCESS_ALLOWED); mCachedDevice.setMessagePermissionChoice(BluetoothDevice.ACCESS_ALLOWED);
} }
if (profile instanceof PbapServerProfile) {
mCachedDevice.setPhonebookPermissionChoice(BluetoothDevice.ACCESS_ALLOWED);
refreshProfilePreference(profilePref, profile);
// PBAP server is not preffered profile and cannot initiate connection, so return
return;
}
if (profile.isPreferred(device)) { if (profile.isPreferred(device)) {
// profile is preferred but not connected: disable auto-connect // profile is preferred but not connected: disable auto-connect
if (profile instanceof PanProfile) { if (profile instanceof PanProfile) {
@@ -301,10 +304,17 @@ public final class DeviceProfilesSettings extends InstrumentedDialogFragment imp
DialogInterface.OnClickListener disconnectListener = DialogInterface.OnClickListener disconnectListener =
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
device.disconnect(profile);
profile.setPreferred(device.getDevice(), false); // Disconnect only when user has selected OK otherwise ignore
if (profile instanceof MapProfile) { if (which == DialogInterface.BUTTON_POSITIVE) {
device.setMessagePermissionChoice(BluetoothDevice.ACCESS_REJECTED); device.disconnect(profile);
profile.setPreferred(device.getDevice(), false);
if (profile instanceof MapProfile) {
device.setMessagePermissionChoice(BluetoothDevice.ACCESS_REJECTED);
}
if (profile instanceof PbapServerProfile) {
device.setPhonebookPermissionChoice(BluetoothDevice.ACCESS_REJECTED);
}
} }
refreshProfilePreference(findProfile(profile.toString()), profile); refreshProfilePreference(findProfile(profile.toString()), profile);
} }
@@ -341,6 +351,19 @@ public final class DeviceProfilesSettings extends InstrumentedDialogFragment imp
for (LocalBluetoothProfile profile : mCachedDevice.getRemovedProfiles()) { for (LocalBluetoothProfile profile : mCachedDevice.getRemovedProfiles()) {
CheckBox profilePref = findProfile(profile.toString()); CheckBox profilePref = findProfile(profile.toString());
if (profilePref != null) { if (profilePref != null) {
if (profile instanceof PbapServerProfile) {
final int pbapPermission = mCachedDevice.getPhonebookPermissionChoice();
Log.d(TAG, "refreshProfiles: pbapPermission = " + pbapPermission);
if (pbapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN)
continue;
}
if (profile instanceof MapProfile) {
final int mapPermission = mCachedDevice.getMessagePermissionChoice();
Log.d(TAG, "refreshProfiles: mapPermission = " + mapPermission);
if (mapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN)
continue;
}
Log.d(TAG, "Removing " + profile.toString() + " from profile list"); Log.d(TAG, "Removing " + profile.toString() + " from profile list");
mProfileContainer.removeView(profilePref); mProfileContainer.removeView(profilePref);
} }