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

Commit aa74644a authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Move oom adjust related code to OomAdjuster

This is part 2 of moving process management related
code out of ActivityManagerService

Move all the compute/update/applyOomAdjust methods,
leaving some shims behind for convenience.

Bug: 111369273
Test: Build and boot
      atest CtsAppTestCases
      atest ActivityManagerInternalTest
      atest ActivityManagerServiceTest
Change-Id: Ie8d203bbdff5a8a7b86a80b368f6125b6a23c949
parent 6169956c
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -505,7 +505,7 @@ public final class ActiveServices {
                }
                }
                // This app knows it is in the new model where this operation is not
                // This app knows it is in the new model where this operation is not
                // allowed, so tell it what has happened.
                // allowed, so tell it what has happened.
                UidRecord uidRec = mAm.mActiveUids.get(r.appInfo.uid);
                UidRecord uidRec = mAm.mProcessList.getUidRecordLocked(r.appInfo.uid);
                return new ComponentName("?", "app is in background uid " + uidRec);
                return new ComponentName("?", "app is in background uid " + uidRec);
            }
            }
        }
        }
+69 −2006

File changed.

Preview size limit exceeded, changes collapsed.

+2100 −0

File added.

Preview size limit exceeded, changes collapsed.

+43 −5
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.am;
package com.android.server.am;


import static android.app.ActivityManager.PROCESS_STATE_CACHED_ACTIVITY;
import static android.app.ActivityManager.PROCESS_STATE_CACHED_ACTIVITY;
import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
import static android.app.ActivityThread.PROC_START_SEQ_IDENT;
import static android.app.ActivityThread.PROC_START_SEQ_IDENT;
import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AUTO;
import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AUTO;
import static android.os.Process.SYSTEM_UID;
import static android.os.Process.SYSTEM_UID;
@@ -123,7 +124,7 @@ import java.util.List;
 * </ul>
 * </ul>
 */
 */
public final class ProcessList {
public final class ProcessList {
    private static final String TAG = TAG_WITH_CLASS_NAME ? "ProcessList" : TAG_AM;
    static final String TAG = TAG_WITH_CLASS_NAME ? "ProcessList" : TAG_AM;


    // The minimum time we allow between crashes, for us to consider this
    // The minimum time we allow between crashes, for us to consider this
    // application to be bad and stop and its services and reject broadcasts.
    // application to be bad and stop and its services and reject broadcasts.
@@ -352,6 +353,8 @@ public final class ProcessList {
     */
     */
    int mLruSeq = 0;
    int mLruSeq = 0;


    ActiveUids mActiveUids;

    /**
    /**
     * The currently running isolated processes.
     * The currently running isolated processes.
     */
     */
@@ -549,8 +552,10 @@ public final class ProcessList {
        updateOomLevels(0, 0, false);
        updateOomLevels(0, 0, false);
    }
    }


