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
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
index f473f2c..84504a9 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
@@ -68,7 +68,8 @@
 
     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 @@
                 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 980bdaa..16d8b32 100644
--- a/src/com/android/settings/development/BluetoothLeAudioDeviceDetailsPreferenceController.java
+++ b/src/com/android/settings/development/BluetoothLeAudioDeviceDetailsPreferenceController.java
@@ -21,7 +21,6 @@
 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 @@
         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 @@
 
     @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 @@
         }
 
         // 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 @@
 
         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 13bc6a4..36c9231 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 @@
 
     @Test
     public void isAvailable_leAudioSupported() {
+        mController.mLeAudioEnabledByDefault = false;
         mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.ERROR_UNKNOWN;
         when(mBluetoothAdapter.isLeAudioSupported())
                 .thenReturn(BluetoothStatusCodes.FEATURE_SUPPORTED);
@@ -122,9 +123,16 @@
 
     @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();
+    }
 }