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

Commit 479ce30c authored by Ludvig Hansson's avatar Ludvig Hansson Committed by Md Shahriar Hossain Sajib
Browse files

Broadcast ACL disconnected when adapter turned off

Send a ACL disconnected broadcast intent for all connected
devices when turning off the bluetooth adapter.

This intent can be received in the background so that
non-running applications like complication data providers
can track BT connectivity state.

Bug: 149746528
Bug: 199827901
Test: IOP and BCST
Tag: #feature

Change-Id: If20fd40415d438be2201f82a76608a1b6c43a33f
(cherry picked from commit da9f8935a6c75882df9c73ebdcca53396bef05e8)
parent 41f99da1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -184,6 +184,7 @@ public class AdapterService extends Service {

    public static final String BLUETOOTH_PRIVILEGED =
            android.Manifest.permission.BLUETOOTH_PRIVILEGED;
    static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH;
    static final String LOCAL_MAC_ADDRESS_PERM = android.Manifest.permission.LOCAL_MAC_ADDRESS;
    static final String RECEIVE_MAP_PERM = android.Manifest.permission.RECEIVE_BLUETOOTH_MAP;

+20 −2
Original line number Diff line number Diff line
@@ -178,9 +178,27 @@ final class RemoteDevices {
            sSdpTracker.clear();
        }

        synchronized (mDevices) {
            if (mDevices != null) {
                debugLog("reset(): Broadcasting ACL_DISCONNECTED");

                mDevices.forEach((address, deviceProperties) -> {
                    BluetoothDevice bluetoothDevice = deviceProperties.getDevice();

                    debugLog("reset(): address=" + address + ", connected="
                            + bluetoothDevice.isConnected());

                    if (bluetoothDevice.isConnected()) {
                        Intent intent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECTED);
                        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, bluetoothDevice);
                        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                                | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
                        sAdapterService.sendBroadcast(intent, AdapterService.BLUETOOTH_PERM);
                    }
                });
                mDevices.clear();
            }
        }

        if (mDualDevicesMap != null) {
            mDualDevicesMap.clear();