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

Commit 361ecf28 authored by Aka (Chih-Yu) Huang's avatar Aka (Chih-Yu) Huang Committed by Android (Google) Code Review
Browse files

Merge changes Idb583186,I8941080a,Iaa5f824f into main

* changes:
  Move LRU sequence to ProcessStateRecord
  Move PlatformCompatCache to new package
  Decouple ProcessStateRecord with Observer pattern
parents 60959866 2dc911ed
Loading
Loading
Loading
Loading
+3 −37
Original line number Diff line number Diff line
@@ -84,7 +84,6 @@ import static com.android.server.am.ActivityManagerService.TAG_LRU;
import static com.android.server.am.ActivityManagerService.TAG_OOM_ADJ;
import static com.android.server.am.ActivityManagerService.TAG_UID_OBSERVERS;
import static com.android.server.am.AppProfiler.TAG_PSS;
import static com.android.server.am.PlatformCompatCache.CACHED_COMPAT_CHANGE_USE_SHORT_FGS_USAGE_INTERACTION_TIME;
import static com.android.server.am.ProcessList.CACHED_APP_IMPORTANCE_LEVELS;
import static com.android.server.am.ProcessList.CACHED_APP_MAX_ADJ;
import static com.android.server.am.ProcessList.CACHED_APP_MIN_ADJ;
@@ -105,6 +104,7 @@ import static com.android.server.am.ProcessList.SERVICE_ADJ;
import static com.android.server.am.ProcessList.TAG_PROCESS_OBSERVERS;
import static com.android.server.am.ProcessList.UNKNOWN_ADJ;
import static com.android.server.am.ProcessList.VISIBLE_APP_ADJ;
import static com.android.server.am.psc.PlatformCompatCache.CACHED_COMPAT_CHANGE_USE_SHORT_FGS_USAGE_INTERACTION_TIME;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH;

import android.annotation.NonNull;
@@ -116,9 +116,6 @@ import android.app.ActivityThread;
import android.app.AppProtoEnums;
import android.app.ApplicationExitInfo;
import android.app.usage.UsageEvents;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledAfter;
import android.compat.annotation.EnabledSince;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -143,7 +140,8 @@ import com.android.internal.annotations.CompositeRWLock;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.ServiceThread;
import com.android.server.am.PlatformCompatCache.CachedCompatChangeId;
import com.android.server.am.psc.PlatformCompatCache;
import com.android.server.am.psc.PlatformCompatCache.CachedCompatChangeId;
import com.android.server.wm.WindowProcessController;

import java.io.PrintWriter;
@@ -277,38 +275,6 @@ public abstract class OomAdjuster {
        }
    }

    /**
     * Flag {@link android.content.Context#BIND_INCLUDE_CAPABILITIES} is used
     * to pass while-in-use capabilities from client process to bound service. In targetSdkVersion
     * R and above, if client is a TOP activity, when this flag is present, bound service gets all
     * while-in-use capabilities; when this flag is not present, bound service gets no while-in-use
     * capability from client.
     */
    @ChangeId
    @EnabledAfter(targetSdkVersion=android.os.Build.VERSION_CODES.Q)
    static final long PROCESS_CAPABILITY_CHANGE_ID = 136274596L;

    /**
     * In targetSdkVersion R and above, foreground service has camera and microphone while-in-use
     * capability only when the {@link android.R.attr#foregroundServiceType} is configured as
     * {@link android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_CAMERA} and
     * {@link android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_MICROPHONE} respectively in the
     * manifest file.
     * In targetSdkVersion below R, foreground service automatically have camera and microphone
     * capabilities.
     */
    @ChangeId
    @EnabledAfter(targetSdkVersion=android.os.Build.VERSION_CODES.Q)
    static final long CAMERA_MICROPHONE_CAPABILITY_CHANGE_ID = 136219221L;

    /**
     * For apps targeting S+, this determines whether to use a shorter timeout before elevating the
     * standby bucket to ACTIVE when apps start a foreground service.
     */
    @ChangeId
    @EnabledSince(targetSdkVersion = android.os.Build.VERSION_CODES.S)
    static final long USE_SHORT_FGS_USAGE_INTERACTION_TIME = 183972877L;

    /**
     * Service for optimizing resource usage from background apps.
     */
