From c43f68e52caa927e71b97fe602268a31390ea706 Mon Sep 17 00:00:00 2001 From: Gustavo Garcia Date: Thu, 29 Jun 2017 11:25:16 +0300 Subject: [PATCH] Fix do not unregister bluetooth receiver if it was not registered Bug: webrtc:7890 Change-Id: Ib46b4a4407fa030500930ed03a093b26c71f8963 Reviewed-on: https://chromium-review.googlesource.com/550617 Commit-Queue: Henrik Andreasson Reviewed-by: Henrik Andreasson Cr-Commit-Position: refs/heads/master@{#18892} --- AUTHORS | 1 + .../apprtc/AppRTCBluetoothManager.java | 32 ++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/AUTHORS b/AUTHORS index cb537cfcdc..3a1735167f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -19,6 +19,7 @@ Eric Rescorla, RTFM Inc. Frederik Riedel, Frogg GmbH Giji Gangadharan Graham Yoakum +Gustavo Garcia Hugues Ekra Jake Hilton James H. Brown diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/AppRTCBluetoothManager.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/AppRTCBluetoothManager.java index 10b1a5cbef..99979a320e 100644 --- a/webrtc/examples/androidapp/src/org/appspot/apprtc/AppRTCBluetoothManager.java +++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/AppRTCBluetoothManager.java @@ -276,23 +276,25 @@ public class AppRTCBluetoothManager { /** Stops and closes all components related to Bluetooth audio. */ public void stop() { ThreadUtils.checkIsOnMainThread(); - unregisterReceiver(bluetoothHeadsetReceiver); Log.d(TAG, "stop: BT state=" + bluetoothState); - if (bluetoothAdapter != null) { - // Stop BT SCO connection with remote device if needed. - stopScoAudio(); - // Close down remaining BT resources. - if (bluetoothState != State.UNINITIALIZED) { - cancelTimer(); - if (bluetoothHeadset != null) { - bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, bluetoothHeadset); - bluetoothHeadset = null; - } - bluetoothAdapter = null; - bluetoothDevice = null; - bluetoothState = State.UNINITIALIZED; - } + if (bluetoothAdapter == null) { + return; } + // Stop BT SCO connection with remote device if needed. + stopScoAudio(); + // Close down remaining BT resources. + if (bluetoothState == State.UNINITIALIZED) { + return; + } + unregisterReceiver(bluetoothHeadsetReceiver); + cancelTimer(); + if (bluetoothHeadset != null) { + bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, bluetoothHeadset); + bluetoothHeadset = null; + } + bluetoothAdapter = null; + bluetoothDevice = null; + bluetoothState = State.UNINITIALIZED; Log.d(TAG, "stop done: BT state=" + bluetoothState); }