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

Commit b6890571 authored by Marie Janssen's avatar Marie Janssen Committed by android-build-merger
Browse files

Merge "Broadcast pairing intents to settings package" am: a92cdfb7 am: cacdc5a5

am: f21a1041

Change-Id: I1a822c2243914df00c0ffbd9794ea9ca69d7d676
parents d6906d2e f21a1041
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -114,7 +114,6 @@
            android:enabled="@bool/profile_supported_opp">
            <intent-filter>
                <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
                <!--action android:name="android.intent.action.BOOT_COMPLETED" /-->
                <action android:name="android.btopp.intent.action.OPEN_RECEIVED_FILES" />
            </intent-filter>
        </receiver>
+4 −2
Original line number Diff line number Diff line
@@ -72,6 +72,8 @@ final class BondStateMachine extends StateMachine {

    public static final String OOBDATA = "oobdata";

    private static final String PAIRING_REQUEST_PACKAGE = "com.android.settings";

    private BondStateMachine(AdapterService service,
            AdapterProperties prop, RemoteDevices remoteDevices) {
        super("BondStateMachine:");
@@ -177,8 +179,6 @@ final class BondStateMachine extends StateMachine {
                 return true;
             }

            Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST);

            switch (msg.what) {
                case CREATE_BOND:
                    OobData oobData = null;
@@ -326,6 +326,7 @@ final class BondStateMachine extends StateMachine {
        }
        intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, variant);
        intent.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        intent.setPackage(PAIRING_REQUEST_PACKAGE);
        mAdapterService.sendOrderedBroadcast(intent, mAdapterService.BLUETOOTH_ADMIN_PERM);
    }

