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; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 23 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 24 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 25 | import static com.android.server.am.ActivityManagerService.MY_PID; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 26 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.app.ActivityManager; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 28 | import android.app.ApplicationErrorReport; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.app.Dialog; |
| 30 | import android.app.IApplicationThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.content.ComponentName; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 32 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.content.pm.ApplicationInfo; |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 34 | import android.content.pm.ServiceInfo; |
Zimuzo | 972e1cd | 2019-01-28 16:30:01 +0000 | [diff] [blame] | 35 | import android.content.pm.VersionedPackage; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 36 | import android.content.res.CompatibilityInfo; |
Joe Onorato | 5719028 | 2016-04-20 15:37:49 -0700 | [diff] [blame] | 37 | import android.os.Binder; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 38 | import android.os.Debug; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.os.IBinder; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 40 | import android.os.Message; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 41 | import android.os.Process; |
Joe Onorato | 5719028 | 2016-04-20 15:37:49 -0700 | [diff] [blame] | 42 | import android.os.RemoteException; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 43 | import android.os.SystemClock; |
Yusuke Sato | cf4b254 | 2015-06-17 00:21:28 -0700 | [diff] [blame] | 44 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 45 | import android.os.UserHandle; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 46 | import android.provider.Settings; |
Yang Lu | 732d638 | 2018-11-05 07:53:12 -0800 | [diff] [blame] | 47 | import android.server.ServerProtoEnums; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 48 | import android.util.ArrayMap; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 49 | import android.util.ArraySet; |
| 50 | import android.util.DebugUtils; |
| 51 | import android.util.EventLog; |
| 52 | import android.util.Slog; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 53 | import android.util.SparseArray; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 54 | import android.util.StatsLog; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 55 | import android.util.TimeUtils; |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 56 | import android.util.proto.ProtoOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 58 | import com.android.internal.annotations.VisibleForTesting; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 59 | import com.android.internal.app.procstats.ProcessState; |
| 60 | import com.android.internal.app.procstats.ProcessStats; |
| 61 | import com.android.internal.os.BatteryStatsImpl; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 62 | import com.android.internal.os.ProcessCpuTracker; |
Sudheer Shanka | 87915d6 | 2018-11-06 10:57:35 -0800 | [diff] [blame] | 63 | import com.android.internal.os.Zygote; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 64 | import com.android.server.wm.WindowProcessController; |
| 65 | import com.android.server.wm.WindowProcessListener; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 66 | |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 67 | import java.io.File; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import java.io.PrintWriter; |
| 69 | import java.util.ArrayList; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 70 | import java.util.Arrays; |
Zimuzo | 972e1cd | 2019-01-28 16:30:01 +0000 | [diff] [blame] | 71 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Full information about a particular process that |
| 75 | * is currently running. |
| 76 | */ |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 77 | class ProcessRecord implements WindowProcessListener { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 78 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ProcessRecord" : TAG_AM; |
| 79 | |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 80 | private final ActivityManagerService mService; // where we came from |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | final ApplicationInfo info; // all about the first app in the process |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 82 | final boolean isolated; // true if this is a special isolated process |
Martijn Coenen | 01e719b | 2018-12-05 16:01:38 +0100 | [diff] [blame] | 83 | final boolean appZygote; // true if this is forked from the app zygote |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 84 | final int uid; // uid of process; may be different from 'info' if isolated |
| 85 | final int userId; // user of process. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | final String processName; // name of the process |
| 87 | // List of packages running in the process |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 88 | final PackageList pkgList = new PackageList(); |
| 89 | final class PackageList { |
| 90 | final ArrayMap<String, ProcessStats.ProcessStateHolder> mPkgList = new ArrayMap<>(); |
| 91 | |
| 92 | ProcessStats.ProcessStateHolder put(String key, ProcessStats.ProcessStateHolder value) { |
| 93 | mWindowProcessController.addPackage(key); |
| 94 | return mPkgList.put(key, value); |
| 95 | } |
| 96 | |
| 97 | void clear() { |
| 98 | mPkgList.clear(); |
| 99 | mWindowProcessController.clearPackageList(); |
| 100 | } |
| 101 | |
| 102 | int size() { |
| 103 | return mPkgList.size(); |
| 104 | } |
| 105 | |
| 106 | String keyAt(int index) { |
| 107 | return mPkgList.keyAt(index); |
| 108 | } |
| 109 | |
| 110 | public ProcessStats.ProcessStateHolder valueAt(int index) { |
| 111 | return mPkgList.valueAt(index); |
| 112 | } |
| 113 | |
Dianne Hackborn | 2aec55a | 2018-06-26 10:35:35 -0700 | [diff] [blame] | 114 | ProcessStats.ProcessStateHolder get(String pkgName) { |
| 115 | return mPkgList.get(pkgName); |
| 116 | } |
| 117 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 118 | boolean containsKey(Object key) { |
| 119 | return mPkgList.containsKey(key); |
| 120 | } |
| 121 | } |
| 122 | |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 123 | final ProcessList.ProcStateMemTracker procStateMemTracker |
| 124 | = new ProcessList.ProcStateMemTracker(); |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 125 | UidRecord uidRecord; // overall state of process's uid. |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 126 | 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] | 127 | IApplicationThread thread; // the actual proc... may be null only if |
| 128 | // 'persistent' is true (in which case we |
| 129 | // are in the process of launching the app) |
Joe Onorato | 4eb64fd | 2016-03-21 15:30:09 -0700 | [diff] [blame] | 130 | ProcessState baseProcessTracker; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 131 | BatteryStatsImpl.Uid.Proc curProcBatteryStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | int pid; // The process of this application; 0 if none |
Dianne Hackborn | 4de5a3a | 2016-06-20 15:20:15 -0700 | [diff] [blame] | 133 | String procStatFile; // path to /proc/<pid>/stat |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 134 | int[] gids; // The gids this process was launched with |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 135 | private String mRequiredAbi;// The ABI this process was launched with |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 136 | 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] | 137 | boolean starting; // True if the process is being started |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 138 | long lastActivityTime; // For managing the LRU list |
Dianne Hackborn | f1cca18 | 2013-08-01 10:50:28 -0700 | [diff] [blame] | 139 | long lastPssTime; // Last time we retrieved PSS data |
| 140 | long nextPssTime; // Next time we want to request PSS data |
| 141 | long lastStateTime; // Last time setProcState changed |
Dianne Hackborn | 35f72be | 2013-09-16 10:57:39 -0700 | [diff] [blame] | 142 | long initialIdlePss; // Initial memory pss of process for idle maintenance. |
| 143 | long lastPss; // Last computed memory pss. |
Thierry Strudel | f0a4418 | 2016-01-07 18:08:04 -0800 | [diff] [blame] | 144 | long lastSwapPss; // Last computed SwapPss. |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 145 | long lastCachedPss; // Last computed pss when in cached state. |
Thierry Strudel | f0a4418 | 2016-01-07 18:08:04 -0800 | [diff] [blame] | 146 | long lastCachedSwapPss; // Last computed SwapPss when in cached state. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | int maxAdj; // Maximum OOM adjustment for this process |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 148 | 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] | 149 | int setRawAdj; // Last set OOM unlimited adjustment for this process |
| 150 | int curAdj; // Current OOM adjustment for this process |
| 151 | int setAdj; // Last set OOM adjustment for this process |
Dianne Hackborn | 4de5a3a | 2016-06-20 15:20:15 -0700 | [diff] [blame] | 152 | int verifiedAdj; // The last adjustment that was verified as actually being set |
Tim Murray | 0b1c8aa | 2018-11-20 10:28:38 -0800 | [diff] [blame] | 153 | long lastCompactTime; // The last time that this process was compacted |
| 154 | int reqCompactAction; // The most recent compaction action requested for this app. |
| 155 | int lastCompactAction; // The most recent compaction action performed for this app. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 156 | private int mCurSchedGroup; // Currently desired scheduling class |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 157 | int setSchedGroup; // Last set to background scheduling class |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 158 | int trimMemoryLevel; // Last selected memory trimming level |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 159 | private int mCurProcState = PROCESS_STATE_NONEXISTENT; // Currently computed process state |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 160 | private int mRepProcState = PROCESS_STATE_NONEXISTENT; // Last reported process state |
Amith Yamasani | 08888c0 | 2018-12-07 09:38:25 -0800 | [diff] [blame] | 161 | private int mCurRawProcState = PROCESS_STATE_NONEXISTENT; // Temp state during computation |
riddle_hsu | 6793fc3 | 2015-03-31 11:54:14 +0800 | [diff] [blame] | 162 | int setProcState = PROCESS_STATE_NONEXISTENT; // Last set process state in process tracker |
| 163 | int pssProcState = PROCESS_STATE_NONEXISTENT; // Currently requesting pss for |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 164 | int pssStatType; // The type of stat collection that we are currently requesting |
Tim Murray | 33eb07f | 2016-06-10 10:03:20 -0700 | [diff] [blame] | 165 | int savedPriority; // Previous priority value if we're switching to non-SCHED_OTHER |
| 166 | int renderThreadTid; // TID for RenderThread |
Dianne Hackborn | a631d56 | 2018-11-20 15:58:15 -0800 | [diff] [blame] | 167 | ServiceRecord connectionService; // Service that applied current connectionGroup/Importance |
| 168 | int connectionGroup; // Last group set by a connection |
| 169 | int connectionImportance; // Last importance set by a connection |
Dianne Hackborn | e02c88a | 2011-10-28 13:58:15 -0700 | [diff] [blame] | 170 | boolean serviceb; // Process currently is on the service B list |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 171 | 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] | 172 | 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] | 173 | private boolean mHasClientActivities; // Are there any client services with activities? |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 174 | boolean hasStartedServices; // Are there any started services running in this process? |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 175 | private boolean mHasForegroundServices; // Running any services that are foreground? |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 176 | 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^] | 177 | private int mRepFgServiceTypes; // Last reported foreground service types. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 178 | private boolean mHasForegroundActivities; // Running any activities that are foreground? |
Dianne Hackborn | 684bf34 | 2014-04-29 17:56:57 -0700 | [diff] [blame] | 179 | boolean repForegroundActivities; // Last reported foreground activities. |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 180 | boolean systemNoUi; // This is a system process, but not currently showing UI. |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 181 | 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] | 182 | 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] | 183 | // is interacting with? E.g. The status bar when it is expanded, but |
| 184 | // not when it is minimized. When true the |
| 185 | // process will be set to use the ProcessList#SCHED_GROUP_TOP_APP |
| 186 | // scheduling group to boost performance. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 187 | 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] | 188 | // overlays on-top of activity UIs on screen. E.g. display a window |
| 189 | // of type |
| 190 | // android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY |
| 191 | // When true the process will oom adj score will be set to |
| 192 | // ProcessList#PERCEPTIBLE_APP_ADJ at minimum to reduce the chance |
| 193 | // of the process getting killed. |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 194 | boolean runningRemoteAnimation; // Is the process currently running a RemoteAnimation? When true |
| 195 | // the process will be set to use the |
| 196 | // ProcessList#SCHED_GROUP_TOP_APP scheduling group to boost |
| 197 | // performance, as well as oom adj score will be set to |
| 198 | // ProcessList#VISIBLE_APP_ADJ at minimum to reduce the chance |
| 199 | // of the process getting killed. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 200 | private boolean mPendingUiClean; // Want to clean up resources from showing UI? |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 201 | boolean hasAboveClient; // Bound using BIND_ABOVE_CLIENT, so want to be lower |
Dianne Hackborn | f0f94d1 | 2014-03-17 16:04:21 -0700 | [diff] [blame] | 202 | boolean treatLikeActivity; // Bound using BIND_TREAT_LIKE_ACTIVITY |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | boolean bad; // True if disabled in the bad process list |
Dianne Hackborn | 35f72be | 2013-09-16 10:57:39 -0700 | [diff] [blame] | 204 | 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] | 205 | boolean killed; // True once we know the process has been killed |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 206 | boolean procStateChanged; // Keep track of whether we changed 'setAdj'. |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 207 | 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] | 208 | boolean unlocked; // True when proc was started in user unlocked state |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 209 | private long mInteractionEventTime; // The time we sent the last interaction event |
| 210 | private long mFgInteractionTime; // When we became foreground for interaction purposes |
Dianne Hackborn | 9357b11 | 2013-10-03 18:27:48 -0700 | [diff] [blame] | 211 | 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] | 212 | Object forcingToImportant; // Token that is forcing this process to be important |
Dianne Hackborn | 906497c | 2010-05-10 15:57:38 -0700 | [diff] [blame] | 213 | int adjSeq; // Sequence id for identifying oom_adj assignment cycles |
Tim Murray | b52f000 | 2018-05-02 15:14:35 -0700 | [diff] [blame] | 214 | int completedAdjSeq; // Sequence id for identifying oom_adj assignment cycles |
| 215 | 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] | 216 | int lruSeq; // Sequence id for identifying LRU update cycles |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 217 | CompatibilityInfo compat; // last used compatibility mode |
Dianne Hackborn | 1b64e0d | 2011-07-17 15:23:59 -0700 | [diff] [blame] | 218 | IBinder.DeathRecipient deathRecipient; // Who is watching for the death. |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 219 | private ActiveInstrumentation mInstr; // Set to currently active instrumentation running in |
| 220 | // process. |
| 221 | 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] | 222 | 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] | 223 | private long mWhenUnimportant; // When (uptime) the process last became unimportant |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 224 | long lastCpuTime; // How long proc has run CPU at last check |
| 225 | 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] | 226 | long lastRequestedGc; // When we last asked the app to do a gc |
Dianne Hackborn | fd12af4 | 2009-08-27 00:44:33 -0700 | [diff] [blame] | 227 | long lastLowMemory; // When we last told the app that memory is low |
Dianne Hackborn | 1a40564 | 2015-11-04 12:32:45 -0800 | [diff] [blame] | 228 | 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] | 229 | 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] | 230 | boolean reportLowMemory; // Set to true when waiting to report low mem |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 231 | boolean empty; // Is this an empty background process? |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 232 | boolean cached; // Is this a cached process? |
Dianne Hackborn | de42bb6 | 2009-08-05 12:26:15 -0700 | [diff] [blame] | 233 | String adjType; // Debugging: primary thing impacting oom_adj. |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 234 | int adjTypeCode; // Debugging: adj code to report to app. |
Dianne Hackborn | de42bb6 | 2009-08-05 12:26:15 -0700 | [diff] [blame] | 235 | Object adjSource; // Debugging: option dependent object. |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 236 | int adjSourceProcState; // Debugging: proc state of adjSource's process. |
Dianne Hackborn | de42bb6 | 2009-08-05 12:26:15 -0700 | [diff] [blame] | 237 | Object adjTarget; // Debugging: target component impacting oom_adj. |
Primiano Tucci | 810c052 | 2014-07-25 18:03:16 +0100 | [diff] [blame] | 238 | Runnable crashHandler; // Optional local handler to be invoked in the process crash. |
| 239 | |
Dianne Hackborn | 8c76d91 | 2018-08-23 15:20:05 -0700 | [diff] [blame] | 240 | // Cache of last retrieve memory info and uptime, to throttle how frequently |
| 241 | // apps can requyest it. |
| 242 | Debug.MemoryInfo lastMemInfo; |
| 243 | long lastMemInfoTime; |
| 244 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 245 | // Controller for driving the process state on the window manager side. |
| 246 | final private WindowProcessController mWindowProcessController; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | // all ServiceRecord running in this process |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 248 | final ArraySet<ServiceRecord> services = new ArraySet<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | // services that are currently executing code (need to remain foreground). |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 250 | final ArraySet<ServiceRecord> executingServices = new ArraySet<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | // All ConnectionRecord this process holds |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 252 | final ArraySet<ConnectionRecord> connections = new ArraySet<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | // all IIntentReceivers that are registered from this process. |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 254 | final ArraySet<ReceiverList> receivers = new ArraySet<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | // class (String) -> ContentProviderRecord |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 256 | final ArrayMap<String, ContentProviderRecord> pubProviders = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | // All ContentProviderRecord process is using |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 258 | final ArrayList<ContentProviderConnection> conProviders = new ArrayList<>(); |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 259 | // A set of tokens that currently contribute to this process being temporarily whitelisted |
| 260 | // to start activities even if it's not in the foreground |
| 261 | final ArraySet<Binder> mAllowBackgroundActivityStartsTokens = new ArraySet<>(); |
Dianne Hackborn | bf36ee2 | 2013-07-26 18:24:10 -0700 | [diff] [blame] | 262 | |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 263 | String isolatedEntryPoint; // Class to run on start if this is a special isolated process. |
| 264 | String[] isolatedEntryPointArgs; // Arguments to pass to isolatedEntryPoint's main(). |
| 265 | |
Dianne Hackborn | bf36ee2 | 2013-07-26 18:24:10 -0700 | [diff] [blame] | 266 | boolean execServicesFg; // do we need to be executing services in the foreground? |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 267 | private boolean mPersistent;// always keep this application running? |
| 268 | private boolean mCrashing; // are we in the process of crashing? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | Dialog crashDialog; // dialog being displayed due to crash. |
Christopher Tate | 58d380d | 2013-03-19 13:10:03 -0700 | [diff] [blame] | 270 | boolean forceCrashReport; // suppress normal auto-dismiss of crash dialog & report UI? |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 271 | private boolean mNotResponding; // does the app have a not responding dialog? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | Dialog anrDialog; // dialog being displayed due to app not resp. |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 273 | volatile boolean removed; // Whether this process should be killed and removed from process |
| 274 | // list. It is set when the package is force-stopped or the process |
| 275 | // has crashed too many times. |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 276 | private boolean mDebugging; // was app launched for debugging? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | boolean waitedForDebugger; // has process show wait for debugger dialog? |
| 278 | Dialog waitDialog; // current wait for debugger dialog |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 279 | |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 280 | String shortStringName; // caching of toShortString() result. |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 281 | String stringName; // caching of toString() result. |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 282 | boolean pendingStart; // Process start is pending. |
| 283 | long startSeq; // Seq no. indicating the latest process start associated with |
| 284 | // this process record. |
Sudheer Shanka | 87915d6 | 2018-11-06 10:57:35 -0800 | [diff] [blame] | 285 | int mountMode; // Indicates how the external storage was mounted for this process. |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | // These reports are generated & stored when an app gets into an error condition. |
| 288 | // They will be "null" when all is OK. |
| 289 | ActivityManager.ProcessErrorStateInfo crashingReport; |
| 290 | ActivityManager.ProcessErrorStateInfo notRespondingReport; |
| 291 | |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 292 | // Who will be notified of the error. This is usually an activity in the |
| 293 | // app that installed the package. |
| 294 | ComponentName errorReportReceiver; |
| 295 | |
Amith Yamasani | b5f3b5c | 2016-05-16 14:23:04 -0700 | [diff] [blame] | 296 | // Process is currently hosting a backup agent for backup or restore |
| 297 | public boolean inFullBackup; |
Felipe Leme | a1b79bf | 2016-05-24 13:06:54 -0700 | [diff] [blame] | 298 | // App is allowed to manage whitelists such as temporary Power Save mode whitelist. |
| 299 | boolean whitelistManager; |
Amith Yamasani | b5f3b5c | 2016-05-16 14:23:04 -0700 | [diff] [blame] | 300 | |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 301 | // Params used in starting this process. |
| 302 | String hostingType; |
| 303 | String hostingNameStr; |
| 304 | String seInfo; |
| 305 | long startTime; |
| 306 | // This will be same as {@link #uid} usually except for some apps used during factory testing. |
| 307 | int startUid; |
| 308 | |
| 309 | void setStartParams(int startUid, String hostingType, String hostingNameStr, String seInfo, |
| 310 | long startTime) { |
| 311 | this.startUid = startUid; |
| 312 | this.hostingType = hostingType; |
| 313 | this.hostingNameStr = hostingNameStr; |
| 314 | this.seInfo = seInfo; |
| 315 | this.startTime = startTime; |
| 316 | } |
| 317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 319 | final long nowUptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 320 | |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 321 | pw.print(prefix); pw.print("user #"); pw.print(userId); |
| 322 | pw.print(" uid="); pw.print(info.uid); |
| 323 | if (uid != info.uid) { |
| 324 | pw.print(" ISOLATED uid="); pw.print(uid); |
| 325 | } |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 326 | pw.print(" gids={"); |
| 327 | if (gids != null) { |
| 328 | for (int gi=0; gi<gids.length; gi++) { |
| 329 | if (gi != 0) pw.print(", "); |
| 330 | pw.print(gids[gi]); |
| 331 | |
| 332 | } |
| 333 | } |
| 334 | pw.println("}"); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 335 | pw.print(prefix); pw.print("mRequiredAbi="); pw.print(mRequiredAbi); |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 336 | pw.print(" instructionSet="); pw.println(instructionSet); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 337 | if (info.className != null) { |
| 338 | pw.print(prefix); pw.print("class="); pw.println(info.className); |
| 339 | } |
| 340 | if (info.manageSpaceActivityName != null) { |
| 341 | pw.print(prefix); pw.print("manageSpaceActivityName="); |
| 342 | pw.println(info.manageSpaceActivityName); |
| 343 | } |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 344 | |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 345 | pw.print(prefix); pw.print("dir="); pw.print(info.sourceDir); |
| 346 | pw.print(" publicDir="); pw.print(info.publicSourceDir); |
| 347 | pw.print(" data="); pw.println(info.dataDir); |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 348 | pw.print(prefix); pw.print("packageList={"); |
| 349 | for (int i=0; i<pkgList.size(); i++) { |
| 350 | if (i > 0) pw.print(", "); |
| 351 | pw.print(pkgList.keyAt(i)); |
| 352 | } |
| 353 | pw.println("}"); |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 354 | if (pkgDeps != null) { |
| 355 | pw.print(prefix); pw.print("packageDependencies={"); |
| 356 | for (int i=0; i<pkgDeps.size(); i++) { |
| 357 | if (i > 0) pw.print(", "); |
| 358 | pw.print(pkgDeps.valueAt(i)); |
| 359 | } |
| 360 | pw.println("}"); |
| 361 | } |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 362 | pw.print(prefix); pw.print("compat="); pw.println(compat); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 363 | if (mInstr != null) { |
| 364 | pw.print(prefix); pw.print("mInstr="); pw.println(mInstr); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 365 | } |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 366 | pw.print(prefix); pw.print("thread="); pw.println(thread); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 367 | pw.print(prefix); pw.print("pid="); pw.print(pid); pw.print(" starting="); |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 368 | pw.println(starting); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 369 | pw.print(prefix); pw.print("lastActivityTime="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 370 | TimeUtils.formatDuration(lastActivityTime, nowUptime, pw); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 371 | pw.print(" lastPssTime="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 372 | TimeUtils.formatDuration(lastPssTime, nowUptime, pw); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 373 | pw.print(" pssStatType="); pw.print(pssStatType); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 374 | pw.print(" nextPssTime="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 375 | TimeUtils.formatDuration(nextPssTime, nowUptime, pw); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 376 | pw.println(); |
| 377 | pw.print(prefix); pw.print("adjSeq="); pw.print(adjSeq); |
| 378 | pw.print(" lruSeq="); pw.print(lruSeq); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 379 | pw.print(" lastPss="); DebugUtils.printSizeValue(pw, lastPss*1024); |
Thierry Strudel | f0a4418 | 2016-01-07 18:08:04 -0800 | [diff] [blame] | 380 | pw.print(" lastSwapPss="); DebugUtils.printSizeValue(pw, lastSwapPss*1024); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 381 | pw.print(" lastCachedPss="); DebugUtils.printSizeValue(pw, lastCachedPss*1024); |
Thierry Strudel | f0a4418 | 2016-01-07 18:08:04 -0800 | [diff] [blame] | 382 | pw.print(" lastCachedSwapPss="); DebugUtils.printSizeValue(pw, lastCachedSwapPss*1024); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 383 | pw.println(); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 384 | pw.print(prefix); pw.print("procStateMemTracker: "); |
| 385 | procStateMemTracker.dumpLine(pw); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 386 | pw.print(prefix); pw.print("cached="); pw.print(cached); |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 387 | pw.print(" empty="); pw.println(empty); |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 388 | if (serviceb) { |
| 389 | pw.print(prefix); pw.print("serviceb="); pw.print(serviceb); |
| 390 | pw.print(" serviceHighRam="); pw.println(serviceHighRam); |
| 391 | } |
Dianne Hackborn | 35f72be | 2013-09-16 10:57:39 -0700 | [diff] [blame] | 392 | if (notCachedSinceIdle) { |
| 393 | pw.print(prefix); pw.print("notCachedSinceIdle="); pw.print(notCachedSinceIdle); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 394 | pw.print(" initialIdlePss="); pw.println(initialIdlePss); |
Dianne Hackborn | 35f72be | 2013-09-16 10:57:39 -0700 | [diff] [blame] | 395 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 396 | pw.print(prefix); pw.print("oom: max="); pw.print(maxAdj); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 397 | pw.print(" curRaw="); pw.print(mCurRawAdj); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 398 | pw.print(" setRaw="); pw.print(setRawAdj); |
| 399 | pw.print(" cur="); pw.print(curAdj); |
| 400 | pw.print(" set="); pw.println(setAdj); |
Tim Murray | 0b1c8aa | 2018-11-20 10:28:38 -0800 | [diff] [blame] | 401 | pw.print(prefix); pw.print("lastCompactTime="); pw.print(lastCompactTime); |
| 402 | pw.print(" lastCompactAction="); pw.print(lastCompactAction); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 403 | pw.print(prefix); pw.print("mCurSchedGroup="); pw.print(mCurSchedGroup); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 404 | pw.print(" setSchedGroup="); pw.print(setSchedGroup); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 405 | pw.print(" systemNoUi="); pw.print(systemNoUi); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 406 | pw.print(" trimMemoryLevel="); pw.println(trimMemoryLevel); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 407 | pw.print(prefix); pw.print("curProcState="); pw.print(getCurProcState()); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 408 | pw.print(" mRepProcState="); pw.print(mRepProcState); |
Dianne Hackborn | f1cca18 | 2013-08-01 10:50:28 -0700 | [diff] [blame] | 409 | pw.print(" pssProcState="); pw.print(pssProcState); |
| 410 | pw.print(" setProcState="); pw.print(setProcState); |
| 411 | pw.print(" lastStateTime="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 412 | TimeUtils.formatDuration(lastStateTime, nowUptime, pw); |
Dianne Hackborn | f1cca18 | 2013-08-01 10:50:28 -0700 | [diff] [blame] | 413 | pw.println(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 414 | if (hasShownUi || mPendingUiClean || hasAboveClient || treatLikeActivity) { |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 415 | pw.print(prefix); pw.print("hasShownUi="); pw.print(hasShownUi); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 416 | pw.print(" pendingUiClean="); pw.print(mPendingUiClean); |
Dianne Hackborn | f0f94d1 | 2014-03-17 16:04:21 -0700 | [diff] [blame] | 417 | pw.print(" hasAboveClient="); pw.print(hasAboveClient); |
| 418 | pw.print(" treatLikeActivity="); pw.println(treatLikeActivity); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 419 | } |
Dianne Hackborn | a631d56 | 2018-11-20 15:58:15 -0800 | [diff] [blame] | 420 | if (connectionService != null || connectionGroup != 0) { |
| 421 | pw.print(prefix); pw.print("connectionGroup="); pw.print(connectionGroup); |
| 422 | pw.print(" Importance="); pw.print(connectionImportance); |
| 423 | pw.print(" Service="); pw.println(connectionService); |
| 424 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 425 | if (hasTopUi() || hasOverlayUi() || runningRemoteAnimation) { |
| 426 | pw.print(prefix); pw.print("hasTopUi="); pw.print(hasTopUi()); |
| 427 | pw.print(" hasOverlayUi="); pw.print(hasOverlayUi()); |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 428 | pw.print(" runningRemoteAnimation="); pw.println(runningRemoteAnimation); |
Dianne Hackborn | a1baf73 | 2017-05-25 15:33:53 -0700 | [diff] [blame] | 429 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 430 | if (mHasForegroundServices || forcingToImportant != null) { |
| 431 | pw.print(prefix); pw.print("mHasForegroundServices="); pw.print(mHasForegroundServices); |
Dianne Hackborn | f965f40 | 2017-05-04 23:27:23 -0700 | [diff] [blame] | 432 | pw.print(" forcingToImportant="); pw.println(forcingToImportant); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 433 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 434 | if (reportedInteraction || mFgInteractionTime != 0) { |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 435 | pw.print(prefix); pw.print("reportedInteraction="); |
| 436 | pw.print(reportedInteraction); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 437 | if (mInteractionEventTime != 0) { |
Dianne Hackborn | fcc95a6 | 2015-11-02 13:43:29 -0800 | [diff] [blame] | 438 | pw.print(" time="); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 439 | TimeUtils.formatDuration(mInteractionEventTime, SystemClock.elapsedRealtime(), pw); |
Dianne Hackborn | fcc95a6 | 2015-11-02 13:43:29 -0800 | [diff] [blame] | 440 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 441 | if (mFgInteractionTime != 0) { |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 442 | pw.print(" fgInteractionTime="); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 443 | TimeUtils.formatDuration(mFgInteractionTime, SystemClock.elapsedRealtime(), pw); |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 444 | } |
| 445 | pw.println(); |
| 446 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 447 | if (mPersistent || removed) { |
| 448 | pw.print(prefix); pw.print("persistent="); pw.print(mPersistent); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 449 | pw.print(" removed="); pw.println(removed); |
| 450 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 451 | if (mHasClientActivities || mHasForegroundActivities || repForegroundActivities) { |
| 452 | pw.print(prefix); pw.print("hasClientActivities="); pw.print(mHasClientActivities); |
| 453 | pw.print(" foregroundActivities="); pw.print(mHasForegroundActivities); |
Dianne Hackborn | 684bf34 | 2014-04-29 17:56:57 -0700 | [diff] [blame] | 454 | pw.print(" (rep="); pw.print(repForegroundActivities); pw.println(")"); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 455 | } |
Dianne Hackborn | 1a40564 | 2015-11-04 12:32:45 -0800 | [diff] [blame] | 456 | if (lastProviderTime > 0) { |
| 457 | pw.print(prefix); pw.print("lastProviderTime="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 458 | TimeUtils.formatDuration(lastProviderTime, nowUptime, pw); |
Dianne Hackborn | 1a40564 | 2015-11-04 12:32:45 -0800 | [diff] [blame] | 459 | pw.println(); |
| 460 | } |
Amith Yamasani | e5bfeee | 2018-09-05 18:52:35 -0700 | [diff] [blame] | 461 | if (lastTopTime > 0) { |
| 462 | pw.print(prefix); pw.print("lastTopTime="); |
| 463 | TimeUtils.formatDuration(lastTopTime, nowUptime, pw); |
| 464 | pw.println(); |
| 465 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 466 | if (hasStartedServices) { |
| 467 | pw.print(prefix); pw.print("hasStartedServices="); pw.println(hasStartedServices); |
| 468 | } |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 469 | if (pendingStart) { |
| 470 | pw.print(prefix); pw.print("pendingStart="); pw.println(pendingStart); |
| 471 | } |
| 472 | pw.print(prefix); pw.print("startSeq="); pw.println(startSeq); |
Sudheer Shanka | 87915d6 | 2018-11-06 10:57:35 -0800 | [diff] [blame] | 473 | pw.print(prefix); pw.print("mountMode="); pw.println( |
| 474 | DebugUtils.valueToString(Zygote.class, "MOUNT_EXTERNAL_", mountMode)); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 475 | if (setProcState > ActivityManager.PROCESS_STATE_SERVICE) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 476 | pw.print(prefix); pw.print("lastCpuTime="); pw.print(lastCpuTime); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 477 | if (lastCpuTime > 0) { |
| 478 | pw.print(" timeUsed="); |
| 479 | TimeUtils.formatDuration(curCpuTime - lastCpuTime, pw); |
| 480 | } |
| 481 | pw.print(" whenUnimportant="); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 482 | TimeUtils.formatDuration(mWhenUnimportant - nowUptime, pw); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 483 | pw.println(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 484 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 485 | pw.print(prefix); pw.print("lastRequestedGc="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 486 | TimeUtils.formatDuration(lastRequestedGc, nowUptime, pw); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 487 | pw.print(" lastLowMemory="); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 488 | TimeUtils.formatDuration(lastLowMemory, nowUptime, pw); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 489 | pw.print(" reportLowMemory="); pw.println(reportLowMemory); |
Dianne Hackborn | d412563 | 2014-09-22 12:52:49 -0700 | [diff] [blame] | 490 | if (killed || killedByAm || waitingToKill != null) { |
| 491 | pw.print(prefix); pw.print("killed="); pw.print(killed); |
| 492 | pw.print(" killedByAm="); pw.print(killedByAm); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 493 | pw.print(" waitingToKill="); pw.println(waitingToKill); |
Dianne Hackborn | 149427c | 2010-04-23 14:20:03 -0700 | [diff] [blame] | 494 | } |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 495 | if (mDebugging || mCrashing || crashDialog != null || mNotResponding |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 496 | || anrDialog != null || bad) { |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 497 | pw.print(prefix); pw.print("mDebugging="); pw.print(mDebugging); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 498 | pw.print(" mCrashing="); pw.print(mCrashing); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 499 | pw.print(" "); pw.print(crashDialog); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 500 | pw.print(" mNotResponding="); pw.print(mNotResponding); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 501 | pw.print(" " ); pw.print(anrDialog); |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 502 | pw.print(" bad="); pw.print(bad); |
| 503 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 504 | // mCrashing or mNotResponding is always set before errorReportReceiver |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 505 | if (errorReportReceiver != null) { |
| 506 | pw.print(" errorReportReceiver="); |
| 507 | pw.print(errorReportReceiver.flattenToShortString()); |
| 508 | } |
| 509 | pw.println(); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 510 | } |
Felipe Leme | a1b79bf | 2016-05-24 13:06:54 -0700 | [diff] [blame] | 511 | if (whitelistManager) { |
| 512 | pw.print(prefix); pw.print("whitelistManager="); pw.println(whitelistManager); |
| 513 | } |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 514 | if (isolatedEntryPoint != null || isolatedEntryPointArgs != null) { |
| 515 | pw.print(prefix); pw.print("isolatedEntryPoint="); pw.println(isolatedEntryPoint); |
| 516 | pw.print(prefix); pw.print("isolatedEntryPointArgs="); |
| 517 | pw.println(Arrays.toString(isolatedEntryPointArgs)); |
| 518 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 519 | mWindowProcessController.dump(pw, prefix); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 520 | if (services.size() > 0) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 521 | pw.print(prefix); pw.println("Services:"); |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 522 | for (int i=0; i<services.size(); i++) { |
| 523 | pw.print(prefix); pw.print(" - "); pw.println(services.valueAt(i)); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 524 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 525 | } |
| 526 | if (executingServices.size() > 0) { |
Dianne Hackborn | bf36ee2 | 2013-07-26 18:24:10 -0700 | [diff] [blame] | 527 | pw.print(prefix); pw.print("Executing Services (fg="); |
| 528 | pw.print(execServicesFg); pw.println(")"); |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 529 | for (int i=0; i<executingServices.size(); i++) { |
| 530 | pw.print(prefix); pw.print(" - "); pw.println(executingServices.valueAt(i)); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 531 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 532 | } |
| 533 | if (connections.size() > 0) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 534 | pw.print(prefix); pw.println("Connections:"); |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 535 | for (int i=0; i<connections.size(); i++) { |
| 536 | pw.print(prefix); pw.print(" - "); pw.println(connections.valueAt(i)); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 537 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 538 | } |
| 539 | if (pubProviders.size() > 0) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 540 | pw.print(prefix); pw.println("Published Providers:"); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 541 | for (int i=0; i<pubProviders.size(); i++) { |
| 542 | pw.print(prefix); pw.print(" - "); pw.println(pubProviders.keyAt(i)); |
| 543 | pw.print(prefix); pw.print(" -> "); pw.println(pubProviders.valueAt(i)); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 544 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 545 | } |
| 546 | if (conProviders.size() > 0) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 547 | pw.print(prefix); pw.println("Connected Providers:"); |
| 548 | for (int i=0; i<conProviders.size(); i++) { |
| 549 | pw.print(prefix); pw.print(" - "); pw.println(conProviders.get(i).toShortString()); |
| 550 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 551 | } |
yangzhenyu | d509bc9 | 2016-08-31 18:26:46 +0800 | [diff] [blame] | 552 | if (!curReceivers.isEmpty()) { |
| 553 | pw.print(prefix); pw.println("Current Receivers:"); |
| 554 | for (int i=0; i < curReceivers.size(); i++) { |
| 555 | pw.print(prefix); pw.print(" - "); pw.println(curReceivers.valueAt(i)); |
| 556 | } |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 557 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 558 | if (receivers.size() > 0) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 559 | pw.print(prefix); pw.println("Receivers:"); |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 560 | for (int i=0; i<receivers.size(); i++) { |
| 561 | pw.print(prefix); pw.print(" - "); pw.println(receivers.valueAt(i)); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 562 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 563 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 565 | |
Bookatz | 152623f | 2018-07-23 15:57:44 -0700 | [diff] [blame] | 566 | ProcessRecord(ActivityManagerService _service, ApplicationInfo _info, String _processName, |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 567 | int _uid) { |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 568 | mService = _service; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | info = _info; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 570 | isolated = _info.uid != _uid; |
Martijn Coenen | 01e719b | 2018-12-05 16:01:38 +0100 | [diff] [blame] | 571 | appZygote = (UserHandle.getAppId(_uid) >= Process.FIRST_APP_ZYGOTE_ISOLATED_UID |
| 572 | && UserHandle.getAppId(_uid) <= Process.LAST_APP_ZYGOTE_ISOLATED_UID); |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 573 | uid = _uid; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 574 | userId = UserHandle.getUserId(_uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 575 | processName = _processName; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 576 | maxAdj = ProcessList.UNKNOWN_ADJ; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 577 | mCurRawAdj = setRawAdj = ProcessList.INVALID_ADJ; |
Dianne Hackborn | 4de5a3a | 2016-06-20 15:20:15 -0700 | [diff] [blame] | 578 | curAdj = setAdj = verifiedAdj = ProcessList.INVALID_ADJ; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 579 | mPersistent = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 580 | removed = false; |
Dianne Hackborn | f1cca18 | 2013-08-01 10:50:28 -0700 | [diff] [blame] | 581 | lastStateTime = lastPssTime = nextPssTime = SystemClock.uptimeMillis(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 582 | mWindowProcessController = new WindowProcessController( |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 583 | mService.mActivityTaskManager, info, processName, uid, userId, this, this); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 584 | pkgList.put(_info.packageName, new ProcessStats.ProcessStateHolder(_info.longVersionCode)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | } |
| 586 | |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 587 | public void setPid(int _pid) { |
| 588 | pid = _pid; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 589 | mWindowProcessController.setPid(pid); |
Dianne Hackborn | 4de5a3a | 2016-06-20 15:20:15 -0700 | [diff] [blame] | 590 | procStatFile = null; |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 591 | shortStringName = null; |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 592 | stringName = null; |
| 593 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 594 | |
| 595 | public void makeActive(IApplicationThread _thread, ProcessStatsService tracker) { |
| 596 | if (thread == null) { |
Joe Onorato | 4eb64fd | 2016-03-21 15:30:09 -0700 | [diff] [blame] | 597 | final ProcessState origBase = baseProcessTracker; |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 598 | if (origBase != null) { |
| 599 | origBase.setState(ProcessStats.STATE_NOTHING, |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 600 | tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList); |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 601 | for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) { |
| 602 | StatsLog.write(StatsLog.PROCESS_STATE_CHANGED, |
| 603 | uid, processName, pkgList.keyAt(ipkg), |
| 604 | ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING), |
| 605 | pkgList.valueAt(ipkg).appVersion); |
| 606 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 607 | origBase.makeInactive(); |
| 608 | } |
Dianne Hackborn | 2f55e5a | 2018-11-30 16:31:31 -0800 | [diff] [blame] | 609 | baseProcessTracker = tracker.getProcessStateLocked(info.packageName, info.uid, |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 610 | info.longVersionCode, processName); |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 611 | baseProcessTracker.makeActive(); |
| 612 | for (int i=0; i<pkgList.size(); i++) { |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 613 | ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i); |
| 614 | if (holder.state != null && holder.state != origBase) { |
| 615 | holder.state.makeInactive(); |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 616 | } |
Dianne Hackborn | 2f55e5a | 2018-11-30 16:31:31 -0800 | [diff] [blame] | 617 | tracker.updateProcessStateHolderLocked(holder, pkgList.keyAt(i), info.uid, |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 618 | info.longVersionCode, processName); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 619 | if (holder.state != baseProcessTracker) { |
| 620 | holder.state.makeActive(); |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 621 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | thread = _thread; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 625 | mWindowProcessController.setThread(thread); |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | public void makeInactive(ProcessStatsService tracker) { |
Dianne Hackborn | 53459a7 | 2013-09-17 17:14:57 -0700 | [diff] [blame] | 629 | thread = null; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 630 | mWindowProcessController.setThread(null); |
Joe Onorato | 4eb64fd | 2016-03-21 15:30:09 -0700 | [diff] [blame] | 631 | final ProcessState origBase = baseProcessTracker; |
Dianne Hackborn | 53459a7 | 2013-09-17 17:14:57 -0700 | [diff] [blame] | 632 | if (origBase != null) { |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 633 | if (origBase != null) { |
| 634 | origBase.setState(ProcessStats.STATE_NOTHING, |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 635 | tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList.mPkgList); |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 636 | for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) { |
| 637 | StatsLog.write(StatsLog.PROCESS_STATE_CHANGED, |
| 638 | uid, processName, pkgList.keyAt(ipkg), |
| 639 | ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING), |
| 640 | pkgList.valueAt(ipkg).appVersion); |
| 641 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 642 | origBase.makeInactive(); |
| 643 | } |
| 644 | baseProcessTracker = null; |
| 645 | for (int i=0; i<pkgList.size(); i++) { |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 646 | ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i); |
| 647 | if (holder.state != null && holder.state != origBase) { |
| 648 | holder.state.makeInactive(); |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 649 | } |
Dianne Hackborn | 2aec55a | 2018-06-26 10:35:35 -0700 | [diff] [blame] | 650 | holder.pkg = null; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 651 | holder.state = null; |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 652 | } |
| 653 | } |
| 654 | } |
| 655 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 656 | boolean hasActivities() { |
| 657 | return mWindowProcessController.hasActivities(); |
| 658 | } |
| 659 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 660 | boolean hasActivitiesOrRecentTasks() { |
| 661 | return mWindowProcessController.hasActivitiesOrRecentTasks(); |
| 662 | } |
| 663 | |
| 664 | boolean hasRecentTasks() { |
| 665 | return mWindowProcessController.hasRecentTasks(); |
| 666 | } |
| 667 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | /** |
| 669 | * This method returns true if any of the activities within the process record are interesting |
| 670 | * to the user. See HistoryRecord.isInterestingToUserLocked() |
| 671 | */ |
| 672 | public boolean isInterestingToUserLocked() { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 673 | if (mWindowProcessController.isInterestingToUser()) { |
| 674 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | } |
Narayan Kamath | a22d9fb | 2017-04-26 15:14:26 +0100 | [diff] [blame] | 676 | |
| 677 | final int servicesSize = services.size(); |
| 678 | for (int i = 0; i < servicesSize; i++) { |
| 679 | ServiceRecord r = services.valueAt(i); |
| 680 | if (r.isForeground) { |
| 681 | return true; |
| 682 | } |
| 683 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | return false; |
| 685 | } |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 686 | |
Dianne Hackborn | 1b64e0d | 2011-07-17 15:23:59 -0700 | [diff] [blame] | 687 | public void unlinkDeathRecipient() { |
| 688 | if (deathRecipient != null && thread != null) { |
| 689 | thread.asBinder().unlinkToDeath(deathRecipient, 0); |
| 690 | } |
| 691 | deathRecipient = null; |
| 692 | } |
| 693 | |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 694 | void updateHasAboveClientLocked() { |
| 695 | hasAboveClient = false; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 696 | for (int i=connections.size()-1; i>=0; i--) { |
| 697 | ConnectionRecord cr = connections.valueAt(i); |
| 698 | if ((cr.flags&Context.BIND_ABOVE_CLIENT) != 0) { |
| 699 | hasAboveClient = true; |
| 700 | break; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 701 | } |
| 702 | } |
| 703 | } |
| 704 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 705 | int modifyRawOomAdj(int adj) { |
| 706 | if (hasAboveClient) { |
| 707 | // If this process has bound to any services with BIND_ABOVE_CLIENT, |
| 708 | // then we need to drop its adjustment to be lower than the service's |
| 709 | // in order to honor the request. We want to drop it by one adjustment |
| 710 | // level... but there is special meaning applied to various levels so |
| 711 | // we will skip some of them. |
| 712 | if (adj < ProcessList.FOREGROUND_APP_ADJ) { |
| 713 | // System process will not get dropped, ever |
| 714 | } else if (adj < ProcessList.VISIBLE_APP_ADJ) { |
| 715 | adj = ProcessList.VISIBLE_APP_ADJ; |
| 716 | } else if (adj < ProcessList.PERCEPTIBLE_APP_ADJ) { |
| 717 | adj = ProcessList.PERCEPTIBLE_APP_ADJ; |
Amith Yamasani | 0567ec6 | 2019-01-23 11:11:02 -0800 | [diff] [blame] | 718 | } else if (adj < ProcessList.PERCEPTIBLE_LOW_APP_ADJ) { |
| 719 | adj = ProcessList.PERCEPTIBLE_LOW_APP_ADJ; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 720 | } else if (adj < ProcessList.CACHED_APP_MIN_ADJ) { |
| 721 | adj = ProcessList.CACHED_APP_MIN_ADJ; |
| 722 | } else if (adj < ProcessList.CACHED_APP_MAX_ADJ) { |
| 723 | adj++; |
| 724 | } |
| 725 | } |
| 726 | return adj; |
| 727 | } |
| 728 | |
Joe Onorato | 5719028 | 2016-04-20 15:37:49 -0700 | [diff] [blame] | 729 | void scheduleCrash(String message) { |
| 730 | // Checking killedbyAm should keep it from showing the crash dialog if the process |
| 731 | // was already dead for a good / normal reason. |
| 732 | if (!killedByAm) { |
| 733 | if (thread != null) { |
| 734 | if (pid == Process.myPid()) { |
| 735 | Slog.w(TAG, "scheduleCrash: trying to crash system process!"); |
| 736 | return; |
| 737 | } |
| 738 | long ident = Binder.clearCallingIdentity(); |
| 739 | try { |
| 740 | thread.scheduleCrash(message); |
| 741 | } catch (RemoteException e) { |
| 742 | // If it's already dead our work is done. If it's wedged just kill it. |
| 743 | // We won't get the crash dialog or the error reporting. |
| 744 | kill("scheduleCrash for '" + message + "' failed", true); |
| 745 | } finally { |
| 746 | Binder.restoreCallingIdentity(ident); |
| 747 | } |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 752 | void kill(String reason, boolean noisy) { |
| 753 | if (!killedByAm) { |
Yusuke Sato | cf4b254 | 2015-06-17 00:21:28 -0700 | [diff] [blame] | 754 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "kill"); |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 755 | if (mService != null && (noisy || info.uid == mService.mCurOomAdjUid)) { |
| 756 | mService.reportUidInfoMessageLocked(TAG, |
| 757 | "Killing " + toShortString() + " (adj " + setAdj + "): " + reason, |
| 758 | info.uid); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 759 | } |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 760 | if (pid > 0) { |
| 761 | EventLog.writeEvent(EventLogTags.AM_KILL, userId, pid, processName, setAdj, reason); |
| 762 | Process.killProcessQuiet(pid); |
Amith Yamasani | 98a0092 | 2018-08-21 12:50:30 -0400 | [diff] [blame] | 763 | ProcessList.killProcessGroup(uid, pid); |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 764 | } else { |
| 765 | pendingStart = false; |
| 766 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 767 | if (!mPersistent) { |
Dianne Hackborn | d412563 | 2014-09-22 12:52:49 -0700 | [diff] [blame] | 768 | killed = true; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 769 | killedByAm = true; |
| 770 | } |
Yusuke Sato | cf4b254 | 2015-06-17 00:21:28 -0700 | [diff] [blame] | 771 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 775 | @Override |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 776 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
Dianne Hackborn | 2f55e5a | 2018-11-30 16:31:31 -0800 | [diff] [blame] | 777 | writeToProto(proto, fieldId, -1); |
| 778 | } |
| 779 | |
| 780 | public void writeToProto(ProtoOutputStream proto, long fieldId, int lruIndex) { |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 781 | long token = proto.start(fieldId); |
| 782 | proto.write(ProcessRecordProto.PID, pid); |
| 783 | proto.write(ProcessRecordProto.PROCESS_NAME, processName); |
Dianne Hackborn | 2f55e5a | 2018-11-30 16:31:31 -0800 | [diff] [blame] | 784 | proto.write(ProcessRecordProto.UID, info.uid); |
| 785 | if (UserHandle.getAppId(info.uid) >= Process.FIRST_APPLICATION_UID) { |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 786 | proto.write(ProcessRecordProto.USER_ID, userId); |
| 787 | proto.write(ProcessRecordProto.APP_ID, UserHandle.getAppId(info.uid)); |
Dianne Hackborn | 2f55e5a | 2018-11-30 16:31:31 -0800 | [diff] [blame] | 788 | } |
| 789 | if (uid != info.uid) { |
| 790 | proto.write(ProcessRecordProto.ISOLATED_APP_ID, UserHandle.getAppId(uid)); |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 791 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 792 | proto.write(ProcessRecordProto.PERSISTENT, mPersistent); |
Dianne Hackborn | 2f55e5a | 2018-11-30 16:31:31 -0800 | [diff] [blame] | 793 | if (lruIndex >= 0) { |
| 794 | proto.write(ProcessRecordProto.LRU_INDEX, lruIndex); |
| 795 | } |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 796 | proto.end(token); |
| 797 | } |
| 798 | |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 799 | public String toShortString() { |
| 800 | if (shortStringName != null) { |
| 801 | return shortStringName; |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 802 | } |
| 803 | StringBuilder sb = new StringBuilder(128); |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 804 | toShortString(sb); |
| 805 | return shortStringName = sb.toString(); |
| 806 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 807 | |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 808 | void toShortString(StringBuilder sb) { |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 809 | sb.append(pid); |
| 810 | sb.append(':'); |
| 811 | sb.append(processName); |
| 812 | sb.append('/'); |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 813 | if (info.uid < Process.FIRST_APPLICATION_UID) { |
| 814 | sb.append(uid); |
| 815 | } else { |
| 816 | sb.append('u'); |
| 817 | sb.append(userId); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 818 | int appId = UserHandle.getAppId(info.uid); |
| 819 | if (appId >= Process.FIRST_APPLICATION_UID) { |
| 820 | sb.append('a'); |
| 821 | sb.append(appId - Process.FIRST_APPLICATION_UID); |
| 822 | } else { |
| 823 | sb.append('s'); |
| 824 | sb.append(appId); |
| 825 | } |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 826 | if (uid != info.uid) { |
| 827 | sb.append('i'); |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 828 | sb.append(UserHandle.getAppId(uid) - Process.FIRST_ISOLATED_UID); |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 829 | } |
| 830 | } |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 831 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 832 | |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 833 | public String toString() { |
| 834 | if (stringName != null) { |
| 835 | return stringName; |
| 836 | } |
| 837 | StringBuilder sb = new StringBuilder(128); |
| 838 | sb.append("ProcessRecord{"); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 839 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 840 | sb.append(' '); |
Dianne Hackborn | dd71fc8 | 2009-12-16 19:24:32 -0800 | [diff] [blame] | 841 | toShortString(sb); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 842 | sb.append('}'); |
| 843 | return stringName = sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | } |
Dianne Hackborn | 9210bc8 | 2013-09-05 12:31:16 -0700 | [diff] [blame] | 845 | |
| 846 | public String makeAdjReason() { |
Dianne Hackborn | 9210bc8 | 2013-09-05 12:31:16 -0700 | [diff] [blame] | 847 | if (adjSource != null || adjTarget != null) { |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 848 | StringBuilder sb = new StringBuilder(128); |
Dianne Hackborn | 9210bc8 | 2013-09-05 12:31:16 -0700 | [diff] [blame] | 849 | sb.append(' '); |
| 850 | if (adjTarget instanceof ComponentName) { |
| 851 | sb.append(((ComponentName)adjTarget).flattenToShortString()); |
| 852 | } else if (adjTarget != null) { |
| 853 | sb.append(adjTarget.toString()); |
| 854 | } else { |
| 855 | sb.append("{null}"); |
| 856 | } |
| 857 | sb.append("<="); |
| 858 | if (adjSource instanceof ProcessRecord) { |
| 859 | sb.append("Proc{"); |
| 860 | sb.append(((ProcessRecord)adjSource).toShortString()); |
| 861 | sb.append("}"); |
| 862 | } else if (adjSource != null) { |
| 863 | sb.append(adjSource.toString()); |
| 864 | } else { |
| 865 | sb.append("{null}"); |
| 866 | } |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 867 | return sb.toString(); |
Dianne Hackborn | 9210bc8 | 2013-09-05 12:31:16 -0700 | [diff] [blame] | 868 | } |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 869 | return null; |
Dianne Hackborn | 9210bc8 | 2013-09-05 12:31:16 -0700 | [diff] [blame] | 870 | } |
| 871 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 872 | @Override |
| 873 | public void addPackage(String pkg, long versionCode) { |
| 874 | synchronized (mService) { |
| 875 | addPackage(pkg, versionCode, mService.mProcessStats); |
| 876 | } |
| 877 | } |
| 878 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 879 | /* |
| 880 | * Return true if package has been added false if not |
| 881 | */ |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 882 | public boolean addPackage(String pkg, long versionCode, ProcessStatsService tracker) { |
Dianne Hackborn | 78a369c | 2013-06-11 17:10:32 -0700 | [diff] [blame] | 883 | if (!pkgList.containsKey(pkg)) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 884 | ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder( |
| 885 | versionCode); |
Dianne Hackborn | 53459a7 | 2013-09-17 17:14:57 -0700 | [diff] [blame] | 886 | if (baseProcessTracker != null) { |
Dianne Hackborn | 2f55e5a | 2018-11-30 16:31:31 -0800 | [diff] [blame] | 887 | tracker.updateProcessStateHolderLocked(holder, pkg, info.uid, versionCode, |
| 888 | processName); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 889 | pkgList.put(pkg, holder); |
| 890 | if (holder.state != baseProcessTracker) { |
| 891 | holder.state.makeActive(); |
Dianne Hackborn | 53459a7 | 2013-09-17 17:14:57 -0700 | [diff] [blame] | 892 | } |
| 893 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 894 | pkgList.put(pkg, holder); |
Dianne Hackborn | 53459a7 | 2013-09-17 17:14:57 -0700 | [diff] [blame] | 895 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 896 | return true; |
| 897 | } |
| 898 | return false; |
| 899 | } |
Dianne Hackborn | 78a369c | 2013-06-11 17:10:32 -0700 | [diff] [blame] | 900 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 901 | public int getSetAdjWithServices() { |
Dianne Hackborn | 20cdcee | 2013-07-10 18:47:04 -0700 | [diff] [blame] | 902 | if (setAdj >= ProcessList.CACHED_APP_MIN_ADJ) { |
| 903 | if (hasStartedServices) { |
| 904 | return ProcessList.SERVICE_B_ADJ; |
| 905 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 906 | } |
| 907 | return setAdj; |
| 908 | } |
| 909 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 910 | public void forceProcessStateUpTo(int newState) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 911 | if (mRepProcState > newState) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 912 | mRepProcState = newState; |
| 913 | setCurProcState(newState); |
Amith Yamasani | 08888c0 | 2018-12-07 09:38:25 -0800 | [diff] [blame] | 914 | setCurRawProcState(newState); |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 915 | for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) { |
| 916 | StatsLog.write(StatsLog.PROCESS_STATE_CHANGED, |
| 917 | uid, processName, pkgList.keyAt(ipkg), |
| 918 | ActivityManager.processStateAmToProto(mRepProcState), |
| 919 | pkgList.valueAt(ipkg).appVersion); |
| 920 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 921 | } |
| 922 | } |
| 923 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | /* |
| 925 | * Delete all packages from list except the package indicated in info |
| 926 | */ |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 927 | public void resetPackageList(ProcessStatsService tracker) { |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 928 | final int N = pkgList.size(); |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 929 | if (baseProcessTracker != null) { |
| 930 | long now = SystemClock.uptimeMillis(); |
| 931 | baseProcessTracker.setState(ProcessStats.STATE_NOTHING, |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 932 | tracker.getMemFactorLocked(), now, pkgList.mPkgList); |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 933 | for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) { |
| 934 | StatsLog.write(StatsLog.PROCESS_STATE_CHANGED, |
| 935 | uid, processName, pkgList.keyAt(ipkg), |
| 936 | ActivityManager.processStateAmToProto(ProcessStats.STATE_NOTHING), |
| 937 | pkgList.valueAt(ipkg).appVersion); |
| 938 | } |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 939 | if (N != 1) { |
| 940 | for (int i=0; i<N; i++) { |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 941 | ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i); |
| 942 | if (holder.state != null && holder.state != baseProcessTracker) { |
| 943 | holder.state.makeInactive(); |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 944 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 945 | |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 946 | } |
| 947 | pkgList.clear(); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 948 | ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder( |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 949 | info.longVersionCode); |
Dianne Hackborn | 2f55e5a | 2018-11-30 16:31:31 -0800 | [diff] [blame] | 950 | tracker.updateProcessStateHolderLocked(holder, info.packageName, info.uid, |
Dianne Hackborn | 2aec55a | 2018-06-26 10:35:35 -0700 | [diff] [blame] | 951 | info.longVersionCode, processName); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 952 | pkgList.put(info.packageName, holder); |
Dianne Hackborn | 2aec55a | 2018-06-26 10:35:35 -0700 | [diff] [blame] | 953 | if (holder.state != baseProcessTracker) { |
| 954 | holder.state.makeActive(); |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 955 | } |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 956 | } |
Dianne Hackborn | e56c2c3 | 2013-09-17 10:56:49 -0700 | [diff] [blame] | 957 | } else if (N != 1) { |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 958 | pkgList.clear(); |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 959 | pkgList.put(info.packageName, new ProcessStats.ProcessStateHolder(info.longVersionCode)); |
Dianne Hackborn | 78a369c | 2013-06-11 17:10:32 -0700 | [diff] [blame] | 960 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 961 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 962 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 963 | public String[] getPackageList() { |
| 964 | int size = pkgList.size(); |
| 965 | if (size == 0) { |
| 966 | return null; |
| 967 | } |
| 968 | String list[] = new String[size]; |
Dianne Hackborn | 78a369c | 2013-06-11 17:10:32 -0700 | [diff] [blame] | 969 | for (int i=0; i<pkgList.size(); i++) { |
| 970 | list[i] = pkgList.keyAt(i); |
| 971 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | return list; |
| 973 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 974 | |
Zimuzo | 972e1cd | 2019-01-28 16:30:01 +0000 | [diff] [blame] | 975 | public List<VersionedPackage> getPackageListWithVersionCode() { |
| 976 | int size = pkgList.size(); |
| 977 | if (size == 0) { |
| 978 | return null; |
| 979 | } |
| 980 | List<VersionedPackage> list = new ArrayList<>(); |
| 981 | for (int i = 0; i < pkgList.size(); i++) { |
| 982 | list.add(new VersionedPackage(pkgList.keyAt(i), pkgList.valueAt(i).appVersion)); |
| 983 | } |
| 984 | return list; |
| 985 | } |
| 986 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 987 | WindowProcessController getWindowProcessController() { |
| 988 | return mWindowProcessController; |
| 989 | } |
| 990 | |
| 991 | void setCurrentSchedulingGroup(int curSchedGroup) { |
| 992 | mCurSchedGroup = curSchedGroup; |
| 993 | mWindowProcessController.setCurrentSchedulingGroup(curSchedGroup); |
| 994 | } |
| 995 | |
| 996 | int getCurrentSchedulingGroup() { |
| 997 | return mCurSchedGroup; |
| 998 | } |
| 999 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1000 | void setCurProcState(int curProcState) { |
| 1001 | mCurProcState = curProcState; |
| 1002 | mWindowProcessController.setCurrentProcState(mCurProcState); |
| 1003 | } |
| 1004 | |
| 1005 | int getCurProcState() { |
| 1006 | return mCurProcState; |
| 1007 | } |
| 1008 | |
Amith Yamasani | 08888c0 | 2018-12-07 09:38:25 -0800 | [diff] [blame] | 1009 | void setCurRawProcState(int curRawProcState) { |
| 1010 | mCurRawProcState = curRawProcState; |
| 1011 | } |
| 1012 | |
| 1013 | int getCurRawProcState() { |
| 1014 | return mCurRawProcState; |
| 1015 | } |
| 1016 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1017 | void setReportedProcState(int repProcState) { |
| 1018 | mRepProcState = repProcState; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 1019 | for (int ipkg = pkgList.size() - 1; ipkg >= 0; ipkg--) { |
| 1020 | StatsLog.write(StatsLog.PROCESS_STATE_CHANGED, |
| 1021 | uid, processName, pkgList.keyAt(ipkg), |
| 1022 | ActivityManager.processStateAmToProto(mRepProcState), |
| 1023 | pkgList.valueAt(ipkg).appVersion); |
| 1024 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1025 | mWindowProcessController.setReportedProcState(repProcState); |
| 1026 | } |
| 1027 | |
| 1028 | int getReportedProcState() { |
| 1029 | return mRepProcState; |
| 1030 | } |
| 1031 | |
| 1032 | void setCrashing(boolean crashing) { |
| 1033 | mCrashing = crashing; |
| 1034 | mWindowProcessController.setCrashing(crashing); |
| 1035 | } |
| 1036 | |
| 1037 | boolean isCrashing() { |
| 1038 | return mCrashing; |
| 1039 | } |
| 1040 | |
| 1041 | void setNotResponding(boolean notResponding) { |
| 1042 | mNotResponding = notResponding; |
| 1043 | mWindowProcessController.setNotResponding(notResponding); |
| 1044 | } |
| 1045 | |
| 1046 | boolean isNotResponding() { |
| 1047 | return mNotResponding; |
| 1048 | } |
| 1049 | |
| 1050 | void setPersistent(boolean persistent) { |
| 1051 | mPersistent = persistent; |
| 1052 | mWindowProcessController.setPersistent(persistent); |
| 1053 | } |
| 1054 | |
| 1055 | boolean isPersistent() { |
| 1056 | return mPersistent; |
| 1057 | } |
| 1058 | |
| 1059 | public void setRequiredAbi(String requiredAbi) { |
| 1060 | mRequiredAbi = requiredAbi; |
| 1061 | mWindowProcessController.setRequiredAbi(requiredAbi); |
| 1062 | } |
| 1063 | |
| 1064 | String getRequiredAbi() { |
| 1065 | return mRequiredAbi; |
| 1066 | } |
| 1067 | |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 1068 | void setHasForegroundServices(boolean hasForegroundServices, int fgServiceTypes) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1069 | mHasForegroundServices = hasForegroundServices; |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 1070 | mFgServiceTypes = fgServiceTypes; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1071 | mWindowProcessController.setHasForegroundServices(hasForegroundServices); |
| 1072 | } |
| 1073 | |
| 1074 | boolean hasForegroundServices() { |
| 1075 | return mHasForegroundServices; |
| 1076 | } |
| 1077 | |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 1078 | boolean hasLocationForegroundServices() { |
| 1079 | return mHasForegroundServices |
| 1080 | && (mFgServiceTypes & ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION) != 0; |
| 1081 | } |
| 1082 | |
Narayan Kamath | 396ce72 | 2019-03-01 16:53:26 +0000 | [diff] [blame^] | 1083 | int getForegroundServiceTypes() { |
| 1084 | return mHasForegroundServices ? mFgServiceTypes : 0; |
| 1085 | } |
| 1086 | |
| 1087 | int getReportedForegroundServiceTypes() { |
| 1088 | return mRepFgServiceTypes; |
| 1089 | } |
| 1090 | |
| 1091 | void setReportedForegroundServiceTypes(int foregroundServiceTypes) { |
| 1092 | mRepFgServiceTypes = foregroundServiceTypes; |
| 1093 | } |
| 1094 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1095 | void setHasForegroundActivities(boolean hasForegroundActivities) { |
| 1096 | mHasForegroundActivities = hasForegroundActivities; |
| 1097 | mWindowProcessController.setHasForegroundActivities(hasForegroundActivities); |
| 1098 | } |
| 1099 | |
| 1100 | boolean hasForegroundActivities() { |
| 1101 | return mHasForegroundActivities; |
| 1102 | } |
| 1103 | |
| 1104 | void setHasClientActivities(boolean hasClientActivities) { |
| 1105 | mHasClientActivities = hasClientActivities; |
| 1106 | mWindowProcessController.setHasClientActivities(hasClientActivities); |
| 1107 | } |
| 1108 | |
| 1109 | boolean hasClientActivities() { |
| 1110 | return mHasClientActivities; |
| 1111 | } |
| 1112 | |
| 1113 | void setHasTopUi(boolean hasTopUi) { |
| 1114 | mHasTopUi = hasTopUi; |
| 1115 | mWindowProcessController.setHasTopUi(hasTopUi); |
| 1116 | } |
| 1117 | |
| 1118 | boolean hasTopUi() { |
| 1119 | return mHasTopUi; |
| 1120 | } |
| 1121 | |
| 1122 | void setHasOverlayUi(boolean hasOverlayUi) { |
| 1123 | mHasOverlayUi = hasOverlayUi; |
| 1124 | mWindowProcessController.setHasOverlayUi(hasOverlayUi); |
| 1125 | } |
| 1126 | |
| 1127 | boolean hasOverlayUi() { |
| 1128 | return mHasOverlayUi; |
| 1129 | } |
| 1130 | |
| 1131 | void setInteractionEventTime(long interactionEventTime) { |
| 1132 | mInteractionEventTime = interactionEventTime; |
| 1133 | mWindowProcessController.setInteractionEventTime(interactionEventTime); |
| 1134 | } |
| 1135 | |
| 1136 | long getInteractionEventTime() { |
| 1137 | return mInteractionEventTime; |
| 1138 | } |
| 1139 | |
| 1140 | void setFgInteractionTime(long fgInteractionTime) { |
| 1141 | mFgInteractionTime = fgInteractionTime; |
| 1142 | mWindowProcessController.setFgInteractionTime(fgInteractionTime); |
| 1143 | } |
| 1144 | |
| 1145 | long getFgInteractionTime() { |
| 1146 | return mFgInteractionTime; |
| 1147 | } |
| 1148 | |
| 1149 | void setWhenUnimportant(long whenUnimportant) { |
| 1150 | mWhenUnimportant = whenUnimportant; |
| 1151 | mWindowProcessController.setWhenUnimportant(whenUnimportant); |
| 1152 | } |
| 1153 | |
| 1154 | long getWhenUnimportant() { |
| 1155 | return mWhenUnimportant; |
| 1156 | } |
| 1157 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 1158 | void setDebugging(boolean debugging) { |
| 1159 | mDebugging = debugging; |
| 1160 | mWindowProcessController.setDebugging(debugging); |
| 1161 | } |
| 1162 | |
| 1163 | boolean isDebugging() { |
| 1164 | return mDebugging; |
| 1165 | } |
| 1166 | |
| 1167 | void setUsingWrapper(boolean usingWrapper) { |
| 1168 | mUsingWrapper = usingWrapper; |
| 1169 | mWindowProcessController.setUsingWrapper(usingWrapper); |
| 1170 | } |
| 1171 | |
| 1172 | boolean isUsingWrapper() { |
| 1173 | return mUsingWrapper; |
| 1174 | } |
| 1175 | |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 1176 | void addAllowBackgroundActivityStartsToken(Binder entity) { |
Michal Karpinski | c8aa91b | 2019-01-10 16:45:59 +0000 | [diff] [blame] | 1177 | if (entity == null) return; |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 1178 | mAllowBackgroundActivityStartsTokens.add(entity); |
| 1179 | mWindowProcessController.setAllowBackgroundActivityStarts(true); |
| 1180 | } |
| 1181 | |
| 1182 | void removeAllowBackgroundActivityStartsToken(Binder entity) { |
Michal Karpinski | c8aa91b | 2019-01-10 16:45:59 +0000 | [diff] [blame] | 1183 | if (entity == null) return; |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 1184 | mAllowBackgroundActivityStartsTokens.remove(entity); |
| 1185 | mWindowProcessController.setAllowBackgroundActivityStarts( |
| 1186 | !mAllowBackgroundActivityStartsTokens.isEmpty()); |
| 1187 | } |
| 1188 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 1189 | void setActiveInstrumentation(ActiveInstrumentation instr) { |
| 1190 | mInstr = instr; |
Michal Karpinski | 4bc5649 | 2019-01-31 12:07:33 +0000 | [diff] [blame] | 1191 | boolean isInstrumenting = instr != null; |
| 1192 | mWindowProcessController.setInstrumenting(isInstrumenting, |
| 1193 | isInstrumenting && instr.mHasBackgroundActivityStartsPermission); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | ActiveInstrumentation getActiveInstrumentation() { |
| 1197 | return mInstr; |
| 1198 | } |
| 1199 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 1200 | void setCurRawAdj(int curRawAdj) { |
| 1201 | mCurRawAdj = curRawAdj; |
| 1202 | mWindowProcessController.setPerceptible(curRawAdj <= ProcessList.PERCEPTIBLE_APP_ADJ); |
| 1203 | } |
| 1204 | |
| 1205 | int getCurRawAdj() { |
| 1206 | return mCurRawAdj; |
| 1207 | } |
| 1208 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1209 | @Override |
| 1210 | public void clearProfilerIfNeeded() { |
| 1211 | synchronized (mService) { |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 1212 | if (mService.mProfileData.getProfileProc() == null |
| 1213 | || mService.mProfileData.getProfilerInfo() == null |
| 1214 | || mService.mProfileData.getProfileProc() != this) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1215 | return; |
| 1216 | } |
| 1217 | mService.clearProfilerLocked(); |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | @Override |
| 1222 | public void updateServiceConnectionActivities() { |
| 1223 | synchronized (mService) { |
| 1224 | mService.mServices.updateServiceConnectionActivitiesLocked(this); |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | @Override |
| 1229 | public void setPendingUiClean(boolean pendingUiClean) { |
| 1230 | synchronized (mService) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1231 | mPendingUiClean = pendingUiClean; |
| 1232 | mWindowProcessController.setPendingUiClean(pendingUiClean); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1233 | } |
| 1234 | } |
| 1235 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1236 | boolean hasPendingUiClean() { |
| 1237 | return mPendingUiClean; |
| 1238 | } |
| 1239 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1240 | @Override |
| 1241 | public void setPendingUiCleanAndForceProcessStateUpTo(int newState) { |
| 1242 | synchronized (mService) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1243 | setPendingUiClean(true); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1244 | forceProcessStateUpTo(newState); |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | @Override |
| 1249 | public void updateProcessInfo(boolean updateServiceConnectionActivities, boolean updateLru, |
| 1250 | boolean activityChange, boolean updateOomAdj) { |
| 1251 | synchronized (mService) { |
| 1252 | if (updateServiceConnectionActivities) { |
| 1253 | mService.mServices.updateServiceConnectionActivitiesLocked(this); |
| 1254 | } |
| 1255 | if (updateLru) { |
Amith Yamasani | 98a0092 | 2018-08-21 12:50:30 -0400 | [diff] [blame] | 1256 | mService.mProcessList.updateLruProcessLocked(this, activityChange, null); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1257 | } |
| 1258 | if (updateOomAdj) { |
| 1259 | mService.updateOomAdjLocked(); |
| 1260 | } |
| 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | @Override |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 1265 | public boolean isRemoved() { |
| 1266 | return removed; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 1269 | /** |
| 1270 | * Returns the total time (in milliseconds) spent executing in both user and system code. |
| 1271 | * Safe to call without lock held. |
| 1272 | */ |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1273 | @Override |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 1274 | public long getCpuTime() { |
| 1275 | return mService.mProcessCpuTracker.getCpuTimeForPid(pid); |
| 1276 | } |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1277 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1278 | @Override |
| 1279 | public void clearWaitingToKill() { |
| 1280 | synchronized (mService) { |
| 1281 | waitingToKill = null; |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | @Override |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 1286 | public void onStartActivity(int topProcessState, boolean setProfileProc) { |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1287 | synchronized (mService) { |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 1288 | if (setProfileProc) { |
| 1289 | mService.mProfileData.setProfileProc(this); |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | hasShownUi = true; |
| 1293 | setPendingUiClean(true); |
| 1294 | forceProcessStateUpTo(topProcessState); |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1295 | } |
| 1296 | } |
| 1297 | |
| 1298 | @Override |
| 1299 | public void appDied() { |
| 1300 | synchronized (mService) { |
| 1301 | mService.appDiedLocked(this); |
| 1302 | } |
| 1303 | } |
| 1304 | |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1305 | public long getInputDispatchingTimeout() { |
| 1306 | return mWindowProcessController.getInputDispatchingTimeout(); |
| 1307 | } |
| 1308 | |
Yang Lu | 732d638 | 2018-11-05 07:53:12 -0800 | [diff] [blame] | 1309 | public int getProcessClassEnum() { |
| 1310 | if (pid == MY_PID) { |
| 1311 | return ServerProtoEnums.SYSTEM_SERVER; |
| 1312 | } |
| 1313 | if (info == null) { |
| 1314 | return ServerProtoEnums.ERROR_SOURCE_UNKNOWN; |
| 1315 | } |
| 1316 | return (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? ServerProtoEnums.SYSTEM_APP : |
| 1317 | ServerProtoEnums.DATA_APP; |
| 1318 | } |
| 1319 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1320 | /** |
| 1321 | * Unless configured otherwise, swallow ANRs in background processes & kill the process. |
| 1322 | * Non-private access is for tests only. |
| 1323 | */ |
| 1324 | @VisibleForTesting |
| 1325 | boolean isSilentAnr() { |
| 1326 | return !getShowBackground() && !isInterestingForBackgroundTraces(); |
| 1327 | } |
| 1328 | |
| 1329 | /** Non-private access is for tests only. */ |
| 1330 | @VisibleForTesting |
| 1331 | List<ProcessRecord> getLruProcessList() { |
| 1332 | return mService.mProcessList.mLruProcesses; |
| 1333 | } |
| 1334 | |
| 1335 | /** Non-private access is for tests only. */ |
| 1336 | @VisibleForTesting |
| 1337 | boolean isMonitorCpuUsage() { |
| 1338 | return mService.MONITOR_CPU_USAGE; |
| 1339 | } |
| 1340 | |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1341 | void appNotResponding(String activityShortComponentName, ApplicationInfo aInfo, |
| 1342 | String parentShortComponentName, WindowProcessController parentProcess, |
| 1343 | boolean aboveSystem, String annotation) { |
| 1344 | ArrayList<Integer> firstPids = new ArrayList<>(5); |
| 1345 | SparseArray<Boolean> lastPids = new SparseArray<>(20); |
| 1346 | |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 1347 | mWindowProcessController.appEarlyNotResponding(annotation, () -> kill("anr", true)); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1348 | |
| 1349 | long anrTime = SystemClock.uptimeMillis(); |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1350 | if (isMonitorCpuUsage()) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1351 | mService.updateCpuStatsNow(); |
| 1352 | } |
| 1353 | |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1354 | synchronized (mService) { |
| 1355 | // 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] | 1356 | if (mService.mAtmInternal.isShuttingDown()) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1357 | Slog.i(TAG, "During shutdown skipping ANR: " + this + " " + annotation); |
| 1358 | return; |
| 1359 | } else if (isNotResponding()) { |
| 1360 | Slog.i(TAG, "Skipping duplicate ANR: " + this + " " + annotation); |
| 1361 | return; |
| 1362 | } else if (isCrashing()) { |
| 1363 | Slog.i(TAG, "Crashing app skipping ANR: " + this + " " + annotation); |
| 1364 | return; |
| 1365 | } else if (killedByAm) { |
| 1366 | Slog.i(TAG, "App already killed by AM skipping ANR: " + this + " " + annotation); |
| 1367 | return; |
| 1368 | } else if (killed) { |
| 1369 | Slog.i(TAG, "Skipping died app ANR: " + this + " " + annotation); |
| 1370 | return; |
| 1371 | } |
| 1372 | |
| 1373 | // In case we come through here for the same app before completing |
| 1374 | // this one, mark as anring now so we will bail out. |
| 1375 | setNotResponding(true); |
| 1376 | |
| 1377 | // Log the ANR to the event log. |
| 1378 | EventLog.writeEvent(EventLogTags.AM_ANR, userId, pid, processName, info.flags, |
| 1379 | annotation); |
| 1380 | |
| 1381 | // Dump thread traces as quickly as we can, starting with "interesting" processes. |
| 1382 | firstPids.add(pid); |
| 1383 | |
| 1384 | // Don't dump other PIDs if it's a background ANR |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1385 | if (!isSilentAnr()) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1386 | int parentPid = pid; |
| 1387 | if (parentProcess != null && parentProcess.getPid() > 0) { |
| 1388 | parentPid = parentProcess.getPid(); |
| 1389 | } |
| 1390 | if (parentPid != pid) firstPids.add(parentPid); |
| 1391 | |
| 1392 | if (MY_PID != pid && MY_PID != parentPid) firstPids.add(MY_PID); |
| 1393 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1394 | for (int i = getLruProcessList().size() - 1; i >= 0; i--) { |
| 1395 | ProcessRecord r = getLruProcessList().get(i); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1396 | if (r != null && r.thread != null) { |
| 1397 | int myPid = r.pid; |
| 1398 | if (myPid > 0 && myPid != pid && myPid != parentPid && myPid != MY_PID) { |
| 1399 | if (r.isPersistent()) { |
| 1400 | firstPids.add(myPid); |
| 1401 | if (DEBUG_ANR) Slog.i(TAG, "Adding persistent proc: " + r); |
| 1402 | } else if (r.treatLikeActivity) { |
| 1403 | firstPids.add(myPid); |
| 1404 | if (DEBUG_ANR) Slog.i(TAG, "Adding likely IME: " + r); |
| 1405 | } else { |
| 1406 | lastPids.put(myPid, Boolean.TRUE); |
| 1407 | if (DEBUG_ANR) Slog.i(TAG, "Adding ANR proc: " + r); |
| 1408 | } |
| 1409 | } |
| 1410 | } |
| 1411 | } |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | // Log the ANR to the main log. |
| 1416 | StringBuilder info = new StringBuilder(); |
| 1417 | info.setLength(0); |
| 1418 | info.append("ANR in ").append(processName); |
| 1419 | if (activityShortComponentName != null) { |
| 1420 | info.append(" (").append(activityShortComponentName).append(")"); |
| 1421 | } |
| 1422 | info.append("\n"); |
| 1423 | info.append("PID: ").append(pid).append("\n"); |
| 1424 | if (annotation != null) { |
| 1425 | info.append("Reason: ").append(annotation).append("\n"); |
| 1426 | } |
| 1427 | if (parentShortComponentName != null |
| 1428 | && parentShortComponentName.equals(activityShortComponentName)) { |
| 1429 | info.append("Parent: ").append(parentShortComponentName).append("\n"); |
| 1430 | } |
| 1431 | |
| 1432 | ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(true); |
| 1433 | |
| 1434 | // don't dump native PIDs for background ANRs unless it is the process of interest |
| 1435 | String[] nativeProcs = null; |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1436 | if (isSilentAnr()) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1437 | for (int i = 0; i < NATIVE_STACKS_OF_INTEREST.length; i++) { |
| 1438 | if (NATIVE_STACKS_OF_INTEREST[i].equals(processName)) { |
| 1439 | nativeProcs = new String[] { processName }; |
| 1440 | break; |
| 1441 | } |
| 1442 | } |
| 1443 | } else { |
| 1444 | nativeProcs = NATIVE_STACKS_OF_INTEREST; |
| 1445 | } |
| 1446 | |
| 1447 | int[] pids = nativeProcs == null ? null : Process.getPidsForCommands(nativeProcs); |
| 1448 | ArrayList<Integer> nativePids = null; |
| 1449 | |
| 1450 | if (pids != null) { |
| 1451 | nativePids = new ArrayList<>(pids.length); |
| 1452 | for (int i : pids) { |
| 1453 | nativePids.add(i); |
| 1454 | } |
| 1455 | } |
| 1456 | |
| 1457 | // For background ANRs, don't pass the ProcessCpuTracker to |
| 1458 | // avoid spending 1/2 second collecting stats to rank lastPids. |
| 1459 | File tracesFile = ActivityManagerService.dumpStackTraces(firstPids, |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1460 | (isSilentAnr()) ? null : processCpuTracker, (isSilentAnr()) ? null : lastPids, |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1461 | nativePids); |
| 1462 | |
| 1463 | String cpuInfo = null; |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1464 | if (isMonitorCpuUsage()) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1465 | mService.updateCpuStatsNow(); |
| 1466 | synchronized (mService.mProcessCpuTracker) { |
| 1467 | cpuInfo = mService.mProcessCpuTracker.printCurrentState(anrTime); |
| 1468 | } |
| 1469 | info.append(processCpuTracker.printCurrentLoad()); |
| 1470 | info.append(cpuInfo); |
| 1471 | } |
| 1472 | |
| 1473 | info.append(processCpuTracker.printCurrentState(anrTime)); |
| 1474 | |
| 1475 | Slog.e(TAG, info.toString()); |
| 1476 | if (tracesFile == null) { |
| 1477 | // There is no trace file, so dump (only) the alleged culprit's threads to the log |
| 1478 | Process.sendSignal(pid, Process.SIGNAL_QUIT); |
| 1479 | } |
| 1480 | |
| 1481 | StatsLog.write(StatsLog.ANR_OCCURRED, uid, processName, |
| 1482 | activityShortComponentName == null ? "unknown": activityShortComponentName, |
| 1483 | annotation, |
| 1484 | (this.info != null) ? (this.info.isInstantApp() |
| 1485 | ? StatsLog.ANROCCURRED__IS_INSTANT_APP__TRUE |
| 1486 | : StatsLog.ANROCCURRED__IS_INSTANT_APP__FALSE) |
| 1487 | : StatsLog.ANROCCURRED__IS_INSTANT_APP__UNAVAILABLE, |
| 1488 | isInterestingToUserLocked() |
| 1489 | ? StatsLog.ANROCCURRED__FOREGROUND_STATE__FOREGROUND |
Yang Lu | 732d638 | 2018-11-05 07:53:12 -0800 | [diff] [blame] | 1490 | : StatsLog.ANROCCURRED__FOREGROUND_STATE__BACKGROUND, |
| 1491 | getProcessClassEnum(), |
| 1492 | (this.info != null) ? this.info.packageName : ""); |
Wale Ogunwale | 97b2b74 | 2018-10-18 08:08:54 -0700 | [diff] [blame] | 1493 | final ProcessRecord parentPr = parentProcess != null |
| 1494 | ? (ProcessRecord) parentProcess.mOwner : null; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1495 | mService.addErrorToDropBox("anr", this, processName, activityShortComponentName, |
Wale Ogunwale | 97b2b74 | 2018-10-18 08:08:54 -0700 | [diff] [blame] | 1496 | parentShortComponentName, parentPr, annotation, cpuInfo, tracesFile, null); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1497 | |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 1498 | if (mWindowProcessController.appNotResponding(info.toString(), () -> kill("anr", true), |
| 1499 | () -> { |
| 1500 | synchronized (mService) { |
| 1501 | mService.mServices.scheduleServiceTimeoutLocked(this); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1502 | } |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 1503 | })) { |
| 1504 | return; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | synchronized (mService) { |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1508 | // mBatteryStatsService can be null if the AMS is constructed with injector only. This |
| 1509 | // will only happen in tests. |
| 1510 | if (mService.mBatteryStatsService != null) { |
| 1511 | mService.mBatteryStatsService.noteProcessAnr(processName, uid); |
| 1512 | } |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1513 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1514 | if (isSilentAnr()) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1515 | kill("bg anr", true); |
| 1516 | return; |
| 1517 | } |
| 1518 | |
| 1519 | // Set the app's notResponding state, and look up the errorReportReceiver |
| 1520 | makeAppNotRespondingLocked(activityShortComponentName, |
| 1521 | annotation != null ? "ANR " + annotation : "ANR", info.toString()); |
| 1522 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1523 | // mUiHandler can be null if the AMS is constructed with injector only. This will only |
| 1524 | // happen in tests. |
| 1525 | if (mService.mUiHandler != null) { |
| 1526 | // Bring up the infamous App Not Responding dialog |
| 1527 | Message msg = Message.obtain(); |
| 1528 | msg.what = ActivityManagerService.SHOW_NOT_RESPONDING_UI_MSG; |
| 1529 | msg.obj = new AppNotRespondingDialog.Data(this, aInfo, aboveSystem); |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1530 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1531 | mService.mUiHandler.sendMessage(msg); |
| 1532 | } |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | private void makeAppNotRespondingLocked(String activity, String shortMsg, String longMsg) { |
| 1537 | setNotResponding(true); |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1538 | // mAppErrors can be null if the AMS is constructed with injector only. This will only |
| 1539 | // happen in tests. |
| 1540 | if (mService.mAppErrors != null) { |
| 1541 | notRespondingReport = mService.mAppErrors.generateProcessError(this, |
| 1542 | ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING, |
| 1543 | activity, shortMsg, longMsg, null); |
| 1544 | } |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 1545 | startAppProblemLocked(); |
| 1546 | getWindowProcessController().stopFreezingActivities(); |
| 1547 | } |
| 1548 | |
| 1549 | void startAppProblemLocked() { |
| 1550 | // If this app is not running under the current user, then we can't give it a report button |
| 1551 | // because that would require launching the report UI under a different user. |
| 1552 | errorReportReceiver = null; |
| 1553 | |
| 1554 | for (int userId : mService.mUserController.getCurrentProfileIds()) { |
| 1555 | if (this.userId == userId) { |
| 1556 | errorReportReceiver = ApplicationErrorReport.getErrorReportReceiver( |
| 1557 | mService.mContext, info.packageName, info.flags); |
| 1558 | } |
| 1559 | } |
| 1560 | mService.skipCurrentReceiverLocked(this); |
| 1561 | } |
| 1562 | |
| 1563 | private boolean isInterestingForBackgroundTraces() { |
| 1564 | // The system_server is always considered interesting. |
| 1565 | if (pid == MY_PID) { |
| 1566 | return true; |
| 1567 | } |
| 1568 | |
| 1569 | // A package is considered interesting if any of the following is true : |
| 1570 | // |
| 1571 | // - It's displaying an activity. |
| 1572 | // - It's the SystemUI. |
| 1573 | // - It has an overlay or a top UI visible. |
| 1574 | // |
| 1575 | // NOTE: The check whether a given ProcessRecord belongs to the systemui |
| 1576 | // process is a bit of a kludge, but the same pattern seems repeated at |
| 1577 | // several places in the system server. |
| 1578 | return isInterestingToUserLocked() || |
| 1579 | (info != null && "com.android.systemui".equals(info.packageName)) |
| 1580 | || (hasTopUi() || hasOverlayUi()); |
| 1581 | } |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 1582 | |
| 1583 | private boolean getShowBackground() { |
| 1584 | return Settings.Secure.getInt(mService.mContext.getContentResolver(), |
| 1585 | Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0; |
| 1586 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1587 | } |