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

Commit 79e98777 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

am: 2194bf52

Change-Id: Ic8dd1a04bf651ef9fa1a969117a7a7c6fcd6089e
parents d170e32f 2194bf52
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -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) {
+4 −4
Original line number Original line Diff line number Diff line
@@ -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);
@@ -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) {
+67 −0
Original line number Original line 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 ===
    // === Test for launcher side APIs ===


    public void testGetShortcuts() {
    public void testGetShortcuts() {