Merge "Make bluetooth profile toggles configurable" into main

This commit is contained in:
Haijie Hong
2024-09-09 12:56:07 +00:00
committed by Android (Google) Code Review
7 changed files with 115 additions and 32 deletions

View File

@@ -26,6 +26,7 @@ import android.sysprop.BluetoothProperties;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
@@ -52,7 +53,9 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -81,7 +84,9 @@ 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 Set<String> mInvisibleProfiles = Collections.emptySet();
private final AtomicReference<Set<String>> mAdditionalInvisibleProfiles =
new AtomicReference<>();
private LocalBluetoothManager mManager;
private LocalBluetoothProfileManager mProfileManager;
@@ -95,13 +100,21 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
@VisibleForTesting
PreferenceCategory mProfilesContainer;
public BluetoothDetailsProfilesController(Context context, PreferenceFragmentCompat fragment,
LocalBluetoothManager manager, CachedBluetoothDevice device, Lifecycle lifecycle) {
public BluetoothDetailsProfilesController(
Context context,
PreferenceFragmentCompat fragment,
LocalBluetoothManager manager,
CachedBluetoothDevice device,
Lifecycle lifecycle,
@Nullable List<String> invisibleProfiles) {
super(context, fragment, device, lifecycle);
mManager = manager;
mProfileManager = mManager.getProfileManager();
mCachedDevice = device;
mCachedDeviceGroup = Utils.findAllCachedBluetoothDevicesByGroupId(mManager, mCachedDevice);
if (invisibleProfiles != null) {
mInvisibleProfiles = Set.copyOf(invisibleProfiles);
}
}
@Override
@@ -563,7 +576,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
protected void refresh() {
ThreadUtils.postOnBackgroundThread(
() -> {
mInvisiblePreferenceKey.set(
mAdditionalInvisibleProfiles.set(
FeatureFactory.getFeatureFactory()
.getBluetoothFeatureProvider()
.getInvisibleProfilePreferenceKeys(
@@ -604,12 +617,15 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
mProfilesContainer.addPreference(preference);
}
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()));
}
Set<String> additionalInvisibleProfiles = mAdditionalInvisibleProfiles.get();
HashSet<String> combinedInvisibleProfiles = new HashSet<>(mInvisibleProfiles);
if (additionalInvisibleProfiles != null) {
combinedInvisibleProfiles.addAll(additionalInvisibleProfiles);
}
Log.i(TAG, "Invisible profiles: " + combinedInvisibleProfiles);
for (int i = 0; i < mProfilesContainer.getPreferenceCount(); ++i) {
Preference pref = mProfilesContainer.getPreference(i);
pref.setVisible(pref.isVisible() && !combinedInvisibleProfiles.contains(pref.getKey()));
}
}