Hide LeAudio toggle for LeAudio-only device

Bug: 333827147
Test: atest BluetoothDetailsProfilesControllerTest
Change-Id: Ie446d8866fb51972795b66aac2db84703ef51b84
This commit is contained in:
Haijie Hong
2024-04-17 16:05:36 +08:00
parent 82e71b7278
commit 0307bbfb1f
3 changed files with 76 additions and 0 deletions

View File

@@ -43,6 +43,7 @@ import com.android.settingslib.bluetooth.A2dpProfile;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HeadsetProfile;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfile;
@@ -512,6 +513,19 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
refresh();
}
private boolean isLeAudioOnlyDevice() {
if (mCachedDevice.getProfiles().stream()
.noneMatch(profile -> profile instanceof LeAudioProfile)) {
return false;
}
return mCachedDevice.getProfiles().stream()
.noneMatch(
profile ->
profile instanceof HearingAidProfile
|| profile instanceof A2dpProfile
|| profile instanceof HeadsetProfile);
}
private void updateLeAudioConfig() {
mIsLeContactSharingEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
SettingsUIDeviceConfig.BT_LE_AUDIO_CONTACT_SHARING_ENABLED, true);
@@ -520,6 +534,13 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
boolean isLeEnabledByDefault =
SystemProperties.getBoolean(LE_AUDIO_CONNECTION_BY_DEFAULT_PROPERTY, true);
mIsLeAudioToggleEnabled = isLeAudioToggleVisible || isLeEnabledByDefault;
if (Flags.hideLeAudioToggleForLeAudioOnlyDevice() && isLeAudioOnlyDevice()) {
mIsLeAudioToggleEnabled = false;
Log.d(
TAG,
"Hide LeAudio toggle for LeAudio-only Device: "
+ mCachedDevice.getDevice().getAnonymizedAddress());
}
Log.d(TAG, "BT_LE_AUDIO_CONTACT_SHARING_ENABLED:" + mIsLeContactSharingEnabled
+ ", LE_AUDIO_TOGGLE_VISIBLE_PROPERTY:" + isLeAudioToggleVisible
+ ", LE_AUDIO_CONNECTION_BY_DEFAULT_PROPERTY:" + isLeEnabledByDefault);