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

Commit 89612e53 authored by Jakub Rotkiewicz's avatar Jakub Rotkiewicz
Browse files

Refactor Bluetooth Codec settings to dynamic ListPreference

Fetch supported codecs from native and present to user using
ListPreference.

Bug: 305779598
Bug: 311451118
Bug: 323319530
Tag: #feature
Test: atest SettingsRoboTests:com.android.settings.development.bluetooth.AbstractBluetoothListPreferenceController
Test: atest SettingsRoboTests:com.android.settings.development.bluetooth.BluetoothCodecListPreferenceControllerTest

Change-Id: Iedbfd01c0d1b59df8a073f4e9aedca3913e6d45f
parent 59007733
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
package: "com.android.settings.development"
container: "system"

flag {
  name: "a2dp_offload_codec_extensibility_settings"
  namespace: "bluetooth"
  description: "Feature flag for Bluetooth Audio Codec extensibility in Settings"
  bug: "323319530"
}

flag {
  name: "deprecate_list_activity"
  namespace: "android_settings"
+3 −0
Original line number Diff line number Diff line
@@ -178,6 +178,9 @@
    <!-- Description for text in accessibility hearing aids footer. [CHAR LIMIT=NONE] -->
    <string name="bluetooth_audio_routing_footer_summary">By default, audio output is determined by individual apps</string>
    <!-- Bluetooth audio codec related settings. Title of the default audio codec selection. [CHAR LIMIT=60] -->
    <string name="bluetooth_audio_codec_default_selection">Use System Selection (Default)</string>
    <!--Bluetooth settings screen, summary text for Bluetooth device with no name -->
    <string name="bluetooth_device">Unnamed Bluetooth device</string>
    <!--Bluetooth settings screen, text that appears in heading bar when scanning for devices -->
+5 −0
Original line number Diff line number Diff line
@@ -430,6 +430,11 @@
            android:positiveButtonText=""
            android:negativeButtonText="@string/dlg_ok"/>

        <ListPreference
            android:key="bluetooth_audio_codec_settings_list"
            android:title="@string/bluetooth_select_a2dp_codec_type"
            android:dialogTitle="@string/bluetooth_select_a2dp_codec_type_dialog_title"/>

        <com.android.settings.development.bluetooth.BluetoothSampleRateDialogPreference
            android:key="bluetooth_sample_rate_settings"
            android:title="@string/bluetooth_select_a2dp_codec_sample_rate"
+30 −5
Original line number Diff line number Diff line
@@ -16,15 +16,19 @@

package com.android.settings.development;

import android.annotation.FlaggedApi;
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecType;

/**
 * Utility class for storing current Bluetooth A2DP profile values
 */
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/** Utility class for storing current Bluetooth A2DP profile values */
public class BluetoothA2dpConfigStore {

    // init default values
    private int mCodecType = BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID;
    private int mCodecTypeNative = BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID;
    @Nullable private BluetoothCodecType mCodecType = null;
    private int mCodecPriority = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
    private int mSampleRate = BluetoothCodecConfig.SAMPLE_RATE_NONE;
    private int mBitsPerSample = BluetoothCodecConfig.BITS_PER_SAMPLE_NONE;
@@ -35,6 +39,10 @@ public class BluetoothA2dpConfigStore {
    private long mCodecSpecific4Value;

    public void setCodecType(int codecType) {
        mCodecTypeNative = codecType;
    }

    public void setCodecType(@Nullable BluetoothCodecType codecType) {
        mCodecType = codecType;
    }

@@ -70,9 +78,26 @@ public class BluetoothA2dpConfigStore {
        mCodecSpecific4Value = codecSpecific4Value;
    }

    /** Create codec config utilizing {@link BluetoothCodecConfig.SourceCodecType} */
    public BluetoothCodecConfig createCodecConfig() {
        return new BluetoothCodecConfig.Builder()
                .setCodecType(mCodecType)
                .setCodecType(mCodecTypeNative)
                .setCodecPriority(mCodecPriority)
                .setSampleRate(mSampleRate)
                .setBitsPerSample(mBitsPerSample)
                .setChannelMode(mChannelMode)
                .setCodecSpecific1(mCodecSpecific1Value)
                .setCodecSpecific2(mCodecSpecific2Value)
                .setCodecSpecific3(mCodecSpecific3Value)
                .setCodecSpecific4(mCodecSpecific4Value)
                .build();
    }

    /** Create codec config utilizing {@link BluetoothCodecType} */
    @FlaggedApi(Flags.FLAG_A2DP_OFFLOAD_CODEC_EXTENSIBILITY_SETTINGS)
    public @NonNull BluetoothCodecConfig createCodecConfigFromCodecType() {
        return new BluetoothCodecConfig.Builder()
                .setExtendedCodecType(mCodecType)
                .setCodecPriority(mCodecPriority)
                .setSampleRate(mSampleRate)
                .setBitsPerSample(mBitsPerSample)
+8 −0
Original line number Diff line number Diff line
@@ -62,10 +62,12 @@ import com.android.settings.development.autofill.AutofillCategoryController;
import com.android.settings.development.autofill.AutofillLoggingLevelPreferenceController;
import com.android.settings.development.autofill.AutofillResetOptionsPreferenceController;
import com.android.settings.development.bluetooth.AbstractBluetoothDialogPreferenceController;
import com.android.settings.development.bluetooth.AbstractBluetoothListPreferenceController;
import com.android.settings.development.bluetooth.AbstractBluetoothPreferenceController;
import com.android.settings.development.bluetooth.BluetoothBitPerSampleDialogPreferenceController;
import com.android.settings.development.bluetooth.BluetoothChannelModeDialogPreferenceController;
import com.android.settings.development.bluetooth.BluetoothCodecDialogPreferenceController;
import com.android.settings.development.bluetooth.BluetoothCodecListPreferenceController;
import com.android.settings.development.bluetooth.BluetoothHDAudioPreferenceController;
import com.android.settings.development.bluetooth.BluetoothQualityDialogPreferenceController;
import com.android.settings.development.bluetooth.BluetoothSampleRateDialogPreferenceController;
@@ -744,6 +746,9 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
        controllers.add(new AutofillResetOptionsPreferenceController(context));
        controllers.add(new BluetoothCodecDialogPreferenceController(context, lifecycle,
                bluetoothA2dpConfigStore, fragment));
        controllers.add(
                new BluetoothCodecListPreferenceController(
                        context, lifecycle, bluetoothA2dpConfigStore, fragment));
        controllers.add(new BluetoothSampleRateDialogPreferenceController(context, lifecycle,
                bluetoothA2dpConfigStore));
        controllers.add(new BluetoothBitPerSampleDialogPreferenceController(context, lifecycle,
@@ -792,6 +797,9 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
                ((AbstractBluetoothDialogPreferenceController) controller).onHDAudioEnabled(
                        enabled);
            }
            if (controller instanceof AbstractBluetoothListPreferenceController) {
                ((AbstractBluetoothListPreferenceController) controller).onHDAudioEnabled(enabled);
            }
        }
    }

Loading