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

Commit a05cb45b authored by William Escande's avatar William Escande
Browse files

Add SystemApi to AudioManager method

getHwOffloadFormatsSupportedForBluetoothMedia is convert to a SystemApi
for module only (only use in BT)

Change-Id: Iae212ff5fd2159198543c0b877c2e56e3aefdb7c
Test: Build
Bug: 190422401
Tag: #refactor
parent 851c1687
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -113,6 +113,8 @@ package android.media {
  public class AudioManager {
    method public void adjustStreamVolumeForUid(int, int, int, @NonNull String, int, int, int);
    method public void adjustSuggestedStreamVolumeForUid(int, int, int, @NonNull String, int, int, int);
    method @NonNull public java.util.List<android.bluetooth.BluetoothCodecConfig> getHwOffloadFormatsSupportedForA2dp();
    method @NonNull public java.util.List<android.bluetooth.BluetoothLeAudioCodecConfig> getHwOffloadFormatsSupportedForLeAudio();
    method @RequiresPermission("android.permission.BLUETOOTH_STACK") public void handleBluetoothActiveDeviceChanged(@Nullable android.bluetooth.BluetoothDevice, @Nullable android.bluetooth.BluetoothDevice, @NonNull android.media.BtProfileConnectionInfo);
    method @RequiresPermission("android.permission.BLUETOOTH_STACK") public void setA2dpSuspended(boolean);
    method @RequiresPermission("android.permission.BLUETOOTH_STACK") public void setBluetoothHeadsetProperties(@NonNull String, boolean, boolean);
+45 −38
Original line number Diff line number Diff line
@@ -6791,44 +6791,54 @@ public class AudioManager {

    /**
     * Returns a list of audio formats that corresponds to encoding formats
     * supported on offload path for A2DP and LE audio playback.
     * supported on offload path for A2DP playback.
     *
     * @param deviceType Indicates the target device type {@link AudioSystem.DeviceType}
     * @return a list of {@link BluetoothCodecConfig} objects containing encoding formats
     * supported for offload A2DP playback or a list of {@link BluetoothLeAudioCodecConfig}
     * objects containing encoding formats supported for offload LE Audio playback
     * supported for offload A2DP playback
     * @hide
     */
    public List<?> getHwOffloadFormatsSupportedForBluetoothMedia(
            @AudioSystem.DeviceType int deviceType) {
        ArrayList<Integer> formatsList = new ArrayList<Integer>();
        ArrayList<BluetoothCodecConfig> a2dpCodecConfigList = new ArrayList<BluetoothCodecConfig>();
        ArrayList<BluetoothLeAudioCodecConfig> leAudioCodecConfigList =
                new ArrayList<BluetoothLeAudioCodecConfig>();

        if (deviceType != AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP
                && deviceType != AudioSystem.DEVICE_OUT_BLE_HEADSET) {
            throw new IllegalArgumentException(
                    "Illegal devicetype for the getHwOffloadFormatsSupportedForBluetoothMedia");
        }
    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    public @NonNull List<BluetoothCodecConfig> getHwOffloadFormatsSupportedForA2dp() {
        ArrayList<Integer> formatsList = new ArrayList<>();
        ArrayList<BluetoothCodecConfig> codecConfigList = new ArrayList<>();

        int status = AudioSystem.getHwOffloadFormatsSupportedForBluetoothMedia(deviceType,
                                                                                formatsList);
        int status = AudioSystem.getHwOffloadFormatsSupportedForBluetoothMedia(
                AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, formatsList);
        if (status != AudioManager.SUCCESS) {
            Log.e(TAG, "getHwOffloadFormatsSupportedForBluetoothMedia for deviceType "
                    + deviceType + " failed:" + status);
            return a2dpCodecConfigList;
            Log.e(TAG, "getHwOffloadEncodingFormatsSupportedForA2DP failed:" + status);
            return codecConfigList;
        }

        if (deviceType == AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP) {
        for (Integer format : formatsList) {
            int btSourceCodec = AudioSystem.audioFormatToBluetoothSourceCodec(format);
            if (btSourceCodec != BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID) {
                    a2dpCodecConfigList.add(new BluetoothCodecConfig(btSourceCodec));
                codecConfigList.add(new BluetoothCodecConfig(btSourceCodec));
            }
        }
        return codecConfigList;
    }
            return a2dpCodecConfigList;
        } else if (deviceType == AudioSystem.DEVICE_OUT_BLE_HEADSET) {

    /**
     * Returns a list of audio formats that corresponds to encoding formats
     * supported on offload path for Le audio playback.
     *
     * @return a list of {@link BluetoothLeAudioCodecConfig} objects containing encoding formats
     * supported for offload Le Audio playback
     * @hide
     */
    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    @NonNull
    public List<BluetoothLeAudioCodecConfig> getHwOffloadFormatsSupportedForLeAudio() {
        ArrayList<Integer> formatsList = new ArrayList<>();
        ArrayList<BluetoothLeAudioCodecConfig> leAudioCodecConfigList = new ArrayList<>();

        int status = AudioSystem.getHwOffloadFormatsSupportedForBluetoothMedia(
                AudioSystem.DEVICE_OUT_BLE_HEADSET, formatsList);
        if (status != AudioManager.SUCCESS) {
            Log.e(TAG, "getHwOffloadEncodingFormatsSupportedForLeAudio failed:" + status);
            return leAudioCodecConfigList;
        }

        for (Integer format : formatsList) {
            int btLeAudioCodec = AudioSystem.audioFormatToBluetoothLeAudioSourceCodec(format);
            if (btLeAudioCodec != BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_INVALID) {
@@ -6839,9 +6849,6 @@ public class AudioManager {
        }
        return leAudioCodecConfigList;
    }
        Log.e(TAG, "Input deviceType " + deviceType + " doesn't support.");
        return a2dpCodecConfigList;
    }

    // Since we need to calculate the changes since THE LAST NOTIFICATION, and not since the
    // (unpredictable) last time updateAudioPortCache() was called by someone, keep a list