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
This commit is contained in:
Alice Kuo
2023-10-08 05:09:24 +08:00
parent b2336ea7db
commit ddec75bb39
3 changed files with 21 additions and 12 deletions

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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();
}
}