Skip to content

Commit

Permalink
base: fix pm cache directory invalidate on new builds
Browse files Browse the repository at this point in the history
This was before in PackageManagerService.jave like
 final String cacheName = FORCE_PACKAGE_PARSED_CACHE_ENABLED ? "debug"
                : SystemProperties.digestOf(ro.build.date.utc);

Now they switched to PackagePartitions.FINGERPRINT which broke
the invalidate of the cache for new builds

also add a missed usage of changed fingerprint in StorageEventHelper.java

Change-Id: I6cca07659a8e7a4f99ed58761dc727e0e5e20ef8
  • Loading branch information
maxwen authored and eldainosor committed Mar 17, 2023
1 parent 52c2116 commit f8842ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ public static void enforceSystemOrRoot(String message) {
// identify cached items. In particular, changing the value of certain
// feature flags should cause us to invalidate any caches.
final String cacheName = FORCE_PACKAGE_PARSED_CACHE_ENABLED ? "debug"
: PackagePartitions.FINGERPRINT;
: SystemProperties.digestOf(String.valueOf(Build.TIME));

// Reconcile cache directories, keeping only what we'd actually use.
for (File cacheDir : FileUtils.listFilesOrEmpty(cacheBaseDir)) {
Expand Down Expand Up @@ -1350,16 +1350,15 @@ public static void enforceSystemOrRoot(String message) {
// NOTE: When no BUILD_NUMBER is set by the build system, it defaults to a build
// that starts with "eng." to signify that this is an engineering build and not
// destined for release.
if (isUpgrade || incrementalVersion.startsWith("eng.")) {
Slog.w(TAG, "Wiping cache directory because the system partition changed.");

if (isUserDebugBuild && incrementalVersion.startsWith("eng.")) {
// Heuristic: If the /system directory has been modified recently due to an "adb sync"
// or a regular make, then blow away the cache. Note that mtimes are *NOT* reliable
// in general and should not be used for production changes. In this specific case,
// we know that they will work.
File frameworkDir =
new File(Environment.getRootDirectory(), "framework");
if (cacheDir.lastModified() < frameworkDir.lastModified()) {
Slog.w(TAG, "Wiping cache directory because the system partition changed.");
FileUtils.deleteContents(cacheBaseDir);
cacheDir = FileUtils.createDir(cacheBaseDir, cacheName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import android.content.pm.PackagePartitions;
import android.content.pm.UserInfo;
import android.content.pm.VersionedPackage;
import android.os.Build;
import android.os.Environment;
import android.os.FileUtils;
import android.os.UserHandle;
Expand Down Expand Up @@ -166,7 +167,7 @@ private void loadPrivatePackagesInner(VolumeInfo vol) {
Slog.w(TAG, "Failed to scan " + ps.getPath() + ": " + e.getMessage());
}

if (!PackagePartitions.FINGERPRINT.equals(ver.fingerprint)) {
if (!String.valueOf(Build.TIME).equals(ver.fingerprint)) {
appDataHelper.clearAppDataLIF(
ps.getPkg(), UserHandle.USER_ALL, FLAG_STORAGE_DE | FLAG_STORAGE_CE
| FLAG_STORAGE_EXTERNAL | Installer.FLAG_CLEAR_CODE_CACHE_ONLY
Expand Down Expand Up @@ -204,10 +205,10 @@ private void loadPrivatePackagesInner(VolumeInfo vol) {
}

synchronized (mPm.mLock) {
final boolean isUpgrade = !PackagePartitions.FINGERPRINT.equals(ver.fingerprint);
final boolean isUpgrade = !String.valueOf(Build.TIME).equals(ver.fingerprint);
if (isUpgrade) {
logCriticalInfo(Log.INFO, "Build fingerprint changed from " + ver.fingerprint
+ " to " + PackagePartitions.FINGERPRINT + "; regranting permissions for "
+ " to " + String.valueOf(Build.TIME) + "; regranting permissions for "
+ volumeUuid);
}
mPm.mPermissionManager.onStorageVolumeMounted(volumeUuid, isUpgrade);
Expand Down

0 comments on commit f8842ae

Please sign in to comment.