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

Commit 2194bf52 authored by Makoto Onuki's avatar Makoto Onuki Committed by android-build-merger
Browse files

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

am: bc8e0052

Change-Id: I009387abcbb24e3051611eee708fedd86f1b9dcd
parents 4bed53a0 bc8e0052
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -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) {
+4 −4
Original line number Diff line number Diff line
@@ -1046,10 +1046,11 @@ public class ShortcutService extends IShortcutService.Stub {
            new File(shortcut.getBitmapPath()).delete();

            shortcut.setBitmapPath(null);
        }
        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) {
        final File packagePath = new File(getUserBitmapFilePath(userId), 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) {
+67 −0
Original line number Diff line number Diff line
@@ -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() {