diff options
author | Cheney Ni <cheneyni@google.com> | 2019-07-29 20:00:37 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-07-29 20:00:37 -0700 |
commit | 0de6f67961dd945ec4a746131729418abb075087 (patch) | |
tree | 1786b2a2135b5f329100bdb4f2dc57a6ea61d2db /framework/java/android/bluetooth/BluetoothCodecStatus.java | |
parent | 99fa3e795775782c0b1e13a1c682820bcc2cf9b9 (diff) | |
parent | ed6755fa55d3dbf5426b0f8dc634d6040f9cef35 (diff) |
Merge "Add helpers to check whether the BluetoothCodecConfig instance is selectable"
am: ed6755fa55
Change-Id: I7718d3f12541bcbb005f7e1930267a1393f9b19a
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothCodecStatus.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index 58b6aeae63..58a764a85b 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -89,6 +89,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, |