+2 −2
Original line number Diff line number Diff line
@@ -58,8 +58,6 @@ import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_UID_OBSERVE
import static com.android.server.am.ActivityManagerService.TAG_BACKUP;
import static com.android.server.am.ActivityManagerService.TAG_OOM_ADJ;
import static com.android.server.am.ActivityManagerService.TAG_UID_OBSERVERS;
import static com.android.server.am.PlatformCompatCache.CACHED_COMPAT_CHANGE_CAMERA_MICROPHONE_CAPABILITY;
import static com.android.server.am.PlatformCompatCache.CACHED_COMPAT_CHANGE_PROCESS_CAPABILITY;
import static com.android.server.am.ProcessCachedOptimizerRecord.SHOULD_NOT_FREEZE_REASON_BINDER_ALLOW_OOM_MANAGEMENT;
import static com.android.server.am.ProcessList.BACKUP_APP_ADJ;
import static com.android.server.am.ProcessList.CACHED_APP_MAX_ADJ;
@@ -86,6 +84,8 @@ import static com.android.server.am.ProcessList.SERVICE_B_ADJ;
import static com.android.server.am.ProcessList.SYSTEM_ADJ;
import static com.android.server.am.ProcessList.UNKNOWN_ADJ;
import static com.android.server.am.ProcessList.VISIBLE_APP_ADJ;
import static com.android.server.am.psc.PlatformCompatCache.CACHED_COMPAT_CHANGE_CAMERA_MICROPHONE_CAPABILITY;
import static com.android.server.am.psc.PlatformCompatCache.CACHED_COMPAT_CHANGE_PROCESS_CAPABILITY;

