The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.am; |
| 18 | |
riddle_hsu | 6793fc3 | 2015-03-31 11:54:14 +0800 | [diff] [blame] | 19 | import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 20 | |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 21 | import static com.android.server.Watchdog.NATIVE_STACKS_OF_INTEREST; |
| 22 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ANR; |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 23 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_OOM_ADJ; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 24 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 25 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 26 | import static com.android.server.am.ActivityManagerService.MY_PID; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 27 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.app.ActivityManager; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 29 | import android.app.ApplicationErrorReport; |
Jing Ji | 8055a3a | 2019-12-17 15:55:33 -0800 | [diff] [blame] | 30 | import android.app.ApplicationExitInfo; |
| 31 | import android.app.ApplicationExitInfo.Reason; |
| 32 | import android.app.ApplicationExitInfo.SubReason; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.app.Dialog; |
| 34 | import android.app.IApplicationThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.content.ComponentName; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 36 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | f6729fa | 2020-01-06 13:12:36 -0800 | [diff] [blame] | 38 | import android.content.pm.ProcessInfo; |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 39 | import android.content.pm.ServiceInfo; |
Zimuzo | 972e1cd | 2019-01-28 16:30:01 +0000 | [diff] [blame] | 40 | import android.content.pm.VersionedPackage; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 41 | import android.content.res.CompatibilityInfo; |
Joe Onorato | 5719028 | 2016-04-20 15:37:49 -0700 | [diff] [blame] | 42 | import android.os.Binder; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 43 | import android.os.Debug; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.os.IBinder; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 45 | import android.os.Message; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 46 | import android.os.Process; |
Joe Onorato | 5719028 | 2016-04-20 15:37:49 -0700 | [diff] [blame] | 47 | import android.os.RemoteException; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 48 | import android.os.SystemClock; |
Yusuke Sato | cf4b254 | 2015-06-17 00:21:28 -0700 | [diff] [blame] | 49 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 50 | import android.os.UserHandle; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 51 | import android.provider.Settings; |
Yang Lu | 732d638 | 2018-11-05 07:53:12 -0800 | [diff] [blame] | 52 | import android.server.ServerProtoEnums; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 53 | import android.util.ArrayMap; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 54 | import android.util.ArraySet; |
| 55 | import android.util.DebugUtils; |
| 56 | import android.util.EventLog; |
| 57 | import android.util.Slog; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 58 | import android.util.SparseArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 59 | import android.util.TimeUtils; |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 60 | import android.util.proto.ProtoOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 62 | import com.android.internal.annotations.VisibleForTesting; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 63 | import com.android.internal.app.procstats.ProcessState; |
| 64 | import com.android.internal.app.procstats.ProcessStats; |
| 65 | import com.android.internal.os.BatteryStatsImpl; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 66 | import com.android.internal.os.ProcessCpuTracker; |
Sudheer Shanka | 87915d6 | 2018-11-06 10:57:35 -0800 | [diff] [blame] | 67 | import com.android.internal.os.Zygote; |
Muhammad Qureshi | edd80fd | 2020-01-27 17:23:07 -0800 | [diff] [blame] | 68 | import com.android.internal.util.FrameworkStatsLog; |
Simon MacMullen | 30f04a7 | 2020-02-05 10:57:40 +0000 | [diff] [blame] | 69 | import com.android.server.MemoryPressureUtil; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 70 | import com.android.server.wm.WindowProcessController; |
| 71 | import com.android.server.wm.WindowProcessListener; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 72 | |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 73 | import java.io.File; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | import java.io.PrintWriter; |
Simon MacMullen | 46755e2 | 2020-02-04 14:03:37 +0000 | [diff] [blame] | 75 | import java.io.StringWriter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | import java.util.ArrayList; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 77 | import java.util.Arrays; |
Zimuzo | 972e1cd | 2019-01-28 16:30:01 +0000 | [diff] [blame] | 78 | import java.util.List; |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 79 | import java.util.function.Consumer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * Full information about a particular process that |
| 83 | * is currently running. |
| 84 | */ |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 85 | class ProcessRecord implements WindowProcessListener { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 86 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ProcessRecord" : TAG_AM; |
| 87 | |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 88 | private final ActivityManagerService mService; // where we came from |
Ryan Mitchell | 03bf28b | 2020-04-17 15:53:20 -0700 | [diff] [blame] | 89 | volatile ApplicationInfo info; // all about the first app in the process |
Dianne Hackborn | f6729fa | 2020-01-06 13:12:36 -0800 | [diff] [blame] | 90 | final ProcessInfo processInfo; // if non-null, process-specific manifest info |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 91 | final boolean isolated; // true if this is a special isolated process |
Martijn Coenen | 01e719b | 2018-12-05 16:01:38 +0100 | [diff] [blame] | 92 | final boolean appZygote; // true if this is forked from the app zygote |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 93 | final int uid; // uid of process; may be different from 'info' if isolated |
| 94 | final int userId; // user of process. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | final String processName; // name of the process |
| 96 | // List of packages running in the process |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 97 | final PackageList pkgList = new PackageList(); |
| 98 | final class PackageList { |
| 99 | final ArrayMap<String, ProcessStats.ProcessStateHolder> mPkgList = new ArrayMap<>(); |
| 100 | |
| 101 | ProcessStats.ProcessStateHolder put(String key, ProcessStats.ProcessStateHolder value) { |
| 102 | mWindowProcessController.addPackage(key); |
| 103 | return mPkgList.put(key, value); |
| 104 | } |
| 105 | |
| 106 | void clear() { |
| 107 | mPkgList.clear(); |
| 108 | mWindowProcessController.clearPackageList(); |
| 109 | } |
| 110 | |
| 111 | int size() { |
| 112 | return mPkgList.size(); |
| 113 | } |
| 114 | |
| 115 | String keyAt(int index) { |
| 116 | return mPkgList.keyAt(index); |
| 117 | } |
| 118 | |
| 119 | public ProcessStats.ProcessStateHolder valueAt(int index) { |
| 120 | return mPkgList.valueAt(index); |
| 121 | } |
| 122 | |
Dianne Hackborn | 2aec55a | 2018-06-26 10:35:35 -0700 | [diff] [blame] | 123 | ProcessStats.ProcessStateHolder get(String pkgName) { |
| 124 | return mPkgList.get(pkgName); |
| 125 | } |
| 126 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 127 | boolean containsKey(Object key) { |
| 128 | return mPkgList.containsKey(key); |
| 129 | } |
| 130 | } |
| 131 | |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 132 | final ProcessList.ProcStateMemTracker procStateMemTracker |
| 133 | = new ProcessList.ProcStateMemTracker(); |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 134 | UidRecord uidRecord; // overall state of process's uid. |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 135 | ArraySet<String> pkgDeps; // additional packages we have a dependency on |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | IApplicationThread thread; // the actual proc... may be null only if |
| 137 | // 'persistent' is true (in which case we |
| 138 | // are in the process of launching the app) |
Joe Onorato | 4eb64fd | 2016-03-21 15:30:09 -0700 | [diff] [blame] | 139 | ProcessState baseProcessTracker; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 140 | BatteryStatsImpl.Uid.Proc curProcBatteryStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | int pid; // The process of this application; 0 if none |
Dianne Hackborn | 4de5a3a | 2016-06-20 15:20:15 -0700 | [diff] [blame] | 142 | String procStatFile; // path to /proc/<pid>/stat |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 143 | int[] gids; // The gids this process was launched with |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 144 | private String mRequiredAbi;// The ABI this process was launched with |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 145 | String instructionSet; // The instruction set this process was launched with |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | boolean starting; // True if the process is being started |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 147 | long lastActivityTime; // For managing the LRU list |
Dianne Hackborn | f1cca18 | 2013-08-01 10:50:28 -0700 | [diff] [blame] | 148 | long lastPssTime; // Last time we retrieved PSS data |
| 149 | long nextPssTime; // Next time we want to request PSS data |
| 150 | long lastStateTime; // Last time setProcState changed |
Dianne Hackborn | 35f72be | 2013-09-16 10:57:39 -0700 | [diff] [blame] | 151 | long initialIdlePss; // Initial memory pss of process for idle maintenance. |
| 152 | long lastPss; // Last computed memory pss. |
Thierry Strudel | f0a4418 | 2016-01-07 18:08:04 -0800 | [diff] [blame] | 153 | long lastSwapPss; // Last computed SwapPss. |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 154 | long lastCachedPss; // Last computed pss when in cached state. |
Thierry Strudel | f0a4418 | 2016-01-07 18:08:04 -0800 | [diff] [blame] | 155 | long lastCachedSwapPss; // Last computed SwapPss when in cached state. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | int maxAdj; // Maximum OOM adjustment for this process |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 157 | private int mCurRawAdj; // Current OOM unlimited adjustment for this process |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | int setRawAdj; // Last set OOM unlimited adjustment for this process |
| 159 | int curAdj; // Current OOM adjustment for this process |
| 160 | int setAdj; // Last set OOM adjustment for this process |
Dianne Hackborn | 4de5a3a | 2016-06-20 15:20:15 -0700 | [diff] [blame] | 161 | int verifiedAdj; // The last adjustment that was verified as actually being set |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 162 | int curCapability; // Current capability flags of this process. For example, |
| 163 | // PROCESS_CAPABILITY_FOREGROUND_LOCATION is one capability. |
| 164 | int setCapability; // Last set capability flags. |
Tim Murray | 0b1c8aa | 2018-11-20 10:28:38 -0800 | [diff] [blame] | 165 | long lastCompactTime; // The last time that this process was compacted |
| 166 | int reqCompactAction; // The most recent compaction action requested for this app. |
| 167 | int lastCompactAction; // The most recent compaction action performed for this app. |
Marco Ballesio | bdaf16e | 2020-01-23 13:57:00 -0800 | [diff] [blame] | 168 | boolean frozen; // True when the process is frozen. |
| 169 | long freezeUnfreezeTime; // Last time the app was (un)frozen, 0 for never |
Tim Murray | 7b4b26b | 2020-02-26 09:20:32 -0800 | [diff] [blame] | 170 | boolean shouldNotFreeze; // True if a process has a WPRI binding from an unfrozen process |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 171 | private int mCurSchedGroup; // Currently desired scheduling class |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 172 | int setSchedGroup; // Last set to background scheduling class |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 173 | int trimMemoryLevel; // Last selected memory trimming level |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 174 | private int mCurProcState = PROCESS_STATE_NONEXISTENT; // Currently computed process state |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 175 | private int mRepProcState = PROCESS_STATE_NONEXISTENT; // Last reported process state |
Amith Yamasani | 08888c0 | 2018-12-07 09:38:25 -0800 | [diff] [blame] | 176 | private int mCurRawProcState = PROCESS_STATE_NONEXISTENT; // Temp state during computation |
riddle_hsu | 6793fc3 | 2015-03-31 11:54:14 +0800 | [diff] [blame] | 177 | int setProcState = PROCESS_STATE_NONEXISTENT; // Last set process state in process tracker |
| 178 | int pssProcState = PROCESS_STATE_NONEXISTENT; // Currently requesting pss for |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 179 | int pssStatType; // The type of stat collection that we are currently requesting |
Tim Murray | 33eb07f | 2016-06-10 10:03:20 -0700 | [diff] [blame] | 180 | int savedPriority; // Previous priority value if we're switching to non-SCHED_OTHER |
| 181 | int renderThreadTid; // TID for RenderThread |
Dianne Hackborn | a631d56 | 2018-11-20 15:58:15 -0800 | [diff] [blame] | 182 | ServiceRecord connectionService; // Service that applied current connectionGroup/Importance |
| 183 | int connectionGroup; // Last group set by a connection |
| 184 | int connectionImportance; // Last importance set by a connection |
Dianne Hackborn | e02c88a | 2011-10-28 13:58:15 -0700 | [diff] [blame] | 185 | boolean serviceb; // Process currently is on the service B list |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 186 | boolean serviceHighRam; // We are forcing to service B list due to its RAM use |
Dianne Hackborn | 35f72be | 2013-09-16 10:57:39 -0700 | [diff] [blame] | 187 | boolean notCachedSinceIdle; // Has this process not been in a cached state since last idle? |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 188 | private boolean mHasClientActivities; // Are there any client services with activities? |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 189 | boolean hasStartedServices; // Are there any started services running in this process? |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 190 | private boolean mHasForegroundServices; // Running any services that are foreground? |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 191 | private int mFgServiceTypes; // Type of foreground service, if there is a foreground service. |
Narayan Kamath | 396ce72 | 2019-03-01 16:53:26 +0000 | [diff] [blame] | 192 | private int mRepFgServiceTypes; // Last reported foreground service types. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 193 | private boolean mHasForegroundActivities; // Running any activities that are foreground? |
Dianne Hackborn | 684bf34 | 2014-04-29 17:56:57 -0700 | [diff] [blame] | 194 | boolean repForegroundActivities; // Last reported foreground activities. |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 195 | boolean systemNoUi; // This is a system process, but not currently showing UI. |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 196 | boolean hasShownUi; // Has UI been shown in this process since it was started? |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 197 | private boolean mHasTopUi; // Is this process currently showing a non-activity UI that the user |
Wale Ogunwale | d993a57 | 2017-02-05 13:52:09 -0800 | [diff] [blame] | 198 | // is interacting with? E.g. The status bar when it is expanded, but |
| 199 | // not when it is minimized. When true the |
| 200 | // process will be set to use the ProcessList#SCHED_GROUP_TOP_APP |
| 201 | // scheduling group to boost performance. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 202 | private boolean mHasOverlayUi; // Is the process currently showing a non-activity UI that |
Wale Ogunwale | d993a57 | 2017-02-05 13:52:09 -0800 | [diff] [blame] | 203 | // overlays on-top of activity UIs on screen. E.g. display a window |
| 204 | // of type |
| 205 | // android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY |
| 206 | // When true the process will oom adj score will be set to |
| 207 | // ProcessList#PERCEPTIBLE_APP_ADJ at minimum to reduce the chance |
| 208 | // of the process getting killed. |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 209 | boolean runningRemoteAnimation; // Is the process currently running a RemoteAnimation? When true |
| 210 | // the process will be set to use the |
| 211 | // ProcessList#SCHED_GROUP_TOP_APP scheduling group to boost |
| 212 | // performance, as well as oom adj score will be set to |
| 213 | // ProcessList#VISIBLE_APP_ADJ at minimum to reduce the chance |
| 214 | // of the process getting killed. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 215 | private boolean mPendingUiClean; // Want to clean up resources from showing UI? |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 216 | boolean hasAboveClient; // Bound using BIND_ABOVE_CLIENT, so want to be lower |
Dianne Hackborn | f0f94d1 | 2014-03-17 16:04:21 -0700 | [diff] [blame] | 217 | boolean treatLikeActivity; // Bound using BIND_TREAT_LIKE_ACTIVITY |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 218 | boolean bad; // True if disabled in the bad process list |
Dianne Hackborn | 35f72be | 2013-09-16 10:57:39 -0700 | [diff] [blame] | 219 | boolean killedByAm; // True when proc has been killed by activity manager, not for RAM |
Dianne Hackborn | d412563 | 2014-09-22 12:52:49 -0700 | [diff] [blame] | 220 | boolean killed; // True once we know the process has been killed |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 221 | boolean procStateChanged; // Keep track of whether we changed 'setAdj'. |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 222 | boolean reportedInteraction;// Whether we have told usage stats about it being an interaction |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 223 | boolean unlocked; // True when proc was started in user unlocked state |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 224 | private long mInteractionEventTime; // The time we sent the last interaction event |
| 225 | private long mFgInteractionTime; // When we became foreground for interaction purposes |
Dianne Hackborn | 9357b11 | 2013-10-03 18:27:48 -0700 | [diff] [blame] | 226 | String waitingToKill; // Process is waiting to be killed when in the bg, and reason |
Dianne Hackborn | f965f40 | 2017-05-04 23:27:23 -0700 | [diff] [blame] | 227 | Object forcingToImportant; // Token that is forcing this process to be important |
Dianne Hackborn | 906497c | 2010-05-10 15:57:38 -0700 | [diff] [blame] | 228 | int adjSeq; // Sequence id for identifying oom_adj assignment cycles |
Tim Murray | b52f000 | 2018-05-02 15:14:35 -0700 | [diff] [blame] | 229 | int completedAdjSeq; // Sequence id for identifying oom_adj assignment cycles |
| 230 | boolean containsCycle; // Whether this app has encountered a cycle in the most recent update |
Dianne Hackborn | 906497c | 2010-05-10 15:57:38 -0700 | [diff] [blame] | 231 | int lruSeq; // Sequence id for identifying LRU update cycles |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 232 | CompatibilityInfo compat; // last used compatibility mode |
Dianne Hackborn | 1b64e0d | 2011-07-17 15:23:59 -0700 | [diff] [blame] | 233 | IBinder.DeathRecipient deathRecipient; // Who is watching for the death. |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 234 | private ActiveInstrumentation mInstr; // Set to currently active instrumentation running in |
| 235 | // process. |
| 236 | private boolean mUsingWrapper; // Set to true when process was launched with a wrapper attached |
yangzhenyu | d509bc9 | 2016-08-31 18:26:46 +0800 | [diff] [blame] | 237 | final ArraySet<BroadcastRecord> curReceivers = new ArraySet<BroadcastRecord>();// receivers currently running in the app |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 238 | private long mWhenUnimportant; // When (uptime) the process last became unimportant |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 239 | long lastCpuTime; // How long proc has run CPU at last check |
| 240 | long curCpuTime; // How long proc has run CPU most recently |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | long lastRequestedGc; // When we last asked the app to do a gc |
Dianne Hackborn | fd12af4 | 2009-08-27 00:44:33 -0700 | [diff] [blame] | 242 | long lastLowMemory; // When we last told the app that memory is low |
Dianne Hackborn | 1a40564 | 2015-11-04 12:32:45 -0800 | [diff] [blame] | 243 | long lastProviderTime; // The last time someone else was using a provider in this process. |
Amith Yamasani | e5bfeee | 2018-09-05 18:52:35 -0700 | [diff] [blame] | 244 | long lastTopTime; // The last time the process was in the TOP state or greater. |
Dianne Hackborn | fd12af4 | 2009-08-27 00:44:33 -0700 | [diff] [blame] | 245 | boolean reportLowMemory; // Set to true when waiting to report low mem |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 246 | boolean empty; // Is this an empty background process? |
Darryl L Johnson | 15192d3 | 2020-01-15 15:31:42 -0800 | [diff] [blame] | 247 | private volatile boolean mCached; // Is this a cached process? |
Dianne Hackborn | de42bb6 | 2009-08-05 12:26:15 -0700 | [diff] [blame] | 248 | String adjType; // Debugging: primary thing impacting oom_adj. |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 249 | int adjTypeCode; // Debugging: adj code to report to app. |
Dianne Hackborn | de42bb6 | 2009-08-05 12:26:15 -0700 | [diff] [blame] | 250 | Object adjSource; // Debugging: option dependent object. |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 251 | int adjSourceProcState; // Debugging: proc state of adjSource's process. |
Dianne Hackborn | de42bb6 | 2009-08-05 12:26:15 -0700 | [diff] [blame] | 252 | Object adjTarget; // Debugging: target component impacting oom_adj. |
Primiano Tucci | 810c052 | 2014-07-25 18:03:16 +0100 | [diff] [blame] | 253 | Runnable crashHandler; // Optional local handler to be invoked in the process crash. |
Ricky Wai | 486d760 | 2020-02-28 16:37:07 +0000 | [diff] [blame] | 254 | boolean bindMountPending; // True if Android/obb and Android/data need to be bind mount . |
Primiano Tucci | 810c052 | 2014-07-25 18:03:16 +0100 | [diff] [blame] | 255 | |
Dianne Hackborn | 8c76d91 | 2018-08-23 15:20:05 -0700 | [diff] [blame] | 256 | // Cache of last retrieve memory info and uptime, to throttle how frequently |
| 257 | // apps can requyest it. |
| 258 | Debug.MemoryInfo lastMemInfo; |
| 259 | long lastMemInfoTime; |
| 260 | |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 261 | // Controller for error dialogs |
| 262 | private final ErrorDialogController mDialogController = new ErrorDialogController(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 263 | // Controller for driving the process state on the window manager side. |
Darryl L Johnson | d02044c | 2020-04-17 11:52:50 -0700 | [diff] [blame] | 264 | private final WindowProcessController mWindowProcessController; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | // all ServiceRecord running in this process |
Darryl L Johnson | d02044c | 2020-04-17 11:52:50 -0700 | [diff] [blame] | 266 | private final ArraySet<ServiceRecord> mServices = new ArraySet<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | // services that are currently executing code (need to remain foreground). |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 268 | final ArraySet<ServiceRecord> executingServices = new ArraySet<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | // All ConnectionRecord this process holds |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 270 | final ArraySet<ConnectionRecord> connections = new ArraySet<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | // all IIntentReceivers that are registered from this process. |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 272 | final ArraySet<ReceiverList> receivers = new ArraySet<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | // class (String) -> ContentProviderRecord |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 274 | final ArrayMap<String, ContentProviderRecord> pubProviders = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | // All ContentProviderRecord process is using |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 276 | final ArrayList<ContentProviderConnection> conProviders = new ArrayList<>(); |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 277 | // A set of tokens that currently contribute to this process being temporarily whitelisted |
| 278 | // to start activities even if it's not in the foreground |
| 279 | final ArraySet<Binder> mAllowBackgroundActivityStartsTokens = new ArraySet<>(); |
Michal Karpinski | b7daac2 | 2019-03-25 10:12:41 +0000 | [diff] [blame] | 280 | // a set of UIDs of all bound clients |
| 281 | private ArraySet<Integer> mBoundClientUids = new ArraySet<>(); |
Dianne Hackborn | bf36ee2 | 2013-07-26 18:24:10 -0700 | [diff] [blame] | 282 | |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 283 | String isolatedEntryPoint; // Class to run on start if this is a special isolated process. |
| 284 | String[] isolatedEntryPointArgs; // Arguments to pass to isolatedEntryPoint's main(). |
| 285 | |
Dianne Hackborn | bf36ee2 | 2013-07-26 18:24:10 -0700 | [diff] [blame] | 286 | boolean execServicesFg; // do we need to be executing services in the foreground? |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 287 | private boolean mPersistent;// always keep this application running? |
| 288 | private boolean mCrashing; // are we in the process of crashing? |
Christopher Tate | 58d380d | 2013-03-19 13:10:03 -0700 | [diff] [blame] | 289 | boolean forceCrashReport; // suppress normal auto-dismiss of crash dialog & report UI? |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 290 | private boolean mNotResponding; // does the app have a not responding dialog? |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 291 | volatile boolean removed; // Whether this process should be killed and removed from process |
| 292 | // list. It is set when the package is force-stopped or the process |
| 293 | // has crashed too many times. |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 294 | private boolean mDebugging; // was app launched for debugging? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | boolean waitedForDebugger; // has process show wait for debugger dialog? |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 296 | |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 297 | String shortStringName; // caching of toShortString() result. |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 298 | String stringName; // caching of toString() result. |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 299 | boolean pendingStart; // Process start is pending. |
| 300 | long startSeq; // Seq no. indicating the latest process start associated with |
| 301 | // this process record. |
Sudheer Shanka | 87915d6 | 2018-11-06 10:57:35 -0800 | [diff] [blame] | 302 | int mountMode; // Indicates how the external storage was mounted for this process. |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | // These reports are generated & stored when an app gets into an error condition. |
| 305 | // They will be "null" when all is OK. |
| 306 | ActivityManager.ProcessErrorStateInfo crashingReport; |
| 307 | ActivityManager.ProcessErrorStateInfo notRespondingReport; |
| 308 | |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 309 | // Who will be notified of the error. This is usually an activity in the |
| 310 | // app that installed the package. |
| 311 | ComponentName errorReportReceiver; |
| 312 | |
Amith Yamasani | b5f3b5c | 2016-05-16 14:23:04 -0700 | [diff] [blame] | 313 | // Process is currently hosting a backup agent for backup or restore |
| 314 | public boolean inFullBackup; |
Felipe Leme | a1b79bf | 2016-05-24 13:06:54 -0700 | [diff] [blame] | 315 | // App is allowed to manage whitelists such as temporary Power Save mode whitelist. |
| 316 | boolean whitelistManager; |
Amith Yamasani | b5f3b5c | 2016-05-16 14:23:04 -0700 | [diff] [blame] | 317 | |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 318 | // Params used in starting this process. |
Martijn Coenen | e8431c2 | 2019-03-28 14:09:38 +0100 | [diff] [blame] | 319 | HostingRecord hostingRecord; |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 320 | String seInfo; |
| 321 | long startTime; |
| 322 | // This will be same as {@link #uid} usually except for some apps used during factory testing. |
| 323 | int startUid; |
atrost | 5ae996f | 2019-12-11 18:32:48 +0000 | [diff] [blame] | 324 | // set of disabled compat changes for the process (all others are enabled) |
| 325 | long[] mDisabledCompatChanges; |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 326 | |
Jing Ji | dcc28a0 | 2020-03-07 00:28:40 -0800 | [diff] [blame] | 327 | long mLastRss; // Last computed memory rss. |
| 328 | |
Jing Ji | 971da4f | 2020-01-28 16:34:59 -0800 | [diff] [blame] | 329 | // The precede instance of the process, which would exist when the previous process is killed |
| 330 | // but not fully dead yet; in this case, the new instance of the process should be held until |
| 331 | // this precede instance is fully dead. |
| 332 | volatile ProcessRecord mPrecedence; |
| 333 | // The succeeding instance of the process, which is going to be started after this process |
| 334 | // is killed successfully. |
| 335 | volatile ProcessRecord mSuccessor; |
| 336 | |
Jing Ji | 094c3ef | 2019-08-27 17:02:09 -0700 | [diff] [blame] | 337 | // Cached task info for OomAdjuster |
| 338 | private static final int VALUE_INVALID = -1; |
| 339 | private static final int VALUE_FALSE = 0; |
| 340 | private static final int VALUE_TRUE = 1; |
| 341 | private int mCachedHasActivities = VALUE_INVALID; |
| 342 | private int mCachedIsHeavyWeight = VALUE_INVALID; |
| 343 | private int mCachedHasVisibleActivities = VALUE_INVALID; |
| 344 | private int mCachedIsHomeProcess = VALUE_INVALID; |
| 345 | private int mCachedIsPreviousProcess = VALUE_INVALID; |
| 346 | private int mCachedHasRecentTasks = VALUE_INVALID; |
| 347 | private int mCachedIsReceivingBroadcast = VALUE_INVALID; |
| 348 | int mCachedAdj = ProcessList.INVALID_ADJ; |
| 349 | boolean mCachedForegroundActivities = false; |
| 350 | int mCachedProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY; |
| 351 | int mCachedSchedGroup = ProcessList.SCHED_GROUP_BACKGROUND; |
| 352 | |
Jing Ji | 619d644 | 2019-11-21 18:26:40 -0800 | [diff] [blame] | 353 | boolean mReachable; // Whether or not this process is reachable from given process |
| 354 | |
Martijn Coenen | e8431c2 | 2019-03-28 14:09:38 +0100 | [diff] [blame] | 355 | void setStartParams(int startUid, HostingRecord hostingRecord, String seInfo, |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 356 | long startTime) { |
| 357 | this.startUid = startUid; |
Martijn Coenen | e8431c2 | 2019-03-28 14:09:38 +0100 | [diff] [blame] | 358 | this.hostingRecord = hostingRecord; |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 359 | this.seInfo = seInfo; |
| 360 | this.startTime = startTime; |
| 361 | } |
| 362 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 364 | final long nowUptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 365 | |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 366 | pw.print(prefix); pw.print("user #"); pw.print(userId); |
| 367 | pw.print(" uid="); pw.print(info.uid); |
| 368 | if (uid != info.uid) { |
| 369 | pw.print(" ISOLATED uid="); pw.print(uid); |
| 370 | } |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 371 | pw.print(" gids={"); |
| 372 | if (gids != null) { |
| 373 | for (int gi=0; gi<gids.length; gi++) { |
| 374 | if (gi != 0) pw.print(", "); |
| 375 | pw.print(gids[gi]); |
| 376 | |
| 377 | } |
| 378 | } |
| 379 | pw.println("}"); |
Dianne Hackborn | 679925b | 2020-02-04 17:02:18 -0800 | [diff] [blame] | 380 | if (processInfo != null) { |
| 381 | pw.print(prefix); pw.println("processInfo:"); |
| 382 | if (processInfo.deniedPermissions != null) { |
| 383 | for (int i = 0; i < processInfo.deniedPermissions.size(); i++) { |
| 384 | pw.print(prefix); pw.print(" deny: "); |
| 385 | pw.println(processInfo.deniedPermissions.valueAt(i)); |
| 386 | } |
| 387 | } |
Evgenii Stepanov | d43d109 | 2020-03-16 13:55:42 -0700 | [diff] [blame] | 388 | if (processInfo.gwpAsanMode != ApplicationInfo.GWP_ASAN_DEFAULT) { |
| 389 | pw.print(prefix); pw.println(" gwpAsanMode=" + processInfo.gwpAsanMode); |
Evgenii Stepanov | 102d3d8 | 2020-02-12 16:48:14 -0800 | [diff] [blame] | 390 | } |
Dianne Hackborn | 679925b | 2020-02-04 17:02:18 -0800 | [diff] [blame] | 391 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 392 | pw.print(prefix); pw.print("mRequiredAbi="); pw.print(mRequiredAbi); |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 393 | pw.print(" instructionSet="); pw.println(instructionSet); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 394 | if (info.className != null) { |
| 395 | pw.print(prefix); pw.print("class="); pw.println(info.className); |
| 396 | } |
| 397 | if (info.manageSpaceActivityName != null) { |
| 398 | pw.print(prefix); pw.print("manageSpaceActivityName="); |
| 399 | pw.println(info.manageSpaceActivityName); |
| 400 | } |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 401 | |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 402 | pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir); |
| 403 | pw.print(" publicDir="); pw.print(info.publicSourceDir); |
| 404 | pw.print(" data="); pw.println(info.dataDir); |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 405 | pw.print(prefix); pw.print("packageList={"); |
| 406 | for (int i=0; i<pkgList.size(); i++) { |
| 407 | if (i > 0) pw.print(", "); |
| 408 | pw.print(pkgList.keyAt(i)); |
| 409 | } |
| 410 | pw.println("}"); |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 411 | if (pkgDeps != null) { |
| 412 | pw.print(prefix); pw.print("packageDependencies={"); |
| 413 | for (int i=0; i<pkgDeps.size(); i++) { |
| 414 | if (i > 0) pw.print(", "); |
| 415 | pw.print(pkgDeps.valueAt(i)); |
| 416 | } |
| 417 | pw.println("}"); |
| 418 | } |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 419 | pw.print(prefix); pw.print("compat="); pw.println(compat); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 420 | if (mInstr != null) { |
| 421 | pw.print(prefix); pw.print("mInstr="); pw.println(mInstr); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 422 | } |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 423 | pw.print(prefix); pw.print("thread="); pw.println(thread); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 424 | pw.print(prefix); pw.print("pid="); pw.print(pid); pw.print(" starting="); |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 425 | pw.println(starting); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 426 | pw.print(prefix); pw.print("lastActivityTime="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 427 | TimeUtils.formatDuration(lastActivityTime, nowUptime, pw); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 428 | pw.print(" lastPssTime="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 429 | TimeUtils.formatDuration(lastPssTime, nowUptime, pw); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 430 | pw.print(" pssStatType="); pw.print(pssStatType); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 431 | pw.print(" nextPssTime="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 432 | TimeUtils.formatDuration(nextPssTime, nowUptime, pw); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 433 | pw.println(); |
Dianne Hackborn | cb6db38 | 2020-05-13 17:03:55 -0700 | [diff] [blame] | 434 | pw.print(prefix); pw.print("lastPss="); DebugUtils.printSizeValue(pw, lastPss * 1024); |
| 435 | pw.print(" lastSwapPss="); DebugUtils.printSizeValue(pw, lastSwapPss * 1024); |
| 436 | pw.print(" lastCachedPss="); DebugUtils.printSizeValue(pw, lastCachedPss * 1024); |
| 437 | pw.print(" lastCachedSwapPss="); DebugUtils.printSizeValue(pw, |
| 438 | lastCachedSwapPss * 1024); |
| 439 | pw.print(" lastRss="); DebugUtils.printSizeValue(pw, mLastRss * 1024); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 440 | pw.println(); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 441 | pw.print(prefix); pw.print("procStateMemTracker: "); |
| 442 | procStateMemTracker.dumpLine(pw); |
Dianne Hackborn | cb6db38 | 2020-05-13 17:03:55 -0700 | [diff] [blame] | 443 | pw.print(prefix); pw.print("adjSeq="); pw.print(adjSeq); |
| 444 | pw.print(" lruSeq="); pw.println(lruSeq); |
| 445 | pw.print(prefix); pw.print("oom adj: max="); pw.print(maxAdj); |
| 446 | pw.print(" curRaw="); pw.print(mCurRawAdj); |
| 447 | pw.print(" setRaw="); pw.print(setRawAdj); |
| 448 | pw.print(" cur="); pw.print(curAdj); |
| 449 | pw.print(" set="); pw.println(setAdj); |
| 450 | pw.print(prefix); pw.print("lastCompactTime="); pw.print(lastCompactTime); |
| 451 | pw.print(" lastCompactAction="); pw.println(lastCompactAction); |
| 452 | pw.print(prefix); pw.print("mCurSchedGroup="); pw.print(mCurSchedGroup); |
| 453 | pw.print(" setSchedGroup="); pw.print(setSchedGroup); |
| 454 | pw.print(" systemNoUi="); pw.print(systemNoUi); |
| 455 | pw.print(" trimMemoryLevel="); pw.println(trimMemoryLevel); |
| 456 | pw.print(prefix); pw.print("curProcState="); pw.print(getCurProcState()); |
| 457 | pw.print(" mRepProcState="); pw.print(mRepProcState); |
| 458 | pw.print(" pssProcState="); pw.print(pssProcState); |
| 459 | pw.print(" setProcState="); pw.print(setProcState); |
| 460 | pw.print(" lastStateTime="); |
| 461 | TimeUtils.formatDuration(lastStateTime, nowUptime, pw); |
| 462 | pw.println(); |
| 463 | pw.print(prefix); pw.print("curCapability="); |
| 464 | ActivityManager.printCapabilitiesFull(pw, curCapability); |
| 465 | pw.print(" setCapability="); |
| 466 | ActivityManager.printCapabilitiesFull(pw, setCapability); |
| 467 | pw.println(); |
| 468 | if (hasShownUi || mPendingUiClean || hasAboveClient || treatLikeActivity) { |
| 469 | pw.print(prefix); pw.print("hasShownUi="); pw.print(hasShownUi); |
| 470 | pw.print(" pendingUiClean="); pw.print(mPendingUiClean); |
| 471 | pw.print(" hasAboveClient="); pw.print(hasAboveClient); |
| 472 | pw.print(" treatLikeActivity="); pw.println(treatLikeActivity); |
| 473 | } |
Darryl L Johnson | 72aac10 | 2020-01-15 15:16:36 -0800 | [diff] [blame] | 474 | pw.print(prefix); pw.print("cached="); pw.print(mCached); |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 475 | pw.print(" empty="); pw.println(empty); |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 476 | if (serviceb) { |
| 477 | pw.print(prefix); pw.print("serviceb="); pw.print(serviceb); |
| 478 | pw.print(" serviceHighRam="); pw.println(serviceHighRam); |
| 479 | } |
Dianne Hackborn | 35f72be | 2013-09-16 10:57:39 -0700 | [diff] [blame] | 480 | if (notCachedSinceIdle) { |
| 481 | pw.print(prefix); pw.print("notCachedSinceIdle="); pw.print(notCachedSinceIdle); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 482 | pw.print(" initialIdlePss="); pw.println(initialIdlePss); |
Dianne Hackborn | 35f72be | 2013-09-16 10:57:39 -0700 | [diff] [blame] | 483 | } |
Dianne Hackborn | a631d56 | 2018-11-20 15:58:15 -0800 | [diff] [blame] | 484 | if (connectionService != null || connectionGroup != 0) { |
| 485 | pw.print(prefix); pw.print("connectionGroup="); pw.print(connectionGroup); |
| 486 | pw.print(" Importance="); pw.print(connectionImportance); |
| 487 | pw.print(" Service="); pw.println(connectionService); |
| 488 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 489 | if (hasTopUi() || hasOverlayUi() || runningRemoteAnimation) { |
| 490 | pw.print(prefix); pw.print("hasTopUi="); pw.print(hasTopUi()); |
| 491 | pw.print(" hasOverlayUi="); pw.print(hasOverlayUi()); |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 492 | pw.print(" runningRemoteAnimation="); pw.println(runningRemoteAnimation); |
Dianne Hackborn | a1baf73 | 2017-05-25 15:33:53 -0700 | [diff] [blame] | 493 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 494 | if (mHasForegroundServices || forcingToImportant != null) { |
| 495 | pw.print(prefix); pw.print("mHasForegroundServices="); pw.print(mHasForegroundServices); |
Dianne Hackborn | f965f40 | 2017-05-04 23:27:23 -0700 | [diff] [blame] | 496 | pw.print(" forcingToImportant="); pw.println(forcingToImportant); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 497 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 498 | if (reportedInteraction || mFgInteractionTime != 0) { |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 499 | pw.print(prefix); pw.print("reportedInteraction="); |
| 500 | pw.print(reportedInteraction); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 501 | if (mInteractionEventTime != 0) { |
Dianne Hackborn | fcc95a6 | 2015-11-02 13:43:29 -0800 | [diff] [blame] | 502 | pw.print(" time="); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 503 | TimeUtils.formatDuration(mInteractionEventTime, SystemClock.elapsedRealtime(), pw); |
Dianne Hackborn | fcc95a6 | 2015-11-02 13:43:29 -0800 | [diff] [blame] | 504 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 505 | if (mFgInteractionTime != 0) { |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 506 | pw.print(" fgInteractionTime="); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 507 | TimeUtils.formatDuration(mFgInteractionTime, SystemClock.elapsedRealtime(), pw); |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 508 | } |
| 509 | pw.println(); |
| 510 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 511 | if (mPersistent || removed) { |
| 512 | pw.print(prefix); pw.print("persistent="); pw.print(mPersistent); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 513 | pw.print(" removed="); pw.println(removed); |
| 514 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 515 | if (mHasClientActivities || mHasForegroundActivities || repForegroundActivities) { |
| 516 | pw.print(prefix); pw.print("hasClientActivities="); pw.print(mHasClientActivities); |
| 517 | pw.print(" foregroundActivities="); pw.print(mHasForegroundActivities); |
Dianne Hackborn | 684bf34 | 2014-04-29 17:56:57 -0700 | [diff] [blame] | 518 | pw.print(" (rep="); pw.print(repForegroundActivities); pw.println(")"); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 519 | } |
Dianne Hackborn | 1a40564 | 2015-11-04 12:32:45 -0800 | [diff] [blame] | 520 | if (lastProviderTime > 0) { |
| 521 | pw.print(prefix); pw.print("lastProviderTime="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 522 | TimeUtils.formatDuration(lastProviderTime, nowUptime, pw); |
Dianne Hackborn | 1a40564 | 2015-11-04 12:32:45 -0800 | [diff] [blame] | 523 | pw.println(); |
| 524 | } |
Amith Yamasani | e5bfeee | 2018-09-05 18:52:35 -0700 | [diff] [blame] | 525 | if (lastTopTime > 0) { |
| 526 | pw.print(prefix); pw.print("lastTopTime="); |
| 527 | TimeUtils.formatDuration(lastTopTime, nowUptime, pw); |
| 528 | pw.println(); |
| 529 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 530 | if (hasStartedServices) { |
| 531 | pw.print(prefix); pw.print("hasStartedServices="); pw.println(hasStartedServices); |
| 532 | } |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 533 | if (pendingStart) { |
| 534 | pw.print(prefix); pw.print("pendingStart="); pw.println(pendingStart); |
| 535 | } |
| 536 | pw.print(prefix); pw.print("startSeq="); pw.println(startSeq); |
Sudheer Shanka | 87915d6 | 2018-11-06 10:57:35 -0800 | [diff] [blame] | 537 | pw.print(prefix); pw.print("mountMode="); pw.println( |
| 538 | DebugUtils.valueToString(Zygote.class, "MOUNT_EXTERNAL_", mountMode)); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 539 | if (setProcState > ActivityManager.PROCESS_STATE_SERVICE) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 540 | pw.print(prefix); pw.print("lastCpuTime="); pw.print(lastCpuTime); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 541 | if (lastCpuTime > 0) { |
| 542 | pw.print(" timeUsed="); |
| 543 | TimeUtils.formatDuration(curCpuTime - lastCpuTime, pw); |
| 544 | } |
| 545 | pw.print(" whenUnimportant="); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 546 | TimeUtils.formatDuration(mWhenUnimportant - nowUptime, pw); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 547 | pw.println(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 548 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 549 | pw.print(prefix); pw.print("lastRequestedGc="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 550 | TimeUtils.formatDuration(lastRequestedGc, nowUptime, pw); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 551 | pw.print(" lastLowMemory="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 552 | TimeUtils.formatDuration(lastLowMemory, nowUptime, pw); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 553 | pw.print(" reportLowMemory="); pw.println(reportLowMemory); |
Dianne Hackborn | d412563 | 2014-09-22 12:52:49 -0700 | [diff] [blame] | 554 | if (killed || killedByAm || waitingToKill != null) { |
| 555 | pw.print(prefix); pw.print("killed="); pw.print(killed); |
| 556 | pw.print(" killedByAm="); pw.print(killedByAm); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 557 | pw.print(" waitingToKill="); pw.println(waitingToKill); |
Dianne Hackborn | 149427c | 2010-04-23 14:20:03 -0700 | [diff] [blame] | 558 | } |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 559 | if (mDebugging || mCrashing || mDialogController.hasCrashDialogs() || mNotResponding |
| 560 | || mDialogController.hasAnrDialogs() || bad) { |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 561 | pw.print(prefix); pw.print("mDebugging="); pw.print(mDebugging); |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 562 | pw.print(" mCrashing=" + mCrashing); |
| 563 | pw.print(" " + mDialogController.mCrashDialogs); |
| 564 | pw.print(" mNotResponding=" + mNotResponding); |
| 565 | pw.print(" " + mDialogController.mAnrDialogs); |
| 566 | pw.print(" bad=" + bad); |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 567 | |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 568 | // mCrashing or mNotResponding is always set before errorReportReceiver |
| 569 | if (errorReportReceiver != null) { |
| 570 | pw.print(" errorReportReceiver="); |
| 571 | pw.print(errorReportReceiver.flattenToShortString()); |
| 572 | } |
| 573 | pw.println(); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 574 | } |
Felipe Leme | a1b79bf | 2016-05-24 13:06:54 -0700 | [diff] [blame] | 575 | if (whitelistManager) { |
| 576 | pw.print(prefix); pw.print("whitelistManager="); pw.println(whitelistManager); |
| 577 | } |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 578 | if (isolatedEntryPoint != null || isolatedEntryPointArgs != null) { |
| 579 | pw.print(prefix); pw.print("isolatedEntryPoint="); pw.println(isolatedEntryPoint); |
| 580 | pw.print(prefix); pw.print("isolatedEntryPointArgs="); |
| 581 | pw.println(Arrays.toString(isolatedEntryPointArgs)); |
| 582 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 583 | mWindowProcessController.dump(pw, prefix); |
Darryl L Johnson | d02044c | 2020-04-17 11:52:50 -0700 | [diff] [blame] | 584 | if (mServices.size() > 0) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 585 | pw.print(prefix); pw.println("Services:"); |
Darryl L Johnson | d02044c | 2020-04-17 11:52:50 -0700 | [diff] [blame] | 586 | for (int i = 0; i < mServices.size(); i++) { |
| 587 | pw.print(prefix); pw.print(" - "); pw.println(mServices.valueAt(i)); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 588 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 589 | } |
| 590 | if (executingServices.size() > 0) { |
Dianne Hackborn | bf36ee2 | 2013-07-26 18:24:10 -0700 | [diff] [blame] | 591 | pw.print(prefix); pw.print("Executing Services (fg="); |
| 592 | pw.print(execServicesFg); pw.println(")"); |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 593 | for (int i=0; i<executingServices.size(); i++) { |
| 594 | pw.print(prefix); pw.print(" - "); pw.println(executingServices.valueAt(i)); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 595 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 596 | } |
| 597 | if (connections.size() > 0) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 598 | pw.print(prefix); pw.println("Connections:"); |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 599 | for (int i=0; i<connections.size(); i++) { |
| 600 | pw.print(prefix); pw.print(" - "); pw.println(connections.valueAt(i)); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 601 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 602 | } |
| 603 | if (pubProviders.size() > 0) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 604 | pw.print(prefix); pw.println("Published Providers:"); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 605 | for (int i=0; i<pubProviders.size(); i++) { |
| 606 | pw.print(prefix); pw.print(" - "); pw.println(pubProviders.keyAt(i)); |
| 607 | pw.print(prefix); pw.print(" -> "); pw.println(pubProviders.valueAt(i)); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 608 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 609 | } |
| 610 | if (conProviders.size() > 0) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 611 | pw.print(prefix); pw.println("Connected Providers:"); |
| 612 | for (int i=0; i<conProviders.size(); i++) { |
| 613 | pw.print(prefix); pw.print(" - "); pw.println(conProviders.get(i).toShortString()); |
| 614 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 615 | } |
yangzhenyu | d509bc9 | 2016-08-31 18:26:46 +0800 | [diff] [blame] | 616 | if (!curReceivers.isEmpty()) { |
| 617 | pw.print(prefix); pw.println("Current Receivers:"); |
| 618 | for (int i=0; i < curReceivers.size(); i++) { |
| 619 | pw.print(prefix); pw.print(" - "); pw.println(curReceivers.valueAt(i)); |
| 620 | } |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 621 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 622 | if (receivers.size() > 0) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 623 | pw.print(prefix); pw.println("Receivers:"); |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 624 | for (int i=0; i<receivers.size(); i++) { |
| 625 | pw.print(prefix); pw.print(" - "); pw.println(receivers.valueAt(i)); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 626 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 627 | } |
Edward Cunningham | de66176 | 2019-03-27 15:51:56 +0000 | [diff] [blame] | 628 | if (mAllowBackgroundActivityStartsTokens.size() > 0) { |
| 629 | pw.print(prefix); pw.println("Background activity start whitelist tokens:"); |
| 630 | for (int i = 0; i < mAllowBackgroundActivityStartsTokens.size(); i++) { |
| 631 | pw.print(prefix); pw.print(" - "); |
| 632 | pw.println(mAllowBackgroundActivityStartsTokens.valueAt(i)); |
| 633 | } |
| 634 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 636 | |
Bookatz | 152623f | 2018-07-23 15:57:44 -0700 | [diff] [blame] | 637 | ProcessRecord(ActivityManagerService _service, ApplicationInfo _info, String _processName, |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 638 | int _uid) { |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 639 | mService = _service; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | info = _info; |
Dianne Hackborn | fc0839a | 2020-01-31 11:02:28 -0800 | [diff] [blame] | 641 | ProcessInfo procInfo = null; |
Dianne Hackborn | f6729fa | 2020-01-06 13:12:36 -0800 | [diff] [blame] | 642 | if (_service.mPackageManagerInt != null) { |
| 643 | ArrayMap<String, ProcessInfo> processes = |
| 644 | _service.mPackageManagerInt.getProcessesForUid(_uid); |
Dianne Hackborn | fc0839a | 2020-01-31 11:02:28 -0800 | [diff] [blame] | 645 | if (processes != null) { |
| 646 | procInfo = processes.get(_processName); |
Evgenii Stepanov | d43d109 | 2020-03-16 13:55:42 -0700 | [diff] [blame] | 647 | if (procInfo != null && procInfo.deniedPermissions == null |
| 648 | && procInfo.gwpAsanMode == ApplicationInfo.GWP_ASAN_DEFAULT) { |
| 649 | // If this process hasn't asked for permissions to be denied, or for a |
| 650 | // non-default GwpAsan mode, then we don't care about it. |
Dianne Hackborn | fc0839a | 2020-01-31 11:02:28 -0800 | [diff] [blame] | 651 | procInfo = null; |
| 652 | } |
| 653 | } |
Dianne Hackborn | f6729fa | 2020-01-06 13:12:36 -0800 | [diff] [blame] | 654 | } |
Dianne Hackborn | fc0839a | 2020-01-31 11:02:28 -0800 | [diff] [blame] | 655 | processInfo = procInfo; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 656 | isolated = _info.uid != _uid; |
Martijn Coenen | 01e719b | 2018-12-05 16:01:38 +0100 | [diff] [blame] | 657 | appZygote = (UserHandle.getAppId(_uid) >= Process.FIRST_APP_ZYGOTE_ISOLATED_UID |
| 658 | && UserHandle.getAppId(_uid) <= Process.LAST_APP_ZYGOTE_ISOLATED_UID); |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 659 | uid = _uid; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 660 | userId = UserHandle.getUserId(_uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 661 | processName = _processName; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 662 | maxAdj = ProcessList.UNKNOWN_ADJ; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 663 | mCurRawAdj = setRawAdj = ProcessList.INVALID_ADJ; |
Dianne Hackborn | 4de5a3a | 2016-06-20 15:20:15 -0700 | [diff] [blame] | 664 | curAdj = setAdj = verifiedAdj = ProcessList.INVALID_ADJ; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 665 | mPersistent = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 666 | removed = false; |
Marco Ballesio | bdaf16e | 2020-01-23 13:57:00 -0800 | [diff] [blame] | 667 | freezeUnfreezeTime = lastStateTime = lastPssTime = nextPssTime = SystemClock.uptimeMillis(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 668 | mWindowProcessController = new WindowProcessController( |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 669 | mService.mActivityTaskManager, info, processName, uid, userId, this, this); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 670 | pkgList.put(_info.packageName, new ProcessStats.ProcessStateHolder(_info.longVersionCode)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 671 | } |
| 672 | |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 673 | public void setPid(int _pid) { |
| 674 | pid = _pid; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 675 | mWindowProcessController.setPid(pid); |
Dianne Hackborn | 4de5a3a | 2016-06-20 15:20:15 -0700 | [diff] [blame] | 676 | procStatFile = null; |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 677 | shortStringName = null; |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 678 | stringName = null; |
| 679 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 680 | |
| 681 | public void makeActive(IApplicationThread _thread, ProcessStatsService tracker) { |
| 682 | if (thread == null) { |
Joe Onorato | 4eb64fd | 2016-03-21 15:30:09 -0700 | [diff] [blame] | 683 | final ProcessState origBase = baseProcessTracker; |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 684 | if (origBase != null) { |
| 685 | origBase.setState(ProcessStats.STATE_NOTHING, |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 686 | tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList); |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 687 | for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) { |
Muhammad Qureshi | edd80fd | 2020-01-27 17:23:07 -0800 | [diff] [blame] | 688 | FrameworkStatsLog.write(FrameworkStatsLog.PROCESS_STATE_CHANGED, |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 689 | uid, processName, pkgList.keyAt(ipkg), |
| 690 | ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING), |
| 691 | pkgList.valueAt(ipkg).appVersion); |
| 692 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 693 | origBase.makeInactive(); |
| 694 | } |
Dianne Hackborn | 2f55e5a | 2018-11-30 16:31:31 -0800 | [diff] [blame] | 695 | baseProcessTracker = tracker.getProcessStateLocked(info.packageName, info.uid, |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 696 | info.longVersionCode, processName); |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 697 | baseProcessTracker.makeActive(); |
| 698 | for (int i=0; i<pkgList.size(); i++) { |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 699 | ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i); |
| 700 | if (holder.state != null && holder.state != origBase) { |
| 701 | holder.state.makeInactive(); |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 702 | } |
Dianne Hackborn | 2f55e5a | 2018-11-30 16:31:31 -0800 | [diff] [blame] | 703 | tracker.updateProcessStateHolderLocked(holder, pkgList.keyAt(i), info.uid, |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 704 | info.longVersionCode, processName); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 705 | if (holder.state != baseProcessTracker) { |
| 706 | holder.state.makeActive(); |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 707 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 708 | } |
| 709 | } |
| 710 | thread = _thread; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 711 | mWindowProcessController.setThread(thread); |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | public void makeInactive(ProcessStatsService tracker) { |
Dianne Hackborn | 53459a7 | 2013-09-17 17:14:57 -0700 | [diff] [blame] | 715 | thread = null; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 716 | mWindowProcessController.setThread(null); |
Joe Onorato | 4eb64fd | 2016-03-21 15:30:09 -0700 | [diff] [blame] | 717 | final ProcessState origBase = baseProcessTracker; |
Dianne Hackborn | 53459a7 | 2013-09-17 17:14:57 -0700 | [diff] [blame] | 718 | if (origBase != null) { |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 719 | if (origBase != null) { |
| 720 | origBase.setState(ProcessStats.STATE_NOTHING, |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 721 | tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList); |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 722 | for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) { |
Muhammad Qureshi | edd80fd | 2020-01-27 17:23:07 -0800 | [diff] [blame] | 723 | FrameworkStatsLog.write(FrameworkStatsLog.PROCESS_STATE_CHANGED, |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 724 | uid, processName, pkgList.keyAt(ipkg), |
| 725 | ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING), |
| 726 | pkgList.valueAt(ipkg).appVersion); |
| 727 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 728 | origBase.makeInactive(); |
| 729 | } |
| 730 | baseProcessTracker = null; |
| 731 | for (int i=0; i<pkgList.size(); i++) { |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 732 | ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i); |
| 733 | if (holder.state != null && holder.state != origBase) { |
| 734 | holder.state.makeInactive(); |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 735 | } |
Dianne Hackborn | 2aec55a | 2018-06-26 10:35:35 -0700 | [diff] [blame] | 736 | holder.pkg = null; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 737 | holder.state = null; |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | } |
| 741 | |
Darryl L Johnson | d02044c | 2020-04-17 11:52:50 -0700 | [diff] [blame] | 742 | /** |
| 743 | * Records a service as running in the process. Note that this method does not actually start |
| 744 | * the service, but records the service as started for bookkeeping. |
| 745 | * |
| 746 | * @return true if the service was added, false otherwise. |
| 747 | */ |
| 748 | boolean startService(ServiceRecord record) { |
| 749 | if (record == null) { |
| 750 | return false; |
| 751 | } |
| 752 | boolean added = mServices.add(record); |
| 753 | if (added && record.serviceInfo != null) { |
| 754 | mWindowProcessController.onServiceStarted(record.serviceInfo); |
| 755 | } |
| 756 | return added; |
| 757 | } |
| 758 | |
| 759 | /** |
| 760 | * Records a service as stopped. Note that like {@link #startService(ServiceRecord)} this method |
| 761 | * does not actually stop the service, but records the service as stopped for bookkeeping. |
| 762 | * |
| 763 | * @return true if the service was removed, false otherwise. |
| 764 | */ |
| 765 | boolean stopService(ServiceRecord record) { |
| 766 | return mServices.remove(record); |
| 767 | } |
| 768 | |
| 769 | /** |
| 770 | * The same as calling {@link #stopService(ServiceRecord)} on all current running services. |
| 771 | */ |
| 772 | void stopAllServices() { |
| 773 | mServices.clear(); |
| 774 | } |
| 775 | |
| 776 | /** |
| 777 | * Returns the number of services added with {@link #startService(ServiceRecord)} and not yet |
| 778 | * removed by a call to {@link #stopService(ServiceRecord)} or {@link #stopAllServices()}. |
| 779 | * |
| 780 | * @see #startService(ServiceRecord) |
| 781 | * @see #stopService(ServiceRecord) |
| 782 | */ |
| 783 | int numberOfRunningServices() { |
| 784 | return mServices.size(); |
| 785 | } |
| 786 | |
| 787 | /** |
| 788 | * Returns the service at the specified {@code index}. |
| 789 | * |
| 790 | * @see #numberOfRunningServices() |
| 791 | */ |
| 792 | ServiceRecord getRunningServiceAt(int index) { |
| 793 | return mServices.valueAt(index); |
| 794 | } |
| 795 | |
Darryl L Johnson | 72aac10 | 2020-01-15 15:16:36 -0800 | [diff] [blame] | 796 | void setCached(boolean cached) { |
Darryl L Johnson | 15192d3 | 2020-01-15 15:31:42 -0800 | [diff] [blame] | 797 | if (mCached != cached) { |
| 798 | mCached = cached; |
| 799 | mWindowProcessController.onProcCachedStateChanged(cached); |
| 800 | } |
Darryl L Johnson | 72aac10 | 2020-01-15 15:16:36 -0800 | [diff] [blame] | 801 | } |
| 802 | |
Darryl L Johnson | 15192d3 | 2020-01-15 15:31:42 -0800 | [diff] [blame] | 803 | @Override |
| 804 | public boolean isCached() { |
Darryl L Johnson | 72aac10 | 2020-01-15 15:16:36 -0800 | [diff] [blame] | 805 | return mCached; |
| 806 | } |
| 807 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 808 | boolean hasActivities() { |
| 809 | return mWindowProcessController.hasActivities(); |
| 810 | } |
| 811 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 812 | boolean hasActivitiesOrRecentTasks() { |
| 813 | return mWindowProcessController.hasActivitiesOrRecentTasks(); |
| 814 | } |
| 815 | |
| 816 | boolean hasRecentTasks() { |
| 817 | return mWindowProcessController.hasRecentTasks(); |
| 818 | } |
| 819 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | /** |
| 821 | * This method returns true if any of the activities within the process record are interesting |
| 822 | * to the user. See HistoryRecord.isInterestingToUserLocked() |
| 823 | */ |
| 824 | public boolean isInterestingToUserLocked() { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 825 | if (mWindowProcessController.isInterestingToUser()) { |
| 826 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 827 | } |
Narayan Kamath | a22d9fb | 2017-04-26 15:14:26 +0100 | [diff] [blame] | 828 | |
Darryl L Johnson | d02044c | 2020-04-17 11:52:50 -0700 | [diff] [blame] | 829 | final int servicesSize = mServices.size(); |
Narayan Kamath | a22d9fb | 2017-04-26 15:14:26 +0100 | [diff] [blame] | 830 | for (int i = 0; i < servicesSize; i++) { |
Darryl L Johnson | d02044c | 2020-04-17 11:52:50 -0700 | [diff] [blame] | 831 | ServiceRecord r = mServices.valueAt(i); |
Narayan Kamath | a22d9fb | 2017-04-26 15:14:26 +0100 | [diff] [blame] | 832 | if (r.isForeground) { |
| 833 | return true; |
| 834 | } |
| 835 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 836 | return false; |
| 837 | } |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 838 | |
Dianne Hackborn | 1b64e0d | 2011-07-17 15:23:59 -0700 | [diff] [blame] | 839 | public void unlinkDeathRecipient() { |
| 840 | if (deathRecipient != null && thread != null) { |
| 841 | thread.asBinder().unlinkToDeath(deathRecipient, 0); |
| 842 | } |
| 843 | deathRecipient = null; |
| 844 | } |
| 845 | |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 846 | void updateHasAboveClientLocked() { |
| 847 | hasAboveClient = false; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 848 | for (int i=connections.size()-1; i>=0; i--) { |
| 849 | ConnectionRecord cr = connections.valueAt(i); |
| 850 | if ((cr.flags&Context.BIND_ABOVE_CLIENT) != 0) { |
| 851 | hasAboveClient = true; |
| 852 | break; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 853 | } |
| 854 | } |
| 855 | } |
| 856 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 857 | int modifyRawOomAdj(int adj) { |
| 858 | if (hasAboveClient) { |
| 859 | // If this process has bound to any services with BIND_ABOVE_CLIENT, |
| 860 | // then we need to drop its adjustment to be lower than the service's |
| 861 | // in order to honor the request. We want to drop it by one adjustment |
| 862 | // level... but there is special meaning applied to various levels so |
| 863 | // we will skip some of them. |
| 864 | if (adj < ProcessList.FOREGROUND_APP_ADJ) { |
| 865 | // System process will not get dropped, ever |
| 866 | } else if (adj < ProcessList.VISIBLE_APP_ADJ) { |
| 867 | adj = ProcessList.VISIBLE_APP_ADJ; |
| 868 | } else if (adj < ProcessList.PERCEPTIBLE_APP_ADJ) { |
| 869 | adj = ProcessList.PERCEPTIBLE_APP_ADJ; |
Amith Yamasani | 0567ec6 | 2019-01-23 11:11:02 -0800 | [diff] [blame] | 870 | } else if (adj < ProcessList.PERCEPTIBLE_LOW_APP_ADJ) { |
| 871 | adj = ProcessList.PERCEPTIBLE_LOW_APP_ADJ; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 872 | } else if (adj < ProcessList.CACHED_APP_MIN_ADJ) { |
| 873 | adj = ProcessList.CACHED_APP_MIN_ADJ; |
| 874 | } else if (adj < ProcessList.CACHED_APP_MAX_ADJ) { |
| 875 | adj++; |
| 876 | } |
| 877 | } |
| 878 | return adj; |
| 879 | } |
| 880 | |
Joe Onorato | 5719028 | 2016-04-20 15:37:49 -0700 | [diff] [blame] | 881 | void scheduleCrash(String message) { |
| 882 | // Checking killedbyAm should keep it from showing the crash dialog if the process |
| 883 | // was already dead for a good / normal reason. |
| 884 | if (!killedByAm) { |
| 885 | if (thread != null) { |
| 886 | if (pid == Process.myPid()) { |
| 887 | Slog.w(TAG, "scheduleCrash: trying to crash system process!"); |
| 888 | return; |
| 889 | } |
| 890 | long ident = Binder.clearCallingIdentity(); |
| 891 | try { |
| 892 | thread.scheduleCrash(message); |
| 893 | } catch (RemoteException e) { |
| 894 | // If it's already dead our work is done. If it's wedged just kill it. |
| 895 | // We won't get the crash dialog or the error reporting. |
Jing Ji | 8055a3a | 2019-12-17 15:55:33 -0800 | [diff] [blame] | 896 | kill("scheduleCrash for '" + message + "' failed", |
| 897 | ApplicationExitInfo.REASON_CRASH, true); |
Joe Onorato | 5719028 | 2016-04-20 15:37:49 -0700 | [diff] [blame] | 898 | } finally { |
| 899 | Binder.restoreCallingIdentity(ident); |
| 900 | } |
| 901 | } |
| 902 | } |
| 903 | } |
| 904 | |
Jing Ji | 8055a3a | 2019-12-17 15:55:33 -0800 | [diff] [blame] | 905 | void kill(String reason, @Reason int reasonCode, boolean noisy) { |
| 906 | kill(reason, reasonCode, ApplicationExitInfo.SUBREASON_UNKNOWN, noisy); |
| 907 | } |
| 908 | |
| 909 | void kill(String reason, @Reason int reasonCode, @SubReason int subReason, boolean noisy) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 910 | if (!killedByAm) { |
Yusuke Sato | cf4b254 | 2015-06-17 00:21:28 -0700 | [diff] [blame] | 911 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "kill"); |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 912 | if (mService != null && (noisy || info.uid == mService.mCurOomAdjUid)) { |
| 913 | mService.reportUidInfoMessageLocked(TAG, |
| 914 | "Killing " + toShortString() + " (adj " + setAdj + "): " + reason, |
| 915 | info.uid); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 916 | } |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 917 | if (pid > 0) { |
Jing Ji | 8055a3a | 2019-12-17 15:55:33 -0800 | [diff] [blame] | 918 | mService.mProcessList.noteAppKill(this, reasonCode, subReason, reason); |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 919 | EventLog.writeEvent(EventLogTags.AM_KILL, userId, pid, processName, setAdj, reason); |
| 920 | Process.killProcessQuiet(pid); |
Amith Yamasani | 98a0092 | 2018-08-21 12:50:30 -0400 | [diff] [blame] | 921 | ProcessList.killProcessGroup(uid, pid); |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 922 | } else { |
| 923 | pendingStart = false; |
| 924 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 925 | if (!mPersistent) { |
Dianne Hackborn | d412563 | 2014-09-22 12:52:49 -0700 | [diff] [blame] | 926 | killed = true; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 927 | killedByAm = true; |
| 928 | } |
Yusuke Sato | cf4b254 | 2015-06-17 00:21:28 -0700 | [diff] [blame] | 929 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 930 | } |
| 931 | } |
| 932 | |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 933 | @Override |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 934 | public void dumpDebug(ProtoOutputStream proto, long fieldId) { |
| 935 | dumpDebug(proto, fieldId, -1); |
Dianne Hackborn | 2f55e5a | 2018-11-30 16:31:31 -0800 | [diff] [blame] | 936 | } |
| 937 | |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 938 | public void dumpDebug(ProtoOutputStream proto, long fieldId, int lruIndex) { |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 939 | long token = proto.start(fieldId); |
| 940 | proto.write(ProcessRecordProto.PID, pid); |
| 941 | proto.write(ProcessRecordProto.PROCESS_NAME, processName); |
Dianne Hackborn | 2f55e5a | 2018-11-30 16:31:31 -0800 | [diff] [blame] | 942 | proto.write(ProcessRecordProto.UID, info.uid); |
| 943 | if (UserHandle.getAppId(info.uid) >= Process.FIRST_APPLICATION_UID) { |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 944 | proto.write(ProcessRecordProto.USER_ID, userId); |
| 945 | proto.write(ProcessRecordProto.APP_ID, UserHandle.getAppId(info.uid)); |
Dianne Hackborn | 2f55e5a | 2018-11-30 16:31:31 -0800 | [diff] [blame] | 946 | } |
| 947 | if (uid != info.uid) { |
| 948 | proto.write(ProcessRecordProto.ISOLATED_APP_ID, UserHandle.getAppId(uid)); |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 949 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 950 | proto.write(ProcessRecordProto.PERSISTENT, mPersistent); |
Dianne Hackborn | 2f55e5a | 2018-11-30 16:31:31 -0800 | [diff] [blame] | 951 | if (lruIndex >= 0) { |
| 952 | proto.write(ProcessRecordProto.LRU_INDEX, lruIndex); |
| 953 | } |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 954 | proto.end(token); |
| 955 | } |
| 956 | |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 957 | public String toShortString() { |
| 958 | if (shortStringName != null) { |
| 959 | return shortStringName; |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 960 | } |
| 961 | StringBuilder sb = new StringBuilder(128); |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 962 | toShortString(sb); |
| 963 | return shortStringName = sb.toString(); |
| 964 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 965 | |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 966 | void toShortString(StringBuilder sb) { |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 967 | sb.append(pid); |
| 968 | sb.append(':'); |
| 969 | sb.append(processName); |
| 970 | sb.append('/'); |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 971 | if (info.uid < Process.FIRST_APPLICATION_UID) { |
| 972 | sb.append(uid); |
| 973 | } else { |
| 974 | sb.append('u'); |
| 975 | sb.append(userId); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 976 | int appId = UserHandle.getAppId(info.uid); |
| 977 | if (appId >= Process.FIRST_APPLICATION_UID) { |
| 978 | sb.append('a'); |
| 979 | sb.append(appId - Process.FIRST_APPLICATION_UID); |
| 980 | } else { |
| 981 | sb.append('s'); |
| 982 | sb.append(appId); |
| 983 | } |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 984 | if (uid != info.uid) { |
| 985 | sb.append('i'); |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 986 | sb.append(UserHandle.getAppId(uid) - Process.FIRST_ISOLATED_UID); |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 987 | } |
| 988 | } |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 989 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 990 | |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 991 | public String toString() { |
| 992 | if (stringName != null) { |
| 993 | return stringName; |
| 994 | } |
| 995 | StringBuilder sb = new StringBuilder(128); |
| 996 | sb.append("ProcessRecord{"); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 997 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 998 | sb.append(' '); |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 999 | toShortString(sb); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 1000 | sb.append('}'); |
| 1001 | return stringName = sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1002 | } |
Dianne Hackborn | 9210bc8 | 2013-09-05 12:31:16 -0700 | [diff] [blame] | 1003 | |
| 1004 | public String makeAdjReason() { |
Dianne Hackborn | 9210bc8 | 2013-09-05 12:31:16 -0700 | [diff] [blame] | 1005 | if (adjSource != null || adjTarget != null) { |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 1006 | StringBuilder sb = new StringBuilder(128); |
Dianne Hackborn | 9210bc8 | 2013-09-05 12:31:16 -0700 | [diff] [blame] | 1007 | sb.append(' '); |
| 1008 | if (adjTarget instanceof ComponentName) { |
| 1009 | sb.append(((ComponentName)adjTarget).flattenToShortString()); |
| 1010 | } else if (adjTarget != null) { |
| 1011 | sb.append(adjTarget.toString()); |
| 1012 | } else { |
| 1013 | sb.append("{null}"); |
| 1014 | } |
| 1015 | sb.append("<="); |
| 1016 | if (adjSource instanceof ProcessRecord) { |
| 1017 | sb.append("Proc{"); |
| 1018 | sb.append(((ProcessRecord)adjSource).toShortString()); |
| 1019 | sb.append("}"); |
| 1020 | } else if (adjSource != null) { |
| 1021 | sb.append(adjSource.toString()); |
| 1022 | } else { |
| 1023 | sb.append("{null}"); |
| 1024 | } |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 1025 | return sb.toString(); |
Dianne Hackborn | 9210bc8 | 2013-09-05 12:31:16 -0700 | [diff] [blame] | 1026 | } |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 1027 | return null; |
Dianne Hackborn | 9210bc8 | 2013-09-05 12:31:16 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1030 | /* |
| 1031 | * Return true if package has been added false if not |
| 1032 | */ |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1033 | public boolean addPackage(String pkg, long versionCode, ProcessStatsService tracker) { |
Dianne Hackborn | 78a369c | 2013-06-11 17:10:32 -0700 | [diff] [blame] | 1034 | if (!pkgList.containsKey(pkg)) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1035 | ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder( |
| 1036 | versionCode); |
Dianne Hackborn | 53459a7 | 2013-09-17 17:14:57 -0700 | [diff] [blame] | 1037 | if (baseProcessTracker != null) { |
Dianne Hackborn | 2f55e5a | 2018-11-30 16:31:31 -0800 | [diff] [blame] | 1038 | tracker.updateProcessStateHolderLocked(holder, pkg, info.uid, versionCode, |
| 1039 | processName); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 1040 | pkgList.put(pkg, holder); |
| 1041 | if (holder.state != baseProcessTracker) { |
| 1042 | holder.state.makeActive(); |
Dianne Hackborn | 53459a7 | 2013-09-17 17:14:57 -0700 | [diff] [blame] | 1043 | } |
| 1044 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1045 | pkgList.put(pkg, holder); |
Dianne Hackborn | 53459a7 | 2013-09-17 17:14:57 -0700 | [diff] [blame] | 1046 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1047 | return true; |
| 1048 | } |
| 1049 | return false; |
| 1050 | } |
Dianne Hackborn | 78a369c | 2013-06-11 17:10:32 -0700 | [diff] [blame] | 1051 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1052 | public int getSetAdjWithServices() { |
Dianne Hackborn | 20cdcee | 2013-07-10 18:47:04 -0700 | [diff] [blame] | 1053 | if (setAdj >= ProcessList.CACHED_APP_MIN_ADJ) { |
| 1054 | if (hasStartedServices) { |
| 1055 | return ProcessList.SERVICE_B_ADJ; |
| 1056 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1057 | } |
| 1058 | return setAdj; |
| 1059 | } |
| 1060 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1061 | public void forceProcessStateUpTo(int newState) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1062 | if (mRepProcState > newState) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1063 | mRepProcState = newState; |
| 1064 | setCurProcState(newState); |
Amith Yamasani | 08888c0 | 2018-12-07 09:38:25 -0800 | [diff] [blame] | 1065 | setCurRawProcState(newState); |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 1066 | for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) { |
Muhammad Qureshi | edd80fd | 2020-01-27 17:23:07 -0800 | [diff] [blame] | 1067 | FrameworkStatsLog.write(FrameworkStatsLog.PROCESS_STATE_CHANGED, |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 1068 | uid, processName, pkgList.keyAt(ipkg), |
| 1069 | ActivityManager.processStateAmToProto(mRepProcState), |
| 1070 | pkgList.valueAt(ipkg).appVersion); |
| 1071 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1072 | } |
| 1073 | } |
| 1074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1075 | /* |
| 1076 | * Delete all packages from list except the package indicated in info |
| 1077 | */ |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 1078 | public void resetPackageList(ProcessStatsService tracker) { |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 1079 | final int N = pkgList.size(); |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 1080 | if (baseProcessTracker != null) { |
| 1081 | long now = SystemClock.uptimeMillis(); |
| 1082 | baseProcessTracker.setState(ProcessStats.STATE_NOTHING, |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1083 | tracker.getMemFactorLocked(), now, pkgList.mPkgList); |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 1084 | for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) { |
Muhammad Qureshi | edd80fd | 2020-01-27 17:23:07 -0800 | [diff] [blame] | 1085 | FrameworkStatsLog.write(FrameworkStatsLog.PROCESS_STATE_CHANGED, |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 1086 | uid, processName, pkgList.keyAt(ipkg), |
| 1087 | ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING), |
| 1088 | pkgList.valueAt(ipkg).appVersion); |
| 1089 | } |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 1090 | if (N != 1) { |
| 1091 | for (int i=0; i<N; i++) { |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 1092 | ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i); |
| 1093 | if (holder.state != null && holder.state != baseProcessTracker) { |
| 1094 | holder.state.makeInactive(); |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 1095 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 1096 | |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 1097 | } |
| 1098 | pkgList.clear(); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 1099 | ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder( |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 1100 | info.longVersionCode); |
Dianne Hackborn | 2f55e5a | 2018-11-30 16:31:31 -0800 | [diff] [blame] | 1101 | tracker.updateProcessStateHolderLocked(holder, info.packageName, info.uid, |
Dianne Hackborn | 2aec55a | 2018-06-26 10:35:35 -0700 | [diff] [blame] | 1102 | info.longVersionCode, processName); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 1103 | pkgList.put(info.packageName, holder); |
Dianne Hackborn | 2aec55a | 2018-06-26 10:35:35 -0700 | [diff] [blame] | 1104 | if (holder.state != baseProcessTracker) { |
| 1105 | holder.state.makeActive(); |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 1106 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 1107 | } |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 1108 | } else if (N != 1) { |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 1109 | pkgList.clear(); |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 1110 | pkgList.put(info.packageName, new ProcessStats.ProcessStateHolder(info.longVersionCode)); |
Dianne Hackborn | 78a369c | 2013-06-11 17:10:32 -0700 | [diff] [blame] | 1111 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 1113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1114 | public String[] getPackageList() { |
| 1115 | int size = pkgList.size(); |
| 1116 | if (size == 0) { |
| 1117 | return null; |
| 1118 | } |
| 1119 | String list[] = new String[size]; |
Dianne Hackborn | 78a369c | 2013-06-11 17:10:32 -0700 | [diff] [blame] | 1120 | for (int i=0; i<pkgList.size(); i++) { |
| 1121 | list[i] = pkgList.keyAt(i); |
| 1122 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1123 | return list; |
| 1124 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1125 | |
Zimuzo | 972e1cd | 2019-01-28 16:30:01 +0000 | [diff] [blame] | 1126 | public List<VersionedPackage> getPackageListWithVersionCode() { |
| 1127 | int size = pkgList.size(); |
| 1128 | if (size == 0) { |
| 1129 | return null; |
| 1130 | } |
| 1131 | List<VersionedPackage> list = new ArrayList<>(); |
| 1132 | for (int i = 0; i < pkgList.size(); i++) { |
| 1133 | list.add(new VersionedPackage(pkgList.keyAt(i), pkgList.valueAt(i).appVersion)); |
| 1134 | } |
| 1135 | return list; |
| 1136 | } |
| 1137 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1138 | WindowProcessController getWindowProcessController() { |
| 1139 | return mWindowProcessController; |
| 1140 | } |
| 1141 | |
| 1142 | void setCurrentSchedulingGroup(int curSchedGroup) { |
| 1143 | mCurSchedGroup = curSchedGroup; |
| 1144 | mWindowProcessController.setCurrentSchedulingGroup(curSchedGroup); |
| 1145 | } |
| 1146 | |
| 1147 | int getCurrentSchedulingGroup() { |
| 1148 | return mCurSchedGroup; |
| 1149 | } |
| 1150 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1151 | void setCurProcState(int curProcState) { |
| 1152 | mCurProcState = curProcState; |
| 1153 | mWindowProcessController.setCurrentProcState(mCurProcState); |
| 1154 | } |
| 1155 | |
| 1156 | int getCurProcState() { |
| 1157 | return mCurProcState; |
| 1158 | } |
| 1159 | |
Amith Yamasani | 08888c0 | 2018-12-07 09:38:25 -0800 | [diff] [blame] | 1160 | void setCurRawProcState(int curRawProcState) { |
| 1161 | mCurRawProcState = curRawProcState; |
| 1162 | } |
| 1163 | |
| 1164 | int getCurRawProcState() { |
| 1165 | return mCurRawProcState; |
| 1166 | } |
| 1167 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1168 | void setReportedProcState(int repProcState) { |
| 1169 | mRepProcState = repProcState; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 1170 | for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) { |
Muhammad Qureshi | edd80fd | 2020-01-27 17:23:07 -0800 | [diff] [blame] | 1171 | FrameworkStatsLog.write(FrameworkStatsLog.PROCESS_STATE_CHANGED, |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 1172 | uid, processName, pkgList.keyAt(ipkg), |
| 1173 | ActivityManager.processStateAmToProto(mRepProcState), |
| 1174 | pkgList.valueAt(ipkg).appVersion); |
| 1175 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1176 | mWindowProcessController.setReportedProcState(repProcState); |
| 1177 | } |
| 1178 | |
| 1179 | int getReportedProcState() { |
| 1180 | return mRepProcState; |
| 1181 | } |
| 1182 | |
| 1183 | void setCrashing(boolean crashing) { |
| 1184 | mCrashing = crashing; |
| 1185 | mWindowProcessController.setCrashing(crashing); |
| 1186 | } |
| 1187 | |
| 1188 | boolean isCrashing() { |
| 1189 | return mCrashing; |
| 1190 | } |
| 1191 | |
| 1192 | void setNotResponding(boolean notResponding) { |
| 1193 | mNotResponding = notResponding; |
| 1194 | mWindowProcessController.setNotResponding(notResponding); |
| 1195 | } |
| 1196 | |
| 1197 | boolean isNotResponding() { |
| 1198 | return mNotResponding; |
| 1199 | } |
| 1200 | |
| 1201 | void setPersistent(boolean persistent) { |
| 1202 | mPersistent = persistent; |
| 1203 | mWindowProcessController.setPersistent(persistent); |
| 1204 | } |
| 1205 | |
| 1206 | boolean isPersistent() { |
| 1207 | return mPersistent; |
| 1208 | } |
| 1209 | |
| 1210 | public void setRequiredAbi(String requiredAbi) { |
| 1211 | mRequiredAbi = requiredAbi; |
| 1212 | mWindowProcessController.setRequiredAbi(requiredAbi); |
| 1213 | } |
| 1214 | |
| 1215 | String getRequiredAbi() { |
| 1216 | return mRequiredAbi; |
| 1217 | } |
| 1218 | |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 1219 | void setHasForegroundServices(boolean hasForegroundServices, int fgServiceTypes) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1220 | mHasForegroundServices = hasForegroundServices; |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 1221 | mFgServiceTypes = fgServiceTypes; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1222 | mWindowProcessController.setHasForegroundServices(hasForegroundServices); |
| 1223 | } |
| 1224 | |
| 1225 | boolean hasForegroundServices() { |
| 1226 | return mHasForegroundServices; |
| 1227 | } |
| 1228 | |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 1229 | boolean hasLocationForegroundServices() { |
| 1230 | return mHasForegroundServices |
| 1231 | && (mFgServiceTypes & ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION) != 0; |
| 1232 | } |
| 1233 | |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 1234 | boolean hasLocationCapability() { |
| 1235 | return (setCapability & ActivityManager.PROCESS_CAPABILITY_FOREGROUND_LOCATION) != 0; |
| 1236 | } |
| 1237 | |
Narayan Kamath | 396ce72 | 2019-03-01 16:53:26 +0000 | [diff] [blame] | 1238 | int getForegroundServiceTypes() { |
| 1239 | return mHasForegroundServices ? mFgServiceTypes : 0; |
| 1240 | } |
| 1241 | |
| 1242 | int getReportedForegroundServiceTypes() { |
| 1243 | return mRepFgServiceTypes; |
| 1244 | } |
| 1245 | |
| 1246 | void setReportedForegroundServiceTypes(int foregroundServiceTypes) { |
| 1247 | mRepFgServiceTypes = foregroundServiceTypes; |
| 1248 | } |
| 1249 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1250 | void setHasForegroundActivities(boolean hasForegroundActivities) { |
| 1251 | mHasForegroundActivities = hasForegroundActivities; |
| 1252 | mWindowProcessController.setHasForegroundActivities(hasForegroundActivities); |
| 1253 | } |
| 1254 | |
| 1255 | boolean hasForegroundActivities() { |
| 1256 | return mHasForegroundActivities; |
| 1257 | } |
| 1258 | |
| 1259 | void setHasClientActivities(boolean hasClientActivities) { |
| 1260 | mHasClientActivities = hasClientActivities; |
| 1261 | mWindowProcessController.setHasClientActivities(hasClientActivities); |
| 1262 | } |
| 1263 | |
| 1264 | boolean hasClientActivities() { |
| 1265 | return mHasClientActivities; |
| 1266 | } |
| 1267 | |
| 1268 | void setHasTopUi(boolean hasTopUi) { |
| 1269 | mHasTopUi = hasTopUi; |
| 1270 | mWindowProcessController.setHasTopUi(hasTopUi); |
Tim Murray | d33c6f8 | 2020-06-19 16:40:47 +0000 | [diff] [blame] | 1271 | updateTopUiOrRunningRemoteAnim(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | boolean hasTopUi() { |
| 1275 | return mHasTopUi; |
| 1276 | } |
| 1277 | |
| 1278 | void setHasOverlayUi(boolean hasOverlayUi) { |
| 1279 | mHasOverlayUi = hasOverlayUi; |
| 1280 | mWindowProcessController.setHasOverlayUi(hasOverlayUi); |
| 1281 | } |
| 1282 | |
| 1283 | boolean hasOverlayUi() { |
| 1284 | return mHasOverlayUi; |
| 1285 | } |
| 1286 | |
| 1287 | void setInteractionEventTime(long interactionEventTime) { |
| 1288 | mInteractionEventTime = interactionEventTime; |
| 1289 | mWindowProcessController.setInteractionEventTime(interactionEventTime); |
| 1290 | } |
| 1291 | |
| 1292 | long getInteractionEventTime() { |
| 1293 | return mInteractionEventTime; |
| 1294 | } |
| 1295 | |
| 1296 | void setFgInteractionTime(long fgInteractionTime) { |
| 1297 | mFgInteractionTime = fgInteractionTime; |
| 1298 | mWindowProcessController.setFgInteractionTime(fgInteractionTime); |
| 1299 | } |
| 1300 | |
| 1301 | long getFgInteractionTime() { |
| 1302 | return mFgInteractionTime; |
| 1303 | } |
| 1304 | |
| 1305 | void setWhenUnimportant(long whenUnimportant) { |
| 1306 | mWhenUnimportant = whenUnimportant; |
| 1307 | mWindowProcessController.setWhenUnimportant(whenUnimportant); |
| 1308 | } |
| 1309 | |
| 1310 | long getWhenUnimportant() { |
| 1311 | return mWhenUnimportant; |
| 1312 | } |
| 1313 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 1314 | void setDebugging(boolean debugging) { |
| 1315 | mDebugging = debugging; |
| 1316 | mWindowProcessController.setDebugging(debugging); |
| 1317 | } |
| 1318 | |
| 1319 | boolean isDebugging() { |
| 1320 | return mDebugging; |
| 1321 | } |
| 1322 | |
| 1323 | void setUsingWrapper(boolean usingWrapper) { |
| 1324 | mUsingWrapper = usingWrapper; |
| 1325 | mWindowProcessController.setUsingWrapper(usingWrapper); |
| 1326 | } |
| 1327 | |
| 1328 | boolean isUsingWrapper() { |
| 1329 | return mUsingWrapper; |
| 1330 | } |
| 1331 | |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 1332 | void addAllowBackgroundActivityStartsToken(Binder entity) { |
Michal Karpinski | c8aa91b | 2019-01-10 16:45:59 +0000 | [diff] [blame] | 1333 | if (entity == null) return; |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 1334 | mAllowBackgroundActivityStartsTokens.add(entity); |
| 1335 | mWindowProcessController.setAllowBackgroundActivityStarts(true); |
| 1336 | } |
| 1337 | |
| 1338 | void removeAllowBackgroundActivityStartsToken(Binder entity) { |
Michal Karpinski | c8aa91b | 2019-01-10 16:45:59 +0000 | [diff] [blame] | 1339 | if (entity == null) return; |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 1340 | mAllowBackgroundActivityStartsTokens.remove(entity); |
| 1341 | mWindowProcessController.setAllowBackgroundActivityStarts( |
| 1342 | !mAllowBackgroundActivityStartsTokens.isEmpty()); |
| 1343 | } |
| 1344 | |
Alan Stokes | 8473a2c | 2019-04-29 13:51:18 +0100 | [diff] [blame] | 1345 | void addBoundClientUid(int clientUid) { |
| 1346 | mBoundClientUids.add(clientUid); |
Michal Karpinski | b7daac2 | 2019-03-25 10:12:41 +0000 | [diff] [blame] | 1347 | mWindowProcessController.setBoundClientUids(mBoundClientUids); |
| 1348 | } |
| 1349 | |
| 1350 | void updateBoundClientUids() { |
Darryl L Johnson | d02044c | 2020-04-17 11:52:50 -0700 | [diff] [blame] | 1351 | if (mServices.isEmpty()) { |
Michal Karpinski | b7daac2 | 2019-03-25 10:12:41 +0000 | [diff] [blame] | 1352 | clearBoundClientUids(); |
| 1353 | return; |
| 1354 | } |
| 1355 | // grab a set of clientUids of all connections of all services |
| 1356 | ArraySet<Integer> boundClientUids = new ArraySet<>(); |
Darryl L Johnson | d02044c | 2020-04-17 11:52:50 -0700 | [diff] [blame] | 1357 | final int serviceCount = mServices.size(); |
| 1358 | for (int j = 0; j < serviceCount; j++) { |
Michal Karpinski | b7daac2 | 2019-03-25 10:12:41 +0000 | [diff] [blame] | 1359 | ArrayMap<IBinder, ArrayList<ConnectionRecord>> conns = |
Darryl L Johnson | d02044c | 2020-04-17 11:52:50 -0700 | [diff] [blame] | 1360 | mServices.valueAt(j).getConnections(); |
Michal Karpinski | b7daac2 | 2019-03-25 10:12:41 +0000 | [diff] [blame] | 1361 | final int N = conns.size(); |
| 1362 | for (int conni = 0; conni < N; conni++) { |
| 1363 | ArrayList<ConnectionRecord> c = conns.valueAt(conni); |
| 1364 | for (int i = 0; i < c.size(); i++) { |
| 1365 | boundClientUids.add(c.get(i).clientUid); |
| 1366 | } |
| 1367 | } |
| 1368 | } |
| 1369 | mBoundClientUids = boundClientUids; |
| 1370 | mWindowProcessController.setBoundClientUids(mBoundClientUids); |
| 1371 | } |
| 1372 | |
| 1373 | void addBoundClientUidsOfNewService(ServiceRecord sr) { |
| 1374 | if (sr == null) { |
| 1375 | return; |
| 1376 | } |
| 1377 | ArrayMap<IBinder, ArrayList<ConnectionRecord>> conns = sr.getConnections(); |
| 1378 | for (int conni = conns.size() - 1; conni >= 0; conni--) { |
| 1379 | ArrayList<ConnectionRecord> c = conns.valueAt(conni); |
| 1380 | for (int i = 0; i < c.size(); i++) { |
| 1381 | mBoundClientUids.add(c.get(i).clientUid); |
| 1382 | } |
| 1383 | } |
| 1384 | mWindowProcessController.setBoundClientUids(mBoundClientUids); |
| 1385 | } |
| 1386 | |
| 1387 | void clearBoundClientUids() { |
| 1388 | mBoundClientUids.clear(); |
| 1389 | mWindowProcessController.setBoundClientUids(mBoundClientUids); |
| 1390 | } |
| 1391 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 1392 | void setActiveInstrumentation(ActiveInstrumentation instr) { |
| 1393 | mInstr = instr; |
Michal Karpinski | 4bc5649 | 2019-01-31 12:07:33 +0000 | [diff] [blame] | 1394 | boolean isInstrumenting = instr != null; |
| 1395 | mWindowProcessController.setInstrumenting(isInstrumenting, |
| 1396 | isInstrumenting && instr.mHasBackgroundActivityStartsPermission); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | ActiveInstrumentation getActiveInstrumentation() { |
| 1400 | return mInstr; |
| 1401 | } |
| 1402 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 1403 | void setCurRawAdj(int curRawAdj) { |
| 1404 | mCurRawAdj = curRawAdj; |
| 1405 | mWindowProcessController.setPerceptible(curRawAdj <= ProcessList.PERCEPTIBLE_APP_ADJ); |
| 1406 | } |
| 1407 | |
| 1408 | int getCurRawAdj() { |
| 1409 | return mCurRawAdj; |
| 1410 | } |
| 1411 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1412 | @Override |
| 1413 | public void clearProfilerIfNeeded() { |
| 1414 | synchronized (mService) { |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 1415 | if (mService.mProfileData.getProfileProc() == null |
| 1416 | || mService.mProfileData.getProfilerInfo() == null |
| 1417 | || mService.mProfileData.getProfileProc() != this) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1418 | return; |
| 1419 | } |
| 1420 | mService.clearProfilerLocked(); |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | @Override |
| 1425 | public void updateServiceConnectionActivities() { |
| 1426 | synchronized (mService) { |
| 1427 | mService.mServices.updateServiceConnectionActivitiesLocked(this); |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | @Override |
| 1432 | public void setPendingUiClean(boolean pendingUiClean) { |
| 1433 | synchronized (mService) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1434 | mPendingUiClean = pendingUiClean; |
| 1435 | mWindowProcessController.setPendingUiClean(pendingUiClean); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1436 | } |
| 1437 | } |
| 1438 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1439 | boolean hasPendingUiClean() { |
| 1440 | return mPendingUiClean; |
| 1441 | } |
| 1442 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1443 | @Override |
| 1444 | public void setPendingUiCleanAndForceProcessStateUpTo(int newState) { |
| 1445 | synchronized (mService) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1446 | setPendingUiClean(true); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1447 | forceProcessStateUpTo(newState); |
| 1448 | } |
| 1449 | } |
| 1450 | |
| 1451 | @Override |
Riddle Hsu | 17e3842 | 2019-04-12 16:55:11 +0800 | [diff] [blame] | 1452 | public void updateProcessInfo(boolean updateServiceConnectionActivities, boolean activityChange, |
| 1453 | boolean updateOomAdj) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1454 | synchronized (mService) { |
| 1455 | if (updateServiceConnectionActivities) { |
| 1456 | mService.mServices.updateServiceConnectionActivitiesLocked(this); |
| 1457 | } |
Riddle Hsu | 17e3842 | 2019-04-12 16:55:11 +0800 | [diff] [blame] | 1458 | mService.mProcessList.updateLruProcessLocked(this, activityChange, null /* client */); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1459 | if (updateOomAdj) { |
Jing Ji | 094c3ef | 2019-08-27 17:02:09 -0700 | [diff] [blame] | 1460 | mService.updateOomAdjLocked(this, OomAdjuster.OOM_ADJ_REASON_ACTIVITY); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1461 | } |
| 1462 | } |
| 1463 | } |
| 1464 | |
| 1465 | @Override |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 1466 | public boolean isRemoved() { |
| 1467 | return removed; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1468 | } |
| 1469 | |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 1470 | /** |
| 1471 | * Returns the total time (in milliseconds) spent executing in both user and system code. |
| 1472 | * Safe to call without lock held. |
| 1473 | */ |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1474 | @Override |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 1475 | public long getCpuTime() { |
| 1476 | return mService.mProcessCpuTracker.getCpuTimeForPid(pid); |
| 1477 | } |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1478 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1479 | @Override |
Riddle Hsu | 17e3842 | 2019-04-12 16:55:11 +0800 | [diff] [blame] | 1480 | public void onStartActivity(int topProcessState, boolean setProfileProc, String packageName, |
| 1481 | long versionCode) { |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1482 | synchronized (mService) { |
| 1483 | waitingToKill = null; |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 1484 | if (setProfileProc) { |
| 1485 | mService.mProfileData.setProfileProc(this); |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1486 | } |
Riddle Hsu | 17e3842 | 2019-04-12 16:55:11 +0800 | [diff] [blame] | 1487 | if (packageName != null) { |
| 1488 | addPackage(packageName, versionCode, mService.mProcessStats); |
| 1489 | } |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1490 | |
Riddle Hsu | 17e3842 | 2019-04-12 16:55:11 +0800 | [diff] [blame] | 1491 | // Update oom adj first, we don't want the additional states are involved in this round. |
| 1492 | updateProcessInfo(false /* updateServiceConnectionActivities */, |
| 1493 | true /* activityChange */, true /* updateOomAdj */); |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1494 | hasShownUi = true; |
| 1495 | setPendingUiClean(true); |
| 1496 | forceProcessStateUpTo(topProcessState); |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | @Override |
Jing Ji | 8055a3a | 2019-12-17 15:55:33 -0800 | [diff] [blame] | 1501 | public void appDied(String reason) { |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1502 | synchronized (mService) { |
Jing Ji | 8055a3a | 2019-12-17 15:55:33 -0800 | [diff] [blame] | 1503 | mService.appDiedLocked(this, reason); |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 1507 | @Override |
| 1508 | public void setRunningRemoteAnimation(boolean runningRemoteAnimation) { |
| 1509 | if (pid == Process.myPid()) { |
| 1510 | Slog.wtf(TAG, "system can't run remote animation"); |
| 1511 | return; |
| 1512 | } |
| 1513 | synchronized (mService) { |
| 1514 | if (this.runningRemoteAnimation == runningRemoteAnimation) { |
| 1515 | return; |
| 1516 | } |
| 1517 | this.runningRemoteAnimation = runningRemoteAnimation; |
| 1518 | if (DEBUG_OOM_ADJ) { |
| 1519 | Slog.i(TAG, "Setting runningRemoteAnimation=" + runningRemoteAnimation |
| 1520 | + " for pid=" + pid); |
| 1521 | } |
Tim Murray | d33c6f8 | 2020-06-19 16:40:47 +0000 | [diff] [blame] | 1522 | updateTopUiOrRunningRemoteAnim(); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 1523 | mService.updateOomAdjLocked(this, true, OomAdjuster.OOM_ADJ_REASON_UI_VISIBILITY); |
| 1524 | } |
| 1525 | } |
| 1526 | |
Tim Murray | d33c6f8 | 2020-06-19 16:40:47 +0000 | [diff] [blame] | 1527 | void updateTopUiOrRunningRemoteAnim() { |
| 1528 | if (runningRemoteAnimation || hasTopUi()) { |
| 1529 | mService.addTopUiOrRunningRemoteAnim(this); |
| 1530 | } else { |
| 1531 | mService.removeTopUiOrRunningRemoteAnim(this); |
| 1532 | } |
| 1533 | } |
| 1534 | |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1535 | public long getInputDispatchingTimeout() { |
| 1536 | return mWindowProcessController.getInputDispatchingTimeout(); |
| 1537 | } |
| 1538 | |
Yang Lu | 732d638 | 2018-11-05 07:53:12 -0800 | [diff] [blame] | 1539 | public int getProcessClassEnum() { |
| 1540 | if (pid == MY_PID) { |
| 1541 | return ServerProtoEnums.SYSTEM_SERVER; |
| 1542 | } |
| 1543 | if (info == null) { |
| 1544 | return ServerProtoEnums.ERROR_SOURCE_UNKNOWN; |
| 1545 | } |
| 1546 | return (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? ServerProtoEnums.SYSTEM_APP : |
| 1547 | ServerProtoEnums.DATA_APP; |
| 1548 | } |
| 1549 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1550 | /** |
| 1551 | * Unless configured otherwise, swallow ANRs in background processes & kill the process. |
| 1552 | * Non-private access is for tests only. |
| 1553 | */ |
| 1554 | @VisibleForTesting |
| 1555 | boolean isSilentAnr() { |
| 1556 | return !getShowBackground() && !isInterestingForBackgroundTraces(); |
| 1557 | } |
| 1558 | |
| 1559 | /** Non-private access is for tests only. */ |
| 1560 | @VisibleForTesting |
| 1561 | List<ProcessRecord> getLruProcessList() { |
| 1562 | return mService.mProcessList.mLruProcesses; |
| 1563 | } |
| 1564 | |
| 1565 | /** Non-private access is for tests only. */ |
| 1566 | @VisibleForTesting |
| 1567 | boolean isMonitorCpuUsage() { |
| 1568 | return mService.MONITOR_CPU_USAGE; |
| 1569 | } |
| 1570 | |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1571 | void appNotResponding(String activityShortComponentName, ApplicationInfo aInfo, |
| 1572 | String parentShortComponentName, WindowProcessController parentProcess, |
Riddle Hsu | f9a2c04f | 2020-03-26 20:22:22 +0800 | [diff] [blame] | 1573 | boolean aboveSystem, String annotation, boolean onlyDumpSelf) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1574 | ArrayList<Integer> firstPids = new ArrayList<>(5); |
| 1575 | SparseArray<Boolean> lastPids = new SparseArray<>(20); |
| 1576 | |
Jing Ji | 8055a3a | 2019-12-17 15:55:33 -0800 | [diff] [blame] | 1577 | mWindowProcessController.appEarlyNotResponding(annotation, () -> kill("anr", |
| 1578 | ApplicationExitInfo.REASON_ANR, true)); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1579 | |
| 1580 | long anrTime = SystemClock.uptimeMillis(); |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1581 | if (isMonitorCpuUsage()) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1582 | mService.updateCpuStatsNow(); |
| 1583 | } |
| 1584 | |
Riddle Hsu | f9a2c04f | 2020-03-26 20:22:22 +0800 | [diff] [blame] | 1585 | final boolean isSilentAnr; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1586 | synchronized (mService) { |
| 1587 | // PowerManager.reboot() can block for a long time, so ignore ANRs while shutting down. |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 1588 | if (mService.mAtmInternal.isShuttingDown()) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1589 | Slog.i(TAG, "During shutdown skipping ANR: " + this + " " + annotation); |
| 1590 | return; |
| 1591 | } else if (isNotResponding()) { |
| 1592 | Slog.i(TAG, "Skipping duplicate ANR: " + this + " " + annotation); |
| 1593 | return; |
| 1594 | } else if (isCrashing()) { |
| 1595 | Slog.i(TAG, "Crashing app skipping ANR: " + this + " " + annotation); |
| 1596 | return; |
| 1597 | } else if (killedByAm) { |
| 1598 | Slog.i(TAG, "App already killed by AM skipping ANR: " + this + " " + annotation); |
| 1599 | return; |
| 1600 | } else if (killed) { |
| 1601 | Slog.i(TAG, "Skipping died app ANR: " + this + " " + annotation); |
| 1602 | return; |
| 1603 | } |
| 1604 | |
| 1605 | // In case we come through here for the same app before completing |
| 1606 | // this one, mark as anring now so we will bail out. |
| 1607 | setNotResponding(true); |
| 1608 | |
| 1609 | // Log the ANR to the event log. |
| 1610 | EventLog.writeEvent(EventLogTags.AM_ANR, userId, pid, processName, info.flags, |
| 1611 | annotation); |
| 1612 | |
| 1613 | // Dump thread traces as quickly as we can, starting with "interesting" processes. |
| 1614 | firstPids.add(pid); |
| 1615 | |
Riddle Hsu | f9a2c04f | 2020-03-26 20:22:22 +0800 | [diff] [blame] | 1616 | // Don't dump other PIDs if it's a background ANR or is requested to only dump self. |
| 1617 | isSilentAnr = isSilentAnr(); |
| 1618 | if (!isSilentAnr && !onlyDumpSelf) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1619 | int parentPid = pid; |
| 1620 | if (parentProcess != null && parentProcess.getPid() > 0) { |
| 1621 | parentPid = parentProcess.getPid(); |
| 1622 | } |
| 1623 | if (parentPid != pid) firstPids.add(parentPid); |
| 1624 | |
| 1625 | if (MY_PID != pid && MY_PID != parentPid) firstPids.add(MY_PID); |
| 1626 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1627 | for (int i = getLruProcessList().size() - 1; i >= 0; i--) { |
| 1628 | ProcessRecord r = getLruProcessList().get(i); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1629 | if (r != null && r.thread != null) { |
| 1630 | int myPid = r.pid; |
| 1631 | if (myPid > 0 && myPid != pid && myPid != parentPid && myPid != MY_PID) { |
| 1632 | if (r.isPersistent()) { |
| 1633 | firstPids.add(myPid); |
| 1634 | if (DEBUG_ANR) Slog.i(TAG, "Adding persistent proc: " + r); |
| 1635 | } else if (r.treatLikeActivity) { |
| 1636 | firstPids.add(myPid); |
| 1637 | if (DEBUG_ANR) Slog.i(TAG, "Adding likely IME: " + r); |
| 1638 | } else { |
| 1639 | lastPids.put(myPid, Boolean.TRUE); |
| 1640 | if (DEBUG_ANR) Slog.i(TAG, "Adding ANR proc: " + r); |
| 1641 | } |
| 1642 | } |
| 1643 | } |
| 1644 | } |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | // Log the ANR to the main log. |
| 1649 | StringBuilder info = new StringBuilder(); |
| 1650 | info.setLength(0); |
| 1651 | info.append("ANR in ").append(processName); |
| 1652 | if (activityShortComponentName != null) { |
| 1653 | info.append(" (").append(activityShortComponentName).append(")"); |
| 1654 | } |
| 1655 | info.append("\n"); |
| 1656 | info.append("PID: ").append(pid).append("\n"); |
| 1657 | if (annotation != null) { |
| 1658 | info.append("Reason: ").append(annotation).append("\n"); |
| 1659 | } |
| 1660 | if (parentShortComponentName != null |
| 1661 | && parentShortComponentName.equals(activityShortComponentName)) { |
| 1662 | info.append("Parent: ").append(parentShortComponentName).append("\n"); |
| 1663 | } |
| 1664 | |
Simon MacMullen | 30f04a7 | 2020-02-05 10:57:40 +0000 | [diff] [blame] | 1665 | StringBuilder report = new StringBuilder(); |
| 1666 | report.append(MemoryPressureUtil.currentPsiState()); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1667 | ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(true); |
| 1668 | |
| 1669 | // don't dump native PIDs for background ANRs unless it is the process of interest |
| 1670 | String[] nativeProcs = null; |
Riddle Hsu | f9a2c04f | 2020-03-26 20:22:22 +0800 | [diff] [blame] | 1671 | if (isSilentAnr || onlyDumpSelf) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1672 | for (int i = 0; i < NATIVE_STACKS_OF_INTEREST.length; i++) { |
| 1673 | if (NATIVE_STACKS_OF_INTEREST[i].equals(processName)) { |
| 1674 | nativeProcs = new String[] { processName }; |
| 1675 | break; |
| 1676 | } |
| 1677 | } |
| 1678 | } else { |
| 1679 | nativeProcs = NATIVE_STACKS_OF_INTEREST; |
| 1680 | } |
| 1681 | |
| 1682 | int[] pids = nativeProcs == null ? null : Process.getPidsForCommands(nativeProcs); |
| 1683 | ArrayList<Integer> nativePids = null; |
| 1684 | |
| 1685 | if (pids != null) { |
| 1686 | nativePids = new ArrayList<>(pids.length); |
| 1687 | for (int i : pids) { |
| 1688 | nativePids.add(i); |
| 1689 | } |
| 1690 | } |
| 1691 | |
| 1692 | // For background ANRs, don't pass the ProcessCpuTracker to |
| 1693 | // avoid spending 1/2 second collecting stats to rank lastPids. |
Simon MacMullen | 46755e2 | 2020-02-04 14:03:37 +0000 | [diff] [blame] | 1694 | StringWriter tracesFileException = new StringWriter(); |
Jing Ji | 56006fd | 2020-03-08 00:32:33 -0800 | [diff] [blame] | 1695 | // To hold the start and end offset to the ANR trace file respectively. |
| 1696 | final long[] offsets = new long[2]; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1697 | File tracesFile = ActivityManagerService.dumpStackTraces(firstPids, |
Riddle Hsu | f9a2c04f | 2020-03-26 20:22:22 +0800 | [diff] [blame] | 1698 | isSilentAnr ? null : processCpuTracker, isSilentAnr ? null : lastPids, |
Jing Ji | 56006fd | 2020-03-08 00:32:33 -0800 | [diff] [blame] | 1699 | nativePids, tracesFileException, offsets); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1700 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1701 | if (isMonitorCpuUsage()) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1702 | mService.updateCpuStatsNow(); |
| 1703 | synchronized (mService.mProcessCpuTracker) { |
Simon MacMullen | 46755e2 | 2020-02-04 14:03:37 +0000 | [diff] [blame] | 1704 | report.append(mService.mProcessCpuTracker.printCurrentState(anrTime)); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1705 | } |
| 1706 | info.append(processCpuTracker.printCurrentLoad()); |
Simon MacMullen | 46755e2 | 2020-02-04 14:03:37 +0000 | [diff] [blame] | 1707 | info.append(report); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1708 | } |
Simon MacMullen | 46755e2 | 2020-02-04 14:03:37 +0000 | [diff] [blame] | 1709 | report.append(tracesFileException.getBuffer()); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1710 | |
| 1711 | info.append(processCpuTracker.printCurrentState(anrTime)); |
| 1712 | |
| 1713 | Slog.e(TAG, info.toString()); |
| 1714 | if (tracesFile == null) { |
| 1715 | // There is no trace file, so dump (only) the alleged culprit's threads to the log |
| 1716 | Process.sendSignal(pid, Process.SIGNAL_QUIT); |
Jing Ji | 56006fd | 2020-03-08 00:32:33 -0800 | [diff] [blame] | 1717 | } else if (offsets[1] > 0) { |
| 1718 | // We've dumped into the trace file successfully |
| 1719 | mService.mProcessList.mAppExitInfoTracker.scheduleLogAnrTrace( |
| 1720 | pid, uid, getPackageList(), tracesFile, offsets[0], offsets[1]); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
Muhammad Qureshi | edd80fd | 2020-01-27 17:23:07 -0800 | [diff] [blame] | 1723 | FrameworkStatsLog.write(FrameworkStatsLog.ANR_OCCURRED, uid, processName, |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1724 | activityShortComponentName == null ? "unknown": activityShortComponentName, |
| 1725 | annotation, |
| 1726 | (this.info != null) ? (this.info.isInstantApp() |
Muhammad Qureshi | edd80fd | 2020-01-27 17:23:07 -0800 | [diff] [blame] | 1727 | ? FrameworkStatsLog.ANROCCURRED__IS_INSTANT_APP__TRUE |
| 1728 | : FrameworkStatsLog.ANROCCURRED__IS_INSTANT_APP__FALSE) |
| 1729 | : FrameworkStatsLog.ANROCCURRED__IS_INSTANT_APP__UNAVAILABLE, |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1730 | isInterestingToUserLocked() |
Muhammad Qureshi | edd80fd | 2020-01-27 17:23:07 -0800 | [diff] [blame] | 1731 | ? FrameworkStatsLog.ANROCCURRED__FOREGROUND_STATE__FOREGROUND |
| 1732 | : FrameworkStatsLog.ANROCCURRED__FOREGROUND_STATE__BACKGROUND, |
Yang Lu | 732d638 | 2018-11-05 07:53:12 -0800 | [diff] [blame] | 1733 | getProcessClassEnum(), |
| 1734 | (this.info != null) ? this.info.packageName : ""); |
Wale Ogunwale | 97b2b74 | 2018-10-18 08:08:54 -0700 | [diff] [blame] | 1735 | final ProcessRecord parentPr = parentProcess != null |
| 1736 | ? (ProcessRecord) parentProcess.mOwner : null; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1737 | mService.addErrorToDropBox("anr", this, processName, activityShortComponentName, |
Simon MacMullen | 46755e2 | 2020-02-04 14:03:37 +0000 | [diff] [blame] | 1738 | parentShortComponentName, parentPr, annotation, report.toString(), tracesFile, |
| 1739 | null); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1740 | |
Jing Ji | 8055a3a | 2019-12-17 15:55:33 -0800 | [diff] [blame] | 1741 | if (mWindowProcessController.appNotResponding(info.toString(), () -> kill("anr", |
| 1742 | ApplicationExitInfo.REASON_ANR, true), |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 1743 | () -> { |
| 1744 | synchronized (mService) { |
| 1745 | mService.mServices.scheduleServiceTimeoutLocked(this); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1746 | } |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 1747 | })) { |
| 1748 | return; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | synchronized (mService) { |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1752 | // mBatteryStatsService can be null if the AMS is constructed with injector only. This |
| 1753 | // will only happen in tests. |
| 1754 | if (mService.mBatteryStatsService != null) { |
| 1755 | mService.mBatteryStatsService.noteProcessAnr(processName, uid); |
| 1756 | } |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1757 | |
Hui Yu | 8e3e445 | 2019-04-11 10:57:51 -0700 | [diff] [blame] | 1758 | if (isSilentAnr() && !isDebugging()) { |
Jing Ji | 8055a3a | 2019-12-17 15:55:33 -0800 | [diff] [blame] | 1759 | kill("bg anr", ApplicationExitInfo.REASON_ANR, true); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1760 | return; |
| 1761 | } |
| 1762 | |
| 1763 | // Set the app's notResponding state, and look up the errorReportReceiver |
| 1764 | makeAppNotRespondingLocked(activityShortComponentName, |
| 1765 | annotation != null ? "ANR " + annotation : "ANR", info.toString()); |
| 1766 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1767 | // mUiHandler can be null if the AMS is constructed with injector only. This will only |
| 1768 | // happen in tests. |
| 1769 | if (mService.mUiHandler != null) { |
| 1770 | // Bring up the infamous App Not Responding dialog |
| 1771 | Message msg = Message.obtain(); |
| 1772 | msg.what = ActivityManagerService.SHOW_NOT_RESPONDING_UI_MSG; |
| 1773 | msg.obj = new AppNotRespondingDialog.Data(this, aInfo, aboveSystem); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1774 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1775 | mService.mUiHandler.sendMessage(msg); |
| 1776 | } |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1777 | } |
| 1778 | } |
| 1779 | |
| 1780 | private void makeAppNotRespondingLocked(String activity, String shortMsg, String longMsg) { |
| 1781 | setNotResponding(true); |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1782 | // mAppErrors can be null if the AMS is constructed with injector only. This will only |
| 1783 | // happen in tests. |
| 1784 | if (mService.mAppErrors != null) { |
| 1785 | notRespondingReport = mService.mAppErrors.generateProcessError(this, |
| 1786 | ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING, |
| 1787 | activity, shortMsg, longMsg, null); |
| 1788 | } |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1789 | startAppProblemLocked(); |
| 1790 | getWindowProcessController().stopFreezingActivities(); |
| 1791 | } |
| 1792 | |
| 1793 | void startAppProblemLocked() { |
| 1794 | // If this app is not running under the current user, then we can't give it a report button |
| 1795 | // because that would require launching the report UI under a different user. |
| 1796 | errorReportReceiver = null; |
| 1797 | |
| 1798 | for (int userId : mService.mUserController.getCurrentProfileIds()) { |
| 1799 | if (this.userId == userId) { |
| 1800 | errorReportReceiver = ApplicationErrorReport.getErrorReportReceiver( |
| 1801 | mService.mContext, info.packageName, info.flags); |
| 1802 | } |
| 1803 | } |
| 1804 | mService.skipCurrentReceiverLocked(this); |
| 1805 | } |
| 1806 | |
| 1807 | private boolean isInterestingForBackgroundTraces() { |
| 1808 | // The system_server is always considered interesting. |
| 1809 | if (pid == MY_PID) { |
| 1810 | return true; |
| 1811 | } |
| 1812 | |
| 1813 | // A package is considered interesting if any of the following is true : |
| 1814 | // |
| 1815 | // - It's displaying an activity. |
| 1816 | // - It's the SystemUI. |
| 1817 | // - It has an overlay or a top UI visible. |
| 1818 | // |
| 1819 | // NOTE: The check whether a given ProcessRecord belongs to the systemui |
| 1820 | // process is a bit of a kludge, but the same pattern seems repeated at |
| 1821 | // several places in the system server. |
| 1822 | return isInterestingToUserLocked() || |
| 1823 | (info != null && "com.android.systemui".equals(info.packageName)) |
| 1824 | || (hasTopUi() || hasOverlayUi()); |
| 1825 | } |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1826 | |
| 1827 | private boolean getShowBackground() { |
| 1828 | return Settings.Secure.getInt(mService.mContext.getContentResolver(), |
| 1829 | Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0; |
| 1830 | } |
Jing Ji | 094c3ef | 2019-08-27 17:02:09 -0700 | [diff] [blame] | 1831 | |
| 1832 | void resetCachedInfo() { |
| 1833 | mCachedHasActivities = VALUE_INVALID; |
| 1834 | mCachedIsHeavyWeight = VALUE_INVALID; |
| 1835 | mCachedHasVisibleActivities = VALUE_INVALID; |
| 1836 | mCachedIsHomeProcess = VALUE_INVALID; |
| 1837 | mCachedIsPreviousProcess = VALUE_INVALID; |
| 1838 | mCachedHasRecentTasks = VALUE_INVALID; |
| 1839 | mCachedIsReceivingBroadcast = VALUE_INVALID; |
| 1840 | mCachedAdj = ProcessList.INVALID_ADJ; |
| 1841 | mCachedForegroundActivities = false; |
| 1842 | mCachedProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY; |
| 1843 | mCachedSchedGroup = ProcessList.SCHED_GROUP_BACKGROUND; |
| 1844 | } |
| 1845 | |
| 1846 | boolean getCachedHasActivities() { |
| 1847 | if (mCachedHasActivities == VALUE_INVALID) { |
| 1848 | mCachedHasActivities = getWindowProcessController().hasActivities() ? VALUE_TRUE |
| 1849 | : VALUE_FALSE; |
| 1850 | } |
| 1851 | return mCachedHasActivities == VALUE_TRUE; |
| 1852 | } |
| 1853 | |
| 1854 | boolean getCachedIsHeavyWeight() { |
| 1855 | if (mCachedIsHeavyWeight == VALUE_INVALID) { |
| 1856 | mCachedIsHeavyWeight = mService.mAtmInternal.isHeavyWeightProcess( |
| 1857 | getWindowProcessController()) ? VALUE_TRUE : VALUE_FALSE; |
| 1858 | } |
| 1859 | return mCachedIsHeavyWeight == VALUE_TRUE; |
| 1860 | } |
| 1861 | |
| 1862 | boolean getCachedHasVisibleActivities() { |
| 1863 | if (mCachedHasVisibleActivities == VALUE_INVALID) { |
| 1864 | mCachedHasVisibleActivities = getWindowProcessController().hasVisibleActivities() |
| 1865 | ? VALUE_TRUE : VALUE_FALSE; |
| 1866 | } |
| 1867 | return mCachedHasVisibleActivities == VALUE_TRUE; |
| 1868 | } |
| 1869 | |
| 1870 | boolean getCachedIsHomeProcess() { |
| 1871 | if (mCachedIsHomeProcess == VALUE_INVALID) { |
| 1872 | mCachedIsHomeProcess = getWindowProcessController().isHomeProcess() |
| 1873 | ? VALUE_TRUE : VALUE_FALSE; |
| 1874 | } |
| 1875 | return mCachedIsHomeProcess == VALUE_TRUE; |
| 1876 | } |
| 1877 | |
| 1878 | boolean getCachedIsPreviousProcess() { |
| 1879 | if (mCachedIsPreviousProcess == VALUE_INVALID) { |
| 1880 | mCachedIsPreviousProcess = getWindowProcessController().isPreviousProcess() |
| 1881 | ? VALUE_TRUE : VALUE_FALSE; |
| 1882 | } |
| 1883 | return mCachedIsPreviousProcess == VALUE_TRUE; |
| 1884 | } |
| 1885 | |
| 1886 | boolean getCachedHasRecentTasks() { |
| 1887 | if (mCachedHasRecentTasks == VALUE_INVALID) { |
| 1888 | mCachedHasRecentTasks = getWindowProcessController().hasRecentTasks() |
| 1889 | ? VALUE_TRUE : VALUE_FALSE; |
| 1890 | } |
| 1891 | return mCachedHasRecentTasks == VALUE_TRUE; |
| 1892 | } |
| 1893 | |
| 1894 | boolean getCachedIsReceivingBroadcast(ArraySet<BroadcastQueue> tmpQueue) { |
| 1895 | if (mCachedIsReceivingBroadcast == VALUE_INVALID) { |
| 1896 | tmpQueue.clear(); |
| 1897 | mCachedIsReceivingBroadcast = mService.isReceivingBroadcastLocked(this, tmpQueue) |
| 1898 | ? VALUE_TRUE : VALUE_FALSE; |
| 1899 | if (mCachedIsReceivingBroadcast == VALUE_TRUE) { |
| 1900 | mCachedSchedGroup = tmpQueue.contains(mService.mFgBroadcastQueue) |
| 1901 | ? ProcessList.SCHED_GROUP_DEFAULT : ProcessList.SCHED_GROUP_BACKGROUND; |
| 1902 | } |
| 1903 | } |
| 1904 | return mCachedIsReceivingBroadcast == VALUE_TRUE; |
| 1905 | } |
| 1906 | |
| 1907 | void computeOomAdjFromActivitiesIfNecessary(OomAdjuster.ComputeOomAdjWindowCallback callback, |
| 1908 | int adj, boolean foregroundActivities, int procState, int schedGroup, int appUid, |
| 1909 | int logUid, int processCurTop) { |
| 1910 | if (mCachedAdj != ProcessList.INVALID_ADJ) { |
| 1911 | return; |
| 1912 | } |
| 1913 | callback.initialize(this, adj, foregroundActivities, procState, schedGroup, appUid, logUid, |
| 1914 | processCurTop); |
| 1915 | final int minLayer = getWindowProcessController().computeOomAdjFromActivities( |
| 1916 | ProcessList.VISIBLE_APP_LAYER_MAX, callback); |
| 1917 | |
| 1918 | mCachedAdj = callback.adj; |
| 1919 | mCachedForegroundActivities = callback.foregroundActivities; |
| 1920 | mCachedProcState = callback.procState; |
| 1921 | mCachedSchedGroup = callback.schedGroup; |
| 1922 | |
| 1923 | if (mCachedAdj == ProcessList.VISIBLE_APP_ADJ) { |
| 1924 | mCachedAdj += minLayer; |
| 1925 | } |
| 1926 | } |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 1927 | |
| 1928 | ErrorDialogController getDialogController() { |
| 1929 | return mDialogController; |
| 1930 | } |
| 1931 | |
| 1932 | /** A controller to generate error dialogs in {@link ProcessRecord} */ |
| 1933 | class ErrorDialogController { |
| 1934 | /** dialogs being displayed due to crash */ |
| 1935 | private List<AppErrorDialog> mCrashDialogs; |
| 1936 | /** dialogs being displayed due to app not responding */ |
| 1937 | private List<AppNotRespondingDialog> mAnrDialogs; |
| 1938 | /** dialogs displayed due to strict mode violation */ |
| 1939 | private List<StrictModeViolationDialog> mViolationDialogs; |
| 1940 | /** current wait for debugger dialog */ |
| 1941 | private AppWaitingForDebuggerDialog mWaitDialog; |
| 1942 | |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 1943 | boolean hasCrashDialogs() { |
| 1944 | return mCrashDialogs != null; |
| 1945 | } |
| 1946 | |
| 1947 | boolean hasAnrDialogs() { |
| 1948 | return mAnrDialogs != null; |
| 1949 | } |
| 1950 | |
| 1951 | boolean hasViolationDialogs() { |
| 1952 | return mViolationDialogs != null; |
| 1953 | } |
| 1954 | |
| 1955 | boolean hasDebugWaitingDialog() { |
| 1956 | return mWaitDialog != null; |
| 1957 | } |
| 1958 | |
| 1959 | void clearAllErrorDialogs() { |
| 1960 | clearCrashDialogs(); |
| 1961 | clearAnrDialogs(); |
| 1962 | clearViolationDialogs(); |
| 1963 | clearWaitingDialog(); |
| 1964 | } |
| 1965 | |
| 1966 | void clearCrashDialogs() { |
| 1967 | clearCrashDialogs(true /* needDismiss */); |
| 1968 | } |
| 1969 | |
| 1970 | void clearCrashDialogs(boolean needDismiss) { |
| 1971 | if (mCrashDialogs == null) { |
| 1972 | return; |
| 1973 | } |
| 1974 | if (needDismiss) { |
| 1975 | forAllDialogs(mCrashDialogs, Dialog::dismiss); |
| 1976 | } |
| 1977 | mCrashDialogs = null; |
| 1978 | } |
| 1979 | |
| 1980 | void clearAnrDialogs() { |
| 1981 | if (mAnrDialogs == null) { |
| 1982 | return; |
| 1983 | } |
| 1984 | forAllDialogs(mAnrDialogs, Dialog::dismiss); |
| 1985 | mAnrDialogs = null; |
| 1986 | } |
| 1987 | |
| 1988 | void clearViolationDialogs() { |
| 1989 | if (mViolationDialogs == null) { |
| 1990 | return; |
| 1991 | } |
| 1992 | forAllDialogs(mViolationDialogs, Dialog::dismiss); |
| 1993 | mViolationDialogs = null; |
| 1994 | } |
| 1995 | |
| 1996 | void clearWaitingDialog() { |
| 1997 | if (mWaitDialog == null) { |
| 1998 | return; |
| 1999 | } |
| 2000 | mWaitDialog.dismiss(); |
| 2001 | mWaitDialog = null; |
| 2002 | } |
| 2003 | |
Charles Chen | ce7c807 | 2020-02-03 16:10:14 +0800 | [diff] [blame] | 2004 | void forAllDialogs(List<? extends BaseErrorDialog> dialogs, Consumer<BaseErrorDialog> c) { |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 2005 | for (int i = dialogs.size() - 1; i >= 0; i--) { |
| 2006 | c.accept(dialogs.get(i)); |
| 2007 | } |
| 2008 | } |
| 2009 | |
| 2010 | void showCrashDialogs(AppErrorDialog.Data data) { |
| 2011 | List<Context> contexts = getDisplayContexts(false /* lastUsedOnly */); |
| 2012 | mCrashDialogs = new ArrayList<>(); |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 2013 | for (int i = contexts.size() - 1; i >= 0; i--) { |
| 2014 | final Context c = contexts.get(i); |
| 2015 | mCrashDialogs.add(new AppErrorDialog(c, mService, data)); |
| 2016 | } |
Charles Chen | ce7c807 | 2020-02-03 16:10:14 +0800 | [diff] [blame] | 2017 | mService.mUiHandler.post(() -> { |
| 2018 | List<AppErrorDialog> dialogs; |
| 2019 | synchronized (mService) { |
| 2020 | dialogs = mCrashDialogs; |
| 2021 | } |
| 2022 | if (dialogs != null) { |
| 2023 | forAllDialogs(dialogs, Dialog::show); |
| 2024 | } |
| 2025 | }); |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | void showAnrDialogs(AppNotRespondingDialog.Data data) { |
| 2029 | List<Context> contexts = getDisplayContexts(isSilentAnr() /* lastUsedOnly */); |
| 2030 | mAnrDialogs = new ArrayList<>(); |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 2031 | for (int i = contexts.size() - 1; i >= 0; i--) { |
| 2032 | final Context c = contexts.get(i); |
| 2033 | mAnrDialogs.add(new AppNotRespondingDialog(mService, c, data)); |
| 2034 | } |
Charles Chen | ce7c807 | 2020-02-03 16:10:14 +0800 | [diff] [blame] | 2035 | mService.mUiHandler.post(() -> { |
| 2036 | List<AppNotRespondingDialog> dialogs; |
| 2037 | synchronized (mService) { |
| 2038 | dialogs = mAnrDialogs; |
| 2039 | } |
| 2040 | if (dialogs != null) { |
| 2041 | forAllDialogs(dialogs, Dialog::show); |
| 2042 | } |
| 2043 | }); |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | void showViolationDialogs(AppErrorResult res) { |
| 2047 | List<Context> contexts = getDisplayContexts(false /* lastUsedOnly */); |
| 2048 | mViolationDialogs = new ArrayList<>(); |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 2049 | for (int i = contexts.size() - 1; i >= 0; i--) { |
| 2050 | final Context c = contexts.get(i); |
| 2051 | mViolationDialogs.add( |
| 2052 | new StrictModeViolationDialog(c, mService, res, ProcessRecord.this)); |
| 2053 | } |
Charles Chen | ce7c807 | 2020-02-03 16:10:14 +0800 | [diff] [blame] | 2054 | mService.mUiHandler.post(() -> { |
| 2055 | List<StrictModeViolationDialog> dialogs; |
| 2056 | synchronized (mService) { |
| 2057 | dialogs = mViolationDialogs; |
| 2058 | } |
| 2059 | if (dialogs != null) { |
| 2060 | forAllDialogs(dialogs, Dialog::show); |
| 2061 | } |
| 2062 | }); |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | void showDebugWaitingDialogs() { |
| 2066 | List<Context> contexts = getDisplayContexts(true /* lastUsedOnly */); |
| 2067 | final Context c = contexts.get(0); |
| 2068 | mWaitDialog = new AppWaitingForDebuggerDialog(mService, c, ProcessRecord.this); |
Charles Chen | ce7c807 | 2020-02-03 16:10:14 +0800 | [diff] [blame] | 2069 | |
| 2070 | mService.mUiHandler.post(() -> { |
| 2071 | Dialog dialog; |
| 2072 | synchronized (mService) { |
| 2073 | dialog = mWaitDialog; |
| 2074 | } |
| 2075 | if (dialog != null) { |
| 2076 | dialog.show(); |
| 2077 | } |
| 2078 | }); |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | /** |
| 2082 | * Helper function to collect contexts from crashed app located displays |
| 2083 | * |
| 2084 | * @param lastUsedOnly Sets to {@code true} to indicate to only get last used context. |
| 2085 | * Sets to {@code false} to collect contexts from crashed app located |
| 2086 | * displays. |
| 2087 | * |
| 2088 | * @return display context list |
| 2089 | */ |
| 2090 | private List<Context> getDisplayContexts(boolean lastUsedOnly) { |
| 2091 | List<Context> displayContexts = new ArrayList<>(); |
| 2092 | if (!lastUsedOnly) { |
| 2093 | mWindowProcessController.getDisplayContextsWithErrorDialogs(displayContexts); |
| 2094 | } |
| 2095 | // If there is no foreground window display, fallback to last used display. |
| 2096 | if (displayContexts.isEmpty() || lastUsedOnly) { |
Riddle Hsu | 03c8642 | 2020-01-17 22:09:17 +0800 | [diff] [blame] | 2097 | displayContexts.add(mService.mWmInternal != null |
| 2098 | ? mService.mWmInternal.getTopFocusedDisplayUiContext() |
| 2099 | : mService.mUiContext); |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 2100 | } |
| 2101 | return displayContexts; |
| 2102 | } |
| 2103 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2104 | } |