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

Commit 2dfc2b23 authored by chihhangchuang's avatar chihhangchuang
Browse files

Ensure the shape app icon and name is a correct pair

Issue screenshot: https://screenshot.googleplex.com/z0L588aXvqa.png
The google icon is unavailable(not in the icon list), but it's name still be available(in the app name list)

Solution: Check app icon and name are available, then added them to the list.

Test: Manually
Fixes: 157535141
Change-Id: Ia7ad0322cdf888a885f7383180dc23e2d6d9a3cb
parent f178e88a
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -214,15 +214,21 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
        List<Drawable> icons = new ArrayList<>();
        List<String> names = new ArrayList<>();
        for (String packageName : mOverlayProvider.getShapePreviewIconPackages()) {
            Drawable icon = null;
            String name = null;
            try {
                icons.add(mContext.getPackageManager().getApplicationIcon(packageName));
                icon = mContext.getPackageManager().getApplicationIcon(packageName);
                ApplicationInfo appInfo = mContext.getPackageManager()
                        .getApplicationInfo(packageName, /* flag= */ 0);
                names.add(String.valueOf(
                        mContext.getPackageManager().getApplicationLabel(appInfo)));
                name = String.valueOf(mContext.getPackageManager().getApplicationLabel(appInfo));
            } catch (NameNotFoundException e) {
                Log.d(TAG, "Couldn't find app " + packageName + ", won't use it for icon shape"
                        + "preview");
            } finally {
                if (icon != null && !TextUtils.isEmpty(name)) {
                    icons.add(icon);
                    names.add(name);
                }
            }
        }
        builder.setShapePreviewIcons(icons);
+9 −3
Original line number Diff line number Diff line
@@ -103,16 +103,22 @@ class OverlayThemeExtractor {
        List<Drawable> icons = new ArrayList<>();
        List<String> names = new ArrayList<>();
        for (String packageName : mShapePreviewIconPackages) {
            Drawable icon = null;
            String name = null;
            try {
                icons.add(mContext.getPackageManager().getApplicationIcon(packageName));
                icon = mContext.getPackageManager().getApplicationIcon(packageName);
                // Add the shape icon app name.
                ApplicationInfo appInfo = mContext.getPackageManager()
                        .getApplicationInfo(packageName, /* flag= */ 0);
                names.add(String.valueOf(
                        mContext.getPackageManager().getApplicationLabel(appInfo)));
                name = String.valueOf(mContext.getPackageManager().getApplicationLabel(appInfo));
            } catch (NameNotFoundException e) {
                Log.d(TAG, "Couldn't find app " + packageName
                        + ", won't use it for icon shape preview");
            } finally {
                if (icon != null && !TextUtils.isEmpty(name)) {
                    icons.add(icon);
                    names.add(name);
                }
            }
        }
        builder.setShapePreviewIcons(icons);
+11 −4
Original line number Diff line number Diff line
@@ -112,21 +112,28 @@ public class ShapeOptionsProvider extends ThemeComponentOptionProvider<ShapeOpti
        List<Drawable> icons = new ArrayList<>();
        List<String> names = new ArrayList<>();
        for (String packageName : mShapePreviewIconPackages) {
            Drawable icon = null;
            String name = null;
            try {
                Drawable appIcon = mContext.getPackageManager().getApplicationIcon(packageName);
                if (appIcon instanceof AdaptiveIconDrawable) {
                    AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) appIcon;
                    icons.add(new DynamicAdaptiveIconDrawable(adaptiveIcon.getBackground(),
                            adaptiveIcon.getForeground(), path));
                    icon = new DynamicAdaptiveIconDrawable(adaptiveIcon.getBackground(),
                            adaptiveIcon.getForeground(), path);

                    ApplicationInfo appInfo = mContext.getPackageManager()
                            .getApplicationInfo(packageName, /* flag= */ 0);
                    names.add(String.valueOf(
                            mContext.getPackageManager().getApplicationLabel(appInfo)));
                    name = String.valueOf(
                            mContext.getPackageManager().getApplicationLabel(appInfo));
                }
            } catch (NameNotFoundException e) {
                Log.d(TAG, "Couldn't find app " + packageName
                        + ", won't use it for icon shape preview");
            } finally {
                if (icon != null && !TextUtils.isEmpty(name)) {
                    icons.add(icon);
                    names.add(name);
                }
            }
        }
        return Pair.create(icons, names);