Merge "Load icon from correct package for Accessibility slices" into main

This commit is contained in:
Chun-Ku Lin
2024-09-13 00:21:35 +00:00
committed by Android (Google) Code Review
2 changed files with 20 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_KEY;
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.R;
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 @@ public class SliceBuilderUtils {
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);

View File

@@ -274,6 +274,12 @@ class SliceDataConverter {
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 @@ class SliceDataConverter {
}
sliceDataBuilder.setKey(flattenedName)
// LINT.ThenChange(SliceBuilderUtils.java:createA11yIcon)
.setTitle(title)
.setUri(new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)