Merge "Load icon from correct package for Accessibility slices" into main
diff --git a/src/com/android/settings/slices/SliceBuilderUtils.java b/src/com/android/settings/slices/SliceBuilderUtils.java
index c9d5f23..f99267e 100644
--- a/src/com/android/settings/slices/SliceBuilderUtils.java
+++ b/src/com/android/settings/slices/SliceBuilderUtils.java
@@ -24,6 +24,7 @@
import android.annotation.ColorInt;
import android.app.PendingIntent;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
@@ -47,6 +48,7 @@
import com.android.settings.SettingsActivity;
import com.android.settings.SubSettings;
import com.android.settings.Utils;
+import com.android.settings.accessibility.AccessibilitySlicePreferenceController;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.SliderPreferenceController;
import com.android.settings.core.SubSettingLauncher;
@@ -448,7 +450,17 @@
iconResource = R.drawable.ic_settings_accent;
}
try {
- return IconCompat.createWithResource(context, iconResource);
+ // LINT.IfChange(createA11yIcon)
+ if (AccessibilitySlicePreferenceController.class.getName().equals(
+ data.getPreferenceController())) {
+ ComponentName serviceComponent = ComponentName.unflattenFromString(data.getKey());
+ return IconCompat.createWithResource(
+ context.createPackageContext(serviceComponent.getPackageName(), 0),
+ iconResource);
+ // LINT.ThenChange()
+ } else {
+ return IconCompat.createWithResource(context, iconResource);
+ }
} catch (Exception e) {
Log.w(TAG, "Falling back to settings icon because there is an error getting slice icon "
+ data.getUri(), e);
diff --git a/src/com/android/settings/slices/SliceDataConverter.java b/src/com/android/settings/slices/SliceDataConverter.java
index f6828af3..983edc0 100644
--- a/src/com/android/settings/slices/SliceDataConverter.java
+++ b/src/com/android/settings/slices/SliceDataConverter.java
@@ -274,6 +274,12 @@
final ServiceInfo serviceInfo = resolveInfo.serviceInfo;
final String packageName = serviceInfo.packageName;
final ComponentName componentName = new ComponentName(packageName, serviceInfo.name);
+
+ // If we change the flattenedName that is used to be set as a key of the Slice, we
+ // need to make corresponding change in SliceBuilderUtils, since we rely on the
+ // the A11y Service Slice's key to be a ComponentName to get the correct package name
+ // to grab the icon belongs to that package.
+ // LINT.IfChange
final String flattenedName = componentName.flattenToString();
if (!a11yServiceNames.contains(flattenedName)) {
@@ -287,6 +293,7 @@
}
sliceDataBuilder.setKey(flattenedName)
+ // LINT.ThenChange(SliceBuilderUtils.java:createA11yIcon)
.setTitle(title)
.setUri(new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)