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

Commit c031a0fa 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: I56be73b7e7934da51336d147b6ad6ae66c98ac32
parents 69ba6656 52e94871
Loading
Loading
Loading
Loading
+23 −0
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.content.pm.ShortcutManager;
import android.content.res.Resources;
import android.content.res.Resources;
import android.graphics.drawable.Icon;
import android.os.PersistableBundle;
import android.os.PersistableBundle;
import android.text.format.Formatter;
import android.text.format.Formatter;
import android.util.ArrayMap;
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.
     * Delete a shortcut by ID. This will *always* remove it even if it's immutable or invisible.
     */
     */
+3 −0
Original line number Original line Diff line number Diff line
@@ -1849,6 +1849,7 @@ public class ShortcutService extends IShortcutService.Stub {
            final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId);
            final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId);


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


            fillInDefaultActivity(newShortcuts);
            fillInDefaultActivity(newShortcuts);


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


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


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


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


            fillInDefaultActivity(newShortcuts);
            fillInDefaultActivity(newShortcuts);