Add bluetooth profile toggle visibility checker

Bug: 321178209
Test: atest BluetoothDetailsProfilesControllerTest
Change-Id: Ic6c040a5a500d51945893061623526271eba94c7
This commit is contained in:
Haijie Hong
2024-01-22 15:36:57 +08:00
parent 628ebac9e2
commit 82688cc1d3
5 changed files with 157 additions and 29 deletions

View File

@@ -37,6 +37,8 @@ import androidx.preference.TwoStatePreference;
import com.android.settings.R;
import com.android.settings.core.SettingsUIDeviceConfig;
import com.android.settings.flags.Flags;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.bluetooth.A2dpProfile;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
@@ -49,11 +51,14 @@ import com.android.settingslib.bluetooth.MapProfile;
import com.android.settingslib.bluetooth.PanProfile;
import com.android.settingslib.bluetooth.PbapServerProfile;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
/**
* This class adds switches for toggling the individual profiles that a Bluetooth device
@@ -79,6 +84,8 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
private static final String LE_AUDIO_TOGGLE_VISIBLE_PROPERTY =
"persist.bluetooth.leaudio.toggle_visible";
private final AtomicReference<Set<String>> mInvisiblePreferenceKey = new AtomicReference<>();
private LocalBluetoothManager mManager;
private LocalBluetoothProfileManager mProfileManager;
private CachedBluetoothDevice mCachedDevice;
@@ -547,6 +554,22 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
*/
@Override
protected void refresh() {
if (Flags.enableBluetoothProfileToggleVisibilityChecker()) {
ThreadUtils.postOnBackgroundThread(
() -> {
mInvisiblePreferenceKey.set(
FeatureFactory.getFeatureFactory()
.getBluetoothFeatureProvider()
.getInvisibleProfilePreferenceKeys(
mContext, mCachedDevice.getDevice()));
ThreadUtils.postOnMainThread(this::refreshUi);
});
} else {
refreshUi();
}
}
private void refreshUi() {
for (LocalBluetoothProfile profile : getProfiles()) {
if (profile == null || !profile.isProfileReady()) {
continue;
@@ -577,6 +600,16 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
preference.setSelectable(false);
mProfilesContainer.addPreference(preference);
}
if (Flags.enableBluetoothProfileToggleVisibilityChecker()) {
Set<String> invisibleKeys = mInvisiblePreferenceKey.get();
if (invisibleKeys != null) {
for (int i = 0; i < mProfilesContainer.getPreferenceCount(); ++i) {
Preference pref = mProfilesContainer.getPreference(i);
pref.setVisible(pref.isVisible() && !invisibleKeys.contains(pref.getKey()));
}
}
}
}
@Override