From ddec75bb398fd59d24681759244ddcc7a9b6386e Mon Sep 17 00:00:00 2001 From: Alice Kuo Date: Sun, 8 Oct 2023 05:09:24 +0800 Subject: [PATCH] Config LE audio connection by default Use LE audio connection by default, and allow to have the differenct configuration per project (system property). As using LE audio connection by default, the toggle, "Show LE audio toggle in Device Details", would be useless, hide this toggle based on the project configuration Bug: 300012501 Test: make RunSettingsRoboTests ROBOTEST_FILTER=BluetoothLeDeviceDetailsPreferenceControllerTest Change-Id: Ia4df48d6a71b5b9f11bd91a69971c8393412da13 --- .../BluetoothDetailsProfilesController.java | 9 +++++---- ...LeAudioDeviceDetailsPreferenceController.java | 16 ++++++++-------- ...dioDeviceDetailsPreferenceControllerTest.java | 8 ++++++++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java index f473f2c91f6..84504a91785 100644 --- a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java +++ b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java @@ -68,7 +68,8 @@ 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 String LE_AUDIO_CONNECTION_BY_DEFAULT_PROPERTY = + "ro.bluetooth.leaudio.le_audio_connection_by_default"; 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"; @@ -469,12 +470,12 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll SettingsUIDeviceConfig.BT_LE_AUDIO_CONTACT_SHARING_ENABLED, true); 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); + boolean isLeEnabledByDefault = + SystemProperties.getBoolean(LE_AUDIO_CONNECTION_BY_DEFAULT_PROPERTY, true); mIsLeAudioToggleEnabled = isLeAudioToggleVisible || isLeEnabledByDefault; Log.d(TAG, "BT_LE_AUDIO_CONTACT_SHARING_ENABLED:" + mIsLeContactSharingEnabled + ", LE_AUDIO_TOGGLE_VISIBLE_PROPERTY:" + isLeAudioToggleVisible - + ", CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT:" + isLeEnabledByDefault); + + ", LE_AUDIO_CONNECTION_BY_DEFAULT_PROPERTY:" + isLeEnabledByDefault); } @Override diff --git a/src/com/android/settings/development/BluetoothLeAudioDeviceDetailsPreferenceController.java b/src/com/android/settings/development/BluetoothLeAudioDeviceDetailsPreferenceController.java index 980bdaa8f5e..16d8b327854 100644 --- a/src/com/android/settings/development/BluetoothLeAudioDeviceDetailsPreferenceController.java +++ b/src/com/android/settings/development/BluetoothLeAudioDeviceDetailsPreferenceController.java @@ -21,7 +21,6 @@ import android.bluetooth.BluetoothManager; import android.bluetooth.BluetoothStatusCodes; import android.content.Context; import android.os.SystemProperties; -import android.provider.DeviceConfig; import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; @@ -39,7 +38,8 @@ public class BluetoothLeAudioDeviceDetailsPreferenceController implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { 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 String LE_AUDIO_CONNECTION_BY_DEFAULT_PROPERTY = + "ro.bluetooth.leaudio.le_audio_connection_by_default"; private static final boolean LE_AUDIO_TOGGLE_VISIBLE_DEFAULT_VALUE = true; static int sLeAudioSupportedStateCache = BluetoothStatusCodes.ERROR_UNKNOWN; @@ -48,10 +48,13 @@ public class BluetoothLeAudioDeviceDetailsPreferenceController @VisibleForTesting BluetoothAdapter mBluetoothAdapter; + @VisibleForTesting boolean mLeAudioEnabledByDefault; public BluetoothLeAudioDeviceDetailsPreferenceController(Context context) { super(context); mBluetoothAdapter = context.getSystemService(BluetoothManager.class).getAdapter(); + mLeAudioEnabledByDefault = + SystemProperties.getBoolean(LE_AUDIO_CONNECTION_BY_DEFAULT_PROPERTY, true); } @Override @@ -70,7 +73,8 @@ public class BluetoothLeAudioDeviceDetailsPreferenceController } // Display the option only if LE Audio is supported - return (sLeAudioSupportedStateCache == BluetoothStatusCodes.FEATURE_SUPPORTED); + return !mLeAudioEnabledByDefault + && (sLeAudioSupportedStateCache == BluetoothStatusCodes.FEATURE_SUPPORTED); } @Override @@ -88,11 +92,7 @@ public class BluetoothLeAudioDeviceDetailsPreferenceController 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(isLeAudioToggleVisible - || leAudioEnabledByDefault); + ((SwitchPreference) mPreference).setChecked(isLeAudioToggleVisible); } } diff --git a/tests/robotests/src/com/android/settings/development/BluetoothLeAudioDeviceDetailsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothLeAudioDeviceDetailsPreferenceControllerTest.java index 13bc6a406bd..36c92318112 100644 --- a/tests/robotests/src/com/android/settings/development/BluetoothLeAudioDeviceDetailsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/BluetoothLeAudioDeviceDetailsPreferenceControllerTest.java @@ -114,6 +114,7 @@ public class BluetoothLeAudioDeviceDetailsPreferenceControllerTest { @Test public void isAvailable_leAudioSupported() { + mController.mLeAudioEnabledByDefault = false; mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.ERROR_UNKNOWN; when(mBluetoothAdapter.isLeAudioSupported()) .thenReturn(BluetoothStatusCodes.FEATURE_SUPPORTED); @@ -122,9 +123,16 @@ public class BluetoothLeAudioDeviceDetailsPreferenceControllerTest { @Test public void isAvailable_leAudioNotSupported() { + mController.mLeAudioEnabledByDefault = false; mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.ERROR_UNKNOWN; when(mBluetoothAdapter.isLeAudioSupported()) .thenReturn(BluetoothStatusCodes.FEATURE_NOT_SUPPORTED); assertThat(mController.isAvailable()).isFalse(); } + + @Test + public void isUnAvailable_ifLeAudioConnectionByDefault() { + mController.mLeAudioEnabledByDefault = true; + assertThat(mController.isAvailable()).isFalse(); + } }