summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothCodecStatus.java
diff options
context:
space:
mode:
authorCheney Ni <cheneyni@google.com>2019-07-18 21:45:10 +0800
committerCheney Ni <cheneyni@google.com>2019-07-23 20:32:06 +0800
commit38a8716ef8fc33e5c8915311b932d945c864ae85 (patch)
treeecfb59447df82551543918de7c9df6f02972e894 /framework/java/android/bluetooth/BluetoothCodecStatus.java
parent39977db7ff795a717d9f4de4c797b2d5cab899ca (diff)
Add helpers to check whether the BluetoothCodecConfig instance is selectable
There will be a helper in the BluetoothCodecStatus to check whether the codec config is matched the selectable array. It uses 3 smaller helpers to confirm the codec config has none (wildcard matching), or one and only one value for the audio feeding parameters. Besides, this CL also adds a helper to compare whether two codec configs are similar or not, and uses NONE values as wildcard. Bug: 131147224 Bug: 133719424 Test: atest -t BluetoothInstrumentationTests:com.android.bluetooth.a2dp Change-Id: I7d8f1a16b8358c440841801d95471b2d010739ec
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothCodecStatus.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java
index 32bb681f2e..8237d6a73c 100644
--- a/framework/java/android/bluetooth/BluetoothCodecStatus.java
+++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java
@@ -88,6 +88,43 @@ public final class BluetoothCodecStatus implements Parcelable {
return Arrays.asList(c1).containsAll(Arrays.asList(c2));
}
+ /**
+ * Checks whether the codec config matches the selectable capabilities.
+ * Any parameters of the codec config with NONE value will be considered a wildcard matching.
+ *
+ * @param codecConfig the codec config to compare against
+ * @return true if the codec config matches, otherwise false
+ */
+ public boolean isCodecConfigSelectable(BluetoothCodecConfig codecConfig) {
+ if (codecConfig == null || !codecConfig.hasSingleSampleRate()
+ || !codecConfig.hasSingleBitsPerSample() || !codecConfig.hasSingleChannelMode()) {
+ return false;
+ }
+ for (BluetoothCodecConfig selectableConfig : mCodecsSelectableCapabilities) {
+ if (codecConfig.getCodecType() != selectableConfig.getCodecType()) {
+ continue;
+ }
+ int sampleRate = codecConfig.getSampleRate();
+ if ((sampleRate & selectableConfig.getSampleRate()) == 0
+ && sampleRate != BluetoothCodecConfig.SAMPLE_RATE_NONE) {
+ continue;
+ }
+ int bitsPerSample = codecConfig.getBitsPerSample();
+ if ((bitsPerSample & selectableConfig.getBitsPerSample()) == 0
+ && bitsPerSample != BluetoothCodecConfig.BITS_PER_SAMPLE_NONE) {
+ continue;
+ }
+ int channelMode = codecConfig.getChannelMode();
+ if ((channelMode & selectableConfig.getChannelMode()) == 0
+ && channelMode != BluetoothCodecConfig.CHANNEL_MODE_NONE) {
+ continue;
+ }
+ return true;
+ }
+ return false;
+ }
+
+
@Override
public int hashCode() {
return Objects.hash(mCodecConfig, mCodecsLocalCapabilities,