Add mechanism to add accessibility service or activity into bluetooth 'Related' category

Bug: 225117933
Test: make RunSettingsRoboTests ROBOTEST_FILTER=BluetoothDetailsRelatedToolsControllerTest
Change-Id: Iaa3593b4fd9d916fe7f96b3e4bb0965fdbbe36ec
This commit is contained in:
jasonwshsu
2022-03-29 21:43:33 +08:00
parent ee56c24ad8
commit 02b373522a
10 changed files with 199 additions and 21 deletions

View File

@@ -186,7 +186,7 @@ public class BluetoothDetailsCompanionAppsController extends BluetoothDetailsCon
String address, PreferenceCategory container) {
// If the device is FastPair, remove CDM companion apps.
final BluetoothFeatureProvider bluetoothFeatureProvider = FeatureFactory.getFactory(context)
.getBluetoothFeatureProvider(context);
.getBluetoothFeatureProvider();
final boolean sliceEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
SettingsUIDeviceConfig.BT_SLICE_SETTINGS_ENABLED, true);
final Uri settingsUri = bluetoothFeatureProvider.getBluetoothDeviceSettingsUri(

View File

@@ -17,22 +17,40 @@
package com.android.settings.bluetooth;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.accessibilityservice.AccessibilityShortcutInfo;
import android.content.ComponentName;
import android.content.Context;
import android.os.UserHandle;
import android.view.accessibility.AccessibilityManager;
import androidx.annotation.NonNull;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;
import com.android.net.module.util.CollectionUtils;
import com.android.settings.accessibility.RestrictedPreferenceHelper;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* This class adds related tools preference.
*/
public class BluetoothDetailsRelatedToolsController extends BluetoothDetailsController{
private static final String KEY_RELATED_TOOLS_GROUP = "bluetooth_related_tools";
private static final String KEY_LIVE_CAPTION = "live_caption";
private static final int ORDINAL = 99;
private PreferenceCategory mPreferenceCategory;
public BluetoothDetailsRelatedToolsController(Context context,
PreferenceFragmentCompat fragment, CachedBluetoothDevice device, Lifecycle lifecycle) {
@@ -51,14 +69,20 @@ public class BluetoothDetailsRelatedToolsController extends BluetoothDetailsCont
return;
}
final PreferenceCategory preferenceCategory = screen.findPreference(getPreferenceKey());
mPreferenceCategory = screen.findPreference(getPreferenceKey());
final Preference liveCaptionPreference = screen.findPreference(KEY_LIVE_CAPTION);
if (!liveCaptionPreference.isVisible()) {
preferenceCategory.removePreference(liveCaptionPreference);
mPreferenceCategory.removePreference(liveCaptionPreference);
}
if (preferenceCategory.getPreferenceCount() == 0) {
screen.removePreference(preferenceCategory);
final List<ComponentName> relatedToolsList = FeatureFactory.getFactory(
mContext).getBluetoothFeatureProvider().getRelatedTools();
if (!CollectionUtils.isEmpty(relatedToolsList)) {
addAccessibilityInstalledRelatedPreference(relatedToolsList);
}
if (mPreferenceCategory.getPreferenceCount() == 0) {
screen.removePreference(mPreferenceCategory);
}
}
@@ -69,4 +93,32 @@ public class BluetoothDetailsRelatedToolsController extends BluetoothDetailsCont
public String getPreferenceKey() {
return KEY_RELATED_TOOLS_GROUP;
}
private void addAccessibilityInstalledRelatedPreference(
@NonNull List<ComponentName> componentNameList) {
final AccessibilityManager a11yManager = AccessibilityManager.getInstance(mContext);
final RestrictedPreferenceHelper preferenceHelper = new RestrictedPreferenceHelper(
mContext);
final List<AccessibilityServiceInfo> a11yServiceInfoList =
a11yManager.getInstalledAccessibilityServiceList().stream()
.filter(info -> componentNameList.contains(info.getComponentName()))
.collect(Collectors.toList());
final List<AccessibilityShortcutInfo> a11yShortcutInfoList =
a11yManager.getInstalledAccessibilityShortcutListAsUser(mContext,
UserHandle.myUserId()).stream()
.filter(info -> componentNameList.contains(info.getComponentName()))
.collect(Collectors.toList());
final List<RestrictedPreference> preferences = Stream.of(
preferenceHelper.createAccessibilityServicePreferenceList(a11yServiceInfoList),
preferenceHelper.createAccessibilityActivityPreferenceList(a11yShortcutInfoList))
.flatMap(Collection::stream)
.collect(Collectors.toList());
for (RestrictedPreference preference : preferences) {
preference.setOrder(ORDINAL);
mPreferenceCategory.addPreference(preference);
}
}
}

View File

@@ -129,7 +129,7 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
use(LeAudioBluetoothDetailsHeaderController.class).init(mCachedDevice, mManager);
final BluetoothFeatureProvider featureProvider = FeatureFactory.getFactory(
context).getBluetoothFeatureProvider(context);
context).getBluetoothFeatureProvider();
final boolean sliceEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
SettingsUIDeviceConfig.BT_SLICE_SETTINGS_ENABLED, true);
@@ -141,7 +141,7 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
private void updateExtraControlUri(int viewWidth) {
BluetoothFeatureProvider featureProvider = FeatureFactory.getFactory(
getContext()).getBluetoothFeatureProvider(getContext());
getContext()).getBluetoothFeatureProvider();
boolean sliceEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
SettingsUIDeviceConfig.BT_SLICE_SETTINGS_ENABLED, true);
Uri controlUri = null;

