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

Commit f71b2ea5 authored by Alice Kuo's avatar Alice Kuo
Browse files

Grey out LE audio offload switcher as LE audio isn't enabled/supported

Screenshot: https://screenshot.googleplex.com/C6pRBzLh7CtNeXr

Bug: 233018305
Bug: 233005340
Test: make RunSettingsRoboTests ROBOTEST_FILTER=BluetoothLeAudioHwOffloadPreferenceControllerTest
Change-Id: I0ea498d2fa191f9b9352b37500a5d2c348b36ce0
parent b13abc03
Loading
Loading
Loading
Loading
+24 −2
Original line number Diff line number Diff line
@@ -18,6 +18,9 @@ package com.android.settings.development;

import static com.android.settings.development.BluetoothA2dpHwOffloadPreferenceController.A2DP_OFFLOAD_SUPPORTED_PROPERTY;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothStatusCodes;
import android.content.Context;
import android.os.SystemProperties;

@@ -43,6 +46,9 @@ public class BluetoothLeAudioHwOffloadPreferenceController
    static final String LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY =
            "ro.bluetooth.leaudio_offload.supported";

    @VisibleForTesting
    BluetoothAdapter mBluetoothAdapter;

    @VisibleForTesting
    boolean mChanged = false;

@@ -50,6 +56,7 @@ public class BluetoothLeAudioHwOffloadPreferenceController
            DevelopmentSettingsDashboardFragment fragment) {
        super(context);
        mFragment = fragment;
        mBluetoothAdapter = context.getSystemService(BluetoothManager.class).getAdapter();
    }

    @Override
@@ -66,10 +73,17 @@ public class BluetoothLeAudioHwOffloadPreferenceController

    @Override
    public void updateState(Preference preference) {
        if (mBluetoothAdapter == null) {
            return;
        }

        final boolean leAudioEnabled =
                (mBluetoothAdapter.isLeAudioSupported() == BluetoothStatusCodes.FEATURE_SUPPORTED);

        final boolean offloadSupported =
                SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false)
                && SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false);
        if (offloadSupported) {
        if (leAudioEnabled && offloadSupported) {
            final boolean offloadDisabled =
                    SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, true);
            ((SwitchPreference) mPreference).setChecked(offloadDisabled);
@@ -82,12 +96,20 @@ public class BluetoothLeAudioHwOffloadPreferenceController
    @Override
    protected void onDeveloperOptionsSwitchDisabled() {
        super.onDeveloperOptionsSwitchDisabled();
        if (mBluetoothAdapter == null) {
            return;
        }

        final boolean leAudioEnabled =
                (mBluetoothAdapter.isLeAudioSupported() == BluetoothStatusCodes.FEATURE_SUPPORTED);
        final boolean offloadSupported =
                SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false)
                && SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false);
        if (offloadSupported) {
        if (leAudioEnabled && offloadSupported) {
            ((SwitchPreference) mPreference).setChecked(true);
            SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, "true");
        } else {
            mPreference.setEnabled(false);
        }
    }