@@ -344,6 +345,7 @@ final class BondStateMachine extends StateMachine {
        intent.putExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, oldState);
        if (newState == BluetoothDevice.BOND_NONE)
            intent.putExtra(BluetoothDevice.EXTRA_REASON, reason);
        intent.setPackage(PAIRING_REQUEST_PACKAGE);
        mAdapterService.sendBroadcastAsUser(intent, UserHandle.ALL,
                AdapterService.BLUETOOTH_PERM);
        infoLog("Bond State Change Intent:" + device + " OldState: " + oldState
+7 −8
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ final class RemoteDevices {
    private static final int UUID_INTENT_DELAY = 6000;
    private static final int MESSAGE_UUID_INTENT = 1;

    private static final String PAIRING_REQUEST_PACKAGE = "com.android.settings";

    private HashMap<String, DeviceProperties> mDevices;
    private Queue<String> mDeviceQueue;

@@ -398,12 +400,8 @@ final class RemoteDevices {
            return;
        }
        int state = mAdapterService.getState();
        Log.e(TAG, "state" + state + "newState" + newState);
        Log.e(TAG, "state " + BluetoothAdapter.nameForState(state) + " newState " + newState);

        DeviceProperties prop = getDeviceProperties(device);
        if (prop == null) {
 //         errorLog("aclStateChangeCallback reported unknown device " + Arrays.toString(address));
        }
        Intent intent = null;
        if (newState == AbstractionLayer.BT_ACL_STATE_CONNECTED) {
            if (state == BluetoothAdapter.STATE_ON || state == BluetoothAdapter.STATE_TURNING_ON) {
@@ -411,12 +409,13 @@ final class RemoteDevices {
            } else if (state == BluetoothAdapter.STATE_BLE_ON || state == BluetoothAdapter.STATE_BLE_TURNING_ON) {
                intent = new Intent(BluetoothAdapter.ACTION_BLE_ACL_CONNECTED);
            }
            debugLog("aclStateChangeCallback: State:Connected to Device:" + device);
            debugLog("aclStateChangeCallback: Connected: " + device);
        } else {
            if (device.getBondState() == BluetoothDevice.BOND_BONDING) {
                /*Broadcasting PAIRING_CANCEL intent as well in this case*/
                // Send PAIRING_CANCEL intent to dismiss any dialog requesting bonding.
                intent = new Intent(BluetoothDevice.ACTION_PAIRING_CANCEL);
                intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
                intent.setPackage(PAIRING_REQUEST_PACKAGE);
                mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_PERM);
            }
            if (state == BluetoothAdapter.STATE_ON || state == BluetoothAdapter.STATE_TURNING_OFF) {
@@ -424,7 +423,7 @@ final class RemoteDevices {
            } else if (state == BluetoothAdapter.STATE_BLE_ON || state == BluetoothAdapter.STATE_BLE_TURNING_OFF) {
                intent = new Intent(BluetoothAdapter.ACTION_BLE_ACL_DISCONNECTED);
            }
            debugLog("aclStateChangeCallback: State:DisConnected to Device:" + device);
            debugLog("aclStateChangeCallback: Disconnected: " + device);
        }
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+6 −18
Original line number Diff line number Diff line
@@ -155,8 +155,6 @@ public class BluetoothMapService extends ProfileService {

    // package and class name to which we send intent to check phone book access permission
    private static final String ACCESS_AUTHORITY_PACKAGE = "com.android.settings";
    private static final String ACCESS_AUTHORITY_CLASS =
        "com.android.settings.bluetooth.BluetoothPermissionRequest";

    private static final ParcelUuid[] MAP_UUIDS = {
        BluetoothUuid.MAP,
@@ -363,7 +361,7 @@ public class BluetoothMapService extends ProfileService {
                case USER_TIMEOUT:
                    if (mIsWaitingAuthorization) {
                        Intent intent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL);
                        intent.setClassName(ACCESS_AUTHORITY_PACKAGE, ACCESS_AUTHORITY_CLASS);
                        intent.setPackage(ACCESS_AUTHORITY_PACKAGE);
                        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice);
                        intent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS);
@@ -873,7 +871,7 @@ public class BluetoothMapService extends ProfileService {
        if (sendIntent) {
            // This will trigger Settings app's dialog.
            Intent intent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_REQUEST);
            intent.setClassName(ACCESS_AUTHORITY_PACKAGE, ACCESS_AUTHORITY_CLASS);
            intent.setPackage(ACCESS_AUTHORITY_PACKAGE);
            intent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                            BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS);
            intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice);
@@ -1127,19 +1125,9 @@ public class BluetoothMapService extends ProfileService {
                if (VERBOSE) Log.v(TAG,"ACL disconnected for " + device);

                if (mRemoteDevice.equals(device)) {
                    // Send any pending timeout now, as ACL got disconnected.
                    // Send any pending timeout now, since 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);
                    mIsWaitingAuthorization = false;
                    cancelUserTimeoutAlarm();
                    mSessionStatusHandler.obtainMessage(MSG_SERVERSESSION_CLOSE, -1, 0)
                            .sendToTarget();
                    mSessionStatusHandler.obtainMessage(USER_TIMEOUT).sendToTarget();
                }
            }
        }
+32 −44
Original line number Diff line number Diff line
@@ -180,8 +180,6 @@ public class BluetoothPbapService extends Service {

    // package and class name to which we send intent to check phone book access permission
    private static final String ACCESS_AUTHORITY_PACKAGE = "com.android.settings";
    private static final String ACCESS_AUTHORITY_CLASS =
        "com.android.settings.bluetooth.BluetoothPermissionRequest";

    public BluetoothPbapService() {
        mState = BluetoothPbap.STATE_DISCONNECTED;
@@ -234,44 +232,31 @@ public class BluetoothPbapService extends Service {
        int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
        if (VERBOSE) Log.v(TAG, "state: " + state);

        boolean removeTimeoutMsg = true;
        if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
            if (state == BluetoothAdapter.STATE_TURNING_OFF) {
        if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)
                && (state == BluetoothAdapter.STATE_TURNING_OFF)) {
            // Send any pending timeout now, as this service will be destroyed.
            if (mSessionStatusHandler.hasMessages(USER_TIMEOUT)) {
                    Intent timeoutIntent =
                        new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL);
                    timeoutIntent.setClassName(ACCESS_AUTHORITY_PACKAGE, ACCESS_AUTHORITY_CLASS);
                    timeoutIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                     BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
                    sendBroadcast(timeoutIntent, BLUETOOTH_ADMIN_PERM);
                mSessionStatusHandler.removeMessages(USER_TIMEOUT);
                mSessionStatusHandler.obtainMessage(USER_TIMEOUT).sendToTarget();
            }
            // Release all resources
            closeService();
            } else {
                removeTimeoutMsg = false;
            }
        } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)
                && mIsWaitingAuthorization) {
            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 (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED) && mIsWaitingAuthorization) {
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            if (mRemoteDevice == null) return;
            if (DEBUG) Log.d(TAG,"ACL disconnected for "+ device);
            if (mRemoteDevice.equals(device)) {
                Intent cancelIntent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL);
                cancelIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
                cancelIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                      BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
                sendBroadcast(cancelIntent);
                mIsWaitingAuthorization = false;
                stopObexServerSession();
                mSessionStatusHandler.removeMessages(USER_TIMEOUT);
                mSessionStatusHandler.obtainMessage(USER_TIMEOUT).sendToTarget();
            }
            return;
        }
        } else if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY)) {

        if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY)) {
            int requestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                           BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);

