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

Commit 2d7a4692 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use system properties for the le audio toggle ui config instead" into udc-qpr-dev

parents 821ed070 aa734eb5
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -69,7 +69,9 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
    private static final String ENABLE_DUAL_MODE_AUDIO =
            "persist.bluetooth.enable_dual_mode_audio";
    private static final String CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT = "le_audio_enabled_by_default";
    private static final boolean LE_AUDIO_DEVICE_DETAIL_DEFAULT_VALUE = true;
    private static final boolean LE_AUDIO_TOGGLE_VISIBLE_DEFAULT_VALUE = true;
    private static final String LE_AUDIO_TOGGLE_VISIBLE_PROPERTY =
            "persist.bluetooth.leaudio.toggle_visible";

    private LocalBluetoothManager mManager;
    private LocalBluetoothProfileManager mProfileManager;
@@ -464,15 +466,13 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
    private void updateLeAudioConfig() {
        mIsLeContactSharingEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
                SettingsUIDeviceConfig.BT_LE_AUDIO_CONTACT_SHARING_ENABLED, true);
        boolean isLeDeviceDetailEnabled = DeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_SETTINGS_UI,
                SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED,
                LE_AUDIO_DEVICE_DETAIL_DEFAULT_VALUE);
        boolean isLeAudioToggleVisible = SystemProperties.getBoolean(
                LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, LE_AUDIO_TOGGLE_VISIBLE_DEFAULT_VALUE);
        boolean isLeEnabledByDefault = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH,
                CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT, false);
        mIsLeAudioToggleEnabled = isLeDeviceDetailEnabled || isLeEnabledByDefault;
        mIsLeAudioToggleEnabled = isLeAudioToggleVisible || isLeEnabledByDefault;
        Log.d(TAG, "BT_LE_AUDIO_CONTACT_SHARING_ENABLED:" + mIsLeContactSharingEnabled
                + ", BT_LE_AUDIO_DEVICE_DETAIL_ENABLED:" + isLeDeviceDetailEnabled
                + ", LE_AUDIO_TOGGLE_VISIBLE_PROPERTY:" + isLeAudioToggleVisible
                + ", CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT:" + isLeEnabledByDefault);
    }

+0 −5
Original line number Diff line number Diff line
@@ -42,9 +42,4 @@ public class SettingsUIDeviceConfig {
     * {@code true} whether or not event_log for generic actions is enabled. Default is true.
     */
    public static final String GENERIC_EVENT_LOGGING_ENABLED = "event_logging_enabled";
    /**
     * {@code true} whether to show LE Audio toggle in device detail page. Default is false.
     */
    public static final String BT_LE_AUDIO_DEVICE_DETAIL_ENABLED =
            "bt_le_audio_device_detail_enabled";
}
+9 −21
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothStatusCodes;
import android.content.Context;
import android.os.SystemProperties;
import android.provider.DeviceConfig;

import androidx.annotation.VisibleForTesting;
@@ -27,7 +28,6 @@ import androidx.preference.Preference;
import androidx.preference.SwitchPreference;

import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.SettingsUIDeviceConfig;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;

