Merge "Resolve BluetoothA2dp hidden APIs to resolve dependencies" am: 67eae9d7ba

am: 5ae6e7adc1

Change-Id: Ibdf41e956337808e63130db9e6101efa0382a4f1
This commit is contained in:
Rahul Sabnis
2019-12-09 11:44:02 -08:00
committed by android-build-merger
5 changed files with 286 additions and 98 deletions

View File

@@ -1251,8 +1251,22 @@ package android.app.usage {
package android.bluetooth { package android.bluetooth {
public final class BluetoothA2dp implements android.bluetooth.BluetoothProfile { public final class BluetoothA2dp implements android.bluetooth.BluetoothProfile {
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public void disableOptionalCodecs(@Nullable android.bluetooth.BluetoothDevice);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public void enableOptionalCodecs(@Nullable android.bluetooth.BluetoothDevice);
method @Nullable @RequiresPermission(android.Manifest.permission.BLUETOOTH) public android.bluetooth.BluetoothDevice getActiveDevice();
method @Nullable @RequiresPermission(android.Manifest.permission.BLUETOOTH) public android.bluetooth.BluetoothCodecStatus getCodecStatus(@Nullable android.bluetooth.BluetoothDevice);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public int getConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice); method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public int getConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public int getOptionalCodecsEnabled(@Nullable android.bluetooth.BluetoothDevice);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public void setCodecConfigPreference(@Nullable android.bluetooth.BluetoothDevice, @Nullable android.bluetooth.BluetoothCodecConfig);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean setConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice, int); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean setConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice, int);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public void setOptionalCodecsEnabled(@Nullable android.bluetooth.BluetoothDevice, int);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public int supportsOptionalCodecs(@Nullable android.bluetooth.BluetoothDevice);
field public static final int OPTIONAL_CODECS_NOT_SUPPORTED = 0; // 0x0
field public static final int OPTIONAL_CODECS_PREF_DISABLED = 0; // 0x0
field public static final int OPTIONAL_CODECS_PREF_ENABLED = 1; // 0x1
field public static final int OPTIONAL_CODECS_PREF_UNKNOWN = -1; // 0xffffffff
field public static final int OPTIONAL_CODECS_SUPPORTED = 1; // 0x1
field public static final int OPTIONAL_CODECS_SUPPORT_UNKNOWN = -1; // 0xffffffff
} }
public final class BluetoothAdapter { public final class BluetoothAdapter {
@@ -1281,6 +1295,52 @@ package android.bluetooth {
method public void onMetadataChanged(@NonNull android.bluetooth.BluetoothDevice, int, @Nullable byte[]); method public void onMetadataChanged(@NonNull android.bluetooth.BluetoothDevice, int, @Nullable byte[]);
} }
public final class BluetoothCodecConfig implements android.os.Parcelable {
ctor public BluetoothCodecConfig(int, int, int, int, int, long, long, long, long);
ctor public BluetoothCodecConfig(int);
method public int getBitsPerSample();
method @NonNull public String getCodecName();
method public int getCodecPriority();
method public long getCodecSpecific1();
method public int getCodecType();
method public int getSampleRate();
method public boolean isMandatoryCodec();
field public static final int BITS_PER_SAMPLE_16 = 1; // 0x1
field public static final int BITS_PER_SAMPLE_24 = 2; // 0x2
field public static final int BITS_PER_SAMPLE_32 = 4; // 0x4
field public static final int BITS_PER_SAMPLE_NONE = 0; // 0x0
field public static final int CHANNEL_MODE_MONO = 1; // 0x1
field public static final int CHANNEL_MODE_NONE = 0; // 0x0
field public static final int CHANNEL_MODE_STEREO = 2; // 0x2
field public static final int CODEC_PRIORITY_DEFAULT = 0; // 0x0
field public static final int CODEC_PRIORITY_DISABLED = -1; // 0xffffffff
field public static final int CODEC_PRIORITY_HIGHEST = 1000000; // 0xf4240
field @NonNull public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothCodecConfig> CREATOR;
field public static final int SAMPLE_RATE_176400 = 16; // 0x10
field public static final int SAMPLE_RATE_192000 = 32; // 0x20
field public static final int SAMPLE_RATE_44100 = 1; // 0x1
field public static final int SAMPLE_RATE_48000 = 2; // 0x2
field public static final int SAMPLE_RATE_88200 = 4; // 0x4
field public static final int SAMPLE_RATE_96000 = 8; // 0x8
field public static final int SAMPLE_RATE_NONE = 0; // 0x0
field public static final int SOURCE_CODEC_TYPE_AAC = 1; // 0x1
field public static final int SOURCE_CODEC_TYPE_APTX = 2; // 0x2
field public static final int SOURCE_CODEC_TYPE_APTX_HD = 3; // 0x3
field public static final int SOURCE_CODEC_TYPE_INVALID = 1000000; // 0xf4240
field public static final int SOURCE_CODEC_TYPE_LDAC = 4; // 0x4
field public static final int SOURCE_CODEC_TYPE_MAX = 5; // 0x5
field public static final int SOURCE_CODEC_TYPE_SBC = 0; // 0x0
}
public final class BluetoothCodecStatus implements android.os.Parcelable {
ctor public BluetoothCodecStatus(@Nullable android.bluetooth.BluetoothCodecConfig, @Nullable android.bluetooth.BluetoothCodecConfig[], @Nullable android.bluetooth.BluetoothCodecConfig[]);
method @Nullable public android.bluetooth.BluetoothCodecConfig getCodecConfig();
method @Nullable public android.bluetooth.BluetoothCodecConfig[] getCodecsLocalCapabilities();
method @Nullable public android.bluetooth.BluetoothCodecConfig[] getCodecsSelectableCapabilities();
field @NonNull public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothCodecStatus> CREATOR;
field public static final String EXTRA_CODEC_STATUS = "android.bluetooth.extra.CODEC_STATUS";
}
public final class BluetoothDevice implements android.os.Parcelable { public final class BluetoothDevice implements android.os.Parcelable {
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean cancelBondProcess(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean cancelBondProcess();
method @Nullable @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public byte[] getMetadata(int); method @Nullable @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public byte[] getMetadata(int);

View File

@@ -17,6 +17,7 @@
package android.bluetooth; package android.bluetooth;
import android.Manifest; import android.Manifest;
import android.annotation.IntDef;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.RequiresPermission; import android.annotation.RequiresPermission;
@@ -32,6 +33,8 @@ import android.os.ParcelUuid;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.Log; import android.util.Log;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -154,13 +157,22 @@ public final class BluetoothA2dp implements BluetoothProfile {
*/ */
public static final int STATE_NOT_PLAYING = 11; public static final int STATE_NOT_PLAYING = 11;
/** @hide */
@IntDef(prefix = "OPTIONAL_CODECS_", value = {
OPTIONAL_CODECS_SUPPORT_UNKNOWN,
OPTIONAL_CODECS_NOT_SUPPORTED,
OPTIONAL_CODECS_SUPPORTED
})
@Retention(RetentionPolicy.SOURCE)
public @interface OptionalCodecsSupportStatus {}
/** /**
* We don't have a stored preference for whether or not the given A2DP sink device supports * We don't have a stored preference for whether or not the given A2DP sink device supports
* optional codecs. * optional codecs.
* *
* @hide * @hide
*/ */
@UnsupportedAppUsage @SystemApi
public static final int OPTIONAL_CODECS_SUPPORT_UNKNOWN = -1; public static final int OPTIONAL_CODECS_SUPPORT_UNKNOWN = -1;
/** /**
@@ -168,7 +180,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
* *
* @hide * @hide
*/ */
@UnsupportedAppUsage @SystemApi
public static final int OPTIONAL_CODECS_NOT_SUPPORTED = 0; public static final int OPTIONAL_CODECS_NOT_SUPPORTED = 0;
/** /**
@@ -176,16 +188,25 @@ public final class BluetoothA2dp implements BluetoothProfile {
* *
* @hide * @hide
*/ */
@UnsupportedAppUsage @SystemApi
public static final int OPTIONAL_CODECS_SUPPORTED = 1; public static final int OPTIONAL_CODECS_SUPPORTED = 1;
/** @hide */
@IntDef(prefix = "OPTIONAL_CODECS_PREF_", value = {
OPTIONAL_CODECS_PREF_UNKNOWN,
OPTIONAL_CODECS_PREF_DISABLED,
OPTIONAL_CODECS_PREF_ENABLED
})
@Retention(RetentionPolicy.SOURCE)
public @interface OptionalCodecsPreferenceStatus {}
/** /**
* We don't have a stored preference for whether optional codecs should be enabled or disabled * We don't have a stored preference for whether optional codecs should be enabled or
* for the given A2DP device. * disabled for the given A2DP device.
* *
* @hide * @hide
*/ */
@UnsupportedAppUsage @SystemApi
public static final int OPTIONAL_CODECS_PREF_UNKNOWN = -1; public static final int OPTIONAL_CODECS_PREF_UNKNOWN = -1;
/** /**
@@ -193,7 +214,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
* *
* @hide * @hide
*/ */
@UnsupportedAppUsage @SystemApi
public static final int OPTIONAL_CODECS_PREF_DISABLED = 0; public static final int OPTIONAL_CODECS_PREF_DISABLED = 0;
/** /**
@@ -201,7 +222,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
* *
* @hide * @hide
*/ */
@UnsupportedAppUsage @SystemApi
public static final int OPTIONAL_CODECS_PREF_ENABLED = 1; public static final int OPTIONAL_CODECS_PREF_ENABLED = 1;
private BluetoothAdapter mAdapter; private BluetoothAdapter mAdapter;
@@ -248,13 +269,12 @@ public final class BluetoothA2dp implements BluetoothProfile {
* the state. Users can get the connection state of the profile * the state. Users can get the connection state of the profile
* from this intent. * from this intent.
* *
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
* permission.
* *
* @param device Remote Bluetooth Device * @param device Remote Bluetooth Device
* @return false on immediate error, true otherwise * @return false on immediate error, true otherwise
* @hide * @hide
*/ */
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
@UnsupportedAppUsage @UnsupportedAppUsage
public boolean connect(BluetoothDevice device) { public boolean connect(BluetoothDevice device) {
if (DBG) log("connect(" + device + ")"); if (DBG) log("connect(" + device + ")");
@@ -289,13 +309,12 @@ public final class BluetoothA2dp implements BluetoothProfile {
* {@link #STATE_DISCONNECTING} can be used to distinguish between the * {@link #STATE_DISCONNECTING} can be used to distinguish between the
* two scenarios. * two scenarios.
* *
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
* permission.
* *
* @param device Remote Bluetooth Device * @param device Remote Bluetooth Device
* @return false on immediate error, true otherwise * @return false on immediate error, true otherwise
* @hide * @hide
*/ */
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
@UnsupportedAppUsage @UnsupportedAppUsage
public boolean disconnect(BluetoothDevice device) { public boolean disconnect(BluetoothDevice device) {
if (DBG) log("disconnect(" + device + ")"); if (DBG) log("disconnect(" + device + ")");
@@ -384,14 +403,12 @@ public final class BluetoothA2dp implements BluetoothProfile {
* {@link #ACTION_ACTIVE_DEVICE_CHANGED} intent will be broadcasted * {@link #ACTION_ACTIVE_DEVICE_CHANGED} intent will be broadcasted
* with the active device. * with the active device.
* *
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
* permission.
*
* @param device the remote Bluetooth device. Could be null to clear * @param device the remote Bluetooth device. Could be null to clear
* the active device and stop streaming audio to a Bluetooth device. * the active device and stop streaming audio to a Bluetooth device.
* @return false on immediate error, true otherwise * @return false on immediate error, true otherwise
* @hide * @hide
*/ */
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
@UnsupportedAppUsage @UnsupportedAppUsage
public boolean setActiveDevice(@Nullable BluetoothDevice device) { public boolean setActiveDevice(@Nullable BluetoothDevice device) {
if (DBG) log("setActiveDevice(" + device + ")"); if (DBG) log("setActiveDevice(" + device + ")");
@@ -412,16 +429,13 @@ public final class BluetoothA2dp implements BluetoothProfile {
/** /**
* Get the connected device that is active. * Get the connected device that is active.
* *
* <p>Requires {@link android.Manifest.permission#BLUETOOTH}
* permission.
*
* @return the connected device that is active or null if no device * @return the connected device that is active or null if no device
* is active * is active
* @hide * @hide
*/ */
@RequiresPermission(Manifest.permission.BLUETOOTH) @SystemApi
@Nullable @Nullable
@UnsupportedAppUsage @RequiresPermission(Manifest.permission.BLUETOOTH)
public BluetoothDevice getActiveDevice() { public BluetoothDevice getActiveDevice() {
if (VDBG) log("getActiveDevice()"); if (VDBG) log("getActiveDevice()");
try { try {
@@ -441,7 +455,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
* Set priority of the profile * Set priority of the profile
* *
* <p> The device should already be paired. * <p> The device should already be paired.
* Priority can be one of {@link #PRIORITY_ON} or {@link #PRIORITY_OFF}, * Priority can be one of {@link #PRIORITY_ON} or {@link #PRIORITY_OFF}
* *
* @param device Paired bluetooth device * @param device Paired bluetooth device
* @param priority * @param priority
@@ -626,8 +640,10 @@ public final class BluetoothA2dp implements BluetoothProfile {
* @return the current codec status * @return the current codec status
* @hide * @hide
*/ */
@UnsupportedAppUsage @SystemApi
public @Nullable BluetoothCodecStatus getCodecStatus(BluetoothDevice device) { @Nullable
@RequiresPermission(Manifest.permission.BLUETOOTH)
public BluetoothCodecStatus getCodecStatus(@Nullable BluetoothDevice device) {
if (DBG) Log.d(TAG, "getCodecStatus(" + device + ")"); if (DBG) Log.d(TAG, "getCodecStatus(" + device + ")");
try { try {
final IBluetoothA2dp service = getService(); final IBluetoothA2dp service = getService();
@@ -652,9 +668,10 @@ public final class BluetoothA2dp implements BluetoothProfile {
* @param codecConfig the codec configuration preference * @param codecConfig the codec configuration preference
* @hide * @hide
*/ */
@UnsupportedAppUsage @SystemApi
public void setCodecConfigPreference(BluetoothDevice device, @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
BluetoothCodecConfig codecConfig) { public void setCodecConfigPreference(@Nullable BluetoothDevice device,
@Nullable BluetoothCodecConfig codecConfig) {
if (DBG) Log.d(TAG, "setCodecConfigPreference(" + device + ")"); if (DBG) Log.d(TAG, "setCodecConfigPreference(" + device + ")");
try { try {
final IBluetoothA2dp service = getService(); final IBluetoothA2dp service = getService();
@@ -676,8 +693,9 @@ public final class BluetoothA2dp implements BluetoothProfile {
* active A2DP Bluetooth device. * active A2DP Bluetooth device.
* @hide * @hide
*/ */
@UnsupportedAppUsage @SystemApi
public void enableOptionalCodecs(BluetoothDevice device) { @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
public void enableOptionalCodecs(@Nullable BluetoothDevice device) {
if (DBG) Log.d(TAG, "enableOptionalCodecs(" + device + ")"); if (DBG) Log.d(TAG, "enableOptionalCodecs(" + device + ")");
enableDisableOptionalCodecs(device, true); enableDisableOptionalCodecs(device, true);
} }
@@ -689,8 +707,9 @@ public final class BluetoothA2dp implements BluetoothProfile {
* active A2DP Bluetooth device. * active A2DP Bluetooth device.
* @hide * @hide
*/ */
@UnsupportedAppUsage @SystemApi
public void disableOptionalCodecs(BluetoothDevice device) { @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
public void disableOptionalCodecs(@Nullable BluetoothDevice device) {
if (DBG) Log.d(TAG, "disableOptionalCodecs(" + device + ")"); if (DBG) Log.d(TAG, "disableOptionalCodecs(" + device + ")");
enableDisableOptionalCodecs(device, false); enableDisableOptionalCodecs(device, false);
} }
@@ -728,8 +747,10 @@ public final class BluetoothA2dp implements BluetoothProfile {
* OPTIONAL_CODECS_SUPPORTED. * OPTIONAL_CODECS_SUPPORTED.
* @hide * @hide
*/ */
@UnsupportedAppUsage @SystemApi
public int supportsOptionalCodecs(BluetoothDevice device) { @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
@OptionalCodecsSupportStatus
public int supportsOptionalCodecs(@Nullable BluetoothDevice device) {
try { try {
final IBluetoothA2dp service = getService(); final IBluetoothA2dp service = getService();
if (service != null && isEnabled() && isValidDevice(device)) { if (service != null && isEnabled() && isValidDevice(device)) {
@@ -738,7 +759,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
if (service == null) Log.w(TAG, "Proxy not attached to service"); if (service == null) Log.w(TAG, "Proxy not attached to service");
return OPTIONAL_CODECS_SUPPORT_UNKNOWN; return OPTIONAL_CODECS_SUPPORT_UNKNOWN;
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "Error talking to BT service in getSupportsOptionalCodecs()", e); Log.e(TAG, "Error talking to BT service in supportsOptionalCodecs()", e);
return OPTIONAL_CODECS_SUPPORT_UNKNOWN; return OPTIONAL_CODECS_SUPPORT_UNKNOWN;
} }
} }
@@ -751,8 +772,10 @@ public final class BluetoothA2dp implements BluetoothProfile {
* OPTIONAL_CODECS_PREF_DISABLED. * OPTIONAL_CODECS_PREF_DISABLED.
* @hide * @hide
*/ */
@UnsupportedAppUsage @SystemApi
public int getOptionalCodecsEnabled(BluetoothDevice device) { @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
@OptionalCodecsPreferenceStatus
public int getOptionalCodecsEnabled(@Nullable BluetoothDevice device) {
try { try {
final IBluetoothA2dp service = getService(); final IBluetoothA2dp service = getService();
if (service != null && isEnabled() && isValidDevice(device)) { if (service != null && isEnabled() && isValidDevice(device)) {
@@ -761,7 +784,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
if (service == null) Log.w(TAG, "Proxy not attached to service"); if (service == null) Log.w(TAG, "Proxy not attached to service");
return OPTIONAL_CODECS_PREF_UNKNOWN; return OPTIONAL_CODECS_PREF_UNKNOWN;
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "Error talking to BT service in getSupportsOptionalCodecs()", e); Log.e(TAG, "Error talking to BT service in getOptionalCodecsEnabled()", e);
return OPTIONAL_CODECS_PREF_UNKNOWN; return OPTIONAL_CODECS_PREF_UNKNOWN;
} }
} }
@@ -775,8 +798,10 @@ public final class BluetoothA2dp implements BluetoothProfile {
* OPTIONAL_CODECS_PREF_DISABLED. * OPTIONAL_CODECS_PREF_DISABLED.
* @hide * @hide
*/ */
@UnsupportedAppUsage @SystemApi
public void setOptionalCodecsEnabled(BluetoothDevice device, int value) { @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
public void setOptionalCodecsEnabled(@Nullable BluetoothDevice device,
@OptionalCodecsPreferenceStatus int value) {
try { try {
if (value != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN if (value != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN
&& value != BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED && value != BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED

View File

@@ -320,7 +320,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
* Set priority of the profile * Set priority of the profile
* *
* <p> The device should already be paired. * <p> The device should already be paired.
* Priority can be one of {@link #PRIORITY_ON} or {@link #PRIORITY_OFF}, * Priority can be one of {@link #PRIORITY_ON} or {@link #PRIORITY_OFF}
* *
* @param device Paired bluetooth device * @param device Paired bluetooth device
* @param priority * @param priority

View File

@@ -16,10 +16,15 @@
package android.bluetooth; package android.bluetooth;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.annotation.UnsupportedAppUsage; import android.annotation.UnsupportedAppUsage;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects; import java.util.Objects;
/** /**
@@ -29,78 +34,131 @@ import java.util.Objects;
* *
* {@hide} * {@hide}
*/ */
@SystemApi
public final class BluetoothCodecConfig implements Parcelable { public final class BluetoothCodecConfig implements Parcelable {
// Add an entry for each source codec here. // Add an entry for each source codec here.
// NOTE: The values should be same as those listed in the following file: // NOTE: The values should be same as those listed in the following file:
// hardware/libhardware/include/hardware/bt_av.h // hardware/libhardware/include/hardware/bt_av.h
@UnsupportedAppUsage
/** @hide */
@IntDef(prefix = "SOURCE_CODEC_TYPE_", value = {
SOURCE_CODEC_TYPE_SBC,
SOURCE_CODEC_TYPE_AAC,
SOURCE_CODEC_TYPE_APTX,
SOURCE_CODEC_TYPE_APTX_HD,
SOURCE_CODEC_TYPE_LDAC,
SOURCE_CODEC_TYPE_MAX,
SOURCE_CODEC_TYPE_INVALID
})
@Retention(RetentionPolicy.SOURCE)
public @interface SourceCodecType {}
public static final int SOURCE_CODEC_TYPE_SBC = 0; public static final int SOURCE_CODEC_TYPE_SBC = 0;
@UnsupportedAppUsage
public static final int SOURCE_CODEC_TYPE_AAC = 1; public static final int SOURCE_CODEC_TYPE_AAC = 1;
@UnsupportedAppUsage
public static final int SOURCE_CODEC_TYPE_APTX = 2; public static final int SOURCE_CODEC_TYPE_APTX = 2;
@UnsupportedAppUsage
public static final int SOURCE_CODEC_TYPE_APTX_HD = 3; public static final int SOURCE_CODEC_TYPE_APTX_HD = 3;
@UnsupportedAppUsage
public static final int SOURCE_CODEC_TYPE_LDAC = 4; public static final int SOURCE_CODEC_TYPE_LDAC = 4;
@UnsupportedAppUsage
public static final int SOURCE_CODEC_TYPE_MAX = 5; public static final int SOURCE_CODEC_TYPE_MAX = 5;
@UnsupportedAppUsage
public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000; public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000;
@UnsupportedAppUsage /** @hide */
@IntDef(prefix = "CODEC_PRIORITY_", value = {
CODEC_PRIORITY_DISABLED,
CODEC_PRIORITY_DEFAULT,
CODEC_PRIORITY_HIGHEST
})
@Retention(RetentionPolicy.SOURCE)
public @interface CodecPriority {}
public static final int CODEC_PRIORITY_DISABLED = -1; public static final int CODEC_PRIORITY_DISABLED = -1;
@UnsupportedAppUsage
public static final int CODEC_PRIORITY_DEFAULT = 0; public static final int CODEC_PRIORITY_DEFAULT = 0;
@UnsupportedAppUsage
public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000; public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000;
@UnsupportedAppUsage
/** @hide */
@IntDef(prefix = "SAMPLE_RATE_", value = {
SAMPLE_RATE_NONE,
SAMPLE_RATE_44100,
SAMPLE_RATE_48000,
SAMPLE_RATE_88200,
SAMPLE_RATE_96000,
SAMPLE_RATE_176400,
SAMPLE_RATE_192000
})
@Retention(RetentionPolicy.SOURCE)
public @interface SampleRate {}
public static final int SAMPLE_RATE_NONE = 0; public static final int SAMPLE_RATE_NONE = 0;
@UnsupportedAppUsage
public static final int SAMPLE_RATE_44100 = 0x1 << 0; public static final int SAMPLE_RATE_44100 = 0x1 << 0;
@UnsupportedAppUsage
public static final int SAMPLE_RATE_48000 = 0x1 << 1; public static final int SAMPLE_RATE_48000 = 0x1 << 1;
@UnsupportedAppUsage
public static final int SAMPLE_RATE_88200 = 0x1 << 2; public static final int SAMPLE_RATE_88200 = 0x1 << 2;
@UnsupportedAppUsage
public static final int SAMPLE_RATE_96000 = 0x1 << 3; public static final int SAMPLE_RATE_96000 = 0x1 << 3;
@UnsupportedAppUsage
public static final int SAMPLE_RATE_176400 = 0x1 << 4; public static final int SAMPLE_RATE_176400 = 0x1 << 4;
@UnsupportedAppUsage
public static final int SAMPLE_RATE_192000 = 0x1 << 5; public static final int SAMPLE_RATE_192000 = 0x1 << 5;
@UnsupportedAppUsage
/** @hide */
@IntDef(prefix = "BITS_PER_SAMPLE_", value = {
BITS_PER_SAMPLE_NONE,
BITS_PER_SAMPLE_16,
BITS_PER_SAMPLE_24,
BITS_PER_SAMPLE_32
})
@Retention(RetentionPolicy.SOURCE)
public @interface BitsPerSample {}
public static final int BITS_PER_SAMPLE_NONE = 0; public static final int BITS_PER_SAMPLE_NONE = 0;
@UnsupportedAppUsage
public static final int BITS_PER_SAMPLE_16 = 0x1 << 0; public static final int BITS_PER_SAMPLE_16 = 0x1 << 0;
@UnsupportedAppUsage
public static final int BITS_PER_SAMPLE_24 = 0x1 << 1; public static final int BITS_PER_SAMPLE_24 = 0x1 << 1;
@UnsupportedAppUsage
public static final int BITS_PER_SAMPLE_32 = 0x1 << 2; public static final int BITS_PER_SAMPLE_32 = 0x1 << 2;
@UnsupportedAppUsage
/** @hide */
@IntDef(prefix = "CHANNEL_MODE_", value = {
CHANNEL_MODE_NONE,
CHANNEL_MODE_MONO,
CHANNEL_MODE_STEREO
})
@Retention(RetentionPolicy.SOURCE)
public @interface ChannelMode {}
public static final int CHANNEL_MODE_NONE = 0; public static final int CHANNEL_MODE_NONE = 0;
@UnsupportedAppUsage
public static final int CHANNEL_MODE_MONO = 0x1 << 0; public static final int CHANNEL_MODE_MONO = 0x1 << 0;
@UnsupportedAppUsage
public static final int CHANNEL_MODE_STEREO = 0x1 << 1; public static final int CHANNEL_MODE_STEREO = 0x1 << 1;
private final int mCodecType; private final @SourceCodecType int mCodecType;
private int mCodecPriority; private @CodecPriority int mCodecPriority;
private final int mSampleRate; private final @SampleRate int mSampleRate;
private final int mBitsPerSample; private final @BitsPerSample int mBitsPerSample;
private final int mChannelMode; private final @ChannelMode int mChannelMode;
private final long mCodecSpecific1; private final long mCodecSpecific1;
private final long mCodecSpecific2; private final long mCodecSpecific2;
private final long mCodecSpecific3; private final long mCodecSpecific3;
private final long mCodecSpecific4; private final long mCodecSpecific4;
@UnsupportedAppUsage public BluetoothCodecConfig(@SourceCodecType int codecType, @CodecPriority int codecPriority,
public BluetoothCodecConfig(int codecType, int codecPriority, @SampleRate int sampleRate, @BitsPerSample int bitsPerSample,
int sampleRate, int bitsPerSample, @ChannelMode int channelMode, long codecSpecific1,
int channelMode, long codecSpecific1,
long codecSpecific2, long codecSpecific3, long codecSpecific2, long codecSpecific3,
long codecSpecific4) { long codecSpecific4) {
mCodecType = codecType; mCodecType = codecType;
@@ -114,8 +172,7 @@ public final class BluetoothCodecConfig implements Parcelable {
mCodecSpecific4 = codecSpecific4; mCodecSpecific4 = codecSpecific4;
} }
@UnsupportedAppUsage public BluetoothCodecConfig(@SourceCodecType int codecType) {
public BluetoothCodecConfig(int codecType) {
mCodecType = codecType; mCodecType = codecType;
mCodecPriority = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT; mCodecPriority = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
mSampleRate = BluetoothCodecConfig.SAMPLE_RATE_NONE; mSampleRate = BluetoothCodecConfig.SAMPLE_RATE_NONE;
@@ -144,6 +201,12 @@ public final class BluetoothCodecConfig implements Parcelable {
return false; return false;
} }
/**
* Returns a hash based on the config values
*
* @return a hash based on the config values
* @hide
*/
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(mCodecType, mCodecPriority, mSampleRate, return Objects.hash(mCodecType, mCodecPriority, mSampleRate,
@@ -155,6 +218,7 @@ public final class BluetoothCodecConfig implements Parcelable {
* Checks whether the object contains valid codec configuration. * Checks whether the object contains valid codec configuration.
* *
* @return true if the object contains valid codec configuration, otherwise false. * @return true if the object contains valid codec configuration, otherwise false.
* @hide
*/ */
public boolean isValid() { public boolean isValid() {
return (mSampleRate != SAMPLE_RATE_NONE) return (mSampleRate != SAMPLE_RATE_NONE)
@@ -242,6 +306,12 @@ public final class BluetoothCodecConfig implements Parcelable {
+ ",mCodecSpecific4:" + mCodecSpecific4 + "}"; + ",mCodecSpecific4:" + mCodecSpecific4 + "}";
} }
/**
* Always returns 0
*
* @return 0
* @hide
*/
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;
@@ -271,6 +341,14 @@ public final class BluetoothCodecConfig 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 @Override
public void writeToParcel(Parcel out, int flags) { public void writeToParcel(Parcel out, int flags) {
out.writeInt(mCodecType); out.writeInt(mCodecType);
@@ -289,7 +367,7 @@ public final class BluetoothCodecConfig implements Parcelable {
* *
* @return the codec name * @return the codec name
*/ */
public String getCodecName() { public @NonNull String getCodecName() {
switch (mCodecType) { switch (mCodecType) {
case SOURCE_CODEC_TYPE_SBC: case SOURCE_CODEC_TYPE_SBC:
return "SBC"; return "SBC";
@@ -315,8 +393,7 @@ public final class BluetoothCodecConfig implements Parcelable {
* *
* @return the codec type * @return the codec type
*/ */
@UnsupportedAppUsage public @SourceCodecType int getCodecType() {
public int getCodecType() {
return mCodecType; return mCodecType;
} }
@@ -336,8 +413,7 @@ public final class BluetoothCodecConfig implements Parcelable {
* *
* @return the codec priority * @return the codec priority
*/ */
@UnsupportedAppUsage public @CodecPriority int getCodecPriority() {
public int getCodecPriority() {
return mCodecPriority; return mCodecPriority;
} }
@@ -347,9 +423,10 @@ public final class BluetoothCodecConfig implements Parcelable {
* means higher priority. If 0, reset to default. * means higher priority. If 0, reset to default.
* *
* @param codecPriority the codec priority * @param codecPriority the codec priority
* @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public void setCodecPriority(int codecPriority) { public void setCodecPriority(@CodecPriority int codecPriority) {
mCodecPriority = codecPriority; mCodecPriority = codecPriority;
} }
@@ -366,8 +443,7 @@ public final class BluetoothCodecConfig implements Parcelable {
* *
* @return the codec sample rate * @return the codec sample rate
*/ */
@UnsupportedAppUsage public @SampleRate int getSampleRate() {
public int getSampleRate() {
return mSampleRate; return mSampleRate;
} }
@@ -381,8 +457,7 @@ public final class BluetoothCodecConfig implements Parcelable {
* *
* @return the codec bits per sample * @return the codec bits per sample
*/ */
@UnsupportedAppUsage public @BitsPerSample int getBitsPerSample() {
public int getBitsPerSample() {
return mBitsPerSample; return mBitsPerSample;
} }
@@ -394,9 +469,10 @@ public final class BluetoothCodecConfig implements Parcelable {
* {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_STEREO} * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_STEREO}
* *
* @return the codec channel mode * @return the codec channel mode
* @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public int getChannelMode() { public @ChannelMode int getChannelMode() {
return mChannelMode; return mChannelMode;
} }
@@ -405,7 +481,6 @@ public final class BluetoothCodecConfig implements Parcelable {
* *
* @return a codec specific value1. * @return a codec specific value1.
*/ */
@UnsupportedAppUsage
public long getCodecSpecific1() { public long getCodecSpecific1() {
return mCodecSpecific1; return mCodecSpecific1;
} }
@@ -414,6 +489,7 @@ public final class BluetoothCodecConfig implements Parcelable {
* Gets a codec specific value2. * Gets a codec specific value2.
* *
* @return a codec specific value2 * @return a codec specific value2
* @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public long getCodecSpecific2() { public long getCodecSpecific2() {
@@ -424,6 +500,7 @@ public final class BluetoothCodecConfig implements Parcelable {
* Gets a codec specific value3. * Gets a codec specific value3.
* *
* @return a codec specific value3 * @return a codec specific value3
* @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public long getCodecSpecific3() { public long getCodecSpecific3() {
@@ -434,6 +511,7 @@ public final class BluetoothCodecConfig implements Parcelable {
* Gets a codec specific value4. * Gets a codec specific value4.
* *
* @return a codec specific value4 * @return a codec specific value4
* @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public long getCodecSpecific4() { public long getCodecSpecific4() {
@@ -445,6 +523,7 @@ public final class BluetoothCodecConfig implements Parcelable {
* *
* @param valueSet the value set presented by a bitmask * @param valueSet the value set presented by a bitmask
* @return true if the valueSet contains zero or single bit, otherwise false. * @return true if the valueSet contains zero or single bit, otherwise false.
* @hide
*/ */
private static boolean hasSingleBit(int valueSet) { private static boolean hasSingleBit(int valueSet) {
return (valueSet == 0 || (valueSet & (valueSet - 1)) == 0); return (valueSet == 0 || (valueSet & (valueSet - 1)) == 0);
@@ -454,6 +533,7 @@ public final class BluetoothCodecConfig implements Parcelable {
* Checks whether the object contains none or single sample rate. * Checks whether the object contains none or single sample rate.
* *
* @return true if the object contains none or single sample rate, otherwise false. * @return true if the object contains none or single sample rate, otherwise false.
* @hide
*/ */
public boolean hasSingleSampleRate() { public boolean hasSingleSampleRate() {
return hasSingleBit(mSampleRate); return hasSingleBit(mSampleRate);
@@ -463,6 +543,7 @@ public final class BluetoothCodecConfig implements Parcelable {
* Checks whether the object contains none or single bits per sample. * Checks whether the object contains none or single bits per sample.
* *
* @return true if the object contains none or single bits per sample, otherwise false. * @return true if the object contains none or single bits per sample, otherwise false.
* @hide
*/ */
public boolean hasSingleBitsPerSample() { public boolean hasSingleBitsPerSample() {
return hasSingleBit(mBitsPerSample); return hasSingleBit(mBitsPerSample);
@@ -472,6 +553,7 @@ public final class BluetoothCodecConfig implements Parcelable {
* Checks whether the object contains none or single channel mode. * Checks whether the object contains none or single channel mode.
* *
* @return true if the object contains none or single channel mode, otherwise false. * @return true if the object contains none or single channel mode, otherwise false.
* @hide
*/ */
public boolean hasSingleChannelMode() { public boolean hasSingleChannelMode() {
return hasSingleBit(mChannelMode); return hasSingleBit(mChannelMode);
@@ -482,6 +564,7 @@ public final class BluetoothCodecConfig implements Parcelable {
* *
* @param other the codec config to compare against * @param other the codec config to compare against
* @return true if the audio feeding parameters are same, otherwise false * @return true if the audio feeding parameters are same, otherwise false
* @hide
*/ */
public boolean sameAudioFeedingParameters(BluetoothCodecConfig other) { public boolean sameAudioFeedingParameters(BluetoothCodecConfig other) {
return (other != null && other.mSampleRate == mSampleRate return (other != null && other.mSampleRate == mSampleRate
@@ -495,6 +578,7 @@ public final class BluetoothCodecConfig implements Parcelable {
* *
* @param other the codec config to compare against * @param other the codec config to compare against
* @return true if the audio feeding parameters are similar, otherwise false. * @return true if the audio feeding parameters are similar, otherwise false.
* @hide
*/ */
public boolean similarCodecFeedingParameters(BluetoothCodecConfig other) { public boolean similarCodecFeedingParameters(BluetoothCodecConfig other) {
if (other == null || mCodecType != other.mCodecType) { if (other == null || mCodecType != other.mCodecType) {
@@ -526,6 +610,7 @@ public final class BluetoothCodecConfig implements Parcelable {
* *
* @param other the codec config to compare against * @param other the codec config to compare against
* @return true if the codec specific parameters are the same, otherwise false. * @return true if the codec specific parameters are the same, otherwise false.
* @hide
*/ */
public boolean sameCodecSpecificParameters(BluetoothCodecConfig other) { public boolean sameCodecSpecificParameters(BluetoothCodecConfig other) {
if (other == null && mCodecType != other.mCodecType) { if (other == null && mCodecType != other.mCodecType) {

View File

@@ -17,7 +17,7 @@
package android.bluetooth; package android.bluetooth;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.UnsupportedAppUsage; import android.annotation.SystemApi;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
@@ -32,6 +32,7 @@ import java.util.Objects;
* *
* {@hide} * {@hide}
*/ */
@SystemApi
public final class BluetoothCodecStatus implements Parcelable { public final class BluetoothCodecStatus implements Parcelable {
/** /**
* Extra for the codec configuration intents of the individual profiles. * 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 * This extra represents the current codec status of the A2DP
* profile. * profile.
*/ */
@UnsupportedAppUsage
public static final String EXTRA_CODEC_STATUS = 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 @Nullable BluetoothCodecConfig mCodecConfig;
private final BluetoothCodecConfig[] mCodecsLocalCapabilities; private final BluetoothCodecConfig[] mCodecsLocalCapabilities;
private final BluetoothCodecConfig[] mCodecsSelectableCapabilities; private final BluetoothCodecConfig[] mCodecsSelectableCapabilities;
public BluetoothCodecStatus(BluetoothCodecConfig codecConfig, public BluetoothCodecStatus(@Nullable BluetoothCodecConfig codecConfig,
BluetoothCodecConfig[] codecsLocalCapabilities, @Nullable BluetoothCodecConfig[] codecsLocalCapabilities,
BluetoothCodecConfig[] codecsSelectableCapabilities) { @Nullable BluetoothCodecConfig[] codecsSelectableCapabilities) {
mCodecConfig = codecConfig; mCodecConfig = codecConfig;
mCodecsLocalCapabilities = codecsLocalCapabilities; mCodecsLocalCapabilities = codecsLocalCapabilities;
mCodecsSelectableCapabilities = codecsSelectableCapabilities; mCodecsSelectableCapabilities = codecsSelectableCapabilities;
@@ -74,6 +74,7 @@ public final class BluetoothCodecStatus implements Parcelable {
* @param c1 the first array of capabilities to compare * @param c1 the first array of capabilities to compare
* @param c2 the second array of capabilities to compare * @param c2 the second array of capabilities to compare
* @return true if both arrays contain same capabilities * @return true if both arrays contain same capabilities
* @hide
*/ */
public static boolean sameCapabilities(BluetoothCodecConfig[] c1, public static boolean sameCapabilities(BluetoothCodecConfig[] c1,
BluetoothCodecConfig[] c2) { BluetoothCodecConfig[] c2) {
@@ -95,6 +96,7 @@ public final class BluetoothCodecStatus implements Parcelable {
* *
* @param codecConfig the codec config to compare against * @param codecConfig the codec config to compare against
* @return true if the codec config matches, otherwise false * @return true if the codec config matches, otherwise false
* @hide
*/ */
public boolean isCodecConfigSelectable(BluetoothCodecConfig codecConfig) { public boolean isCodecConfigSelectable(BluetoothCodecConfig codecConfig) {
if (codecConfig == null || !codecConfig.hasSingleSampleRate() if (codecConfig == null || !codecConfig.hasSingleSampleRate()
@@ -125,7 +127,12 @@ public final class BluetoothCodecStatus implements Parcelable {
return false; return false;
} }
/**
* Returns a hash based on the codec config and local capabilities
*
* @return a hash based on the config values
* @hide
*/
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(mCodecConfig, mCodecsLocalCapabilities, return Objects.hash(mCodecConfig, mCodecsLocalCapabilities,
@@ -140,6 +147,12 @@ public final class BluetoothCodecStatus implements Parcelable {
+ "}"; + "}";
} }
/**
* Always returns 0
*
* @return 0
* @hide
*/
@Override @Override
public int describeContents() { public int describeContents() {
return 0; 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 @Override
public void writeToParcel(Parcel out, int flags) { public void writeToParcel(Parcel out, int flags) {
out.writeTypedObject(mCodecConfig, 0); out.writeTypedObject(mCodecConfig, 0);
@@ -177,7 +198,6 @@ public final class BluetoothCodecStatus implements Parcelable {
* *
* @return the current codec configuration * @return the current codec configuration
*/ */
@UnsupportedAppUsage
public @Nullable BluetoothCodecConfig getCodecConfig() { public @Nullable BluetoothCodecConfig getCodecConfig() {
return mCodecConfig; return mCodecConfig;
} }
@@ -187,8 +207,7 @@ public final class BluetoothCodecStatus implements Parcelable {
* *
* @return an array with the codecs local capabilities * @return an array with the codecs local capabilities
*/ */
@UnsupportedAppUsage public @Nullable BluetoothCodecConfig[] getCodecsLocalCapabilities() {
public BluetoothCodecConfig[] getCodecsLocalCapabilities() {
return mCodecsLocalCapabilities; return mCodecsLocalCapabilities;
} }
@@ -197,8 +216,7 @@ public final class BluetoothCodecStatus implements Parcelable {
* *
* @return an array with the codecs selectable capabilities * @return an array with the codecs selectable capabilities
*/ */
@UnsupportedAppUsage public @Nullable BluetoothCodecConfig[] getCodecsSelectableCapabilities() {
public BluetoothCodecConfig[] getCodecsSelectableCapabilities() {
return mCodecsSelectableCapabilities; return mCodecsSelectableCapabilities;
} }
} }