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

Commit dd01ec61 authored by Jackal Guo's avatar Jackal Guo
Browse files

Remove orphaned cached result

PackageManagerService would parse all installed APKs info and cache
them, but only delete them when system update. As long as the APKs
keep updating without having system update, the older cached result
would eventually occupy more and more user space.

One way to mitigate this is removing the cached result when the APK
is updated or uninstalled.

Bug: 120608320
Test: Update/uninstall an APK, and check its cached result
Change-Id: I977a0923703bda6f145c9d240a1408f6f87c5625
parent 0f54ce6b
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -10330,6 +10330,7 @@ public class PackageManagerService extends IPackageManager.Stub
                mInstaller.rmPackageDir(codePath.getAbsolutePath());
                if (codePathParent.getName().startsWith(RANDOM_DIR_PREFIX)) {
                    mInstaller.rmPackageDir(codePathParent.getAbsolutePath());
                    removeCachedResult(codePathParent);
                }
            } catch (InstallerException e) {
                Slog.w(TAG, "Failed to remove code path", e);
@@ -10339,6 +10340,16 @@ public class PackageManagerService extends IPackageManager.Stub
        }
    }
    private void removeCachedResult(@NonNull File codePath) {
        if (mCacheDir == null) {
            return;
        }
        final PackageCacher cacher = new PackageCacher(mCacheDir);
        // Find and delete the cached result belong to the given codePath.
        cacher.cleanCachedResult(codePath);
    }
    private int[] resolveUserIds(int userId) {
        return (userId == UserHandle.USER_ALL) ? mUserManager.getUserIds() : new int[] { userId };
    }