aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Wang <tedwang@google.com>2019-03-19 21:21:32 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-03-19 21:21:32 -0700
commit6e50b84f56404d91b301f60ed21333e551fa56d4 (patch)
tree543912c4e15d7873a9aeed181813cafc507d41df
parentfde8c56fe57f75c770fc258ca450648644586cf4 (diff)
parent1b3fbe270f1e7c25831085aad48d181ea14e83f6 (diff)
downloadsl4a-6e50b84f56404d91b301f60ed21333e551fa56d4.tar.gz
Add get current Bluetooth codec config method to facade
am: 1b3fbe270f Change-Id: I89bfa96b51f4f8839a19d75e48f8ea2de972320c
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothA2dpFacade.java20
-rw-r--r--Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java15
2 files changed, 34 insertions, 1 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 5e847b34..5d876079 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothA2dpFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothA2dpFacade.java
@@ -44,6 +44,8 @@ public class BluetoothA2dpFacade extends RpcReceiver {
static final ParcelUuid[] SINK_UUIDS = {
BluetoothUuid.AudioSink, BluetoothUuid.AdvAudioDist,
};
+ private BluetoothCodecConfig mBluetoothCodecConfig;
+
private final Service mService;
private final EventFacade mEventFacade;
private final BroadcastReceiver mBluetoothA2dpReceiver;
@@ -51,7 +53,6 @@ public class BluetoothA2dpFacade extends RpcReceiver {
private static boolean sIsA2dpReady = false;
private static BluetoothA2dp sA2dpProfile = null;
- private BluetoothCodecConfig mBluetoothCodecConfig;
public BluetoothA2dpFacade(FacadeManager manager) {
super(manager);
@@ -287,6 +288,23 @@ public class BluetoothA2dpFacade extends RpcReceiver {
return false;
}
+ /**
+ * Get current active device codec config
+ *
+ * @return Current active device codec config,
+ */
+ @Rpc(description = "Get current codec config.")
+ public BluetoothCodecConfig bluetoothA2dpGetCurrentCodecConfig() throws Exception {
+ while (!sIsA2dpReady) {
+ continue;
+ }
+ if (sA2dpProfile.getActiveDevice() == null) {
+ Log.e("No active device.");
+ throw new Exception("No active device");
+ }
+ return sA2dpProfile.getCodecStatus(sA2dpProfile.getActiveDevice()).getCodecConfig();
+ }
+
@Override
public void shutdown() {
mService.unregisterReceiver(mBluetoothA2dpReceiver);
diff --git a/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java b/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
index 5c05bde3..da634997 100644
--- a/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
+++ b/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
@@ -19,6 +19,7 @@ package com.googlecode.android_scripting.jsonrpc;
import static com.googlecode.android_scripting.ConvertUtils.toNonNullString;
import android.annotation.NonNull;
+import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
@@ -212,6 +213,9 @@ public class JsonBuilder {
if (data instanceof BluetoothDevice) {
return buildJsonBluetoothDevice((BluetoothDevice) data);
}
+ if (data instanceof BluetoothCodecConfig) {
+ return buildJsonBluetoothCodecConfig((BluetoothCodecConfig) data);
+ }
if (data instanceof PlaybackState) {
return buildJsonPlaybackState((PlaybackState) data);
}
@@ -466,6 +470,17 @@ public class JsonBuilder {
return result;
}
+ private static JSONObject buildJsonBluetoothCodecConfig(BluetoothCodecConfig codecConfig)
+ throws JSONException {
+ JSONObject result = new JSONObject();
+ result.put("codecType", codecConfig.getCodecType());
+ result.put("sampleRate", codecConfig.getSampleRate());
+ result.put("bitsPerSample", codecConfig.getBitsPerSample());
+ result.put("channelMode", codecConfig.getChannelMode());
+ result.put("codecSpecific1", codecConfig.getCodecSpecific1());
+ return result;
+ }
+
private static JSONObject buildJsonBluetoothDevice(BluetoothDevice data)
throws JSONException {
JSONObject deviceInfo = new JSONObject();