Add bluetooth profile toggle visibility checker
Bug: 321178209 Test: atest BluetoothDetailsProfilesControllerTest Change-Id: Ic6c040a5a500d51945893061623526271eba94c7
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -27,6 +27,7 @@ import androidx.preference.Preference;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Provider for bluetooth related features.
|
||||
@@ -73,4 +74,14 @@ public interface BluetoothFeatureProvider {
|
||||
* @return the extra bluetooth preference list
|
||||
*/
|
||||
List<Preference> getBluetoothExtraOptions(Context context, CachedBluetoothDevice device);
|
||||
|
||||
/**
|
||||
* Gets the bluetooth profile preference keys which should be hidden in the device details page.
|
||||
*
|
||||
* @param context Context
|
||||
* @param bluetoothDevice the bluetooth device
|
||||
* @return the profiles which should be hidden
|
||||
*/
|
||||
Set<String> getInvisibleProfilePreferenceKeys(
|
||||
Context context, BluetoothDevice bluetoothDevice);
|
||||
}
|
||||
|
||||
@@ -29,8 +29,10 @@ import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Impl of {@link BluetoothFeatureProvider}
|
||||
@@ -65,4 +67,10 @@ public class BluetoothFeatureProviderImpl implements BluetoothFeatureProvider {
|
||||
CachedBluetoothDevice device) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getInvisibleProfilePreferenceKeys(
|
||||
Context context, BluetoothDevice bluetoothDevice) {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user