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

Commit 6a8d1fe8 authored by Christopher Tate's avatar Christopher Tate
Browse files

No longer require the AMS lock for isAppBad()

Bug: 166319711
Test: atest android.jobscheduler.cts
Test: atest ActivityManagerServiceTest
Change-Id: Idaf20c4f220b356de77028db65633a19995d3d5c
parent 462fc154
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -5762,9 +5762,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    private boolean isAppBad(final String processName, final int uid) {
        synchronized (this) {
            return mAppErrors.isBadProcessLocked(processName, uid);
        }
        return mAppErrors.isBadProcess(processName, uid);
    }
    // NOTE: this is an internal method used by the OnShellCommand implementation only and should
+79 −63
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import android.util.SparseArray;
import android.util.TimeUtils;
import android.util.proto.ProtoOutputStream;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.ProcessMap;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto;
@@ -96,7 +97,11 @@ class AppErrors {
     * a minimum amount of time; they are removed from it when they are
     * later restarted (hopefully due to some user action).  The value is the
     * time it was added to the list.
     *
     * Access is synchronized on the container object itself, and no other
     * locks may be acquired while holding that one.
     */
    @GuardedBy("mBadProcesses")
    private final ProcessMap<BadProcessInfo> mBadProcesses = new ProcessMap<>();


@@ -114,10 +119,13 @@ class AppErrors {
        mProcessCrashTimes.clear();
        mProcessCrashTimesPersistent.clear();
        mProcessCrashShowDialogTimes.clear();
        synchronized (mBadProcesses) {
            mBadProcesses.clear();
        }
    }

    void dumpDebug(ProtoOutputStream proto, long fieldId, String dumpPackage) {
        synchronized (mBadProcesses) {
            if (mProcessCrashTimes.getMap().isEmpty() && mBadProcesses.getMap().isEmpty()) {
                return;
            }
@@ -139,7 +147,8 @@ class AppErrors {
                    for (int i = 0; i < uidCount; i++) {
                        final int puid = uids.keyAt(i);
                        final ProcessRecord r = mService.getProcessNames().get(pname, puid);
                    if (dumpPackage != null && (r == null || !r.pkgList.containsKey(dumpPackage))) {
                        if (dumpPackage != null
                                && (r == null || !r.pkgList.containsKey(dumpPackage))) {
                            continue;
                        }
                        final long etoken = proto.start(AppErrorsProto.ProcessCrashTime.ENTRIES);
@@ -185,6 +194,7 @@ class AppErrors {

            proto.end(token);
        }
    }

    boolean dumpLocked(FileDescriptor fd, PrintWriter pw, boolean needSep, String dumpPackage) {
        if (!mProcessCrashTimes.getMap().isEmpty()) {
@@ -272,13 +282,17 @@ class AppErrors {
        return needSep;
    }

    boolean isBadProcessLocked(final String processName, final int uid) {
    boolean isBadProcess(final String processName, final int uid) {
        synchronized (mBadProcesses) {
            return mBadProcesses.get(processName, uid) != null;
        }
    }

    void clearBadProcessLocked(final String processName, final int uid) {
    void clearBadProcess(final String processName, final int uid) {
        synchronized (mBadProcesses) {
            mBadProcesses.remove(processName, uid);
        }
    }

    void resetProcessCrashTimeLocked(final String processName, final int uid) {
        mProcessCrashTimes.remove(processName, uid);
@@ -747,8 +761,10 @@ class AppErrors {
                if (!app.isolated) {
                    // XXX We don't have a way to mark isolated processes
                    // as bad, since they don't have a peristent identity.
                    synchronized (mBadProcesses) {
                        mBadProcesses.put(app.processName, app.uid,
                                new BadProcessInfo(now, shortMsg, longMsg, stackTrace));
                    }
                    mProcessCrashTimes.remove(app.processName, app.uid);
                }
                app.bad = true;
+3 −3
Original line number Diff line number Diff line
@@ -2360,7 +2360,7 @@ public final class ProcessList {
            if ((intentFlags & Intent.FLAG_FROM_BACKGROUND) != 0) {
                // If we are in the background, then check to see if this process
                // is bad.  If so, we will just silently fail.
                if (mService.mAppErrors.isBadProcessLocked(processName, info.uid)) {
                if (mService.mAppErrors.isBadProcess(processName, info.uid)) {
                    if (DEBUG_PROCESSES) Slog.v(TAG, "Bad process: " + info.uid
                            + "/" + processName);
                    return null;
@@ -2373,11 +2373,11 @@ public final class ProcessList {
                if (DEBUG_PROCESSES) Slog.v(TAG, "Clearing bad process: " + info.uid
                        + "/" + processName);
                mService.mAppErrors.resetProcessCrashTimeLocked(processName, info.uid);
                if (mService.mAppErrors.isBadProcessLocked(processName, info.uid)) {
                if (mService.mAppErrors.isBadProcess(processName, info.uid)) {
                    EventLog.writeEvent(EventLogTags.AM_PROC_GOOD,
                            UserHandle.getUserId(info.uid), info.uid,
                            info.processName);
                    mService.mAppErrors.clearBadProcessLocked(processName, info.uid);
                    mService.mAppErrors.clearBadProcess(processName, info.uid);
                    if (app != null) {
                        app.bad = false;
                    }