Merge "Fix updateShortcuts() with icons" into nyc-mr1-dev

This commit is contained in:
Makoto Onuki
2016-06-29 23:55:01 +00:00
committed by Android (Google) Code Review
3 changed files with 81 additions and 4 deletions

View File

@@ -1450,6 +1450,16 @@ class ShortcutPackage extends ShortcutPackageItem {
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId()
+ " is floating, but has rank=" + si.getRank());
}
if (si.getIcon() != null) {
failed = true;
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId()
+ " still has an icon");
}
if (si.hasIconFile() && si.hasIconResource()) {
failed = true;
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId()
+ " has both resource and bitmap icons");
}
}
if (failed) {

View File

@@ -1046,9 +1046,10 @@ public class ShortcutService extends IShortcutService.Stub {
new File(shortcut.getBitmapPath()).delete();
shortcut.setBitmapPath(null);
shortcut.setIconResourceId(0);
shortcut.clearFlags(ShortcutInfo.FLAG_HAS_ICON_FILE | ShortcutInfo.FLAG_HAS_ICON_RES);
}
shortcut.setIconResourceId(0);
shortcut.setIconResName(null);
shortcut.clearFlags(ShortcutInfo.FLAG_HAS_ICON_FILE | ShortcutInfo.FLAG_HAS_ICON_RES);
}
public void cleanupBitmapsForPackage(@UserIdInt int userId, String packageName) {
@@ -1165,8 +1166,7 @@ public class ShortcutService extends IShortcutService.Stub {
final long token = injectClearCallingIdentity();
try {
// Clear icon info on the shortcut.
shortcut.setIconResourceId(0);
shortcut.setBitmapPath(null);
removeIcon(userId, shortcut);
final Icon icon = shortcut.getIcon();
if (icon == null) {

View File

@@ -1084,6 +1084,73 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
});
}
public void testUpdateShortcuts_icons() {
runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> {
assertTrue(mManager.setDynamicShortcuts(list(
makeShortcut("s1")
)));
// Set resource icon
assertTrue(mManager.updateShortcuts(list(
new ShortcutInfo.Builder(mClientContext, "s1")
.setIcon(Icon.createWithResource(getTestContext(), R.drawable.black_32x32))
.build()
)));
assertWith(getCallerShortcuts())
.forShortcutWithId("s1", si -> {
assertTrue(si.hasIconResource());
assertEquals(R.drawable.black_32x32, si.getIconResourceId());
});
// Set bitmap icon
assertTrue(mManager.updateShortcuts(list(
new ShortcutInfo.Builder(mClientContext, "s1")
.setIcon(Icon.createWithBitmap(BitmapFactory.decodeResource(
getTestContext().getResources(), R.drawable.black_64x64)))
.build()
)));
assertWith(getCallerShortcuts())
.forShortcutWithId("s1", si -> {
assertTrue(si.hasIconFile());
});
mInjectedCurrentTimeMillis += INTERVAL; // reset throttling
// Do it again, with the reverse order (bitmap -> icon)
assertTrue(mManager.setDynamicShortcuts(list(
makeShortcut("s1")
)));
// Set bitmap icon
assertTrue(mManager.updateShortcuts(list(
new ShortcutInfo.Builder(mClientContext, "s1")
.setIcon(Icon.createWithBitmap(BitmapFactory.decodeResource(
getTestContext().getResources(), R.drawable.black_64x64)))
.build()
)));
assertWith(getCallerShortcuts())
.forShortcutWithId("s1", si -> {
assertTrue(si.hasIconFile());
});
// Set resource icon
assertTrue(mManager.updateShortcuts(list(
new ShortcutInfo.Builder(mClientContext, "s1")
.setIcon(Icon.createWithResource(getTestContext(), R.drawable.black_32x32))
.build()
)));
assertWith(getCallerShortcuts())
.forShortcutWithId("s1", si -> {
assertTrue(si.hasIconResource());
assertEquals(R.drawable.black_32x32, si.getIconResourceId());
});
});
}
// === Test for launcher side APIs ===
public void testGetShortcuts() {