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

Commit 20bb403d authored by Hemant Gupta's avatar Hemant Gupta Committed by Gerrit - the friendly Code Review server
Browse files

Bluetooth: Add PBAP Profile to preference list in special case

This patch adds pbap profile to preference list only when pbap connect
request has been recieved from pbap client. Also implemenation for showing
connection state changes for PBAP is now added to Settings UI so that
user can see latest state of PBAP Server connection. Without this change,
settings UI was showing PBAP preference checkbox for all devices for which
pairing was performed by user intervention irrespective of remote
device supporting pbap or not. Also some updates are done to show MAP
connection updates shown dynamically.

Change-Id: I4ec463bf398c45e81cee4ae8ceb693e346dd5b5c
CRs-Fixed: 758697
parent bc2d463f
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -286,6 +286,8 @@
    <string name="bluetooth_connected_no_headset">Connected (no phone)</string>
    <!-- Bluetooth settings.  Message when connected to a device, except for media audio. [CHAR LIMIT=40] -->
    <string name="bluetooth_connected_no_a2dp">Connected (no media)</string>
    <!-- Bluetooth settings.  Message when connected to a device, except for pbap. [CHAR LIMIT=40] -->
    <string name="bluetooth_connected_no_pbap">Connected (no phonebook access)</string>
    <!-- Bluetooth settings.  Message when connected to a device, except for map. [CHAR LIMIT=40] -->
    <string name="bluetooth_connected_no_map">Connected (no message access)</string>
    <!-- Bluetooth settings.  Message when connected to a device, except for phone/media audio. [CHAR LIMIT=40] -->
