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

Commit 71880acb authored by Henri Chataing's avatar Henri Chataing Committed by Automerger Merge Worker
Browse files

Merge "framework: Implement BluetoothCodecType to extend SourceCodecType" into main am: c4d10a09

parents 80f74f22 c4d10a09
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ oneway interface IBluetoothA2dp {
    oneway void setAvrcpAbsoluteVolume(int volume, in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    void isA2dpPlaying(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    void getSupportedCodecTypes(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    void getCodecStatus(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
+48 −0
Original line number Diff line number Diff line
@@ -329,6 +329,51 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {
  }
}

static jobjectArray getSupportedCodecTypesNative(JNIEnv* env) {
  ALOGI("%s: %p", __func__, sBluetoothA2dpInterface);

  jclass android_bluetooth_BluetoothCodecType_clazz = (jclass)env->NewGlobalRef(
      env->FindClass("android/bluetooth/BluetoothCodecType"));
  if (android_bluetooth_BluetoothCodecType_clazz == nullptr) {
    ALOGE("%s: Failed to allocate Global Ref for BluetoothCodecType class",
          __func__);
    return nullptr;
  }

  jmethodID createFromType = env->GetStaticMethodID(
      android_bluetooth_BluetoothCodecType_clazz, "createFromType",
      "(I)Landroid/bluetooth/BluetoothCodecType;");
  if (createFromType == nullptr) {
    ALOGE(
        "%s: Failed to find method createFromType of BluetoothCodecType class",
        __func__);
    return nullptr;
  }

  std::array<btav_a2dp_codec_index_t, 6> default_supported_codecs = {
      BTAV_A2DP_CODEC_INDEX_SOURCE_SBC,  BTAV_A2DP_CODEC_INDEX_SOURCE_AAC,
      BTAV_A2DP_CODEC_INDEX_SOURCE_APTX, BTAV_A2DP_CODEC_INDEX_SOURCE_APTX_HD,
      BTAV_A2DP_CODEC_INDEX_SOURCE_LDAC, BTAV_A2DP_CODEC_INDEX_SOURCE_OPUS,
  };
  jobjectArray result =
      env->NewObjectArray(default_supported_codecs.size(),
                          android_bluetooth_BluetoothCodecType_clazz, nullptr);
  if (result == nullptr) {
    ALOGE("%s: Failed to allocate result array of BluetoothCodecType",
          __func__);
    return nullptr;
  }

  for (size_t index = 0; index < default_supported_codecs.size(); index++) {
    jobject codec_type = env->CallStaticObjectMethod(
        android_bluetooth_BluetoothCodecType_clazz, createFromType,
        (jint)default_supported_codecs[index]);
    env->SetObjectArrayElement(result, index, codec_type);
  }

  return result;
}

static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,
                                  jbyteArray address) {
  ALOGI("%s: sBluetoothA2dpInterface: %p", __func__, sBluetoothA2dpInterface);
@@ -466,6 +511,9 @@ int register_com_android_bluetooth_a2dp(JNIEnv* env) {
       "[Landroid/bluetooth/BluetoothCodecConfig;)V",
       (void*)initNative},
      {"cleanupNative", "()V", (void*)cleanupNative},
      {"getSupportedCodecTypesNative",
       "()[Landroid/bluetooth/BluetoothCodecType;",
       (void*)getSupportedCodecTypesNative},
      {"connectA2dpNative", "([B)Z", (void*)connectA2dpNative},
      {"disconnectA2dpNative", "([B)Z", (void*)disconnectA2dpNative},
      {"setSilenceDeviceNative", "([BZ)Z", (void*)setSilenceDeviceNative},
+15 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothCodecType;
import android.bluetooth.BluetoothDevice;
import android.util.Log;

@@ -34,6 +35,7 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
@@ -48,6 +50,8 @@ public class A2dpNativeInterface {
    @GuardedBy("INSTANCE_LOCK")
    private static A2dpNativeInterface sInstance;

    private static BluetoothCodecType[] sSupportedCodecTypes;

    private static final Object INSTANCE_LOCK = new Object();

    @VisibleForTesting
@@ -99,6 +103,14 @@ public class A2dpNativeInterface {
        cleanupNative();
    }

    /** Returns the list of locally supported codec types. */
    public List<BluetoothCodecType> getSupportedCodecTypes() {
        if (sSupportedCodecTypes == null) {
            sSupportedCodecTypes = getSupportedCodecTypesNative();
        }
        return Arrays.asList(sSupportedCodecTypes);
    }

    /**
     * Initiates A2DP connection to a remote device.
     *
@@ -235,6 +247,9 @@ public class A2dpNativeInterface {
                                   BluetoothCodecConfig[] codecConfigPriorities,
                                   BluetoothCodecConfig[] codecConfigOffloading);
    private native void cleanupNative();

    private native BluetoothCodecType[] getSupportedCodecTypesNative();

    private native boolean connectA2dpNative(byte[] address);
    private native boolean disconnectA2dpNative(byte[] address);
    private native boolean setSilenceDeviceNative(byte[] address, boolean silence);
+23 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.bluetooth.BluetoothA2dp.OptionalCodecsSupportStatus;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothCodecType;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUuid;
@@ -726,6 +727,12 @@ public class A2dpService extends ProfileService {
        }
    }

    /** Returns the list of locally supported codec types. */
    public List<BluetoothCodecType> getSupportedCodecTypes() {
        Log.d(TAG, "getSupportedCodecTypes()");
        return mNativeInterface.getSupportedCodecTypes();
    }

    /**
     * Gets the current codec status (configuration and capability).
     *
@@ -1557,6 +1564,22 @@ public class A2dpService extends ProfileService {
            }
        }

        @Override
        public void getSupportedCodecTypes(
                AttributionSource source, SynchronousResultReceiver receiver) {
            try {
                A2dpService service = getService(source);
                List<BluetoothCodecType> result = new ArrayList<>();
                if (service != null) {
                    enforceBluetoothPrivilegedPermission(service);
                    result = service.getSupportedCodecTypes();
                }
                receiver.send(result);
            } catch (RuntimeException e) {
                receiver.propagateException(e);
            }
        }

        @Override
        public void getCodecStatus(BluetoothDevice device,
                AttributionSource source, SynchronousResultReceiver receiver) {
+28 −10
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ package android.bluetooth {
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public java.util.List<android.bluetooth.BluetoothDevice> getConnectedDevices();
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public int getConnectionState(android.bluetooth.BluetoothDevice);
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public java.util.List<android.bluetooth.BluetoothDevice> getDevicesMatchingConnectionStates(int[]);
    method @FlaggedApi("com.android.bluetooth.flags.a2dp_offload_codec_extensibility") @NonNull @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public java.util.List<android.bluetooth.BluetoothCodecType> getSupportedCodecTypes();
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean isA2dpPlaying(android.bluetooth.BluetoothDevice);
    field @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static final String ACTION_CONNECTION_STATE_CHANGED = "android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED";
    field @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static final String ACTION_PLAYING_STATE_CHANGED = "android.bluetooth.a2dp.profile.action.PLAYING_STATE_CHANGED";
@@ -429,7 +430,8 @@ package android.bluetooth {
    method public long getCodecSpecific2();
    method public long getCodecSpecific3();
    method public long getCodecSpecific4();
    method public int getCodecType();
    method @Deprecated public int getCodecType();
    method @FlaggedApi("com.android.bluetooth.flags.a2dp_offload_codec_extensibility") @Nullable public android.bluetooth.BluetoothCodecType getExtendedCodecType();
    method public int getSampleRate();
    method public boolean isMandatoryCodec();
    method public void writeToParcel(android.os.Parcel, int);
@@ -451,14 +453,14 @@ package android.bluetooth {
    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_LC3 = 5; // 0x5
    field public static final int SOURCE_CODEC_TYPE_LDAC = 4; // 0x4
    field public static final int SOURCE_CODEC_TYPE_OPUS = 6; // 0x6
    field public static final int SOURCE_CODEC_TYPE_SBC = 0; // 0x0
    field @Deprecated public static final int SOURCE_CODEC_TYPE_AAC = 1; // 0x1
    field @Deprecated public static final int SOURCE_CODEC_TYPE_APTX = 2; // 0x2
    field @Deprecated public static final int SOURCE_CODEC_TYPE_APTX_HD = 3; // 0x3
    field @Deprecated public static final int SOURCE_CODEC_TYPE_INVALID = 1000000; // 0xf4240
    field @Deprecated public static final int SOURCE_CODEC_TYPE_LC3 = 5; // 0x5
    field @Deprecated public static final int SOURCE_CODEC_TYPE_LDAC = 4; // 0x4
    field @Deprecated public static final int SOURCE_CODEC_TYPE_OPUS = 6; // 0x6
    field @Deprecated public static final int SOURCE_CODEC_TYPE_SBC = 0; // 0x0
  }

  public static final class BluetoothCodecConfig.Builder {
@@ -471,7 +473,8 @@ package android.bluetooth {
    method @NonNull public android.bluetooth.BluetoothCodecConfig.Builder setCodecSpecific2(long);
    method @NonNull public android.bluetooth.BluetoothCodecConfig.Builder setCodecSpecific3(long);
    method @NonNull public android.bluetooth.BluetoothCodecConfig.Builder setCodecSpecific4(long);
    method @NonNull public android.bluetooth.BluetoothCodecConfig.Builder setCodecType(int);
    method @Deprecated @NonNull public android.bluetooth.BluetoothCodecConfig.Builder setCodecType(int);
    method @FlaggedApi("com.android.bluetooth.flags.a2dp_offload_codec_extensibility") @NonNull public android.bluetooth.BluetoothCodecConfig.Builder setCodecType(@Nullable android.bluetooth.BluetoothCodecType);
    method @NonNull public android.bluetooth.BluetoothCodecConfig.Builder setSampleRate(int);
  }

@@ -494,6 +497,21 @@ package android.bluetooth {
    method @NonNull public android.bluetooth.BluetoothCodecStatus.Builder setCodecsSelectableCapabilities(@NonNull java.util.List<android.bluetooth.BluetoothCodecConfig>);
  }

  @FlaggedApi("com.android.bluetooth.flags.a2dp_offload_codec_extensibility") public final class BluetoothCodecType implements android.os.Parcelable {
    method @FlaggedApi("com.android.bluetooth.flags.a2dp_offload_codec_extensibility") public int describeContents();
    method @FlaggedApi("com.android.bluetooth.flags.a2dp_offload_codec_extensibility") public long getCodecId();
    method @FlaggedApi("com.android.bluetooth.flags.a2dp_offload_codec_extensibility") @NonNull public String getCodecName();
    method @FlaggedApi("com.android.bluetooth.flags.a2dp_offload_codec_extensibility") public boolean isMandatoryCodec();
    method @FlaggedApi("com.android.bluetooth.flags.a2dp_offload_codec_extensibility") public void writeToParcel(@NonNull android.os.Parcel, int);
    field public static final long CODEC_ID_AAC = 1L; // 0x1L
    field public static final long CODEC_ID_APTX = 16797695L; // 0x1004fffL
    field public static final long CODEC_ID_APTX_HD = 604035071L; // 0x2400d7ffL
    field public static final long CODEC_ID_LDAC = -1442763265L; // 0xffffffffaa012dffL
    field public static final long CODEC_ID_OPUS = 16834815L; // 0x100e0ffL
    field public static final long CODEC_ID_SBC = 0L; // 0x0L
    field @FlaggedApi("com.android.bluetooth.flags.a2dp_offload_codec_extensibility") @NonNull public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothCodecType> CREATOR;
  }

  public final class BluetoothCsipSetCoordinator implements java.lang.AutoCloseable android.bluetooth.BluetoothProfile {
    method public void close();
    method protected void finalize();
Loading