/**
@@ -40,9 +40,12 @@ public class BluetoothLeAudioDeviceDetailsPreferenceController

    private static final String PREFERENCE_KEY = "bluetooth_show_leaudio_device_details";
    private static final String CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT = "le_audio_enabled_by_default";
    private static final boolean LE_AUDIO_DEVICE_DETAIL_DEFAULT_VALUE = true;
    private static final boolean LE_AUDIO_TOGGLE_VISIBLE_DEFAULT_VALUE = true;
    static int sLeAudioSupportedStateCache = BluetoothStatusCodes.ERROR_UNKNOWN;

    static final String LE_AUDIO_TOGGLE_VISIBLE_PROPERTY =
            "persist.bluetooth.leaudio.toggle_visible";

    @VisibleForTesting
    BluetoothAdapter mBluetoothAdapter;

@@ -73,10 +76,7 @@ public class BluetoothLeAudioDeviceDetailsPreferenceController
    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        final boolean isEnabled = (Boolean) newValue;
        DeviceConfig.setProperty(
                DeviceConfig.NAMESPACE_SETTINGS_UI,
                SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED,
                isEnabled ? "true" : "false", LE_AUDIO_DEVICE_DETAIL_DEFAULT_VALUE);
        SystemProperties.set(LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, Boolean.toString(isEnabled));
        return true;
    }

@@ -86,25 +86,13 @@ public class BluetoothLeAudioDeviceDetailsPreferenceController
            return;
        }

        final boolean leAudioDeviceDetailEnabled = DeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_SETTINGS_UI,
                SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED,
                LE_AUDIO_DEVICE_DETAIL_DEFAULT_VALUE);
        final boolean isLeAudioToggleVisible = SystemProperties.getBoolean(
                LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, LE_AUDIO_TOGGLE_VISIBLE_DEFAULT_VALUE);
        final boolean leAudioEnabledByDefault = DeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_BLUETOOTH, CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT, false);

        mPreference.setEnabled(!leAudioEnabledByDefault);
        ((SwitchPreference) mPreference).setChecked(leAudioDeviceDetailEnabled
        ((SwitchPreference) mPreference).setChecked(isLeAudioToggleVisible
                || leAudioEnabledByDefault);
    }

    @Override
    protected void onDeveloperOptionsSwitchDisabled() {
        super.onDeveloperOptionsSwitchDisabled();
        // Reset the toggle to null when the developer option is disabled
        DeviceConfig.setProperty(
                DeviceConfig.NAMESPACE_SETTINGS_UI,
                SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED, "null",
                LE_AUDIO_DEVICE_DETAIL_DEFAULT_VALUE);
    }
}
+10 −13
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.settings.development;

import static com.android.settings.development.BluetoothLeAudioDeviceDetailsPreferenceController
        .LE_AUDIO_TOGGLE_VISIBLE_PROPERTY;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.spy;
@@ -25,12 +28,11 @@ import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothStatusCodes;
import android.content.Context;
import android.provider.DeviceConfig;
import android.os.SystemProperties;

import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;

import com.android.settings.core.SettingsUIDeviceConfig;
import com.android.settings.testutils.shadow.ShadowDeviceConfig;

import org.junit.After;
@@ -77,9 +79,8 @@ public class BluetoothLeAudioDeviceDetailsPreferenceControllerTest {
    public void onPreferenceChanged_settingEnabled_shouldTurnOnLeAudioDeviceDetailSetting() {
        mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.FEATURE_SUPPORTED;
        mController.onPreferenceChange(mPreference, true /* new value */);
        final boolean isEnabled = DeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_SETTINGS_UI,
                SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED, false);
        final boolean isEnabled = SystemProperties.getBoolean(
                LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, false);

        assertThat(isEnabled).isTrue();
    }
@@ -88,9 +89,8 @@ public class BluetoothLeAudioDeviceDetailsPreferenceControllerTest {
    public void onPreferenceChanged_settingDisabled_shouldTurnOffLeAudioDeviceDetailSetting() {
        mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.FEATURE_SUPPORTED;
        mController.onPreferenceChange(mPreference, false /* new value */);
        final boolean isEnabled = DeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_SETTINGS_UI,
                SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED, false);
        final boolean isEnabled = SystemProperties.getBoolean(
                LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, true);

        assertThat(isEnabled).isFalse();
    }
@@ -98,18 +98,15 @@ public class BluetoothLeAudioDeviceDetailsPreferenceControllerTest {
    @Test
    public void updateState_settingEnabled_preferenceShouldBeChecked() {
        mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.FEATURE_SUPPORTED;
        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI,
                SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED, "true", false);
        SystemProperties.set(LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, "true");
        mController.updateState(mPreference);

        verify(mPreference).setChecked(true);
    }

    @Test
    public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
        mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.FEATURE_SUPPORTED;
        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI,
                SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED, "false", false);
        SystemProperties.set(LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, "false");
        mController.updateState(mPreference);

        verify(mPreference).setChecked(false);