@@ -1259,8 +1261,6 @@
    <string name="bluetooth_profile_pan">Internet access</string>
    <!-- Bluetooth settings. The user-visible string that is used whenever referring to the PBAP profile. [CHAR LIMIT=40] -->
    <string name="bluetooth_profile_pbap">Contact sharing</string>
    <!-- Bluetooth settings. The user-visible summary string that is used whenever referring to the PBAP profile (sharing contacts). [CHAR LIMIT=60] -->
    <string name="bluetooth_profile_pbap_summary">Use for contact sharing</string>
    <!-- Bluetooth settings. The user-visible string that is used whenever referring to the PAN profile (sharing this device's Internet connection). [CHAR LIMIT=40] -->
    <string name="bluetooth_profile_pan_nap">Internet connection sharing</string>
    <!-- Bluetooth settings.  The user-visible string that is used whenever referring to the map profile. -->
@@ -1301,6 +1301,8 @@
    <string name="bluetooth_headset_profile_summary_connected">Connected to phone audio</string>
    <!-- Bluetooth settings.  Connection options screen.  The summary for the OPP checkbox preference when OPP is connected. -->
    <string name="bluetooth_opp_profile_summary_connected">Connected to file transfer server</string>
    <!-- Bluetooth settings.  Connection options screen.  The summary for the pbap checkbox preference when pbap is connected. -->
    <string name="bluetooth_pbap_profile_summary_connected">Connected to pbap server</string>
    <!-- Bluetooth settings.  Connection options screen.  The summary for the map checkbox preference when map is connected. -->
    <string name="bluetooth_map_profile_summary_connected">Connected to map</string>
    <!-- Bluetooth settings.  Connection options screen.  The summary for the DUN checkbox preference when DUN is connected. -->
@@ -1334,6 +1336,8 @@
         for the PAN checkbox preference that describes how checking it
         will set the PAN profile as preferred. -->
    <string name="bluetooth_pan_profile_summary_use_for">Use for Internet access</string>
    <!-- Bluetooth settings.  Connection options screen.  The summary for the pbap checkbox preference that describes how checking it will set the pbap profile as preferred. -->
    <string name="bluetooth_pbap_profile_summary_use_for">Use for Contact sharing</string>
    <!-- Bluetooth settings.  Connection options screen.  The summary for the map checkbox preference that describes how checking it will set the map profile as preferred. -->
    <string name="bluetooth_map_profile_summary_use_for">Use for map</string>

+2 −1
Original line number Diff line number Diff line
@@ -217,7 +217,8 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {

            if (phonebookPermission == CachedBluetoothDevice.ACCESS_UNKNOWN) {
                // Leave 'processed' as false.
            } else if (phonebookPermission == CachedBluetoothDevice.ACCESS_ALLOWED) {
            } else if (phonebookPermission == CachedBluetoothDevice.ACCESS_ALLOWED ||
                phonebookPermission == CachedBluetoothDevice.PBAP_CONNECT_RECEIVED) {
                sendReplyIntentToReceiver(true);
                processed = true;
            } else if (phonebookPermission == CachedBluetoothDevice.ACCESS_REJECTED) {
+8 −14
Original line number Diff line number Diff line
@@ -83,6 +83,9 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
    // User has rejected the connection and let Settings app remember the decision
    public final static int ACCESS_REJECTED = 2;

    // PBAP Client has sent pbap connection request
    public final static int PBAP_CONNECT_RECEIVED = 3;

    // How many times user should reject the connection to make the choice persist.
    private final static int MESSAGE_REJECTION_COUNT_LIMIT_TO_PERSIST = 2;

@@ -140,6 +143,8 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
        if (newProfileState == BluetoothProfile.STATE_CONNECTED) {
            if (profile instanceof MapProfile) {
                profile.setPreferred(mDevice, true);
                mRemovedProfiles.remove(profile);
                mProfiles.add(profile);
            } else if (!mProfiles.contains(profile)) {
                mRemovedProfiles.remove(profile);
                mProfiles.add(profile);
@@ -712,23 +717,12 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
    }

    int getPhonebookPermissionChoice() {
        int permission = mDevice.getPhonebookAccessPermission();
        if (permission == BluetoothDevice.ACCESS_ALLOWED) {
            return ACCESS_ALLOWED;
        } else if (permission == BluetoothDevice.ACCESS_REJECTED) {
            return ACCESS_REJECTED;
        }
        return ACCESS_UNKNOWN;
        return mDevice.getPhonebookAccessPermission();
    }

    void setPhonebookPermissionChoice(int permissionChoice) {
        int permission = BluetoothDevice.ACCESS_UNKNOWN;
        if (permissionChoice == ACCESS_ALLOWED) {
            permission = BluetoothDevice.ACCESS_ALLOWED;
        } else if (permissionChoice == ACCESS_REJECTED) {
            permission = BluetoothDevice.ACCESS_REJECTED;
        }
        mDevice.setPhonebookAccessPermission(permission);
        Log.d(TAG,"setPhonebookPermissionChoice, permissionChoice = " + permissionChoice);
        mDevice.setPhonebookAccessPermission(permissionChoice);
    }

    // Migrates data from old data store (in Settings app's shared preferences) to new (in Bluetooth
+33 −22
Original line number Diff line number Diff line
@@ -144,21 +144,26 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
    private void addPreferencesForProfiles() {
        mProfileContainer.removeAll();
        for (LocalBluetoothProfile profile : mCachedDevice.getConnectableProfiles()) {
            // MAP and PBAP profiles would be added based on permission access
            if (!((profile instanceof PbapServerProfile) ||
                (profile instanceof MapProfile))) {
                Preference pref = createProfilePreference(profile);
                mProfileContainer.addPreference(pref);
            }
        }

        final int pbapPermission = mCachedDevice.getPhonebookPermissionChoice();
        // Only provide PBAP cabability if the client device has requested PBAP.
        if (pbapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) {
        Log.d(TAG, "addPreferencesForProfiles: pbapPermission = " + pbapPermission);
        if (pbapPermission == CachedBluetoothDevice.PBAP_CONNECT_RECEIVED) {
            final PbapServerProfile psp = mManager.getProfileManager().getPbapProfile();
            CheckBoxPreference pbapPref = createProfilePreference(psp);
            mProfileContainer.addPreference(pbapPref);
        }

        final MapProfile mapProfile = mManager.getProfileManager().getMapProfile();
        final int mapPermission = mCachedDevice.getMessagePermissionChoice();
        Log.d(TAG, "addPreferencesForProfiles: mapPermission = " + mapPermission);
        if (mapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) {
            final MapProfile mapProfile = mManager.getProfileManager().getMapProfile();
            CheckBoxPreference mapPreference = createProfilePreference(mapProfile);
            mProfileContainer.addPreference(mapPreference);
        }
@@ -221,15 +226,6 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
    private void onProfileClicked(LocalBluetoothProfile profile, CheckBoxPreference profilePref) {
        BluetoothDevice device = mCachedDevice.getDevice();

        if (profilePref.getKey().equals(KEY_PBAP_SERVER)) {
            final int newPermission = mCachedDevice.getPhonebookPermissionChoice()
                == CachedBluetoothDevice.ACCESS_ALLOWED ? CachedBluetoothDevice.ACCESS_REJECTED
                : CachedBluetoothDevice.ACCESS_ALLOWED;
            mCachedDevice.setPhonebookPermissionChoice(newPermission);
            profilePref.setChecked(newPermission == CachedBluetoothDevice.ACCESS_ALLOWED);
            return;
        }

        int status = profile.getConnectionStatus(device);
        boolean isConnected =
                status == BluetoothProfile.STATE_CONNECTED;
@@ -240,6 +236,12 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
            if (profile instanceof MapProfile) {
                mCachedDevice.setMessagePermissionChoice(BluetoothDevice.ACCESS_ALLOWED);
                refreshProfilePreference(profilePref, profile);
            } else if (profile instanceof PbapServerProfile) {
                // Special handling for pbap server, as server cant connect to client
                mCachedDevice.setPhonebookPermissionChoice(
                    CachedBluetoothDevice.PBAP_CONNECT_RECEIVED);
                refreshProfilePreference(profilePref, profile);
                return;
            }
            if (profile.isPreferred(device)) {
                // profile is preferred but not connected: disable auto-connect
@@ -284,6 +286,11 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
                        refreshProfilePreference(
                            (CheckBoxPreference)findPreference(profile.toString()), profile);
                    }
                    if (profile instanceof PbapServerProfile) {
                        device.setPhonebookPermissionChoice(BluetoothDevice.ACCESS_REJECTED);
                        refreshProfilePreference(
                            (CheckBoxPreference)findPreference(profile.toString()), profile);
                    }
                }
            }
        };
@@ -316,9 +323,16 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
                refreshProfilePreference(profilePref, profile);
            }
        }

        for (LocalBluetoothProfile profile : mCachedDevice.getRemovedProfiles()) {
            Preference profilePref = findPreference(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;
                }
                Log.d(TAG, "Removing " + profile.toString() + " from profile list");
                mProfileContainer.removePreference(profilePref);
            }
@@ -338,15 +352,12 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
            profilePref.setChecked(mCachedDevice.getMessagePermissionChoice()
                    == CachedBluetoothDevice.ACCESS_ALLOWED);
        } else if (profile instanceof PbapServerProfile) {
            // Handle PBAP specially.
            profilePref.setChecked(mCachedDevice.getPhonebookPermissionChoice()
                    == CachedBluetoothDevice.ACCESS_ALLOWED);
        }
        if (profile instanceof PanProfile) {
                    == CachedBluetoothDevice.PBAP_CONNECT_RECEIVED);
        } else if (profile instanceof PanProfile) {
                profilePref.setChecked(profile.getConnectionStatus(device) ==
                        BluetoothProfile.STATE_CONNECTED);
        }
        else {
        } else {
            profilePref.setChecked(profile.isPreferred(device));
        }
        profilePref.setSummary(profile.getSummaryResourceForDevice(device));
