Merge changes from topic "le_audio_allowlist" into main
* changes: Config LE audio connection by default LE Audio Allowlist toggle behavior refactor Remove allowlist reboot behavior Change the LE Audio Allowlist toggle wording
This commit is contained in:
@@ -21,6 +21,7 @@ import android.bluetooth.BluetoothManager;
|
||||
import android.bluetooth.BluetoothStatusCodes;
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.sysprop.BluetoothProperties;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
@@ -36,27 +37,27 @@ public class BluetoothLeAudioAllowListPreferenceController
|
||||
extends DeveloperOptionsPreferenceController
|
||||
implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
|
||||
|
||||
private static final String PREFERENCE_KEY = "bluetooth_enable_leaudio_allow_list";
|
||||
private static final String PREFERENCE_KEY = "bluetooth_bypass_leaudio_allowlist";
|
||||
|
||||
private static final String LE_AUDIO_ALLOW_LIST_SWITCH_SUPPORT_PROPERTY =
|
||||
"ro.bluetooth.leaudio_allow_list.supported";
|
||||
static final String LE_AUDIO_CONNECTION_BY_DEFAULT_PROPERTY =
|
||||
"ro.bluetooth.leaudio.le_audio_connection_by_default";
|
||||
@VisibleForTesting
|
||||
static final String LE_AUDIO_ALLOW_LIST_ENABLED_PROPERTY =
|
||||
"persist.bluetooth.leaudio.enable_allow_list";
|
||||
static final String BYPASS_LE_AUDIO_ALLOWLIST_PROPERTY =
|
||||
"persist.bluetooth.leaudio.bypass_allow_list";
|
||||
|
||||
@VisibleForTesting
|
||||
BluetoothAdapter mBluetoothAdapter;
|
||||
@VisibleForTesting boolean mLeAudioConnectionByDefault;
|
||||
|
||||
private final DevelopmentSettingsDashboardFragment mFragment;
|
||||
|
||||
@VisibleForTesting
|
||||
boolean mChanged = false;
|
||||
|
||||
public BluetoothLeAudioAllowListPreferenceController(Context context,
|
||||
DevelopmentSettingsDashboardFragment fragment) {
|
||||
super(context);
|
||||
mFragment = fragment;
|
||||
mBluetoothAdapter = context.getSystemService(BluetoothManager.class).getAdapter();
|
||||
mLeAudioConnectionByDefault =
|
||||
SystemProperties.getBoolean(LE_AUDIO_CONNECTION_BY_DEFAULT_PROPERTY, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,53 +65,49 @@ public class BluetoothLeAudioAllowListPreferenceController
|
||||
return PREFERENCE_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return BluetoothProperties.isProfileBapUnicastClientEnabled().orElse(false)
|
||||
&& mLeAudioConnectionByDefault;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
BluetoothRebootDialog.show(mFragment);
|
||||
mChanged = true;
|
||||
return false;
|
||||
final boolean isBypassed = (Boolean) newValue;
|
||||
SystemProperties.set(BYPASS_LE_AUDIO_ALLOWLIST_PROPERTY,
|
||||
isBypassed ? "true" : "false");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (mBluetoothAdapter == null) {
|
||||
mPreference.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
final int leAudioSupportedState = mBluetoothAdapter.isLeAudioSupported();
|
||||
final boolean leAudioEnabled =
|
||||
(leAudioSupportedState == BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||
final boolean leAudioAllowListSupport =
|
||||
SystemProperties.getBoolean(LE_AUDIO_ALLOW_LIST_SWITCH_SUPPORT_PROPERTY, false);
|
||||
|
||||
if (leAudioEnabled && leAudioAllowListSupport) {
|
||||
final boolean leAudioAllowListEnabled =
|
||||
SystemProperties.getBoolean(LE_AUDIO_ALLOW_LIST_ENABLED_PROPERTY, false);
|
||||
((SwitchPreference) mPreference).setChecked(leAudioAllowListEnabled);
|
||||
} else {
|
||||
final boolean isLeAudioSupported =
|
||||
(mBluetoothAdapter.isLeAudioSupported() == BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||
if (!isLeAudioSupported) {
|
||||
mPreference.setEnabled(false);
|
||||
((SwitchPreference) mPreference).setChecked(false);
|
||||
return;
|
||||
}
|
||||
|
||||
mPreference.setEnabled(true);
|
||||
final boolean isLeAudioAllowlistBypassed =
|
||||
SystemProperties.getBoolean(BYPASS_LE_AUDIO_ALLOWLIST_PROPERTY, false);
|
||||
((SwitchPreference) mPreference).setChecked(isLeAudioAllowlistBypassed);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDeveloperOptionsSwitchDisabled() {
|
||||
super.onDeveloperOptionsSwitchDisabled();
|
||||
final boolean isBypassed =
|
||||
SystemProperties.getBoolean(BYPASS_LE_AUDIO_ALLOWLIST_PROPERTY, false);
|
||||
if (isBypassed) {
|
||||
SystemProperties.set(BYPASS_LE_AUDIO_ALLOWLIST_PROPERTY, Boolean.toString(false));
|
||||
((SwitchPreference) mPreference).setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the RebootDialog confirm is clicked.
|
||||
*/
|
||||
public void onRebootDialogConfirmed() {
|
||||
if (!mChanged) {
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean leAudioAllowListEnabled =
|
||||
SystemProperties.getBoolean(LE_AUDIO_ALLOW_LIST_ENABLED_PROPERTY, false);
|
||||
SystemProperties.set(LE_AUDIO_ALLOW_LIST_ENABLED_PROPERTY,
|
||||
Boolean.toString(!leAudioAllowListEnabled));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the RebootDialog cancel is clicked.
|
||||
*/
|
||||
public void onRebootDialogCanceled() {
|
||||
mChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,11 +442,6 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
getDevelopmentOptionsController(
|
||||
BluetoothLeAudioPreferenceController.class);
|
||||
leAudioFeatureController.onRebootDialogConfirmed();
|
||||
|
||||
final BluetoothLeAudioAllowListPreferenceController leAudioAllowListController =
|
||||
getDevelopmentOptionsController(
|
||||
BluetoothLeAudioAllowListPreferenceController.class);
|
||||
leAudioAllowListController.onRebootDialogConfirmed();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -464,11 +459,6 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
getDevelopmentOptionsController(
|
||||
BluetoothLeAudioPreferenceController.class);
|
||||
leAudioFeatureController.onRebootDialogCanceled();
|
||||
|
||||
final BluetoothLeAudioAllowListPreferenceController leAudioAllowListController =
|
||||
getDevelopmentOptionsController(
|
||||
BluetoothLeAudioAllowListPreferenceController.class);
|
||||
leAudioAllowListController.onRebootDialogCanceled();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user