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

Commit 481d7562 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 aee6c7fb
Loading
Loading
Loading
Loading
+6 −1
Original line number Original line Diff line number Diff line
@@ -93,6 +93,7 @@ class AdapterProperties {
    private boolean mIsLePeriodicAdvertisingSupported;
    private boolean mIsLePeriodicAdvertisingSupported;
    private int mLeMaximumAdvertisingDataLength;
    private int mLeMaximumAdvertisingDataLength;


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


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