Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cf507b60 authored by jasonwshsu's avatar jasonwshsu Committed by Automerger Merge Worker
Browse files

Add mechanism to add accessibility service or activity into bluetooth...

Add mechanism to add accessibility service or activity into bluetooth 'Related' category am: 02b37352

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/17472403



Change-Id: Ib7ee39c79cbd738b169dd49469badfacaa1daa64
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents aecbda38 02b37352
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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(
+56 −4
Original line number Diff line number Diff line
@@ -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);
        }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -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;
+14 −3
Original line number Diff line number Diff line
@@ -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();
}
+9 −5
Original line number Diff line number Diff line
@@ -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;
    }
}
Loading