+10 −3
Original line number Diff line number Diff line
@@ -146,10 +146,10 @@ final class LocalBluetoothProfileManager {
                    BluetoothSap.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
        mPbapProfile = new PbapServerProfile(context);
        addProfile(mPbapProfile, PbapServerProfile.NAME,
               BluetoothPbap.PBAP_STATE_CHANGED_ACTION);

        if (DEBUG) Log.d(TAG, "LocalBluetoothProfileManager construction complete");
    }
@@ -263,6 +263,7 @@ final class LocalBluetoothProfileManager {
            }
            int newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0);
            int oldState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, 0);
            Log.w(TAG, "StateChangedHandler mProfile = " + mProfile + " new state = " + newState);
            if (newState == BluetoothProfile.STATE_DISCONNECTED &&
                    oldState == BluetoothProfile.STATE_CONNECTING) {
                Log.i(TAG, "Failed to connect " + mProfile + " device");
@@ -429,6 +430,12 @@ final class LocalBluetoothProfileManager {
            removedProfiles.remove(mMapProfile);
            mMapProfile.setPreferred(device, true);
        }

        if ((mPbapProfile != null) &&
            (mPbapProfile.getConnectionStatus(device) == BluetoothProfile.STATE_CONNECTED)) {
            profiles.add(mPbapProfile);
            removedProfiles.remove(mPbapProfile);
        }
    }

}
Loading