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

Commit 9a6a5762 authored by Nitin Arora's avatar Nitin Arora Committed by Linux Build Service Account
Browse files

Bluetooth: Tracking the devices added using BLE On Apps

This change keeps a hashset of the devices connected using BLE Always
On Apps, so that when ACL disconnection callbacks are received in
STATE_BLE_ON or BLE_TURNING_OFF, the BLE_ACL_DISCONNECTED broadcast
is sent to only those ACL connections wheras the other devices
disconnecting due to reasons such as BT turn Off or SSR can still
receive ACL_DISCONNECTED intents.

Change-Id: I19b0f257d53f9d0e5590316b06088852ccd32804
parent 7bd83570
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -30,10 +30,12 @@ import com.android.bluetooth.Utils;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;


final class RemoteDevices {
    private static final boolean DBG = false;
    private static final boolean DBG = true;
    private static final String TAG = "BluetoothRemoteDevices";


@@ -47,11 +49,14 @@ final class RemoteDevices {

    private HashMap<BluetoothDevice, DeviceProperties> mDevices;

    private Set<BluetoothDevice> mBleOnDevices;

    RemoteDevices(AdapterService service) {
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        mAdapterService = service;
        mSdpTracker = new ArrayList<BluetoothDevice>();
        mDevices = new HashMap<BluetoothDevice, DeviceProperties>();
        mBleOnDevices = new HashSet<BluetoothDevice>();
    }


@@ -61,6 +66,9 @@ final class RemoteDevices {

        if (mDevices != null)
            mDevices.clear();

        if (mBleOnDevices != null)
            mBleOnDevices.clear();
    }

    @Override
@@ -344,6 +352,9 @@ final class RemoteDevices {
                intent = new Intent(BluetoothDevice.ACTION_ACL_CONNECTED);
            } else if (state == BluetoothAdapter.STATE_BLE_ON || state == BluetoothAdapter.STATE_BLE_TURNING_ON) {
                intent = new Intent(BluetoothAdapter.ACTION_BLE_ACL_CONNECTED);
                /* also save the device into LE always on device list */
                debugLog("aclStateChangeCallback: added device to Ble ON list");
                mBleOnDevices.add(device);
            }
            debugLog("aclStateChangeCallback: State:Connected to Device:" + device);
        } else {
@@ -353,10 +364,14 @@ final class RemoteDevices {
                intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
                mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_PERM);
            }
            if (state == BluetoothAdapter.STATE_ON || state == BluetoothAdapter.STATE_TURNING_OFF) {
                intent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECTED);
            } else if (state == BluetoothAdapter.STATE_BLE_ON || state == BluetoothAdapter.STATE_BLE_TURNING_OFF) {
            if ((state == BluetoothAdapter.STATE_BLE_ON || state == BluetoothAdapter.STATE_BLE_TURNING_OFF) &&
                (mBleOnDevices.contains(device))) {
                intent = new Intent(BluetoothAdapter.ACTION_BLE_ACL_DISCONNECTED);
                debugLog("aclStateChangeCallback: removing device from Ble Always On List");
                mBleOnDevices.remove(device);
            } else {
                intent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECTED);
                debugLog("aclStateChangeCallback: sending ACL disconnected intent");
            }
            debugLog("aclStateChangeCallback: State:DisConnected to Device:" + device);
        }