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

Commit 82c14a0d authored by Jiaquan Si's avatar Jiaquan Si Committed by Patrick Baumann
Browse files

Set threshold of historical sessions size in PackageInstallerService



In extreme cases, size of historical sessions recorded in PackageInstallerService
is very large, resulting in huge memory usage in system server.
This commit adds threshold of historical sessions size and the oldest historical
sessions will be cleared if the list size reaches the threshold.

Bug: 248960979
Fixed: 248960979
Test: presubmit

Signed-off-by: default avatarJiaquan Si <sijiaquan@oppo.corp-partner.google.com>
Change-Id: Ie0af8f00e73a59bdacc4b9a6f5bea0a2a3f9258b
parent 98652d25
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -154,6 +154,11 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
    /** Destroy sessions older than this on storage free request */
    private static final long MAX_SESSION_AGE_ON_LOW_STORAGE_MILLIS = 8 * DateUtils.HOUR_IN_MILLIS;

    /** Threshold of historical sessions size */
    private static final int HISTORICAL_SESSIONS_THRESHOLD = 500;
    /** Size of historical sessions to be cleared when reaching threshold */
    private static final int HISTORICAL_CLEAR_SIZE = 400;

    /**
     * Allow verification-skipping if it's a development app installed through ADB with
     * disable verification flag specified.
@@ -549,6 +554,10 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
        CharArrayWriter writer = new CharArrayWriter();
        IndentingPrintWriter pw = new IndentingPrintWriter(writer, "    ");
        session.dump(pw);
        if (mHistoricalSessions.size() > HISTORICAL_SESSIONS_THRESHOLD) {
            Slog.d(TAG, "Historical sessions size reaches threshold, clear the oldest");
            mHistoricalSessions.subList(0, HISTORICAL_CLEAR_SIZE).clear();
        }
        mHistoricalSessions.add(writer.toString());

        int installerUid = session.getInstallerUid();