• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.server.am;
18 
19 import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
20 import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
21 import static com.android.server.am.ActivityManagerService.MY_PID;
22 
23 import android.annotation.Nullable;
24 import android.app.ActivityManager;
25 import android.app.ApplicationExitInfo;
26 import android.app.ApplicationExitInfo.Reason;
27 import android.app.ApplicationExitInfo.SubReason;
28 import android.app.IApplicationThread;
29 import android.content.pm.ApplicationInfo;
30 import android.content.pm.PackageManagerInternal;
31 import android.content.pm.ProcessInfo;
32 import android.content.pm.VersionedPackage;
33 import android.content.res.CompatibilityInfo;
34 import android.os.Binder;
35 import android.os.Bundle;
36 import android.os.IBinder;
37 import android.os.Process;
38 import android.os.RemoteException;
39 import android.os.SystemClock;
40 import android.os.Trace;
41 import android.os.UserHandle;
42 import android.server.ServerProtoEnums;
43 import android.util.ArrayMap;
44 import android.util.ArraySet;
45 import android.util.DebugUtils;
46 import android.util.EventLog;
47 import android.util.Slog;
48 import android.util.TimeUtils;
49 import android.util.proto.ProtoOutputStream;
50 
51 import com.android.internal.annotations.CompositeRWLock;
52 import com.android.internal.annotations.GuardedBy;
53 import com.android.internal.annotations.VisibleForTesting;
54 import com.android.internal.app.procstats.ProcessState;
55 import com.android.internal.app.procstats.ProcessStats;
56 import com.android.internal.os.Zygote;
57 import com.android.internal.util.FrameworkStatsLog;
58 import com.android.server.wm.WindowProcessController;
59 import com.android.server.wm.WindowProcessListener;
60 
61 import java.io.PrintWriter;
62 import java.util.Arrays;
63 import java.util.List;
64 import java.util.Objects;
65 
66 /**
67  * Full information about a particular process that
68  * is currently running.
69  */
70 class ProcessRecord implements WindowProcessListener {
71     static final String TAG = TAG_WITH_CLASS_NAME ? "ProcessRecord" : TAG_AM;
72 
73     final ActivityManagerService mService; // where we came from
74     private final ActivityManagerGlobalLock mProcLock;
75 
76     // =========================================================
77     // Basic info of the process, immutable or semi-immutable over
78     // the lifecycle of the process
79     // =========================================================
80     volatile ApplicationInfo info; // all about the first app in the process
81     final ProcessInfo processInfo; // if non-null, process-specific manifest info
82     final boolean isolated;     // true if this is a special isolated process
83     public final boolean isSdkSandbox; // true if this is an SDK sandbox process
84     final boolean appZygote;    // true if this is forked from the app zygote
85     final int uid;              // uid of process; may be different from 'info' if isolated
86     final int userId;           // user of process.
87     final String processName;   // name of the process
88     final String sdkSandboxClientAppPackage; // if this is an sdk sandbox process, name of the
89                                              // app package for which it is running
90     final String sdkSandboxClientAppVolumeUuid; // uuid of the app for which the sandbox is running
91 
92     /**
93      * Overall state of process's uid.
94      */
95     @CompositeRWLock({"mService", "mProcLock"})
96     private UidRecord mUidRecord;
97 
98     /**
99      * List of packages running in the process.
100      */
101     private final PackageList mPkgList = new PackageList(this);
102 
103     /**
104      * Additional packages we have a dependency on.
105      */
106     @CompositeRWLock({"mService", "mProcLock"})
107     private ArraySet<String> mPkgDeps;
108 
109     /**
110      * The process of this application; 0 if none.
111      */
112     @CompositeRWLock({"mService", "mProcLock"})
113     int mPid;
114 
115     /**
116      * The process ID which will be set when we're killing this process.
117      */
118     @GuardedBy("mService")
119     private int mDyingPid;
120 
121     /**
122      * The gids this process was launched with.
123      */
124     @GuardedBy("mService")
125     private int[] mGids;
126 
127     /**
128      * The ABI this process was launched with.
129      */
130     @GuardedBy("mService")
131     private String mRequiredAbi;
132 
133     /**
134      * The instruction set this process was launched with.
135      */
136     @GuardedBy("mService")
137     private String mInstructionSet;
138 
139     /**
140      * The actual proc...  may be null only if 'persistent' is true
141      * (in which case we are in the process of launching the app).
142      */
143     @CompositeRWLock({"mService", "mProcLock"})
144     private IApplicationThread mThread;
145 
146     /**
147      * Always keep this application running?
148      */
149     private volatile boolean mPersistent;
150 
151     /**
152      * Caching of toShortString() result.
153      * <p>Note: No lock here, it doesn't matter in case of race condition</p>
154      */
155     private String mShortStringName;
156 
157     /**
158      * Caching of toString() result.
159      * <p>Note: No lock here, it doesn't matter in case of race condition</p>
160      */
161     private String mStringName;
162 
163     /**
164      * Process start is pending.
165      */
166     @GuardedBy("mService")
167     private boolean mPendingStart;
168 
169     /**
170      * Seq no. Indicating the latest process start associated with this process record.
171      */
172     @GuardedBy("mService")
173     private long mStartSeq;
174 
175     /**
176      * Params used in starting this process.
177      */
178     private volatile HostingRecord mHostingRecord;
179 
180     /**
181      * Selinux info of this process.
182      */
183     private volatile String mSeInfo;
184 
185     /**
186      * When the process is started. (before zygote fork)
187      */
188     private volatile long mStartUptime;
189 
190     /**
191      * When the process is started. (before zygote fork)
192      */
193     private volatile long mStartElapsedTime;
194 
195     /**
196      * This will be same as {@link #uid} usually except for some apps used during factory testing.
197      */
198     private volatile int mStartUid;
199 
200     /**
201      * Indicates how the external storage was mounted for this process.
202      */
203     private volatile int mMountMode;
204 
205     /**
206      * True if Android/obb and Android/data need to be bind mount.
207      */
208     private volatile boolean mBindMountPending;
209 
210     /**
211      * True when proc was started in user unlocked state.
212      */
213     @GuardedBy("mProcLock")
214     private boolean mUnlocked;
215 
216     /**
217      * TID for RenderThread.
218      */
219     @GuardedBy("mProcLock")
220     private int mRenderThreadTid;
221 
222     /**
223      * Last used compatibility mode.
224      */
225     @GuardedBy("mService")
226     private CompatibilityInfo mCompat;
227 
228     /**
229      * Set of disabled compat changes for the process (all others are enabled).
230      */
231     @GuardedBy("mService")
232     private long[] mDisabledCompatChanges;
233 
234     /**
235      * Who is watching for the death.
236      */
237     @GuardedBy("mService")
238     private IBinder.DeathRecipient mDeathRecipient;
239 
240     /**
241      * Set to currently active instrumentation running in process.
242      */
243     @CompositeRWLock({"mService", "mProcLock"})
244     private ActiveInstrumentation mInstr;
245 
246     /**
247      * True when proc has been killed by activity manager, not for RAM.
248      */
249     @CompositeRWLock({"mService", "mProcLock"})
250     private boolean mKilledByAm;
251 
252     /**
253      * True once we know the process has been killed.
254      */
255     @CompositeRWLock({"mService", "mProcLock"})
256     private boolean mKilled;
257 
258     /**
259      * The timestamp in uptime when this process was killed.
260      */
261     @CompositeRWLock({"mService", "mProcLock"})
262     private long mKillTime;
263 
264     /**
265      * Process is waiting to be killed when in the bg, and reason.
266      */
267     @GuardedBy("mService")
268     private String mWaitingToKill;
269 
270     /**
271      * Whether this process should be killed and removed from process list.
272      * It is set when the package is force-stopped or the process has crashed too many times.
273      */
274     private volatile boolean mRemoved;
275 
276     /**
277      * Was app launched for debugging?
278      */
279     @GuardedBy("mService")
280     private boolean mDebugging;
281 
282     /**
283      * Has process show wait for debugger dialog?
284      */
285     @GuardedBy("mProcLock")
286     private boolean mWaitedForDebugger;
287 
288     /**
289      * For managing the LRU list.
290      */
291     @CompositeRWLock({"mService", "mProcLock"})
292     private long mLastActivityTime;
293 
294     /**
295      * Set to true when process was launched with a wrapper attached.
296      */
297     @GuardedBy("mService")
298     private boolean mUsingWrapper;
299 
300     /**
301      * Sequence id for identifying LRU update cycles.
302      */
303     @GuardedBy("mService")
304     private int mLruSeq;
305 
306     /**
307      * Class to run on start if this is a special isolated process.
308      */
309     @GuardedBy("mService")
310     private String mIsolatedEntryPoint;
311 
312     /**
313      * Arguments to pass to isolatedEntryPoint's main().
314      */
315     @GuardedBy("mService")
316     private String[] mIsolatedEntryPointArgs;
317 
318     /**
319      * Process is currently hosting a backup agent for backup or restore.
320      */
321     @GuardedBy("mService")
322     private boolean mInFullBackup;
323 
324     /**
325      * Controller for driving the process state on the window manager side.
326      */
327     private final WindowProcessController mWindowProcessController;
328 
329     /**
330      * Profiling info of the process, such as PSS, cpu, etc.
331      */
332     final ProcessProfileRecord mProfile;
333 
334     /**
335      * All about the services in this process.
336      */
337     final ProcessServiceRecord mServices;
338 
339     /**
340      * All about the providers in this process.
341      */
342     final ProcessProviderRecord mProviders;
343 
344     /**
345      * All about the receivers in this process.
346      */
347     final ProcessReceiverRecord mReceivers;
348 
349     /**
350      * All about the error state(crash, ANR) in this process.
351      */
352     final ProcessErrorStateRecord mErrorState;
353 
354     /**
355      * All about the process state info (proc state, oom adj score) in this process.
356      */
357     final ProcessStateRecord mState;
358 
359     /**
360      * All about the state info of the optimizer when the process is cached.
361      */
362     final ProcessCachedOptimizerRecord mOptRecord;
363 
364     /**
365      * The preceding instance of the process, which would exist when the previous process is killed
366      * but not fully dead yet; in this case, the new instance of the process should be held until
367      * this preceding instance is fully dead.
368      */
369     volatile ProcessRecord mPredecessor;
370 
371     /**
372      * The succeeding instance of the process, which is going to be started after this process
373      * is killed successfully.
374      */
375     volatile ProcessRecord mSuccessor;
376 
377     /**
378      * The routine to start its successor process.
379      *
380      * <p>Note: It should be accessed from process start thread only.</p>
381      */
382     Runnable mSuccessorStartRunnable;
383 
setStartParams(int startUid, HostingRecord hostingRecord, String seInfo, long startUptime, long startElapsedTime)384     void setStartParams(int startUid, HostingRecord hostingRecord, String seInfo,
385             long startUptime, long startElapsedTime) {
386         this.mStartUid = startUid;
387         this.mHostingRecord = hostingRecord;
388         this.mSeInfo = seInfo;
389         this.mStartUptime = startUptime;
390         this.mStartElapsedTime = startElapsedTime;
391     }
392 
393     @GuardedBy({"mService", "mProcLock"})
dump(PrintWriter pw, String prefix)394     void dump(PrintWriter pw, String prefix) {
395         final long nowUptime = SystemClock.uptimeMillis();
396         final long nowElapsedTime = SystemClock.elapsedRealtime();
397 
398         pw.print(prefix); pw.print("user #"); pw.print(userId);
399                 pw.print(" uid="); pw.print(info.uid);
400         if (uid != info.uid) {
401             pw.print(" ISOLATED uid="); pw.print(uid);
402         }
403         pw.print(" gids={");
404         if (mGids != null) {
405             for (int gi = 0; gi < mGids.length; gi++) {
406                 if (gi != 0) pw.print(", ");
407                 pw.print(mGids[gi]);
408 
409             }
410         }
411         pw.println("}");
412         if (processInfo != null) {
413             pw.print(prefix); pw.println("processInfo:");
414             if (processInfo.deniedPermissions != null) {
415                 for (int i = 0; i < processInfo.deniedPermissions.size(); i++) {
416                     pw.print(prefix); pw.print("  deny: ");
417                     pw.println(processInfo.deniedPermissions.valueAt(i));
418                 }
419             }
420             if (processInfo.gwpAsanMode != ApplicationInfo.GWP_ASAN_DEFAULT) {
421                 pw.print(prefix); pw.println("  gwpAsanMode=" + processInfo.gwpAsanMode);
422             }
423             if (processInfo.memtagMode != ApplicationInfo.MEMTAG_DEFAULT) {
424                 pw.print(prefix); pw.println("  memtagMode=" + processInfo.memtagMode);
425             }
426         }
427         pw.print(prefix); pw.print("mRequiredAbi="); pw.print(mRequiredAbi);
428         pw.print(" instructionSet="); pw.println(mInstructionSet);
429         if (info.className != null) {
430             pw.print(prefix); pw.print("class="); pw.println(info.className);
431         }
432         if (info.manageSpaceActivityName != null) {
433             pw.print(prefix); pw.print("manageSpaceActivityName=");
434             pw.println(info.manageSpaceActivityName);
435         }
436 
437         pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir);
438                 pw.print(" publicDir="); pw.print(info.publicSourceDir);
439                 pw.print(" data="); pw.println(info.dataDir);
440         mPkgList.dump(pw, prefix);
441         if (mPkgDeps != null) {
442             pw.print(prefix); pw.print("packageDependencies={");
443             for (int i = 0; i < mPkgDeps.size(); i++) {
444                 if (i > 0) pw.print(", ");
445                 pw.print(mPkgDeps.valueAt(i));
446             }
447             pw.println("}");
448         }
449         pw.print(prefix); pw.print("compat="); pw.println(mCompat);
450         if (mInstr != null) {
451             pw.print(prefix); pw.print("mInstr="); pw.println(mInstr);
452         }
453         pw.print(prefix); pw.print("thread="); pw.println(mThread);
454         pw.print(prefix); pw.print("pid="); pw.println(mPid);
455         pw.print(prefix); pw.print("lastActivityTime=");
456         TimeUtils.formatDuration(mLastActivityTime, nowUptime, pw);
457         pw.print(prefix); pw.print("startUptimeTime=");
458         TimeUtils.formatDuration(mStartElapsedTime, nowUptime, pw);
459         pw.print(prefix); pw.print("startElapsedTime=");
460         TimeUtils.formatDuration(mStartElapsedTime, nowElapsedTime, pw);
461         pw.println();
462         if (mPersistent || mRemoved) {
463             pw.print(prefix); pw.print("persistent="); pw.print(mPersistent);
464             pw.print(" removed="); pw.println(mRemoved);
465         }
466         if (mDebugging) {
467             pw.print(prefix); pw.print("mDebugging="); pw.println(mDebugging);
468         }
469         if (mPendingStart) {
470             pw.print(prefix); pw.print("pendingStart="); pw.println(mPendingStart);
471         }
472         pw.print(prefix); pw.print("startSeq="); pw.println(mStartSeq);
473         pw.print(prefix); pw.print("mountMode="); pw.println(
474                 DebugUtils.valueToString(Zygote.class, "MOUNT_EXTERNAL_", mMountMode));
475         if (mKilled || mKilledByAm || mWaitingToKill != null) {
476             pw.print(prefix); pw.print("killed="); pw.print(mKilled);
477             pw.print(" killedByAm="); pw.print(mKilledByAm);
478             pw.print(" waitingToKill="); pw.println(mWaitingToKill);
479         }
480         if (mIsolatedEntryPoint != null || mIsolatedEntryPointArgs != null) {
481             pw.print(prefix); pw.print("isolatedEntryPoint="); pw.println(mIsolatedEntryPoint);
482             pw.print(prefix); pw.print("isolatedEntryPointArgs=");
483             pw.println(Arrays.toString(mIsolatedEntryPointArgs));
484         }
485         if (mState.getSetProcState() > ActivityManager.PROCESS_STATE_SERVICE) {
486             mProfile.dumpCputime(pw, prefix);
487         }
488         mProfile.dumpPss(pw, prefix, nowUptime);
489         mState.dump(pw, prefix, nowUptime);
490         mErrorState.dump(pw, prefix, nowUptime);
491         mServices.dump(pw, prefix, nowUptime);
492         mProviders.dump(pw, prefix, nowUptime);
493         mReceivers.dump(pw, prefix, nowUptime);
494         mOptRecord.dump(pw, prefix, nowUptime);
495         mWindowProcessController.dump(pw, prefix);
496     }
497 
ProcessRecord(ActivityManagerService _service, ApplicationInfo _info, String _processName, int _uid)498     ProcessRecord(ActivityManagerService _service, ApplicationInfo _info, String _processName,
499             int _uid) {
500         this(_service, _info, _processName, _uid, null, -1, null);
501     }
502 
ProcessRecord(ActivityManagerService _service, ApplicationInfo _info, String _processName, int _uid, String _sdkSandboxClientAppPackage, int _definingUid, String _definingProcessName)503     ProcessRecord(ActivityManagerService _service, ApplicationInfo _info, String _processName,
504             int _uid, String _sdkSandboxClientAppPackage, int _definingUid,
505             String _definingProcessName) {
506         mService = _service;
507         mProcLock = _service.mProcLock;
508         info = _info;
509         ProcessInfo procInfo = null;
510         if (_service.mPackageManagerInt != null) {
511             if (_definingUid > 0) {
512                 ArrayMap<String, ProcessInfo> processes =
513                         _service.mPackageManagerInt.getProcessesForUid(_definingUid);
514                 if (processes != null) procInfo = processes.get(_definingProcessName);
515             } else {
516                 ArrayMap<String, ProcessInfo> processes =
517                         _service.mPackageManagerInt.getProcessesForUid(_uid);
518                 if (processes != null) procInfo = processes.get(_processName);
519             }
520             if (procInfo != null && procInfo.deniedPermissions == null
521                     && procInfo.gwpAsanMode == ApplicationInfo.GWP_ASAN_DEFAULT
522                     && procInfo.memtagMode == ApplicationInfo.MEMTAG_DEFAULT
523                     && procInfo.nativeHeapZeroInitialized == ApplicationInfo.ZEROINIT_DEFAULT) {
524                 // If this process hasn't asked for permissions to be denied, or for a
525                 // non-default GwpAsan mode, or any other non-default setting, then we don't
526                 // care about it.
527                 procInfo = null;
528             }
529         }
530         processInfo = procInfo;
531         isolated = Process.isIsolated(_uid);
532         isSdkSandbox = Process.isSdkSandboxUid(_uid);
533         appZygote = (UserHandle.getAppId(_uid) >= Process.FIRST_APP_ZYGOTE_ISOLATED_UID
534                 && UserHandle.getAppId(_uid) <= Process.LAST_APP_ZYGOTE_ISOLATED_UID);
535         uid = _uid;
536         userId = UserHandle.getUserId(_uid);
537         processName = _processName;
538         sdkSandboxClientAppPackage = _sdkSandboxClientAppPackage;
539         if (isSdkSandbox) {
540             sdkSandboxClientAppVolumeUuid = getClientInfoForSdkSandbox().volumeUuid;
541         } else {
542             sdkSandboxClientAppVolumeUuid = null;
543         }
544         mPersistent = false;
545         mRemoved = false;
546         mProfile = new ProcessProfileRecord(this);
547         mServices = new ProcessServiceRecord(this);
548         mProviders = new ProcessProviderRecord(this);
549         mReceivers = new ProcessReceiverRecord(this);
550         mErrorState = new ProcessErrorStateRecord(this);
551         mState = new ProcessStateRecord(this);
552         mOptRecord = new ProcessCachedOptimizerRecord(this);
553         final long now = SystemClock.uptimeMillis();
554         mProfile.init(now);
555         mOptRecord.init(now);
556         mState.init(now);
557         mWindowProcessController = new WindowProcessController(
558                 mService.mActivityTaskManager, info, processName, uid, userId, this, this);
559         mPkgList.put(_info.packageName, new ProcessStats.ProcessStateHolder(_info.longVersionCode));
560     }
561 
562     @GuardedBy(anyOf = {"mService", "mProcLock"})
getUidRecord()563     UidRecord getUidRecord() {
564         return mUidRecord;
565     }
566 
567     @GuardedBy({"mService", "mProcLock"})
setUidRecord(UidRecord uidRecord)568     void setUidRecord(UidRecord uidRecord) {
569         mUidRecord = uidRecord;
570     }
571 
getPkgList()572     PackageList getPkgList() {
573         return mPkgList;
574     }
575 
576     @GuardedBy(anyOf = {"mService", "mProcLock"})
getPkgDeps()577     ArraySet<String> getPkgDeps() {
578         return mPkgDeps;
579     }
580 
581     @GuardedBy({"mService", "mProcLock"})
setPkgDeps(ArraySet<String> pkgDeps)582     void setPkgDeps(ArraySet<String> pkgDeps) {
583         mPkgDeps = pkgDeps;
584     }
585 
586     @GuardedBy(anyOf = {"mService", "mProcLock"})
getPid()587     int getPid() {
588         return mPid;
589     }
590 
591     @GuardedBy({"mService", "mProcLock"})
setPid(int pid)592     void setPid(int pid) {
593         mPid = pid;
594         mWindowProcessController.setPid(pid);
595         mShortStringName = null;
596         mStringName = null;
597         synchronized (mProfile.mProfilerLock) {
598             mProfile.setPid(pid);
599         }
600     }
601 
602     @GuardedBy(anyOf = {"mService", "mProcLock"})
getThread()603     IApplicationThread getThread() {
604         return mThread;
605     }
606 
607     @GuardedBy({"mService", "mProcLock"})
makeActive(IApplicationThread thread, ProcessStatsService tracker)608     public void makeActive(IApplicationThread thread, ProcessStatsService tracker) {
609         mProfile.onProcessActive(thread, tracker);
610         mThread = thread;
611         mWindowProcessController.setThread(thread);
612     }
613 
614     @GuardedBy({"mService", "mProcLock"})
makeInactive(ProcessStatsService tracker)615     public void makeInactive(ProcessStatsService tracker) {
616         mThread = null;
617         mWindowProcessController.setThread(null);
618         mProfile.onProcessInactive(tracker);
619     }
620 
621     @GuardedBy("mService")
getDyingPid()622     int getDyingPid() {
623         return mDyingPid;
624     }
625 
626     @GuardedBy("mService")
setDyingPid(int dyingPid)627     void setDyingPid(int dyingPid) {
628         mDyingPid = dyingPid;
629     }
630 
631     @GuardedBy("mService")
getGids()632     int[] getGids() {
633         return mGids;
634     }
635 
636     @GuardedBy("mService")
setGids(int[] gids)637     void setGids(int[] gids) {
638         mGids = gids;
639     }
640 
641     @GuardedBy("mService")
getRequiredAbi()642     String getRequiredAbi() {
643         return mRequiredAbi;
644     }
645 
646     @GuardedBy("mService")
setRequiredAbi(String requiredAbi)647     void setRequiredAbi(String requiredAbi) {
648         mRequiredAbi = requiredAbi;
649         mWindowProcessController.setRequiredAbi(requiredAbi);
650     }
651 
652     @GuardedBy("mService")
getInstructionSet()653     String getInstructionSet() {
654         return mInstructionSet;
655     }
656 
657     @GuardedBy("mService")
setInstructionSet(String instructionSet)658     void setInstructionSet(String instructionSet) {
659         mInstructionSet = instructionSet;
660     }
661 
setPersistent(boolean persistent)662     void setPersistent(boolean persistent) {
663         mPersistent = persistent;
664         mWindowProcessController.setPersistent(persistent);
665     }
666 
isPersistent()667     boolean isPersistent() {
668         return mPersistent;
669     }
670 
671     @GuardedBy("mService")
isPendingStart()672     boolean isPendingStart() {
673         return mPendingStart;
674     }
675 
676     @GuardedBy("mService")
setPendingStart(boolean pendingStart)677     void setPendingStart(boolean pendingStart) {
678         mPendingStart = pendingStart;
679     }
680 
681     @GuardedBy("mService")
getStartSeq()682     long getStartSeq() {
683         return mStartSeq;
684     }
685 
686     @GuardedBy("mService")
setStartSeq(long startSeq)687     void setStartSeq(long startSeq) {
688         mStartSeq = startSeq;
689     }
690 
getHostingRecord()691     HostingRecord getHostingRecord() {
692         return mHostingRecord;
693     }
694 
setHostingRecord(HostingRecord hostingRecord)695     void setHostingRecord(HostingRecord hostingRecord) {
696         mHostingRecord = hostingRecord;
697     }
698 
getSeInfo()699     String getSeInfo() {
700         return mSeInfo;
701     }
702 
setSeInfo(String seInfo)703     void setSeInfo(String seInfo) {
704         mSeInfo = seInfo;
705     }
706 
getStartUptime()707     long getStartUptime() {
708         return mStartUptime;
709     }
710 
711     /**
712      * Same as {@link #getStartUptime()}.
713      * @deprecated use {@link #getStartUptime()} instead for clarity.
714      */
715     @Deprecated
getStartTime()716     long getStartTime() {
717         return mStartUptime;
718     }
719 
getStartElapsedTime()720     long getStartElapsedTime() {
721         return mStartElapsedTime;
722     }
723 
getStartUid()724     int getStartUid() {
725         return mStartUid;
726     }
727 
setStartUid(int startUid)728     void setStartUid(int startUid) {
729         mStartUid = startUid;
730     }
731 
getMountMode()732     int getMountMode() {
733         return mMountMode;
734     }
735 
setMountMode(int mountMode)736     void setMountMode(int mountMode) {
737         mMountMode = mountMode;
738     }
739 
isBindMountPending()740     boolean isBindMountPending() {
741         return mBindMountPending;
742     }
743 
setBindMountPending(boolean bindMountPending)744     void setBindMountPending(boolean bindMountPending) {
745         mBindMountPending = bindMountPending;
746     }
747 
748     @GuardedBy("mProcLock")
isUnlocked()749     boolean isUnlocked() {
750         return mUnlocked;
751     }
752 
753     @GuardedBy("mProcLock")
setUnlocked(boolean unlocked)754     void setUnlocked(boolean unlocked) {
755         mUnlocked = unlocked;
756     }
757 
758     @GuardedBy("mProcLock")
getRenderThreadTid()759     int getRenderThreadTid() {
760         return mRenderThreadTid;
761     }
762 
763     @GuardedBy("mProcLock")
setRenderThreadTid(int renderThreadTid)764     void setRenderThreadTid(int renderThreadTid) {
765         mRenderThreadTid = renderThreadTid;
766     }
767 
768     @GuardedBy("mService")
getCompat()769     CompatibilityInfo getCompat() {
770         return mCompat;
771     }
772 
773     @GuardedBy("mService")
setCompat(CompatibilityInfo compat)774     void setCompat(CompatibilityInfo compat) {
775         mCompat = compat;
776     }
777 
778     @GuardedBy("mService")
getDisabledCompatChanges()779     long[] getDisabledCompatChanges() {
780         return mDisabledCompatChanges;
781     }
782 
783     @GuardedBy("mService")
setDisabledCompatChanges(long[] disabledCompatChanges)784     void setDisabledCompatChanges(long[] disabledCompatChanges) {
785         mDisabledCompatChanges = disabledCompatChanges;
786     }
787 
788     @GuardedBy("mService")
unlinkDeathRecipient()789     void unlinkDeathRecipient() {
790         if (mDeathRecipient != null && mThread != null) {
791             mThread.asBinder().unlinkToDeath(mDeathRecipient, 0);
792         }
793         mDeathRecipient = null;
794     }
795 
796     @GuardedBy("mService")
setDeathRecipient(IBinder.DeathRecipient deathRecipient)797     void setDeathRecipient(IBinder.DeathRecipient deathRecipient) {
798         mDeathRecipient = deathRecipient;
799     }
800 
801     @GuardedBy("mService")
getDeathRecipient()802     IBinder.DeathRecipient getDeathRecipient() {
803         return mDeathRecipient;
804     }
805 
806     @GuardedBy({"mService", "mProcLock"})
setActiveInstrumentation(ActiveInstrumentation instr)807     void setActiveInstrumentation(ActiveInstrumentation instr) {
808         mInstr = instr;
809         boolean isInstrumenting = instr != null;
810         mWindowProcessController.setInstrumenting(
811                 isInstrumenting,
812                 isInstrumenting ? instr.mSourceUid : -1,
813                 isInstrumenting && instr.mHasBackgroundActivityStartsPermission);
814     }
815 
816     @GuardedBy(anyOf = {"mService", "mProcLock"})
getActiveInstrumentation()817     ActiveInstrumentation getActiveInstrumentation() {
818         return mInstr;
819     }
820 
821     @GuardedBy(anyOf = {"mService", "mProcLock"})
isKilledByAm()822     boolean isKilledByAm() {
823         return mKilledByAm;
824     }
825 
826     @GuardedBy({"mService", "mProcLock"})
setKilledByAm(boolean killedByAm)827     void setKilledByAm(boolean killedByAm) {
828         mKilledByAm = killedByAm;
829     }
830 
831     @GuardedBy(anyOf = {"mService", "mProcLock"})
isKilled()832     boolean isKilled() {
833         return mKilled;
834     }
835 
836     @GuardedBy({"mService", "mProcLock"})
setKilled(boolean killed)837     void setKilled(boolean killed) {
838         mKilled = killed;
839     }
840 
841     @GuardedBy(anyOf = {"mService", "mProcLock"})
getKillTime()842     long getKillTime() {
843         return mKillTime;
844     }
845 
846     @GuardedBy({"mService", "mProcLock"})
setKillTime(long killTime)847     void setKillTime(long killTime) {
848         mKillTime = killTime;
849     }
850 
851     @GuardedBy("mService")
getWaitingToKill()852     String getWaitingToKill() {
853         return mWaitingToKill;
854     }
855 
856     @GuardedBy("mService")
setWaitingToKill(String waitingToKill)857     void setWaitingToKill(String waitingToKill) {
858         mWaitingToKill = waitingToKill;
859     }
860 
861     @Override
isRemoved()862     public boolean isRemoved() {
863         return mRemoved;
864     }
865 
setRemoved(boolean removed)866     void setRemoved(boolean removed) {
867         mRemoved = removed;
868     }
869 
870     @GuardedBy("mService")
isDebugging()871     boolean isDebugging() {
872         return mDebugging;
873     }
874 
875     @Nullable
getClientInfoForSdkSandbox()876     public ApplicationInfo getClientInfoForSdkSandbox() {
877         if (!isSdkSandbox || sdkSandboxClientAppPackage == null) {
878             throw new IllegalStateException(
879                     "getClientInfoForSdkSandbox called for non-sandbox process"
880             );
881         }
882         PackageManagerInternal pm = mService.getPackageManagerInternal();
883         return pm.getApplicationInfo(
884                 sdkSandboxClientAppPackage, /* flags */0, Process.SYSTEM_UID, userId);
885     }
886 
isDebuggable()887     public boolean isDebuggable() {
888         if ((info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
889             return true;
890         }
891         if (isSdkSandbox) {
892             ApplicationInfo clientInfo = getClientInfoForSdkSandbox();
893             return clientInfo != null && (clientInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
894         }
895         return false;
896     }
897 
898     @GuardedBy("mService")
setDebugging(boolean debugging)899     void setDebugging(boolean debugging) {
900         mDebugging = debugging;
901         mWindowProcessController.setDebugging(debugging);
902     }
903 
904     @GuardedBy("mProcLock")
hasWaitedForDebugger()905     boolean hasWaitedForDebugger() {
906         return mWaitedForDebugger;
907     }
908 
909     @GuardedBy("mProcLock")
setWaitedForDebugger(boolean waitedForDebugger)910     void setWaitedForDebugger(boolean waitedForDebugger) {
911         mWaitedForDebugger = waitedForDebugger;
912     }
913 
914     @GuardedBy(anyOf = {"mService", "mProcLock"})
getLastActivityTime()915     long getLastActivityTime() {
916         return mLastActivityTime;
917     }
918 
919     @GuardedBy({"mService", "mProcLock"})
setLastActivityTime(long lastActivityTime)920     void setLastActivityTime(long lastActivityTime) {
921         mLastActivityTime = lastActivityTime;
922     }
923 
924     @GuardedBy("mService")
isUsingWrapper()925     boolean isUsingWrapper() {
926         return mUsingWrapper;
927     }
928 
929     @GuardedBy("mService")
setUsingWrapper(boolean usingWrapper)930     void setUsingWrapper(boolean usingWrapper) {
931         mUsingWrapper = usingWrapper;
932         mWindowProcessController.setUsingWrapper(usingWrapper);
933     }
934 
935     @GuardedBy("mService")
getLruSeq()936     int getLruSeq() {
937         return mLruSeq;
938     }
939 
940     @GuardedBy("mService")
setLruSeq(int lruSeq)941     void setLruSeq(int lruSeq) {
942         mLruSeq = lruSeq;
943     }
944 
945     @GuardedBy("mService")
getIsolatedEntryPoint()946     String getIsolatedEntryPoint() {
947         return mIsolatedEntryPoint;
948     }
949 
950     @GuardedBy("mService")
setIsolatedEntryPoint(String isolatedEntryPoint)951     void setIsolatedEntryPoint(String isolatedEntryPoint) {
952         mIsolatedEntryPoint = isolatedEntryPoint;
953     }
954 
955     @GuardedBy("mService")
getIsolatedEntryPointArgs()956     String[] getIsolatedEntryPointArgs() {
957         return mIsolatedEntryPointArgs;
958     }
959 
960     @GuardedBy("mService")
setIsolatedEntryPointArgs(String[] isolatedEntryPointArgs)961     void setIsolatedEntryPointArgs(String[] isolatedEntryPointArgs) {
962         mIsolatedEntryPointArgs = isolatedEntryPointArgs;
963     }
964 
965     @GuardedBy("mService")
isInFullBackup()966     boolean isInFullBackup() {
967         return mInFullBackup;
968     }
969 
970     @GuardedBy("mService")
setInFullBackup(boolean inFullBackup)971     void setInFullBackup(boolean inFullBackup) {
972         mInFullBackup = inFullBackup;
973     }
974 
975     @Override
isCached()976     public boolean isCached() {
977         return mState.isCached();
978     }
979 
hasActivities()980     boolean hasActivities() {
981         return mWindowProcessController.hasActivities();
982     }
983 
hasActivitiesOrRecentTasks()984     boolean hasActivitiesOrRecentTasks() {
985         return mWindowProcessController.hasActivitiesOrRecentTasks();
986     }
987 
hasRecentTasks()988     boolean hasRecentTasks() {
989         return mWindowProcessController.hasRecentTasks();
990     }
991 
992     @GuardedBy({"mService", "mProcLock"})
onCleanupApplicationRecordLSP(ProcessStatsService processStats, boolean allowRestart, boolean unlinkDeath)993     boolean onCleanupApplicationRecordLSP(ProcessStatsService processStats, boolean allowRestart,
994             boolean unlinkDeath) {
995         mErrorState.onCleanupApplicationRecordLSP();
996 
997         resetPackageList(processStats);
998         if (unlinkDeath) {
999             unlinkDeathRecipient();
1000         }
1001         makeInactive(processStats);
1002         setWaitingToKill(null);
1003 
1004         mState.onCleanupApplicationRecordLSP();
1005         mServices.onCleanupApplicationRecordLocked();
1006         mReceivers.onCleanupApplicationRecordLocked();
1007 
1008         return mProviders.onCleanupApplicationRecordLocked(allowRestart);
1009     }
1010 
1011     /**
1012      * This method returns true if any of the activities within the process record are interesting
1013      * to the user. See HistoryRecord.isInterestingToUserLocked()
1014      */
isInterestingToUserLocked()1015     public boolean isInterestingToUserLocked() {
1016         if (mWindowProcessController.isInterestingToUser()) {
1017             return true;
1018         }
1019 
1020         return mServices.hasForegroundServices();
1021     }
1022 
1023     /**
1024      * Let an app process throw an exception on a binder thread, which typically crashes the
1025      * process, unless it has an unhandled exception handler.
1026      *
1027      * See {@link ActivityThread#throwRemoteServiceException}.
1028      *
1029      * @param message exception message
1030      * @param exceptionTypeId ID defined in {@link android.app.RemoteServiceException} or one
1031      *                        of its subclasses.
1032      */
1033     @GuardedBy("mService")
scheduleCrashLocked(String message, int exceptionTypeId, @Nullable Bundle extras)1034     void scheduleCrashLocked(String message, int exceptionTypeId, @Nullable Bundle extras) {
1035         // Checking killedbyAm should keep it from showing the crash dialog if the process
1036         // was already dead for a good / normal reason.
1037         if (!mKilledByAm) {
1038             if (mThread != null) {
1039                 if (mPid == Process.myPid()) {
1040                     Slog.w(TAG, "scheduleCrash: trying to crash system process!");
1041                     return;
1042                 }
1043                 final long ident = Binder.clearCallingIdentity();
1044                 try {
1045                     mThread.scheduleCrash(message, exceptionTypeId, extras);
1046                 } catch (RemoteException e) {
1047                     // If it's already dead our work is done. If it's wedged just kill it.
1048                     // We won't get the crash dialog or the error reporting.
1049                     killLocked("scheduleCrash for '" + message + "' failed",
1050                             ApplicationExitInfo.REASON_CRASH, true);
1051                 } finally {
1052                     Binder.restoreCallingIdentity(ident);
1053                 }
1054             }
1055         }
1056     }
1057 
1058     @GuardedBy("mService")
killLocked(String reason, @Reason int reasonCode, boolean noisy)1059     void killLocked(String reason, @Reason int reasonCode, boolean noisy) {
1060         killLocked(reason, reasonCode, ApplicationExitInfo.SUBREASON_UNKNOWN, noisy);
1061     }
1062 
1063     @GuardedBy("mService")
killLocked(String reason, @Reason int reasonCode, @SubReason int subReason, boolean noisy)1064     void killLocked(String reason, @Reason int reasonCode, @SubReason int subReason,
1065             boolean noisy) {
1066         killLocked(reason, reason, reasonCode, subReason, noisy);
1067     }
1068 
1069     @GuardedBy("mService")
killLocked(String reason, String description, @Reason int reasonCode, @SubReason int subReason, boolean noisy)1070     void killLocked(String reason, String description, @Reason int reasonCode,
1071             @SubReason int subReason, boolean noisy) {
1072         if (!mKilledByAm) {
1073             Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "kill");
1074             if (reasonCode == ApplicationExitInfo.REASON_ANR
1075                     && mErrorState.getAnrAnnotation() != null) {
1076                 description = description + ": " + mErrorState.getAnrAnnotation();
1077             }
1078             if (mService != null && (noisy || info.uid == mService.mCurOomAdjUid)) {
1079                 mService.reportUidInfoMessageLocked(TAG,
1080                         "Killing " + toShortString() + " (adj " + mState.getSetAdj()
1081                         + "): " + reason, info.uid);
1082             }
1083             if (mPid > 0) {
1084                 mService.mProcessList.noteAppKill(this, reasonCode, subReason, description);
1085                 EventLog.writeEvent(EventLogTags.AM_KILL,
1086                         userId, mPid, processName, mState.getSetAdj(), reason);
1087                 Process.killProcessQuiet(mPid);
1088                 ProcessList.killProcessGroup(uid, mPid);
1089             } else {
1090                 mPendingStart = false;
1091             }
1092             if (!mPersistent) {
1093                 synchronized (mProcLock) {
1094                     mKilled = true;
1095                     mKilledByAm = true;
1096                     mKillTime = SystemClock.uptimeMillis();
1097                 }
1098             }
1099             Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
1100         }
1101     }
1102 
1103     @Override
dumpDebug(ProtoOutputStream proto, long fieldId)1104     public void dumpDebug(ProtoOutputStream proto, long fieldId) {
1105         dumpDebug(proto, fieldId, -1);
1106     }
1107 
dumpDebug(ProtoOutputStream proto, long fieldId, int lruIndex)1108     public void dumpDebug(ProtoOutputStream proto, long fieldId, int lruIndex) {
1109         long token = proto.start(fieldId);
1110         proto.write(ProcessRecordProto.PID, mPid);
1111         proto.write(ProcessRecordProto.PROCESS_NAME, processName);
1112         proto.write(ProcessRecordProto.UID, info.uid);
1113         if (UserHandle.getAppId(info.uid) >= Process.FIRST_APPLICATION_UID) {
1114             proto.write(ProcessRecordProto.USER_ID, userId);
1115             proto.write(ProcessRecordProto.APP_ID, UserHandle.getAppId(info.uid));
1116         }
1117         if (uid != info.uid) {
1118             proto.write(ProcessRecordProto.ISOLATED_APP_ID, UserHandle.getAppId(uid));
1119         }
1120         proto.write(ProcessRecordProto.PERSISTENT, mPersistent);
1121         if (lruIndex >= 0) {
1122             proto.write(ProcessRecordProto.LRU_INDEX, lruIndex);
1123         }
1124         proto.end(token);
1125     }
1126 
toShortString()1127     public String toShortString() {
1128         final String shortStringName = mShortStringName;
1129         if (shortStringName != null) {
1130             return shortStringName;
1131         }
1132         StringBuilder sb = new StringBuilder(128);
1133         toShortString(sb);
1134         return mShortStringName = sb.toString();
1135     }
1136 
toShortString(StringBuilder sb)1137     void toShortString(StringBuilder sb) {
1138         sb.append(mPid);
1139         sb.append(':');
1140         sb.append(processName);
1141         sb.append('/');
1142         if (info.uid < Process.FIRST_APPLICATION_UID) {
1143             sb.append(uid);
1144         } else {
1145             sb.append('u');
1146             sb.append(userId);
1147             int appId = UserHandle.getAppId(info.uid);
1148             if (appId >= Process.FIRST_APPLICATION_UID) {
1149                 sb.append('a');
1150                 sb.append(appId - Process.FIRST_APPLICATION_UID);
1151             } else {
1152                 sb.append('s');
1153                 sb.append(appId);
1154             }
1155             if (uid != info.uid) {
1156                 sb.append('i');
1157                 sb.append(UserHandle.getAppId(uid) - Process.FIRST_ISOLATED_UID);
1158             }
1159         }
1160     }
1161 
toString()1162     public String toString() {
1163         final String stringName = mStringName;
1164         if (stringName != null) {
1165             return stringName;
1166         }
1167         StringBuilder sb = new StringBuilder(128);
1168         sb.append("ProcessRecord{");
1169         sb.append(Integer.toHexString(System.identityHashCode(this)));
1170         sb.append(' ');
1171         toShortString(sb);
1172         sb.append('}');
1173         return mStringName = sb.toString();
1174     }
1175 
1176     /*
1177      *  Return true if package has been added false if not
1178      */
addPackage(String pkg, long versionCode, ProcessStatsService tracker)1179     public boolean addPackage(String pkg, long versionCode, ProcessStatsService tracker) {
1180         synchronized (tracker.mLock) {
1181             synchronized (mPkgList) {
1182                 if (!mPkgList.containsKey(pkg)) {
1183                     ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
1184                             versionCode);
1185                     final ProcessState baseProcessTracker = mProfile.getBaseProcessTracker();
1186                     if (baseProcessTracker != null) {
1187                         tracker.updateProcessStateHolderLocked(holder, pkg, info.uid, versionCode,
1188                                 processName);
1189                         mPkgList.put(pkg, holder);
1190                         if (holder.state != baseProcessTracker) {
1191                             holder.state.makeActive();
1192                         }
1193                     } else {
1194                         mPkgList.put(pkg, holder);
1195                     }
1196                     return true;
1197                 }
1198             }
1199         }
1200         return false;
1201     }
1202 
1203     /*
1204      *  Delete all packages from list except the package indicated in info
1205      */
resetPackageList(ProcessStatsService tracker)1206     public void resetPackageList(ProcessStatsService tracker) {
1207         synchronized (tracker.mLock) {
1208             final ProcessState baseProcessTracker = mProfile.getBaseProcessTracker();
1209             synchronized (mPkgList) {
1210                 final int numOfPkgs = mPkgList.size();
1211                 if (baseProcessTracker != null) {
1212                     long now = SystemClock.uptimeMillis();
1213                     baseProcessTracker.setState(ProcessStats.STATE_NOTHING,
1214                             tracker.getMemFactorLocked(), now, mPkgList.getPackageListLocked());
1215                     mPkgList.forEachPackage((pkgName, holder) ->
1216                             FrameworkStatsLog.write(FrameworkStatsLog.PROCESS_STATE_CHANGED,
1217                                 uid, processName, pkgName,
1218                                 ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING),
1219                                 holder.appVersion)
1220                     );
1221                     if (numOfPkgs != 1) {
1222                         mPkgList.forEachPackageProcessStats(holder -> {
1223                             if (holder.state != null && holder.state != baseProcessTracker) {
1224                                 holder.state.makeInactive();
1225                             }
1226                         });
1227                         mPkgList.clear();
1228                         ProcessStats.ProcessStateHolder holder =
1229                                 new ProcessStats.ProcessStateHolder(info.longVersionCode);
1230                         tracker.updateProcessStateHolderLocked(holder, info.packageName, info.uid,
1231                                 info.longVersionCode, processName);
1232                         mPkgList.put(info.packageName, holder);
1233                         if (holder.state != baseProcessTracker) {
1234                             holder.state.makeActive();
1235                         }
1236                     }
1237                 } else if (numOfPkgs != 1) {
1238                     mPkgList.clear();
1239                     mPkgList.put(info.packageName,
1240                             new ProcessStats.ProcessStateHolder(info.longVersionCode));
1241                 }
1242             }
1243         }
1244     }
1245 
getPackageList()1246     String[] getPackageList() {
1247         return mPkgList.getPackageList();
1248     }
1249 
getPackageListWithVersionCode()1250     List<VersionedPackage> getPackageListWithVersionCode() {
1251         return mPkgList.getPackageListWithVersionCode();
1252     }
1253 
getWindowProcessController()1254     WindowProcessController getWindowProcessController() {
1255         return mWindowProcessController;
1256     }
1257 
1258     /**
1259      * Allows background activity starts using token {@param entity}. Optionally, you can provide
1260      * {@param originatingToken} if you have one such originating token, this is useful for tracing
1261      * back the grant in the case of the notification token.
1262      */
addOrUpdateAllowBackgroundActivityStartsToken(Binder entity, @Nullable IBinder originatingToken)1263     void addOrUpdateAllowBackgroundActivityStartsToken(Binder entity,
1264             @Nullable IBinder originatingToken) {
1265         Objects.requireNonNull(entity);
1266         mWindowProcessController.addOrUpdateAllowBackgroundActivityStartsToken(entity,
1267                 originatingToken);
1268     }
1269 
removeAllowBackgroundActivityStartsToken(Binder entity)1270     void removeAllowBackgroundActivityStartsToken(Binder entity) {
1271         Objects.requireNonNull(entity);
1272         mWindowProcessController.removeAllowBackgroundActivityStartsToken(entity);
1273     }
1274 
1275     @Override
clearProfilerIfNeeded()1276     public void clearProfilerIfNeeded() {
1277         synchronized (mService.mAppProfiler.mProfilerLock) {
1278             mService.mAppProfiler.clearProfilerLPf();
1279         }
1280     }
1281 
1282     @Override
updateServiceConnectionActivities()1283     public void updateServiceConnectionActivities() {
1284         synchronized (mService) {
1285             mService.mServices.updateServiceConnectionActivitiesLocked(mServices);
1286         }
1287     }
1288 
1289     @Override
setPendingUiClean(boolean pendingUiClean)1290     public void setPendingUiClean(boolean pendingUiClean) {
1291         synchronized (mProcLock) {
1292             mProfile.setPendingUiClean(pendingUiClean);
1293         }
1294     }
1295 
1296     @Override
setPendingUiCleanAndForceProcessStateUpTo(int newState)1297     public void setPendingUiCleanAndForceProcessStateUpTo(int newState) {
1298         synchronized (mService) {
1299             setPendingUiClean(true);
1300             mState.forceProcessStateUpTo(newState);
1301         }
1302     }
1303 
1304     @Override
updateProcessInfo(boolean updateServiceConnectionActivities, boolean activityChange, boolean updateOomAdj)1305     public void updateProcessInfo(boolean updateServiceConnectionActivities, boolean activityChange,
1306             boolean updateOomAdj) {
1307         synchronized (mService) {
1308             if (updateServiceConnectionActivities) {
1309                 mService.mServices.updateServiceConnectionActivitiesLocked(mServices);
1310             }
1311             if (mThread == null) {
1312                 // Only update lru and oom-adj if the process is alive. Because it may be called
1313                 // when cleaning up the last activity from handling process died, the dead process
1314                 // should not be added to lru list again.
1315                 return;
1316             }
1317             mService.updateLruProcessLocked(this, activityChange, null /* client */);
1318             if (updateOomAdj) {
1319                 mService.updateOomAdjLocked(this, OomAdjuster.OOM_ADJ_REASON_ACTIVITY);
1320             }
1321         }
1322     }
1323 
1324     /**
1325      * Returns the total time (in milliseconds) spent executing in both user and system code.
1326      * Safe to call without lock held.
1327      */
1328     @Override
getCpuTime()1329     public long getCpuTime() {
1330         return mService.mAppProfiler.getCpuTimeForPid(mPid);
1331     }
1332 
1333     @Override
onStartActivity(int topProcessState, boolean setProfileProc, String packageName, long versionCode)1334     public void onStartActivity(int topProcessState, boolean setProfileProc, String packageName,
1335             long versionCode) {
1336         synchronized (mService) {
1337             mWaitingToKill = null;
1338             if (setProfileProc) {
1339                 synchronized (mService.mAppProfiler.mProfilerLock) {
1340                     mService.mAppProfiler.setProfileProcLPf(this);
1341                 }
1342             }
1343             if (packageName != null) {
1344                 addPackage(packageName, versionCode, mService.mProcessStats);
1345             }
1346 
1347             // Update oom adj first, we don't want the additional states are involved in this round.
1348             updateProcessInfo(false /* updateServiceConnectionActivities */,
1349                     true /* activityChange */, true /* updateOomAdj */);
1350             setPendingUiClean(true);
1351             mState.setHasShownUi(true);
1352             mState.forceProcessStateUpTo(topProcessState);
1353         }
1354     }
1355 
1356     @Override
appDied(String reason)1357     public void appDied(String reason) {
1358         synchronized (mService) {
1359             mService.appDiedLocked(this, reason);
1360         }
1361     }
1362 
1363     @Override
setRunningRemoteAnimation(boolean runningRemoteAnimation)1364     public void setRunningRemoteAnimation(boolean runningRemoteAnimation) {
1365         if (mPid == Process.myPid()) {
1366             Slog.wtf(TAG, "system can't run remote animation");
1367             return;
1368         }
1369         synchronized (mService) {
1370             mState.setRunningRemoteAnimation(runningRemoteAnimation);
1371         }
1372     }
1373 
getInputDispatchingTimeoutMillis()1374     public long getInputDispatchingTimeoutMillis() {
1375         return mWindowProcessController.getInputDispatchingTimeoutMillis();
1376     }
1377 
getProcessClassEnum()1378     public int getProcessClassEnum() {
1379         if (mPid == MY_PID) {
1380             return ServerProtoEnums.SYSTEM_SERVER;
1381         }
1382         if (info == null) {
1383             return ServerProtoEnums.ERROR_SOURCE_UNKNOWN;
1384         }
1385         return (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? ServerProtoEnums.SYSTEM_APP :
1386             ServerProtoEnums.DATA_APP;
1387     }
1388 
1389     /** Non-private access is for tests only. */
1390     @VisibleForTesting
getLruProcessList()1391     List<ProcessRecord> getLruProcessList() {
1392         return mService.mProcessList.getLruProcessesLOSP();
1393     }
1394 }
1395