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

This commit is contained in:
Treehugger Robot
2023-09-19 06:31:29 +00:00
committed by Android (Google) Code Review
4 changed files with 26 additions and 46 deletions

View File

@@ -69,7 +69,9 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
private static final String ENABLE_DUAL_MODE_AUDIO = private static final String ENABLE_DUAL_MODE_AUDIO =
"persist.bluetooth.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 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 LocalBluetoothManager mManager;
private LocalBluetoothProfileManager mProfileManager; private LocalBluetoothProfileManager mProfileManager;
@@ -464,15 +466,13 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
private void updateLeAudioConfig() { private void updateLeAudioConfig() {
mIsLeContactSharingEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI, mIsLeContactSharingEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
SettingsUIDeviceConfig.BT_LE_AUDIO_CONTACT_SHARING_ENABLED, true); SettingsUIDeviceConfig.BT_LE_AUDIO_CONTACT_SHARING_ENABLED, true);
boolean isLeDeviceDetailEnabled = DeviceConfig.getBoolean( boolean isLeAudioToggleVisible = SystemProperties.getBoolean(
DeviceConfig.NAMESPACE_SETTINGS_UI, LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, LE_AUDIO_TOGGLE_VISIBLE_DEFAULT_VALUE);
SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED,
LE_AUDIO_DEVICE_DETAIL_DEFAULT_VALUE);
boolean isLeEnabledByDefault = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, boolean isLeEnabledByDefault = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH,
CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT, false); CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT, false);
mIsLeAudioToggleEnabled = isLeDeviceDetailEnabled || isLeEnabledByDefault; mIsLeAudioToggleEnabled = isLeAudioToggleVisible || isLeEnabledByDefault;
Log.d(TAG, "BT_LE_AUDIO_CONTACT_SHARING_ENABLED:" + mIsLeContactSharingEnabled 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); + ", CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT:" + isLeEnabledByDefault);
} }

View File

@@ -42,9 +42,4 @@ public class SettingsUIDeviceConfig {
* {@code true} whether or not event_log for generic actions is enabled. Default is true. * {@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"; 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";
} }

View File

@@ -20,6 +20,7 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager; import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothStatusCodes; import android.bluetooth.BluetoothStatusCodes;
import android.content.Context; import android.content.Context;
import android.os.SystemProperties;
import android.provider.DeviceConfig; import android.provider.DeviceConfig;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
@@ -27,7 +28,6 @@ import androidx.preference.Preference;
import androidx.preference.SwitchPreference; import androidx.preference.SwitchPreference;
import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.SettingsUIDeviceConfig;
import com.android.settingslib.development.DeveloperOptionsPreferenceController; 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 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 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 int sLeAudioSupportedStateCache = BluetoothStatusCodes.ERROR_UNKNOWN;
static final String LE_AUDIO_TOGGLE_VISIBLE_PROPERTY =
"persist.bluetooth.leaudio.toggle_visible";
@VisibleForTesting @VisibleForTesting
BluetoothAdapter mBluetoothAdapter; BluetoothAdapter mBluetoothAdapter;
@@ -73,10 +76,7 @@ public class BluetoothLeAudioDeviceDetailsPreferenceController
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean isEnabled = (Boolean) newValue; final boolean isEnabled = (Boolean) newValue;
DeviceConfig.setProperty( SystemProperties.set(LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, Boolean.toString(isEnabled));
DeviceConfig.NAMESPACE_SETTINGS_UI,
SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED,
isEnabled ? "true" : "false", LE_AUDIO_DEVICE_DETAIL_DEFAULT_VALUE);
return true; return true;
} }
@@ -86,25 +86,13 @@ public class BluetoothLeAudioDeviceDetailsPreferenceController
return; return;
} }
final boolean leAudioDeviceDetailEnabled = DeviceConfig.getBoolean( final boolean isLeAudioToggleVisible = SystemProperties.getBoolean(
DeviceConfig.NAMESPACE_SETTINGS_UI, LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, LE_AUDIO_TOGGLE_VISIBLE_DEFAULT_VALUE);
SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED,
LE_AUDIO_DEVICE_DETAIL_DEFAULT_VALUE);
final boolean leAudioEnabledByDefault = DeviceConfig.getBoolean( final boolean leAudioEnabledByDefault = DeviceConfig.getBoolean(
DeviceConfig.NAMESPACE_BLUETOOTH, CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT, false); DeviceConfig.NAMESPACE_BLUETOOTH, CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT, false);
mPreference.setEnabled(!leAudioEnabledByDefault); mPreference.setEnabled(!leAudioEnabledByDefault);
((SwitchPreference) mPreference).setChecked(leAudioDeviceDetailEnabled ((SwitchPreference) mPreference).setChecked(isLeAudioToggleVisible
|| leAudioEnabledByDefault); || 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);
}
} }

