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

Commit b203cb49 authored by Mehdi Alizadeh's avatar Mehdi Alizadeh Committed by Automerger Merge Worker
Browse files

Merge "Logs error when bitmap icon is used in long-lived shortcuts" into rvc-dev am: 52e94871

Change-Id: I303d252e8b5cfca091b9699d8f422c9fc2c158a0
parents 3a598b69 52e94871
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.content.res.Resources;
import android.graphics.drawable.Icon;
import android.os.PersistableBundle;
import android.text.format.Formatter;
import android.util.ArrayMap;
@@ -256,6 +257,28 @@ class ShortcutPackage extends ShortcutPackageItem {
        }
    }

    public void ensureNoBitmapIconIfShortcutIsLongLived(@NonNull List<ShortcutInfo> shortcuts) {
        for (int i = shortcuts.size() - 1; i >= 0; i--) {
            final ShortcutInfo si = shortcuts.get(i);
            if (!si.isLongLived()) {
                continue;
            }
            final Icon icon = si.getIcon();
            if (icon != null && icon.getType() != Icon.TYPE_BITMAP
                    && icon.getType() == Icon.TYPE_ADAPTIVE_BITMAP) {
                continue;
            }
            if (icon == null && !si.hasIconFile()) {
                continue;
            }

            // TODO: Throw IllegalArgumentException instead.
            Slog.e(TAG, "Invalid icon type in shortcut " + si.getId() + ". Bitmaps are not allowed"
                    + " in long-lived shortcuts. Use Resource icons, or Uri-based icons instead.");
            return;  // Do not spam and return early.
        }
    }

    /**
     * Delete a shortcut by ID. This will *always* remove it even if it's immutable or invisible.
     */
+3 −0
Original line number Diff line number Diff line
@@ -1849,6 +1849,7 @@ public class ShortcutService extends IShortcutService.Stub {
            final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId);

            ps.ensureImmutableShortcutsNotIncluded(newShortcuts, /*ignoreInvisible=*/ true);
            ps.ensureNoBitmapIconIfShortcutIsLongLived(newShortcuts);

            fillInDefaultActivity(newShortcuts);

@@ -1915,6 +1916,7 @@ public class ShortcutService extends IShortcutService.Stub {
            final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId);

            ps.ensureImmutableShortcutsNotIncluded(newShortcuts, /*ignoreInvisible=*/ true);
            ps.ensureNoBitmapIconIfShortcutIsLongLived(newShortcuts);

            // For update, don't fill in the default activity.  Having null activity means
            // "don't update the activity" here.
@@ -2013,6 +2015,7 @@ public class ShortcutService extends IShortcutService.Stub {
            final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId);

            ps.ensureImmutableShortcutsNotIncluded(newShortcuts, /*ignoreInvisible=*/ true);
            ps.ensureNoBitmapIconIfShortcutIsLongLived(newShortcuts);

            fillInDefaultActivity(newShortcuts);