import android.annotation.IntDef;
import android.annotation.NonNull;
+6 −4
Original line number Diff line number Diff line
@@ -146,6 +146,7 @@ import com.android.server.ServiceThread;
import com.android.server.SystemConfig;
import com.android.server.Watchdog;
import com.android.server.am.ActivityManagerService.ProcessChangeItem;
import com.android.server.am.psc.PlatformCompatCache;
import com.android.server.compat.PlatformCompat;
import com.android.server.pm.pkg.AndroidPackage;
import com.android.server.pm.pkg.PackageStateInternal;
@@ -3707,7 +3708,7 @@ public final class ProcessList {
            if (DEBUG_LRU) Slog.d(TAG_LRU, "Moving dep from " + lrui + " to " + index
                    + " in LRU list: " + app);
            mLruProcesses.add(index, app);
            app.setLruSeq(mLruSeq);
            app.mState.setLruSeq(mLruSeq);

            if (isActivity) {
                nextActivityIndex = index;
@@ -4113,7 +4114,7 @@ public final class ProcessList {
            }
        }

        app.setLruSeq(mLruSeq);
        app.mState.setLruSeq(mLruSeq);

        // Key of the indices array holds the current index of the process in the LRU list and the
        // value is a boolean indicating whether the process is an activity process or not.
@@ -4130,7 +4131,7 @@ public final class ProcessList {
            ConnectionRecord cr = psr.getConnectionAt(j);
            if (cr.binding != null && !cr.serviceDead && cr.binding.service != null
                    && cr.binding.service.app != null
                    && cr.binding.service.app.getLruSeq() != mLruSeq
                    && cr.binding.service.app.mState.getLruSeq() != mLruSeq
                    && cr.notHasFlag(Context.BIND_REDUCTION_FLAGS)
                    && !cr.binding.service.app.isPersistent()) {
                if (cr.binding.service.app.mServices.hasClientActivities()) {
@@ -4147,7 +4148,8 @@ public final class ProcessList {
        final ProcessProviderRecord ppr = app.mProviders;
        for (int j = ppr.numberOfProviderConnections() - 1; j >= 0; j--) {
            ContentProviderRecord cpr = ppr.getProviderConnectionAt(j).provider;
            if (cpr.proc != null && cpr.proc.getLruSeq() != mLruSeq && !cpr.proc.isPersistent()) {
            if (cpr.proc != null && cpr.proc.mState.getLruSeq() != mLruSeq
                    && !cpr.proc.isPersistent()) {
                indices.append(offerLruProcessInternalLSP(cpr.proc, now,
                        "provider reference", cpr, app), false);
            }
+11 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.am;

import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_EMPTY;
import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_STARTED_SERVICE;

import android.app.IApplicationThread;
import android.app.ProcessMemoryState.HostingComponentType;
@@ -44,7 +45,7 @@ import java.util.concurrent.atomic.AtomicLong;
 *
 * TODO(b/297542292): Update PSS names with RSS once AppProfiler's PSS profiling has been replaced.
 */
final class ProcessProfileRecord {
final class ProcessProfileRecord implements ProcessStateRecord.StartedServiceObserver {
    final ProcessRecord mApp;

    private final ActivityManagerService mService;
@@ -731,4 +732,13 @@ final class ProcessProfileRecord {
        }
        pw.println();
    }

    @Override
    public void onHasStartedServicesChanged(boolean hasStartedServices) {
        if (hasStartedServices) {
            addHostingComponentType(HOSTING_COMPONENT_TYPE_STARTED_SERVICE);
        } else {
            clearHostingComponentType(HOSTING_COMPONENT_TYPE_STARTED_SERVICE);
        }
    }
}
+6 −19
Original line number Diff line number Diff line
@@ -339,12 +339,6 @@ class ProcessRecord implements WindowProcessListener {
    @GuardedBy("mService")
    private boolean mUsingWrapper;

    /**
     * Sequence id for identifying LRU update cycles.
     */
    @GuardedBy("mService")
    private int mLruSeq;

    /**
     * Class to run on start if this is a special isolated process.
     */
@@ -562,6 +556,9 @@ class ProcessRecord implements WindowProcessListener {
        if (mState.getSetProcState() > ActivityManager.PROCESS_STATE_SERVICE) {
            mProfile.dumpCputime(pw, prefix);
        }
        if (mProfile.hasPendingUiClean()) {
            pw.print(prefix); pw.print("pendingUiClean="); pw.println(mProfile.hasPendingUiClean());
        }
        mProfile.dumpPss(pw, prefix, nowUptime);
        mState.dump(pw, prefix, nowUptime);
        mErrorState.dump(pw, prefix, nowUptime);
@@ -627,14 +624,14 @@ class ProcessRecord implements WindowProcessListener {
        mProviders = new ProcessProviderRecord(this);
        mReceivers = new ProcessReceiverRecord(this);
        mErrorState = new ProcessErrorStateRecord(this);
        mState = new ProcessStateRecord(processName, uid, this);
        mWindowProcessController = new WindowProcessController(
                mService.mActivityTaskManager, info, processName, uid, userId, this, this);
        mState = new ProcessStateRecord(processName, uid, mWindowProcessController, mProfile, this);
        mOptRecord = new ProcessCachedOptimizerRecord(this);
        final long now = SystemClock.uptimeMillis();
        mProfile.init(now);
        mOptRecord.init(now);
        mState.init(now);
        mWindowProcessController = new WindowProcessController(
                mService.mActivityTaskManager, info, processName, uid, userId, this, this);
        mPkgList.put(_info.packageName, new ProcessStats.ProcessStateHolder(_info.longVersionCode));
        updateProcessRecordNodes(this);
    }
@@ -1138,16 +1135,6 @@ class ProcessRecord implements WindowProcessListener {
        mWindowProcessController.setUsingWrapper(usingWrapper);
    }

    @GuardedBy("mService")
    int getLruSeq() {
        return mLruSeq;
    }

    @GuardedBy("mService")
    void setLruSeq(int lruSeq) {
        mLruSeq = lruSeq;
    }

    @GuardedBy("mService")
    String getIsolatedEntryPoint() {
        return mIsolatedEntryPoint;
Loading