From 9a0ad7cd86d64240f1b805167b073ae4c1987bd5 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 6 Feb 2014 11:04:55 +0100 Subject: [PATCH] Started bluetooth headset vendor events support --- src/org/linphone/BluetoothActionReceiver.java | 35 +++++++++++++++++++ src/org/linphone/LinphoneManager.java | 9 ++++- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/org/linphone/BluetoothActionReceiver.java diff --git a/src/org/linphone/BluetoothActionReceiver.java b/src/org/linphone/BluetoothActionReceiver.java new file mode 100644 index 000000000..cf160aa0d --- /dev/null +++ b/src/org/linphone/BluetoothActionReceiver.java @@ -0,0 +1,35 @@ +package org.linphone; + +import org.linphone.mediastream.Log; + +import android.annotation.TargetApi; +import android.bluetooth.BluetoothDevice; +import android.bluetooth.BluetoothHeadset; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.os.Build; + +@TargetApi(Build.VERSION_CODES.HONEYCOMB) +public class BluetoothActionReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction().equals(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT)) { + BluetoothDevice device = (BluetoothDevice) intent.getExtras().get(BluetoothDevice.EXTRA_DEVICE); + String command = intent.getExtras().getString(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD); + int type = intent.getExtras().getInt(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE); + + Object[] temp = (Object[]) intent.getExtras().get(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS); + String[] args = new String[temp.length]; + String logArgs = ""; + for (int i = 0; i < temp.length; i++) { + args[i] = (String) temp[i]; + logArgs += args[i] + " "; + } + + Log.d("Bluetooth headset event from " + device.getName() + ", command: " + command + " (type: " + type + ") with args: " + logArgs); + + //TODO: parse command/args and do something with it + } + } +} diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index 690eefe78..1e1924529 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -150,6 +150,7 @@ public class LinphoneManager implements LinphoneCoreListener { private BluetoothHeadset mBluetoothHeadset; private BluetoothProfile.ServiceListener mProfileListener; private BroadcastReceiver bluetoothReiceiver = new BluetoothManager(); + private BroadcastReceiver bluetoothActionReceiver = new BluetoothActionReceiver(); public boolean isBluetoothScoConnected; public boolean isUsingBluetoothAudioRoute; private boolean mBluetoothStarted; @@ -252,14 +253,16 @@ public class LinphoneManager implements LinphoneCoreListener { @TargetApi(Build.VERSION_CODES.HONEYCOMB) public void onServiceConnected(int profile, BluetoothProfile proxy) { if (profile == BluetoothProfile.HEADSET) { + Log.d("Bluetooth headset connected"); + mServiceContext.registerReceiver(bluetoothActionReceiver, new IntentFilter(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT)); mBluetoothHeadset = (BluetoothHeadset) proxy; isBluetoothScoConnected = true; - Log.d("Bluetooth headset connected"); } } @TargetApi(Build.VERSION_CODES.HONEYCOMB) public void onServiceDisconnected(int profile) { if (profile == BluetoothProfile.HEADSET) { + mServiceContext.unregisterReceiver(bluetoothActionReceiver); mBluetoothHeadset = null; isBluetoothScoConnected = false; Log.d("Bluetooth headset disconnected"); @@ -748,6 +751,10 @@ public class LinphoneManager implements LinphoneCoreListener { mServiceContext.unregisterReceiver(bluetoothReiceiver); } catch (Exception e) {} + try { + mServiceContext.unregisterReceiver(bluetoothActionReceiver); + } catch (Exception e) {} + try { if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);