View File

@@ -17,15 +17,18 @@
package com.android.settings.bluetooth;
import android.bluetooth.BluetoothDevice;
import android.content.ComponentName;
import android.net.Uri;
import java.util.List;
/**
* Provider for bluetooth related feature
* Provider for bluetooth related features.
*/
public interface BluetoothFeatureProvider {
/**
* Get the {@link Uri} that represents extra settings for a specific bluetooth device
* Gets the {@link Uri} that represents extra settings for a specific bluetooth device
*
* @param bluetoothDevice bluetooth device
* @return {@link Uri} for extra settings
@@ -33,10 +36,18 @@ public interface BluetoothFeatureProvider {
Uri getBluetoothDeviceSettingsUri(BluetoothDevice bluetoothDevice);
/**
* Get the {@link Uri} that represents extra control for a specific bluetooth device
* Gets the {@link Uri} that represents extra control for a specific bluetooth device
*
* @param bluetoothDevice bluetooth device
* @return {@link String} uri string for extra control
*/
String getBluetoothDeviceControlUri(BluetoothDevice bluetoothDevice);
/**
* Gets the {@link ComponentName} of services or activities that need to be shown in related
* tools.
*
* @return list of {@link ComponentName}
*/
List<ComponentName> getRelatedTools();
}

View File

@@ -17,21 +17,20 @@
package com.android.settings.bluetooth;
import android.bluetooth.BluetoothDevice;
import android.content.ComponentName;
import android.content.Context;
import android.net.Uri;
import com.android.settingslib.bluetooth.BluetoothUtils;
import java.util.List;
/**
* Impl of {@link BluetoothFeatureProvider}
*/
public class BluetoothFeatureProviderImpl implements BluetoothFeatureProvider {
private Context mContext;
public BluetoothFeatureProviderImpl(Context context) {
mContext = context;
}
public BluetoothFeatureProviderImpl(Context context) {}
@Override
public Uri getBluetoothDeviceSettingsUri(BluetoothDevice bluetoothDevice) {
@@ -44,4 +43,9 @@ public class BluetoothFeatureProviderImpl implements BluetoothFeatureProvider {
public String getBluetoothDeviceControlUri(BluetoothDevice bluetoothDevice) {
return BluetoothUtils.getControlUriMetaData(bluetoothDevice);
}
@Override
public List<ComponentName> getRelatedTools() {
return null;
}
}