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

Commit 51a7895a authored by Myles Watson's avatar Myles Watson Committed by Hansong Zhang
Browse files

Revert "DO NOT MERGE Separate SDP procedure from bonding state (2/2)"

This reverts commit 00636461.

Bug: 79703832
Bug: 130553855
Reason for revert: Regression with cross-key pairing

Change-Id: I1171a0255ad13c4e5ae993a0aab2eed3dfab19af
Merged-In: Ib0a552ffc06286e63f8114db5d918718fcc1c3cc
parent 43d0b638
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -878,10 +878,8 @@ 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;
    }

+1 −3
Original line number Diff line number Diff line
@@ -716,10 +716,8 @@ public class A2dpSinkStateMachine extends StateMachine {
        if((BluetoothProfile.PRIORITY_OFF < priority) ||
                ((BluetoothProfile.PRIORITY_UNDEFINED == priority) &&
                (device.getBondState() != BluetoothDevice.BOND_NONE))){
            if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
            return true;
        }
        }
        logw("okToConnect not OK to connect " + device);
        return false;
    }
+0 −12
Original line number Diff line number Diff line
@@ -1582,18 +1582,6 @@ 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());
+1 −42
Original line number Diff line number Diff line
@@ -40,8 +40,6 @@ 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.
@@ -61,7 +59,6 @@ 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;
@@ -71,7 +68,6 @@ 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();

@@ -148,11 +144,6 @@ 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:
@@ -341,44 +332,12 @@ 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 (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);
            }
        }

        if (oldState == newState) return;
        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);
+1 −3
Original line number Diff line number Diff line
@@ -347,10 +347,8 @@ 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) {
                                mAdapterService.deviceUuidUpdated(bdDevice);
                            if (mAdapterService.getState() == BluetoothAdapter.STATE_ON)
                                sendUuidIntent(bdDevice);
                            }
                            break;
                        case AbstractionLayer.BT_PROPERTY_TYPE_OF_DEVICE:
                            // The device type from hal layer, defined in bluetooth.h,
Loading