diff options
4 files changed, 36 insertions, 57 deletions
diff --git a/services/core/java/com/android/server/pm/ShortcutPackage.java b/services/core/java/com/android/server/pm/ShortcutPackage.java index 38d69ed287e1..d558b07a7a70 100644 --- a/services/core/java/com/android/server/pm/ShortcutPackage.java +++ b/services/core/java/com/android/server/pm/ShortcutPackage.java @@ -635,11 +635,7 @@ class ShortcutPackage extends ShortcutPackageItem { return false; // Shouldn't happen. } - // Always scan the settings app, since its version code is the same for DR and MR1. - // TODO Fix it properly: b/32554059 - final boolean isSettings = "com.android.settings".equals(getPackageName()); - - if (!isNewApp && !forceRescan && !isSettings) { + if (!isNewApp && !forceRescan) { // Return if the package hasn't changed, ie: // - version code hasn't change // - lastUpdateTime hasn't change @@ -656,11 +652,6 @@ class ShortcutPackage extends ShortcutPackageItem { return false; } } - if (isSettings) { - if (ShortcutService.DEBUG) { - Slog.d(TAG, "Always scan settings."); - } - } } finally { s.logDurationStat(Stats.PACKAGE_UPDATE_CHECK, start); } diff --git a/services/core/java/com/android/server/pm/ShortcutService.java b/services/core/java/com/android/server/pm/ShortcutService.java index 37acf5cc4a0f..26c65498090a 100644 --- a/services/core/java/com/android/server/pm/ShortcutService.java +++ b/services/core/java/com/android/server/pm/ShortcutService.java @@ -2667,8 +2667,7 @@ public class ShortcutService extends IShortcutService.Stub { } } - rescanUpdatedPackagesLocked(ownerUserId, user.getLastAppScanTime(), - /* forceRescan=*/ false); + rescanUpdatedPackagesLocked(ownerUserId, user.getLastAppScanTime()); } } finally { logDurationStat(Stats.CHECK_PACKAGE_CHANGES, start); @@ -2676,8 +2675,7 @@ public class ShortcutService extends IShortcutService.Stub { verifyStates(); } - private void rescanUpdatedPackagesLocked(@UserIdInt int userId, long lastScanTime, - boolean forceRescan) { + private void rescanUpdatedPackagesLocked(@UserIdInt int userId, long lastScanTime) { final ShortcutUser user = getUserShortcutsLocked(userId); // Note after each OTA, we'll need to rescan all system apps, as their lastUpdateTime @@ -2689,7 +2687,8 @@ public class ShortcutService extends IShortcutService.Stub { // Then for each installed app, publish manifest shortcuts when needed. forUpdatedPackages(userId, lastScanTime, afterOta, ai -> { user.attemptToRestoreIfNeededAndSave(this, ai.packageName, userId); - user.rescanPackageIfNeeded(ai.packageName, forceRescan); + + user.rescanPackageIfNeeded(ai.packageName, /* forceRescan= */ true); }); // Write the time just before the scan, because there may be apps that have just @@ -2937,32 +2936,26 @@ public class ShortcutService extends IShortcutService.Stub { private void forUpdatedPackages(@UserIdInt int userId, long lastScanTime, boolean afterOta, Consumer<ApplicationInfo> callback) { if (DEBUG) { - Slog.d(TAG, "forUpdatedPackages for user " + userId + ", lastScanTime=" + lastScanTime); + Slog.d(TAG, "forUpdatedPackages for user " + userId + ", lastScanTime=" + lastScanTime + + " afterOta=" + afterOta); } final List<PackageInfo> list = getInstalledPackages(userId); for (int i = list.size() - 1; i >= 0; i--) { final PackageInfo pi = list.get(i); // If the package has been updated since the last scan time, then scan it. - // Also if it's a system app with no update, lastUpdateTime is not reliable, so - // just scan it. - if (pi.lastUpdateTime >= lastScanTime - || (afterOta && isPureSystemApp(pi.applicationInfo))) { + // Also if it's right after an OTA, always re-scan all apps anyway, since the + // shortcut parser might have changed. + if (afterOta || (pi.lastUpdateTime >= lastScanTime)) { if (DEBUG) { - Slog.d(TAG, "Found updated package " + pi.packageName); + Slog.d(TAG, "Found updated package " + pi.packageName + + " updateTime=" + pi.lastUpdateTime); } callback.accept(pi.applicationInfo); } } } - /** - * @return true if it's a system app with no updates. - */ - private boolean isPureSystemApp(ApplicationInfo ai) { - return ai.isSystemApp() && !ai.isUpdatedSystemApp(); - } - private boolean isApplicationFlagSet(@NonNull String packageName, int userId, int flags) { final ApplicationInfo ai = injectApplicationInfoWithUninstalled(packageName, userId); return (ai != null) && ((ai.flags & flags) == flags); @@ -3213,8 +3206,8 @@ public class ShortcutService extends IShortcutService.Stub { // Rescan all packages to re-publish manifest shortcuts and do other checks. rescanUpdatedPackagesLocked(userId, - 0, // lastScanTime = 0; rescan all packages. - /* forceRescan= */ true); + 0 // lastScanTime = 0; rescan all packages. + ); saveUserLocked(userId); } diff --git a/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java b/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java index 792f3001c049..9f01773eea10 100644 --- a/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java @@ -737,6 +737,10 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase { // Start the service. initService(); setCaller(CALLING_PACKAGE_1); + + if (ENABLE_DUMP) { + Log.d(TAG, "setUp done"); + } } private static boolean b(Boolean value) { diff --git a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java index 3cfdc329a971..771ca1467d61 100644 --- a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java +++ b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java @@ -4181,7 +4181,7 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { assertEquals(START_TIME, findShortcut(shortcuts.getValue(), "s4").getLastChangedTimestamp()); - // Next, send unlock even on user-10. Now we scan packages on this user and send a + // Next, send an unlock event on user-10. Now we scan packages on this user and send a // notification to the launcher. mInjectedCurrentTimeMillis = START_TIME + 200; @@ -4222,9 +4222,8 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { updatePackageVersion(CALLING_PACKAGE_2, 10); // Then send the broadcast, to only user-0. - mService.mPackageMonitor.onReceive(getTestContext(), + mService.mPackageMonitor.onReceive(getTestContext(), genPackageUpdateIntent(CALLING_PACKAGE_2, USER_0)); - mService.checkPackageChanges(USER_10); waitOnMainThread(); @@ -4395,7 +4394,7 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { }); // Next. - // Update the build finger print. All system apps will be scanned now. + // Update the build finger print. All apps will be scanned now. mInjectedBuildFingerprint = "update1"; mInjectedCurrentTimeMillis += 1000; mService.checkPackageChanges(USER_0); @@ -4406,12 +4405,11 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { }); runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { assertWith(getCallerShortcuts()) - .isEmpty(); + .haveIds("ms1"); }); // Next. // Update manifest shortcuts. - mInjectedBuildFingerprint = "update2"; addManifestShortcutResource( new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), R.xml.shortcut_2); @@ -4421,35 +4419,20 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { mInjectedCurrentTimeMillis += 1000; mService.checkPackageChanges(USER_0); - // Fingerprint hasn't changed, so CALLING_PACKAGE_1 wasn't scanned. + // Fingerprint hasn't changed, so there packages weren't scanned. runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { assertWith(getCallerShortcuts()) .haveIds("ms1"); }); runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { assertWith(getCallerShortcuts()) - .isEmpty(); - }); - - // Update the fingerprint, but CALLING_PACKAGE_1's version code hasn't changed, so - // still not scanned. - mInjectedBuildFingerprint = "update2"; - mInjectedCurrentTimeMillis += 1000; - mService.checkPackageChanges(USER_0); - - runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { - assertWith(getCallerShortcuts()) .haveIds("ms1"); }); - runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { - assertWith(getCallerShortcuts()) - .isEmpty(); - }); - // Now update the version code, so CALLING_PACKAGE_1 is scanned again. - mInjectedBuildFingerprint = "update3"; + // Update the fingerprint. CALLING_PACKAGE_1's version code hasn't changed, but we scan + // all apps anyway. + mInjectedBuildFingerprint = "update2"; mInjectedCurrentTimeMillis += 1000; - updatePackageVersion(CALLING_PACKAGE_1, 1); mService.checkPackageChanges(USER_0); runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { @@ -4458,7 +4441,7 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { }); runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { assertWith(getCallerShortcuts()) - .isEmpty(); + .haveIds("ms1", "ms2"); }); // Make sure getLastAppScanTime / getLastAppScanOsFingerprint are persisted. @@ -5721,6 +5704,7 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { R.xml.shortcut_5); // Unlock user-0. + mInjectedCurrentTimeMillis += 100; mService.handleUnlockUser(USER_0); runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { @@ -5750,6 +5734,7 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { uninstallPackage(USER_10, CALLING_PACKAGE_1); uninstallPackage(USER_10, CALLING_PACKAGE_3); + mInjectedCurrentTimeMillis += 100; mService.handleUnlockUser(USER_10); runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { @@ -5774,6 +5759,8 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { // hasn't changed. shutdownServices(); + mInjectedCurrentTimeMillis += 100; + addManifestShortcutResource( new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), R.xml.shortcut_5); @@ -5785,7 +5772,7 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { mService.handleUnlockUser(USER_0); runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { - assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( + assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( // FAIL mManager.getManifestShortcuts()))), "ms1"); assertEmpty(mManager.getPinnedShortcuts()); @@ -5808,6 +5795,8 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { // Do it again, but this time we change the app version, so we do detect the changes. shutdownServices(); + mInjectedCurrentTimeMillis += 100; + updatePackageVersion(CALLING_PACKAGE_1, 1); updatePackageLastUpdateTime(CALLING_PACKAGE_3, 1); @@ -5870,6 +5859,8 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { shutdownServices(); + mInjectedCurrentTimeMillis += 100; + addManifestShortcutResource( new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), R.xml.shortcut_0); |