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

Commit b9046947 authored by Hemant Gupta's avatar Hemant Gupta
Browse files

MAP: Remove pending MAP authorization pop up

- If USER turn off BT on DUT before accepting incoming
authorization request for MAP connection, then MAP
authorization pop up should be removed. Thsi was failing
as user time-out scenario was not handled currently,
where MAP OBEX session is stopped. So MAP OBEX session will
not get cleared till BT OFF. So MAP OBEX connection was failing
from next iteration onward. Queuing User time-out(30 seconds)
to disconnect MAP OBEX session to solve this issue.

-If ACL is disconnected by remote device before accepting
incoming authorization request for MAP connection, then MAP
authorization pop up should be removed.

Change-Id: Ib8068f793eb1b55a155d3ff657efefc40728233c
parent 63260439
Loading
Loading
Loading
Loading
+59 −4
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ public class BluetoothMapService extends ProfileService {
     */
    public static final String USER_CONFIRM_TIMEOUT_ACTION =
            "com.android.bluetooth.map.userconfirmtimeout";
    private static final int USER_CONFIRM_TIMEOUT_VALUE = 30000;

    /**
     * Intent Extra name indicating session key which is sent from
@@ -140,6 +141,7 @@ public class BluetoothMapService extends ProfileService {
    private int mState;

    private boolean isWaitingAuthorization = false;
    private boolean removeTimeoutMsg = false;

    // package and class name to which we send intent to check message access access permission
    private static final String ACCESS_AUTHORITY_PACKAGE = "com.android.settings";
@@ -426,6 +428,12 @@ public class BluetoothMapService extends ProfileService {

                        if (DEBUG) Log.d(TAG, "waiting for authorization for connection from: "
                                + sRemoteDeviceName);
                        //Queue USER_TIMEOUT to disconnect MAP OBEX session. If user doesn't
                        //accept or reject authorization request
                        removeTimeoutMsg = true;
                        mSessionStatusHandler.sendMessageDelayed(mSessionStatusHandler
                                .obtainMessage(USER_TIMEOUT), USER_CONFIRM_TIMEOUT_VALUE);


                    }
                    stopped = true; // job done ,close this thread;
@@ -455,11 +463,12 @@ public class BluetoothMapService extends ProfileService {
                    break;
                case USER_TIMEOUT:
                    Intent intent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL);
                    intent.setClassName(ACCESS_AUTHORITY_PACKAGE, ACCESS_AUTHORITY_CLASS);
                    intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice);
                    intent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                    BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS);
                    sendBroadcast(intent);
                    sendBroadcast(intent, BLUETOOTH_PERM);
                    isWaitingAuthorization = false;
                    removeTimeoutMsg = false;
                    stopObexServerSession();
                    break;
                case MSG_SERVERSESSION_CLOSE:
@@ -633,6 +642,7 @@ public class BluetoothMapService extends ProfileService {
        IntentFilter filter = new IntentFilter();
        filter.addAction(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY);
        filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
        filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
        try {
            registerReceiver(mMapReceiver, filter);
        } catch (Exception e) {
@@ -667,6 +677,7 @@ public class BluetoothMapService extends ProfileService {
        return true;
    }


    private MapBroadcastReceiver mMapReceiver = new MapBroadcastReceiver();

    private class MapBroadcastReceiver extends BroadcastReceiver {
@@ -678,7 +689,22 @@ public class BluetoothMapService extends ProfileService {
                int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
                                               BluetoothAdapter.ERROR);
                if (state == BluetoothAdapter.STATE_TURNING_OFF) {
                    if (DEBUG) Log.d(TAG, "STATE_TURNING_OFF");
                    if (DEBUG) Log.d(TAG, "STATE_TURNING_OFF removeTimeoutMsg:" + removeTimeoutMsg);
                    // Send any pending timeout now, as this service will be destroyed.
                    if (removeTimeoutMsg) {
                        mSessionStatusHandler.removeMessages(USER_TIMEOUT);

                        Intent timeoutIntent =
                                new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL);
                        timeoutIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice);
                        timeoutIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                               BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS);
                        sendBroadcast(timeoutIntent, BLUETOOTH_PERM);
                        isWaitingAuthorization = false;
                        removeTimeoutMsg = false;
                        stopObexServerSession();
                    }

                    // Release all resources
                    closeService();
                } else if (state == BluetoothAdapter.STATE_ON) {
@@ -692,7 +718,7 @@ public class BluetoothMapService extends ProfileService {
                int requestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                               BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
                if (DEBUG) Log.d(TAG, "Received ACTION_CONNECTION_ACCESS_REPLY:" +
                           requestType + ":" + isWaitingAuthorization);
                           requestType + "isWaitingAuthorization:" + isWaitingAuthorization);
                if ((!isWaitingAuthorization) ||
                    (requestType != BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS)) {
                    // this reply is not for us
@@ -700,6 +726,10 @@ public class BluetoothMapService extends ProfileService {
                }

                isWaitingAuthorization = false;
                if (removeTimeoutMsg) {
                    mSessionStatusHandler.removeMessages(USER_TIMEOUT);
                    removeTimeoutMsg = false;
                }

                if (intent.getIntExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT,
                                       BluetoothDevice.CONNECTION_ACCESS_NO) ==
@@ -722,6 +752,31 @@ public class BluetoothMapService extends ProfileService {
                } else {
                    stopObexServerSession();
                }
            } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED) &&
                    isWaitingAuthorization) {
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

                if (mRemoteDevice == null || device == null) {
                    Log.e(TAG, "Unexpected error!");
                    return;
                }

                if (DEBUG) Log.d(TAG,"ACL disconnected for "+ device);

                if (mRemoteDevice.equals(device) && removeTimeoutMsg) {
                    // Send any pending timeout now, as ACL got disconnected.
                    mSessionStatusHandler.removeMessages(USER_TIMEOUT);

                    Intent timeoutIntent =
                            new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL);
                    timeoutIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice);
                    timeoutIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                           BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS);
                    sendBroadcast(timeoutIntent, BLUETOOTH_PERM);
                    isWaitingAuthorization = false;
                    removeTimeoutMsg = false;
                    stopObexServerSession();
                }
            }
        }
    };