From b5d1e0958039da485a0d23b4ac5899ffe6370e5e Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 26 Feb 2013 16:37:03 +0100 Subject: [PATCH 1/7] Bluetooth support for android 2.2+ added --- src/org/linphone/BluetoothManager.java | 49 +++++++++--- src/org/linphone/LinphoneManager.java | 105 ++++++++++++++++--------- 2 files changed, 105 insertions(+), 49 deletions(-) diff --git a/src/org/linphone/BluetoothManager.java b/src/org/linphone/BluetoothManager.java index 5e6287442..0e0d8885c 100644 --- a/src/org/linphone/BluetoothManager.java +++ b/src/org/linphone/BluetoothManager.java @@ -2,39 +2,68 @@ package org.linphone; import org.linphone.mediastream.Log; -import android.bluetooth.BluetoothAdapter; +import android.annotation.TargetApi; import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.media.AudioManager; +import android.os.Build; +@TargetApi(Build.VERSION_CODES.HONEYCOMB) public class BluetoothManager extends BroadcastReceiver { - public void onReceive(Context context, Intent intent) { + @SuppressWarnings("deprecation") + public void onReceive(Context context, Intent intent) { boolean routeToBT = context.getResources().getBoolean(R.bool.route_audio_to_bluetooth_if_available); if (!routeToBT) return; String action = intent.getAction(); LinphoneManager lm = LinphoneManager.getInstance(); - + + String actionScoConnected = AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED; if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) { Log.e("Bluetooth Received Event" + " ACTION_ACL_DISCONNECTED" ); if (lm != null) { - lm.uninitBluetooth(); + lm.isBluetoothScoConnected = false; + lm.scoDisconnected(); lm.routeAudioToReceiver(); } - } else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { + } + else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { Log.e("Bluetooth Received Event" + " ACTION_ACL_CONNECTED" ); if (lm != null) { - lm.routeToBluetoothIfAvailable(); + lm.isBluetoothScoConnected = true; + lm.scoConnected(); } - } else if (BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED.equals(action)) { - Log.e("Bluetooth state changed!"); - if (lm != null) { + } + else if (actionScoConnected.equals(action)) { + int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, 0); + Log.e("Bluetooth sco state changed : " + state); + if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) { + if (lm != null) { + lm.isBluetoothScoConnected = true; + lm.scoConnected(); + } + } else if (state == AudioManager.SCO_AUDIO_STATE_DISCONNECTED) { + if (lm != null) { + lm.isBluetoothScoConnected = false; + lm.scoDisconnected(); + lm.routeAudioToReceiver(); + } + } + } + //Using real value instead of constant because not available before sdk 11 + else if ("android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED".equals(action)) { //BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED + int currentConnState = intent.getIntExtra("android.bluetooth.adapter.extra.CONNECTION_STATE", //BluetoothAdapter.EXTRA_CONNECTION_STATE + 0); //BluetoothAdapter.STATE_DISCONNECTED + Log.e("Bluetooth state changed: " + currentConnState); + if (lm != null && currentConnState == 2) { //BluetoothAdapter.STATE_CONNECTED + lm.isBluetoothScoConnected = true; lm.startBluetooth(); } - } + } } } diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index 16a26d6d7..65148120f 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -150,6 +150,8 @@ public final class LinphoneManager implements LinphoneCoreListener { private BluetoothAdapter mBluetoothAdapter; private BluetoothHeadset mBluetoothHeadset; private BluetoothProfile.ServiceListener mProfileListener; + private BroadcastReceiver bluetoothReiceiver = new BluetoothManager(); + public boolean isBluetoothScoConnected; private static List simpleListeners = new ArrayList(); public static void addListener(LinphoneSimpleListener listener) { @@ -204,14 +206,14 @@ public final class LinphoneManager implements LinphoneCoreListener { boolean routeToBT = mServiceContext.getResources().getBoolean(R.bool.route_audio_to_bluetooth_if_available); if (!routeToBT || (routeToBT && !routeToBluetoothIfAvailable())) { mLc.enableSpeaker(false); - uninitBluetooth(); + scoDisconnected(); } else { Log.d("Routing audio to bluetooth headset"); routeToBluetoothEnabled = true; } } else { mLc.enableSpeaker(true); - uninitBluetooth(); + scoDisconnected(); } for (LinphoneOnAudioChangedListener listener : getSimpleListeners(LinphoneOnAudioChangedListener.class)) { @@ -243,27 +245,40 @@ public final class LinphoneManager implements LinphoneCoreListener { @TargetApi(Build.VERSION_CODES.HONEYCOMB) public void startBluetooth() { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); - if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30) && mBluetoothAdapter.isEnabled()) { - mProfileListener = new BluetoothProfile.ServiceListener() { - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public void onServiceConnected(int profile, BluetoothProfile proxy) { - if (profile == BluetoothProfile.HEADSET) { - mBluetoothHeadset = (BluetoothHeadset) proxy; - Log.d("Bluetooth headset connected"); - routeToBluetoothIfAvailable(); - } - } - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public void onServiceDisconnected(int profile) { - if (profile == BluetoothProfile.HEADSET) { - mBluetoothHeadset = null; - Log.d("Bluetooth headset disconnected"); - routeAudioToReceiver(); - } - } - }; - mBluetoothAdapter.getProfileProxy(mServiceContext, mProfileListener, BluetoothProfile.HEADSET); - } else { + if (mBluetoothAdapter.isEnabled()) { + if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) { + mProfileListener = new BluetoothProfile.ServiceListener() { + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + public void onServiceConnected(int profile, BluetoothProfile proxy) { + if (profile == BluetoothProfile.HEADSET) { + mBluetoothHeadset = (BluetoothHeadset) proxy; + Log.d("Bluetooth headset connected"); + routeToBluetoothIfAvailable(); + } + } + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + public void onServiceDisconnected(int profile) { + if (profile == BluetoothProfile.HEADSET) { + mBluetoothHeadset = null; + Log.d("Bluetooth headset disconnected"); + routeAudioToReceiver(); + } + } + }; + mBluetoothAdapter.getProfileProxy(mServiceContext, mProfileListener, BluetoothProfile.HEADSET); + } else { + @SuppressWarnings("deprecation") + String actionScoConnected = AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED; + Intent currentValue = mServiceContext.registerReceiver(bluetoothReiceiver, new IntentFilter(actionScoConnected)); + int state = currentValue == null ? 0 : currentValue.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, 0); + if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) { + isBluetoothScoConnected = true; + scoConnected(); + } + } + } + else { + scoDisconnected(); routeAudioToReceiver(); } } @@ -271,30 +286,42 @@ public final class LinphoneManager implements LinphoneCoreListener { @TargetApi(Build.VERSION_CODES.HONEYCOMB) public boolean routeToBluetoothIfAvailable() { BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); - if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30) && mBluetoothAdapter.isEnabled() && mAudioManager.isBluetoothScoAvailableOffCall()) { + if (mBluetoothAdapter.isEnabled() && mAudioManager.isBluetoothScoAvailableOffCall()) { mAudioManager.setBluetoothScoOn(true); mAudioManager.startBluetoothSco(); - - boolean connected = false; - if (mBluetoothHeadset != null) { - List devices = mBluetoothHeadset.getConnectedDevices(); - for (final BluetoothDevice dev : devices) { - connected |= mBluetoothHeadset.getConnectionState(dev) == BluetoothHeadset.STATE_CONNECTED; - } - } - if (!connected) { - Log.d("No bluetooth device available"); - uninitBluetooth(); + if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) { + boolean connected = false; + if (mBluetoothHeadset != null) { + List devices = mBluetoothHeadset.getConnectedDevices(); + for (final BluetoothDevice dev : devices) { + connected |= mBluetoothHeadset.getConnectionState(dev) == BluetoothHeadset.STATE_CONNECTED; + } + } + + if (!connected) { + Log.d("No bluetooth device available"); + scoDisconnected(); + } + return connected; + } else { + return isBluetoothScoConnected; } - return connected; } + return false; } - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public void uninitBluetooth() { - if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30) && mAudioManager != null) { + public void scoConnected() { + Log.e("Bluetooth sco connected!"); + mAudioManager.setMode(AudioManager.MODE_IN_CALL); + routeToBluetoothIfAvailable(); + } + + public void scoDisconnected() { + Log.e("Bluetooth sco disconnected!"); + if (mAudioManager != null) { + mAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.stopBluetoothSco(); mAudioManager.setBluetoothScoOn(false); } From fcefbb076dcdba263ff72bdd66b4d2df74921429 Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Thu, 28 Feb 2013 10:47:07 +0100 Subject: [PATCH 2/7] Update linphone submodule --- submodules/linphone | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/linphone b/submodules/linphone index 8e9b2b9a2..1a5169a14 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 8e9b2b9a2453279e4fea1322ac6e7024f46b0d6a +Subproject commit 1a5169a1472b81e1d68b8248550dc789b54b607c From ada976d2783e7b05487a8187b2644fc740688a5e Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Thu, 28 Feb 2013 14:05:53 +0100 Subject: [PATCH 3/7] Add NDK debug flag in Makefile --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 77dd23225..e07592e01 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ LINPHONE_VERSION=$(shell cd submodules/linphone && git describe) LINPHONE_ANDROID_DEBUG_VERSION=$(shell git describe) ANDROID_MOST_RECENT_TARGET=$(shell android list target -c | grep android | tail -n1) +NDK_DEBUG=0 BUILD_UPNP=1 BUILD_REMOTE_PROVISIONING=1 BUILD_X264=1 @@ -89,7 +90,7 @@ prepare-mediastreamer2: prepare-sources: prepare-ffmpeg prepare-ilbc prepare-vpx prepare-silk prepare-srtp prepare-mediastreamer2 generate-libs: - $(NDK_PATH)/ndk-build LINPHONE_VERSION=$(LINPHONE_VERSION) BUILD_UPNP=$(BUILD_UPNP) BUILD_REMOTE_PROVISIONING=$(BUILD_REMOTE_PROVISIONING) BUILD_X264=$(BUILD_X264) BUILD_AMRNB=$(BUILD_AMRNB) BUILD_AMRWB=$(BUILD_AMRWB) BUILD_GPLV3_ZRTP=$(BUILD_GPLV3_ZRTP) BUILD_SILK=$(BUILD_SILK) BUILD_G729=$(BUILD_G729) BUILD_TUNNEL=$(BUILD_TUNNEL) BUILD_WEBRTC_AECM=$(BUILD_WEBRTC_AECM) BUILD_FOR_X86=$(BUILD_FOR_X86) USE_JAVAH=$(USE_JAVAH) -j$(NUMCPUS) + $(NDK_PATH)/ndk-build NDK_DEBUG=$(NDK_DEBUG) LINPHONE_VERSION=$(LINPHONE_VERSION) BUILD_UPNP=$(BUILD_UPNP) BUILD_REMOTE_PROVISIONING=$(BUILD_REMOTE_PROVISIONING) BUILD_X264=$(BUILD_X264) BUILD_AMRNB=$(BUILD_AMRNB) BUILD_AMRWB=$(BUILD_AMRWB) BUILD_GPLV3_ZRTP=$(BUILD_GPLV3_ZRTP) BUILD_SILK=$(BUILD_SILK) BUILD_G729=$(BUILD_G729) BUILD_TUNNEL=$(BUILD_TUNNEL) BUILD_WEBRTC_AECM=$(BUILD_WEBRTC_AECM) BUILD_FOR_X86=$(BUILD_FOR_X86) USE_JAVAH=$(USE_JAVAH) -j$(NUMCPUS) update-project: $(SDK_PATH)/android update project --path . --target $(ANDROID_MOST_RECENT_TARGET) From 8c5a892acf6686026a364526cb1f909d59cbe635 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Mon, 4 Mar 2013 14:35:31 +0100 Subject: [PATCH 4/7] Add missing parenthese. --- jni/Application.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jni/Application.mk b/jni/Application.mk index 1d68d962d..94a2b0c13 100644 --- a/jni/Application.mk +++ b/jni/Application.mk @@ -58,7 +58,7 @@ ifeq ($(BUILD_G729),1) APP_MODULES +=libbcg729 libmsbcg729 endif -ifneq ($BUILD_WEBRTC_AECM), 0) +ifneq ($(BUILD_WEBRTC_AECM), 0) APP_MODULES += libwebrtc_system_wrappers libwebrtc_spl libwebrtc_apm_utility libwebrtc_aecm APP_MODULES += libwebrtc_spl_neon libwebrtc_aecm_neon endif From 51ca66f9ece571e6167f72f97a0c658587388054 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Mon, 4 Mar 2013 14:37:23 +0100 Subject: [PATCH 5/7] Update linphone submodule. --- submodules/linphone | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/linphone b/submodules/linphone index 1a5169a14..7f127269f 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 1a5169a1472b81e1d68b8248550dc789b54b607c +Subproject commit 7f127269fbfe22d211fb6ea8429da583e766a23d From e41c4507e5aee97f7b84c12e35b2ae20a8579ce4 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Thu, 7 Mar 2013 17:41:39 +0100 Subject: [PATCH 6/7] update linphone submodule --- submodules/linphone | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/linphone b/submodules/linphone index 7f127269f..4539d3c2d 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 7f127269fbfe22d211fb6ea8429da583e766a23d +Subproject commit 4539d3c2d618117dbbed640fccb96c68a31bcb04 From 13669909ad5195e1fef2fd1f7ec61e5b90e4633a Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Fri, 8 Mar 2013 15:56:56 +0100 Subject: [PATCH 7/7] Update linphone submodule --- submodules/linphone | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/linphone b/submodules/linphone index 4539d3c2d..837c566c0 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 4539d3c2d618117dbbed640fccb96c68a31bcb04 +Subproject commit 837c566c0a2cfd5d27d738f1647872703786d6cd