View File

@@ -16,6 +16,9 @@
package com.android.settings.development; 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 com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
@@ -25,12 +28,11 @@ import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothStatusCodes; import android.bluetooth.BluetoothStatusCodes;
import android.content.Context; import android.content.Context;
import android.provider.DeviceConfig; import android.os.SystemProperties;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference; import androidx.preference.SwitchPreference;
import com.android.settings.core.SettingsUIDeviceConfig;
import com.android.settings.testutils.shadow.ShadowDeviceConfig; import com.android.settings.testutils.shadow.ShadowDeviceConfig;
import org.junit.After; import org.junit.After;
@@ -77,9 +79,8 @@ public class BluetoothLeAudioDeviceDetailsPreferenceControllerTest {
public void onPreferenceChanged_settingEnabled_shouldTurnOnLeAudioDeviceDetailSetting() { public void onPreferenceChanged_settingEnabled_shouldTurnOnLeAudioDeviceDetailSetting() {
mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.FEATURE_SUPPORTED; mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.FEATURE_SUPPORTED;
mController.onPreferenceChange(mPreference, true /* new value */); mController.onPreferenceChange(mPreference, true /* new value */);
final boolean isEnabled = DeviceConfig.getBoolean( final boolean isEnabled = SystemProperties.getBoolean(
DeviceConfig.NAMESPACE_SETTINGS_UI, LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, false);
SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED, false);
assertThat(isEnabled).isTrue(); assertThat(isEnabled).isTrue();
} }
@@ -88,9 +89,8 @@ public class BluetoothLeAudioDeviceDetailsPreferenceControllerTest {
public void onPreferenceChanged_settingDisabled_shouldTurnOffLeAudioDeviceDetailSetting() { public void onPreferenceChanged_settingDisabled_shouldTurnOffLeAudioDeviceDetailSetting() {
mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.FEATURE_SUPPORTED; mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.FEATURE_SUPPORTED;
mController.onPreferenceChange(mPreference, false /* new value */); mController.onPreferenceChange(mPreference, false /* new value */);
final boolean isEnabled = DeviceConfig.getBoolean( final boolean isEnabled = SystemProperties.getBoolean(
DeviceConfig.NAMESPACE_SETTINGS_UI, LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, true);
SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED, false);
assertThat(isEnabled).isFalse(); assertThat(isEnabled).isFalse();
} }
@@ -98,18 +98,15 @@ public class BluetoothLeAudioDeviceDetailsPreferenceControllerTest {
@Test @Test
public void updateState_settingEnabled_preferenceShouldBeChecked() { public void updateState_settingEnabled_preferenceShouldBeChecked() {
mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.FEATURE_SUPPORTED; mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.FEATURE_SUPPORTED;
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI, SystemProperties.set(LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, "true");
SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED, "true", false);
mController.updateState(mPreference); mController.updateState(mPreference);
verify(mPreference).setChecked(true); verify(mPreference).setChecked(true);
} }
@Test @Test
public void updateState_settingDisabled_preferenceShouldNotBeChecked() { public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.FEATURE_SUPPORTED; mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.FEATURE_SUPPORTED;
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI, SystemProperties.set(LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, "false");
SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED, "false", false);
mController.updateState(mPreference); mController.updateState(mPreference);
verify(mPreference).setChecked(false); verify(mPreference).setChecked(false);