    void init(ActivityManagerService service) {
    void init(ActivityManagerService service, ActiveUids activeUids) {
        mService = service;
        mService = service;
        mActiveUids = activeUids;

        if (sKillHandler == null) {
        if (sKillHandler == null) {
            sKillThread = new ServiceThread(TAG + ":kill",
            sKillThread = new ServiceThread(TAG + ":kill",
                    THREAD_PRIORITY_BACKGROUND, true /* allowIo */);
                    THREAD_PRIORITY_BACKGROUND, true /* allowIo */);
@@ -2176,7 +2181,7 @@ public final class ProcessList {
        } else if (old != null) {
        } else if (old != null) {
            Slog.wtf(TAG, "Already have existing proc " + old + " when adding " + proc);
            Slog.wtf(TAG, "Already have existing proc " + old + " when adding " + proc);
        }
        }
        UidRecord uidRec = mService.mActiveUids.get(proc.uid);
        UidRecord uidRec = mActiveUids.get(proc.uid);
        if (uidRec == null) {
        if (uidRec == null) {
            uidRec = new UidRecord(proc.uid, mService.mAtmInternal);
            uidRec = new UidRecord(proc.uid, mService.mAtmInternal);
            // This is the first appearance of the uid, report it now!
            // This is the first appearance of the uid, report it now!
@@ -2188,7 +2193,7 @@ public final class ProcessList {
                uidRec.setWhitelist = uidRec.curWhitelist = true;
                uidRec.setWhitelist = uidRec.curWhitelist = true;
            }
            }
            uidRec.updateHasInternetPermission();
            uidRec.updateHasInternetPermission();
            mService.mActiveUids.put(proc.uid, uidRec);
            mActiveUids.put(proc.uid, uidRec);
            EventLogTags.writeAmUidRunning(uidRec.uid);
            EventLogTags.writeAmUidRunning(uidRec.uid);
            mService.noteUidProcessState(uidRec.uid, uidRec.getCurProcState());
            mService.noteUidProcessState(uidRec.uid, uidRec.getCurProcState());
        }
        }
@@ -2290,7 +2295,7 @@ public final class ProcessList {
                        "No more processes in " + old.uidRecord);
                        "No more processes in " + old.uidRecord);
                mService.enqueueUidChangeLocked(old.uidRecord, -1, UidRecord.CHANGE_GONE);
                mService.enqueueUidChangeLocked(old.uidRecord, -1, UidRecord.CHANGE_GONE);
                EventLogTags.writeAmUidStopped(uid);
                EventLogTags.writeAmUidStopped(uid);
                mService.mActiveUids.remove(uid);
                mActiveUids.remove(uid);
                mService.noteUidProcessState(uid, ActivityManager.PROCESS_STATE_NONEXISTENT);
                mService.noteUidProcessState(uid, ActivityManager.PROCESS_STATE_NONEXISTENT);
            }
            }
            old.uidRecord = null;
            old.uidRecord = null;
@@ -3050,4 +3055,37 @@ public final class ProcessList {
            }
            }
        }
        }
    }
    }

    /** Returns the uid's process state or PROCESS_STATE_NONEXISTENT if not running */
    @GuardedBy("mService")
    int getUidProcStateLocked(int uid) {
        UidRecord uidRec = mActiveUids.get(uid);
        return uidRec == null ? PROCESS_STATE_NONEXISTENT : uidRec.getCurProcState();
    }

    /** Returns the UidRecord for the given uid, if it exists. */
    @GuardedBy("mService")
    UidRecord getUidRecordLocked(int uid) {
        return mActiveUids.get(uid);
    }

    /**
     * Call {@link ActivityManagerService#doStopUidLocked}
     * (which will also stop background services) for all idle UIDs.
     */
    @GuardedBy("mService")
    void doStopUidForIdleUidsLocked() {
        final int size = mActiveUids.size();
        for (int i = 0; i < size; i++) {
            final int uid = mActiveUids.keyAt(i);
            if (UserHandle.isCore(uid)) {
                continue;
            }
            final UidRecord uidRec = mActiveUids.valueAt(i);
            if (!uidRec.idle) {
                continue;
            }
            mService.doStopUidLocked(uidRec.uid, uidRec);
        }
    }
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -117,7 +117,7 @@ public class ActivityManagerInternalTest {
        thread2.assertWaiting("Unexpected state for " + record2);
        thread2.assertWaiting("Unexpected state for " + record2);
        thread2.interrupt();
        thread2.interrupt();


        mAms.mActiveUids.clear();
        mAms.mProcessList.mActiveUids.clear();
    }
    }


    private UidRecord addActiveUidRecord(int uid, long curProcStateSeq,
    private UidRecord addActiveUidRecord(int uid, long curProcStateSeq,
@@ -126,7 +126,7 @@ public class ActivityManagerInternalTest {
        record.lastNetworkUpdatedProcStateSeq = lastNetworkUpdatedProcStateSeq;
        record.lastNetworkUpdatedProcStateSeq = lastNetworkUpdatedProcStateSeq;
        record.curProcStateSeq = curProcStateSeq;
        record.curProcStateSeq = curProcStateSeq;
        record.waitingForNetwork = true;
        record.waitingForNetwork = true;
        mAms.mActiveUids.put(uid, record);
        mAms.mProcessList.mActiveUids.put(uid, record);
        return record;
        return record;
    }
    }


Loading