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

Commit 8bbecf46 authored by Chun-Ku Lin's avatar Chun-Ku Lin
Browse files

Load icon from correct package for Accessibility slices

Bug: 326233533
Flag: EXEMPT low risk
Test: Mannual. Search TalkBack in Settings app, the Icon shows up
correctly. Search "Turn on TalkBack" in assistant app, the Icon is not
affected.

Change-Id: I6c15a13b4e7dd56f873124ae5722f15f2447f5b4
parent 06ab83eb
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -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 {
            // 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);
+7 −0
Original line number Diff line number Diff line
@@ -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)