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

Commit 0a38abda authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Adapter: Reset adapter connection states when BR/EDR is ready" into oc-mr1-dev

parents d7f81d32 6ce309a3
Loading
Loading
Loading
Loading
+13 −15
Original line number Diff line number Diff line
@@ -65,8 +65,8 @@ class AdapterProperties {
    private CopyOnWriteArrayList<BluetoothDevice> mBondedDevices = new CopyOnWriteArrayList<BluetoothDevice>();

    private int mProfilesConnecting, mProfilesConnected, mProfilesDisconnecting;
    private HashMap<Integer, Pair<Integer, Integer>> mProfileConnectionState;

    private final HashMap<Integer, Pair<Integer, Integer>> mProfileConnectionState =
            new HashMap<>();

    private volatile int mConnectionState = BluetoothAdapter.STATE_DISCONNECTED;
    private volatile int mState = BluetoothAdapter.STATE_OFF;
@@ -156,11 +156,7 @@ class AdapterProperties {
        mAdapter = BluetoothAdapter.getDefaultAdapter();
    }
    public void init(RemoteDevices remoteDevices) {
        if (mProfileConnectionState ==null) {
            mProfileConnectionState = new HashMap<Integer, Pair<Integer, Integer>>();
        } else {
        mProfileConnectionState.clear();
        }
        mRemoteDevices = remoteDevices;

        IntentFilter filter = new IntentFilter();
@@ -182,10 +178,7 @@ class AdapterProperties {

    public void cleanup() {
        mRemoteDevices = null;
        if (mProfileConnectionState != null) {
        mProfileConnectionState.clear();
            mProfileConnectionState = null;
        }
        if (mReceiverRegistered) {
            mService.unregisterReceiver(mReceiver);
            mReceiverRegistered = false;
@@ -762,12 +755,17 @@ class AdapterProperties {
    }

    void onBluetoothReady() {
        Log.d(TAG, "ScanMode =  " + mScanMode );
        Log.d(TAG, "State =  " + getState() );
        debugLog("onBluetoothReady, state=" + getState() + ", ScanMode=" + mScanMode);

        synchronized (mObject) {
            // Reset adapter and profile connection states
            setConnectionState(BluetoothAdapter.STATE_DISCONNECTED);
            mProfileConnectionState.clear();
            mProfilesConnected = 0;
            mProfilesConnecting = 0;
            mProfilesDisconnecting = 0;
            // When BT is being turned on, all adapter properties will be sent in 1
            // callback. At this stage, set the scan mode.
        synchronized (mObject) {
            if (getState() == BluetoothAdapter.STATE_TURNING_ON &&
                    mScanMode == BluetoothAdapter.SCAN_MODE_NONE) {
                    /* mDiscoverableTimeout is part of the
+2 −0
Original line number Diff line number Diff line
@@ -1499,6 +1499,7 @@ public class AdapterService extends Service {
    }

     boolean startDiscovery() {
        debugLog("startDiscovery");
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                       "Need BLUETOOTH ADMIN permission");

@@ -1506,6 +1507,7 @@ public class AdapterService extends Service {
    }

     boolean cancelDiscovery() {
        debugLog("cancelDiscovery");
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                       "Need BLUETOOTH ADMIN permission");