Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 67eae9d7 authored by Rahul Sabnis's avatar Rahul Sabnis Committed by Gerrit Code Review
Browse files

Merge "Resolve BluetoothA2dp hidden APIs to resolve dependencies"

parents d915fc70 625e1c3e
Loading
Loading
Loading
Loading
+60 −0
Original line number Diff line number Diff line
@@ -1251,8 +1251,22 @@ package android.app.usage {
package android.bluetooth {
  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_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_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 {
@@ -1281,6 +1295,52 @@ package android.bluetooth {
    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 {
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean cancelBondProcess();
    method @Nullable @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public byte[] getMetadata(int);
+63 −38
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.bluetooth;

import android.Manifest;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
@@ -32,6 +33,8 @@ import android.os.ParcelUuid;
import android.os.RemoteException;
import android.util.Log;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;

@@ -154,13 +157,22 @@ public final class BluetoothA2dp implements BluetoothProfile {
     */
    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
     * optional codecs.
     *
     * @hide
     */
    @UnsupportedAppUsage
    @SystemApi
    public static final int OPTIONAL_CODECS_SUPPORT_UNKNOWN = -1;

    /**
@@ -168,7 +180,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
     *
     * @hide
     */
    @UnsupportedAppUsage
    @SystemApi
    public static final int OPTIONAL_CODECS_NOT_SUPPORTED = 0;

    /**
@@ -176,16 +188,25 @@ public final class BluetoothA2dp implements BluetoothProfile {
     *
     * @hide
     */
    @UnsupportedAppUsage
    @SystemApi
    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
     * for the given A2DP device.
     * We don't have a stored preference for whether optional codecs should be enabled or
     * disabled for the given A2DP device.
     *
     * @hide
     */
    @UnsupportedAppUsage
    @SystemApi
    public static final int OPTIONAL_CODECS_PREF_UNKNOWN = -1;

    /**
@@ -193,7 +214,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
     *
     * @hide
     */
    @UnsupportedAppUsage
    @SystemApi
    public static final int OPTIONAL_CODECS_PREF_DISABLED = 0;

    /**
@@ -201,7 +222,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
     *
     * @hide
     */
    @UnsupportedAppUsage
    @SystemApi
    public static final int OPTIONAL_CODECS_PREF_ENABLED = 1;

    private BluetoothAdapter mAdapter;
@@ -248,13 +269,12 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * the state. Users can get the connection state of the profile
     * from this intent.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
     * permission.
     *
     * @param device Remote Bluetooth Device
     * @return false on immediate error, true otherwise
     * @hide
     */
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    @UnsupportedAppUsage
    public boolean connect(BluetoothDevice 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
     * two scenarios.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
     * permission.
     *
     * @param device Remote Bluetooth Device
     * @return false on immediate error, true otherwise
     * @hide
     */
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    @UnsupportedAppUsage
    public boolean disconnect(BluetoothDevice 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
     * with the active device.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
     * permission.
     *
     * @param device the remote Bluetooth device. Could be null to clear
     * the active device and stop streaming audio to a Bluetooth device.
     * @return false on immediate error, true otherwise
     * @hide
     */
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    @UnsupportedAppUsage
    public boolean setActiveDevice(@Nullable BluetoothDevice device) {
        if (DBG) log("setActiveDevice(" + device + ")");
@@ -412,16 +429,13 @@ public final class BluetoothA2dp implements BluetoothProfile {
    /**
     * 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
     * is active
     * @hide
     */
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    @SystemApi
    @Nullable
    @UnsupportedAppUsage
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    public BluetoothDevice getActiveDevice() {
        if (VDBG) log("getActiveDevice()");
        try {
@@ -441,7 +455,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * Set priority of the profile
     *
     * <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 priority
@@ -626,8 +640,10 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * @return the current codec status
     * @hide
     */
    @UnsupportedAppUsage
    public @Nullable BluetoothCodecStatus getCodecStatus(BluetoothDevice device) {
    @SystemApi
    @Nullable
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    public BluetoothCodecStatus getCodecStatus(@Nullable BluetoothDevice device) {
        if (DBG) Log.d(TAG, "getCodecStatus(" + device + ")");
        try {
            final IBluetoothA2dp service = getService();
@@ -652,9 +668,10 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * @param codecConfig the codec configuration preference
     * @hide
     */
    @UnsupportedAppUsage
    public void setCodecConfigPreference(BluetoothDevice device,
                                         BluetoothCodecConfig codecConfig) {
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public void setCodecConfigPreference(@Nullable BluetoothDevice device,
                                         @Nullable BluetoothCodecConfig codecConfig) {
        if (DBG) Log.d(TAG, "setCodecConfigPreference(" + device + ")");
        try {
            final IBluetoothA2dp service = getService();
@@ -676,8 +693,9 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * active A2DP Bluetooth device.
     * @hide
     */
    @UnsupportedAppUsage
    public void enableOptionalCodecs(BluetoothDevice device) {
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public void enableOptionalCodecs(@Nullable BluetoothDevice device) {
        if (DBG) Log.d(TAG, "enableOptionalCodecs(" + device + ")");
        enableDisableOptionalCodecs(device, true);
    }
@@ -689,8 +707,9 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * active A2DP Bluetooth device.
     * @hide
     */
    @UnsupportedAppUsage
    public void disableOptionalCodecs(BluetoothDevice device) {
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public void disableOptionalCodecs(@Nullable BluetoothDevice device) {
        if (DBG) Log.d(TAG, "disableOptionalCodecs(" + device + ")");
        enableDisableOptionalCodecs(device, false);
    }
@@ -728,8 +747,10 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * OPTIONAL_CODECS_SUPPORTED.
     * @hide
     */
    @UnsupportedAppUsage
    public int supportsOptionalCodecs(BluetoothDevice device) {
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    @OptionalCodecsSupportStatus
    public int supportsOptionalCodecs(@Nullable BluetoothDevice device) {
        try {
            final IBluetoothA2dp service = getService();
            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");
            return OPTIONAL_CODECS_SUPPORT_UNKNOWN;
        } 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;
        }
    }
@@ -751,8 +772,10 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * OPTIONAL_CODECS_PREF_DISABLED.
     * @hide
     */
    @UnsupportedAppUsage
    public int getOptionalCodecsEnabled(BluetoothDevice device) {
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    @OptionalCodecsPreferenceStatus
    public int getOptionalCodecsEnabled(@Nullable BluetoothDevice device) {
        try {
            final IBluetoothA2dp service = getService();
            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");
            return OPTIONAL_CODECS_PREF_UNKNOWN;
        } 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;
        }
    }
@@ -775,8 +798,10 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * OPTIONAL_CODECS_PREF_DISABLED.
     * @hide
     */
    @UnsupportedAppUsage
    public void setOptionalCodecsEnabled(BluetoothDevice device, int value) {
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public void setOptionalCodecsEnabled(@Nullable BluetoothDevice device,
            @OptionalCodecsPreferenceStatus int value) {
        try {
            if (value != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN
                    && value != BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED
+1 −1
Original line number Diff line number Diff line
@@ -320,7 +320,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
     * Set priority of the profile
     *
     * <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 priority
+132 −47

File changed.

Preview size limit exceeded, changes collapsed.

+30 −12
Original line number Diff line number Diff line
@@ -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;
    }
}