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