aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2018-06-07 07:26:06 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-06-07 07:26:06 +0000
commit91f381cfd5007945e9fcfac3eebf1eb64b2c0a69 (patch)
tree9282a40737ec36a4dc8efac5a2395b9f14061ceb
parentaa969da293cd8f7bddb1acc9014908f6574edf4e (diff)
parente76a08babeec457d3ec28d24d91c833fbd223ba5 (diff)
downloadsl4a-pie-cts-release.tar.gz
Snap for 4826885 from e76a08babeec457d3ec28d24d91c833fbd223ba5 to pi-releaseandroid-wear-9.0.0_r9android-wear-9.0.0_r8android-wear-9.0.0_r7android-wear-9.0.0_r6android-wear-9.0.0_r5android-wear-9.0.0_r4android-wear-9.0.0_r34android-wear-9.0.0_r33android-wear-9.0.0_r32android-wear-9.0.0_r31android-wear-9.0.0_r30android-wear-9.0.0_r3android-wear-9.0.0_r29android-wear-9.0.0_r28android-wear-9.0.0_r27android-wear-9.0.0_r26android-wear-9.0.0_r25android-wear-9.0.0_r24android-wear-9.0.0_r23android-wear-9.0.0_r22android-wear-9.0.0_r21android-wear-9.0.0_r20android-wear-9.0.0_r2android-wear-9.0.0_r19android-wear-9.0.0_r18android-wear-9.0.0_r17android-wear-9.0.0_r16android-wear-9.0.0_r15android-wear-9.0.0_r14android-wear-9.0.0_r13android-wear-9.0.0_r12android-wear-9.0.0_r11android-wear-9.0.0_r10android-wear-9.0.0_r1android-vts-9.0_r9android-vts-9.0_r8android-vts-9.0_r7android-vts-9.0_r6android-vts-9.0_r5android-vts-9.0_r4android-vts-9.0_r19android-vts-9.0_r18android-vts-9.0_r17android-vts-9.0_r16android-vts-9.0_r15android-vts-9.0_r14android-vts-9.0_r13android-vts-9.0_r12android-vts-9.0_r11android-vts-9.0_r10android-security-9.0.0_r76android-security-9.0.0_r75android-security-9.0.0_r74android-security-9.0.0_r73android-security-9.0.0_r72android-security-9.0.0_r71android-security-9.0.0_r70android-security-9.0.0_r69android-security-9.0.0_r68android-security-9.0.0_r67android-security-9.0.0_r66android-security-9.0.0_r65android-security-9.0.0_r64android-security-9.0.0_r63android-security-9.0.0_r62android-cts-9.0_r9android-cts-9.0_r8android-cts-9.0_r7android-cts-9.0_r6android-cts-9.0_r5android-cts-9.0_r4android-cts-9.0_r3android-cts-9.0_r20android-cts-9.0_r2android-cts-9.0_r19android-cts-9.0_r18android-cts-9.0_r17android-cts-9.0_r16android-cts-9.0_r15android-cts-9.0_r14android-cts-9.0_r13android-cts-9.0_r12android-cts-9.0_r11android-cts-9.0_r10android-cts-9.0_r1android-9.0.0_r9android-9.0.0_r8android-9.0.0_r7android-9.0.0_r61android-9.0.0_r60android-9.0.0_r6android-9.0.0_r59android-9.0.0_r58android-9.0.0_r57android-9.0.0_r56android-9.0.0_r55android-9.0.0_r54android-9.0.0_r53android-9.0.0_r52android-9.0.0_r51android-9.0.0_r50android-9.0.0_r5android-9.0.0_r49android-9.0.0_r48android-9.0.0_r3android-9.0.0_r2android-9.0.0_r18android-9.0.0_r17android-9.0.0_r10android-9.0.0_r1security-pi-releasepie-vts-releasepie-security-releasepie-s2-releasepie-release-2pie-releasepie-r2-s2-releasepie-r2-s1-releasepie-r2-releasepie-cts-release
Change-Id: I7e036bb4fde4c0c2839fec79227fe5277e46d815
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothA2dpFacade.java18
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothA2dpSinkFacade.java282
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothAvrcpFacade.java115
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothBroadcastHelper.java65
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java14
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothDiscoveryHelper.java124
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothFacade.java51
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothHfpClientFacade.java322
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothHidFacade.java675
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothHspFacade.java521
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeAdvertiseFacade.java87
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeScanFacade.java180
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMapClientFacade.java58
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMapFacade.java162
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMediaFacade.java10
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPairingHelper.java204
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPanFacade.java6
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPbapClientFacade.java309
18 files changed, 1861 insertions, 1342 deletions
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothA2dpFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothA2dpFacade.java
index 932bcbd4..cee0fe9c 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothA2dpFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothA2dpFacade.java
@@ -140,8 +140,9 @@ public class BluetoothA2dpFacade extends RpcReceiver {
if (sA2dpProfile == null) {
return false;
}
- BluetoothDevice mDevice = BluetoothFacade.getDevice(
- BluetoothFacade.DiscoveredDevices, deviceID);
+ BluetoothDevice mDevice =
+ BluetoothFacade.getDevice(
+ mBluetoothAdapter.getBondedDevices(), deviceID);
Log.d("Connecting to device " + mDevice.getAliasName());
return a2dpConnect(mDevice);
}
@@ -161,9 +162,11 @@ public class BluetoothA2dpFacade extends RpcReceiver {
if (sA2dpProfile == null) {
return false;
}
- List<BluetoothDevice> connectedA2dpDevices = sA2dpProfile.getConnectedDevices();
+ List<BluetoothDevice> connectedA2dpDevices =
+ sA2dpProfile.getConnectedDevices();
Log.d("Connected a2dp devices " + connectedA2dpDevices);
- BluetoothDevice mDevice = BluetoothFacade.getDevice(connectedA2dpDevices, deviceID);
+ BluetoothDevice mDevice = BluetoothFacade.getDevice(
+ connectedA2dpDevices, deviceID);
return a2dpDisconnect(mDevice);
}
@@ -179,10 +182,9 @@ public class BluetoothA2dpFacade extends RpcReceiver {
continue;
}
return sA2dpProfile.getDevicesMatchingConnectionStates(
- new int[] {
- BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_CONNECTING,
- BluetoothProfile.STATE_DISCONNECTING});
+ new int[] { BluetoothProfile.STATE_CONNECTED,
+ BluetoothProfile.STATE_CONNECTING,
+ BluetoothProfile.STATE_DISCONNECTING});
}
@Override
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothA2dpSinkFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothA2dpSinkFacade.java
index 1b1e5b62..5d072009 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothA2dpSinkFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothA2dpSinkFacade.java
@@ -16,9 +16,6 @@
package com.googlecode.android_scripting.facade.bluetooth;
-import java.util.List;
-import java.util.ArrayList;
-
import android.app.Service;
import android.bluetooth.BluetoothA2dpSink;
import android.bluetooth.BluetoothAdapter;
@@ -33,131 +30,182 @@ import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
import com.googlecode.android_scripting.rpc.Rpc;
import com.googlecode.android_scripting.rpc.RpcParameter;
+import java.util.ArrayList;
+import java.util.List;
+
public class BluetoothA2dpSinkFacade extends RpcReceiver {
- static final ParcelUuid[] SOURCE_UUIDS = {
- BluetoothUuid.AudioSource,
- };
+ static final ParcelUuid[] SOURCE_UUIDS = {
+ BluetoothUuid.AudioSource,
+ };
- private final Service mService;
- private final BluetoothAdapter mBluetoothAdapter;
+ private final Service mService;
+ private final BluetoothAdapter mBluetoothAdapter;
- private static BluetoothA2dpSink sA2dpSinkProfile = null;
+ private static BluetoothA2dpSink sA2dpSinkProfile = null;
- public BluetoothA2dpSinkFacade(FacadeManager manager) {
- super(manager);
- mService = manager.getService();
- mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
- mBluetoothAdapter.getProfileProxy(mService, new A2dpSinkServiceListener(),
+ public BluetoothA2dpSinkFacade(FacadeManager manager) {
+ super(manager);
+ mService = manager.getService();
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ mBluetoothAdapter.getProfileProxy(mService, new A2dpSinkServiceListener(),
BluetoothProfile.A2DP_SINK);
- }
+ }
- class A2dpSinkServiceListener implements BluetoothProfile.ServiceListener {
- @Override
- public void onServiceConnected(int profile, BluetoothProfile proxy) {
- sA2dpSinkProfile = (BluetoothA2dpSink) proxy;
+ class A2dpSinkServiceListener implements BluetoothProfile.ServiceListener {
+ @Override
+ public void onServiceConnected(int profile, BluetoothProfile proxy) {
+ sA2dpSinkProfile = (BluetoothA2dpSink) proxy;
+ }
+
+ @Override
+ public void onServiceDisconnected(int profile) {
+ sA2dpSinkProfile = null;
+ }
}
- @Override
- public void onServiceDisconnected(int profile) {
- sA2dpSinkProfile = null;
+ /**
+ * Connect A2dp Sink profile.
+ * @param device - the Bluetooth Device object to connect.
+ * @return if the A2dp Sink Profile connection was successful or not.
+ */
+ public Boolean a2dpSinkConnect(BluetoothDevice device) {
+ if (sA2dpSinkProfile == null) return false;
+ return sA2dpSinkProfile.connect(device);
}
- }
-
- public Boolean a2dpSinkConnect(BluetoothDevice device) {
- if (sA2dpSinkProfile == null) return false;
- return sA2dpSinkProfile.connect(device);
- }
-
- public Boolean a2dpSinkDisconnect(BluetoothDevice device) {
- if (sA2dpSinkProfile == null) return false;
- return sA2dpSinkProfile.disconnect(device);
- }
-
- @Rpc(description = "Set priority of the profile")
- public void bluetoothA2dpSinkSetPriority(
- @RpcParameter(name = "device", description = "Mac address of a BT device.")
- String deviceStr,
- @RpcParameter(name = "priority", description = "Priority that needs to be set.")
- Integer priority)
- throws Exception {
- if (sA2dpSinkProfile == null) return;
- BluetoothDevice device =
- BluetoothFacade.getDevice(mBluetoothAdapter.getBondedDevices(), deviceStr);
- Log.d("Changing priority of device " + device.getAliasName() + " p: " + priority);
- sA2dpSinkProfile.setPriority(device, priority);
- }
-
- @Rpc(description = "get priority of the profile")
- public Integer bluetoothA2dpSinkGetPriority(
- @RpcParameter(name = "device", description = "Mac address of a BT device.")
- String deviceStr)
- throws Exception {
- if (sA2dpSinkProfile == null) return BluetoothProfile.PRIORITY_UNDEFINED;
- BluetoothDevice device =
- BluetoothFacade.getDevice(mBluetoothAdapter.getBondedDevices(), deviceStr);
- return sA2dpSinkProfile.getPriority(device);
- }
-
- @Rpc(description = "Is A2dpSink profile ready.")
- public Boolean bluetoothA2dpSinkIsReady() {
- return (sA2dpSinkProfile != null);
- }
-
- @Rpc(description = "Connect to an A2DP Sink device.")
- public Boolean bluetoothA2dpSinkConnect(
- @RpcParameter(name = "device", description = "Name or MAC address of a bluetooth device.")
- String deviceStr)
- throws Exception {
- if (sA2dpSinkProfile == null) return false;
- BluetoothDevice device =
- BluetoothFacade.getDevice(BluetoothFacade.DiscoveredDevices, deviceStr);
- Log.d("Connecting to device " + device.getAliasName());
- return a2dpSinkConnect(device);
- }
-
- @Rpc(description = "Disconnect an A2DP Sink device.")
- public Boolean bluetoothA2dpSinkDisconnect(
- @RpcParameter(name = "device", description = "Name or MAC address of a device.")
- String deviceStr) {
- if (sA2dpSinkProfile == null) return false;
- Log.d("Connected devices: " + sA2dpSinkProfile.getConnectedDevices());
- BluetoothDevice device = null;
- try {
- device = BluetoothFacade.getDevice(sA2dpSinkProfile.getConnectedDevices(), deviceStr);
- return a2dpSinkDisconnect(device);
- } catch (Exception e) {
- // Do nothing here. Since it is disconnect this function should force shutdown anyways.
- Log.d("bluetoothA2dpSinkDisconnect error while getDevice " + e);
+
+ /**
+ * Disconnect A2dp Sink profile.
+ * @param device - the Bluetooth Device object to connect.
+ * @return if the A2dp Sink Profile disconnection was successful or not.
+ */
+ public Boolean a2dpSinkDisconnect(BluetoothDevice device) {
+ if (sA2dpSinkProfile == null) return false;
+ return sA2dpSinkProfile.disconnect(device);
}
- return false;
- }
-
- @Rpc(description = "Get all the devices connected through A2DP Sink.")
- public List<BluetoothDevice> bluetoothA2dpSinkGetConnectedDevices() {
- if (sA2dpSinkProfile == null) return new ArrayList<BluetoothDevice>();
- return sA2dpSinkProfile.getConnectedDevices();
- }
-
- @Rpc(description = "Get the connection status of a device.")
- public Integer bluetoothA2dpSinkGetConnectionStatus(
- @RpcParameter(name = "deviceID",
- description = "Name or MAC address of a bluetooth device.")
- String deviceID) {
- if (sA2dpSinkProfile == null) {
- return BluetoothProfile.STATE_DISCONNECTED;
+
+ /**
+ * Set priority of the profile.
+ * @param deviceStr - Mac address of a Bluetooth device.
+ * @param priority - Priority that needs to be set.
+ */
+ @Rpc(description = "Set priority of the profile")
+ public void bluetoothA2dpSinkSetPriority(
+ @RpcParameter(name = "device", description = "Mac address of a BT device.")
+ String deviceStr,
+ @RpcParameter(name = "priority", description = "Priority that needs to be set.")
+ Integer priority)
+ throws Exception {
+ if (sA2dpSinkProfile == null) return;
+ BluetoothDevice device =
+ BluetoothFacade.getDevice(
+ mBluetoothAdapter.getBondedDevices(), deviceStr);
+ Log.d("Changing priority of device "
+ + device.getAliasName() + " p: " + priority);
+ sA2dpSinkProfile.setPriority(device, priority);
}
- List<BluetoothDevice> deviceList = sA2dpSinkProfile.getConnectedDevices();
- BluetoothDevice device;
- try {
- device = BluetoothFacade.getDevice(deviceList, deviceID);
- } catch (Exception e) {
- Log.e(e);
- return BluetoothProfile.STATE_DISCONNECTED;
+
+ /**
+ * Get priority of the profile.
+ * @param deviceStr - Mac address of a Bluetooth device.
+ * @return priority of the device.
+ */
+ @Rpc(description = "get priority of the profile")
+ public Integer bluetoothA2dpSinkGetPriority(
+ @RpcParameter(name = "device", description = "Mac address of a BT device.")
+ String deviceStr)
+ throws Exception {
+ if (sA2dpSinkProfile == null) return BluetoothProfile.PRIORITY_UNDEFINED;
+ BluetoothDevice device =
+ BluetoothFacade.getDevice(
+ mBluetoothAdapter.getBondedDevices(), deviceStr);
+ return sA2dpSinkProfile.getPriority(device);
}
- return sA2dpSinkProfile.getConnectionState(device);
- }
- @Override
- public void shutdown() {
- }
+ /**
+ * Is A2dpSink profile ready.
+ * @return if the Profile is ready or not.
+ */
+ @Rpc(description = "Is A2dpSink profile ready.")
+ public Boolean bluetoothA2dpSinkIsReady() {
+ return sA2dpSinkProfile != null;
+ }
+
+ /**
+ * Connect to an A2DP Sink device.
+ * @param deviceStr - Name or MAC address of a bluetooth device.
+ * @return connection to A2DP was successful.
+ */
+ @Rpc(description = "Connect to an A2DP Sink device.")
+ public Boolean bluetoothA2dpSinkConnect(
+ @RpcParameter(name = "device", description =
+ "Name or MAC address of a bluetooth device.") String deviceStr)
+ throws Exception {
+ if (sA2dpSinkProfile == null) return false;
+ BluetoothDevice device =
+ BluetoothFacade.getDevice(
+ BluetoothFacade.DiscoveredDevices, deviceStr);
+ Log.d("Connecting to device " + device.getAliasName());
+ return a2dpSinkConnect(device);
+ }
+
+ /**
+ * Disconnect to an A2DP Sink device.
+ * @param deviceStr - Name or MAC address of a bluetooth device.
+ * @return disconnection to A2DP was successful or not.
+ */
+ @Rpc(description = "Disconnect an A2DP Sink device.")
+ public Boolean bluetoothA2dpSinkDisconnect(
+ @RpcParameter(name = "device", description = "Name or MAC address of a device.")
+ String deviceStr) {
+ if (sA2dpSinkProfile == null) return false;
+ Log.d("Connected devices: " + sA2dpSinkProfile.getConnectedDevices());
+ BluetoothDevice device = null;
+ try {
+ device = BluetoothFacade.getDevice(
+ sA2dpSinkProfile.getConnectedDevices(), deviceStr);
+ return a2dpSinkDisconnect(device);
+ } catch (Exception e) {
+ // Do nothing here. Since it is disconnect this function should force shutdown anyways.
+ Log.d("bluetoothA2dpSinkDisconnect error while getDevice " + e);
+ }
+ return false;
+ }
+
+ /**
+ * Get all the devices connected through A2DP Sink.
+ * @return List of all the devices connected through A2dp Sink.
+ */
+ @Rpc(description = "Get all the devices connected through A2DP Sink.")
+ public List<BluetoothDevice> bluetoothA2dpSinkGetConnectedDevices() {
+ if (sA2dpSinkProfile == null) return new ArrayList<BluetoothDevice>();
+ return sA2dpSinkProfile.getConnectedDevices();
+ }
+
+ /**
+ * Get the connection status of a device.
+ * @param deviceID - Name or MAC address of a bluetooth device.
+ * @return connection status of the device.
+ */
+ @Rpc(description = "Get the connection status of a device.")
+ public Integer bluetoothA2dpSinkGetConnectionStatus(
+ @RpcParameter(name = "deviceID",
+ description = "Name or MAC address of a bluetooth device.")
+ String deviceID) {
+ if (sA2dpSinkProfile == null) {
+ return BluetoothProfile.STATE_DISCONNECTED;
+ }
+ List<BluetoothDevice> deviceList = sA2dpSinkProfile.getConnectedDevices();
+ BluetoothDevice device;
+ try {
+ device = BluetoothFacade.getDevice(deviceList, deviceID);
+ } catch (Exception e) {
+ Log.e(e);
+ return BluetoothProfile.STATE_DISCONNECTED;
+ }
+ return sA2dpSinkProfile.getConnectionState(device);
+ }
+
+ @Override
+ public void shutdown() {
+ }
}
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothAvrcpFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothAvrcpFacade.java
index 4ecba055..52bb36df 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothAvrcpFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothAvrcpFacade.java
@@ -16,9 +16,6 @@
package com.googlecode.android_scripting.facade.bluetooth;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.List;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
@@ -33,65 +30,79 @@ import com.googlecode.android_scripting.facade.FacadeManager;
import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
import com.googlecode.android_scripting.rpc.Rpc;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.List;
+
public class BluetoothAvrcpFacade extends RpcReceiver {
- static final ParcelUuid[] AVRCP_UUIDS = {
- BluetoothUuid.AvrcpTarget, BluetoothUuid.AvrcpController
- };
- private final Service mService;
- private final BluetoothAdapter mBluetoothAdapter;
+ static final ParcelUuid[] AVRCP_UUIDS = {
+ BluetoothUuid.AvrcpTarget, BluetoothUuid.AvrcpController
+ };
+ private final Service mService;
+ private final BluetoothAdapter mBluetoothAdapter;
- private static boolean sIsAvrcpReady = false;
- private static BluetoothAvrcpController sAvrcpProfile = null;
+ private static boolean sIsAvrcpReady = false;
+ private static BluetoothAvrcpController sAvrcpProfile = null;
- public BluetoothAvrcpFacade(FacadeManager manager) {
- super(manager);
- mService = manager.getService();
- mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
- mBluetoothAdapter.getProfileProxy(mService, new AvrcpServiceListener(),
+ public BluetoothAvrcpFacade(FacadeManager manager) {
+ super(manager);
+ mService = manager.getService();
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ mBluetoothAdapter.getProfileProxy(mService, new AvrcpServiceListener(),
BluetoothProfile.AVRCP_CONTROLLER);
- }
-
- class AvrcpServiceListener implements BluetoothProfile.ServiceListener {
- @Override
- public void onServiceConnected(int profile, BluetoothProfile proxy) {
- sAvrcpProfile = (BluetoothAvrcpController) proxy;
- sIsAvrcpReady = true;
}
- @Override
- public void onServiceDisconnected(int profile) {
- sIsAvrcpReady = false;
+ class AvrcpServiceListener implements BluetoothProfile.ServiceListener {
+ @Override
+ public void onServiceConnected(int profile, BluetoothProfile proxy) {
+ sAvrcpProfile = (BluetoothAvrcpController) proxy;
+ sIsAvrcpReady = true;
+ }
+
+ @Override
+ public void onServiceDisconnected(int profile) {
+ sIsAvrcpReady = false;
+ }
}
- }
- @Rpc(description = "Is Avrcp profile ready.")
- public Boolean bluetoothAvrcpIsReady() {
- return sIsAvrcpReady;
- }
+ /**
+ * Is Avrcp profile ready.
+ * @return Avrcp profile is ready or not.
+ */
+ @Rpc(description = "Is Avrcp profile ready.")
+ public Boolean bluetoothAvrcpIsReady() {
+ return sIsAvrcpReady;
+ }
- @Rpc(description = "Get all the devices connected through AVRCP.")
- public List<BluetoothDevice> bluetoothAvrcpGetConnectedDevices() {
- if (!sIsAvrcpReady) {
- Log.d("AVRCP profile is not ready.");
- return null;
+ /**
+ * Get all the devices connected through AVRCP.
+ * @return Lsit of the devices connected through AVRCP.
+ */
+ @Rpc(description = "Get all the devices connected through AVRCP.")
+ public List<BluetoothDevice> bluetoothAvrcpGetConnectedDevices() {
+ if (!sIsAvrcpReady) {
+ Log.d("AVRCP profile is not ready.");
+ return null;
+ }
+ return sAvrcpProfile.getConnectedDevices();
}
- return sAvrcpProfile.getConnectedDevices();
- }
- @Rpc(description = "Close AVRCP connection.")
- public void bluetoothAvrcpDisconnect() throws NoSuchMethodException,
- IllegalAccessException,
- IllegalArgumentException,
- InvocationTargetException {
- if (!sIsAvrcpReady) {
- Log.d("AVRCP profile is not ready.");
- return;
- }
- Method m = sAvrcpProfile.getClass().getMethod("close");
- m.invoke(sAvrcpProfile);
- }
+ /**
+ * Close AVRCP connection.
+ */
+ @Rpc(description = "Close AVRCP connection.")
+ public void bluetoothAvrcpDisconnect() throws NoSuchMethodException,
+ IllegalAccessException, IllegalArgumentException,
+ InvocationTargetException {
+ if (!sIsAvrcpReady) {
+ Log.d("AVRCP profile is not ready.");
+ return;
+ }
+ Method m = sAvrcpProfile.getClass().getMethod("close");
+ m.invoke(sAvrcpProfile);
+ }
- @Override
- public void shutdown() {
- }
+ @Override
+ public void shutdown() {
+ }
}
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothBroadcastHelper.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothBroadcastHelper.java
index f3bc288c..aab5e63b 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothBroadcastHelper.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothBroadcastHelper.java
@@ -25,36 +25,45 @@ import android.content.IntentFilter;
public class BluetoothBroadcastHelper {
- private static BroadcastReceiver mListener;
- private final Context mContext;
- private final BroadcastReceiver mReceiver;
- private final String[] mActions = {BluetoothDevice.ACTION_FOUND,
- BluetoothDevice.ACTION_UUID,
- BluetoothAdapter.ACTION_DISCOVERY_STARTED,
- BluetoothAdapter.ACTION_DISCOVERY_FINISHED};
-
- public BluetoothBroadcastHelper(Context context, BroadcastReceiver listener) {
- mContext = context;
- mListener = listener;
- mReceiver = new BluetoothReceiver();
- }
-
- public void startReceiver() {
- IntentFilter mIntentFilter = new IntentFilter();
- for(String action : mActions) {
- mIntentFilter.addAction(action);
+ private static BroadcastReceiver sListener;
+ private final Context mContext;
+ private final BroadcastReceiver mReceiver;
+ private final String[] mActions = {BluetoothDevice.ACTION_FOUND,
+ BluetoothDevice.ACTION_UUID,
+ BluetoothAdapter.ACTION_DISCOVERY_STARTED,
+ BluetoothAdapter.ACTION_DISCOVERY_FINISHED};
+
+ public BluetoothBroadcastHelper(Context context, BroadcastReceiver listener) {
+ mContext = context;
+ sListener = listener;
+ mReceiver = new BluetoothReceiver();
+ }
+
+ /**
+ * Start the Receiver.
+ */
+ public void startReceiver() {
+ IntentFilter mIntentFilter = new IntentFilter();
+ for (String action : mActions) {
+ mIntentFilter.addAction(action);
+ }
+ mContext.registerReceiver(mReceiver, mIntentFilter);
}
- mContext.registerReceiver(mReceiver, mIntentFilter);
- }
- public static class BluetoothReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- mListener.onReceive(context, intent);
+ /**
+ * Bluetooth Receiver Class.
+ */
+ public static class BluetoothReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ sListener.onReceive(context, intent);
+ }
}
- }
- public void stopReceiver() {
- mContext.unregisterReceiver(mReceiver);
- }
+ /**
+ * Unregister the receiver.
+ */
+ public void stopReceiver() {
+ mContext.unregisterReceiver(mReceiver);
+ }
}
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java
index 84438836..6945f9ef 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java
@@ -16,13 +16,6 @@
package com.googlecode.android_scripting.facade.bluetooth;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import android.app.Service;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothA2dpSink;
@@ -58,6 +51,13 @@ import com.googlecode.android_scripting.rpc.RpcParameter;
import org.json.JSONArray;
import org.json.JSONException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
public class BluetoothConnectionFacade extends RpcReceiver {
private final Service mService;
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothDiscoveryHelper.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothDiscoveryHelper.java
index 11a240c7..51ebf5fd 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothDiscoveryHelper.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothDiscoveryHelper.java
@@ -23,74 +23,98 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import java.util.Set;
-
import com.googlecode.android_scripting.Log;
-public class BluetoothDiscoveryHelper {
-
- public static interface BluetoothDiscoveryListener {
- public void addBondedDevice(String name, String address);
+import java.util.Set;
- public void addDevice(String name, String address);
+/**
+ * This class is used to put the device in discovery mode.
+ */
+public class BluetoothDiscoveryHelper {
- public void scanDone();
- }
+ /**
+ * BLuetooth discovery listener Interface.
+ */
+ public interface BluetoothDiscoveryListener {
+
+ /**
+ * Add Bonded device.
+ */
+ void addBondedDevice(String name, String address);
+
+ /**
+ * Add Devices.
+ */
+ void addDevice(String name, String address);
+
+ /**
+ * Complete scanning.
+ */
+ void scanDone();
+ }
- private final Context mContext;
- private final BluetoothDiscoveryListener mListener;
- private final BroadcastReceiver mReceiver;
+ private final Context mContext;
+ private final BluetoothDiscoveryListener mListener;
+ private final BroadcastReceiver mReceiver;
- public BluetoothDiscoveryHelper(Context context, BluetoothDiscoveryListener listener) {
+ public BluetoothDiscoveryHelper(
+ Context context, BluetoothDiscoveryListener listener) {
mContext = context;
mListener = listener;
mReceiver = new BluetoothReceiver();
- }
+ }
- private class BluetoothReceiver extends BroadcastReceiver {
+ private class BluetoothReceiver extends BroadcastReceiver {
@Override
- public void onReceive(Context context, Intent intent) {
- final String action = intent.getAction();
-
- if (BluetoothDevice.ACTION_FOUND.equals(action)) {
- // Get the BluetoothDevice object from the Intent.
- BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
- Log.d("Found device " + device.getAliasName());
- // If it's already paired, skip it, because it's been listed already.
- if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
- mListener.addDevice(device.getName(), device.getAddress());
+ public void onReceive(Context context, Intent intent) {
+ final String action = intent.getAction();
+
+ if (BluetoothDevice.ACTION_FOUND.equals(action)) {
+ // Get the BluetoothDevice object from the Intent.
+ BluetoothDevice device = intent.getParcelableExtra(
+ BluetoothDevice.EXTRA_DEVICE);
+ Log.d("Found device " + device.getAliasName());
+ // If it's already paired, skip it, because it's been listed already.
+ if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
+ mListener.addDevice(device.getName(), device.getAddress());
+ }
+ } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
+ mListener.scanDone();
+ }
}
- } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
- mListener.scanDone();
- }
}
- }
+ /**
+ * Start Bluetooth Discovery.
+ */
- public void startDiscovery() {
- BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ public void startDiscovery() {
+ BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
- if (bluetoothAdapter.isDiscovering()) {
- bluetoothAdapter.cancelDiscovery();
- }
+ if (bluetoothAdapter.isDiscovering()) {
+ bluetoothAdapter.cancelDiscovery();
+ }
- Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
- for (BluetoothDevice device : pairedDevices) {
- mListener.addBondedDevice(device.getName(), device.getAddress());
- }
+ Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
+ for (BluetoothDevice device : pairedDevices) {
+ mListener.addBondedDevice(device.getName(), device.getAddress());
+ }
- IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
- filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
- mContext.registerReceiver(mReceiver, filter);
+ IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
+ filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
+ mContext.registerReceiver(mReceiver, filter);
- if (!bluetoothAdapter.isEnabled()) {
- bluetoothAdapter.enable();
- }
+ if (!bluetoothAdapter.isEnabled()) {
+ bluetoothAdapter.enable();
+ }
- bluetoothAdapter.startDiscovery();
- }
+ bluetoothAdapter.startDiscovery();
+ }
- public void cancel() {
- mContext.unregisterReceiver(mReceiver);
- mListener.scanDone();
- }
+ /**
+ * Cancel.
+ */
+ public void cancel() {
+ mContext.unregisterReceiver(mReceiver);
+ mListener.scanDone();
+ }
}
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothFacade.java
index c2c2cfc1..e675340e 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothFacade.java
@@ -64,7 +64,8 @@ public class BluetoothFacade extends RpcReceiver {
public BluetoothFacade(FacadeManager manager) {
super(manager);
- mBluetoothAdapter = MainThread.run(manager.getService(), new Callable<BluetoothAdapter>() {
+ mBluetoothAdapter = MainThread.run(manager.getService(),
+ new Callable<BluetoothAdapter>() {
@Override
public BluetoothAdapter call() throws Exception {
return BluetoothAdapter.getDefaultAdapter();
@@ -87,7 +88,8 @@ public class BluetoothFacade extends RpcReceiver {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(BluetoothDevice.ACTION_FOUND)) {
- BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ BluetoothDevice device = intent.getParcelableExtra(
+ BluetoothDevice.EXTRA_DEVICE);
Log.d("Found device " + device.getAliasName());
if (!DiscoveredDevices.containsKey(device.getAddress())) {
String name = device.getAliasName();
@@ -124,11 +126,15 @@ public class BluetoothFacade extends RpcReceiver {
if (state == BluetoothAdapter.STATE_ON) {
msg.putString("State", "ON");
mEventFacade.postEvent("BluetoothStateChangedOn", msg);
- if (!mIsMultiBroadcast) mService.unregisterReceiver(mStateReceiver);
+ if (!mIsMultiBroadcast) {
+ mService.unregisterReceiver(mStateReceiver);
+ }
} else if(state == BluetoothAdapter.STATE_OFF) {
msg.putString("State", "OFF");
mEventFacade.postEvent("BluetoothStateChangedOff", msg);
- if (!mIsMultiBroadcast) mService.unregisterReceiver(mStateReceiver);
+ if (!mIsMultiBroadcast) {
+ mService.unregisterReceiver(mStateReceiver);
+ }
}
msg.clear();
}
@@ -155,10 +161,18 @@ public class BluetoothFacade extends RpcReceiver {
public static boolean deviceMatch(BluetoothDevice device, String deviceID) {
- return deviceID.equals(device.getAliasName()) || deviceID.equals(device.getAddress());
+ return deviceID.equals(device.getAliasName()) || deviceID.equals(
+ device.getAddress());
}
- public static <T> BluetoothDevice getDevice(ConcurrentHashMap<String, T> devices, String device)
+ /**
+ * Get Bluetooth device.
+ * @param devices - HashMap of Device Address and Bluetooth device name.
+ * @param device - name of the device.
+ * @return the device name if it exits.
+ */
+ public static <T> BluetoothDevice getDevice(
+ ConcurrentHashMap<String, T> devices, String device)
throws Exception {
if (devices.containsKey(device)) {
return (BluetoothDevice) devices.get(device);
@@ -167,7 +181,14 @@ public class BluetoothFacade extends RpcReceiver {
}
}
- public static BluetoothDevice getDevice(Collection<BluetoothDevice> devices, String deviceID)
+ /**
+ * Get Bluetooth device.
+ * @param devices - Collection of device IDs.
+ * @param deviceID - ID of the desired device.
+ * @return the Bluetooth device if the device ID is matched.
+ */
+ public static BluetoothDevice getDevice(
+ Collection<BluetoothDevice> devices, String deviceID)
throws Exception {
Log.d("Looking for " + deviceID);
for (BluetoothDevice bd : devices) {
@@ -180,7 +201,14 @@ public class BluetoothFacade extends RpcReceiver {
throw new Exception("Can't find device " + deviceID);
}
- public static boolean deviceExists(Collection<BluetoothDevice> devices, String deviceID) {
+ /**
+ * Verify device existence.
+ * @param devices - Collection of device IDs.
+ * @param deviceID - ID of the desired device.
+ * @return if the device Exists or not.
+ */
+ public static boolean deviceExists(
+ Collection<BluetoothDevice> devices, String deviceID) {
for (BluetoothDevice bd : devices) {
if (deviceMatch(bd, deviceID)) {
Log.d("Found match " + bd.getAliasName() + " " + bd.getAddress());
@@ -204,8 +232,8 @@ public class BluetoothFacade extends RpcReceiver {
@RpcDefault("300")
Integer duration) {
Log.d("Making discoverable for " + duration + " seconds.\n");
- mBluetoothAdapter
- .setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, duration);
+ mBluetoothAdapter.setScanMode(
+ BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, duration);
}
@Rpc(description = "Requests that the device be not discoverable.")
@@ -483,7 +511,8 @@ public class BluetoothFacade extends RpcReceiver {
@Override
public void shutdown() {
- for (Map.Entry<String, BluetoothConnection> entry : connections.entrySet()) {
+ for (Map.Entry<String,
+ BluetoothConnection> entry : connections.entrySet()) {
entry.getValue().stop();
}
if (mMultiStateReceiver != null ) bluetoothStopListeningForAdapterStateChange();
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothHfpClientFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothHfpClientFacade.java
index 930b229b..a1f23287 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothHfpClientFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothHfpClientFacade.java
@@ -34,146 +34,197 @@ import java.util.ArrayList;
import java.util.List;
public class BluetoothHfpClientFacade extends RpcReceiver {
- static final ParcelUuid[] UUIDS = {
- BluetoothUuid.Handsfree_AG,
- };
+ static final ParcelUuid[] UUIDS = {
+ BluetoothUuid.Handsfree_AG,
+ };
- private final Service mService;
- private final BluetoothAdapter mBluetoothAdapter;
+ private final Service mService;
+ private final BluetoothAdapter mBluetoothAdapter;
- private static boolean sIsHfpClientReady = false;
- private static BluetoothHeadsetClient sHfpClientProfile = null;
+ private static boolean sIsHfpClientReady = false;
+ private static BluetoothHeadsetClient sHfpClientProfile = null;
- public BluetoothHfpClientFacade(FacadeManager manager) {
- super(manager);
- mService = manager.getService();
- mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
- mBluetoothAdapter.getProfileProxy(mService, new HfpClientServiceListener(),
- BluetoothProfile.HEADSET_CLIENT);
- }
+ public BluetoothHfpClientFacade(FacadeManager manager) {
+ super(manager);
+ mService = manager.getService();
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ mBluetoothAdapter.getProfileProxy(mService,
+ new HfpClientServiceListener(),
+ BluetoothProfile.HEADSET_CLIENT);
+ }
- class HfpClientServiceListener implements BluetoothProfile.ServiceListener {
- @Override
- public void onServiceConnected(int profile, BluetoothProfile proxy) {
- sHfpClientProfile = (BluetoothHeadsetClient) proxy;
- sIsHfpClientReady = true;
+ class HfpClientServiceListener implements BluetoothProfile.ServiceListener {
+ @Override
+ public void onServiceConnected(int profile, BluetoothProfile proxy) {
+ sHfpClientProfile = (BluetoothHeadsetClient) proxy;
+ sIsHfpClientReady = true;
+ }
+
+ @Override
+ public void onServiceDisconnected(int profile) {
+ sIsHfpClientReady = false;
+ }
}
- @Override
- public void onServiceDisconnected(int profile) {
- sIsHfpClientReady = false;
+ /**
+ * Connect to HfpClient.
+ * @param device - the BluetoothDevice object to connect Hfp client.
+ * @return if the connection was successfull or not.
+ */
+ public Boolean hfpClientConnect(BluetoothDevice device) {
+ if (sHfpClientProfile == null) return false;
+ return sHfpClientProfile.connect(device);
}
- }
-
- public Boolean hfpClientConnect(BluetoothDevice device) {
- if (sHfpClientProfile == null) return false;
- return sHfpClientProfile.connect(device);
- }
-
- public Boolean hfpClientDisconnect(BluetoothDevice device) {
- if (sHfpClientProfile == null) return false;
- return sHfpClientProfile.disconnect(device);
- }
-
- @Rpc(description = "Is HfpClient profile ready.")
- public Boolean bluetoothHfpClientIsReady() {
- return sIsHfpClientReady;
- }
-
- @Rpc(description = "Set priority of the profile")
- public void bluetoothHfpClientSetPriority(
- @RpcParameter(name = "device", description = "Mac address of a BT device.")
- String deviceStr,
- @RpcParameter(name = "priority", description = "Priority that needs to be set.")
- Integer priority)
- throws Exception {
- if (sHfpClientProfile == null) return;
- BluetoothDevice device =
- BluetoothFacade.getDevice(mBluetoothAdapter.getBondedDevices(), deviceStr);
- Log.d("Changing priority of device " + device.getAliasName() + " p: " + priority);
- sHfpClientProfile.setPriority(device, priority);
- }
-
- @Rpc(description = "Get priority of the profile")
- public Integer bluetoothHfpClientGetPriority(
- @RpcParameter(name = "device", description = "Mac address of a BT device.")
- String deviceStr)
- throws Exception {
- if (sHfpClientProfile == null) return BluetoothProfile.PRIORITY_UNDEFINED;
- BluetoothDevice device =
- BluetoothFacade.getDevice(mBluetoothAdapter.getBondedDevices(), deviceStr);
- return sHfpClientProfile.getPriority(device);
- }
-
- @Rpc(description = "Connect to an HFP Client device.")
- public Boolean bluetoothHfpClientConnect(
- @RpcParameter(name = "device", description = "Name or MAC address of a bluetooth device.")
- String deviceStr)
- throws Exception {
- if (sHfpClientProfile == null) return false;
- try {
- BluetoothDevice device =
- BluetoothFacade.getDevice(BluetoothFacade.DiscoveredDevices, deviceStr);
- Log.d("Connecting to device " + device.getAliasName());
- return hfpClientConnect(device);
- } catch (Exception e) {
- Log.e("bluetoothHfpClientConnect failed on getDevice " + deviceStr + " with " + e);
- return false;
+
+ /**
+ * Disconnect from HfpClient.
+ * @param device - the BluetoothDevice object to disconnect from Hfp client.
+ * @return if the disconnection was successfull or not.
+ */
+ public Boolean hfpClientDisconnect(BluetoothDevice device) {
+ if (sHfpClientProfile == null) return false;
+ return sHfpClientProfile.disconnect(device);
}
- }
-
- @Rpc(description = "Disconnect an HFP Client device.")
- public Boolean bluetoothHfpClientDisconnect(
- @RpcParameter(name = "device", description = "Name or MAC address of a device.")
- String deviceStr) {
- if (sHfpClientProfile == null) return false;
- Log.d("Connected devices: " + sHfpClientProfile.getConnectedDevices());
- try {
+
+ /**
+ * Is Hfp Client profile ready.
+ * @return Hfp Client profile is ready or not.
+ */
+ @Rpc(description = "Is HfpClient profile ready.")
+ public Boolean bluetoothHfpClientIsReady() {
+ return sIsHfpClientReady;
+ }
+
+ /**
+ * Set priority of the profile.
+ * @param deviceStr - Mac address of a BT device.
+ * @param priority - Priority that needs to be set.
+ */
+ @Rpc(description = "Set priority of the profile")
+ public void bluetoothHfpClientSetPriority(
+ @RpcParameter(name = "device",
+ description = "Mac address of a BT device.") String deviceStr,
+ @RpcParameter(name = "priority",
+ description = "Priority that needs to be set.")
+ Integer priority) throws Exception {
+ if (sHfpClientProfile == null) return;
BluetoothDevice device =
- BluetoothFacade.getDevice(sHfpClientProfile.getConnectedDevices(), deviceStr);
- return hfpClientDisconnect(device);
- } catch (Exception e) {
- // Do nothing since it is disconnect and this function should force disconnect.
- Log.e("bluetoothHfpClientConnect getDevice failed " + e);
+ BluetoothFacade.getDevice(mBluetoothAdapter.getBondedDevices(),
+ deviceStr);
+ Log.d("Changing priority of device " + device.getAliasName()
+ + " p: " + priority);
+ sHfpClientProfile.setPriority(device, priority);
+ }
+
+ /**
+ * Get priority of the profile.
+ * @param deviceStr - Mac address of a BT device.
+ * @return Priority of the device.
+ */
+ @Rpc(description = "Get priority of the profile")
+ public Integer bluetoothHfpClientGetPriority(
+ @RpcParameter(name = "device", description =
+ "Mac address of a BT device.") String deviceStr)
+ throws Exception {
+ if (sHfpClientProfile == null) return BluetoothProfile.PRIORITY_UNDEFINED;
+ BluetoothDevice device = BluetoothFacade.getDevice(
+ mBluetoothAdapter.getBondedDevices(), deviceStr);
+ return sHfpClientProfile.getPriority(device);
+ }
+
+ /**
+ * Connect to an HFP Client device.
+ * @param deviceStr - Name or MAC address of a bluetooth device.
+ * @return Hfp Client was connected or not.
+ */
+ @Rpc(description = "Connect to an HFP Client device.")
+ public Boolean bluetoothHfpClientConnect(
+ @RpcParameter(name = "device",
+ description = "Name or MAC address of a bluetooth device.")
+ String deviceStr)
+ throws Exception {
+ if (sHfpClientProfile == null) return false;
+ try {
+ BluetoothDevice device = BluetoothFacade.getDevice(
+ BluetoothFacade.DiscoveredDevices, deviceStr);
+ Log.d("Connecting to device " + device.getAliasName());
+ return hfpClientConnect(device);
+ } catch (Exception e) {
+ Log.e("bluetoothHfpClientConnect failed on getDevice "
+ + deviceStr + " with " + e);
+ return false;
+ }
+ }
+
+ /**
+ * Disconnect an HFP Client device.
+ * @param deviceStr - Name or MAC address of a bluetooth device.
+ * @return Hfp Client was disconnected or not.
+ */
+ @Rpc(description = "Disconnect an HFP Client device.")
+ public Boolean bluetoothHfpClientDisconnect(
+ @RpcParameter(name = "device",
+ description = "Name or MAC address of a device.")
+ String deviceStr) {
+ if (sHfpClientProfile == null) return false;
+ Log.d("Connected devices: " + sHfpClientProfile.getConnectedDevices());
+ try {
+ BluetoothDevice device = BluetoothFacade.getDevice(
+ sHfpClientProfile.getConnectedDevices(), deviceStr);
+ return hfpClientDisconnect(device);
+ } catch (Exception e) {
+ // Do nothing since it is disconnect and this
+ // function should force disconnect.
+ Log.e("bluetoothHfpClientConnect getDevice failed " + e);
+ }
+ return false;
+ }
+
+ /**
+ * Get all the devices connected through HFP Client.
+ * @return List of all the devices connected through HFP Client.
+ */
+ @Rpc(description = "Get all the devices connected through HFP Client.")
+ public List<BluetoothDevice> bluetoothHfpClientGetConnectedDevices() {
+ if (sHfpClientProfile == null) return new ArrayList<BluetoothDevice>();
+ return sHfpClientProfile.getConnectedDevices();
+ }
+
+ /**
+ * Get the connection status of a device.
+ * @param deviceID - Name or MAC address of a bluetooth device.
+ * @return connection status of the device.
+ */
+ @Rpc(description = "Get the connection status of a device.")
+ public Integer bluetoothHfpClientGetConnectionStatus(
+ @RpcParameter(name = "deviceID",
+ description = "Name or MAC address of a bluetooth device.")
+ String deviceID) {
+ if (sHfpClientProfile == null) {
+ return BluetoothProfile.STATE_DISCONNECTED;
+ }
+ List<BluetoothDevice> deviceList =
+ sHfpClientProfile.getConnectedDevices();
+ BluetoothDevice device;
+ try {
+ device = BluetoothFacade.getDevice(deviceList, deviceID);
+ } catch (Exception e) {
+ Log.e(e);
+ return BluetoothProfile.STATE_DISCONNECTED;
+ }
+ return sHfpClientProfile.getConnectionState(device);
}
- return false;
- }
-
- @Rpc(description = "Get all the devices connected through HFP Client.")
- public List<BluetoothDevice> bluetoothHfpClientGetConnectedDevices() {
- if (sHfpClientProfile == null) return new ArrayList<BluetoothDevice>();
- return sHfpClientProfile.getConnectedDevices();
- }
-
- @Rpc(description = "Get the connection status of a device.")
- public Integer bluetoothHfpClientGetConnectionStatus(
- @RpcParameter(name = "deviceID",
- description = "Name or MAC address of a bluetooth device.")
- String deviceID) {
- if (sHfpClientProfile == null) {
- return BluetoothProfile.STATE_DISCONNECTED;
- }
- List<BluetoothDevice> deviceList = sHfpClientProfile.getConnectedDevices();
- BluetoothDevice device;
- try {
- device = BluetoothFacade.getDevice(deviceList, deviceID);
- } catch (Exception e) {
- Log.e(e);
- return BluetoothProfile.STATE_DISCONNECTED;
- }
- return sHfpClientProfile.getConnectionState(device);
- }
/**
* Get the audio routing state of specified device.
- *
* @param deviceStr the Bluetooth MAC address of remote device
- * @return Audio State
+ * @return Audio State of the device.
*/
@Rpc(description = "Get all the devices connected through HFP Client.")
public Integer bluetoothHfpClientGetAudioState(
- @RpcParameter(name = "device", description = "MAC address of a bluetooth device.")
- String deviceStr) {
+ @RpcParameter(name = "device",
+ description = "MAC address of a bluetooth device.")
+ String deviceStr) {
if (sHfpClientProfile == null) return -1;
BluetoothDevice device;
try {
@@ -194,12 +245,14 @@ public class BluetoothHfpClientFacade extends RpcReceiver {
*/
@Rpc(description = "Start Remote device Voice Recognition through HFP Client.")
public boolean bluetoothHfpClientStartVoiceRecognition(
- @RpcParameter(name = "device", description = "MAC address of a bluetooth device.")
- String deviceStr) {
+ @RpcParameter(name = "device",
+ description = "MAC address of a bluetooth device.")
+ String deviceStr) {
if (sHfpClientProfile == null) return false;
BluetoothDevice device;
try {
- device = BluetoothFacade.getDevice(sHfpClientProfile.getConnectedDevices(), deviceStr);
+ device = BluetoothFacade.getDevice(
+ sHfpClientProfile.getConnectedDevices(), deviceStr);
} catch (Exception e) {
// Do nothing since it is disconnect and this function should force disconnect.
Log.e("bluetoothHfpClientConnect getDevice failed " + e);
@@ -216,21 +269,24 @@ public class BluetoothHfpClientFacade extends RpcReceiver {
*/
@Rpc(description = "Stop Remote device Voice Recognition through HFP Client.")
public boolean bluetoothHfpClientStopVoiceRecognition(
- @RpcParameter(name = "device", description = "MAC address of a bluetooth device.")
- String deviceStr) {
+ @RpcParameter(name = "device",
+ description = "MAC address of a bluetooth device.")
+ String deviceStr) {
if (sHfpClientProfile == null) return false;
BluetoothDevice device;
try {
- device = BluetoothFacade.getDevice(sHfpClientProfile.getConnectedDevices(), deviceStr);
+ device = BluetoothFacade.getDevice(
+ sHfpClientProfile.getConnectedDevices(), deviceStr);
} catch (Exception e) {
- // Do nothing since it is disconnect and this function should force disconnect.
+ // Do nothing since it is disconnect
+ // and this function should force disconnect.
Log.e("bluetoothHfpClientConnect getDevice failed " + e);
return false;
}
return sHfpClientProfile.stopVoiceRecognition(device);
}
- @Override
- public void shutdown() {
- }
+ @Override
+ public void shutdown() {
+ }
}
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothHidFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothHidFacade.java
index 52245efe..140c1dea 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothHidFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothHidFacade.java
@@ -16,19 +16,17 @@
package com.googlecode.android_scripting.facade.bluetooth;
-import java.util.List;
-
import android.app.Service;
-import android.bluetooth.BluetoothHidHost;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothHidHost;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUuid;
-import android.os.ParcelUuid;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.os.ParcelUuid;
import com.googlecode.android_scripting.Log;
import com.googlecode.android_scripting.facade.EventFacade;
@@ -38,177 +36,228 @@ import com.googlecode.android_scripting.rpc.Rpc;
import com.googlecode.android_scripting.rpc.RpcDefault;
import com.googlecode.android_scripting.rpc.RpcParameter;
+import java.util.List;
+
+/*
+ * Class Bluetooth HidFacade
+ */
public class BluetoothHidFacade extends RpcReceiver {
- public final static ParcelUuid[] UUIDS = { BluetoothUuid.Hid };
+ public static final ParcelUuid[] UUIDS = { BluetoothUuid.Hid };
- private final Service mService;
- private final BluetoothAdapter mBluetoothAdapter;
+ private final Service mService;
+ private final BluetoothAdapter mBluetoothAdapter;
- private static boolean sIsHidReady = false;
- private static BluetoothHidHost sHidProfile = null;
+ private static boolean sIsHidReady = false;
+ private static BluetoothHidHost sHidProfile = null;
- private final EventFacade mEventFacade;
+ private final EventFacade mEventFacade;
- public BluetoothHidFacade(FacadeManager manager) {
- super(manager);
- mService = manager.getService();
- mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
- mBluetoothAdapter.getProfileProxy(mService, new HidServiceListener(),
+ public BluetoothHidFacade(FacadeManager manager) {
+ super(manager);
+ mService = manager.getService();
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ mBluetoothAdapter.getProfileProxy(mService, new HidServiceListener(),
BluetoothProfile.HID_HOST);
- IntentFilter pkgFilter = new IntentFilter();
- pkgFilter.addAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED);
- pkgFilter.addAction(BluetoothHidHost.ACTION_PROTOCOL_MODE_CHANGED);
- pkgFilter.addAction(BluetoothHidHost.ACTION_HANDSHAKE);
- pkgFilter.addAction(BluetoothHidHost.ACTION_REPORT);
- pkgFilter.addAction(BluetoothHidHost.ACTION_VIRTUAL_UNPLUG_STATUS);
- pkgFilter.addAction(BluetoothHidHost.ACTION_IDLE_TIME_CHANGED);
- mService.registerReceiver(mHidServiceBroadcastReceiver, pkgFilter);
- Log.d(HidServiceBroadcastReceiver.TAG + " registered");
- mEventFacade = manager.getReceiver(EventFacade.class);
- }
-
- class HidServiceListener implements BluetoothProfile.ServiceListener {
- @Override
- public void onServiceConnected(int profile, BluetoothProfile proxy) {
- sHidProfile = (BluetoothHidHost) proxy;
- sIsHidReady = true;
+ IntentFilter pkgFilter = new IntentFilter();
+ pkgFilter.addAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED);
+ pkgFilter.addAction(BluetoothHidHost.ACTION_PROTOCOL_MODE_CHANGED);
+ pkgFilter.addAction(BluetoothHidHost.ACTION_HANDSHAKE);
+ pkgFilter.addAction(BluetoothHidHost.ACTION_REPORT);
+ pkgFilter.addAction(BluetoothHidHost.ACTION_VIRTUAL_UNPLUG_STATUS);
+ pkgFilter.addAction(BluetoothHidHost.ACTION_IDLE_TIME_CHANGED);
+ mService.registerReceiver(mHidServiceBroadcastReceiver, pkgFilter);
+ Log.d(HidServiceBroadcastReceiver.TAG + " registered");
+ mEventFacade = manager.getReceiver(EventFacade.class);
}
- @Override
- public void onServiceDisconnected(int profile) {
- sIsHidReady = false;
+ class HidServiceListener implements BluetoothProfile.ServiceListener {
+ @Override
+ public void onServiceConnected(int profile, BluetoothProfile proxy) {
+ sHidProfile = (BluetoothHidHost) proxy;
+ sIsHidReady = true;
+ }
+
+ @Override
+ public void onServiceDisconnected(int profile) {
+ sIsHidReady = false;
+ }
+ }
+
+ class HidServiceBroadcastReceiver extends BroadcastReceiver {
+ private static final String TAG = "HidServiceBroadcastReceiver";
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ Log.d(TAG + " action=" + action);
+
+ switch (action) {
+ case BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED: {
+ int previousState = intent.getIntExtra(
+ BluetoothProfile.EXTRA_PREVIOUS_STATE, -1);
+ int state = intent.getIntExtra(
+ BluetoothProfile.EXTRA_STATE, -1);
+ Log.d("Connection state changed: "
+ + previousState + " -> " + state);
+ }
+ break;
+ case BluetoothHidHost.ACTION_PROTOCOL_MODE_CHANGED: {
+ int status = intent.getIntExtra(
+ BluetoothHidHost.EXTRA_STATUS, -1);
+ Log.d("Protocol mode changed: " + status);
+ }
+ break;
+ case BluetoothHidHost.ACTION_HANDSHAKE: {
+ int status = intent.getIntExtra(
+ BluetoothHidHost.EXTRA_STATUS, -1);
+ Log.d("Handshake received: " + status);
+ }
+ break;
+ case BluetoothHidHost.ACTION_REPORT: {
+ char[] report = intent.getCharArrayExtra(
+ BluetoothHidHost.EXTRA_REPORT);
+ Log.d("Received report: " + String.valueOf(report));
+ }
+ break;
+ case BluetoothHidHost.ACTION_VIRTUAL_UNPLUG_STATUS: {
+ int status = intent.getIntExtra(
+ BluetoothHidHost.EXTRA_VIRTUAL_UNPLUG_STATUS, -1);
+ Log.d("Virtual unplug status: " + status);
+ }
+ break;
+ case BluetoothHidHost.ACTION_IDLE_TIME_CHANGED: {
+ int idleTime = intent.getIntExtra(
+ BluetoothHidHost.EXTRA_IDLE_TIME, -1);
+ Log.d("Idle time changed: " + idleTime);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ private final BroadcastReceiver mHidServiceBroadcastReceiver =
+ new HidServiceBroadcastReceiver();
+
+ /**
+ * Connect to Hid Profile.
+ * @param device - the Bluetooth Device object to connect to.
+ * @return if the connection was successfull or not.
+ */
+ public Boolean hidConnect(BluetoothDevice device) {
+ if (sHidProfile == null) return false;
+ return sHidProfile.connect(device);
+ }
+
+ /**
+ * Disconnect to Hid Profile.
+ * @param device - the Bluetooth Device object to disconnect to.
+ * @return if the disconnection was successfull or not.
+ */
+ public Boolean hidDisconnect(BluetoothDevice device) {
+ if (sHidProfile == null) return false;
+ return sHidProfile.disconnect(device);
+ }
+
+ /**
+ * Is Hid profile ready.
+ * @return if Hid profile is ready or not.
+ */
+ @Rpc(description = "Is Hid profile ready.")
+ public Boolean bluetoothHidIsReady() {
+ return sIsHidReady;
+ }
+
+ /**
+ * Connect to an HID device.
+ * @param device - Name or MAC address of a bluetooth device.
+ * @return if the connection was successfull or not.
+ */
+ @Rpc(description = "Connect to an HID device.")
+ public Boolean bluetoothHidConnect(
+ @RpcParameter(name = "device",
+ description = "Name or MAC address of a bluetooth device.")
+ String device)
+ throws Exception {
+ if (sHidProfile == null) return false;
+ BluetoothDevice mDevice = BluetoothFacade.getDevice(
+ BluetoothFacade.DiscoveredDevices, device);
+ Log.d("Connecting to device " + mDevice.getAliasName());
+ return hidConnect(mDevice);
+ }
+
+ /**
+ * Disconnect an HID device.
+ * @param device - the Bluetooth Device object to disconnect to.
+ * @return if the disconnection was successfull or not.
+ */
+ @Rpc(description = "Disconnect an HID device.")
+ public Boolean bluetoothHidDisconnect(
+ @RpcParameter(name = "device",
+ description = "Name or MAC address of a device.")
+ String device)
+ throws Exception {
+ if (sHidProfile == null) return false;
+ Log.d("Connected devices: " + sHidProfile.getConnectedDevices());
+ BluetoothDevice mDevice = BluetoothFacade.getDevice(
+ sHidProfile.getConnectedDevices(), device);
+ return hidDisconnect(mDevice);
+ }
+
+ /**
+ * Get all the devices connected through HID.
+ * @return List of all the devices connected through HID.
+ */
+ @Rpc(description = "Get all the devices connected through HID.")
+ public List<BluetoothDevice> bluetoothHidGetConnectedDevices() {
+ if (!sIsHidReady) return null;
+ return sHidProfile.getConnectedDevices();
+ }
+
+ /**
+ * Get the connection status of a device.
+ * @param deviceID - Name or MAC address of a bluetooth device.
+ * @return connection status of a device.
+ */
+ @Rpc(description = "Get the connection status of a device.")
+ public Integer bluetoothHidGetConnectionStatus(
+ @RpcParameter(name = "deviceID",
+ description = "Name or MAC address of a bluetooth device.")
+ String deviceID) {
+ if (sHidProfile == null) {
+ return BluetoothProfile.STATE_DISCONNECTED;
+ }
+ List<BluetoothDevice> deviceList = sHidProfile.getConnectedDevices();
+ BluetoothDevice device;
+ try {
+ device = BluetoothFacade.getDevice(deviceList, deviceID);
+ } catch (Exception e) {
+ return BluetoothProfile.STATE_DISCONNECTED;
+ }
+ return sHidProfile.getConnectionState(device);
+ }
+
+ /**
+ * Send Set_Report command to the connected HID input device.
+ * @param deviceID - Name or MAC address of a bluetooth device.
+ * @return True if successfully sent the command; otherwise false
+ */
+ @Rpc(description =
+ "Send Set_Report command to the connected HID input device.")
+ public Boolean bluetoothHidSetReport(
+ @RpcParameter(name = "deviceID",
+ description = "Name or MAC address of a bluetooth device.")
+ String deviceID,
+ @RpcParameter(name = "type")
+ @RpcDefault(value = "1") Integer type,
+ @RpcParameter(name = "report")
+ String report) throws Exception {
+ BluetoothDevice device = BluetoothFacade.getDevice(
+ sHidProfile.getConnectedDevices(), deviceID);
+ Log.d("type=" + type);
+ return sHidProfile.setReport(device, (byte) (int) type, report);
}
- }
-
- class HidServiceBroadcastReceiver extends BroadcastReceiver {
- private static final String TAG = "HidServiceBroadcastReceiver";
-
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- Log.d(TAG + " action=" + action);
-
- switch (action) {
- case BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED: {
- int previousState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, -1);
- int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1);
- Log.d("Connection state changed: " + previousState + " -> " + state);
- }
- break;
- case BluetoothHidHost.ACTION_PROTOCOL_MODE_CHANGED: {
- int status = intent.getIntExtra(BluetoothHidHost.EXTRA_STATUS, -1);
- Log.d("Protocol mode changed: " + status);
- }
- break;
- case BluetoothHidHost.ACTION_HANDSHAKE: {
- int status = intent.getIntExtra(BluetoothHidHost.EXTRA_STATUS, -1);
- Log.d("Handshake received: " + status);
- }
- break;
- case BluetoothHidHost.ACTION_REPORT: {
- char[] report = intent.getCharArrayExtra(BluetoothHidHost.EXTRA_REPORT);
- Log.d("Received report: " + String.valueOf(report));
- }
- break;
- case BluetoothHidHost.ACTION_VIRTUAL_UNPLUG_STATUS: {
- int status = intent.getIntExtra(
- BluetoothHidHost.EXTRA_VIRTUAL_UNPLUG_STATUS, -1);
- Log.d("Virtual unplug status: " + status);
- }
- break;
- case BluetoothHidHost.ACTION_IDLE_TIME_CHANGED: {
- int idleTime = intent.getIntExtra(BluetoothHidHost.EXTRA_IDLE_TIME, -1);
- Log.d("Idle time changed: " + idleTime);
- }
- break;
- default:
- break;
- }
- }
- }
-
- private final BroadcastReceiver mHidServiceBroadcastReceiver = new HidServiceBroadcastReceiver();
-
-
- public Boolean hidConnect(BluetoothDevice device) {
- if (sHidProfile == null) return false;
- return sHidProfile.connect(device);
- }
-
- public Boolean hidDisconnect(BluetoothDevice device) {
- if (sHidProfile == null) return false;
- return sHidProfile.disconnect(device);
- }
-
- @Rpc(description = "Is Hid profile ready.")
- public Boolean bluetoothHidIsReady() {
- return sIsHidReady;
- }
-
- @Rpc(description = "Connect to an HID device.")
- public Boolean bluetoothHidConnect(
- @RpcParameter(name = "device", description = "Name or MAC address of a bluetooth device.")
- String device)
- throws Exception {
- if (sHidProfile == null)
- return false;
- BluetoothDevice mDevice = BluetoothFacade.getDevice(BluetoothFacade.DiscoveredDevices, device);
- Log.d("Connecting to device " + mDevice.getAliasName());
- return hidConnect(mDevice);
- }
-
- @Rpc(description = "Disconnect an HID device.")
- public Boolean bluetoothHidDisconnect(
- @RpcParameter(name = "device", description = "Name or MAC address of a device.")
- String device)
- throws Exception {
- if (sHidProfile == null)
- return false;
- Log.d("Connected devices: " + sHidProfile.getConnectedDevices());
- BluetoothDevice mDevice = BluetoothFacade.getDevice(sHidProfile.getConnectedDevices(),
- device);
- return hidDisconnect(mDevice);
- }
-
- @Rpc(description = "Get all the devices connected through HID.")
- public List<BluetoothDevice> bluetoothHidGetConnectedDevices() {
- while (!sIsHidReady);
- return sHidProfile.getConnectedDevices();
- }
-
- @Rpc(description = "Get the connection status of a device.")
- public Integer bluetoothHidGetConnectionStatus(
- @RpcParameter(name = "deviceID",
- description = "Name or MAC address of a bluetooth device.")
- String deviceID) {
- if (sHidProfile == null) {
- return BluetoothProfile.STATE_DISCONNECTED;
- }
- List<BluetoothDevice> deviceList = sHidProfile.getConnectedDevices();
- BluetoothDevice device;
- try {
- device = BluetoothFacade.getDevice(deviceList, deviceID);
- } catch (Exception e) {
- return BluetoothProfile.STATE_DISCONNECTED;
- }
- return sHidProfile.getConnectionState(device);
- }
-
- @Rpc(description = "Send Set_Report command to the connected HID input device.")
- public Boolean bluetoothHidSetReport(
- @RpcParameter(name = "deviceID",
- description = "Name or MAC address of a bluetooth device.")
- String deviceID,
- @RpcParameter(name = "type")
- @RpcDefault(value = "1")
- Integer type,
- @RpcParameter(name = "report")
- String report) throws Exception {
- BluetoothDevice device = BluetoothFacade.getDevice(sHidProfile.getConnectedDevices(),
- deviceID);
- Log.d("type=" + type);
- return sHidProfile.setReport(device, (byte) (int) type, report);
- }
/**
* Sends the Get_Report command to the given connected HID input device.
@@ -219,173 +268,177 @@ public class BluetoothHidFacade extends RpcReceiver {
* @return True if successfully sent the command; otherwise false
* @throws Exception error from Bluetooth HidService
*/
- @Rpc(description = "Send Get_Report command to the connected HID input device.")
- public Boolean bluetoothHidGetReport(
- @RpcParameter(name = "deviceID",
- description = "Name or MAC address of a bluetooth device.")
- String deviceID,
- @RpcParameter(name = "type")
- @RpcDefault(value = "1")
- Integer type,
- @RpcParameter(name = "reportId")
- Integer reportId,
- @RpcParameter(name = "buffSize")
- Integer buffSize) throws Exception {
- BluetoothDevice device = BluetoothFacade.getDevice(sHidProfile.getConnectedDevices(),
- deviceID);
- Log.d("type=" + type + " reportId=" + reportId);
- return sHidProfile.getReport(device, (byte) (int) type, (byte) (int) reportId, buffSize);
- }
- /**
- * Sends a data report to the given connected HID input device.
- * @param deviceID name or MAC address or the HID input device
- * @param report the report payload
- * @return True if successfully sent the command; otherwise false
- * @throws Exception error from Bluetooth HidService
- */
- @Rpc(description = "Send data to a connected HID device.")
- public Boolean bluetoothHidSendData(
- @RpcParameter(name = "deviceID",
- description = "Name or MAC address of a bluetooth device.")
- String deviceID,
- @RpcParameter(name = "report")
- String report) throws Exception {
- BluetoothDevice device = BluetoothFacade.getDevice(sHidProfile.getConnectedDevices(),
- deviceID);
- return sHidProfile.sendData(device, report);
- }
-
-
- /**
- * Sends the virtual cable unplug command to the given connected HID input device.
- * @param deviceID name or MAC address or the HID input device
- * @return True if successfully sent the command; otherwise false
- * @throws Exception error from Bluetooth HidService
- */
- @Rpc(description = "Send virtual unplug to a connected HID device.")
- public Boolean bluetoothHidVirtualUnplug(
- @RpcParameter(name = "deviceID",
+ @Rpc(description = "Send Get_Report command to the connected HID input device.")
+ public Boolean bluetoothHidGetReport(
+ @RpcParameter(name = "deviceID",
+ description = "Name or MAC address of a bluetooth device.")
+ String deviceID,
+ @RpcParameter(name = "type")
+ @RpcDefault(value = "1") Integer type,
+ @RpcParameter(name = "reportId")
+ Integer reportId,
+ @RpcParameter(name = "buffSize")
+ Integer buffSize) throws Exception {
+ BluetoothDevice device = BluetoothFacade.getDevice(
+ sHidProfile.getConnectedDevices(), deviceID);
+ Log.d("type=" + type + " reportId=" + reportId);
+ return sHidProfile.getReport(
+ device, (byte) (int) type, (byte) (int) reportId, buffSize);
+ }
+
+ /**
+ * Sends a data report to the given connected HID input device.
+ * @param deviceID name or MAC address or the HID input device
+ * @param report the report payload
+ * @return True if successfully sent the command; otherwise false
+ * @throws Exception error from Bluetooth HidService
+ */
+ @Rpc(description = "Send data to a connected HID device.")
+ public Boolean bluetoothHidSendData(
+ @RpcParameter(name = "deviceID",
+ description = "Name or MAC address of a bluetooth device.")
+ String deviceID,
+ @RpcParameter(name = "report")
+ String report) throws Exception {
+ BluetoothDevice device = BluetoothFacade.getDevice(
+ sHidProfile.getConnectedDevices(), deviceID);
+ return sHidProfile.sendData(device, report);
+ }
+
+
+ /**
+ * Sends the virtual cable unplug command to the given connected HID input device.
+ * @param deviceID name or MAC address or the HID input device
+ * @return True if successfully sent the command; otherwise false
+ * @throws Exception error from Bluetooth HidService
+ */
+ @Rpc(description = "Send virtual unplug to a connected HID device.")
+ public Boolean bluetoothHidVirtualUnplug(
+ @RpcParameter(name = "deviceID",
description = "Name or MAC address of a bluetooth device.")
String deviceID) throws Exception {
- BluetoothDevice device = BluetoothFacade.getDevice(sHidProfile.getConnectedDevices(),
+ BluetoothDevice device = BluetoothFacade.getDevice(sHidProfile.getConnectedDevices(),
deviceID);
- return sHidProfile.virtualUnplug(device);
- }
-
- /**
- * Sends the Set_Priority command to the given connected HID input device.
- * @param deviceID name or MAC address or the HID input device
- * @param priority priority level
- * @return True if successfully sent the command; otherwise false
- * @throws Exception error from Bluetooth HidService
- */
- @Rpc(description = "Set priority of the profile")
-
- public Boolean bluetoothHidSetPriority(
+ return sHidProfile.virtualUnplug(device);
+ }
+
+ /**
+ * Sends the Set_Priority command to the given connected HID input device.
+ * @param deviceID name or MAC address or the HID input device
+ * @param priority priority level
+ * @return True if successfully sent the command; otherwise false
+ * @throws Exception error from Bluetooth HidService
+ */
+ @Rpc(description = "Set priority of the profile")
+ public Boolean bluetoothHidSetPriority(
@RpcParameter(name = "deviceID",
description = "Name or MAC address of a bluetooth device.")
String deviceID,
@RpcParameter(name = "priority")
Integer priority) throws Exception {
- BluetoothDevice device = BluetoothFacade.getDevice(sHidProfile.getConnectedDevices(),
+ BluetoothDevice device = BluetoothFacade.getDevice(sHidProfile.getConnectedDevices(),
deviceID);
- return sHidProfile.setPriority(device, priority);
- }
-
- /**
- * Sends the Get_Priority command to the given connected HID input device.
- * @param deviceID name or MAC address or the HID input device
- * @return The value of the HID input device priority
- * @throws Exception error from Bluetooth HidService
- */
- @Rpc(description = "Get priority of the profile")
- public Integer bluetoothHidGetPriority(
+ return sHidProfile.setPriority(device, priority);
+ }
+
+ /**
+ * Sends the Get_Priority command to the given connected HID input device.
+ * @param deviceID name or MAC address or the HID input device
+ * @return The value of the HID input device priority
+ * @throws Exception error from Bluetooth HidService
+ */
+ @Rpc(description = "Get priority of the profile")
+ public Integer bluetoothHidGetPriority(
@RpcParameter(name = "deviceID",
description = "Name or MAC address of a bluetooth device.")
String deviceID) throws Exception {
- BluetoothDevice device = BluetoothFacade.getDevice(sHidProfile.getConnectedDevices(),
+ BluetoothDevice device = BluetoothFacade.getDevice(sHidProfile.getConnectedDevices(),
deviceID);
- return sHidProfile.getPriority(device);
- }
-
- /**
- * Sends the Set_Protocol_Mode command to the given connected HID input device.
- * @param deviceID name or MAC address or the HID input device
- * @param protocolMode protocol mode
- * @return True if successfully sent the command; otherwise false
- * @throws Exception error from Bluetooth HidService
- */
- @Rpc(description = "Send Set_Protocol_Mode command to the connected HID input device.")
- public Boolean bluetoothHidSetProtocolMode(
+ return sHidProfile.getPriority(device);
+ }
+
+ /**
+ * Sends the Set_Protocol_Mode command to the given connected HID input device.
+ * @param deviceID name or MAC address or the HID input device
+ * @param protocolMode protocol mode
+ * @return True if successfully sent the command; otherwise false
+ * @throws Exception error from Bluetooth HidService
+ */
+ @Rpc(description = "Send Set_Protocol_Mode command to the connected HID input device.")
+ public Boolean bluetoothHidSetProtocolMode(
@RpcParameter(name = "deviceID",
description = "Name or MAC address of a bluetooth device.")
String deviceID,
@RpcParameter(name = "protocolMode")
Integer protocolMode) throws Exception {
- BluetoothDevice device = BluetoothFacade.getDevice(sHidProfile.getConnectedDevices(),
+ BluetoothDevice device = BluetoothFacade.getDevice(sHidProfile.getConnectedDevices(),
deviceID);
- return sHidProfile.setProtocolMode(device, protocolMode);
- }
-
- /**
- * Sends the Get_Protocol_Mode command to the given connected HID input device.
- * @param deviceID name or MAC address or the HID input device
- * @return True if successfully sent the command; otherwise false
- * @throws Exception error from Bluetooth HidService
- */
- @Rpc(description = "Send Get_Protocol_Mode command to the connected HID input device.")
- public Boolean bluetoothHidGetProtocolMode(
+ return sHidProfile.setProtocolMode(device, protocolMode);
+ }
+
+ /**
+ * Sends the Get_Protocol_Mode command to the given connected HID input device.
+ * @param deviceID name or MAC address or the HID input device
+ * @return True if successfully sent the command; otherwise false
+ * @throws Exception error from Bluetooth HidService
+ */
+ @Rpc(description =
+ "Send Get_Protocol_Mode command to the connected HID input device.")
+ public Boolean bluetoothHidGetProtocolMode(
@RpcParameter(name = "deviceID",
description = "Name or MAC address of a bluetooth device.")
String deviceID) throws Exception {
- BluetoothDevice device = BluetoothFacade.getDevice(sHidProfile.getConnectedDevices(),
- deviceID);
- return sHidProfile.getProtocolMode(device);
- }
-
- /**
- * Sends the Set_Idle_Time command to the given connected HID input device.
- * @param deviceID name or MAC address or the HID input device
- * @param idleTime idle time
- * @return True if successfully sent the command; otherwise false
- * @throws Exception error from Bluetooth HidService
- */
- @Rpc(description = "Send Set_Idle_Time command to the connected HID input device.")
- public Boolean bluetoothHidSetIdleTime(
- @RpcParameter(name = "deviceID",
- description = "Name or MAC address of a bluetooth device.")
- String deviceID,
- @RpcParameter(name = "idleTime")
- Integer idleTime) throws Exception {
- BluetoothDevice device = BluetoothFacade.getDevice(sHidProfile.getConnectedDevices(),
- deviceID);
- return sHidProfile.setIdleTime(device, (byte) (int) idleTime);
- }
-
- /**
- * Sends the Get_Idle_Time command to the given connected HID input device.
- * @param deviceID name or MAC address or the HID input device
- * @return True if successfully sent the command; otherwise false
- * @throws Exception error from Bluetooth HidService
- */
- @Rpc(description = "Send Get_Idle_Time command to the connected HID input device.")
- public Boolean bluetoothHidGetIdleTime(
- @RpcParameter(name = "deviceID",
+ BluetoothDevice device = BluetoothFacade.getDevice(
+ sHidProfile.getConnectedDevices(), deviceID);
+ return sHidProfile.getProtocolMode(device);
+ }
+
+ /**
+ * Sends the Set_Idle_Time command to the given connected HID input device.
+ * @param deviceID name or MAC address or the HID input device
+ * @param idleTime idle time
+ * @return True if successfully sent the command; otherwise false
+ * @throws Exception error from Bluetooth HidService
+ */
+ @Rpc(description = "Send Set_Idle_Time command to the connected HID input device.")
+ public Boolean bluetoothHidSetIdleTime(
+ @RpcParameter(name = "deviceID",
+ description = "Name or MAC address of a bluetooth device.")
+ String deviceID,
+ @RpcParameter(name = "idleTime")
+ Integer idleTime) throws Exception {
+ BluetoothDevice device = BluetoothFacade.getDevice(
+ sHidProfile.getConnectedDevices(), deviceID);
+ return sHidProfile.setIdleTime(
+ device, (byte) (int) idleTime);
+ }
+
+ /**
+ * Sends the Get_Idle_Time command to the given connected HID input device.
+ * @param deviceID name or MAC address or the HID input device
+ * @return True if successfully sent the command; otherwise false
+ * @throws Exception error from Bluetooth HidService
+ */
+ @Rpc(description = "Send Get_Idle_Time command to the connected HID input device.")
+ public Boolean bluetoothHidGetIdleTime(
+ @RpcParameter(name = "deviceID",
description = "Name or MAC address of a bluetooth device.")
String deviceID) throws Exception {
- BluetoothDevice device = BluetoothFacade.getDevice(sHidProfile.getConnectedDevices(),
- deviceID);
- return sHidProfile.getIdleTime(device);
- }
-
- @Rpc(description = "Test byte transfer.")
- public byte[] testByte() {
- byte[] bts = {0b01,0b10,0b11,0b100};
- return bts;
- }
-
- @Override
- public void shutdown() {
- }
-}
+ BluetoothDevice device = BluetoothFacade.getDevice(
+ sHidProfile.getConnectedDevices(), deviceID);
+ return sHidProfile.getIdleTime(device);
+ }
+
+ /**
+ * Test byte transfer.
+ */
+ @Rpc(description = "Test byte transfer.")
+ public byte[] testByte() {
+ byte[] bts = {0b01, 0b10, 0b11, 0b100};
+ return bts;
+ }
+ @Override
+ public void shutdown() {
+ }
+}
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothHspFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothHspFacade.java
index 0af2b9c5..d8abfae7 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothHspFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothHspFacade.java
@@ -33,218 +33,325 @@ import com.googlecode.android_scripting.rpc.RpcParameter;
import java.util.List;
public class BluetoothHspFacade extends RpcReceiver {
- static final ParcelUuid[] UUIDS = {
- BluetoothUuid.HSP, BluetoothUuid.Handsfree
- };
+ static final ParcelUuid[] UUIDS = {
+ BluetoothUuid.HSP, BluetoothUuid.Handsfree
+ };
- private final Service mService;
- private final BluetoothAdapter mBluetoothAdapter;
+ private final Service mService;
+ private final BluetoothAdapter mBluetoothAdapter;
- private static boolean sIsHspReady = false;
- private static BluetoothHeadset sHspProfile = null;
+ private static boolean sIsHspReady = false;
+ private static BluetoothHeadset sHspProfile = null;
- public BluetoothHspFacade(FacadeManager manager) {
- super(manager);
- mService = manager.getService();
- mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
- mBluetoothAdapter.getProfileProxy(mService, new HspServiceListener(),
- BluetoothProfile.HEADSET);
- }
+ public BluetoothHspFacade(FacadeManager manager) {
+ super(manager);
+ mService = manager.getService();
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ mBluetoothAdapter.getProfileProxy(mService, new HspServiceListener(),
+ BluetoothProfile.HEADSET);
+ }
- class HspServiceListener implements BluetoothProfile.ServiceListener {
- @Override
- public void onServiceConnected(int profile, BluetoothProfile proxy) {
- sHspProfile = (BluetoothHeadset) proxy;
- sIsHspReady = true;
+ class HspServiceListener implements BluetoothProfile.ServiceListener {
+ @Override
+ public void onServiceConnected(int profile, BluetoothProfile proxy) {
+ sHspProfile = (BluetoothHeadset) proxy;
+ sIsHspReady = true;
+ }
+
+ @Override
+ public void onServiceDisconnected(int profile) {
+ sIsHspReady = false;
+ }
+ }
+
+ /**
+ * Connect to Hsp Profile
+ * @param device - the BluetoothDevice object to connect to.
+ * @return if the connection was successfull or not.
+ */
+ public Boolean hspConnect(BluetoothDevice device) {
+ if (sHspProfile == null) return false;
+ return sHspProfile.connect(device);
+ }
+
+ /**
+ * Disconnect to Hsp Profile.
+ * @param device - the Bluetooth Device object to disconnect from.
+ * @return if the disconnection was successfull or not.
+ */
+ public Boolean hspDisconnect(BluetoothDevice device) {
+ if (sHspProfile == null) return false;
+ return sHspProfile.disconnect(device);
+ }
+
+ /**
+ * Is Hsp profile ready.
+ * @return if Hid profile is ready or not.
+ */
+ @Rpc(description = "Is Hsp profile ready.")
+ public Boolean bluetoothHspIsReady() {
+ return sIsHspReady;
+ }
+
+ /**
+ * Set priority of the profile.
+ * @param deviceStr - name or MAC address of a Bluetooth device.
+ * @param priority - Priority that needs to be set.
+ */
+ @Rpc(description = "Set priority of the profile.")
+ public void bluetoothHspSetPriority(
+ @RpcParameter(name = "device", description = "Mac address of a BT device.")
+ String deviceStr,
+ @RpcParameter(name = "priority", description = "Priority that needs to be set.")
+ Integer priority) throws Exception {
+ if (sHspProfile == null) return;
+ BluetoothDevice device = BluetoothFacade.getDevice(
+ mBluetoothAdapter.getBondedDevices(), deviceStr);
+ Log.d("Changing priority of device " + device.getAliasName() + " p: " + priority);
+ sHspProfile.setPriority(device, priority);
+ }
+
+ /**
+ * Connect to an HSP device.
+ * @param device - Name or MAC address of a bluetooth device.
+ * @return True if the connection was successful; otherwise False.
+ */
+ @Rpc(description = "Connect to an HSP device.")
+ public Boolean bluetoothHspConnect(
+ @RpcParameter(name = "device", description =
+ "Name or MAC address of a bluetooth device.")
+ String device) throws Exception {
+ if (sHspProfile == null) return false;
+ BluetoothDevice mDevice = BluetoothFacade.getDevice(
+ mBluetoothAdapter.getBondedDevices(), device);
+ Log.d("Connecting to device " + mDevice.getAliasName());
+ return hspConnect(mDevice);
+ }
+
+ /**
+ * Disconnect an HSP device.
+ * @param device - Name or MAC address of a bluetooth device.
+ * @return True if the disconnection was successful; otherwise False.
+ */
+ @Rpc(description = "Disconnect an HSP device.")
+ public Boolean bluetoothHspDisconnect(
+ @RpcParameter(name = "device", description = "Name or MAC address of a device.")
+ String device) throws Exception {
+ if (sHspProfile == null) return false;
+ Log.d("Connected devices: " + sHspProfile.getConnectedDevices());
+ BluetoothDevice mDevice = BluetoothFacade.getDevice(
+ sHspProfile.getConnectedDevices(), device);
+ return hspDisconnect(mDevice);
+ }
+
+ /**
+ * Get all the devices connected through HSP.
+ * @return List of all the devices connected through HSP.
+ */
+ @Rpc(description = "Get all the devices connected through HSP.")
+ public List<BluetoothDevice> bluetoothHspGetConnectedDevices() {
+ if (!sIsHspReady) return null;
+ return sHspProfile.getConnectedDevices();
+ }
+
+ /**
+ * Get the connection status of a device.
+ * @param deviceID - Name or MAC address of a bluetooth device.
+ * @return connection status of a device.
+ */
+ @Rpc(description = "Get the connection status of a device.")
+ public Integer bluetoothHspGetConnectionStatus(
+ @RpcParameter(name = "deviceID",
+ description = "Name or MAC address of a bluetooth device.")
+ String deviceID) {
+ if (sHspProfile == null) {
+ return BluetoothProfile.STATE_DISCONNECTED;
+ }
+ List<BluetoothDevice> deviceList = sHspProfile.getConnectedDevices();
+ BluetoothDevice device;
+ try {
+ device = BluetoothFacade.getDevice(deviceList, deviceID);
+ } catch (Exception e) {
+ return BluetoothProfile.STATE_DISCONNECTED;
+ }
+ return sHspProfile.getConnectionState(device);
+ }
+
+ /**
+ * Force SCO audio on DUT, ignore all other restrictions
+ *
+ * @param force True to force SCO audio, False to resume normal
+ * @return True if the setup is successful
+ */
+ @Rpc(description = "Force SCO audio connection on DUT.")
+ public Boolean bluetoothHspForceScoAudio(
+ @RpcParameter(name = "force", description = "whether to force SCO audio")
+ Boolean force) {
+ if (sHspProfile == null) {
+ return false;
+ }
+ sHspProfile.setForceScoAudio(force);
+ return true;
+ }
+
+ /**
+ * Connect SCO audio to a remote device
+ *
+ * @param deviceAddress the Bluetooth MAC address of remote device
+ * @return True if connection is successful, False otherwise
+ */
+ @Rpc(description = "Connect SCO audio for a remote device.")
+ public Boolean bluetoothHspConnectAudio(
+ @RpcParameter(name = "deviceAddress",
+ description = "MAC address of a bluetooth device.")
+ String deviceAddress) {
+ if (sHspProfile == null) {
+ return false;
+ }
+ Log.d("Connected devices: " + sHspProfile.getConnectedDevices());
+ BluetoothDevice device = null;
+ if (sHspProfile.getConnectedDevices().size() > 1) {
+ Log.d("More than one device available");
+ }
+ try {
+ device = BluetoothFacade.getDevice(
+ sHspProfile.getConnectedDevices(), deviceAddress);
+ } catch (Exception e) {
+ Log.d("Cannot find device " + deviceAddress);
+ return false;
+ }
+ return sHspProfile.connectAudio();
+ }
+
+ /**
+ * Disconnect SCO audio for a remote device
+ *
+ * @param deviceAddress the Bluetooth MAC address of remote device
+ * @return True if disconnection is successful, False otherwise
+ */
+ @Rpc(description = "Disconnect SCO audio for a remote device")
+ public Boolean bluetoothHspDisconnectAudio(
+ @RpcParameter(name = "deviceAddress",
+ description = "MAC address of a bluetooth device.")
+ String deviceAddress) {
+ if (sHspProfile == null) {
+ return false;
+ }
+ Log.d("Connected devices: " + sHspProfile.getConnectedDevices());
+ BluetoothDevice device = null;
+ if (sHspProfile.getConnectedDevices().size() > 1) {
+ Log.d("More than one device available");
+ }
+ try {
+ device = BluetoothFacade.getDevice(
+ sHspProfile.getConnectedDevices(), deviceAddress);
+ } catch (Exception e) {
+ Log.d("Cannot find device " + deviceAddress);
+ return false;
+ }
+ if (!sHspProfile.isAudioConnected(device)) {
+ Log.d("SCO audio is not connected for device " + deviceAddress);
+ return false;
+ }
+ return sHspProfile.disconnectAudio();
+ }
+
+ /**
+ * Check if SCO audio is connected for a remote device
+ *
+ * @param deviceAddress the Bluetooth MAC address of remote device
+ * @return True if device is connected to us via SCO audio, False otherwise
+ */
+ @Rpc(description = "Check if SCO audio is connected for a remote device")
+ public Boolean bluetoothHspIsAudioConnected(
+ @RpcParameter(name = "deviceAddress",
+ description = "MAC address of a bluetooth device.")
+ String deviceAddress) {
+ if (sHspProfile == null) {
+ return false;
+ }
+ Log.d("Connected devices: " + sHspProfile.getConnectedDevices());
+ BluetoothDevice device = null;
+ if (sHspProfile.getConnectedDevices().size() > 1) {
+ Log.d("More than one device available");
+ }
+ try {
+ device = BluetoothFacade.getDevice(
+ sHspProfile.getConnectedDevices(), deviceAddress);
+ } catch (Exception e) {
+ Log.d("Cannot find device " + deviceAddress);
+ return false;
+ }
+ return sHspProfile.isAudioConnected(device);
+ }
+
+ /**
+ * Start voice recognition. Send BVRA command.
+ *
+ * @param deviceAddress the Bluetooth MAC address of remote device
+ * @return True if started successfully, False otherwise.
+ */
+ @Rpc(description = "Start Voice Recognition.")
+ public Boolean bluetoothHspStartVoiceRecognition(
+ @RpcParameter(name = "deviceAddress",
+ description = "MAC address of a bluetooth device.")
+ String deviceAddress) throws Exception {
+ BluetoothDevice device = BluetoothFacade.getDevice(
+ sHspProfile.getConnectedDevices(), deviceAddress);
+ return sHspProfile.startVoiceRecognition(device);
+ }
+
+ /**
+ * Stop voice recognition. Send BVRA command.
+ *
+ * @param deviceAddress the Bluetooth MAC address of remote device
+ * @return True if stopped successfully, False otherwise.
+ */
+ @Rpc(description = "Stop Voice Recognition.")
+ public Boolean bluetoothHspStopVoiceRecognition(
+ @RpcParameter(name = "deviceAddress",
+ description = "MAC address of a bluetooth device.")
+ String deviceAddress) throws Exception {
+ BluetoothDevice device = BluetoothFacade.getDevice(
+ sHspProfile.getConnectedDevices(), deviceAddress);
+ return sHspProfile.stopVoiceRecognition(device);
+ }
+
+ /**
+ * Determine whether in-band ringtone is enabled or not.
+ *
+ * @return True if enabled, False otherwise.
+ */
+ @Rpc(description = "In-band ringtone enabled check.")
+ public Boolean bluetoothHspIsInbandRingingEnabled() {
+ return sHspProfile.isInbandRingingEnabled();
+ }
+
+ /**
+ * Send a CLCC response from Sl4a (experimental).
+ *
+ * @param index the index of the call
+ * @param direction the direction of the call
+ * @param status the status of the call
+ * @param mode the mode
+ * @param mpty the mpty value
+ * @param number the phone number
+ * @param type the type
+ */
+ @Rpc(description = "Send generic clcc response.")
+ public void bluetoothHspClccResponse(
+ @RpcParameter(name = "index", description = "") Integer index,
+ @RpcParameter(name = "direction", description = "") Integer direction,
+ @RpcParameter(name = "status", description = "") Integer status,
+ @RpcParameter(name = "mode", description = "") Integer mode,
+ @RpcParameter(name = "mpty", description = "") Boolean mpty,
+ @RpcParameter(name = "number", description = "") String number,
+ @RpcParameter(name = "type", description = "") Integer type
+ ) {
+ sHspProfile.clccResponse(index, direction, status, mode, mpty, number, type);
}
@Override
- public void onServiceDisconnected(int profile) {
- sIsHspReady = false;
- }
- }
-
- public Boolean hspConnect(BluetoothDevice device) {
- if (sHspProfile == null) return false;
- return sHspProfile.connect(device);
- }
-
- public Boolean hspDisconnect(BluetoothDevice device) {
- if (sHspProfile == null) return false;
- return sHspProfile.disconnect(device);
- }
-
- @Rpc(description = "Is Hsp profile ready.")
- public Boolean bluetoothHspIsReady() {
- return sIsHspReady;
- }
-
- @Rpc(description = "Set priority of the profile")
- public void bluetoothHspSetPriority(
- @RpcParameter(name = "device", description = "Mac address of a BT device.")
- String deviceStr,
- @RpcParameter(name = "priority", description = "Priority that needs to be set.")
- Integer priority)
- throws Exception {
- if (sHspProfile == null) return;
- BluetoothDevice device =
- BluetoothFacade.getDevice(mBluetoothAdapter.getBondedDevices(), deviceStr);
- Log.d("Changing priority of device " + device.getAliasName() + " p: " + priority);
- sHspProfile.setPriority(device, priority);
- }
-
- @Rpc(description = "Connect to an HSP device.")
- public Boolean bluetoothHspConnect(
- @RpcParameter(name = "device", description = "Name or MAC address of a bluetooth device.")
- String device)
- throws Exception {
- if (sHspProfile == null)
- return false;
- BluetoothDevice mDevice = BluetoothFacade.getDevice(BluetoothFacade.DiscoveredDevices, device);
- Log.d("Connecting to device " + mDevice.getAliasName());
- return hspConnect(mDevice);
- }
-
- @Rpc(description = "Disconnect an HSP device.")
- public Boolean bluetoothHspDisconnect(
- @RpcParameter(name = "device", description = "Name or MAC address of a device.")
- String device)
- throws Exception {
- if (sHspProfile == null)
- return false;
- Log.d("Connected devices: " + sHspProfile.getConnectedDevices());
- BluetoothDevice mDevice = BluetoothFacade.getDevice(sHspProfile.getConnectedDevices(),
- device);
- return hspDisconnect(mDevice);
- }
-
- @Rpc(description = "Get all the devices connected through HSP.")
- public List<BluetoothDevice> bluetoothHspGetConnectedDevices() {
- while (!sIsHspReady);
- return sHspProfile.getConnectedDevices();
- }
-
- @Rpc(description = "Get the connection status of a device.")
- public Integer bluetoothHspGetConnectionStatus(
- @RpcParameter(name = "deviceID",
- description = "Name or MAC address of a bluetooth device.")
- String deviceID) {
- if (sHspProfile == null) {
- return BluetoothProfile.STATE_DISCONNECTED;
- }
- List<BluetoothDevice> deviceList = sHspProfile.getConnectedDevices();
- BluetoothDevice device;
- try {
- device = BluetoothFacade.getDevice(deviceList, deviceID);
- } catch (Exception e) {
- return BluetoothProfile.STATE_DISCONNECTED;
- }
- return sHspProfile.getConnectionState(device);
- }
-
- /**
- * Force SCO audio on DUT, ignore all other restrictions
- *
- * @param force True to force SCO audio, False to resume normal
- * @return True if the setup is successful
- */
- @Rpc(description = "Force SCO audio connection on DUT")
- public Boolean bluetoothHspForceScoAudio(
- @RpcParameter(name = "force", description = "whether to force SCO audio")
- Boolean force) {
- if (sHspProfile == null) {
- return false;
- }
- sHspProfile.setForceScoAudio(force);
- return true;
- }
-
- /**
- * Connect SCO audio to a remote device
- *
- * @param deviceAddress the Bluetooth MAC address of remote device
- * @return True if connection is successful, False otherwise
- */
- @Rpc(description = "Connect SCO audio for a remote device")
- public Boolean bluetoothHspConnectAudio(
- @RpcParameter(name = "deviceAddress", description = "MAC address of a bluetooth device.")
- String deviceAddress) {
- if (sHspProfile == null) {
- return false;
- }
- Log.d("Connected devices: " + sHspProfile.getConnectedDevices());
- BluetoothDevice device = null;
- if (sHspProfile.getConnectedDevices().size() > 1) {
- Log.d("More than one device available");
- }
- try {
- device = BluetoothFacade.getDevice(sHspProfile.getConnectedDevices(), deviceAddress);
- } catch (Exception e) {
- Log.d("Cannot find device " + deviceAddress);
- return false;
- }
- return sHspProfile.connectAudio();
- }
-
- /**
- * Disconnect SCO audio for a remote device
- *
- * @param deviceAddress the Bluetooth MAC address of remote device
- * @return True if disconnection is successful, False otherwise
- */
- @Rpc(description = "Disconnect SCO audio for a remote device")
- public Boolean bluetoothHspDisconnectAudio(
- @RpcParameter(name = "deviceAddress", description = "MAC address of a bluetooth device.")
- String deviceAddress) {
- if (sHspProfile == null) {
- return false;
- }
- Log.d("Connected devices: " + sHspProfile.getConnectedDevices());
- BluetoothDevice device = null;
- if (sHspProfile.getConnectedDevices().size() > 1) {
- Log.d("More than one device available");
- }
- try {
- device = BluetoothFacade.getDevice(sHspProfile.getConnectedDevices(), deviceAddress);
- } catch (Exception e) {
- Log.d("Cannot find device " + deviceAddress);
- return false;
- }
- if (!sHspProfile.isAudioConnected(device)) {
- Log.d("SCO audio is not connected for device " + deviceAddress);
- return false;
- }
- return sHspProfile.disconnectAudio();
- }
-
- /**
- * Check if SCO audio is connected for a remote device
- *
- * @param deviceAddress the Bluetooth MAC address of remote device
- * @return True if device is connected to us via SCO audio, False otherwise
- */
- @Rpc(description = "Check if SCO audio is connected for a remote device")
- public Boolean bluetoothHspIsAudioConnected(
- @RpcParameter(name = "deviceAddress", description = "MAC address of a bluetooth device.")
- String deviceAddress) {
- if (sHspProfile == null) {
- return false;
- }
- Log.d("Connected devices: " + sHspProfile.getConnectedDevices());
- BluetoothDevice device = null;
- if (sHspProfile.getConnectedDevices().size() > 1) {
- Log.d("More than one device available");
- }
- try {
- device = BluetoothFacade.getDevice(sHspProfile.getConnectedDevices(), deviceAddress);
- } catch (Exception e) {
- Log.d("Cannot find device " + deviceAddress);
- return false;
- }
- return sHspProfile.isAudioConnected(device);
- }
-
- @Override
- public void shutdown() {
- }
+ public void shutdown() {
+ }
}
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeAdvertiseFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeAdvertiseFacade.java
index 521c517a..d18dc56b 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeAdvertiseFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeAdvertiseFacade.java
@@ -73,7 +73,8 @@ public class BluetoothLeAdvertiseFacade extends RpcReceiver {
mAdvertiseDataList = new HashMap<Integer, AdvertiseData>();
mAdvertiseSettingsList = new HashMap<Integer, AdvertiseSettings>();
mAdvertiseDataBuilder = new Builder();
- mAdvertiseSettingsBuilder = new android.bluetooth.le.AdvertiseSettings.Builder();
+ mAdvertiseSettingsBuilder =
+ new android.bluetooth.le.AdvertiseSettings.Builder();
}
/**
@@ -96,7 +97,8 @@ public class BluetoothLeAdvertiseFacade extends RpcReceiver {
*
* @return index
*/
- @Rpc(description = "Constructs a new Builder obj for AdvertiseData and returns its index")
+ @Rpc(description =
+ "Constructs a new Builder obj for AdvertiseData and returns its index")
public Integer bleBuildAdvertiseData() {
BleAdvertiseDataCount += 1;
int index = BleAdvertiseDataCount;
@@ -111,13 +113,15 @@ public class BluetoothLeAdvertiseFacade extends RpcReceiver {
*
* @return index
*/
- @Rpc(description = "Constructs a new Builder obj for AdvertiseData and returns its index")
+ @Rpc(description =
+ "Constructs a new Builder obj for AdvertiseData and returns its index")
public Integer bleBuildAdvertiseSettings() {
BleAdvertiseSettingsCount += 1;
int index = BleAdvertiseSettingsCount;
mAdvertiseSettingsList.put(index,
mAdvertiseSettingsBuilder.build());
- mAdvertiseSettingsBuilder = new android.bluetooth.le.AdvertiseSettings.Builder();
+ mAdvertiseSettingsBuilder =
+ new android.bluetooth.le.AdvertiseSettings.Builder();
return index;
}
@@ -136,7 +140,8 @@ public class BluetoothLeAdvertiseFacade extends RpcReceiver {
mAdvertise.stopAdvertising(mAdvertiseCallbackList
.get(index));
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -162,25 +167,29 @@ public class BluetoothLeAdvertiseFacade extends RpcReceiver {
if (mAdvertiseDataList.get(dataIndex) != null) {
mData = mAdvertiseDataList.get(dataIndex);
} else {
- throw new Exception("Invalid dataIndex input:" + Integer.toString(dataIndex));
+ throw new Exception("Invalid dataIndex input:"
+ + Integer.toString(dataIndex));
}
if (mAdvertiseSettingsList.get(settingsIndex) != null) {
mSettings = mAdvertiseSettingsList.get(settingsIndex);
} else {
- throw new Exception("Invalid settingsIndex input:" + Integer.toString(settingsIndex));
+ throw new Exception("Invalid settingsIndex input:"
+ + Integer.toString(settingsIndex));
}
if (mAdvertiseCallbackList.get(callbackIndex) != null) {
Log.d("bluetooth_le starting a background advertisement on callback index: "
+ Integer.toString(callbackIndex));
- mAdvertise
- .startAdvertising(mSettings, mData, mAdvertiseCallbackList.get(callbackIndex));
+ mAdvertise.startAdvertising(
+ mSettings, mData, mAdvertiseCallbackList.get(callbackIndex));
} else {
- throw new Exception("Invalid callbackIndex input" + Integer.toString(callbackIndex));
+ throw new Exception("Invalid callbackIndex input"
+ + Integer.toString(callbackIndex));
}
}
/**
- * Starts ble advertising with a scanResponse. ScanResponses are created in the same way
+ * Starts ble advertising with a scanResponse. ScanResponses are created in
+ * the same way
* AdvertiseData is created since they share the same object type.
*
* @param callbackIndex The advertisementCallback index
@@ -207,12 +216,14 @@ public class BluetoothLeAdvertiseFacade extends RpcReceiver {
if (mAdvertiseDataList.get(dataIndex) != null) {
mData = mAdvertiseDataList.get(dataIndex);
} else {
- throw new Exception("Invalid dataIndex input:" + Integer.toString(dataIndex));
+ throw new Exception("Invalid dataIndex input:"
+ + Integer.toString(dataIndex));
}
if (mAdvertiseSettingsList.get(settingsIndex) != null) {
mSettings = mAdvertiseSettingsList.get(settingsIndex);
} else {
- throw new Exception("Invalid settingsIndex input:" + Integer.toString(settingsIndex));
+ throw new Exception("Invalid settingsIndex input:"
+ + Integer.toString(settingsIndex));
}
if (mAdvertiseDataList.get(scanResponseIndex) != null) {
mScanResponse = mAdvertiseDataList.get(scanResponseIndex);
@@ -227,7 +238,8 @@ public class BluetoothLeAdvertiseFacade extends RpcReceiver {
.startAdvertising(mSettings, mData, mScanResponse,
mAdvertiseCallbackList.get(callbackIndex));
} else {
- throw new Exception("Invalid callbackIndex input" + Integer.toString(callbackIndex));
+ throw new Exception("Invalid callbackIndex input"
+ + Integer.toString(callbackIndex));
}
}
@@ -246,7 +258,8 @@ public class BluetoothLeAdvertiseFacade extends RpcReceiver {
AdvertiseSettings mSettings = mAdvertiseSettingsList.get(index);
return mSettings.getMode();
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -304,7 +317,8 @@ public class BluetoothLeAdvertiseFacade extends RpcReceiver {
AdvertiseData mData = mAdvertiseDataList.get(index);
return mData.getIncludeTxPowerLevel();
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -327,10 +341,12 @@ public class BluetoothLeAdvertiseFacade extends RpcReceiver {
if (mData.getManufacturerSpecificData() != null) {
return mData.getManufacturerSpecificData().get(manufacturerId);
} else {
- throw new Exception("Invalid manufacturerId input:" + Integer.toString(manufacturerId));
+ throw new Exception("Invalid manufacturerId input:"
+ + Integer.toString(manufacturerId));
}
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -350,7 +366,8 @@ public class BluetoothLeAdvertiseFacade extends RpcReceiver {
AdvertiseData mData = mAdvertiseDataList.get(index);
return mData.getIncludeDeviceName();
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -377,7 +394,8 @@ public class BluetoothLeAdvertiseFacade extends RpcReceiver {
throw new Exception("Invalid serviceUuid input:" + serviceUuid);
}
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -396,7 +414,8 @@ public class BluetoothLeAdvertiseFacade extends RpcReceiver {
AdvertiseData mData = mAdvertiseDataList.get(index);
return mData.getServiceUuids();
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -498,8 +517,8 @@ public class BluetoothLeAdvertiseFacade extends RpcReceiver {
/**
* Set ble advertisement data include tx power level
*
- * @param includeTxPowerLevel boolean whether to include the tx power level or not in the
- * advertisement
+ * @param includeTxPowerLevel boolean whether to include the tx
+ * power level or not in the advertisement
*/
@Rpc(description = "Set ble advertisement data include tx power level")
public void bleSetAdvertiseDataIncludeTxPowerLevel(
@@ -525,8 +544,8 @@ public class BluetoothLeAdvertiseFacade extends RpcReceiver {
/**
* Set ble advertisement data include device name
*
- * @param includeDeviceName boolean whether to include device name or not in the
- * advertisement
+ * @param includeDeviceName boolean whether to include device name or
+ * not in the advertisement
*/
@Rpc(description = "Set ble advertisement data include device name")
public void bleSetAdvertiseDataIncludeDeviceName(
@@ -553,22 +572,28 @@ public class BluetoothLeAdvertiseFacade extends RpcReceiver {
+ index);
mResults.putString("Type", "onSuccess");
mResults.putParcelable("SettingsInEffect", settingsInEffect);
- mEventFacade.postEvent(mEventType + index + "onSuccess", mResults.clone());
+ mEventFacade.postEvent(mEventType + index
+ + "onSuccess", mResults.clone());
mResults.clear();
}
@Override
public void onStartFailure(int errorCode) {
String errorString = "UNKNOWN_ERROR_CODE";
- if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_ALREADY_STARTED) {
+ if (errorCode
+ == AdvertiseCallback.ADVERTISE_FAILED_ALREADY_STARTED) {
errorString = "ADVERTISE_FAILED_ALREADY_STARTED";
- } else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_DATA_TOO_LARGE) {
+ } else if (errorCode
+ == AdvertiseCallback.ADVERTISE_FAILED_DATA_TOO_LARGE) {
errorString = "ADVERTISE_FAILED_DATA_TOO_LARGE";
- } else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_FEATURE_UNSUPPORTED) {
+ } else if (errorCode
+ == AdvertiseCallback.ADVERTISE_FAILED_FEATURE_UNSUPPORTED) {
errorString = "ADVERTISE_FAILED_FEATURE_UNSUPPORTED";
- } else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR) {
+ } else if (errorCode
+ == AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR) {
errorString = "ADVERTISE_FAILED_INTERNAL_ERROR";
- } else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_TOO_MANY_ADVERTISERS) {
+ } else if (errorCode
+ == AdvertiseCallback.ADVERTISE_FAILED_TOO_MANY_ADVERTISERS) {
errorString = "ADVERTISE_FAILED_TOO_MANY_ADVERTISERS";
}
Log.d("bluetooth_le_advertisement onFailure " + mEventType + " "
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeScanFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeScanFacade.java
index ba92ab94..06f22168 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeScanFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeScanFacade.java
@@ -226,7 +226,8 @@ public class BluetoothLeScanFacade extends RpcReceiver {
+ Integer.toString(scanSettingsIndex));
}
if (mScanCallbackList.get(callbackIndex) != null) {
- mScanner.startScan(mScanFilters, mScanSettings, mScanCallbackList.get(callbackIndex));
+ mScanner.startScan(mScanFilters, mScanSettings,
+ mScanCallbackList.get(callbackIndex));
} else {
throw new Exception("Invalid filterListIndex input:"
+ Integer.toString(filterListIndex));
@@ -247,7 +248,8 @@ public class BluetoothLeScanFacade extends RpcReceiver {
Log.d("bluetooth_le_scan starting a background scan");
boolean result = false;
if (mLeScanCallbackList.get(leCallbackIndex) != null) {
- result = mBluetoothAdapter.startLeScan(mLeScanCallbackList.get(leCallbackIndex));
+ result = mBluetoothAdapter.startLeScan(
+ mLeScanCallbackList.get(leCallbackIndex));
} else {
throw new Exception("Invalid leCallbackIndex input:"
+ Integer.toString(leCallbackIndex));
@@ -452,7 +454,8 @@ public class BluetoothLeScanFacade extends RpcReceiver {
ScanSettings mScanSettings = mScanSettingsList.get(index);
return mScanSettings.getScanResultType();
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -475,10 +478,12 @@ public class BluetoothLeScanFacade extends RpcReceiver {
return mScanFilterList.get(index)
.get(filterIndex).getManufacturerId();
} else {
- throw new Exception("Invalid filterIndex input:" + Integer.toString(filterIndex));
+ throw new Exception("Invalid filterIndex input:"
+ + Integer.toString(filterIndex));
}
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -498,12 +503,15 @@ public class BluetoothLeScanFacade extends RpcReceiver {
throws Exception {
if (mScanFilterList.get(index) != null) {
if (mScanFilterList.get(index).get(filterIndex) != null) {
- return mScanFilterList.get(index).get(filterIndex).getDeviceAddress();
+ return mScanFilterList.get(index).get(
+ filterIndex).getDeviceAddress();
} else {
- throw new Exception("Invalid filterIndex input:" + Integer.toString(filterIndex));
+ throw new Exception("Invalid filterIndex input:"
+ + Integer.toString(filterIndex));
}
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -523,12 +531,15 @@ public class BluetoothLeScanFacade extends RpcReceiver {
throws Exception {
if (mScanFilterList.get(index) != null) {
if (mScanFilterList.get(index).get(filterIndex) != null) {
- return mScanFilterList.get(index).get(filterIndex).getDeviceName();
+ return mScanFilterList.get(index).get(
+ filterIndex).getDeviceName();
} else {
- throw new Exception("Invalid filterIndex input:" + Integer.toString(filterIndex));
+ throw new Exception("Invalid filterIndex input:"
+ + Integer.toString(filterIndex));
}
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -548,12 +559,15 @@ public class BluetoothLeScanFacade extends RpcReceiver {
throws Exception {
if (mScanFilterList.get(index) != null) {
if (mScanFilterList.get(index).get(filterIndex) != null) {
- return mScanFilterList.get(index).get(filterIndex).getManufacturerData();
+ return mScanFilterList.get(index).get(
+ filterIndex).getManufacturerData();
} else {
- throw new Exception("Invalid filterIndex input:" + Integer.toString(filterIndex));
+ throw new Exception("Invalid filterIndex input:"
+ + Integer.toString(filterIndex));
}
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -573,12 +587,15 @@ public class BluetoothLeScanFacade extends RpcReceiver {
throws Exception {
if (mScanFilterList.get(index) != null) {
if (mScanFilterList.get(index).get(filterIndex) != null) {
- return mScanFilterList.get(index).get(filterIndex).getManufacturerDataMask();
+ return mScanFilterList.get(index).get(
+ filterIndex).getManufacturerDataMask();
} else {
- throw new Exception("Invalid filterIndex input:" + Integer.toString(filterIndex));
+ throw new Exception("Invalid filterIndex input:"
+ + Integer.toString(filterIndex));
}
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -598,12 +615,15 @@ public class BluetoothLeScanFacade extends RpcReceiver {
throws Exception {
if (mScanFilterList.get(index) != null) {
if (mScanFilterList.get(index).get(filterIndex) != null) {
- return mScanFilterList.get(index).get(filterIndex).getServiceData();
+ return mScanFilterList.get(index).get(
+ filterIndex).getServiceData();
} else {
- throw new Exception("Invalid filterIndex input:" + Integer.toString(filterIndex));
+ throw new Exception("Invalid filterIndex input:"
+ + Integer.toString(filterIndex));
}
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -623,12 +643,15 @@ public class BluetoothLeScanFacade extends RpcReceiver {
throws Exception {
if (mScanFilterList.get(index) != null) {
if (mScanFilterList.get(index).get(filterIndex) != null) {
- return mScanFilterList.get(index).get(filterIndex).getServiceDataMask();
+ return mScanFilterList.get(index).get(
+ filterIndex).getServiceDataMask();
} else {
- throw new Exception("Invalid filterIndex input:" + Integer.toString(filterIndex));
+ throw new Exception("Invalid filterIndex input:"
+ + Integer.toString(filterIndex));
}
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -648,17 +671,21 @@ public class BluetoothLeScanFacade extends RpcReceiver {
throws Exception {
if (mScanFilterList.get(index) != null) {
if (mScanFilterList.get(index).get(filterIndex) != null) {
- if (mScanFilterList.get(index).get(filterIndex).getServiceUuid() != null) {
- return mScanFilterList.get(index).get(filterIndex).getServiceUuid().toString();
+ if (mScanFilterList.get(index).get(
+ filterIndex).getServiceUuid() != null) {
+ return mScanFilterList.get(index).get(
+ filterIndex).getServiceUuid().toString();
} else {
throw new Exception("No Service Uuid set for filter:"
+ Integer.toString(filterIndex));
}
} else {
- throw new Exception("Invalid filterIndex input:" + Integer.toString(filterIndex));
+ throw new Exception("Invalid filterIndex input:"
+ + Integer.toString(filterIndex));
}
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -678,18 +705,22 @@ public class BluetoothLeScanFacade extends RpcReceiver {
throws Exception {
if (mScanFilterList.get(index) != null) {
if (mScanFilterList.get(index).get(filterIndex) != null) {
- if (mScanFilterList.get(index).get(filterIndex).getServiceUuidMask() != null) {
- return mScanFilterList.get(index).get(filterIndex).getServiceUuidMask()
+ if (mScanFilterList.get(index).get(
+ filterIndex).getServiceUuidMask() != null) {
+ return mScanFilterList.get(
+ index).get(filterIndex).getServiceUuidMask()
.toString();
} else {
throw new Exception("No Service Uuid Mask set for filter:"
+ Integer.toString(filterIndex));
}
} else {
- throw new Exception("Invalid filterIndex input:" + Integer.toString(filterIndex));
+ throw new Exception("Invalid filterIndex input:"
+ + Integer.toString(filterIndex));
}
} else {
- throw new Exception("Invalid index input:" + Integer.toString(index));
+ throw new Exception("Invalid index input:"
+ + Integer.toString(index));
}
}
@@ -708,8 +739,8 @@ public class BluetoothLeScanFacade extends RpcReceiver {
}
/**
- * Add filter "manufacturereDataId and/or manufacturerData" to existing ScanFilter
- *
+ * Add filter "manufacturereDataId and/or manufacturerData" to existing
+ * ScanFilter
* @param manufacturerDataId the manufacturer data id to filter against
* @param manufacturerDataMask the manufacturere data mask to filter against
* @throws Exception
@@ -742,13 +773,10 @@ public class BluetoothLeScanFacade extends RpcReceiver {
*/
@Rpc(description = "Add filter \"serviceData and serviceDataMask\" to existing ScanFilter ")
public void bleSetScanFilterServiceData(
- @RpcParameter(name = "serviceUuid")
- String serviceUuid,
- @RpcParameter(name = "serviceData")
- byte[] serviceData,
+ @RpcParameter(name = "serviceUuid") String serviceUuid,
+ @RpcParameter(name = "serviceData") byte[] serviceData,
@RpcParameter(name = "serviceDataMask")
- @RpcOptional
- byte[] serviceDataMask
+ @RpcOptional byte[] serviceDataMask
) {
if (serviceDataMask != null) {
mScanFilterBuilder
@@ -841,14 +869,17 @@ public class BluetoothLeScanFacade extends RpcReceiver {
String errorString = "UNKNOWN_ERROR_CODE";
if (errorCode == ScanCallback.SCAN_FAILED_ALREADY_STARTED) {
errorString = "SCAN_FAILED_ALREADY_STARTED";
- } else if (errorCode == ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED) {
+ } else if (errorCode
+ == ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED) {
errorString = "SCAN_FAILED_APPLICATION_REGISTRATION_FAILED";
- } else if (errorCode == ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED) {
+ } else if (errorCode
+ == ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED) {
errorString = "SCAN_FAILED_FEATURE_UNSUPPORTED";
} else if (errorCode == ScanCallback.SCAN_FAILED_INTERNAL_ERROR) {
errorString = "SCAN_FAILED_INTERNAL_ERROR";
}
- Log.d("bluetooth_le_scan change onScanFailed " + mEventType + " " + index + " error "
+ Log.d("bluetooth_le_scan change onScanFailed "
+ + mEventType + " " + index + " error "
+ errorString);
mResults.putInt("ID", index);
mResults.putString("Type", "onScanFailed");
@@ -861,12 +892,14 @@ public class BluetoothLeScanFacade extends RpcReceiver {
@Override
public void onScanResult(int callbackType, ScanResult result) {
- Log.d("bluetooth_le_scan change onUpdate " + mEventType + " " + index);
+ Log.d("bluetooth_le_scan change onUpdate "
+ + mEventType + " " + index);
mResults.putInt("ID", index);
mResults.putInt("CallbackType", callbackType);
mResults.putString("Type", "onScanResult");
mResults.putParcelable("Result", result);
- mEventFacade.postEvent(mEventType + index + "onScanResults", mResults.clone());
+ mEventFacade.postEvent(
+ mEventType + index + "onScanResults", mResults.clone());
mResults.clear();
}
@@ -877,7 +910,8 @@ public class BluetoothLeScanFacade extends RpcReceiver {
mResults.putInt("ID", index);
mResults.putString("Type", "onBatchScanResults");
mResults.putParcelableList("Results", results);
- mEventFacade.postEvent(mEventType + index + "onBatchScanResult", mResults.clone());
+ mEventFacade.postEvent(mEventType
+ + index + "onBatchScanResult", mResults.clone());
mResults.clear();
}
}
@@ -894,43 +928,45 @@ public class BluetoothLeScanFacade extends RpcReceiver {
}
@Override
- public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
+ public void onLeScan(
+ BluetoothDevice device, int rssi, byte[] scanRecord) {
Log.d("bluetooth_classic_le_scan " + mEventType + " " + index);
mResults.putParcelable("Device", device);
mResults.putInt("Rssi", rssi);
mResults.putByteArray("ScanRecord", scanRecord);
mResults.putString("Type", "onLeScan");
- mEventFacade.postEvent(mEventType + index + "onLeScan", mResults.clone());
+ mEventFacade.postEvent(mEventType
+ + index + "onLeScan", mResults.clone());
mResults.clear();
}
}
@Override
public void shutdown() {
- if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
- for (myScanCallback mScanCallback : mScanCallbackList.values()) {
- if (mScanCallback != null) {
- try {
- mBluetoothAdapter.getBluetoothLeScanner()
- .stopScan(mScanCallback);
- } catch (NullPointerException e) {
- Log.e("Failed to stop ble scan callback.", e);
- }
- }
- }
- for (myLeScanCallback mLeScanCallback : mLeScanCallbackList.values()) {
- if (mLeScanCallback != null) {
- try {
- mBluetoothAdapter.stopLeScan(mLeScanCallback);
- } catch (NullPointerException e) {
- Log.e("Failed to stop classic ble scan callback.", e);
- }
- }
- }
- }
- mScanCallbackList.clear();
- mScanFilterList.clear();
- mScanSettingsList.clear();
- mLeScanCallbackList.clear();
+ if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
+ for (myScanCallback mScanCallback : mScanCallbackList.values()) {
+ if (mScanCallback != null) {
+ try {
+ mBluetoothAdapter.getBluetoothLeScanner()
+ .stopScan(mScanCallback);
+ } catch (NullPointerException e) {
+ Log.e("Failed to stop ble scan callback.", e);
+ }
+ }
+ }
+ for (myLeScanCallback mLeScanCallback : mLeScanCallbackList.values()) {
+ if (mLeScanCallback != null) {
+ try {
+ mBluetoothAdapter.stopLeScan(mLeScanCallback);
+ } catch (NullPointerException e) {
+ Log.e("Failed to stop classic ble scan callback.", e);
+ }
+ }
+ }
+ }
+ mScanCallbackList.clear();
+ mScanFilterList.clear();
+ mScanSettingsList.clear();
+ mLeScanCallbackList.clear();
}
}
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMapClientFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMapClientFacade.java
index 0de2829f..36573d22 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMapClientFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMapClientFacade.java
@@ -72,12 +72,16 @@ public class BluetoothMapClientFacade extends RpcReceiver {
mEventFacade = manager.getReceiver(EventFacade.class);
mNotificationReceiver = new NotificationReceiver();
- mSendIntent = new Intent(BluetoothMapClient.ACTION_MESSAGE_SENT_SUCCESSFULLY);
- mDeliveryIntent = new Intent(BluetoothMapClient.ACTION_MESSAGE_DELIVERED_SUCCESSFULLY);
+ mSendIntent = new Intent(
+ BluetoothMapClient.ACTION_MESSAGE_SENT_SUCCESSFULLY);
+ mDeliveryIntent = new Intent(
+ BluetoothMapClient.ACTION_MESSAGE_DELIVERED_SUCCESSFULLY);
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(BluetoothMapClient.ACTION_MESSAGE_RECEIVED);
- intentFilter.addAction(BluetoothMapClient.ACTION_MESSAGE_SENT_SUCCESSFULLY);
- intentFilter.addAction(BluetoothMapClient.ACTION_MESSAGE_DELIVERED_SUCCESSFULLY);
+ intentFilter.addAction(
+ BluetoothMapClient.ACTION_MESSAGE_SENT_SUCCESSFULLY);
+ intentFilter.addAction(
+ BluetoothMapClient.ACTION_MESSAGE_DELIVERED_SUCCESSFULLY);
mService.registerReceiver(mNotificationReceiver, intentFilter);
Log.d("notification receiver registered");
}
@@ -107,34 +111,41 @@ public class BluetoothMapClientFacade extends RpcReceiver {
@Rpc(description = "Connect to an MAP MSE device.")
public Boolean bluetoothMapClientConnect(
- @RpcParameter(name = "device", description = "Name or MAC address of a bluetooth "
+ @RpcParameter(name = "device",
+ description = "Name or MAC address of a bluetooth "
+ "device.")
String device)
throws Exception {
if (sMapProfile == null) return false;
- BluetoothDevice mDevice = BluetoothFacade.getDevice(mBluetoothAdapter.getBondedDevices(),
- device);
+ BluetoothDevice mDevice = BluetoothFacade.getDevice(
+ mBluetoothAdapter.getBondedDevices(), device);
Log.d("Connecting to device " + mDevice.getAliasName());
return sMapProfile.connect(mDevice);
}
@Rpc(description = "Send a (text) message via bluetooth.")
public Boolean mapSendMessage(
- @RpcParameter(name = "deviceID", description = "Name or MAC address of a device.")
+ @RpcParameter(name = "deviceID",
+ description = "Name or MAC address of a device.")
String deviceID,
- @RpcParameter(name = "phoneNumbers", description = "Phone number of contact.")
+ @RpcParameter(name = "phoneNumbers",
+ description = "Phone number of contact.")
String[] phoneNumbers,
- @RpcParameter(name = "message", description = "Message to send.") String message) {
+ @RpcParameter(name = "message",
+ description = "Message to send.") String message) {
try {
BluetoothDevice device =
- BluetoothFacade.getDevice(sMapProfile.getConnectedDevices(), deviceID);
+ BluetoothFacade.getDevice(
+ sMapProfile.getConnectedDevices(), deviceID);
mSentIntent = PendingIntent.getBroadcast(mService, 0, mSendIntent,
PendingIntent.FLAG_ONE_SHOT);
- mDeliveredIntent = PendingIntent.getBroadcast(mService, 0, mDeliveryIntent,
+ mDeliveredIntent = PendingIntent.getBroadcast(
+ mService, 0, mDeliveryIntent,
PendingIntent.FLAG_ONE_SHOT);
Uri[] contacts = new Uri[phoneNumbers.length];
for (int i = 0; i < phoneNumbers.length; i++) {
- Log.d("PhoneNumber count: " + phoneNumbers.length + " = " + phoneNumbers[i]);
+ Log.d("PhoneNumber count: " + phoneNumbers.length + " = "
+ + phoneNumbers[i]);
contacts[i] = Uri.parse(phoneNumbers[i]);
}
return sMapProfile.sendMessage(device, contacts, message, mSentIntent,
@@ -159,14 +170,18 @@ public class BluetoothMapClientFacade extends RpcReceiver {
@Rpc(description = "Disconnect an MAP device.")
public Boolean bluetoothMapClientDisconnect(
- @RpcParameter(name = "deviceID", description = "Name or MAC address of a device.")
+ @RpcParameter(name = "deviceID",
+ description = "Name or MAC address of a device.")
String deviceID)
throws Exception {
if (sMapProfile == null) return false;
- List<BluetoothDevice> connectedMapDevices = sMapProfile.getConnectedDevices();
+ List<BluetoothDevice> connectedMapDevices =
+ sMapProfile.getConnectedDevices();
Log.d("Connected map devices: " + connectedMapDevices);
- BluetoothDevice mDevice = BluetoothFacade.getDevice(connectedMapDevices, deviceID);
- if (!connectedMapDevices.isEmpty() && connectedMapDevices.get(0).equals(mDevice)) {
+ BluetoothDevice mDevice = BluetoothFacade.getDevice(
+ connectedMapDevices, deviceID);
+ if (!connectedMapDevices.isEmpty()
+ && connectedMapDevices.get(0).equals(mDevice)) {
if (sMapProfile.getPriority(mDevice) > BluetoothProfile.PRIORITY_ON) {
sMapProfile.setPriority(mDevice, BluetoothProfile.PRIORITY_ON);
}
@@ -198,10 +213,13 @@ public class BluetoothMapClientFacade extends RpcReceiver {
if (action.equals(BluetoothMapClient.ACTION_MESSAGE_RECEIVED)) {
mEventFacade.postEvent(MAP_EVENT,
intent.getStringExtra(android.content.Intent.EXTRA_TEXT));
- } else if (action.equals(BluetoothMapClient.ACTION_MESSAGE_SENT_SUCCESSFULLY)) {
+ } else if (action.equals(
+ BluetoothMapClient.ACTION_MESSAGE_SENT_SUCCESSFULLY)) {
mEventFacade.postEvent(MAP_SMS_SENT_SUCCESS,
- intent.getStringExtra(android.content.Intent.EXTRA_TEXT));
- } else if (action.equals(BluetoothMapClient.ACTION_MESSAGE_DELIVERED_SUCCESSFULLY)) {
+ intent.getStringExtra(
+ android.content.Intent.EXTRA_TEXT));
+ } else if (action.equals(
+ BluetoothMapClient.ACTION_MESSAGE_DELIVERED_SUCCESSFULLY)) {
mEventFacade.postEvent(MAP_SMS_DELIVER_SUCCESS,
intent.getStringExtra(android.content.Intent.EXTRA_TEXT));
}
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMapFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMapFacade.java
index 01c1bd46..e3fe007b 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMapFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMapFacade.java
@@ -16,12 +16,10 @@
package com.googlecode.android_scripting.facade.bluetooth;
-import java.util.List;
-
import android.app.Service;
-import android.bluetooth.BluetoothMap;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothMap;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUuid;
import android.os.ParcelUuid;
@@ -32,86 +30,114 @@ import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
import com.googlecode.android_scripting.rpc.Rpc;
import com.googlecode.android_scripting.rpc.RpcParameter;
+import java.util.List;
+
public class BluetoothMapFacade extends RpcReceiver {
- static final ParcelUuid[] MAP_UUIDS = {
- BluetoothUuid.MAP,
- BluetoothUuid.MNS,
- BluetoothUuid.MAS,
- };
- private final Service mService;
- private final BluetoothAdapter mBluetoothAdapter;
+ static final ParcelUuid[] MAP_UUIDS = {
+ BluetoothUuid.MAP,
+ BluetoothUuid.MNS,
+ BluetoothUuid.MAS,
+ };
+ private final Service mService;
+ private final BluetoothAdapter mBluetoothAdapter;
- private static boolean sIsMapReady = false;
- private static BluetoothMap sMapProfile = null;
+ private static boolean sIsMapReady = false;
+ private static BluetoothMap sMapProfile = null;
- public BluetoothMapFacade(FacadeManager manager) {
- super(manager);
- mService = manager.getService();
- mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
- mBluetoothAdapter.getProfileProxy(mService, new MapServiceListener(),
+ public BluetoothMapFacade(FacadeManager manager) {
+ super(manager);
+ mService = manager.getService();
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ mBluetoothAdapter.getProfileProxy(mService, new MapServiceListener(),
BluetoothProfile.MAP);
- }
-
- class MapServiceListener implements BluetoothProfile.ServiceListener {
- @Override
- public void onServiceConnected(int profile, BluetoothProfile proxy) {
- sMapProfile = (BluetoothMap) proxy;
- sIsMapReady = true;
}
- @Override
- public void onServiceDisconnected(int profile) {
- sIsMapReady = false;
+ class MapServiceListener implements BluetoothProfile.ServiceListener {
+ @Override
+ public void onServiceConnected(int profile, BluetoothProfile proxy) {
+ sMapProfile = (BluetoothMap) proxy;
+ sIsMapReady = true;
+ }
+
+ @Override
+ public void onServiceDisconnected(int profile) {
+ sIsMapReady = false;
+ }
}
- }
- public Boolean mapDisconnect(BluetoothDevice device) {
- if (sMapProfile.getPriority(device) > BluetoothProfile.PRIORITY_ON) {
- sMapProfile.setPriority(device, BluetoothProfile.PRIORITY_ON);
+ /**
+ * Disconnect Map Profile.
+ * @param device - the BluetoothDevice object to connect to.
+ * @return if the disconnection was successfull or not.
+ */
+ public Boolean mapDisconnect(BluetoothDevice device) {
+ if (sMapProfile.getPriority(device) > BluetoothProfile.PRIORITY_ON) {
+ sMapProfile.setPriority(device, BluetoothProfile.PRIORITY_ON);
+ }
+ return sMapProfile.disconnect(device);
}
- return sMapProfile.disconnect(device);
- }
- @Rpc(description = "Is Map profile ready.")
- public Boolean bluetoothMapIsReady() {
+ /**
+ * Is Map profile ready.
+ * @return if Map profile is ready or not.
+ */
+ @Rpc(description = "Is Map profile ready.")
+ public Boolean bluetoothMapIsReady() {
return sIsMapReady;
- }
+ }
- @Rpc(description = "Disconnect an MAP device.")
- public Boolean bluetoothMapDisconnect(
- @RpcParameter(name = "deviceID", description = "Name or MAC address of a device.")
- String deviceID)
- throws Exception {
- if (sMapProfile == null) return false;
- List<BluetoothDevice> connectedMapDevices = sMapProfile.getConnectedDevices();
- Log.d("Connected map devices: " + connectedMapDevices);
- BluetoothDevice mDevice = BluetoothFacade.getDevice(connectedMapDevices, deviceID);
- if (!connectedMapDevices.isEmpty() && connectedMapDevices.get(0).equals(mDevice)) {
- if (sMapProfile.getPriority(mDevice) > BluetoothProfile.PRIORITY_ON) {
- sMapProfile.setPriority(mDevice, BluetoothProfile.PRIORITY_ON);
+ /**
+ * Disconnect an MAP device.
+ * @param deviceID - Name or MAC address of a bluetooth device.
+ * @return True if the disconnection was successful; otherwise False.
+ */
+ @Rpc(description = "Disconnect an MAP device.")
+ public Boolean bluetoothMapDisconnect(
+ @RpcParameter(name = "deviceID",
+ description = "Name or MAC address of a device.")
+ String deviceID) throws Exception {
+ if (sMapProfile == null) return false;
+ List<BluetoothDevice> connectedMapDevices =
+ sMapProfile.getConnectedDevices();
+ Log.d("Connected map devices: " + connectedMapDevices);
+ BluetoothDevice mDevice = BluetoothFacade.getDevice(connectedMapDevices, deviceID);
+ if (!connectedMapDevices.isEmpty()
+ && connectedMapDevices.get(0).equals(mDevice)) {
+ if (sMapProfile.getPriority(mDevice)
+ > BluetoothProfile.PRIORITY_ON) {
+ sMapProfile.setPriority(mDevice, BluetoothProfile.PRIORITY_ON);
+ }
+ return sMapProfile.disconnect(mDevice);
+ } else {
+ return false;
}
- return sMapProfile.disconnect(mDevice);
- } else {
- return false;
}
- }
- @Rpc(description = "Get all the devices connected through MAP.")
- public List<BluetoothDevice> bluetoothMapGetConnectedDevices() {
- while (!sIsMapReady);
- return sMapProfile.getDevicesMatchingConnectionStates(
- new int[] {BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_CONNECTING,
- BluetoothProfile.STATE_DISCONNECTING});
- }
+ /**
+ * Get all the devices connected through MAP.
+ * @return List of all the devices connected through MAP.
+ */
+ @Rpc(description = "Get all the devices connected through MAP.")
+ public List<BluetoothDevice> bluetoothMapGetConnectedDevices() {
+ if (!sIsMapReady) return null;
+ return sMapProfile.getDevicesMatchingConnectionStates(
+ new int[] {BluetoothProfile.STATE_CONNECTED,
+ BluetoothProfile.STATE_CONNECTING,
+ BluetoothProfile.STATE_DISCONNECTING});
+ }
- @Rpc(description = "Get the currently connected remote Bluetooth device (PCE).")
- public BluetoothDevice bluetoothMapGetClient() {
- if (sMapProfile == null) { return null; }
- return sMapProfile.getClient();
- }
+ /**
+ * Get the currently connected remote Bluetooth device (PCE).
+ * @return remote Bluetooth device which is currently conencted.
+ */
+ @Rpc(description =
+ "Get the currently connected remote Bluetooth device (PCE).")
+ public BluetoothDevice bluetoothMapGetClient() {
+ if (sMapProfile == null) return null;
+ return sMapProfile.getClient();
+ }
- @Override
- public void shutdown() {
- }
+ @Override
+ public void shutdown() {
+ }
}
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMediaFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMediaFacade.java
index c179b637..404a7911 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMediaFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMediaFacade.java
@@ -17,27 +17,25 @@
package com.googlecode.android_scripting.facade.bluetooth;
import android.app.Service;
-import android.content.Intent;
import android.content.ComponentName;
import android.content.Context;
-
+import android.content.Intent;
import android.media.MediaMetadata;
-import android.media.session.MediaSessionManager;
-import android.media.session.PlaybackState;
import android.media.browse.MediaBrowser;
import android.media.session.MediaController;
-
+import android.media.session.MediaSessionManager;
+import android.media.session.PlaybackState;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
+import com.googlecode.android_scripting.Log;
import com.googlecode.android_scripting.facade.EventFacade;
import com.googlecode.android_scripting.facade.FacadeManager;
import com.googlecode.android_scripting.facade.bluetooth.media.BluetoothSL4AAudioSrcMBS;
import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
import com.googlecode.android_scripting.rpc.Rpc;
import com.googlecode.android_scripting.rpc.RpcParameter;
-import com.googlecode.android_scripting.Log;
import java.util.ArrayList;
import java.util.HashMap;
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPairingHelper.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPairingHelper.java
index 18def705..597b17aa 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPairingHelper.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPairingHelper.java
@@ -23,106 +23,128 @@ import android.content.Intent;
import android.os.Bundle;
import com.googlecode.android_scripting.Log;
-import com.googlecode.android_scripting.facade.EventFacade;
import com.googlecode.android_scripting.event.Event;
+import com.googlecode.android_scripting.facade.EventFacade;
public class BluetoothPairingHelper extends BroadcastReceiver {
- private final EventFacade mEventFacade;
- private static final int DEFAULT_TIMEOUT_MS = 5000;
- private boolean mAutoConfirm = true;
+ private final EventFacade mEventFacade;
+ private static final int DEFAULT_TIMEOUT_MS = 5000;
+ private boolean mAutoConfirm = true;
+
+ public BluetoothPairingHelper(EventFacade eventFacade) {
+ super();
+ mEventFacade = eventFacade;
+ Log.d("Pairing helper created.");
+ }
- public BluetoothPairingHelper(EventFacade eventFacade) {
- super();
- mEventFacade = eventFacade;
- Log.d("Pairing helper created.");
- }
/**
* Confirms bluetooth connection/bonding requests.
*/
- @Override
- public void onReceive(Context c, Intent intent) {
- String action = intent.getAction();
- Bundle result = new Bundle();
- Log.d("Bluetooth pairing intent received: " + action);
- BluetoothDevice mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
- if(action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
- mDevice.setMessageAccessPermission(BluetoothDevice.ACCESS_ALLOWED);
- mDevice.setPhonebookAccessPermission(BluetoothDevice.ACCESS_ALLOWED);
- int type = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.ERROR);
- Log.d("Processing Action Paring Request with type " + type);
- int pin = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY,0);
- String deviceAddress = mDevice.getAddress();
- result.putInt("Pin", pin);
- result.putInt("PairingVariant", type);
- result.putString("DeviceAddress", deviceAddress);
- mEventFacade.postEvent("BluetoothActionPairingRequest", result.clone());
- result.clear();
- if(type == BluetoothDevice.PAIRING_VARIANT_CONSENT) {
- mDevice.setPairingConfirmation(true);
- Log.d("Connection auto-confirmed by consent");
- abortBroadcast(); // Abort the broadcast so Settings app doesn't get it.
- } else if (type == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION) {
- if (mAutoConfirm) {
- mDevice.setPairingConfirmation(true);
- Log.d("Connection auto-confirmed");
- } else {
- // Wait for confirmation
- Event userConfirmEvent = null;
- try {
- userConfirmEvent = mEventFacade.eventWaitFor(
- "BluetoothActionPairingRequestUserConfirm",
- true, DEFAULT_TIMEOUT_MS);
- } catch (InterruptedException e) {
- Log.d("Connection interrupted");
- userConfirmEvent = null;
- }
- if (userConfirmEvent == null) {
- Log.d("Null response received from test server or timeout");
- mDevice.setPairingConfirmation(false);
- } else {
- String userConfirmEventData = (String) userConfirmEvent.getData();
- if (userConfirmEventData.equalsIgnoreCase("True")) {
- mDevice.setPairingConfirmation(true);
- Log.d("Connection confirmed");
- } else {
- mDevice.setPairingConfirmation(false);
- Log.d("Connection rejected");
+ @Override
+ public void onReceive(Context c, Intent intent) {
+ String action = intent.getAction();
+ Bundle result = new Bundle();
+ Log.d("Bluetooth pairing intent received: " + action);
+ BluetoothDevice mDevice = intent.getParcelableExtra(
+ BluetoothDevice.EXTRA_DEVICE);
+ if (action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
+ mDevice.setMessageAccessPermission(BluetoothDevice.ACCESS_ALLOWED);
+ mDevice.setPhonebookAccessPermission(
+ BluetoothDevice.ACCESS_ALLOWED);
+ int type = intent.getIntExtra(
+ BluetoothDevice.EXTRA_PAIRING_VARIANT,
+ BluetoothDevice.ERROR);
+ Log.d("Processing Action Paring Request with type " + type);
+ int pin = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY, 0);
+ String deviceAddress = mDevice.getAddress();
+ result.putInt("Pin", pin);
+ result.putInt("PairingVariant", type);
+ result.putString("DeviceAddress", deviceAddress);
+ mEventFacade.postEvent("BluetoothActionPairingRequest",
+ result.clone());
+ result.clear();
+ if (type == BluetoothDevice.PAIRING_VARIANT_CONSENT) {
+ mDevice.setPairingConfirmation(true);
+ Log.d("Connection auto-confirmed by consent");
+ // Abort the broadcast so Settings app doesn't get it.
+ abortBroadcast();
+ } else if (type
+ == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION) {
+ if (mAutoConfirm) {
+ mDevice.setPairingConfirmation(true);
+ Log.d("Connection auto-confirmed");
+ } else {
+ // Wait for confirmation
+ Event userConfirmEvent = null;
+ try {
+ userConfirmEvent = mEventFacade.eventWaitFor(
+ "BluetoothActionPairingRequestUserConfirm",
+ true, DEFAULT_TIMEOUT_MS);
+ } catch (InterruptedException e) {
+ Log.d("Connection interrupted");
+ userConfirmEvent = null;
+ }
+ if (userConfirmEvent == null) {
+ Log.d("Null response received from test server or timeout");
+ mDevice.setPairingConfirmation(false);
+ } else {
+ String userConfirmEventData =
+ (String) userConfirmEvent.getData();
+ if (userConfirmEventData.equalsIgnoreCase("True")) {
+ mDevice.setPairingConfirmation(true);
+ Log.d("Connection confirmed");
+ } else {
+ mDevice.setPairingConfirmation(false);
+ Log.d("Connection rejected");
+ }
+ }
+ }
+ // Abort the broadcast so Settings app doesn't get it.
+ abortBroadcast();
+ }
+ } else if (action.equals(
+ BluetoothDevice.ACTION_CONNECTION_ACCESS_REQUEST)) {
+ int type = intent.getIntExtra(
+ BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
+ BluetoothDevice.ERROR);
+ Log.d("Processing Action Connection Access Request type " + type);
+ if (type == BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS
+ || type == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS
+ || type
+ == BluetoothDevice.REQUEST_TYPE_PROFILE_CONNECTION) {
+ Intent newIntent =
+ new Intent(
+ BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY);
+ String mReturnPackage =
+ intent.getStringExtra(
+ BluetoothDevice.EXTRA_PACKAGE_NAME);
+ String mReturnClass =
+ intent.getStringExtra(BluetoothDevice.EXTRA_CLASS_NAME);
+ int mRequestType =
+ intent.getIntExtra(
+ BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
+ BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS);
+ if (mReturnPackage != null && mReturnClass != null) {
+ newIntent.setClassName(mReturnPackage, mReturnClass);
+ }
+ newIntent.putExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT,
+ BluetoothDevice.CONNECTION_ACCESS_YES);
+ newIntent.putExtra(BluetoothDevice.EXTRA_ALWAYS_ALLOWED, true);
+ newIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
+ newIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
+ mRequestType);
+ Log.d("Sending connection access acceptance intent.");
+ abortBroadcast();
+ c.sendBroadcast(newIntent,
+ android.Manifest.permission.BLUETOOTH_ADMIN);
}
- }
}
- abortBroadcast(); // Abort the broadcast so Settings app doesn't get it.
- }
}
- else if(action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_REQUEST)) {
- int type = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, BluetoothDevice.ERROR);
- Log.d("Processing Action Connection Access Request type " + type);
- if(type == BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS ||
- type == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS ||
- type == BluetoothDevice.REQUEST_TYPE_PROFILE_CONNECTION) {
- Intent newIntent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY);
- String mReturnPackage = intent.getStringExtra(BluetoothDevice.EXTRA_PACKAGE_NAME);
- String mReturnClass = intent.getStringExtra(BluetoothDevice.EXTRA_CLASS_NAME);
- int mRequestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
- BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS);
- if (mReturnPackage != null && mReturnClass != null) {
- newIntent.setClassName(mReturnPackage, mReturnClass);
- }
- newIntent.putExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT,
- BluetoothDevice.CONNECTION_ACCESS_YES);
- newIntent.putExtra(BluetoothDevice.EXTRA_ALWAYS_ALLOWED, true);
- newIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
- newIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, mRequestType);
- Log.d("Sending connection access acceptance intent.");
- abortBroadcast();
- c.sendBroadcast(newIntent, android.Manifest.permission.BLUETOOTH_ADMIN);
- }
- }
- }
- /**
- * Set autoConfirm flag to Value
- */
- public synchronized void setAutoConfirm(boolean value) {
- mAutoConfirm = value;
- }
+ /**
+ * Set autoConfirm flag to Value.
+ */
+ public synchronized void setAutoConfirm(boolean value) {
+ mAutoConfirm = value;
+ }
}
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPanFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPanFacade.java
index 0a1235a9..14357ed8 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPanFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPanFacade.java
@@ -16,8 +16,6 @@
package com.googlecode.android_scripting.facade.bluetooth;
-import java.util.List;
-
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
@@ -31,6 +29,8 @@ import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
import com.googlecode.android_scripting.rpc.Rpc;
import com.googlecode.android_scripting.rpc.RpcParameter;
+import java.util.List;
+
public class BluetoothPanFacade extends RpcReceiver {
static final ParcelUuid[] UUIDS = {
@@ -49,7 +49,7 @@ public class BluetoothPanFacade extends RpcReceiver {
mService = manager.getService();
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothAdapter.getProfileProxy(mService, new PanServiceListener(),
- BluetoothProfile.PAN);
+ BluetoothProfile.PAN);
}
class PanServiceListener implements BluetoothProfile.ServiceListener {
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPbapClientFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPbapClientFacade.java
index 7a0a7690..e1c20cd9 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPbapClientFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothPbapClientFacade.java
@@ -16,13 +16,10 @@
package com.googlecode.android_scripting.facade.bluetooth;
-import java.util.List;
-import java.util.ArrayList;
-
import android.app.Service;
-import android.bluetooth.BluetoothPbapClient;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothPbapClient;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUuid;
import android.os.ParcelUuid;
@@ -33,138 +30,196 @@ import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
import com.googlecode.android_scripting.rpc.Rpc;
import com.googlecode.android_scripting.rpc.RpcParameter;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * BluetoothPbapClientFacade
+ */
public class BluetoothPbapClientFacade extends RpcReceiver {
- static final ParcelUuid[] UUIDS = {
- BluetoothUuid.PBAP_PSE,
- };
+ static final ParcelUuid[] UUIDS = {
+ BluetoothUuid.PBAP_PSE,
+ };
+
+ private final Service mService;
+ private final BluetoothAdapter mBluetoothAdapter;
+
+ private static boolean sIsPbapClientReady = false;
+ private static BluetoothPbapClient sPbapClientProfile = null;
+
+ public BluetoothPbapClientFacade(FacadeManager manager) {
+ super(manager);
+ mService = manager.getService();
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ mBluetoothAdapter.getProfileProxy(mService,
+ new PbapClientServiceListener(), BluetoothProfile.PBAP_CLIENT);
+ }
- private final Service mService;
- private final BluetoothAdapter mBluetoothAdapter;
+ class PbapClientServiceListener implements
+ BluetoothProfile.ServiceListener {
+ @Override
+ public void onServiceConnected(int profile, BluetoothProfile proxy) {
+ sPbapClientProfile = (BluetoothPbapClient) proxy;
+ sIsPbapClientReady = true;
+ }
+
+ @Override
+ public void onServiceDisconnected(int profile) {
+ sIsPbapClientReady = false;
+ }
+ }
- private static boolean sIsPbapClientReady = false;
- private static BluetoothPbapClient sPbapClientProfile = null;
+ /**
+ * Connect PbapClient profile.
+ * @param device - the BluetoothDevice object to connect to.
+ * @return if the connection was successfull or not.
+ */
+ public Boolean pbapClientConnect(BluetoothDevice device) {
+ if (sPbapClientProfile == null) return false;
+ return sPbapClientProfile.connect(device);
+ }
- public BluetoothPbapClientFacade(FacadeManager manager) {
- super(manager);
- mService = manager.getService();
- mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
- mBluetoothAdapter.getProfileProxy(mService, new PbapClientServiceListener(),
- BluetoothProfile.PBAP_CLIENT);
- }
+ /**
+ * Disconnect PbapClient profile.
+ * @param device - the Bluetooth Device object to disconnect from.
+ * @return if the disconnection was successfull or not.
+ */
+ public Boolean pbapClientDisconnect(BluetoothDevice device) {
+ if (sPbapClientProfile == null) return false;
+ return sPbapClientProfile.disconnect(device);
+ }
- class PbapClientServiceListener implements BluetoothProfile.ServiceListener {
- @Override
- public void onServiceConnected(int profile, BluetoothProfile proxy) {
- sPbapClientProfile = (BluetoothPbapClient) proxy;
- sIsPbapClientReady = true;
+ /**
+ * Is PbapClient profile ready.
+ * @return if PbapClient profile is ready or not.
+ */
+ @Rpc(description = "Is PbapClient profile ready.")
+ public Boolean bluetoothPbapClientIsReady() {
+ return sIsPbapClientReady;
}
- @Override
- public void onServiceDisconnected(int profile) {
- sIsPbapClientReady = false;
+ /**
+ * Set priority of the profile.
+ * @param deviceStr - name or MAC address of a Bluetooth device.
+ * @param priority - Priority that needs to be set.
+ */
+ @Rpc(description = "Set priority of the profile")
+ public void bluetoothPbapClientSetPriority(@RpcParameter(name = "device",
+ description = "Mac address of a BT device.") String deviceStr,
+ @RpcParameter(name = "priority",
+ description = "Priority that needs to be set.")
+ Integer priority) throws Exception {
+ if (sPbapClientProfile == null) return;
+ BluetoothDevice device =
+ BluetoothFacade.getDevice(mBluetoothAdapter.getBondedDevices(),
+ deviceStr);
+ Log.d("Changing priority of device " + device.getAliasName()
+ + " p: " + priority);
+ sPbapClientProfile.setPriority(device, priority);
+ }
+
+ /**
+ * Get priority of the profile.
+ * @return Priority of the device.
+ */
+ @Rpc(description = "Get priority of the profile")
+ public Integer bluetoothPbapClientGetPriority(
+ @RpcParameter(name = "device",
+ description = "Mac address of a BT device.") String deviceStr)
+ throws Exception {
+ if (sPbapClientProfile == null) {
+ return BluetoothProfile.PRIORITY_UNDEFINED;
+ }
+ BluetoothDevice device =
+ BluetoothFacade.getDevice(mBluetoothAdapter.getBondedDevices(),
+ deviceStr);
+ return sPbapClientProfile.getPriority(device);
}
- }
-
- public Boolean pbapClientConnect(BluetoothDevice device) {
- if (sPbapClientProfile == null) return false;
- return sPbapClientProfile.connect(device);
- }
-
- public Boolean pbapClientDisconnect(BluetoothDevice device) {
- if (sPbapClientProfile == null) return false;
- return sPbapClientProfile.disconnect(device);
- }
-
- @Rpc(description = "Is PbapClient profile ready.")
- public Boolean bluetoothPbapClientIsReady() {
- return sIsPbapClientReady;
- }
-
- @Rpc(description = "Set priority of the profile")
- public void bluetoothPbapClientSetPriority(
- @RpcParameter(name = "device", description = "Mac address of a BT device.")
- String deviceStr,
- @RpcParameter(name = "priority", description = "Priority that needs to be set.")
- Integer priority)
- throws Exception {
- if (sPbapClientProfile == null) return;
- BluetoothDevice device =
- BluetoothFacade.getDevice(mBluetoothAdapter.getBondedDevices(), deviceStr);
- Log.d("Changing priority of device " + device.getAliasName() + " p: " + priority);
- sPbapClientProfile.setPriority(device, priority);
- }
-
- @Rpc(description = "Get priority of the profile")
- public Integer bluetoothPbapClientGetPriority(
- @RpcParameter(name = "device", description = "Mac address of a BT device.")
- String deviceStr)
- throws Exception {
- if (sPbapClientProfile == null) return BluetoothProfile.PRIORITY_UNDEFINED;
- BluetoothDevice device =
- BluetoothFacade.getDevice(mBluetoothAdapter.getBondedDevices(), deviceStr);
- return sPbapClientProfile.getPriority(device);
- }
-
- @Rpc(description = "Connect to an PBAP Client device.")
- public Boolean bluetoothPbapClientConnect(
- @RpcParameter(name = "device", description = "Name or MAC address of a bluetooth device.")
- String deviceStr)
- throws Exception {
- if (sPbapClientProfile == null) return false;
- try {
- BluetoothDevice device =
- BluetoothFacade.getDevice(mBluetoothAdapter.getBondedDevices(), deviceStr);
- Log.d("Connecting to device " + device.getAliasName());
- return pbapClientConnect(device);
- } catch (Exception e) {
- Log.e("bluetoothPbapClientConnect failed on getDevice " + deviceStr + " with " + e);
+
+ /**
+ * Connect to an PBAP Client device.
+ * @param deviceStr - Name or MAC address of a bluetooth device.
+ * @return True if the connection was successful; otherwise False.
+ */
+ @Rpc(description = "Connect to an PBAP Client device.")
+ public Boolean bluetoothPbapClientConnect(
+ @RpcParameter(name = "device",
+ description = "Name or MAC address of a bluetooth device.")
+ String deviceStr) throws Exception {
+ if (sPbapClientProfile == null) return false;
+ try {
+ BluetoothDevice device =
+ BluetoothFacade.getDevice(
+ mBluetoothAdapter.getBondedDevices(), deviceStr);
+ Log.d("Connecting to device " + device.getAliasName());
+ return pbapClientConnect(device);
+ } catch (Exception e) {
+ Log.e("bluetoothPbapClientConnect failed on getDevice "
+ + deviceStr + " with " + e);
+ return false;
+ }
+ }
+
+ /**
+ * Disconnect an PBAP Client device.
+ * @param deviceStr - Name or MAC address of a bluetooth device.
+ * @return True if the disconnection was successful; otherwise False.
+ */
+ @Rpc(description = "Disconnect an PBAP Client device.")
+ public Boolean bluetoothPbapClientDisconnect(
+ @RpcParameter(name = "device",
+ description = "Name or MAC address of a device.")
+ String deviceStr) {
+ if (sPbapClientProfile == null) return false;
+ Log.d("Connected devices: " + sPbapClientProfile.getConnectedDevices());
+ try {
+ BluetoothDevice device =
+ BluetoothFacade.getDevice(
+ sPbapClientProfile.getConnectedDevices(), deviceStr);
+ return pbapClientDisconnect(device);
+ } catch (Exception e) {
+ // Do nothing since it is disconnect and the above call
+ // should force disconnect.
+ Log.e("bluetoothPbapClientConnect getDevice failed " + e);
+ }
return false;
}
- }
-
- @Rpc(description = "Disconnect an PBAP Client device.")
- public Boolean bluetoothPbapClientDisconnect(
- @RpcParameter(name = "device", description = "Name or MAC address of a device.")
- String deviceStr) {
- if (sPbapClientProfile == null) return false;
- Log.d("Connected devices: " + sPbapClientProfile.getConnectedDevices());
- try {
- BluetoothDevice device =
- BluetoothFacade.getDevice(sPbapClientProfile.getConnectedDevices(), deviceStr);
- return pbapClientDisconnect(device);
- } catch (Exception e) {
- // Do nothing since it is disconnect and the above call should force disconnect.
- Log.e("bluetoothPbapClientConnect getDevice failed " + e);
+
+ /**
+ * Get all the devices connected through PBAP Client.
+ * @return List of all the devices connected through PBAP client.
+ */
+ @Rpc(description = "Get all the devices connected through PBAP Client.")
+ public List<BluetoothDevice> bluetoothPbapClientGetConnectedDevices() {
+ if (sPbapClientProfile == null) return new ArrayList<BluetoothDevice>();
+ return sPbapClientProfile.getConnectedDevices();
+ }
+
+ /**
+ * Get the connection status of a device.
+ * @return connection status of the device.
+ */
+ @Rpc(description = "Get the connection status of a device.")
+ public Integer bluetoothPbapClientGetConnectionStatus(
+ @RpcParameter(name = "deviceID",
+ description = "Name or MAC address of a bluetooth device.")
+ String deviceID) {
+ if (sPbapClientProfile == null) {
+ return BluetoothProfile.STATE_DISCONNECTED;
+ }
+ List<BluetoothDevice> deviceList =
+ sPbapClientProfile.getConnectedDevices();
+ BluetoothDevice device;
+ try {
+ device = BluetoothFacade.getDevice(deviceList, deviceID);
+ } catch (Exception e) {
+ Log.e(e);
+ return BluetoothProfile.STATE_DISCONNECTED;
+ }
+ return sPbapClientProfile.getConnectionState(device);
+ }
+
+ @Override
+ public void shutdown() {
}
- return false;
- }
-
- @Rpc(description = "Get all the devices connected through PBAP Client.")
- public List<BluetoothDevice> bluetoothPbapClientGetConnectedDevices() {
- if (sPbapClientProfile == null) return new ArrayList<BluetoothDevice>();
- return sPbapClientProfile.getConnectedDevices();
- }
-
- @Rpc(description = "Get the connection status of a device.")
- public Integer bluetoothPbapClientGetConnectionStatus(
- @RpcParameter(name = "deviceID",
- description = "Name or MAC address of a bluetooth device.")
- String deviceID) {
- if (sPbapClientProfile == null) {
- return BluetoothProfile.STATE_DISCONNECTED;
- }
- List<BluetoothDevice> deviceList = sPbapClientProfile.getConnectedDevices();
- BluetoothDevice device;
- try {
- device = BluetoothFacade.getDevice(deviceList, deviceID);
- } catch (Exception e) {
- Log.e(e);
- return BluetoothProfile.STATE_DISCONNECTED;
- }
- return sPbapClientProfile.getConnectionState(device);
- }
-
- @Override
- public void shutdown() {
- }
}