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

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

Fix issue with apps restored to lower versions. am: fac592f6

am: affadd52

Change-Id: I159f53023179cb67b7225969f4c7220ddd0c03dc
parents ed6824cc affadd52
Loading
Loading
Loading
Loading
+18 −14
Original line number Original line Diff line number Diff line
@@ -106,27 +106,31 @@ abstract class ShortcutPackageItem {
            }
            }
            return; // Not installed, no need to restore yet.
            return; // Not installed, no need to restore yet.
        }
        }
        boolean blockRestore = false;
        if (!mPackageInfo.hasSignatures()) {
        if (!mPackageInfo.hasSignatures()) {
            s.wtf("Attempted to restore package " + mPackageName + ", user=" + mPackageUserId
            s.wtf("Attempted to restore package " + mPackageName + ", user=" + mPackageUserId
                    + " but signatures not found in the restore data.");
                    + " but signatures not found in the restore data.");
            onRestoreBlocked();
            blockRestore = true;
            return;
        }
        }

        if (!blockRestore) {
            final PackageInfo pi = s.getPackageInfoWithSignatures(mPackageName, mPackageUserId);
            final PackageInfo pi = s.getPackageInfoWithSignatures(mPackageName, mPackageUserId);
            if (!mPackageInfo.canRestoreTo(s, pi)) {
            if (!mPackageInfo.canRestoreTo(s, pi)) {
                // Package is now installed, but can't restore.  Let the subclass do the cleanup.
                // Package is now installed, but can't restore.  Let the subclass do the cleanup.
            onRestoreBlocked();
                blockRestore = true;
            return;
            }
            }
        }
        if (blockRestore) {
            onRestoreBlocked();
        } else {
            if (ShortcutService.DEBUG) {
            if (ShortcutService.DEBUG) {
                Slog.d(TAG, String.format("Restored package: %s/%d on user %d", mPackageName,
                Slog.d(TAG, String.format("Restored package: %s/%d on user %d", mPackageName,
                        mPackageUserId, getOwnerUserId()));
                        mPackageUserId, getOwnerUserId()));
            }
            }


            onRestored();
            onRestored();
        }


        // Now the package is not shadow.
        // Either way, it's no longer a shadow.
        mPackageInfo.setShadow(false);
        mPackageInfo.setShadow(false);


        s.scheduleSaveUser(mPackageUserId);
        s.scheduleSaveUser(mPackageUserId);
+10 −0
Original line number Original line Diff line number Diff line
@@ -3733,6 +3733,16 @@ public class ShortcutService extends IShortcutService.Stub {
        }
        }
    }
    }


    @VisibleForTesting
    ShortcutLauncher getLauncherShortcutForTest(String packageName, int userId) {
        synchronized (mLock) {
            final ShortcutUser user = mUsers.get(userId);
            if (user == null) return null;

            return user.getAllLaunchersForTest().get(PackageWithUser.of(userId, packageName));
        }
    }

    /**
    /**
     * Control whether {@link #verifyStates} should be performed.  We always perform it during unit
     * Control whether {@link #verifyStates} should be performed.  We always perform it during unit
     * tests.
     * tests.
+9 −0
Original line number Original line Diff line number Diff line
@@ -4921,6 +4921,9 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
            assertEquals(0, mManager.getDynamicShortcuts().size());
            assertEquals(0, mManager.getDynamicShortcuts().size());
            assertEquals(0, mManager.getPinnedShortcuts().size());
            assertEquals(0, mManager.getPinnedShortcuts().size());
        });
        });
        assertFalse(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, USER_0)
                .getPackageInfo().isShadow());



        installPackage(USER_0, CALLING_PACKAGE_2);
        installPackage(USER_0, CALLING_PACKAGE_2);
        runWithCaller(CALLING_PACKAGE_2, USER_0, () -> {
        runWithCaller(CALLING_PACKAGE_2, USER_0, () -> {
@@ -4929,6 +4932,8 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
                    mManager.getPinnedShortcuts()),
                    mManager.getPinnedShortcuts()),
                    "s1", "s2", "s3");
                    "s1", "s2", "s3");
        });
        });
        assertFalse(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, USER_0)
                .getPackageInfo().isShadow());


        installPackage(USER_0, LAUNCHER_1);
        installPackage(USER_0, LAUNCHER_1);
        runWithCaller(LAUNCHER_1, USER_0, () -> {
        runWithCaller(LAUNCHER_1, USER_0, () -> {
@@ -5052,6 +5057,8 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
                    mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0))
                    mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0))
                    /* empty */);
                    /* empty */);
        });
        });
        assertFalse(mService.getLauncherShortcutForTest(LAUNCHER_1, USER_0)
                .getPackageInfo().isShadow());


        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
            assertEquals(0, mManager.getDynamicShortcuts().size());
            assertEquals(0, mManager.getDynamicShortcuts().size());
@@ -5074,6 +5081,8 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
                    mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0))
                    mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0))
                    /* empty */);
                    /* empty */);
        });
        });
        assertFalse(mService.getLauncherShortcutForTest(LAUNCHER_2, USER_0)
                .getPackageInfo().isShadow());


        installPackage(USER_0, CALLING_PACKAGE_3);
        installPackage(USER_0, CALLING_PACKAGE_3);
        runWithCaller(CALLING_PACKAGE_3, USER_0, () -> {
        runWithCaller(CALLING_PACKAGE_3, USER_0, () -> {