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

Commit 02bf7ae9 authored by Hemant Gupta's avatar Hemant Gupta Committed by Arne Coucheron
Browse files

PBAP: Add support for handling connection state

This patch adds support for updating connection state for pbap server
on settings UI. A new flag is added to allow settings sub menu to
show pbap preference only when remote device has intiaited pbap
request and not for all devices for which user has started/accepted
pairing request from remote device.

Change-Id: I3ba777a6be4a6321a260739b9a87a8c6054a74d3
CRs-Fixed: 758697
parent 1e84e28b
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -1768,8 +1768,7 @@ public class AdapterService extends Service {
        if (!pref.contains(device.getAddress())) {
            return BluetoothDevice.ACCESS_UNKNOWN;
        }
        return pref.getBoolean(device.getAddress(), false)
                ? BluetoothDevice.ACCESS_ALLOWED : BluetoothDevice.ACCESS_REJECTED;
        return pref.getInt(device.getAddress(), BluetoothDevice.ACCESS_UNKNOWN);
    }

    boolean setPhonebookAccessPermission(BluetoothDevice device, int value) {
@@ -1781,7 +1780,7 @@ public class AdapterService extends Service {
        if (value == BluetoothDevice.ACCESS_UNKNOWN) {
            editor.remove(device.getAddress());
        } else {
            editor.putBoolean(device.getAddress(), value == BluetoothDevice.ACCESS_ALLOWED);
            editor.putInt(device.getAddress(), value);
        }
        return editor.commit();
    }
+1 −1
Original line number Diff line number Diff line
@@ -1029,7 +1029,7 @@ public class BluetoothMapService extends ProfileService {
                }
            } else if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY)) {
                int requestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                               BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
                                               BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS);
                if (DEBUG) Log.d(TAG, "Received ACTION_CONNECTION_ACCESS_REPLY:" +
                           requestType + "isWaitingAuthorization:" + isWaitingAuthorization);
                if ((!isWaitingAuthorization) ||
+11 −5
Original line number Diff line number Diff line
@@ -178,6 +178,9 @@ public class BluetoothPbapService extends Service {

    private int mStartId = -1;

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

    //private IBluetooth mBluetoothService;

    private boolean mIsWaitingAuthorization = false;
@@ -295,9 +298,9 @@ public class BluetoothPbapService extends Service {

                if (intent.getBooleanExtra(BluetoothDevice.EXTRA_ALWAYS_ALLOWED, false)) {
                    boolean result = mRemoteDevice.setPhonebookAccessPermission(
                            BluetoothDevice.ACCESS_ALLOWED);
                            PBAP_CONNECT_RECEIVED);
                    if (VERBOSE) {
                        Log.v(TAG, "setPhonebookAccessPermission(ACCESS_ALLOWED) result="
                        Log.v(TAG, "setPhonebookAccessPermission(PBAP_CONNECT_RECEIVED) result="
                                + result);
                    }
                }
@@ -614,12 +617,15 @@ public class BluetoothPbapService extends Service {
                    int permission = mRemoteDevice.getPhonebookAccessPermission();
                    if (VERBOSE) Log.v(TAG, "getPhonebookAccessPermission() = " + permission);

                    if (permission == BluetoothDevice.ACCESS_ALLOWED) {
                    if (permission == BluetoothDevice.ACCESS_ALLOWED ||
                        permission == PBAP_CONNECT_RECEIVED) {
                        try {
                            if (VERBOSE) {
                                Log.v(TAG, "incoming connection accepted from: " + sRemoteDeviceName
                                        + " automatically as already allowed device");
                            }
                            // update permission access request
                            mRemoteDevice.setPhonebookAccessPermission(PBAP_CONNECT_RECEIVED);
                            startObexServerSession();
                        } catch (IOException ex) {
                            Log.e(TAG, "Caught exception starting obex server session"
@@ -756,8 +762,8 @@ public class BluetoothPbapService extends Service {
            int prevState = mState;
            mState = state;
            Intent intent = new Intent(BluetoothPbap.PBAP_STATE_CHANGED_ACTION);
            intent.putExtra(BluetoothPbap.PBAP_PREVIOUS_STATE, prevState);
            intent.putExtra(BluetoothPbap.PBAP_STATE, mState);
            intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
            intent.putExtra(BluetoothProfile.EXTRA_STATE, mState);
            intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice);
            sendBroadcast(intent, BLUETOOTH_PERM);
            AdapterService s = AdapterService.getAdapterService();