Merge "Provide installed a11y services/activities from dynamicRawData for search" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
428829bfc5
@@ -26,6 +26,7 @@ import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -101,6 +102,11 @@ public class AccessibilityActivityPreference extends RestrictedPreference {
|
||||
return mLabel;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ComponentName getComponentName() {
|
||||
return mComponentName;
|
||||
}
|
||||
|
||||
private Drawable getA11yActivityIcon() {
|
||||
ActivityInfo activityInfo = mA11yShortcutInfo.getActivityInfo();
|
||||
Drawable serviceIcon;
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
|
||||
import java.util.List;
|
||||
@@ -28,10 +32,22 @@ import java.util.List;
|
||||
public interface AccessibilitySearchFeatureProvider {
|
||||
|
||||
/**
|
||||
* Returns a list of raw data for indexing. See {@link SearchIndexableRaw}
|
||||
* Returns accessibility features to be searched where the accessibility features are always on
|
||||
* the device and their feature names won't change.
|
||||
*
|
||||
* @param context a valid context {@link Context} instance
|
||||
* @return a list of {@link SearchIndexableRaw} references. Can be null.
|
||||
* @return a list of {@link SearchIndexableRaw} references
|
||||
*/
|
||||
@Nullable
|
||||
List<SearchIndexableRaw> getSearchIndexableRawData(Context context);
|
||||
|
||||
/**
|
||||
* Returns synonyms of the Accessibility component that is used for search.
|
||||
*
|
||||
* @param context the context that is used for grabbing resources
|
||||
* @param componentName the ComponentName of the accessibility feature
|
||||
* @return a comma separated synonyms e.g. "wifi, wi-fi, network connection"
|
||||
*/
|
||||
@NonNull
|
||||
String getSynonymsForComponent(@NonNull Context context, @NonNull ComponentName componentName);
|
||||
}
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
|
||||
import java.util.List;
|
||||
@@ -27,8 +31,16 @@ import java.util.List;
|
||||
*/
|
||||
public class AccessibilitySearchFeatureProviderImpl implements AccessibilitySearchFeatureProvider {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<SearchIndexableRaw> getSearchIndexableRawData(Context context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getSynonymsForComponent(@NonNull Context context,
|
||||
@NonNull ComponentName componentName) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -95,6 +96,11 @@ public class AccessibilityServicePreference extends RestrictedPreference {
|
||||
super.performClick();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ComponentName getComponentName() {
|
||||
return mComponentName;
|
||||
}
|
||||
|
||||
private Drawable getA11yServiceIcon() {
|
||||
ResolveInfo resolveInfo = mA11yServiceInfo.getResolveInfo();
|
||||
Drawable serviceIcon;
|
||||
|
||||
@@ -473,7 +473,7 @@ public class AccessibilitySettings extends DashboardFragment implements
|
||||
* @param installedShortcutList A list of installed {@link AccessibilityShortcutInfo}s.
|
||||
* @param installedServiceList A list of installed {@link AccessibilityServiceInfo}s.
|
||||
*/
|
||||
private List<RestrictedPreference> getInstalledAccessibilityPreferences(Context context,
|
||||
private static List<RestrictedPreference> getInstalledAccessibilityPreferences(Context context,
|
||||
List<AccessibilityShortcutInfo> installedShortcutList,
|
||||
List<AccessibilityServiceInfo> installedServiceList) {
|
||||
final RestrictedPreferenceHelper preferenceHelper = new RestrictedPreferenceHelper(context);
|
||||
@@ -623,6 +623,51 @@ public class AccessibilitySettings extends DashboardFragment implements
|
||||
.getAccessibilitySearchFeatureProvider().getSearchIndexableRawData(
|
||||
context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableRaw> getDynamicRawDataToIndex(Context context,
|
||||
boolean enabled) {
|
||||
List<SearchIndexableRaw> dynamicRawData = super.getDynamicRawDataToIndex(
|
||||
context, enabled);
|
||||
if (dynamicRawData == null) {
|
||||
dynamicRawData = new ArrayList<>();
|
||||
}
|
||||
if (!Flags.fixA11ySettingsSearch()) {
|
||||
return dynamicRawData;
|
||||
}
|
||||
|
||||
AccessibilityManager a11yManager = context.getSystemService(
|
||||
AccessibilityManager.class);
|
||||
AccessibilitySearchFeatureProvider a11ySearchFeatureProvider =
|
||||
FeatureFactory.getFeatureFactory()
|
||||
.getAccessibilitySearchFeatureProvider();
|
||||
List<RestrictedPreference> installedA11yFeaturesPref =
|
||||
AccessibilitySettings.getInstalledAccessibilityPreferences(
|
||||
context,
|
||||
a11yManager.getInstalledAccessibilityShortcutListAsUser(
|
||||
context, UserHandle.myUserId()),
|
||||
a11yManager.getInstalledAccessibilityServiceList()
|
||||
);
|
||||
for (RestrictedPreference pref : installedA11yFeaturesPref) {
|
||||
SearchIndexableRaw indexableRaw = new SearchIndexableRaw(context);
|
||||
indexableRaw.key = pref.getKey();
|
||||
indexableRaw.title = pref.getTitle().toString();
|
||||
@NonNull String synonyms = "";
|
||||
if (pref instanceof AccessibilityServicePreference) {
|
||||
synonyms = a11ySearchFeatureProvider.getSynonymsForComponent(
|
||||
context,
|
||||
((AccessibilityServicePreference) pref).getComponentName());
|
||||
} else if (pref instanceof AccessibilityActivityPreference) {
|
||||
synonyms = a11ySearchFeatureProvider.getSynonymsForComponent(
|
||||
context,
|
||||
((AccessibilityActivityPreference) pref).getComponentName());
|
||||
}
|
||||
indexableRaw.keywords = synonyms;
|
||||
dynamicRawData.add(indexableRaw);
|
||||
}
|
||||
|
||||
return dynamicRawData;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user