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

Change-Id: I303d252e8b5cfca091b9699d8f422c9fc2c158a0
This commit is contained in:
Mehdi Alizadeh
2020-05-20 22:05:19 +00:00
committed by Automerger Merge Worker
2 changed files with 26 additions and 0 deletions

View File

@@ -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.
*/

View File

@@ -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);