Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d13f411b authored by Hemant Gupta's avatar Hemant Gupta Committed by Sravan Kumar V
Browse files

Bluetooth: PBAP: Add support for PBAP UI preference

This pach adds support for PBAP UI preference in SettingsLib. Without this
change it is not possible to properly use the pbap checkbox preference from
Bluetooth subsettings menu. Also some map profile specific bug fixes are also
incorporated in this change.

Change-Id: I4981aa063b2541b58ce1d36e3576578cbeb02acc
CRs-Fixed: 1061628
parent 453baf4b
Loading
Loading
Loading
Loading
+39 −15
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ public final class DeviceProfilesSettings extends DialogFragment implements
    private ViewGroup mProfileContainer;
    private TextView mProfileLabel;
    private EditTextPreference mDeviceNamePref;
    private static final int OK_BUTTON = -1;

    private final HashMap<LocalBluetoothProfile, CheckBoxPreference> mAutoConnectPrefs
            = new HashMap<LocalBluetoothProfile, CheckBoxPreference>();
@@ -173,11 +174,16 @@ public final class DeviceProfilesSettings extends DialogFragment implements
    private void addPreferencesForProfiles() {
        mProfileContainer.removeAllViews();
        for (LocalBluetoothProfile profile : mCachedDevice.getConnectableProfiles()) {
            // MAP and PBAP profiles would be added based on permission access
            if (!((profile instanceof PbapServerProfile) ||
                (profile instanceof MapProfile))) {
                CheckBox pref = createProfilePreference(profile);
                mProfileContainer.addView(pref);
            }
        }

        final int pbapPermission = mCachedDevice.getPhonebookPermissionChoice();
        Log.d(TAG, "addPreferencesForProfiles: pbapPermission = " + pbapPermission);
        // Only provide PBAP cabability if the client device has requested PBAP.
        if (pbapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) {
            final PbapServerProfile psp = mManager.getProfileManager().getPbapProfile();
@@ -187,6 +193,7 @@ public final class DeviceProfilesSettings extends DialogFragment implements

        final MapProfile mapProfile = mManager.getProfileManager().getMapProfile();
        final int mapPermission = mCachedDevice.getMessagePermissionChoice();
        Log.d(TAG, "addPreferencesForProfiles: mapPermission = " + mapPermission);
        if (mapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) {
            CheckBox mapPreference = createProfilePreference(mapProfile);
            mProfileContainer.addView(mapPreference);
@@ -241,15 +248,6 @@ public final class DeviceProfilesSettings extends DialogFragment implements
    private void onProfileClicked(LocalBluetoothProfile profile, CheckBox profilePref) {
        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()) {
            // Recheck it, until the dialog is done.
            profilePref.setChecked(true);
@@ -258,6 +256,11 @@ public final class DeviceProfilesSettings extends DialogFragment implements
            if (profile instanceof MapProfile) {
                mCachedDevice.setMessagePermissionChoice(BluetoothDevice.ACCESS_ALLOWED);
            }
            if (profile instanceof PbapServerProfile) {
                mCachedDevice.setPhonebookPermissionChoice(BluetoothDevice.ACCESS_ALLOWED);
                refreshProfilePreference(profilePref, profile);
                return;
            }
            if (profile.isPreferred(device)) {
                // profile is preferred but not connected: disable auto-connect
                if (profile instanceof PanProfile) {
@@ -291,11 +294,19 @@ public final class DeviceProfilesSettings extends DialogFragment implements
        DialogInterface.OnClickListener disconnectListener =
                new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                // Disconnect only when user has selected OK
                if (which == OK_BUTTON) {
                    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);
            }
        };
@@ -331,6 +342,19 @@ public final class DeviceProfilesSettings extends DialogFragment implements
        for (LocalBluetoothProfile profile : mCachedDevice.getRemovedProfiles()) {
            CheckBox profilePref = findProfile(profile.toString());
            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");
                mProfileContainer.removeView(profilePref);
            }