aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Wang <tedwang@google.com>2019-02-13 16:00:12 +0800
committerTed Wang <tedwang@google.com>2019-03-19 05:55:28 +0000
commit1b3fbe270f1e7c25831085aad48d181ea14e83f6 (patch)
tree543912c4e15d7873a9aeed181813cafc507d41df
parente70e01578b9fd6b4e76f9dc70e367cdd27608b4d (diff)
downloadsl4a-1b3fbe270f1e7c25831085aad48d181ea14e83f6.tar.gz
Add get current Bluetooth codec config method to facadeandroid-q-preview-6android-q-preview-5android-q-preview-4android-q-preview-2.5
This patch is to add bluetoothGetCurrentCodecConfig method to facade for obtaining current codec config. Bug: 120083042 Test: SL4A Change-Id: I4cfb3dac6fb1748e202bafafc9519f70bc9528d5
-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();