From f6d543a7d0e6919a7d9055f4911d57e209e3e9db Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Wed, 25 Jan 2017 16:54:07 -0800 Subject: Update the A2DP Codec Config API Previously, the JNI upcall would contain only the current codec config. In the new API, the upcall contains: 1. The current codec config 2. The list of codecs containing the local codecs capabilities 3. The list of codecs containing the selectable codecs capabilities. This list is the intersection of the local codecs capabilities and the capabilities of the paired device. Also, refactored the Java internals to accomodate the extra information: * Added new class BluetoothCodecStatus that contains the extra info: current codec config, local codecs capabilities and selectable codecs capabilities * Renamed method getCodecConfig() to getCodecStatus() and return the corresponding BluetoothCodecStatus object. * Updates to class BluetoothCodecConfig: new methods isValid(), getCodecName(), and updated toString() so it is more user friendly * Removed BluetoothCodecConfig.EXTRA_CODEC_CONFIG and EXTRA_PREVIOUS_CODEC_CONFIG. The former is superseded by BluetoothCodecStatus.EXTRA_CODEC_STATUS; the latter is not really used. Test: A2DP streaming with headsets and switching the codecs Change-Id: Ia1af2c22e521e863e28a360610aca49f7e62d31b --- .../android/bluetooth/BluetoothCodecStatus.java | 134 +++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 framework/java/android/bluetooth/BluetoothCodecStatus.java (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java new file mode 100644 index 0000000000..c8cd8d17ce --- /dev/null +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.bluetooth; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.Arrays; +import java.util.Objects; + +/** + * Represents the codec status (configuration and capability) for a Bluetooth + * A2DP source device. + * + * {@see BluetoothA2dp} + * + * {@hide} + */ +public final class BluetoothCodecStatus implements Parcelable { + /** + * Extra for the codec configuration intents of the individual profiles. + * + * This extra represents the current codec status of the A2DP + * profile. + */ + public static final String EXTRA_CODEC_STATUS = + "android.bluetooth.codec.extra.CODEC_STATUS"; + + private final BluetoothCodecConfig mCodecConfig; + private final BluetoothCodecConfig[] mCodecsLocalCapabilities; + private final BluetoothCodecConfig[] mCodecsSelectableCapabilities; + + public BluetoothCodecStatus(BluetoothCodecConfig codecConfig, + BluetoothCodecConfig[] codecsLocalCapabilities, + BluetoothCodecConfig[] codecsSelectableCapabilities) { + mCodecConfig = codecConfig; + mCodecsLocalCapabilities = codecsLocalCapabilities; + mCodecsSelectableCapabilities = codecsSelectableCapabilities; + } + + @Override + public boolean equals(Object o) { + if (o instanceof BluetoothCodecStatus) { + BluetoothCodecStatus other = (BluetoothCodecStatus)o; + return (Objects.equals(other.mCodecConfig, mCodecConfig) && + Objects.equals(other.mCodecsLocalCapabilities, + mCodecsLocalCapabilities) && + Objects.equals(other.mCodecsSelectableCapabilities, + mCodecsSelectableCapabilities)); + } + return false; + } + + @Override + public int hashCode() { + return Objects.hash(mCodecConfig, mCodecsLocalCapabilities, + mCodecsLocalCapabilities); + } + + @Override + public String toString() { + return "{mCodecConfig:" + mCodecConfig + + ",mCodecsLocalCapabilities:" + Arrays.toString(mCodecsLocalCapabilities) + + ",mCodecsSelectableCapabilities:" + Arrays.toString(mCodecsSelectableCapabilities) + + "}"; + } + + public int describeContents() { + return 0; + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public BluetoothCodecStatus createFromParcel(Parcel in) { + final BluetoothCodecConfig codecConfig = in.readTypedObject(BluetoothCodecConfig.CREATOR); + final BluetoothCodecConfig[] codecsLocalCapabilities = in.createTypedArray(BluetoothCodecConfig.CREATOR); + final BluetoothCodecConfig[] codecsSelectableCapabilities = in.createTypedArray(BluetoothCodecConfig.CREATOR); + + return new BluetoothCodecStatus(codecConfig, + codecsLocalCapabilities, + codecsSelectableCapabilities); + } + public BluetoothCodecStatus[] newArray(int size) { + return new BluetoothCodecStatus[size]; + } + }; + + public void writeToParcel(Parcel out, int flags) { + out.writeTypedObject(mCodecConfig, 0); + out.writeTypedArray(mCodecsLocalCapabilities, 0); + out.writeTypedArray(mCodecsSelectableCapabilities, 0); + } + + /** + * Gets the current codec configuration. + * + * @return the current codec configuration + */ + public BluetoothCodecConfig getCodecConfig() { + return mCodecConfig; + } + + /** + * Gets the codecs local capabilities. + * + * @return an array with the codecs local capabilities + */ + public BluetoothCodecConfig[] getCodecsLocalCapabilities() { + return mCodecsLocalCapabilities; + } + + /** + * Gets the codecs selectable capabilities. + * + * @return an array with the codecs selectable capabilities + */ + public BluetoothCodecConfig[] getCodecsSelectableCapabilities() { + return mCodecsSelectableCapabilities; + } +} -- cgit v1.2.3 From 910201beb0bde1dcf6b33e4ec5d1eb60042419d8 Mon Sep 17 00:00:00 2001 From: Jack He Date: Tue, 22 Aug 2017 16:06:54 -0700 Subject: Fix checkstyle errors (1/2) * Automatic style corrections through IDE Bug: 63596319 Test: make checkbuild, no manual changes, no functional changes Change-Id: I2397d55abc34c9b7a9b748bec6137778df3421a7 --- .../android/bluetooth/BluetoothCodecStatus.java | 50 ++++++++++++---------- 1 file changed, 27 insertions(+), 23 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index c8cd8d17ce..61e2941697 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -38,15 +38,15 @@ public final class BluetoothCodecStatus implements Parcelable { * profile. */ public static final String EXTRA_CODEC_STATUS = - "android.bluetooth.codec.extra.CODEC_STATUS"; + "android.bluetooth.codec.extra.CODEC_STATUS"; private final BluetoothCodecConfig mCodecConfig; private final BluetoothCodecConfig[] mCodecsLocalCapabilities; private final BluetoothCodecConfig[] mCodecsSelectableCapabilities; public BluetoothCodecStatus(BluetoothCodecConfig codecConfig, - BluetoothCodecConfig[] codecsLocalCapabilities, - BluetoothCodecConfig[] codecsSelectableCapabilities) { + BluetoothCodecConfig[] codecsLocalCapabilities, + BluetoothCodecConfig[] codecsSelectableCapabilities) { mCodecConfig = codecConfig; mCodecsLocalCapabilities = codecsLocalCapabilities; mCodecsSelectableCapabilities = codecsSelectableCapabilities; @@ -55,12 +55,12 @@ public final class BluetoothCodecStatus implements Parcelable { @Override public boolean equals(Object o) { if (o instanceof BluetoothCodecStatus) { - BluetoothCodecStatus other = (BluetoothCodecStatus)o; + BluetoothCodecStatus other = (BluetoothCodecStatus) o; return (Objects.equals(other.mCodecConfig, mCodecConfig) && Objects.equals(other.mCodecsLocalCapabilities, - mCodecsLocalCapabilities) && + mCodecsLocalCapabilities) && Objects.equals(other.mCodecsSelectableCapabilities, - mCodecsSelectableCapabilities)); + mCodecsSelectableCapabilities)); } return false; } @@ -68,15 +68,15 @@ public final class BluetoothCodecStatus implements Parcelable { @Override public int hashCode() { return Objects.hash(mCodecConfig, mCodecsLocalCapabilities, - mCodecsLocalCapabilities); + mCodecsLocalCapabilities); } @Override public String toString() { return "{mCodecConfig:" + mCodecConfig + - ",mCodecsLocalCapabilities:" + Arrays.toString(mCodecsLocalCapabilities) + - ",mCodecsSelectableCapabilities:" + Arrays.toString(mCodecsSelectableCapabilities) + - "}"; + ",mCodecsLocalCapabilities:" + Arrays.toString(mCodecsLocalCapabilities) + + ",mCodecsSelectableCapabilities:" + Arrays.toString(mCodecsSelectableCapabilities) + + "}"; } public int describeContents() { @@ -85,19 +85,23 @@ public final class BluetoothCodecStatus implements Parcelable { public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - public BluetoothCodecStatus createFromParcel(Parcel in) { - final BluetoothCodecConfig codecConfig = in.readTypedObject(BluetoothCodecConfig.CREATOR); - final BluetoothCodecConfig[] codecsLocalCapabilities = in.createTypedArray(BluetoothCodecConfig.CREATOR); - final BluetoothCodecConfig[] codecsSelectableCapabilities = in.createTypedArray(BluetoothCodecConfig.CREATOR); - - return new BluetoothCodecStatus(codecConfig, - codecsLocalCapabilities, - codecsSelectableCapabilities); - } - public BluetoothCodecStatus[] newArray(int size) { - return new BluetoothCodecStatus[size]; - } - }; + public BluetoothCodecStatus createFromParcel(Parcel in) { + final BluetoothCodecConfig codecConfig = in.readTypedObject( + BluetoothCodecConfig.CREATOR); + final BluetoothCodecConfig[] codecsLocalCapabilities = in.createTypedArray( + BluetoothCodecConfig.CREATOR); + final BluetoothCodecConfig[] codecsSelectableCapabilities = in.createTypedArray( + BluetoothCodecConfig.CREATOR); + + return new BluetoothCodecStatus(codecConfig, + codecsLocalCapabilities, + codecsSelectableCapabilities); + } + + public BluetoothCodecStatus[] newArray(int size) { + return new BluetoothCodecStatus[size]; + } + }; public void writeToParcel(Parcel out, int flags) { out.writeTypedObject(mCodecConfig, 0); -- cgit v1.2.3 From 9e045d26d0128826b40520f523307d8d16473779 Mon Sep 17 00:00:00 2001 From: Jack He Date: Tue, 22 Aug 2017 21:21:23 -0700 Subject: Fix checkstyle errors (2/2) * Manual style corrections with IDE assistance * Variable name refactors are done through IDE * Corrected general style errors such as: - "final private var" -> "private final var" - "&&", "+", "||" should not be at the end of line - Non-static private variable should be like "mVar" - Private static variable should be like "sVar" - Code file should always end with newline - Inherited methods should be annotated with @Override and no @hide tags - Public methods should always have a JavaDoc entry - "int[] array" is preferred over "int array[]" - private methods should be accessed without "this." when there is no name collisions. - "boolean ? true : false" -> boolean - "boolean ? false : true" -> !boolean - "boolean == true" OR "boolean != false" -> boolean - "boolean != true" OR "boolean == false" -> !boolean Bug: 63596319 Test: make checkbuild, no functional changes Change-Id: Iabdc2be912a32dd63a53213d175cf1bfef268ccd --- .../java/android/bluetooth/BluetoothCodecStatus.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index 61e2941697..7ae4cb7062 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -56,11 +56,10 @@ public final class BluetoothCodecStatus implements Parcelable { public boolean equals(Object o) { if (o instanceof BluetoothCodecStatus) { BluetoothCodecStatus other = (BluetoothCodecStatus) o; - return (Objects.equals(other.mCodecConfig, mCodecConfig) && - Objects.equals(other.mCodecsLocalCapabilities, - mCodecsLocalCapabilities) && - Objects.equals(other.mCodecsSelectableCapabilities, - mCodecsSelectableCapabilities)); + return (Objects.equals(other.mCodecConfig, mCodecConfig) + && Objects.equals(other.mCodecsLocalCapabilities, mCodecsLocalCapabilities) + && Objects.equals(other.mCodecsSelectableCapabilities, + mCodecsSelectableCapabilities)); } return false; } @@ -73,12 +72,13 @@ public final class BluetoothCodecStatus implements Parcelable { @Override public String toString() { - return "{mCodecConfig:" + mCodecConfig + - ",mCodecsLocalCapabilities:" + Arrays.toString(mCodecsLocalCapabilities) + - ",mCodecsSelectableCapabilities:" + Arrays.toString(mCodecsSelectableCapabilities) + - "}"; + return "{mCodecConfig:" + mCodecConfig + + ",mCodecsLocalCapabilities:" + Arrays.toString(mCodecsLocalCapabilities) + + ",mCodecsSelectableCapabilities:" + Arrays.toString(mCodecsSelectableCapabilities) + + "}"; } + @Override public int describeContents() { return 0; } @@ -103,6 +103,7 @@ public final class BluetoothCodecStatus implements Parcelable { } }; + @Override public void writeToParcel(Parcel out, int flags) { out.writeTypedObject(mCodecConfig, 0); out.writeTypedArray(mCodecsLocalCapabilities, 0); -- cgit v1.2.3 From 93e6d423f62546155b9316a399ab786f8d057dc5 Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Thu, 19 Apr 2018 14:16:15 -0700 Subject: Fix the implementation of BluetoothCodecStatus.equals() Previously, the BluetoothCodecStatus.equals() implementation was incorrect when comparing arrays of capabilities. In the new implementation, the arrays are compared correctly, and also the ordering of the capabilities in each array is ignored. Also, added unit tests for class BluetoothCodecConfig and class BluetoothCodecStatus. Bug: 73404858 Bug: 73379307 Test: Unit tests (in frameworks/base) runtest --path core/tests/bluetoothtests/src/android/bluetooth/BluetoothCodecConfigTest.java runtest --path core/tests/bluetoothtests/src/android/bluetooth/BluetoothCodecStatusTest.java Change-Id: If22087465397b7c4175c33f7d1909a15d957fb24 --- .../android/bluetooth/BluetoothCodecStatus.java | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index 7ae4cb7062..3a05e7093d 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -57,13 +57,35 @@ public final class BluetoothCodecStatus implements Parcelable { if (o instanceof BluetoothCodecStatus) { BluetoothCodecStatus other = (BluetoothCodecStatus) o; return (Objects.equals(other.mCodecConfig, mCodecConfig) - && Objects.equals(other.mCodecsLocalCapabilities, mCodecsLocalCapabilities) - && Objects.equals(other.mCodecsSelectableCapabilities, + && sameCapabilities(other.mCodecsLocalCapabilities, mCodecsLocalCapabilities) + && sameCapabilities(other.mCodecsSelectableCapabilities, mCodecsSelectableCapabilities)); } return false; } + /** + * Checks whether two arrays of capabilities contain same capabilities. + * The order of the capabilities in each array is ignored. + * + * @param c1 the first array of capabilities to compare + * @param c2 the second array of capabilities to compare + * @return true if both arrays contain same capabilities + */ + private static boolean sameCapabilities(BluetoothCodecConfig[] c1, + BluetoothCodecConfig[] c2) { + if (c1 == null) { + return (c2 == null); + } + if (c2 == null) { + return false; + } + if (c1.length != c2.length) { + return false; + } + return Arrays.asList(c1).containsAll(Arrays.asList(c2)); + } + @Override public int hashCode() { return Objects.hash(mCodecConfig, mCodecsLocalCapabilities, -- cgit v1.2.3 From 7d543894e0497651fc160728d659543483500f87 Mon Sep 17 00:00:00 2001 From: Mathew Inwood Date: Wed, 1 Aug 2018 15:07:20 +0100 Subject: Add @UnsupportedAppUsage annotations For packages: android.bluetooth.le android.bluetooth This is an automatically generated CL. See go/UnsupportedAppUsage for more details. Exempted-From-Owner-Approval: Mechanical changes to the codebase which have been approved by Android API council and announced on android-eng@ Bug: 110868826 Test: m Change-Id: Ifcf24c0617acd7facc0e03f30a95c3a6b09b205c Merged-In: I88a1311e27c5f9a5f9d1035db76034f86f650efc --- framework/java/android/bluetooth/BluetoothCodecStatus.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index 3a05e7093d..78560d2de4 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -16,6 +16,7 @@ package android.bluetooth; +import android.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; @@ -37,6 +38,7 @@ public final class BluetoothCodecStatus implements Parcelable { * This extra represents the current codec status of the A2DP * profile. */ + @UnsupportedAppUsage public static final String EXTRA_CODEC_STATUS = "android.bluetooth.codec.extra.CODEC_STATUS"; @@ -137,6 +139,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return the current codec configuration */ + @UnsupportedAppUsage public BluetoothCodecConfig getCodecConfig() { return mCodecConfig; } @@ -146,6 +149,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return an array with the codecs local capabilities */ + @UnsupportedAppUsage public BluetoothCodecConfig[] getCodecsLocalCapabilities() { return mCodecsLocalCapabilities; } @@ -155,6 +159,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return an array with the codecs selectable capabilities */ + @UnsupportedAppUsage public BluetoothCodecConfig[] getCodecsSelectableCapabilities() { return mCodecsSelectableCapabilities; } -- cgit v1.2.3 From de2b201ddbf64e0a14475155ce5635d829ea5692 Mon Sep 17 00:00:00 2001 From: Mathew Inwood Date: Wed, 1 Aug 2018 15:00:35 +0100 Subject: Add @UnsupportedAppUsage annotations For packages: android.bluetooth.le android.bluetooth This is an automatically generated CL. See go/UnsupportedAppUsage for more details. Exempted-From-Owner-Approval: Mechanical changes to the codebase which have been approved by Android API council and announced on android-eng@ Bug: 110868826 Test: m Change-Id: I88a1311e27c5f9a5f9d1035db76034f86f650efc --- framework/java/android/bluetooth/BluetoothCodecStatus.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index 3a05e7093d..78560d2de4 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -16,6 +16,7 @@ package android.bluetooth; +import android.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; @@ -37,6 +38,7 @@ public final class BluetoothCodecStatus implements Parcelable { * This extra represents the current codec status of the A2DP * profile. */ + @UnsupportedAppUsage public static final String EXTRA_CODEC_STATUS = "android.bluetooth.codec.extra.CODEC_STATUS"; @@ -137,6 +139,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return the current codec configuration */ + @UnsupportedAppUsage public BluetoothCodecConfig getCodecConfig() { return mCodecConfig; } @@ -146,6 +149,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return an array with the codecs local capabilities */ + @UnsupportedAppUsage public BluetoothCodecConfig[] getCodecsLocalCapabilities() { return mCodecsLocalCapabilities; } @@ -155,6 +159,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return an array with the codecs selectable capabilities */ + @UnsupportedAppUsage public BluetoothCodecConfig[] getCodecsSelectableCapabilities() { return mCodecsSelectableCapabilities; } -- cgit v1.2.3 From dfd389ca2c818b1c345f8858c357ee57ac1755b5 Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Fri, 14 Sep 2018 16:01:28 -0700 Subject: AudioDeviceBroker in audio service New AudioDeviceBroker class running in audio service. Has dedicated message loop for handling audio device connections and disconnections. New helper classes for AudioDeviceBroker: - BtHelper for Bluetooth - AudioDeviceInventory to manage list of devices Bug: 112863932 Test: media CTS + audio CTS Verifier Change-Id: I3e8f662a9d82fa7245695888e14fac7f4fc6e728 --- framework/java/android/bluetooth/BluetoothCodecStatus.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index 78560d2de4..2cb7b2d3c7 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -16,6 +16,7 @@ package android.bluetooth; +import android.annotation.Nullable; import android.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; @@ -42,7 +43,7 @@ public final class BluetoothCodecStatus implements Parcelable { public static final String EXTRA_CODEC_STATUS = "android.bluetooth.codec.extra.CODEC_STATUS"; - private final BluetoothCodecConfig mCodecConfig; + private final @Nullable BluetoothCodecConfig mCodecConfig; private final BluetoothCodecConfig[] mCodecsLocalCapabilities; private final BluetoothCodecConfig[] mCodecsSelectableCapabilities; @@ -140,7 +141,7 @@ public final class BluetoothCodecStatus implements Parcelable { * @return the current codec configuration */ @UnsupportedAppUsage - public BluetoothCodecConfig getCodecConfig() { + public @Nullable BluetoothCodecConfig getCodecConfig() { return mCodecConfig; } -- cgit v1.2.3 From 5075a69b222e323a8eb91fa1eb20a9f33068d3ff Mon Sep 17 00:00:00 2001 From: Ugo Yu Date: Mon, 25 Feb 2019 21:10:08 +0800 Subject: Change BluetoothCodecStatus.sameCapabilities() to public - Public this API to help A2DP state machine check selectable codec capabilities status. Bug: 124254557 Bug: 125551347 Test: runtest bluetooth Change-Id: If44887f756d2e8348e8f76dfb67b77b993ffd8db --- framework/java/android/bluetooth/BluetoothCodecStatus.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index 78560d2de4..32bb681f2e 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -74,8 +74,8 @@ public final class BluetoothCodecStatus implements Parcelable { * @param c2 the second array of capabilities to compare * @return true if both arrays contain same capabilities */ - private static boolean sameCapabilities(BluetoothCodecConfig[] c1, - BluetoothCodecConfig[] c2) { + public static boolean sameCapabilities(BluetoothCodecConfig[] c1, + BluetoothCodecConfig[] c2) { if (c1 == null) { return (c2 == null); } -- cgit v1.2.3 From 13613a3f176ab3e10367685367443dddeee77db5 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Thu, 28 Feb 2019 12:06:45 -0700 Subject: All Parcelable CREATOR fields are @NonNull. If they were null, then the Parcelable would fail to work. Bug: 126726802 Test: manual Change-Id: I7929ffa2f20e5de1c8e68e8263cca99496e9d014 Exempt-From-Owner-Approval: Trivial API annotations --- framework/java/android/bluetooth/BluetoothCodecStatus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index 2cb7b2d3c7..8eae2b4cf5 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -108,7 +108,7 @@ public final class BluetoothCodecStatus implements Parcelable { return 0; } - public static final Parcelable.Creator CREATOR = + public static final @android.annotation.NonNull Parcelable.Creator CREATOR = new Parcelable.Creator() { public BluetoothCodecStatus createFromParcel(Parcel in) { final BluetoothCodecConfig codecConfig = in.readTypedObject( -- cgit v1.2.3 From 38a8716ef8fc33e5c8915311b932d945c864ae85 Mon Sep 17 00:00:00 2001 From: Cheney Ni Date: Thu, 18 Jul 2019 21:45:10 +0800 Subject: 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 --- .../android/bluetooth/BluetoothCodecStatus.java | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') 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, -- cgit v1.2.3 From 4f8a2b36d14cf7beb64a51132d2352a28636eb93 Mon Sep 17 00:00:00 2001 From: Rahul Sabnis Date: Fri, 15 Nov 2019 16:08:54 -0800 Subject: Resolve BluetoothA2dp hidden APIs to resolve dependencies Bug: 143240341 Test: Manual Change-Id: Ib55e0fb106fa7b91ef4d3559da12ea2c048f1ae5 --- .../android/bluetooth/BluetoothCodecStatus.java | 42 +++++++++++++++------- 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index 58a764a85b..b6e77391da 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -17,7 +17,7 @@ package android.bluetooth; import android.annotation.Nullable; -import android.annotation.UnsupportedAppUsage; +import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; @@ -32,6 +32,7 @@ import java.util.Objects; * * {@hide} */ +@SystemApi public final class BluetoothCodecStatus implements Parcelable { /** * Extra for the codec configuration intents of the individual profiles. @@ -39,17 +40,16 @@ public final class BluetoothCodecStatus implements Parcelable { * This extra represents the current codec status of the A2DP * profile. */ - @UnsupportedAppUsage public static final String EXTRA_CODEC_STATUS = - "android.bluetooth.codec.extra.CODEC_STATUS"; + "android.bluetooth.extra.CODEC_STATUS"; private final @Nullable BluetoothCodecConfig mCodecConfig; private final BluetoothCodecConfig[] mCodecsLocalCapabilities; private final BluetoothCodecConfig[] mCodecsSelectableCapabilities; - public BluetoothCodecStatus(BluetoothCodecConfig codecConfig, - BluetoothCodecConfig[] codecsLocalCapabilities, - BluetoothCodecConfig[] codecsSelectableCapabilities) { + public BluetoothCodecStatus(@Nullable BluetoothCodecConfig codecConfig, + @Nullable BluetoothCodecConfig[] codecsLocalCapabilities, + @Nullable BluetoothCodecConfig[] codecsSelectableCapabilities) { mCodecConfig = codecConfig; mCodecsLocalCapabilities = codecsLocalCapabilities; mCodecsSelectableCapabilities = codecsSelectableCapabilities; @@ -74,6 +74,7 @@ public final class BluetoothCodecStatus implements Parcelable { * @param c1 the first array of capabilities to compare * @param c2 the second array of capabilities to compare * @return true if both arrays contain same capabilities + * @hide */ public static boolean sameCapabilities(BluetoothCodecConfig[] c1, BluetoothCodecConfig[] c2) { @@ -95,6 +96,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @param codecConfig the codec config to compare against * @return true if the codec config matches, otherwise false + * @hide */ public boolean isCodecConfigSelectable(BluetoothCodecConfig codecConfig) { if (codecConfig == null || !codecConfig.hasSingleSampleRate() @@ -125,7 +127,12 @@ public final class BluetoothCodecStatus implements Parcelable { return false; } - + /** + * Returns a hash based on the codec config and local capabilities + * + * @return a hash based on the config values + * @hide + */ @Override public int hashCode() { return Objects.hash(mCodecConfig, mCodecsLocalCapabilities, @@ -140,6 +147,12 @@ public final class BluetoothCodecStatus implements Parcelable { + "}"; } + /** + * Always returns 0 + * + * @return 0 + * @hide + */ @Override public int describeContents() { return 0; @@ -165,6 +178,14 @@ public final class BluetoothCodecStatus implements Parcelable { } }; + /** + * Flattens the object to a parcel + * + * @param out The Parcel in which the object should be written. + * @param flags Additional flags about how the object should be written. + * + * @hide + */ @Override public void writeToParcel(Parcel out, int flags) { out.writeTypedObject(mCodecConfig, 0); @@ -177,7 +198,6 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return the current codec configuration */ - @UnsupportedAppUsage public @Nullable BluetoothCodecConfig getCodecConfig() { return mCodecConfig; } @@ -187,8 +207,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return an array with the codecs local capabilities */ - @UnsupportedAppUsage - public BluetoothCodecConfig[] getCodecsLocalCapabilities() { + public @Nullable BluetoothCodecConfig[] getCodecsLocalCapabilities() { return mCodecsLocalCapabilities; } @@ -197,8 +216,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return an array with the codecs selectable capabilities */ - @UnsupportedAppUsage - public BluetoothCodecConfig[] getCodecsSelectableCapabilities() { + public @Nullable BluetoothCodecConfig[] getCodecsSelectableCapabilities() { return mCodecsSelectableCapabilities; } } -- cgit v1.2.3 From ce594994e8aa1b4bf9a6917e18c4f2f3b68c1ddc Mon Sep 17 00:00:00 2001 From: Rahul Sabnis Date: Wed, 18 Mar 2020 17:46:33 -0700 Subject: Add BLUETOOTH_PRIVILEGED permission as a requirement for all new Bluetooth SystemApis and for hidden connect/disconnect APIs. Hide some APIs that were previously marked as @UnsupportedAppUsage and re-add annotation as changing the permissions for these SystemApis would break the unsupported app contract that was previously there. Therefore, we're choosing to hide them until we have a good story on how to deal with them next release. Bug: 148689314 Test: Manual Change-Id: I33ee2c7ccd3827db3d23d6447cf82d9ffc36836a --- framework/java/android/bluetooth/BluetoothCodecStatus.java | 2 -- 1 file changed, 2 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index b6e77391da..1e394b830d 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -17,7 +17,6 @@ package android.bluetooth; import android.annotation.Nullable; -import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; @@ -32,7 +31,6 @@ import java.util.Objects; * * {@hide} */ -@SystemApi public final class BluetoothCodecStatus implements Parcelable { /** * Extra for the codec configuration intents of the individual profiles. -- cgit v1.2.3 From f12655cc803675060d87665b8f6685d5c4816431 Mon Sep 17 00:00:00 2001 From: Rahul Sabnis Date: Mon, 21 Sep 2020 20:50:10 -0700 Subject: Move all BluetoothCodecConfig and BluetoothCodecStatus APIs moved from the non-SDK API list to the blocklist in Android 11 back to the non-SDK API list. Tag: #feature Bug: 168812851 Test: atest BluetoothHostTest#testCodecMethodsAccessible Change-Id: I29983284b1a1c271d983c99b286e204604abdc72 --- framework/java/android/bluetooth/BluetoothCodecStatus.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index 1e394b830d..7b567b4098 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -17,6 +17,7 @@ package android.bluetooth; import android.annotation.Nullable; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; @@ -38,6 +39,7 @@ public final class BluetoothCodecStatus implements Parcelable { * This extra represents the current codec status of the A2DP * profile. */ + @UnsupportedAppUsage public static final String EXTRA_CODEC_STATUS = "android.bluetooth.extra.CODEC_STATUS"; @@ -196,6 +198,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return the current codec configuration */ + @UnsupportedAppUsage public @Nullable BluetoothCodecConfig getCodecConfig() { return mCodecConfig; } @@ -205,6 +208,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return an array with the codecs local capabilities */ + @UnsupportedAppUsage public @Nullable BluetoothCodecConfig[] getCodecsLocalCapabilities() { return mCodecsLocalCapabilities; } @@ -214,6 +218,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return an array with the codecs selectable capabilities */ + @UnsupportedAppUsage public @Nullable BluetoothCodecConfig[] getCodecsSelectableCapabilities() { return mCodecsSelectableCapabilities; } -- cgit v1.2.3 From 2883f7ab9e740b5da3c872b9fe675691ddfc322d Mon Sep 17 00:00:00 2001 From: Roman Kalukiewicz Date: Wed, 14 Oct 2020 15:59:06 -0700 Subject: Add @Nullable annotation to the parameter of Object.equals() methods. Those annotations could be inferred by some tools (like Kotlin), but the https://checkerframework.org/ doesn't check inherited annotations complaining about all equals() invocations that get nullable argument. The change was generated by running find . -name \*.java | xargs sed -i 's/public boolean equals(Object /public boolean equals(@Nullable Object /' in the frameworks/base directory and by automatically adding and formatting required imports if needed. No manual edits. Bug: 170883422 Test: Annotation change only. Should have not impact. Exempt-From-Owner-Approval: Mechanical change not specific to any component. Change-Id: I5eedb571c9d78862115dfdc5dae1cf2a35343580 --- framework/java/android/bluetooth/BluetoothCodecStatus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index 7b567b4098..7764ebeb2e 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -56,7 +56,7 @@ public final class BluetoothCodecStatus implements Parcelable { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (o instanceof BluetoothCodecStatus) { BluetoothCodecStatus other = (BluetoothCodecStatus) o; return (Objects.equals(other.mCodecConfig, mCodecConfig) -- cgit v1.2.3 From bc9a809f18a3b0ec23cbc39802fb4928c2074ea3 Mon Sep 17 00:00:00 2001 From: Mathew Inwood Date: Tue, 27 Oct 2020 11:47:29 +0000 Subject: Add maxTargetSdk restriction to unused APIs. These are APIs that have @UnsupportedAppUsage but for which we don't have any evidence of them currently being used, so should be safe to remove from the unsupported list. Bug: 170729553 Test: Treehugger Change-Id: I4c8fd0006f950de9955242e93968fb0996ceb372 --- framework/java/android/bluetooth/BluetoothCodecStatus.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index 7764ebeb2e..3a65aaa0d1 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -18,6 +18,7 @@ package android.bluetooth; import android.annotation.Nullable; import android.compat.annotation.UnsupportedAppUsage; +import android.os.Build; import android.os.Parcel; import android.os.Parcelable; @@ -39,7 +40,7 @@ public final class BluetoothCodecStatus implements Parcelable { * This extra represents the current codec status of the A2DP * profile. */ - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public static final String EXTRA_CODEC_STATUS = "android.bluetooth.extra.CODEC_STATUS"; @@ -198,7 +199,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return the current codec configuration */ - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public @Nullable BluetoothCodecConfig getCodecConfig() { return mCodecConfig; } @@ -208,7 +209,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return an array with the codecs local capabilities */ - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public @Nullable BluetoothCodecConfig[] getCodecsLocalCapabilities() { return mCodecsLocalCapabilities; } @@ -218,7 +219,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return an array with the codecs selectable capabilities */ - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public @Nullable BluetoothCodecConfig[] getCodecsSelectableCapabilities() { return mCodecsSelectableCapabilities; } -- cgit v1.2.3 From bddbb77484a3694357df750c5e7df9527f409c8a Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Wed, 28 Oct 2020 19:38:11 +0000 Subject: Revert "Add maxTargetSdk restriction to unused APIs." This reverts commit bc9a809f18a3b0ec23cbc39802fb4928c2074ea3. Reason for revert: Droidcop-triggered revert due to breakage https://android-build.googleplex.com/builds/quarterdeck?testMethod=testAppZygotePreload&testClass=android.app.cts.ServiceTest&atpConfigName=suite%2Ftest-mapping-presubmit-retry_cloud-tf&testModule=CtsAppTestCases&fkbb=6936597&lkbb=6936969&lkgb=6936551&testResults=true&branch=git_master&target=cf_x86_phone-userdebug>, bug b/171886397 Bug: 171886397 Change-Id: Ibe0f0430a3451477c1ee8ef56a596e91ea1e7672 --- framework/java/android/bluetooth/BluetoothCodecStatus.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index 3a65aaa0d1..7764ebeb2e 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -18,7 +18,6 @@ package android.bluetooth; import android.annotation.Nullable; import android.compat.annotation.UnsupportedAppUsage; -import android.os.Build; import android.os.Parcel; import android.os.Parcelable; @@ -40,7 +39,7 @@ public final class BluetoothCodecStatus implements Parcelable { * This extra represents the current codec status of the A2DP * profile. */ - @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) + @UnsupportedAppUsage public static final String EXTRA_CODEC_STATUS = "android.bluetooth.extra.CODEC_STATUS"; @@ -199,7 +198,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return the current codec configuration */ - @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) + @UnsupportedAppUsage public @Nullable BluetoothCodecConfig getCodecConfig() { return mCodecConfig; } @@ -209,7 +208,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return an array with the codecs local capabilities */ - @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) + @UnsupportedAppUsage public @Nullable BluetoothCodecConfig[] getCodecsLocalCapabilities() { return mCodecsLocalCapabilities; } @@ -219,7 +218,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return an array with the codecs selectable capabilities */ - @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) + @UnsupportedAppUsage public @Nullable BluetoothCodecConfig[] getCodecsSelectableCapabilities() { return mCodecsSelectableCapabilities; } -- cgit v1.2.3 From cba870b777fc6d2a03a27758cf1db1c38556efe8 Mon Sep 17 00:00:00 2001 From: Mathew Inwood Date: Tue, 27 Oct 2020 11:47:29 +0000 Subject: Add maxTargetSdk restriction to unused APIs. These are APIs that have @UnsupportedAppUsage but for which we don't have any evidence of them currently being used, so should be safe to remove from the unsupported list. This is a resubmit of ag/12929664 with some APIs excluded that caused test failures; see bugs 171886397, 171888296, 171864568. APIs excluded: Landroid/bluetooth/le/ScanRecord;->parseFromBytes([B)Landroid/bluetooth/le/ScanRecord; Landroid/os/Process;->myPpid()I Landroid/os/SharedMemory;->getFd()I Landroid/hardware/input/InputManager;->INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH:I Bug: 170729553 Test: Treehugger Change-Id: I8285daa8530260251ecad6f3f38f98e263629ca7 --- framework/java/android/bluetooth/BluetoothCodecStatus.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index 7764ebeb2e..3a65aaa0d1 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -18,6 +18,7 @@ package android.bluetooth; import android.annotation.Nullable; import android.compat.annotation.UnsupportedAppUsage; +import android.os.Build; import android.os.Parcel; import android.os.Parcelable; @@ -39,7 +40,7 @@ public final class BluetoothCodecStatus implements Parcelable { * This extra represents the current codec status of the A2DP * profile. */ - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public static final String EXTRA_CODEC_STATUS = "android.bluetooth.extra.CODEC_STATUS"; @@ -198,7 +199,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return the current codec configuration */ - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public @Nullable BluetoothCodecConfig getCodecConfig() { return mCodecConfig; } @@ -208,7 +209,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return an array with the codecs local capabilities */ - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public @Nullable BluetoothCodecConfig[] getCodecsLocalCapabilities() { return mCodecsLocalCapabilities; } @@ -218,7 +219,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return an array with the codecs selectable capabilities */ - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public @Nullable BluetoothCodecConfig[] getCodecsSelectableCapabilities() { return mCodecsSelectableCapabilities; } -- cgit v1.2.3 From b91f59cfb53b0821df3f69cd60f635f9c21db4c6 Mon Sep 17 00:00:00 2001 From: Mathew Inwood Date: Wed, 4 Nov 2020 09:42:27 +0000 Subject: De-restrict BluetoothCodecStatus hidden APIs. They were erroneously included in b/170729553 but should not have been. Tag: #feature Test: Manual Change-Id: Ia3bd3b55de19a89d41a025dc0e03dec850c1ab07 --- framework/java/android/bluetooth/BluetoothCodecStatus.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index 3a65aaa0d1..7764ebeb2e 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -18,7 +18,6 @@ package android.bluetooth; import android.annotation.Nullable; import android.compat.annotation.UnsupportedAppUsage; -import android.os.Build; import android.os.Parcel; import android.os.Parcelable; @@ -40,7 +39,7 @@ public final class BluetoothCodecStatus implements Parcelable { * This extra represents the current codec status of the A2DP * profile. */ - @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) + @UnsupportedAppUsage public static final String EXTRA_CODEC_STATUS = "android.bluetooth.extra.CODEC_STATUS"; @@ -199,7 +198,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return the current codec configuration */ - @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) + @UnsupportedAppUsage public @Nullable BluetoothCodecConfig getCodecConfig() { return mCodecConfig; } @@ -209,7 +208,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return an array with the codecs local capabilities */ - @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) + @UnsupportedAppUsage public @Nullable BluetoothCodecConfig[] getCodecsLocalCapabilities() { return mCodecsLocalCapabilities; } @@ -219,7 +218,7 @@ public final class BluetoothCodecStatus implements Parcelable { * * @return an array with the codecs selectable capabilities */ - @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) + @UnsupportedAppUsage public @Nullable BluetoothCodecConfig[] getCodecsSelectableCapabilities() { return mCodecsSelectableCapabilities; } -- cgit v1.2.3 From 55a03869afdab02fd0737daf3f78151959e0d32c Mon Sep 17 00:00:00 2001 From: Etienne Ruffieux Date: Tue, 5 Oct 2021 17:11:45 +0000 Subject: Make BluetoothCodecConfig and BluetoothCodecStatus public. Made BluetoothCodecConfig and BluetoothCodecStatus public, added Builder to BluetoothCodecConfig, added accessor for SOURCE_CODEC_TYPE_MAX and changed Arrays returns to List. Tag: #feature Bug: 200202780 Bug: 170678351 Test: BluetoothCodecConfigTest & BluetoothCodecStatusTest NoNonSdkCheck: Only user actually requested the changes Change-Id: Ic61b7087f53f45781f7e0eecca8b6d983093a22d --- .../android/bluetooth/BluetoothCodecStatus.java | 111 +++++++++------------ 1 file changed, 47 insertions(+), 64 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java index 7764ebeb2e..02606feb3b 100644 --- a/framework/java/android/bluetooth/BluetoothCodecStatus.java +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -16,12 +16,13 @@ package android.bluetooth; +import android.annotation.NonNull; import android.annotation.Nullable; -import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; -import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.Objects; /** @@ -29,8 +30,6 @@ import java.util.Objects; * A2DP source device. * * {@see BluetoothA2dp} - * - * {@hide} */ public final class BluetoothCodecStatus implements Parcelable { /** @@ -39,22 +38,27 @@ public final class BluetoothCodecStatus implements Parcelable { * This extra represents the current codec status of the A2DP * profile. */ - @UnsupportedAppUsage public static final String EXTRA_CODEC_STATUS = "android.bluetooth.extra.CODEC_STATUS"; private final @Nullable BluetoothCodecConfig mCodecConfig; - private final BluetoothCodecConfig[] mCodecsLocalCapabilities; - private final BluetoothCodecConfig[] mCodecsSelectableCapabilities; + private final @Nullable List mCodecsLocalCapabilities; + private final @Nullable List mCodecsSelectableCapabilities; public BluetoothCodecStatus(@Nullable BluetoothCodecConfig codecConfig, - @Nullable BluetoothCodecConfig[] codecsLocalCapabilities, - @Nullable BluetoothCodecConfig[] codecsSelectableCapabilities) { + @Nullable List codecsLocalCapabilities, + @Nullable List codecsSelectableCapabilities) { mCodecConfig = codecConfig; mCodecsLocalCapabilities = codecsLocalCapabilities; mCodecsSelectableCapabilities = codecsSelectableCapabilities; } + private BluetoothCodecStatus(Parcel in) { + mCodecConfig = in.readTypedObject(BluetoothCodecConfig.CREATOR); + mCodecsLocalCapabilities = in.createTypedArrayList(BluetoothCodecConfig.CREATOR); + mCodecsSelectableCapabilities = in.createTypedArrayList(BluetoothCodecConfig.CREATOR); + } + @Override public boolean equals(@Nullable Object o) { if (o instanceof BluetoothCodecStatus) { @@ -68,26 +72,25 @@ public final class BluetoothCodecStatus implements Parcelable { } /** - * Checks whether two arrays of capabilities contain same capabilities. - * The order of the capabilities in each array is ignored. + * Checks whether two lists of capabilities contain same capabilities. + * The order of the capabilities in each list is ignored. * - * @param c1 the first array of capabilities to compare - * @param c2 the second array of capabilities to compare - * @return true if both arrays contain same capabilities - * @hide + * @param c1 the first list of capabilities to compare + * @param c2 the second list of capabilities to compare + * @return {@code true} if both lists contain same capabilities */ - public static boolean sameCapabilities(BluetoothCodecConfig[] c1, - BluetoothCodecConfig[] c2) { + private static boolean sameCapabilities(@Nullable List c1, + @Nullable List c2) { if (c1 == null) { return (c2 == null); } if (c2 == null) { return false; } - if (c1.length != c2.length) { + if (c1.size() != c2.size()) { return false; } - return Arrays.asList(c1).containsAll(Arrays.asList(c2)); + return c1.containsAll(c2); } /** @@ -95,10 +98,9 @@ public final class BluetoothCodecStatus implements Parcelable { * 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 - * @hide + * @return {@code true} if the codec config matches, {@code false} otherwise */ - public boolean isCodecConfigSelectable(BluetoothCodecConfig codecConfig) { + public boolean isCodecConfigSelectable(@Nullable BluetoothCodecConfig codecConfig) { if (codecConfig == null || !codecConfig.hasSingleSampleRate() || !codecConfig.hasSingleBitsPerSample() || !codecConfig.hasSingleChannelMode()) { return false; @@ -128,10 +130,7 @@ public final class BluetoothCodecStatus implements Parcelable { } /** - * Returns a hash based on the codec config and local capabilities - * - * @return a hash based on the config values - * @hide + * Returns a hash based on the codec config and local capabilities. */ @Override public int hashCode() { @@ -139,17 +138,19 @@ public final class BluetoothCodecStatus implements Parcelable { mCodecsLocalCapabilities); } + /** + * Returns a {@link String} that describes each BluetoothCodecStatus parameter + * current value. + */ @Override public String toString() { return "{mCodecConfig:" + mCodecConfig - + ",mCodecsLocalCapabilities:" + Arrays.toString(mCodecsLocalCapabilities) - + ",mCodecsSelectableCapabilities:" + Arrays.toString(mCodecsSelectableCapabilities) + + ",mCodecsLocalCapabilities:" + mCodecsLocalCapabilities + + ",mCodecsSelectableCapabilities:" + mCodecsSelectableCapabilities + "}"; } /** - * Always returns 0 - * * @return 0 * @hide */ @@ -161,16 +162,7 @@ public final class BluetoothCodecStatus implements Parcelable { public static final @android.annotation.NonNull Parcelable.Creator CREATOR = new Parcelable.Creator() { public BluetoothCodecStatus createFromParcel(Parcel in) { - final BluetoothCodecConfig codecConfig = in.readTypedObject( - BluetoothCodecConfig.CREATOR); - final BluetoothCodecConfig[] codecsLocalCapabilities = in.createTypedArray( - BluetoothCodecConfig.CREATOR); - final BluetoothCodecConfig[] codecsSelectableCapabilities = in.createTypedArray( - BluetoothCodecConfig.CREATOR); - - return new BluetoothCodecStatus(codecConfig, - codecsLocalCapabilities, - codecsSelectableCapabilities); + return new BluetoothCodecStatus(in); } public BluetoothCodecStatus[] newArray(int size) { @@ -179,47 +171,38 @@ public final class BluetoothCodecStatus implements Parcelable { }; /** - * Flattens the object to a parcel + * Flattens the object to a parcel. * - * @param out The Parcel in which the object should be written. - * @param flags Additional flags about how the object should be written. - * - * @hide + * @param out The Parcel in which the object should be written + * @param flags Additional flags about how the object should be written */ @Override - public void writeToParcel(Parcel out, int flags) { + public void writeToParcel(@NonNull Parcel out, int flags) { out.writeTypedObject(mCodecConfig, 0); - out.writeTypedArray(mCodecsLocalCapabilities, 0); - out.writeTypedArray(mCodecsSelectableCapabilities, 0); + out.writeTypedList(mCodecsLocalCapabilities); + out.writeTypedList(mCodecsSelectableCapabilities); } /** - * Gets the current codec configuration. - * - * @return the current codec configuration + * Returns the current codec configuration. */ - @UnsupportedAppUsage public @Nullable BluetoothCodecConfig getCodecConfig() { return mCodecConfig; } /** - * Gets the codecs local capabilities. - * - * @return an array with the codecs local capabilities + * Returns the codecs local capabilities. */ - @UnsupportedAppUsage - public @Nullable BluetoothCodecConfig[] getCodecsLocalCapabilities() { - return mCodecsLocalCapabilities; + public @NonNull List getCodecsLocalCapabilities() { + return (mCodecsLocalCapabilities == null) + ? Collections.emptyList() : mCodecsLocalCapabilities; } /** - * Gets the codecs selectable capabilities. - * - * @return an array with the codecs selectable capabilities + * Returns the codecs selectable capabilities. */ - @UnsupportedAppUsage - public @Nullable BluetoothCodecConfig[] getCodecsSelectableCapabilities() { - return mCodecsSelectableCapabilities; + public @NonNull List getCodecsSelectableCapabilities() { + return (mCodecsSelectableCapabilities == null) + ? Collections.emptyList() : mCodecsSelectableCapabilities; } } -- cgit v1.2.3