Loading services/core/java/com/android/server/pm/ShortcutPackage.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -1450,6 +1450,16 @@ class ShortcutPackage extends ShortcutPackageItem { Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " is floating, but has rank=" + si.getRank()); + " 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) { if (failed) { Loading services/core/java/com/android/server/pm/ShortcutService.java +4 −4 Original line number Original line Diff line number Diff line Loading @@ -1046,10 +1046,11 @@ public class ShortcutService extends IShortcutService.Stub { new File(shortcut.getBitmapPath()).delete(); new File(shortcut.getBitmapPath()).delete(); shortcut.setBitmapPath(null); shortcut.setBitmapPath(null); } shortcut.setIconResourceId(0); shortcut.setIconResourceId(0); shortcut.setIconResName(null); shortcut.clearFlags(ShortcutInfo.FLAG_HAS_ICON_FILE | ShortcutInfo.FLAG_HAS_ICON_RES); shortcut.clearFlags(ShortcutInfo.FLAG_HAS_ICON_FILE | ShortcutInfo.FLAG_HAS_ICON_RES); } } } public void cleanupBitmapsForPackage(@UserIdInt int userId, String packageName) { public void cleanupBitmapsForPackage(@UserIdInt int userId, String packageName) { final File packagePath = new File(getUserBitmapFilePath(userId), packageName); final File packagePath = new File(getUserBitmapFilePath(userId), packageName); Loading Loading @@ -1165,8 +1166,7 @@ public class ShortcutService extends IShortcutService.Stub { final long token = injectClearCallingIdentity(); final long token = injectClearCallingIdentity(); try { try { // Clear icon info on the shortcut. // Clear icon info on the shortcut. shortcut.setIconResourceId(0); removeIcon(userId, shortcut); shortcut.setBitmapPath(null); final Icon icon = shortcut.getIcon(); final Icon icon = shortcut.getIcon(); if (icon == null) { if (icon == null) { Loading services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java +67 −0 Original line number Original line Diff line number Diff line Loading @@ -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 === // === Test for launcher side APIs === public void testGetShortcuts() { public void testGetShortcuts() { Loading Loading
services/core/java/com/android/server/pm/ShortcutPackage.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -1450,6 +1450,16 @@ class ShortcutPackage extends ShortcutPackageItem { Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " is floating, but has rank=" + si.getRank()); + " 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) { if (failed) { Loading
services/core/java/com/android/server/pm/ShortcutService.java +4 −4 Original line number Original line Diff line number Diff line Loading @@ -1046,10 +1046,11 @@ public class ShortcutService extends IShortcutService.Stub { new File(shortcut.getBitmapPath()).delete(); new File(shortcut.getBitmapPath()).delete(); shortcut.setBitmapPath(null); shortcut.setBitmapPath(null); } shortcut.setIconResourceId(0); shortcut.setIconResourceId(0); shortcut.setIconResName(null); shortcut.clearFlags(ShortcutInfo.FLAG_HAS_ICON_FILE | ShortcutInfo.FLAG_HAS_ICON_RES); shortcut.clearFlags(ShortcutInfo.FLAG_HAS_ICON_FILE | ShortcutInfo.FLAG_HAS_ICON_RES); } } } public void cleanupBitmapsForPackage(@UserIdInt int userId, String packageName) { public void cleanupBitmapsForPackage(@UserIdInt int userId, String packageName) { final File packagePath = new File(getUserBitmapFilePath(userId), packageName); final File packagePath = new File(getUserBitmapFilePath(userId), packageName); Loading Loading @@ -1165,8 +1166,7 @@ public class ShortcutService extends IShortcutService.Stub { final long token = injectClearCallingIdentity(); final long token = injectClearCallingIdentity(); try { try { // Clear icon info on the shortcut. // Clear icon info on the shortcut. shortcut.setIconResourceId(0); removeIcon(userId, shortcut); shortcut.setBitmapPath(null); final Icon icon = shortcut.getIcon(); final Icon icon = shortcut.getIcon(); if (icon == null) { if (icon == null) { Loading
services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java +67 −0 Original line number Original line Diff line number Diff line Loading @@ -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 === // === Test for launcher side APIs === public void testGetShortcuts() { public void testGetShortcuts() { Loading