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

Commit d76cc0a4 authored by Marie Janssen's avatar Marie Janssen
Browse files

Bluetooth: only unregisterReceiver if we register

We can get to onDestroy() without registering now.

Test: none
Fixes: 36501241
Change-Id: I90da3b350f9951993238d51f9fde86ccb335cafd
(cherry picked from commit af34ed06)
parent 0c474740
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ public final class BluetoothPairingService extends Service {
    return pairingIntent;
  }

  private boolean mRegistered = false;
  private final BroadcastReceiver mCancelReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
@@ -130,6 +131,7 @@ public final class BluetoothPairingService extends Service {
    filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
    filter.addAction(BluetoothDevice.ACTION_PAIRING_CANCEL);
    registerReceiver(mCancelReceiver, filter);
    mRegistered = true;

    startForeground(NOTIFICATION_ID, builder.getNotification());
    return START_REDELIVER_INTENT;
@@ -137,7 +139,10 @@ public final class BluetoothPairingService extends Service {

  @Override
  public void onDestroy() {
    if (mRegistered) {
      unregisterReceiver(mCancelReceiver);
      mRegistered = false;
    }
    stopForeground(true);
  }