1 /*
2  * Copyright (C) 2020 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 android.app.ActivityManager.PROCESS_CAPABILITY_NONE;
20 import static android.app.ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
21 import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
22 
23 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_OOM_ADJ;
24 import static com.android.server.am.OomAdjuster.CachedCompatChangeId;
25 import static com.android.server.am.ProcessRecord.TAG;
26 
27 import android.annotation.ElapsedRealtimeLong;
28 import android.app.ActivityManager;
29 import android.content.ComponentName;
30 import android.os.SystemClock;
31 import android.util.ArraySet;
32 import android.util.Slog;
33 import android.util.TimeUtils;
34 
35 import com.android.internal.annotations.CompositeRWLock;
36 import com.android.internal.annotations.GuardedBy;
37 import com.android.internal.util.FrameworkStatsLog;
38 
39 import java.io.PrintWriter;
40 
41 /**
42  * The state info of the process, including proc state, oom adj score, et al.
43  */
44 final class ProcessStateRecord {
45     private final ProcessRecord mApp;
46     private final ActivityManagerService mService;
47     private final ActivityManagerGlobalLock mProcLock;
48 
49     /**
50      * Maximum OOM adjustment for this process.
51      */
52     @GuardedBy("mService")
53     private int mMaxAdj = ProcessList.UNKNOWN_ADJ;
54 
55     /**
56      *  Current OOM unlimited adjustment for this process.
57      */
58     @CompositeRWLock({"mService", "mProcLock"})
59     private int mCurRawAdj = ProcessList.INVALID_ADJ;
60 
61     /**
62      * Last set OOM unlimited adjustment for this process.
63      */
64     @CompositeRWLock({"mService", "mProcLock"})
65     private int mSetRawAdj = ProcessList.INVALID_ADJ;
66 
67     /**
68      * Current OOM adjustment for this process.
69      */
70     @CompositeRWLock({"mService", "mProcLock"})
71     private int mCurAdj = ProcessList.INVALID_ADJ;
72 
73     /**
74      * Last set OOM adjustment for this process.
75      */
76     @CompositeRWLock({"mService", "mProcLock"})
77     private int mSetAdj = ProcessList.INVALID_ADJ;
78 
79     /**
80      * The last adjustment that was verified as actually being set.
81      */
82     @GuardedBy("mService")
83     private int mVerifiedAdj = ProcessList.INVALID_ADJ;
84 
85     /**
86      * Current capability flags of this process.
87      * For example, PROCESS_CAPABILITY_FOREGROUND_LOCATION is one capability.
88      */
89     @CompositeRWLock({"mService", "mProcLock"})
90     private int mCurCapability = PROCESS_CAPABILITY_NONE;
91 
92     /**
93      * Last set capability flags.
94      */
95     @CompositeRWLock({"mService", "mProcLock"})
96     private int mSetCapability = PROCESS_CAPABILITY_NONE;
97 
98     /**
99      * Currently desired scheduling class.
100      */
101     @CompositeRWLock({"mService", "mProcLock"})
102     private int mCurSchedGroup = ProcessList.SCHED_GROUP_BACKGROUND;
103 
104     /**
105      * Last set to background scheduling class.
106      */
107     @CompositeRWLock({"mService", "mProcLock"})
108     private int mSetSchedGroup = ProcessList.SCHED_GROUP_BACKGROUND;
109 
110     /**
111      * Currently computed process state.
112      */
113     @CompositeRWLock({"mService", "mProcLock"})
114     private int mCurProcState = PROCESS_STATE_NONEXISTENT;
115 
116     /**
117      * Last reported process state.
118      */
119     @CompositeRWLock({"mService", "mProcLock"})
120     private int mRepProcState = PROCESS_STATE_NONEXISTENT;
121 
122     /**
123      * Temp state during computation.
124      */
125     @CompositeRWLock({"mService", "mProcLock"})
126     private int mCurRawProcState = PROCESS_STATE_NONEXISTENT;
127 
128     /**
129      * Last set process state in process tracker.
130      */
131     @CompositeRWLock({"mService", "mProcLock"})
132     private int mSetProcState = PROCESS_STATE_NONEXISTENT;
133 
134     /**
135      * Last time mSetProcState changed.
136      */
137     @CompositeRWLock({"mService", "mProcLock"})
138     private long mLastStateTime;
139 
140     /**
141      * Previous priority value if we're switching to non-SCHED_OTHER.
142      */
143     @CompositeRWLock({"mService", "mProcLock"})
144     private int mSavedPriority;
145 
146     /**
147      * Process currently is on the service B list.
148      */
149     @CompositeRWLock({"mService", "mProcLock"})
150     private boolean mServiceB;
151 
152     /**
153      * We are forcing to service B list due to its RAM use.
154      */
155     @CompositeRWLock({"mService", "mProcLock"})
156     private boolean mServiceHighRam;
157 
158     /**
159      * Has this process not been in a cached state since last idle?
160      */
161     @GuardedBy("mProcLock")
162     private boolean mNotCachedSinceIdle;
163 
164     /**
165      * Are there any started services running in this process?
166      */
167     @CompositeRWLock({"mService", "mProcLock"})
168     private boolean mHasStartedServices;
169 
170     /**
171      * Running any activities that are foreground?
172      */
173     @CompositeRWLock({"mService", "mProcLock"})
174     private boolean mHasForegroundActivities;
175 
176     /**
177      * Last reported foreground activities.
178      */
179     @CompositeRWLock({"mService", "mProcLock"})
180     private boolean mRepForegroundActivities;
181 
182     /**
183      * Has UI been shown in this process since it was started?
184      */
185     @GuardedBy("mService")
186     private boolean mHasShownUi;
187 
188     /**
189      * Is this process currently showing a non-activity UI that the user
190      * is interacting with? E.g. The status bar when it is expanded, but
191      * not when it is minimized. When true the
192      * process will be set to use the ProcessList#SCHED_GROUP_TOP_APP
193      * scheduling group to boost performance.
194      */
195     @GuardedBy("mService")
196     private boolean mHasTopUi;
197 
198     /**
199      * Is the process currently showing a non-activity UI that
200      * overlays on-top of activity UIs on screen. E.g. display a window
201      * of type android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY
202      * When true the process will oom adj score will be set to
203      * ProcessList#PERCEPTIBLE_APP_ADJ at minimum to reduce the chance
204      * of the process getting killed.
205      */
206     @GuardedBy("mService")
207     private boolean mHasOverlayUi;
208 
209     /**
210      * Is the process currently running a RemoteAnimation? When true
211      * the process will be set to use the
212      * ProcessList#SCHED_GROUP_TOP_APP scheduling group to boost
213      * performance, as well as oom adj score will be set to
214      * ProcessList#VISIBLE_APP_ADJ at minimum to reduce the chance
215      * of the process getting killed.
216      */
217     @GuardedBy("mService")
218     private boolean mRunningRemoteAnimation;
219 
220     /**
221      * Keep track of whether we changed 'mSetAdj'.
222      */
223     @CompositeRWLock({"mService", "mProcLock"})
224     private boolean mProcStateChanged;
225 
226     /**
227      * Whether we have told usage stats about it being an interaction.
228      */
229     @CompositeRWLock({"mService", "mProcLock"})
230     private boolean mReportedInteraction;
231 
232     /**
233      * The time we sent the last interaction event.
234      */
235     @CompositeRWLock({"mService", "mProcLock"})
236     private long mInteractionEventTime;
237 
238     /**
239      * When we became foreground for interaction purposes.
240      */
241     @CompositeRWLock({"mService", "mProcLock"})
242     private long mFgInteractionTime;
243 
244     /**
245      * Token that is forcing this process to be important.
246      */
247     @GuardedBy("mService")
248     private Object mForcingToImportant;
249 
250     /**
251      * Sequence id for identifying oom_adj assignment cycles.
252      */
253     @GuardedBy("mService")
254     private int mAdjSeq;
255 
256     /**
257      * Sequence id for identifying oom_adj assignment cycles.
258      */
259     @GuardedBy("mService")
260     private int mCompletedAdjSeq;
261 
262     /**
263      * Whether this app has encountered a cycle in the most recent update.
264      */
265     @GuardedBy("mService")
266     private boolean mContainsCycle;
267 
268     /**
269      * When (uptime) the process last became unimportant.
270      */
271     @CompositeRWLock({"mService", "mProcLock"})
272     private long mWhenUnimportant;
273 
274     /**
275      * The last time the process was in the TOP state or greater.
276      */
277     @GuardedBy("mService")
278     private long mLastTopTime;
279 
280     /**
281      * Is this an empty background process?
282      */
283     @GuardedBy("mService")
284     private boolean mEmpty;
285 
286     /**
287      * Is this a cached process?
288      */
289     @GuardedBy("mService")
290     private boolean mCached;
291 
292     /**
293      * This is a system process, but not currently showing UI.
294      */
295     @GuardedBy("mService")
296     private boolean mSystemNoUi;
297 
298     /**
299      * If the proc state is PROCESS_STATE_BOUND_FOREGROUND_SERVICE or above, it can start FGS.
300      * It must obtain the proc state from a persistent/top process or FGS, not transitive.
301      */
302     @GuardedBy("mService")
303     private int mAllowStartFgsState = PROCESS_STATE_NONEXISTENT;
304 
305     /**
306      * Debugging: primary thing impacting oom_adj.
307      */
308     @GuardedBy("mService")
309     private String mAdjType;
310 
311     /**
312      * Debugging: adj code to report to app.
313      */
314     @CompositeRWLock({"mService", "mProcLock"})
315     private int mAdjTypeCode;
316 
317     /**
318      * Debugging: option dependent object.
319      */
320     @CompositeRWLock({"mService", "mProcLock"})
321     private Object mAdjSource;
322 
323     /**
324      * Debugging: proc state of mAdjSource's process.
325      */
326     @CompositeRWLock({"mService", "mProcLock"})
327     private int mAdjSourceProcState;
328 
329     /**
330      * Debugging: target component impacting oom_adj.
331      */
332     @CompositeRWLock({"mService", "mProcLock"})
333     private Object mAdjTarget;
334 
335     /**
336      * Approximates the usage count of the app, used for cache re-ranking by CacheOomRanker.
337      *
338      * Counts the number of times the process is re-added to the cache (i.e. setCached(false);
339      * setCached(true)). This over counts, as setCached is sometimes reset while remaining in the
340      * cache. However, this happens uniformly across processes, so ranking is not affected.
341      */
342     @GuardedBy("mService")
343     private int mCacheOomRankerUseCount;
344 
345     /**
346      * Process memory usage (RSS).
347      *
348      * Periodically populated by {@code CacheOomRanker}, stored in this object to cache the values.
349      */
350     @GuardedBy("mService")
351     private long mCacheOomRankerRss;
352 
353     /**
354      * The last time, in milliseconds since boot, since {@link #mCacheOomRankerRss} was updated.
355      */
356     @GuardedBy("mService")
357     private long mCacheOomRankerRssTimeMs;
358 
359     /**
360      * Whether or not this process is reachable from given process.
361      */
362     @GuardedBy("mService")
363     private boolean mReachable;
364 
365     /**
366      * The most recent time when the last visible activity within this process became invisible.
367      *
368      * <p> It'll be set to 0 if there is never a visible activity, or Long.MAX_VALUE if there is
369      * any visible activities within this process at this moment.</p>
370      */
371     @GuardedBy("mService")
372     @ElapsedRealtimeLong
373     private long mLastInvisibleTime;
374 
375     // Below are the cached task info for OomAdjuster only
376     private static final int VALUE_INVALID = -1;
377     private static final int VALUE_FALSE = 0;
378     private static final int VALUE_TRUE = 1;
379 
380     @GuardedBy("mService")
381     private int mCachedHasActivities = VALUE_INVALID;
382     @GuardedBy("mService")
383     private int mCachedIsHeavyWeight = VALUE_INVALID;
384     @GuardedBy("mService")
385     private int mCachedHasVisibleActivities = VALUE_INVALID;
386     @GuardedBy("mService")
387     private int mCachedIsHomeProcess = VALUE_INVALID;
388     @GuardedBy("mService")
389     private int mCachedIsPreviousProcess = VALUE_INVALID;
390     @GuardedBy("mService")
391     private int mCachedHasRecentTasks = VALUE_INVALID;
392     @GuardedBy("mService")
393     private int mCachedIsReceivingBroadcast = VALUE_INVALID;
394 
395     /**
396      * Cache the return value of PlatformCompat.isChangeEnabled().
397      */
398     @GuardedBy("mService")
399     private int[] mCachedCompatChanges = new int[] {
400         VALUE_INVALID, // CACHED_COMPAT_CHANGE_PROCESS_CAPABILITY
401         VALUE_INVALID, // CACHED_COMPAT_CHANGE_CAMERA_MICROPHONE_CAPABILITY
402         VALUE_INVALID, // CACHED_COMPAT_CHANGE_USE_SHORT_FGS_USAGE_INTERACTION_TIME
403     };
404 
405     @GuardedBy("mService")
406     private int mCachedAdj = ProcessList.INVALID_ADJ;
407     @GuardedBy("mService")
408     private boolean mCachedForegroundActivities = false;
409     @GuardedBy("mService")
410     private int mCachedProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
411     @GuardedBy("mService")
412     private int mCachedSchedGroup = ProcessList.SCHED_GROUP_BACKGROUND;
413 
ProcessStateRecord(ProcessRecord app)414     ProcessStateRecord(ProcessRecord app) {
415         mApp = app;
416         mService = app.mService;
417         mProcLock = mService.mProcLock;
418     }
419 
init(long now)420     void init(long now) {
421         mLastStateTime = now;
422     }
423 
424     @GuardedBy("mService")
setMaxAdj(int maxAdj)425     void setMaxAdj(int maxAdj) {
426         mMaxAdj = maxAdj;
427     }
428 
429     @GuardedBy("mService")
getMaxAdj()430     int getMaxAdj() {
431         return mMaxAdj;
432     }
433 
434     @GuardedBy({"mService", "mProcLock"})
setCurRawAdj(int curRawAdj)435     void setCurRawAdj(int curRawAdj) {
436         mCurRawAdj = curRawAdj;
437         mApp.getWindowProcessController().setPerceptible(
438                 curRawAdj <= ProcessList.PERCEPTIBLE_APP_ADJ);
439     }
440 
441     @GuardedBy(anyOf = {"mService", "mProcLock"})
getCurRawAdj()442     int getCurRawAdj() {
443         return mCurRawAdj;
444     }
445 
446     @GuardedBy({"mService", "mProcLock"})
setSetRawAdj(int setRawAdj)447     void setSetRawAdj(int setRawAdj) {
448         mSetRawAdj = setRawAdj;
449     }
450 
451     @GuardedBy(anyOf = {"mService", "mProcLock"})
getSetRawAdj()452     int getSetRawAdj() {
453         return mSetRawAdj;
454     }
455 
456     @GuardedBy({"mService", "mProcLock"})
setCurAdj(int curAdj)457     void setCurAdj(int curAdj) {
458         mCurAdj = curAdj;
459     }
460 
461     @GuardedBy(anyOf = {"mService", "mProcLock"})
getCurAdj()462     int getCurAdj() {
463         return mCurAdj;
464     }
465 
466     @GuardedBy({"mService", "mProcLock"})
setSetAdj(int setAdj)467     void setSetAdj(int setAdj) {
468         mSetAdj = setAdj;
469     }
470 
471     @GuardedBy(anyOf = {"mService", "mProcLock"})
getSetAdj()472     int getSetAdj() {
473         return mSetAdj;
474     }
475 
476     @GuardedBy(anyOf = {"mService", "mProcLock"})
getSetAdjWithServices()477     int getSetAdjWithServices() {
478         if (mSetAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
479             if (mHasStartedServices) {
480                 return ProcessList.SERVICE_B_ADJ;
481             }
482         }
483         return mSetAdj;
484     }
485 
486     @GuardedBy("mService")
setVerifiedAdj(int verifiedAdj)487     void setVerifiedAdj(int verifiedAdj) {
488         mVerifiedAdj = verifiedAdj;
489     }
490 
491     @GuardedBy("mService")
getVerifiedAdj()492     int getVerifiedAdj() {
493         return mVerifiedAdj;
494     }
495 
496     @GuardedBy({"mService", "mProcLock"})
setCurCapability(int curCapability)497     void setCurCapability(int curCapability) {
498         mCurCapability = curCapability;
499     }
500 
501     @GuardedBy(anyOf = {"mService", "mProcLock"})
getCurCapability()502     int getCurCapability() {
503         return mCurCapability;
504     }
505 
506     @GuardedBy({"mService", "mProcLock"})
setSetCapability(int setCapability)507     void setSetCapability(int setCapability) {
508         mSetCapability = setCapability;
509     }
510 
511     @GuardedBy(anyOf = {"mService", "mProcLock"})
getSetCapability()512     int getSetCapability() {
513         return mSetCapability;
514     }
515 
516     @GuardedBy({"mService", "mProcLock"})
setCurrentSchedulingGroup(int curSchedGroup)517     void setCurrentSchedulingGroup(int curSchedGroup) {
518         mCurSchedGroup = curSchedGroup;
519         mApp.getWindowProcessController().setCurrentSchedulingGroup(curSchedGroup);
520     }
521 
522     @GuardedBy(anyOf = {"mService", "mProcLock"})
getCurrentSchedulingGroup()523     int getCurrentSchedulingGroup() {
524         return mCurSchedGroup;
525     }
526 
527     @GuardedBy({"mService", "mProcLock"})
setSetSchedGroup(int setSchedGroup)528     void setSetSchedGroup(int setSchedGroup) {
529         mSetSchedGroup = setSchedGroup;
530     }
531 
532     @GuardedBy(anyOf = {"mService", "mProcLock"})
getSetSchedGroup()533     int getSetSchedGroup() {
534         return mSetSchedGroup;
535     }
536 
537     @GuardedBy({"mService", "mProcLock"})
setCurProcState(int curProcState)538     void setCurProcState(int curProcState) {
539         mCurProcState = curProcState;
540         mApp.getWindowProcessController().setCurrentProcState(mCurProcState);
541     }
542 
543     @GuardedBy(anyOf = {"mService", "mProcLock"})
getCurProcState()544     int getCurProcState() {
545         return mCurProcState;
546     }
547 
548     @GuardedBy({"mService", "mProcLock"})
setCurRawProcState(int curRawProcState)549     void setCurRawProcState(int curRawProcState) {
550         mCurRawProcState = curRawProcState;
551     }
552 
553     @GuardedBy(anyOf = {"mService", "mProcLock"})
getCurRawProcState()554     int getCurRawProcState() {
555         return mCurRawProcState;
556     }
557 
558     @GuardedBy({"mService", "mProcLock"})
setReportedProcState(int repProcState)559     void setReportedProcState(int repProcState) {
560         mRepProcState = repProcState;
561         mApp.getPkgList().forEachPackage((pkgName, holder) ->
562                 FrameworkStatsLog.write(FrameworkStatsLog.PROCESS_STATE_CHANGED,
563                     mApp.uid, mApp.processName, pkgName,
564                     ActivityManager.processStateAmToProto(mRepProcState),
565                     holder.appVersion)
566         );
567         mApp.getWindowProcessController().setReportedProcState(repProcState);
568     }
569 
570     @GuardedBy(anyOf = {"mService", "mProcLock"})
getReportedProcState()571     int getReportedProcState() {
572         return mRepProcState;
573     }
574 
575     @GuardedBy("mService")
forceProcessStateUpTo(int newState)576     void forceProcessStateUpTo(int newState) {
577         if (mRepProcState > newState) {
578             synchronized (mProcLock) {
579                 mRepProcState = newState;
580                 setCurProcState(newState);
581                 setCurRawProcState(newState);
582                 mApp.getPkgList().forEachPackage((pkgName, holder) ->
583                         FrameworkStatsLog.write(FrameworkStatsLog.PROCESS_STATE_CHANGED,
584                             mApp.uid, mApp.processName, pkgName,
585                             ActivityManager.processStateAmToProto(mRepProcState),
586                             holder.appVersion)
587                 );
588             }
589         }
590     }
591 
592     @GuardedBy({"mService", "mProcLock"})
setSetProcState(int setProcState)593     void setSetProcState(int setProcState) {
594         if (ActivityManager.isProcStateCached(mSetProcState)
595                 && !ActivityManager.isProcStateCached(setProcState)) {
596             mCacheOomRankerUseCount++;
597         }
598         mSetProcState = setProcState;
599     }
600 
601     @GuardedBy(anyOf = {"mService", "mProcLock"})
getSetProcState()602     int getSetProcState() {
603         return mSetProcState;
604     }
605 
606     @GuardedBy({"mService", "mProcLock"})
setLastStateTime(long lastStateTime)607     void setLastStateTime(long lastStateTime) {
608         mLastStateTime = lastStateTime;
609     }
610 
611     @GuardedBy(anyOf = {"mService", "mProcLock"})
getLastStateTime()612     long getLastStateTime() {
613         return mLastStateTime;
614     }
615 
616     @GuardedBy({"mService", "mProcLock"})
setSavedPriority(int savedPriority)617     void setSavedPriority(int savedPriority) {
618         mSavedPriority = savedPriority;
619     }
620 
621     @GuardedBy(anyOf = {"mService", "mProcLock"})
getSavedPriority()622     int getSavedPriority() {
623         return mSavedPriority;
624     }
625 
626     @GuardedBy({"mService", "mProcLock"})
setServiceB(boolean serviceb)627     void setServiceB(boolean serviceb) {
628         mServiceB = serviceb;
629     }
630 
631     @GuardedBy(anyOf = {"mService", "mProcLock"})
isServiceB()632     boolean isServiceB() {
633         return mServiceB;
634     }
635 
636     @GuardedBy({"mService", "mProcLock"})
setServiceHighRam(boolean serviceHighRam)637     void setServiceHighRam(boolean serviceHighRam) {
638         mServiceHighRam = serviceHighRam;
639     }
640 
641     @GuardedBy(anyOf = {"mService", "mProcLock"})
isServiceHighRam()642     boolean isServiceHighRam() {
643         return mServiceHighRam;
644     }
645 
646     @GuardedBy("mProcLock")
setNotCachedSinceIdle(boolean notCachedSinceIdle)647     void setNotCachedSinceIdle(boolean notCachedSinceIdle) {
648         mNotCachedSinceIdle = notCachedSinceIdle;
649     }
650 
651     @GuardedBy("mProcLock")
isNotCachedSinceIdle()652     boolean isNotCachedSinceIdle() {
653         return mNotCachedSinceIdle;
654     }
655 
656     @GuardedBy("mProcLock")
setHasStartedServices(boolean hasStartedServices)657     void setHasStartedServices(boolean hasStartedServices) {
658         mHasStartedServices = hasStartedServices;
659     }
660 
661     @GuardedBy("mProcLock")
hasStartedServices()662     boolean hasStartedServices() {
663         return mHasStartedServices;
664     }
665 
666     @GuardedBy({"mService", "mProcLock"})
setHasForegroundActivities(boolean hasForegroundActivities)667     void setHasForegroundActivities(boolean hasForegroundActivities) {
668         mHasForegroundActivities = hasForegroundActivities;
669     }
670 
671     @GuardedBy(anyOf = {"mService", "mProcLock"})
hasForegroundActivities()672     boolean hasForegroundActivities() {
673         return mHasForegroundActivities;
674     }
675 
676     @GuardedBy({"mService", "mProcLock"})
setRepForegroundActivities(boolean repForegroundActivities)677     void setRepForegroundActivities(boolean repForegroundActivities) {
678         mRepForegroundActivities = repForegroundActivities;
679     }
680 
681     @GuardedBy(anyOf = {"mService", "mProcLock"})
hasRepForegroundActivities()682     boolean hasRepForegroundActivities() {
683         return mRepForegroundActivities;
684     }
685 
686     @GuardedBy("mService")
setHasShownUi(boolean hasShownUi)687     void setHasShownUi(boolean hasShownUi) {
688         mHasShownUi = hasShownUi;
689     }
690 
691     @GuardedBy("mService")
hasShownUi()692     boolean hasShownUi() {
693         return mHasShownUi;
694     }
695 
696     @GuardedBy("mService")
setHasTopUi(boolean hasTopUi)697     void setHasTopUi(boolean hasTopUi) {
698         mHasTopUi = hasTopUi;
699         mApp.getWindowProcessController().setHasTopUi(hasTopUi);
700     }
701 
702     @GuardedBy("mService")
hasTopUi()703     boolean hasTopUi() {
704         return mHasTopUi;
705     }
706 
707     @GuardedBy("mService")
setHasOverlayUi(boolean hasOverlayUi)708     void setHasOverlayUi(boolean hasOverlayUi) {
709         mHasOverlayUi = hasOverlayUi;
710         mApp.getWindowProcessController().setHasOverlayUi(hasOverlayUi);
711     }
712 
713     @GuardedBy("mService")
hasOverlayUi()714     boolean hasOverlayUi() {
715         return mHasOverlayUi;
716     }
717 
718     @GuardedBy("mService")
isRunningRemoteAnimation()719     boolean isRunningRemoteAnimation() {
720         return mRunningRemoteAnimation;
721     }
722 
723     @GuardedBy("mService")
setRunningRemoteAnimation(boolean runningRemoteAnimation)724     void setRunningRemoteAnimation(boolean runningRemoteAnimation) {
725         if (mRunningRemoteAnimation == runningRemoteAnimation) {
726             return;
727         }
728         mRunningRemoteAnimation = runningRemoteAnimation;
729         if (DEBUG_OOM_ADJ) {
730             Slog.i(TAG, "Setting runningRemoteAnimation=" + runningRemoteAnimation
731                     + " for pid=" + mApp.getPid());
732         }
733         mService.updateOomAdjLocked(mApp, OomAdjuster.OOM_ADJ_REASON_UI_VISIBILITY);
734     }
735 
736     @GuardedBy({"mService", "mProcLock"})
setProcStateChanged(boolean procStateChanged)737     void setProcStateChanged(boolean procStateChanged) {
738         mProcStateChanged = procStateChanged;
739     }
740 
741     @GuardedBy(anyOf = {"mService", "mProcLock"})
hasProcStateChanged()742     boolean hasProcStateChanged() {
743         return mProcStateChanged;
744     }
745 
746     @GuardedBy({"mService", "mProcLock"})
setReportedInteraction(boolean reportedInteraction)747     void setReportedInteraction(boolean reportedInteraction) {
748         mReportedInteraction = reportedInteraction;
749     }
750 
751     @GuardedBy(anyOf = {"mService", "mProcLock"})
hasReportedInteraction()752     boolean hasReportedInteraction() {
753         return mReportedInteraction;
754     }
755 
756     @GuardedBy({"mService", "mProcLock"})
setInteractionEventTime(long interactionEventTime)757     void setInteractionEventTime(long interactionEventTime) {
758         mInteractionEventTime = interactionEventTime;
759         mApp.getWindowProcessController().setInteractionEventTime(interactionEventTime);
760     }
761 
762     @GuardedBy(anyOf = {"mService", "mProcLock"})
getInteractionEventTime()763     long getInteractionEventTime() {
764         return mInteractionEventTime;
765     }
766 
767     @GuardedBy({"mService", "mProcLock"})
setFgInteractionTime(long fgInteractionTime)768     void setFgInteractionTime(long fgInteractionTime) {
769         mFgInteractionTime = fgInteractionTime;
770         mApp.getWindowProcessController().setFgInteractionTime(fgInteractionTime);
771     }
772 
773     @GuardedBy(anyOf = {"mService", "mProcLock"})
getFgInteractionTime()774     long getFgInteractionTime() {
775         return mFgInteractionTime;
776     }
777 
778     @GuardedBy("mService")
setForcingToImportant(Object forcingToImportant)779     void setForcingToImportant(Object forcingToImportant) {
780         mForcingToImportant = forcingToImportant;
781     }
782 
783     @GuardedBy("mService")
getForcingToImportant()784     Object getForcingToImportant() {
785         return mForcingToImportant;
786     }
787 
788     @GuardedBy("mService")
setAdjSeq(int adjSeq)789     void setAdjSeq(int adjSeq) {
790         mAdjSeq = adjSeq;
791     }
792 
793     @GuardedBy("mService")
decAdjSeq()794     void decAdjSeq() {
795         mAdjSeq--;
796     }
797 
798     @GuardedBy("mService")
getAdjSeq()799     int getAdjSeq() {
800         return mAdjSeq;
801     }
802 
803     @GuardedBy("mService")
setCompletedAdjSeq(int completedAdjSeq)804     void setCompletedAdjSeq(int completedAdjSeq) {
805         mCompletedAdjSeq = completedAdjSeq;
806     }
807 
808     @GuardedBy("mService")
decCompletedAdjSeq()809     void decCompletedAdjSeq() {
810         mCompletedAdjSeq--;
811     }
812 
813     @GuardedBy("mService")
getCompletedAdjSeq()814     int getCompletedAdjSeq() {
815         return mCompletedAdjSeq;
816     }
817 
818     @GuardedBy("mService")
setContainsCycle(boolean containsCycle)819     void setContainsCycle(boolean containsCycle) {
820         mContainsCycle = containsCycle;
821     }
822 
823     @GuardedBy("mService")
containsCycle()824     boolean containsCycle() {
825         return mContainsCycle;
826     }
827 
828     @GuardedBy({"mService", "mProcLock"})
setWhenUnimportant(long whenUnimportant)829     void setWhenUnimportant(long whenUnimportant) {
830         mWhenUnimportant = whenUnimportant;
831         mApp.getWindowProcessController().setWhenUnimportant(whenUnimportant);
832     }
833 
834     @GuardedBy(anyOf = {"mService", "mProcLock"})
getWhenUnimportant()835     long getWhenUnimportant() {
836         return mWhenUnimportant;
837     }
838 
839     @GuardedBy("mService")
setLastTopTime(long lastTopTime)840     void setLastTopTime(long lastTopTime) {
841         mLastTopTime = lastTopTime;
842     }
843 
844     @GuardedBy("mService")
getLastTopTime()845     long getLastTopTime() {
846         return mLastTopTime;
847     }
848 
849     @GuardedBy("mService")
setEmpty(boolean empty)850     void setEmpty(boolean empty) {
851         mEmpty = empty;
852     }
853 
854     @GuardedBy("mService")
isEmpty()855     boolean isEmpty() {
856         return mEmpty;
857     }
858 
859     @GuardedBy("mService")
setCached(boolean cached)860     void setCached(boolean cached) {
861         mCached = cached;
862     }
863 
864     @GuardedBy("mService")
isCached()865     boolean isCached() {
866         return mCached;
867     }
868 
869     @GuardedBy("mService")
getCacheOomRankerUseCount()870     int getCacheOomRankerUseCount() {
871         return mCacheOomRankerUseCount;
872     }
873 
874     @GuardedBy("mService")
setSystemNoUi(boolean systemNoUi)875     void setSystemNoUi(boolean systemNoUi) {
876         mSystemNoUi = systemNoUi;
877     }
878 
879     @GuardedBy("mService")
isSystemNoUi()880     boolean isSystemNoUi() {
881         return mSystemNoUi;
882     }
883 
884     @GuardedBy("mService")
setAdjType(String adjType)885     void setAdjType(String adjType) {
886         mAdjType = adjType;
887     }
888 
889     @GuardedBy("mService")
getAdjType()890     String getAdjType() {
891         return mAdjType;
892     }
893 
894     @GuardedBy({"mService", "mProcLock"})
setAdjTypeCode(int adjTypeCode)895     void setAdjTypeCode(int adjTypeCode) {
896         mAdjTypeCode = adjTypeCode;
897     }
898 
899     @GuardedBy(anyOf = {"mService", "mProcLock"})
getAdjTypeCode()900     int getAdjTypeCode() {
901         return mAdjTypeCode;
902     }
903 
904     @GuardedBy({"mService", "mProcLock"})
setAdjSource(Object adjSource)905     void setAdjSource(Object adjSource) {
906         mAdjSource = adjSource;
907     }
908 
909     @GuardedBy(anyOf = {"mService", "mProcLock"})
getAdjSource()910     Object getAdjSource() {
911         return mAdjSource;
912     }
913 
914     @GuardedBy({"mService", "mProcLock"})
setAdjSourceProcState(int adjSourceProcState)915     void setAdjSourceProcState(int adjSourceProcState) {
916         mAdjSourceProcState = adjSourceProcState;
917     }
918 
919     @GuardedBy(anyOf = {"mService", "mProcLock"})
getAdjSourceProcState()920     int getAdjSourceProcState() {
921         return mAdjSourceProcState;
922     }
923 
924     @GuardedBy({"mService", "mProcLock"})
setAdjTarget(Object adjTarget)925     void setAdjTarget(Object adjTarget) {
926         mAdjTarget = adjTarget;
927     }
928 
929     @GuardedBy(anyOf = {"mService", "mProcLock"})
getAdjTarget()930     Object getAdjTarget() {
931         return mAdjTarget;
932     }
933 
934     @GuardedBy("mService")
isReachable()935     boolean isReachable() {
936         return mReachable;
937     }
938 
939     @GuardedBy("mService")
setReachable(boolean reachable)940     void setReachable(boolean reachable) {
941         mReachable = reachable;
942     }
943 
944     @GuardedBy("mService")
resetCachedInfo()945     void resetCachedInfo() {
946         mCachedHasActivities = VALUE_INVALID;
947         mCachedIsHeavyWeight = VALUE_INVALID;
948         mCachedHasVisibleActivities = VALUE_INVALID;
949         mCachedIsHomeProcess = VALUE_INVALID;
950         mCachedIsPreviousProcess = VALUE_INVALID;
951         mCachedHasRecentTasks = VALUE_INVALID;
952         mCachedIsReceivingBroadcast = VALUE_INVALID;
953         mCachedAdj = ProcessList.INVALID_ADJ;
954         mCachedForegroundActivities = false;
955         mCachedProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
956         mCachedSchedGroup = ProcessList.SCHED_GROUP_BACKGROUND;
957     }
958 
959     @GuardedBy("mService")
getCachedHasActivities()960     boolean getCachedHasActivities() {
961         if (mCachedHasActivities == VALUE_INVALID) {
962             mCachedHasActivities = mApp.getWindowProcessController().hasActivities() ? VALUE_TRUE
963                     : VALUE_FALSE;
964         }
965         return mCachedHasActivities == VALUE_TRUE;
966     }
967 
968     @GuardedBy("mService")
getCachedIsHeavyWeight()969     boolean getCachedIsHeavyWeight() {
970         if (mCachedIsHeavyWeight == VALUE_INVALID) {
971             mCachedIsHeavyWeight = mApp.getWindowProcessController().isHeavyWeightProcess()
972                     ? VALUE_TRUE : VALUE_FALSE;
973         }
974         return mCachedIsHeavyWeight == VALUE_TRUE;
975     }
976 
977     @GuardedBy("mService")
getCachedHasVisibleActivities()978     boolean getCachedHasVisibleActivities() {
979         if (mCachedHasVisibleActivities == VALUE_INVALID) {
980             mCachedHasVisibleActivities = mApp.getWindowProcessController().hasVisibleActivities()
981                     ? VALUE_TRUE : VALUE_FALSE;
982         }
983         return mCachedHasVisibleActivities == VALUE_TRUE;
984     }
985 
986     @GuardedBy("mService")
getCachedIsHomeProcess()987     boolean getCachedIsHomeProcess() {
988         if (mCachedIsHomeProcess == VALUE_INVALID) {
989             if (mApp.getWindowProcessController().isHomeProcess()) {
990                 mCachedIsHomeProcess = VALUE_TRUE;
991                 mService.mAppProfiler.mHasHomeProcess = true;
992             } else {
993                 mCachedIsHomeProcess = VALUE_FALSE;
994             }
995         }
996         return mCachedIsHomeProcess == VALUE_TRUE;
997     }
998 
999     @GuardedBy("mService")
getCachedIsPreviousProcess()1000     boolean getCachedIsPreviousProcess() {
1001         if (mCachedIsPreviousProcess == VALUE_INVALID) {
1002             if (mApp.getWindowProcessController().isPreviousProcess()) {
1003                 mCachedIsPreviousProcess = VALUE_TRUE;
1004                 mService.mAppProfiler.mHasPreviousProcess = true;
1005             } else {
1006                 mCachedIsPreviousProcess = VALUE_FALSE;
1007             }
1008         }
1009         return mCachedIsPreviousProcess == VALUE_TRUE;
1010     }
1011 
1012     @GuardedBy("mService")
getCachedHasRecentTasks()1013     boolean getCachedHasRecentTasks() {
1014         if (mCachedHasRecentTasks == VALUE_INVALID) {
1015             mCachedHasRecentTasks = mApp.getWindowProcessController().hasRecentTasks()
1016                     ? VALUE_TRUE : VALUE_FALSE;
1017         }
1018         return mCachedHasRecentTasks == VALUE_TRUE;
1019     }
1020 
1021     @GuardedBy("mService")
getCachedIsReceivingBroadcast(ArraySet<BroadcastQueue> tmpQueue)1022     boolean getCachedIsReceivingBroadcast(ArraySet<BroadcastQueue> tmpQueue) {
1023         if (mCachedIsReceivingBroadcast == VALUE_INVALID) {
1024             tmpQueue.clear();
1025             mCachedIsReceivingBroadcast = mService.isReceivingBroadcastLocked(mApp, tmpQueue)
1026                     ? VALUE_TRUE : VALUE_FALSE;
1027             if (mCachedIsReceivingBroadcast == VALUE_TRUE) {
1028                 mCachedSchedGroup = tmpQueue.contains(mService.mFgBroadcastQueue)
1029                         ? ProcessList.SCHED_GROUP_DEFAULT : ProcessList.SCHED_GROUP_BACKGROUND;
1030             }
1031         }
1032         return mCachedIsReceivingBroadcast == VALUE_TRUE;
1033     }
1034 
1035     @GuardedBy("mService")
getCachedCompatChange(@achedCompatChangeId int cachedCompatChangeId)1036     boolean getCachedCompatChange(@CachedCompatChangeId int cachedCompatChangeId) {
1037         if (mCachedCompatChanges[cachedCompatChangeId] == VALUE_INVALID) {
1038             mCachedCompatChanges[cachedCompatChangeId] = mService.mOomAdjuster
1039                     .isChangeEnabled(cachedCompatChangeId, mApp.info, false /* default */)
1040                     ? VALUE_TRUE : VALUE_FALSE;
1041         }
1042         return mCachedCompatChanges[cachedCompatChangeId] == VALUE_TRUE;
1043     }
1044 
1045     @GuardedBy("mService")
computeOomAdjFromActivitiesIfNecessary(OomAdjuster.ComputeOomAdjWindowCallback callback, int adj, boolean foregroundActivities, boolean hasVisibleActivities, int procState, int schedGroup, int appUid, int logUid, int processCurTop)1046     void computeOomAdjFromActivitiesIfNecessary(OomAdjuster.ComputeOomAdjWindowCallback callback,
1047             int adj, boolean foregroundActivities, boolean hasVisibleActivities, int procState,
1048             int schedGroup, int appUid, int logUid, int processCurTop) {
1049         if (mCachedAdj != ProcessList.INVALID_ADJ) {
1050             return;
1051         }
1052         callback.initialize(mApp, adj, foregroundActivities, hasVisibleActivities, procState,
1053                 schedGroup, appUid, logUid, processCurTop);
1054         final int minLayer = Math.min(ProcessList.VISIBLE_APP_LAYER_MAX,
1055                 mApp.getWindowProcessController().computeOomAdjFromActivities(callback));
1056 
1057         mCachedAdj = callback.adj;
1058         mCachedForegroundActivities = callback.foregroundActivities;
1059         mCachedHasVisibleActivities = callback.mHasVisibleActivities ? VALUE_TRUE : VALUE_FALSE;
1060         mCachedProcState = callback.procState;
1061         mCachedSchedGroup = callback.schedGroup;
1062 
1063         if (mCachedAdj == ProcessList.VISIBLE_APP_ADJ) {
1064             mCachedAdj += minLayer;
1065         }
1066     }
1067 
1068     @GuardedBy("mService")
getCachedAdj()1069     int getCachedAdj() {
1070         return mCachedAdj;
1071     }
1072 
1073     @GuardedBy("mService")
getCachedForegroundActivities()1074     boolean getCachedForegroundActivities() {
1075         return mCachedForegroundActivities;
1076     }
1077 
1078     @GuardedBy("mService")
getCachedProcState()1079     int getCachedProcState() {
1080         return mCachedProcState;
1081     }
1082 
1083     @GuardedBy("mService")
getCachedSchedGroup()1084     int getCachedSchedGroup() {
1085         return mCachedSchedGroup;
1086     }
1087 
1088     @GuardedBy(anyOf = {"mService", "mProcLock"})
makeAdjReason()1089     public String makeAdjReason() {
1090         if (mAdjSource != null || mAdjTarget != null) {
1091             StringBuilder sb = new StringBuilder(128);
1092             sb.append(' ');
1093             if (mAdjTarget instanceof ComponentName) {
1094                 sb.append(((ComponentName) mAdjTarget).flattenToShortString());
1095             } else if (mAdjTarget != null) {
1096                 sb.append(mAdjTarget.toString());
1097             } else {
1098                 sb.append("{null}");
1099             }
1100             sb.append("<=");
1101             if (mAdjSource instanceof ProcessRecord) {
1102                 sb.append("Proc{");
1103                 sb.append(((ProcessRecord) mAdjSource).toShortString());
1104                 sb.append("}");
1105             } else if (mAdjSource != null) {
1106                 sb.append(mAdjSource.toString());
1107             } else {
1108                 sb.append("{null}");
1109             }
1110             return sb.toString();
1111         }
1112         return null;
1113     }
1114 
1115     @GuardedBy({"mService", "mProcLock"})
onCleanupApplicationRecordLSP()1116     void onCleanupApplicationRecordLSP() {
1117         setHasForegroundActivities(false);
1118         mHasShownUi = false;
1119         mForcingToImportant = null;
1120         mCurRawAdj = mSetRawAdj = mCurAdj = mSetAdj = mVerifiedAdj = ProcessList.INVALID_ADJ;
1121         mCurCapability = mSetCapability = PROCESS_CAPABILITY_NONE;
1122         mCurSchedGroup = mSetSchedGroup = ProcessList.SCHED_GROUP_BACKGROUND;
1123         mCurProcState = mCurRawProcState = mSetProcState = mAllowStartFgsState =
1124                 PROCESS_STATE_NONEXISTENT;
1125         for (int i = 0; i < mCachedCompatChanges.length; i++) {
1126             mCachedCompatChanges[i] = VALUE_INVALID;
1127         }
1128     }
1129 
1130     @GuardedBy("mService")
resetAllowStartFgsState()1131     void resetAllowStartFgsState() {
1132         mAllowStartFgsState = PROCESS_STATE_NONEXISTENT;
1133     }
1134 
1135     @GuardedBy("mService")
bumpAllowStartFgsState(int newProcState)1136     void bumpAllowStartFgsState(int newProcState) {
1137         if (newProcState < mAllowStartFgsState) {
1138             mAllowStartFgsState = newProcState;
1139         }
1140     }
1141 
1142     @GuardedBy("mService")
getAllowStartFgsState()1143     int getAllowStartFgsState() {
1144         return mAllowStartFgsState;
1145     }
1146 
1147     @GuardedBy("mService")
isAllowedStartFgsState()1148     boolean isAllowedStartFgsState() {
1149         return mAllowStartFgsState <= PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
1150     }
1151 
1152     @GuardedBy("mService")
updateLastInvisibleTime(boolean hasVisibleActivities)1153     void updateLastInvisibleTime(boolean hasVisibleActivities) {
1154         if (hasVisibleActivities) {
1155             mLastInvisibleTime = Long.MAX_VALUE;
1156         } else if (mLastInvisibleTime == Long.MAX_VALUE) {
1157             mLastInvisibleTime = SystemClock.elapsedRealtime();
1158         }
1159     }
1160 
1161     @GuardedBy("mService")
1162     @ElapsedRealtimeLong
getLastInvisibleTime()1163     long getLastInvisibleTime() {
1164         return mLastInvisibleTime;
1165     }
1166 
setCacheOomRankerRss(long rss, long rssTimeMs)1167     public void setCacheOomRankerRss(long rss, long rssTimeMs) {
1168         mCacheOomRankerRss = rss;
1169         mCacheOomRankerRssTimeMs = rssTimeMs;
1170     }
1171 
1172     @GuardedBy("mService")
getCacheOomRankerRss()1173     public long getCacheOomRankerRss() {
1174         return mCacheOomRankerRss;
1175     }
1176 
1177     @GuardedBy("mService")
getCacheOomRankerRssTimeMs()1178     public long getCacheOomRankerRssTimeMs() {
1179         return mCacheOomRankerRssTimeMs;
1180     }
1181 
1182     @GuardedBy({"mService", "mProcLock"})
dump(PrintWriter pw, String prefix, long nowUptime)1183     void dump(PrintWriter pw, String prefix, long nowUptime) {
1184         if (mReportedInteraction || mFgInteractionTime != 0) {
1185             pw.print(prefix); pw.print("reportedInteraction=");
1186             pw.print(mReportedInteraction);
1187             if (mInteractionEventTime != 0) {
1188                 pw.print(" time=");
1189                 TimeUtils.formatDuration(mInteractionEventTime, SystemClock.elapsedRealtime(), pw);
1190             }
1191             if (mFgInteractionTime != 0) {
1192                 pw.print(" fgInteractionTime=");
1193                 TimeUtils.formatDuration(mFgInteractionTime, SystemClock.elapsedRealtime(), pw);
1194             }
1195             pw.println();
1196         }
1197         pw.print(prefix); pw.print("adjSeq="); pw.print(mAdjSeq);
1198         pw.print(" lruSeq="); pw.println(mApp.getLruSeq());
1199         pw.print(prefix); pw.print("oom adj: max="); pw.print(mMaxAdj);
1200         pw.print(" curRaw="); pw.print(mCurRawAdj);
1201         pw.print(" setRaw="); pw.print(mSetRawAdj);
1202         pw.print(" cur="); pw.print(mCurAdj);
1203         pw.print(" set="); pw.println(mSetAdj);
1204         pw.print(prefix); pw.print("mCurSchedGroup="); pw.print(mCurSchedGroup);
1205         pw.print(" setSchedGroup="); pw.print(mSetSchedGroup);
1206         pw.print(" systemNoUi="); pw.println(mSystemNoUi);
1207         pw.print(prefix); pw.print("curProcState="); pw.print(getCurProcState());
1208         pw.print(" mRepProcState="); pw.print(mRepProcState);
1209         pw.print(" setProcState="); pw.print(mSetProcState);
1210         pw.print(" lastStateTime=");
1211         TimeUtils.formatDuration(getLastStateTime(), nowUptime, pw);
1212         pw.println();
1213         pw.print(prefix); pw.print("curCapability=");
1214         ActivityManager.printCapabilitiesFull(pw, mCurCapability);
1215         pw.print(" setCapability=");
1216         ActivityManager.printCapabilitiesFull(pw, mSetCapability);
1217         pw.println();
1218         pw.print(prefix); pw.print("allowStartFgsState=");
1219         pw.println(mAllowStartFgsState);
1220         if (mHasShownUi || mApp.mProfile.hasPendingUiClean()) {
1221             pw.print(prefix); pw.print("hasShownUi="); pw.print(mHasShownUi);
1222             pw.print(" pendingUiClean="); pw.println(mApp.mProfile.hasPendingUiClean());
1223         }
1224         pw.print(prefix); pw.print("cached="); pw.print(mCached);
1225         pw.print(" empty="); pw.println(mEmpty);
1226         if (mServiceB) {
1227             pw.print(prefix); pw.print("serviceb="); pw.print(mServiceB);
1228             pw.print(" serviceHighRam="); pw.println(mServiceHighRam);
1229         }
1230         if (mNotCachedSinceIdle) {
1231             pw.print(prefix); pw.print("notCachedSinceIdle="); pw.print(mNotCachedSinceIdle);
1232             pw.print(" initialIdlePss="); pw.println(mApp.mProfile.getInitialIdlePss());
1233         }
1234         if (hasTopUi() || hasOverlayUi() || mRunningRemoteAnimation) {
1235             pw.print(prefix); pw.print("hasTopUi="); pw.print(hasTopUi());
1236             pw.print(" hasOverlayUi="); pw.print(hasOverlayUi());
1237             pw.print(" runningRemoteAnimation="); pw.println(mRunningRemoteAnimation);
1238         }
1239         if (mHasForegroundActivities || mRepForegroundActivities) {
1240             pw.print(prefix);
1241             pw.print("foregroundActivities="); pw.print(mHasForegroundActivities);
1242             pw.print(" (rep="); pw.print(mRepForegroundActivities); pw.println(")");
1243         }
1244         if (mSetProcState > ActivityManager.PROCESS_STATE_SERVICE) {
1245             pw.print(prefix);
1246             pw.print("whenUnimportant=");
1247             TimeUtils.formatDuration(mWhenUnimportant - nowUptime, pw);
1248             pw.println();
1249         }
1250         if (mLastTopTime > 0) {
1251             pw.print(prefix); pw.print("lastTopTime=");
1252             TimeUtils.formatDuration(mLastTopTime, nowUptime, pw);
1253             pw.println();
1254         }
1255         if (mLastInvisibleTime > 0 && mLastInvisibleTime < Long.MAX_VALUE) {
1256             pw.print(prefix); pw.print("lastInvisibleTime=");
1257             final long elapsedRealtimeNow = SystemClock.elapsedRealtime();
1258             final long currentTimeNow = System.currentTimeMillis();
1259             final long lastInvisibleCurrentTime =
1260                     currentTimeNow - elapsedRealtimeNow + mLastInvisibleTime;
1261             TimeUtils.dumpTimeWithDelta(pw, lastInvisibleCurrentTime, currentTimeNow);
1262             pw.println();
1263         }
1264         if (mHasStartedServices) {
1265             pw.print(prefix); pw.print("hasStartedServices="); pw.println(mHasStartedServices);
1266         }
1267     }
1268 }
1269