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