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

Commit 42b2fd9b authored by Android Build Merger (Role)'s avatar Android Build Merger (Role)
Browse files

[automerger] DO NOT MERGE Separate SDP procedure from bonding state (2/2) am:...

[automerger] DO NOT MERGE Separate SDP procedure from bonding state (2/2) am: 36ba892c am: a37455ef am: 2ef64864 am: 0603c803

Change-Id: If0442bd25b0e14b6ad31da1c39644beecba44546
parents ec8ee0e9 0603c803
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -683,8 +683,10 @@ final class A2dpStateMachine extends StateMachine {
        else if((BluetoothProfile.PRIORITY_OFF < priority) ||
                ((BluetoothProfile.PRIORITY_UNDEFINED == priority) &&
                (device.getBondState() != BluetoothDevice.BOND_NONE))){
            if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
                ret = true;
            }
        }
        return ret;
    }

+12 −0
Original line number Diff line number Diff line
@@ -1884,6 +1884,18 @@ public class AdapterService extends Service {
         }
    }

    /**
     * Update device UUID changed to {@link BondStateMachine}
     *
     * @param device remote device of interest
     */
    public void deviceUuidUpdated(BluetoothDevice device) {
        // Notify BondStateMachine for SDP complete / UUID changed.
        Message msg = mBondStateMachine.obtainMessage(BondStateMachine.UUID_UPDATE);
        msg.obj = device;
        mBondStateMachine.sendMessage(msg);
    }

     boolean cancelBondProcess(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission");
        byte[] addr = Utils.getBytesFromAddress(device.getAddress());
+43 −1
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ import com.android.internal.util.State;
import com.android.internal.util.StateMachine;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
 * This state machine handles Bluetooth Adapter State.
@@ -56,6 +58,7 @@ final class BondStateMachine extends StateMachine {
    static final int BONDING_STATE_CHANGE = 4;
    static final int SSP_REQUEST = 5;
    static final int PIN_REQUEST = 6;
    static final int UUID_UPDATE = 10;
    static final int BOND_STATE_NONE = 0;
    static final int BOND_STATE_BONDING = 1;
    static final int BOND_STATE_BONDED = 2;
@@ -65,6 +68,7 @@ final class BondStateMachine extends StateMachine {
    private RemoteDevices mRemoteDevices;
    private BluetoothAdapter mAdapter;

    private Set<BluetoothDevice> mPendingBondedDevices = new HashSet<>();
    private PendingCommandState mPendingCommandState = new PendingCommandState();
    private StableState mStableState = new StableState();

@@ -141,6 +145,11 @@ final class BondStateMachine extends StateMachine {
                    Log.e(TAG, "In stable state, received invalid newState: " + newState);
                }
                break;
              case UUID_UPDATE:
                  if (mPendingBondedDevices.contains(dev)) {
                      sendIntent(dev, BluetoothDevice.BOND_BONDED, 0);
                  }
                  break;

              case CANCEL_BOND:
              default:
@@ -330,12 +339,45 @@ final class BondStateMachine extends StateMachine {
    private void sendIntent(BluetoothDevice device, int newState, int reason) {
        DeviceProperties devProp = mRemoteDevices.getDeviceProperties(device);
        int oldState = BluetoothDevice.BOND_NONE;
        if (newState != BluetoothDevice.BOND_NONE
                && newState != BluetoothDevice.BOND_BONDING
                && newState != BluetoothDevice.BOND_BONDED) {
            infoLog("Invalid bond state " + newState);
            return;
        }
        if (devProp != null) {
            oldState = devProp.getBondState();
        }
        if (oldState == newState) return;
        if (mPendingBondedDevices.contains(device)) {
            mPendingBondedDevices.remove(device);
            if (oldState == BluetoothDevice.BOND_BONDED) {
                if (newState == BluetoothDevice.BOND_BONDING) {
                    mAdapterProperties.onBondStateChanged(device, newState);
                }
                oldState = BluetoothDevice.BOND_BONDING;
            } else {
                // Should not enter here.
                throw new IllegalArgumentException("Invalid old state " + oldState);
            }
        }

        mAdapterProperties.onBondStateChanged(device, newState);

        if ((devProp.getDeviceType() == BluetoothDevice.DEVICE_TYPE_CLASSIC
                || devProp.getDeviceType() == BluetoothDevice.DEVICE_TYPE_DUAL)
                && newState == BluetoothDevice.BOND_BONDED && devProp.getUuids() == null) {
            infoLog(device + " is bonded, wait for SDP complete to broadcast bonded intent");
            if (!mPendingBondedDevices.contains(device)) {
                mPendingBondedDevices.add(device);
            }
            if (oldState == BluetoothDevice.BOND_NONE) {
                // Broadcast NONE->BONDING for NONE->BONDED case.
                newState = BluetoothDevice.BOND_BONDING;
            } else {
                return;
            }
        }

        Intent intent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        intent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, newState);
+3 −1
Original line number Diff line number Diff line
@@ -318,8 +318,10 @@ final class RemoteDevices {
                        case AbstractionLayer.BT_PROPERTY_UUIDS:
                            int numUuids = val.length/AbstractionLayer.BT_UUID_SIZE;
                            device.mUuids = Utils.byteArrayToUuid(val);
                            if (mAdapterService.getState() == BluetoothAdapter.STATE_ON)
                            if (mAdapterService.getState() == BluetoothAdapter.STATE_ON) {
                                mAdapterService.deviceUuidUpdated(bdDevice);
                                sendUuidIntent(bdDevice);
                            }
                            break;
                        case AbstractionLayer.BT_PROPERTY_TYPE_OF_DEVICE:
                            // The device type from hal layer, defined in bluetooth.h,
+4 −1
Original line number Diff line number Diff line
@@ -3444,8 +3444,11 @@ final class HeadsetStateMachine extends StateMachine {
        else if((BluetoothProfile.PRIORITY_OFF < priority) ||
                ((BluetoothProfile.PRIORITY_UNDEFINED == priority) &&
                (device.getBondState() != BluetoothDevice.BOND_NONE))){
            if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
                ret = true;
            }
 
        }
        return ret;
    }

Loading