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

Commit e8317ba8 authored by Li Li's avatar Li Li
Browse files

Exempt apps with INSTALL_PACKAGES from freezer



System applications with INSTALL_PACKAGES permission, like store
apps, have long-running processes in order to keep the system stable
and secure. Don't freeze them even if they are cached.

Bug: 184584402
Test: Verified store apps with the permission won't be frozen.

Change-Id: I4ae45a3688ac6d50c0e7d6ef11ce506b283ee82f
Merged-In: I4ae45a3688ac6d50c0e7d6ef11ce506b283ee82f
Signed-off-by: default avatarLi Li <dualli@google.com>
(cherry picked from commit 3527866d)
parent d7d47480
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -3035,6 +3035,10 @@ public final class OomAdjuster {
            return;
        }

        if (app.mOptRecord.isFreezeExempt()) {
            return;
        }

        final ProcessCachedOptimizerRecord opt = app.mOptRecord;
        // if an app is already frozen and shouldNotFreeze becomes true, immediately unfreeze
        if (opt.isFrozen() && opt.shouldNotFreeze()) {
+17 −0
Original line number Diff line number Diff line
@@ -80,6 +80,12 @@ final class ProcessCachedOptimizerRecord {
    @GuardedBy("mProcLock")
    private boolean mShouldNotFreeze;

    /**
     * Exempt from freezer (now for system apps with INSTALL_PACKAGES permission)
     */
    @GuardedBy("mProcLock")
    private boolean mFreezeExempt;

    @GuardedBy("mProcLock")
    long getLastCompactTime() {
        return mLastCompactTime;
@@ -160,6 +166,16 @@ final class ProcessCachedOptimizerRecord {
        mShouldNotFreeze = shouldNotFreeze;
    }

    @GuardedBy("mProcLock")
    boolean isFreezeExempt() {
        return mFreezeExempt;
    }

    @GuardedBy("mPreLock")
    void setFreezeExempt(boolean exempt) {
        mFreezeExempt = exempt;
    }

    ProcessCachedOptimizerRecord(ProcessRecord app) {
        mApp = app;
        mProcLock = app.mService.mProcLock;
@@ -173,6 +189,7 @@ final class ProcessCachedOptimizerRecord {
    void dump(PrintWriter pw, String prefix, long nowUptime) {
        pw.print(prefix); pw.print("lastCompactTime="); pw.print(mLastCompactTime);
        pw.print(" lastCompactAction="); pw.println(mLastCompactAction);
        pw.print(prefix); pw.print("isFreezeExempt="); pw.print(mFreezeExempt);
        pw.print(" " + IS_FROZEN + "="); pw.println(mFrozen);
    }
}
+9 −1
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import static com.android.server.am.ActivityManagerService.TAG_NETWORK;
import static com.android.server.am.ActivityManagerService.TAG_PROCESSES;
import static com.android.server.am.ActivityManagerService.TAG_UID_OBSERVERS;

import android.Manifest;
import android.annotation.NonNull;
import android.app.ActivityManager;
import android.app.ActivityManager.ProcessCapability;
@@ -76,6 +77,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.res.Resources;
import android.graphics.Point;
@@ -1773,9 +1775,9 @@ public final class ProcessList {
        mService.updateCpuStats();
        checkSlow(startTime, "startProcess: done updating cpu stats");

        try {
        try {
            final int userId = UserHandle.getUserId(app.uid);
            try {
                AppGlobals.getPackageManager().checkPackageStartable(app.info.packageName, userId);
            } catch (RemoteException e) {
                throw e.rethrowAsRuntimeException();
@@ -1798,6 +1800,12 @@ public final class ProcessList {
                            app.info.packageName);
                    externalStorageAccess = storageManagerInternal.hasExternalStorageAccess(uid,
                            app.info.packageName);
                    if (pm.checkPermission(Manifest.permission.INSTALL_PACKAGES,
                            app.info.packageName, userId)
                            == PackageManager.PERMISSION_GRANTED) {
                        Slog.i(TAG, app.info.packageName + " is exempt from freezer");
                        app.mOptRecord.setFreezeExempt(true);
                    }
                } catch (RemoteException e) {
                    throw e.rethrowAsRuntimeException();
                }
+1 −1

File changed.

Contains only whitespace changes.