From c208d3e3776b85e1ae153da32d94b0acfbe99163 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 29 Oct 2014 14:54:39 +0100 Subject: [PATCH] Try to prevent BT crash that happen for some people --- AndroidManifest.xml | 2 +- src/org/linphone/BluetoothManager.java | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index b16eaf24b..e80ad5a8a 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -147,7 +147,7 @@ - + diff --git a/src/org/linphone/BluetoothManager.java b/src/org/linphone/BluetoothManager.java index 4e10e89d5..0a79fafc2 100644 --- a/src/org/linphone/BluetoothManager.java +++ b/src/org/linphone/BluetoothManager.java @@ -66,14 +66,26 @@ public class BluetoothManager extends BroadcastReceiver { return instance; } - public BluetoothManager() { + private BluetoothManager() { isBluetoothConnected = false; - mContext = LinphoneService.instance().getApplicationContext(); - mAudioManager = ((AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE)); + if (LinphoneService.isReady()) { + mContext = LinphoneService.instance().getApplicationContext(); + mAudioManager = ((AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE)); + } else { + Log.w("BluetoothManager tried to init but LinphoneService not ready yet..."); + } instance = this; } public void initBluetooth() { + if (mContext == null && LinphoneService.isReady()) { + mContext = LinphoneService.instance().getApplicationContext(); + mAudioManager = ((AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE)); + } else if (mContext == null) { + Log.w("BluetoothManager tried to init bluetooth but LinphoneService not ready yet..."); + return; + } + IntentFilter filter = new IntentFilter(); filter.addCategory(BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY + "." + BluetoothAssignedNumbers.PLANTRONICS); filter.addAction(Compatibility.getAudioManagerEventForBluetoothConnectionStateChangedEvent());