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

Commit 82e0712f authored by Hans Månsson's avatar Hans Månsson Committed by Ed Savage-Jones
Browse files

AdapterProperties: Guard unregisterReceiver

At first boot if Bluetooth is not enabled by default the Bluetooth app
will crash due to a poorly guarded cleanup method.

The root cause is that BluetoothMangerService.handleOnBootPhase() issues
a MESSAGE_GET_NAME_AND_ADDRESS, which inturn will try get device address
and name. When done it will call unbindAndFinish() if Bluetooth is not
enabled. The Bluetooth app then cleans up in preparation for shutdown
and the crash occurs.

Test: def_bluetooth_on => false in SettingsProvider defaults. Build/boot
Change-Id: Idc6817eacd75fcc22d284ca0e54933914b587e49
parent f297d325
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ class AdapterProperties {
    private boolean mIsLePeriodicAdvertisingSupported;
    private int mLeMaximumAdvertisingDataLength;

    private boolean mReceiverRegistered;
    private BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
@@ -158,6 +159,7 @@ class AdapterProperties {
        filter.addAction(BluetoothPbapClient.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothDevice.ACTION_UUID);
        mService.registerReceiver(mReceiver, filter);
        mReceiverRegistered = true;
    }

    public void cleanup() {
@@ -166,7 +168,10 @@ class AdapterProperties {
            mProfileConnectionState.clear();
            mProfileConnectionState = null;
        }
        if (mReceiverRegistered) {
            mService.unregisterReceiver(mReceiver);
            mReceiverRegistered = false;
        }
        mService = null;
        mBondedDevices.clear();
    }