@@ -281,6 +266,7 @@ public class BluetoothPbapService extends Service {
                return;
            }

            mSessionStatusHandler.removeMessages(USER_TIMEOUT);
            mIsWaitingAuthorization = false;

            if (intent.getIntExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT,
@@ -290,7 +276,7 @@ public class BluetoothPbapService extends Service {
                    boolean result = mRemoteDevice.setPhonebookAccessPermission(
                            BluetoothDevice.ACCESS_ALLOWED);
                    if (VERBOSE) {
                        Log.v(TAG, "setPhonebookAccessPermission(ACCESS_ALLOWED) result=" + result);
                        Log.v(TAG, "setPhonebookAccessPermission(ACCESS_ALLOWED)=" + result);
                    }
                }
                try {
@@ -307,25 +293,26 @@ public class BluetoothPbapService extends Service {
                    boolean result = mRemoteDevice.setPhonebookAccessPermission(
                            BluetoothDevice.ACCESS_REJECTED);
                    if (VERBOSE) {
                        Log.v(TAG, "setPhonebookAccessPermission(ACCESS_REJECTED) result="
                                + result);
                        Log.v(TAG, "setPhonebookAccessPermission(ACCESS_REJECTED)=" + result);
                    }
                }
                stopObexServerSession();
            }
        } else if (action.equals(AUTH_RESPONSE_ACTION)) {
            return;
        }

        if (action.equals(AUTH_RESPONSE_ACTION)) {
            String sessionkey = intent.getStringExtra(EXTRA_SESSION_KEY);
            notifyAuthKeyInput(sessionkey);
        } else if (action.equals(AUTH_CANCELLED_ACTION)) {
            notifyAuthCancelled();
        } else {
            removeTimeoutMsg = false;
            Log.w(TAG, "Unrecognized intent!");
            return;
        }

        if (removeTimeoutMsg) {
        mSessionStatusHandler.removeMessages(USER_TIMEOUT);
    }
    }

    @Override
    public void onDestroy() {
@@ -625,7 +612,7 @@ public class BluetoothPbapService extends Service {
                        // Send an Intent to Settings app to ask user preference.
                        Intent intent =
                                new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_REQUEST);
                        intent.setClassName(ACCESS_AUTHORITY_PACKAGE, ACCESS_AUTHORITY_CLASS);
                        intent.setPackage(ACCESS_AUTHORITY_PACKAGE);
                        intent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                        BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
                        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice);
@@ -682,10 +669,11 @@ public class BluetoothPbapService extends Service {
                    break;
                case USER_TIMEOUT:
                    Intent intent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL);
                    intent.setPackage(ACCESS_AUTHORITY_PACKAGE);
                    intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice);
                    intent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                    BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
                    sendBroadcast(intent);
                    sendBroadcast(intent, BLUETOOTH_ADMIN_PERM);
                    mIsWaitingAuthorization = false;
                    stopObexServerSession();
                    break;
Loading