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

Commit ba444030 authored by Chih-Yu Huang's avatar Chih-Yu Huang
Browse files

psc: Introduce ProcessServiceRecordInternal

This change moves service-related process state fields from
ProcessServiceRecord to a new abstract base class,
ProcessServiceRecordInternal. This encapsulates these internal state
variables and their accessors, improving modularity and preparing for
future PSC-related refactor.

Bug: 425766486
Test: m services.core
Test: atest MockingOomAdjusterTests OomAdjusterTests
Test: atest FrameworksServicesTestsRavenwood_ProcessStateController
Flag: EXEMPT pure refactor

Change-Id: I2a416ad2ea7f29b9f52983b734984e307a1fb267
parent a4f3d47a
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -5306,8 +5306,7 @@ public final class ActiveServices {
            if (r.app != null) {
                psr = r.app.mServices;
                mAm.mProcessStateController.startExecutingService(psr, r);
                mAm.mProcessStateController.setExecServicesFg(psr,
                        psr.shouldExecServicesFg() || fg);
                mAm.mProcessStateController.setExecServicesFg(psr, psr.isExecServicesFg() || fg);
                if (timeoutNeeded && psr.numberOfExecutingServices() == 1) {
                    if (!shouldSkipTimeout) {
                        scheduleServiceTimeoutLocked(r.app);
@@ -5318,7 +5317,7 @@ public final class ActiveServices {
            }
        } else if (r.app != null && fg) {
            psr = r.app.mServices;
            if (!psr.shouldExecServicesFg()) {
            if (!psr.isExecServicesFg()) {
                mAm.mProcessStateController.setExecServicesFg(psr, true);
                if (timeoutNeeded) {
                    if (!shouldSkipTimeout) {
@@ -7714,7 +7713,7 @@ public final class ActiveServices {
                }
                final long now = SystemClock.uptimeMillis();
                final long maxTime =  now
                        - (psr.shouldExecServicesFg()
                        - (psr.isExecServicesFg()
                        ? mAm.mConstants.SERVICE_TIMEOUT
                        : mAm.mConstants.SERVICE_BACKGROUND_TIMEOUT);
                ServiceRecord timeout = null;
@@ -7746,7 +7745,7 @@ public final class ActiveServices {
                    mActiveServiceAnrTimer.accept(proc, timeoutRecord);
                } else {
                    mActiveServiceAnrTimer.discard(proc);
                    final long delay = psr.shouldExecServicesFg()
                    final long delay = psr.isExecServicesFg()
                                       ? (nextTime + mAm.mConstants.SERVICE_TIMEOUT) :
                                       (nextTime + mAm.mConstants.SERVICE_BACKGROUND_TIMEOUT)
                                       - SystemClock.uptimeMillis();
@@ -7890,7 +7889,7 @@ public final class ActiveServices {
        if (proc.mServices.numberOfExecutingServices() == 0 || proc.getThread() == null) {
            return;
        }
        final long delay = proc.mServices.shouldExecServicesFg()
        final long delay = proc.mServices.isExecServicesFg()
                ? mAm.mConstants.SERVICE_TIMEOUT : mAm.mConstants.SERVICE_BACKGROUND_TIMEOUT;
        mActiveServiceAnrTimer.start(proc, delay);
        proc.mServices.noteScheduleServiceTimeoutPending(false);
+8 −7
Original line number Diff line number Diff line
@@ -152,6 +152,7 @@ import com.android.server.am.psc.ContentProviderConnectionInternal;
import com.android.server.am.psc.PlatformCompatCache;
import com.android.server.am.psc.PlatformCompatCache.CachedCompatChangeId;
import com.android.server.am.psc.ProcessRecordInternal;
import com.android.server.am.psc.ProcessServiceRecordInternal;
import com.android.server.am.psc.ServiceRecordInternal;
import com.android.server.am.psc.UidRecordInternal;
import com.android.server.wm.WindowProcessController;
@@ -652,7 +653,7 @@ public abstract class OomAdjuster {
        if (!includeWarmPkg) {
            return;
        }
        final ProcessServiceRecord psr = app.mServices;
        final ProcessServiceRecordInternal psr = app.mServices;
        for (int j = psr.numberOfRunningServices() - 1; j >= 0; j--) {
            psr.getRunningServiceAt(j).updateKeepWarmLocked();
        }
@@ -1064,7 +1065,7 @@ public abstract class OomAdjuster {
                        targetAdj += 10 + mConstants.TIERED_CACHED_ADJ_UI_TIER_SIZE;
                    }
                    state.setCurRawAdj(targetAdj);
                    state.setCurAdj(applyBindAboveClientToAdj(psr.hasAboveClient(), targetAdj));
                    state.setCurAdj(applyBindAboveClientToAdj(psr.isHasAboveClient(), targetAdj));
                }
            }
        } else {
@@ -1121,7 +1122,7 @@ public abstract class OomAdjuster {
                } else if (!app.isKilledByAm() && app.getThread() != null
                               && curAdj >= UNKNOWN_ADJ) {
                    // If we haven't yet assigned the final cached adj to the process, do that now.
                    final ProcessServiceRecord psr = app.mServices;
                    final ProcessServiceRecordInternal psr = app.mServices;
                    switch (state.getCurProcState()) {
                        case PROCESS_STATE_LAST_ACTIVITY:
                        case PROCESS_STATE_CACHED_ACTIVITY:
@@ -1168,7 +1169,7 @@ public abstract class OomAdjuster {
                            final int rawAdj = curCachedAdj + curCachedImpAdj;
                            state.setCurRawAdj(rawAdj);
                            state.setCurAdj(
                                    applyBindAboveClientToAdj(psr.hasAboveClient(), rawAdj));
                                    applyBindAboveClientToAdj(psr.isHasAboveClient(), rawAdj));
                            if (DEBUG_LRU) {
                                Slog.d(TAG_LRU, "Assigning activity LRU #" + i
                                        + " adj: " + state.getCurAdj()
@@ -1195,8 +1196,8 @@ public abstract class OomAdjuster {
                            // cached level will be treated as empty (since their process
                            // state is still as a service), which is what we want.
                            state.setCurRawAdj(curEmptyAdj);
                            state.setCurAdj(
                                    applyBindAboveClientToAdj(psr.hasAboveClient(), curEmptyAdj));
                            state.setCurAdj(applyBindAboveClientToAdj(psr.isHasAboveClient(),
                                    curEmptyAdj));
                            if (DEBUG_LRU) {
                                Slog.d(TAG_LRU, "Assigning empty LRU #" + i
                                        + " adj: " + state.getCurAdj()
@@ -2056,7 +2057,7 @@ public abstract class OomAdjuster {
            // Process has user perceptible activities.
            return CPU_TIME_REASON_OTHER;
        }
        if (app.mServices.numberOfExecutingServices() > 0) {
        if (app.mServices.hasExecutingServices()) {
            // Ensure that services get cpu time during start-up and tear-down.
            return CPU_TIME_REASON_OTHER;
        }
+5 −5
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ import com.android.server.am.psc.ActiveUidsInternal;
import com.android.server.am.psc.ConnectionRecordInternal;
import com.android.server.am.psc.ContentProviderConnectionInternal;
import com.android.server.am.psc.ProcessRecordInternal;
import com.android.server.am.psc.ProcessServiceRecordInternal;
import com.android.server.am.psc.ServiceRecordInternal;
import com.android.server.am.psc.UidRecordInternal;
import com.android.server.wm.ActivityServiceConnectionsHolder;
@@ -1085,7 +1086,7 @@ public class OomAdjusterImpl extends OomAdjuster {
    @GuardedBy({"mService", "mProcLock"})
    private static void forEachClientConnectionLSP(ProcessRecord app,
            BiConsumer<Connection, ProcessRecord> connectionConsumer) {
        final ProcessServiceRecord psr = app.mServices;
        final ProcessServiceRecordInternal psr = app.mServices;

        for (int i = psr.numberOfRunningServices() - 1; i >= 0; i--) {
            final ServiceRecordInternal s = psr.getRunningServiceAt(i);
@@ -1330,12 +1331,11 @@ public class OomAdjusterImpl extends OomAdjuster {
            if (reportDebugMsgs) {
                reportOomAdjMessageLocked(TAG_OOM_ADJ, "Making broadcast: " + app);
            }
        } else if (psr.numberOfExecutingServices() > 0) {
        } else if (psr.hasExecutingServices()) {
            // An app that is currently executing a service callback also
            // counts as being in the foreground.
            adj = FOREGROUND_APP_ADJ;
            schedGroup = psr.shouldExecServicesFg()
                    ? SCHED_GROUP_DEFAULT : SCHED_GROUP_BACKGROUND;
            schedGroup = psr.isExecServicesFg() ? SCHED_GROUP_DEFAULT : SCHED_GROUP_BACKGROUND;
            state.setAdjType("exec-service");
            procState = PROCESS_STATE_SERVICE;
            if (reportDebugMsgs) {
@@ -1758,7 +1758,7 @@ public class OomAdjusterImpl extends OomAdjuster {
                // This is a cached process, but with client activities.  Mark it so.
                procState = PROCESS_STATE_CACHED_ACTIVITY_CLIENT;
                state.setAdjType("cch-client-act");
            } else if (psr.isTreatedLikeActivity()) {
            } else if (psr.isTreatLikeActivity()) {
                // This is a cached process, but somebody wants us to treat it like it has
                // an activity, okay!
                procState = PROCESS_STATE_CACHED_ACTIVITY;
+1 −1
Original line number Diff line number Diff line
@@ -418,7 +418,7 @@ class ProcessErrorStateRecord {
                            if (r.isPersistent()) {
                                firstPids.add(myPid);
                                if (DEBUG_ANR) Slog.i(TAG, "Adding persistent proc: " + r);
                            } else if (r.mServices.isTreatedLikeActivity()) {
                            } else if (r.mServices.isTreatLikeActivity()) {
                                firstPids.add(myPid);
                                if (DEBUG_ANR) Slog.i(TAG, "Adding likely IME: " + r);
                            } else {
+8 −8
Original line number Diff line number Diff line
@@ -3755,7 +3755,7 @@ public final class ProcessList implements ProcessStateController.ProcessLruUpdat
    private void updateClientActivitiesOrderingLSP(final ProcessRecord topApp, final int topI,
            final int bottomI, int endIndex) {
        final ProcessServiceRecord topPsr = topApp.mServices;
        if (topApp.hasActivitiesOrRecentTasks() || topPsr.isTreatedLikeActivity()
        if (topApp.hasActivitiesOrRecentTasks() || topPsr.isTreatLikeActivity()
                || !topPsr.hasClientActivities()) {
            // If this is not a special process that has client activities, then there is
            // nothing to do.
@@ -3860,7 +3860,7 @@ public final class ProcessList implements ProcessStateController.ProcessLruUpdat
                        if (DEBUG_LRU) Slog.d(TAG_LRU,
                                "Looking at next app at " + i + ": " + subProc);
                        if (subProc.hasActivitiesOrRecentTasks()
                                || subPsr.isTreatedLikeActivity()) {
                                || subPsr.isTreatLikeActivity()) {
                            if (DEBUG_LRU) Slog.d(TAG_LRU,
                                    "This is hosting an activity!");
                            if (hasActivity) {
@@ -3945,7 +3945,7 @@ public final class ProcessList implements ProcessStateController.ProcessLruUpdat
            ProcessRecord client) {
        final ProcessServiceRecord psr = app.mServices;
        final boolean hasActivity = app.hasActivitiesOrRecentTasks() || psr.hasClientActivities()
                || psr.isTreatedLikeActivity();
                || psr.isTreatLikeActivity();
        final boolean hasService = false; // not impl yet. app.services.size() > 0;
        if (!activityChange && hasActivity) {
            // The process has activities, so we are only allowing activity-based adjustments
@@ -4065,7 +4065,7 @@ public final class ProcessList implements ProcessStateController.ProcessLruUpdat
        if (hasActivity) {
            final int N = mLruProcesses.size();
            nextIndex = mLruProcessServiceStart;
            if (!app.hasActivitiesOrRecentTasks() && !psr.isTreatedLikeActivity()
            if (!app.hasActivitiesOrRecentTasks() && !psr.isTreatLikeActivity()
                    && mLruProcessActivityStart < (N - 1)) {
                // Process doesn't have activities, but has clients with
                // activities...  move it up, but below the app that is binding to it.
@@ -4428,7 +4428,7 @@ public final class ProcessList implements ProcessStateController.ProcessLruUpdat
        pw.print(proc.toShortString());
        final ProcessServiceRecord psr = proc.mServices;
        if (proc.hasActivitiesOrRecentTasks() || psr.hasClientActivities()
                || psr.isTreatedLikeActivity()) {
                || psr.isTreatLikeActivity()) {
            pw.print(" act:");
            boolean printed = false;
            if (proc.hasActivities()) {
@@ -4449,7 +4449,7 @@ public final class ProcessList implements ProcessStateController.ProcessLruUpdat
                pw.print("client");
                printed = true;
            }
            if (psr.isTreatedLikeActivity()) {
            if (psr.isTreatLikeActivity()) {
                if (printed) {
                    pw.print("|");
                }
@@ -4786,7 +4786,7 @@ public final class ProcessList implements ProcessStateController.ProcessLruUpdat
                        r.mProfile.getLastCachedPss() * 1024, new StringBuilder()));
                proto.write(ProcessOomProto.Detail.CACHED, state.isCached());
                proto.write(ProcessOomProto.Detail.EMPTY, state.isEmpty());
                proto.write(ProcessOomProto.Detail.HAS_ABOVE_CLIENT, psr.hasAboveClient());
                proto.write(ProcessOomProto.Detail.HAS_ABOVE_CLIENT, psr.isHasAboveClient());

                if (state.getSetProcState() >= ActivityManager.PROCESS_STATE_SERVICE) {
                    long lastCpuTime = r.mProfile.mLastCpuTime.get();
@@ -4934,7 +4934,7 @@ public final class ProcessList implements ProcessStateController.ProcessLruUpdat
                pw.print("    ");
                pw.print("cached="); pw.print(state.isCached());
                pw.print(" empty="); pw.print(state.isEmpty());
                pw.print(" hasAboveClient="); pw.println(psr.hasAboveClient());
                pw.print(" hasAboveClient="); pw.println(psr.isHasAboveClient());

                if (state.getSetProcState() >= ActivityManager.PROCESS_STATE_SERVICE) {
                    long lastCpuTime = r.mProfile.mLastCpuTime.get();
Loading