blob: 9b1044c467dda995baf45da4febebff2842d4c9f [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.server.am;
18
Wale Ogunwalee23149f2015-03-06 15:39:44 -080019import static com.android.server.am.ActivityManagerDebugConfig.*;
Wale Ogunwale18795a22014-12-03 11:38:33 -080020import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
21
Craig Mautner21d24a22014-04-23 11:45:37 -070022import android.app.ActivityManager.TaskDescription;
Dianne Hackbornb5a380d2015-05-20 18:18:46 -070023import android.app.PendingIntent;
Craig Mautnera0026042014-04-23 11:45:37 -070024import android.os.PersistableBundle;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -070025import android.os.Trace;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070026
Dianne Hackborn2d69d492012-04-06 16:24:14 -070027import com.android.internal.app.ResolverActivity;
Dianne Hackborn85d558c2014-11-04 10:31:54 -080028import com.android.internal.content.ReferrerIntent;
Craig Mautner21d24a22014-04-23 11:45:37 -070029import com.android.internal.util.XmlUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import com.android.server.AttributeCache;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070031import com.android.server.am.ActivityStack.ActivityState;
Craig Mautner4a1cb222013-12-04 16:14:06 -080032import com.android.server.am.ActivityStackSupervisor.ActivityContainer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
Dianne Hackborn7a2195c2012-03-19 17:38:00 -070034import android.app.ActivityOptions;
Craig Mautner05d6272ba2013-02-11 09:39:27 -080035import android.app.ResultInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.content.ComponentName;
37import android.content.Intent;
38import android.content.pm.ActivityInfo;
39import android.content.pm.ApplicationInfo;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -070040import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.content.res.Configuration;
42import android.graphics.Bitmap;
Dianne Hackbornd367ca82012-05-07 15:49:39 -070043import android.graphics.Rect;
Dianne Hackborn247fe742011-01-08 17:25:57 -080044import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import android.os.Bundle;
Dianne Hackbornbe707852011-11-11 14:32:10 -080046import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import android.os.Message;
48import android.os.Process;
Dianne Hackborn39792d22010-08-19 18:01:52 -070049import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.os.SystemClock;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070051import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import android.util.EventLog;
53import android.util.Log;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070054import android.util.Slog;
Dianne Hackborn0dad3642010-09-09 21:25:35 -070055import android.util.TimeUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.view.IApplicationToken;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -080057import android.view.WindowManager;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070058
Craig Mautner21d24a22014-04-23 11:45:37 -070059import org.xmlpull.v1.XmlPullParser;
60import org.xmlpull.v1.XmlPullParserException;
61import org.xmlpull.v1.XmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062
Craig Mautner21d24a22014-04-23 11:45:37 -070063import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import java.io.PrintWriter;
65import java.lang.ref.WeakReference;
66import java.util.ArrayList;
67import java.util.HashSet;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070068import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069
70/**
71 * An entry in the history stack, representing an activity.
72 */
Dianne Hackbornbe707852011-11-11 14:32:10 -080073final class ActivityRecord {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080074 private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityRecord" : TAG_AM;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -070075 private static final String TAG_STATES = TAG + POSTFIX_STATES;
Wale Ogunwaleee006da2015-03-30 14:49:25 -070076 private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH;
77 private static final String TAG_THUMBNAILS = TAG + POSTFIX_THUMBNAILS;
Wale Ogunwalee23149f2015-03-06 15:39:44 -080078
Wale Ogunwale3ab9a272015-03-16 09:55:45 -070079 private static final boolean SHOW_ACTIVITY_START_TIME = true;
Winson Chung740c3ac2014-11-12 16:14:38 -080080 final public static String RECENTS_PACKAGE_NAME = "com.android.systemui.recents";
Craig Mautnerb59dcfd2013-05-06 13:12:58 -070081
Craig Mautner21d24a22014-04-23 11:45:37 -070082 private static final String ATTR_ID = "id";
83 private static final String TAG_INTENT = "intent";
84 private static final String ATTR_USERID = "user_id";
85 private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle";
86 private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -070087 private static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package";
Craig Mautner21d24a22014-04-23 11:45:37 -070088 private static final String ATTR_RESOLVEDTYPE = "resolved_type";
89 private static final String ATTR_COMPONENTSPECIFIED = "component_specified";
Dianne Hackborn337abb32014-09-24 12:44:29 -070090 static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_";
Craig Mautner21d24a22014-04-23 11:45:37 -070091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 final ActivityManagerService service; // owner
Dianne Hackbornbe707852011-11-11 14:32:10 -080093 final IApplicationToken.Stub appToken; // window manager token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 final ActivityInfo info; // all about me
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070095 final ApplicationInfo appInfo; // information about activity's app
Stefan Kuhnee88d1e52015-05-18 10:33:45 -070096 final int launchedFromUid; // always the uid who started the activity.
Dianne Hackbornf265ea92013-01-31 15:00:51 -080097 final String launchedFromPackage; // always the package who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -070098 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 final Intent intent; // the original intent that generated us
100 final ComponentName realActivity; // the intent component, or target of an alias.
101 final String shortComponentName; // the short component name of the intent
102 final String resolvedType; // as per original caller;
103 final String packageName; // the package implementing intent's component
104 final String processName; // process where this component wants to run
105 final String taskAffinity; // as per ActivityInfo.taskAffinity
106 final boolean stateNotNeeded; // As per ActivityInfo.flags
Craig Mautner4addfc52013-06-25 08:05:45 -0700107 boolean fullscreen; // covers the full screen?
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800108 final boolean noDisplay; // activity is not displayed?
The Android Open Source Project4df24232009-03-05 14:34:35 -0800109 final boolean componentSpecified; // did caller specifiy an explicit component?
Craig Mautner86d67a42013-05-14 10:34:38 -0700110
111 static final int APPLICATION_ACTIVITY_TYPE = 0;
112 static final int HOME_ACTIVITY_TYPE = 1;
113 static final int RECENTS_ACTIVITY_TYPE = 2;
Craig Mautner2c1faed2013-07-23 12:56:02 -0700114 int mActivityType;
Craig Mautner86d67a42013-05-14 10:34:38 -0700115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 CharSequence nonLocalizedLabel; // the label information from the package mgr.
117 int labelRes; // the label information from the package mgr.
118 int icon; // resource identifier of activity's icon.
Adam Powell04fe6eb2013-05-31 14:39:48 -0700119 int logo; // resource identifier of activity's logo.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 int theme; // resource identifier of activity's theme.
Dianne Hackborn247fe742011-01-08 17:25:57 -0800121 int realTheme; // actual theme resource we will use, never 0.
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800122 int windowFlags; // custom window flags for preview window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 TaskRecord task; // the task this is in.
Craig Mautner21d24a22014-04-23 11:45:37 -0700124 long createTime = System.currentTimeMillis();
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700125 long displayStartTime; // when we started launching this activity
126 long fullyDrawnStartTime; // when we started launching this activity
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700127 long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -0800128 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700129 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700130 long pauseTime; // last time we started pausing the activity
131 long launchTickTime; // base time for launch tick messages
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 Configuration configuration; // configuration activity was last running in
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700133 // Overridden configuration by the activity task
134 // WARNING: Reference points to {@link TaskRecord#mOverrideConfig}, so its internal state
Wale Ogunwale60454db2015-01-23 16:05:07 -0800135 // should never be altered directly.
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700136 Configuration taskConfigOverride;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700137 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700138 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 final String resultWho; // additional identifier for use by resultTo.
140 final int requestCode; // code given by requester (resultTo)
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800141 ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800143 ArrayList<ReferrerIntent> newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700144 ActivityOptions pendingOptions; // most recently given options
George Mount6ba042b2014-07-28 11:12:28 -0700145 ActivityOptions returningOptions; // options that are coming back via convertToTranslucent
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700146 AppTimeTracker appTimeTracker; // set if we are tracking the time in this app/task/activity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700148 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700149 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700150 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 Bundle icicle; // last saved activity state
Craig Mautnera0026042014-04-23 11:45:37 -0700152 PersistableBundle persistentState; // last persistently saved activity state
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 boolean frontOfTask; // is this the root activity of its task?
154 boolean launchFailed; // set if a launched failed, to abort on 2nd try
155 boolean haveState; // have we gotten the last activity state?
156 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700157 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 boolean finishing; // activity in pending finish list?
159 boolean configDestroy; // need to destroy due to config change?
160 int configChangeFlags; // which config values have changed
161 boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 int launchMode; // the launch mode activity attribute.
163 boolean visible; // does this activity's window need to be shown?
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800164 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 boolean nowVisible; // is this activity's window visible?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 boolean idle; // has the activity gone idle?
167 boolean hasBeenLaunched;// has this activity ever been launched?
168 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400169 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400170 boolean forceNewConfig; // force re-create with new config next time
Dianne Hackborn07981492013-01-28 11:36:23 -0800171 int launchCount; // count of launches since last state
172 long lastLaunchTime; // time of last lauch of this activity
Craig Mautnerf4c909b2014-04-17 18:39:38 -0700173 ArrayList<ActivityContainer> mChildContainers = new ArrayList<ActivityContainer>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700175 String stringName; // for caching of toString().
Craig Mautnerde4ef022013-04-07 19:01:33 -0700176
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700177 private boolean inHistory; // are we in the history stack?
Craig Mautnerde4ef022013-04-07 19:01:33 -0700178 final ActivityStackSupervisor mStackSupervisor;
Craig Mautnera61bc652013-10-28 15:43:18 -0700179 boolean mStartingWindowShown = false;
Craig Mautnere0a38842013-12-16 16:14:02 -0800180 ActivityContainer mInitialActivityContainer;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700181
Craig Mautner21d24a22014-04-23 11:45:37 -0700182 TaskDescription taskDescription; // the recents information for this activity
Craig Mautnerbb742462014-07-07 15:28:55 -0700183 boolean mLaunchTaskBehind; // this activity is actively being launched with
184 // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed.
Craig Mautner2fbd7542014-03-21 09:34:07 -0700185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700187 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700188 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
189 pw.print(" processName="); pw.println(processName);
190 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Craig Mautnere11f2b72013-04-01 12:37:17 -0700191 pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800192 pw.print(" userId="); pw.println(userId);
193 pw.print(prefix); pw.print("app="); pw.println(app);
194 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700195 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
196 pw.print(" task="); pw.println(task);
197 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700198 pw.print(prefix); pw.print("realActivity=");
199 pw.println(realActivity.flattenToShortString());
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700200 if (appInfo != null) {
201 pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir);
202 if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) {
203 pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir);
204 }
205 pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800206 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700207 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
208 pw.print(" componentSpecified="); pw.print(componentSpecified);
Craig Mautner86d67a42013-05-14 10:34:38 -0700209 pw.print(" mActivityType="); pw.println(mActivityType);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800210 pw.print(prefix); pw.print("compat="); pw.print(compat);
211 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
212 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
213 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Dianne Hackborne17aeb32011-04-07 15:11:57 -0700214 pw.print(prefix); pw.print("config="); pw.println(configuration);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700215 pw.print(prefix); pw.print("taskConfigOverride="); pw.println(taskConfigOverride);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700216 if (resultTo != null || resultWho != null) {
217 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
218 pw.print(" resultWho="); pw.print(resultWho);
219 pw.print(" resultCode="); pw.println(requestCode);
220 }
Craig Mautner29c58ca2014-10-14 16:17:06 -0700221 if (taskDescription != null) {
222 final String iconFilename = taskDescription.getIconFilename();
223 if (iconFilename != null || taskDescription.getLabel() != null ||
224 taskDescription.getPrimaryColor() != 0) {
225 pw.print(prefix); pw.print("taskDescription:");
226 pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename());
227 pw.print(" label=\""); pw.print(taskDescription.getLabel());
228 pw.print("\"");
229 pw.print(" color=");
230 pw.println(Integer.toHexString(taskDescription.getPrimaryColor()));
231 }
232 if (iconFilename == null && taskDescription.getIcon() != null) {
233 pw.print(prefix); pw.println("taskDescription contains Bitmap");
234 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700235 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700236 if (results != null) {
237 pw.print(prefix); pw.print("results="); pw.println(results);
238 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700239 if (pendingResults != null && pendingResults.size() > 0) {
240 pw.print(prefix); pw.println("Pending Results:");
241 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
242 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
243 pw.print(prefix); pw.print(" - ");
244 if (pir == null) {
245 pw.println("null");
246 } else {
247 pw.println(pir);
248 pir.dump(pw, prefix + " ");
249 }
250 }
251 }
252 if (newIntents != null && newIntents.size() > 0) {
253 pw.print(prefix); pw.println("Pending New Intents:");
254 for (int i=0; i<newIntents.size(); i++) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800255 Intent intent = newIntents.get(i);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700256 pw.print(prefix); pw.print(" - ");
257 if (intent == null) {
258 pw.println("null");
259 } else {
260 pw.println(intent.toShortString(false, true, false, true));
261 }
262 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700263 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700264 if (pendingOptions != null) {
265 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
266 }
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700267 if (appTimeTracker != null) {
268 appTimeTracker.dumpWithHeader(pw, prefix, false);
269 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700270 if (uriPermissions != null) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700271 uriPermissions.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700272 }
273 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800274 pw.print(" launchCount="); pw.print(launchCount);
275 pw.print(" lastLaunchTime=");
276 if (lastLaunchTime == 0) pw.print("0");
277 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
278 pw.println();
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700279 pw.print(prefix); pw.print("haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700280 pw.print(" icicle="); pw.println(icicle);
281 pw.print(prefix); pw.print("state="); pw.print(state);
282 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700283 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700284 pw.print(" finishing="); pw.println(finishing);
285 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
286 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700287 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800288 pw.print(" sleeping="); pw.print(sleeping);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700289 pw.print(" idle="); pw.println(idle);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800290 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
291 pw.print(" noDisplay="); pw.print(noDisplay);
292 pw.print(" immersive="); pw.print(immersive);
293 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800294 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400295 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700296 pw.print(prefix); pw.print("mActivityType=");
297 pw.println(activityTypeToString(mActivityType));
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700298 if (displayStartTime != 0 || startTime != 0) {
299 pw.print(prefix); pw.print("displayStartTime=");
300 if (displayStartTime == 0) pw.print("0");
301 else TimeUtils.formatDuration(displayStartTime, now, pw);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700302 pw.print(" startTime=");
303 if (startTime == 0) pw.print("0");
304 else TimeUtils.formatDuration(startTime, now, pw);
305 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700306 }
Craig Mautner8c14c152015-01-15 17:32:07 -0800307 final boolean waitingVisible = mStackSupervisor.mWaitingVisibleActivities.contains(this);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800308 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700309 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800310 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700311 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700312 if (lastVisibleTime == 0) pw.print("0");
313 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
314 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700315 }
316 if (configDestroy || configChangeFlags != 0) {
317 pw.print(prefix); pw.print("configDestroy="); pw.print(configDestroy);
318 pw.print(" configChangeFlags=");
319 pw.println(Integer.toHexString(configChangeFlags));
320 }
321 if (connections != null) {
322 pw.print(prefix); pw.print("connections="); pw.println(connections);
323 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 }
325
Dianne Hackbornbe707852011-11-11 14:32:10 -0800326 static class Token extends IApplicationToken.Stub {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700327 private final WeakReference<ActivityRecord> weakActivity;
328 private final ActivityManagerService mService;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800329
Wale Ogunwale7d701172015-03-11 15:36:30 -0700330 Token(ActivityRecord activity, ActivityManagerService service) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800331 weakActivity = new WeakReference<>(activity);
Wale Ogunwale7d701172015-03-11 15:36:30 -0700332 mService = service;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800333 }
334
Wale Ogunwale7d701172015-03-11 15:36:30 -0700335 @Override
336 public void windowsDrawn() {
337 synchronized (mService) {
338 ActivityRecord r = tokenToActivityRecordLocked(this);
339 if (r != null) {
340 r.windowsDrawnLocked();
341 }
Dianne Hackbornbe707852011-11-11 14:32:10 -0800342 }
343 }
344
Wale Ogunwale7d701172015-03-11 15:36:30 -0700345 @Override
346 public void windowsVisible() {
347 synchronized (mService) {
348 ActivityRecord r = tokenToActivityRecordLocked(this);
349 if (r != null) {
350 r.windowsVisibleLocked();
351 }
Dianne Hackbornbe707852011-11-11 14:32:10 -0800352 }
353 }
354
Wale Ogunwale7d701172015-03-11 15:36:30 -0700355 @Override
356 public void windowsGone() {
357 synchronized (mService) {
358 ActivityRecord r = tokenToActivityRecordLocked(this);
359 if (r != null) {
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700360 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + r);
Wale Ogunwale7d701172015-03-11 15:36:30 -0700361 r.nowVisible = false;
362 return;
363 }
Dianne Hackbornbe707852011-11-11 14:32:10 -0800364 }
365 }
366
Wale Ogunwale7d701172015-03-11 15:36:30 -0700367 @Override
368 public boolean keyDispatchingTimedOut(String reason) {
369 ActivityRecord r;
370 ActivityRecord anrActivity;
371 ProcessRecord anrApp;
372 synchronized (mService) {
373 r = tokenToActivityRecordLocked(this);
374 if (r == null) {
375 return false;
376 }
377 anrActivity = r.getWaitingHistoryRecordLocked();
378 anrApp = r != null ? r.app : null;
379 }
380 return mService.inputDispatchingTimedOut(anrApp, anrActivity, r, false, reason);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800381 }
382
Wale Ogunwale7d701172015-03-11 15:36:30 -0700383 @Override
384 public long getKeyDispatchingTimeout() {
385 synchronized (mService) {
386 ActivityRecord r = tokenToActivityRecordLocked(this);
387 if (r == null) {
388 return 0;
389 }
390 r = r.getWaitingHistoryRecordLocked();
391 return ActivityManagerService.getInputDispatchingTimeoutLocked(r);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800392 }
Wale Ogunwale7d701172015-03-11 15:36:30 -0700393 }
394
395 private static final ActivityRecord tokenToActivityRecordLocked(Token token) {
396 if (token == null) {
397 return null;
398 }
399 ActivityRecord r = token.weakActivity.get();
400 if (r == null || r.task == null || r.task.stack == null) {
401 return null;
402 }
403 return r;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800404 }
405
Craig Mautnerde4ef022013-04-07 19:01:33 -0700406 @Override
Dianne Hackbornbe707852011-11-11 14:32:10 -0800407 public String toString() {
408 StringBuilder sb = new StringBuilder(128);
409 sb.append("Token{");
410 sb.append(Integer.toHexString(System.identityHashCode(this)));
411 sb.append(' ');
412 sb.append(weakActivity.get());
413 sb.append('}');
414 return sb.toString();
415 }
416 }
417
Wale Ogunwale7d701172015-03-11 15:36:30 -0700418 static ActivityRecord forTokenLocked(IBinder token) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800419 try {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700420 return Token.tokenToActivityRecordLocked((Token)token);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800421 } catch (ClassCastException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800422 Slog.w(TAG, "Bad activity token: " + token, e);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800423 return null;
424 }
425 }
426
Craig Mautnerac6f8432013-07-17 13:24:59 -0700427 boolean isNotResolverActivity() {
428 return !ResolverActivity.class.getName().equals(realActivity.getClassName());
429 }
430
Craig Mautnerd2328952013-03-05 12:46:26 -0800431 ActivityRecord(ActivityManagerService _service, ProcessRecord _caller,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800432 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700434 ActivityRecord _resultTo, String _resultWho, int _reqCode,
Craig Mautnere0a38842013-12-16 16:14:02 -0800435 boolean _componentSpecified, ActivityStackSupervisor supervisor,
Craig Mautner233ceee2014-05-09 17:05:11 -0700436 ActivityContainer container, Bundle options) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 service = _service;
Wale Ogunwale7d701172015-03-11 15:36:30 -0700438 appToken = new Token(this, service);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 info = aInfo;
440 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800441 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700442 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 intent = _intent;
444 shortComponentName = _intent.getComponent().flattenToShortString();
445 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800446 componentSpecified = _componentSpecified;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 configuration = _configuration;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700448 taskConfigOverride = Configuration.EMPTY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 resultTo = _resultTo;
450 resultWho = _resultWho;
451 requestCode = _reqCode;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700452 state = ActivityState.INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 frontOfTask = false;
454 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700456 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 finishing = false;
458 configDestroy = false;
459 keysPaused = false;
460 inHistory = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 visible = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 nowVisible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 idle = false;
464 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700465 mStackSupervisor = supervisor;
Craig Mautnere0a38842013-12-16 16:14:02 -0800466 mInitialActivityContainer = container;
Craig Mautner233ceee2014-05-09 17:05:11 -0700467 if (options != null) {
468 pendingOptions = new ActivityOptions(options);
Craig Mautnerbb742462014-07-07 15:28:55 -0700469 mLaunchTaskBehind = pendingOptions.getLaunchTaskBehind();
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700470 PendingIntent usageReport = pendingOptions.getUsageTimeReport();
471 if (usageReport != null) {
472 appTimeTracker = new AppTimeTracker(usageReport);
473 }
Craig Mautner233ceee2014-05-09 17:05:11 -0700474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700476 // This starts out true, since the initial state of an activity
477 // is that we have everything, and we shouldn't never consider it
478 // lacking in state to be removed if it dies.
479 haveState = true;
480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 if (aInfo != null) {
482 if (aInfo.targetActivity == null
483 || aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE
484 || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
485 realActivity = _intent.getComponent();
486 } else {
487 realActivity = new ComponentName(aInfo.packageName,
488 aInfo.targetActivity);
489 }
490 taskAffinity = aInfo.taskAffinity;
491 stateNotNeeded = (aInfo.flags&
492 ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700493 appInfo = aInfo.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 nonLocalizedLabel = aInfo.nonLocalizedLabel;
495 labelRes = aInfo.labelRes;
496 if (nonLocalizedLabel == null && labelRes == 0) {
497 ApplicationInfo app = aInfo.applicationInfo;
498 nonLocalizedLabel = app.nonLocalizedLabel;
499 labelRes = app.labelRes;
500 }
501 icon = aInfo.getIconResource();
Adam Powell04fe6eb2013-05-31 14:39:48 -0700502 logo = aInfo.getLogoResource();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 theme = aInfo.getThemeResource();
Dianne Hackborn247fe742011-01-08 17:25:57 -0800504 realTheme = theme;
505 if (realTheme == 0) {
506 realTheme = aInfo.applicationInfo.targetSdkVersion
507 < Build.VERSION_CODES.HONEYCOMB
508 ? android.R.style.Theme
509 : android.R.style.Theme_Holo;
510 }
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800511 if ((aInfo.flags&ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
512 windowFlags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0
515 && _caller != null
516 && (aInfo.applicationInfo.uid == Process.SYSTEM_UID
517 || aInfo.applicationInfo.uid == _caller.info.uid)) {
518 processName = _caller.processName;
519 } else {
520 processName = aInfo.processName;
521 }
522
523 if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
524 intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
525 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 packageName = aInfo.applicationInfo.packageName;
528 launchMode = aInfo.launchMode;
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700531 realTheme, com.android.internal.R.styleable.Window, userId);
Dianne Hackbornb795d7c2015-07-28 17:40:06 -0700532 final boolean translucent = ent != null && (ent.array.getBoolean(
Filip Gruszczynski23958c62015-02-23 18:05:27 -0800533 com.android.internal.R.styleable.Window_windowIsTranslucent, false)
534 || (!ent.array.hasValue(
535 com.android.internal.R.styleable.Window_windowIsTranslucent)
536 && ent.array.getBoolean(
537 com.android.internal.R.styleable.Window_windowSwipeToDismiss,
Dianne Hackbornb795d7c2015-07-28 17:40:06 -0700538 false)));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 fullscreen = ent != null && !ent.array.getBoolean(
540 com.android.internal.R.styleable.Window_windowIsFloating, false)
Filip Gruszczynski23958c62015-02-23 18:05:27 -0800541 && !translucent;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800542 noDisplay = ent != null && ent.array.getBoolean(
543 com.android.internal.R.styleable.Window_windowNoDisplay, false);
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700544
Craig Mautner80259352013-09-28 12:35:25 -0700545 if ((!_componentSpecified || _launchedFromUid == Process.myUid()
Craig Mautner86d67a42013-05-14 10:34:38 -0700546 || _launchedFromUid == 0) &&
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700547 Intent.ACTION_MAIN.equals(_intent.getAction()) &&
548 _intent.hasCategory(Intent.CATEGORY_HOME) &&
549 _intent.getCategories().size() == 1 &&
550 _intent.getData() == null &&
551 _intent.getType() == null &&
Craig Mautner80259352013-09-28 12:35:25 -0700552 (intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 &&
553 isNotResolverActivity()) {
Craig Mautner86d67a42013-05-14 10:34:38 -0700554 // This sure looks like a home activity!
555 mActivityType = HOME_ACTIVITY_TYPE;
Craig Mautner80259352013-09-28 12:35:25 -0700556 } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) {
Craig Mautner86d67a42013-05-14 10:34:38 -0700557 mActivityType = RECENTS_ACTIVITY_TYPE;
558 } else {
559 mActivityType = APPLICATION_ACTIVITY_TYPE;
560 }
Daniel Sandler69a48172010-06-23 16:29:36 -0400561
562 immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 } else {
564 realActivity = null;
565 taskAffinity = null;
566 stateNotNeeded = false;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700567 appInfo = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 processName = null;
569 packageName = null;
570 fullscreen = true;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800571 noDisplay = false;
Craig Mautner86d67a42013-05-14 10:34:38 -0700572 mActivityType = APPLICATION_ACTIVITY_TYPE;
Daniel Sandler69a48172010-06-23 16:29:36 -0400573 immersive = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 }
575 }
576
Craig Mautnera228ae92014-07-09 05:44:55 -0700577 void setTask(TaskRecord newTask, TaskRecord taskToAffiliateWith) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700578 if (task != null && task.removeActivity(this) && task != newTask && task.stack != null) {
579 task.stack.removeTask(task, "setTask");
Craig Mautnerde4ef022013-04-07 19:01:33 -0700580 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700581 task = newTask;
Craig Mautnera228ae92014-07-09 05:44:55 -0700582 setTaskToAffiliateWith(taskToAffiliateWith);
583 }
584
585 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
586 if (taskToAffiliateWith != null &&
587 launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE &&
588 launchMode != ActivityInfo.LAUNCH_SINGLE_TASK) {
589 task.setTaskToAffiliateWith(taskToAffiliateWith);
590 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700591 }
592
Craig Mautner5eda9b32013-07-02 11:58:16 -0700593 boolean changeWindowTranslucency(boolean toOpaque) {
594 if (fullscreen == toOpaque) {
595 return false;
596 }
Craig Mautner4addfc52013-06-25 08:05:45 -0700597
Craig Mautner5eda9b32013-07-02 11:58:16 -0700598 // Keep track of the number of fullscreen activities in this task.
599 task.numFullscreen += toOpaque ? +1 : -1;
600
601 fullscreen = toOpaque;
602 return true;
Craig Mautner4addfc52013-06-25 08:05:45 -0700603 }
604
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700605 void putInHistory() {
606 if (!inHistory) {
607 inHistory = true;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700608 }
609 }
610
611 void takeFromHistory() {
612 if (inHistory) {
613 inHistory = false;
614 if (task != null && !finishing) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800615 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700616 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700617 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700618 }
619 }
620
621 boolean isInHistory() {
622 return inHistory;
623 }
624
Wale Ogunwale7d701172015-03-11 15:36:30 -0700625 boolean isInStackLocked() {
626 return task != null && task.stack != null && task.stack.isInStackLocked(this) != null;
627 }
628
Craig Mautner86d67a42013-05-14 10:34:38 -0700629 boolean isHomeActivity() {
630 return mActivityType == HOME_ACTIVITY_TYPE;
631 }
632
633 boolean isRecentsActivity() {
634 return mActivityType == RECENTS_ACTIVITY_TYPE;
635 }
636
637 boolean isApplicationActivity() {
638 return mActivityType == APPLICATION_ACTIVITY_TYPE;
639 }
640
Craig Mautner21d24a22014-04-23 11:45:37 -0700641 boolean isPersistable() {
Craig Mautner43e52ed2014-06-16 17:18:52 -0700642 return (info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY ||
643 info.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS) &&
644 (intent == null ||
645 (intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
Craig Mautner21d24a22014-04-23 11:45:37 -0700646 }
647
Wale Ogunwale7d701172015-03-11 15:36:30 -0700648 void makeFinishingLocked() {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800649 if (!finishing) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700650 if (task != null && task.stack != null
651 && this == task.stack.getVisibleBehindActivity()) {
Jose Lima34ff4922014-08-18 15:19:41 -0700652 // A finishing activity should not remain as visible in the background
653 mStackSupervisor.requestVisibleBehindLocked(this, false);
654 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800655 finishing = true;
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700656 if (stopped) {
657 clearOptionsLocked();
658 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800659 }
660 }
661
Dianne Hackborn7e269642010-08-25 19:50:20 -0700662 UriPermissionOwner getUriPermissionsLocked() {
663 if (uriPermissions == null) {
664 uriPermissions = new UriPermissionOwner(service, this);
665 }
666 return uriPermissions;
667 }
668
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700669 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 int requestCode, int resultCode,
671 Intent resultData) {
672 ActivityResult r = new ActivityResult(from, resultWho,
John Spurlock8a985d22014-02-25 09:40:05 -0500673 requestCode, resultCode, resultData);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800675 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 }
677 results.add(r);
678 }
679
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700680 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 int requestCode) {
682 if (results != null) {
683 for (int i=results.size()-1; i>=0; i--) {
684 ActivityResult r = (ActivityResult)results.get(i);
685 if (r.mFrom != from) continue;
686 if (r.mResultWho == null) {
687 if (resultWho != null) continue;
688 } else {
689 if (!r.mResultWho.equals(resultWho)) continue;
690 }
691 if (r.mRequestCode != requestCode) continue;
692
693 results.remove(i);
694 }
695 }
696 }
697
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800698 void addNewIntentLocked(ReferrerIntent intent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699 if (newIntents == null) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800700 newIntents = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 }
702 newIntents.add(intent);
703 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700704
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700705 /**
706 * Deliver a new Intent to an existing activity, so that its onNewIntent()
707 * method will be called at the proper time.
708 */
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800709 final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) {
Dianne Hackborn514074f2013-02-11 10:52:46 -0800710 // The activity now gets access to the data associated with this Intent.
711 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
Nicolas Prevotc6cf95c2014-05-29 11:30:36 +0100712 intent, getUriPermissionsLocked(), userId);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700713 // We want to immediately deliver the intent to the activity if
714 // it is currently the top resumed activity... however, if the
715 // device is sleeping, then all activities are stopped, so in that
716 // case we will deliver it if this is the current top activity on its
717 // stack.
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800718 final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
Craig Mautner86d67a42013-05-14 10:34:38 -0700719 boolean unsent = true;
Wale Ogunwale7d701172015-03-11 15:36:30 -0700720 if ((state == ActivityState.RESUMED
721 || (service.isSleeping() && task.stack != null
722 && task.stack.topRunningActivityLocked(null) == this))
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700723 && app != null && app.thread != null) {
724 try {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800725 ArrayList<ReferrerIntent> ar = new ArrayList<>(1);
726 ar.add(rintent);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800727 app.thread.scheduleNewIntent(ar, appToken);
Craig Mautner86d67a42013-05-14 10:34:38 -0700728 unsent = false;
Dianne Hackborn39792d22010-08-19 18:01:52 -0700729 } catch (RemoteException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800730 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn39792d22010-08-19 18:01:52 -0700731 } catch (NullPointerException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800732 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700733 }
734 }
Craig Mautner86d67a42013-05-14 10:34:38 -0700735 if (unsent) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800736 addNewIntentLocked(rintent);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700737 }
738 }
739
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700740 void updateOptionsLocked(Bundle options) {
741 if (options != null) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700742 if (pendingOptions != null) {
743 pendingOptions.abort();
744 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700745 pendingOptions = new ActivityOptions(options);
746 }
747 }
748
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700749 void updateOptionsLocked(ActivityOptions options) {
750 if (options != null) {
751 if (pendingOptions != null) {
752 pendingOptions.abort();
753 }
754 pendingOptions = options;
755 }
756 }
757
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700758 void applyOptionsLocked() {
George Mount2c92c972014-03-20 09:38:23 -0700759 if (pendingOptions != null
760 && pendingOptions.getAnimationType() != ActivityOptions.ANIM_SCENE_TRANSITION) {
Michael Jurka21385cd2012-05-03 10:57:31 -0700761 final int animationType = pendingOptions.getAnimationType();
762 switch (animationType) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700763 case ActivityOptions.ANIM_CUSTOM:
764 service.mWindowManager.overridePendingAppTransition(
765 pendingOptions.getPackageName(),
766 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -0700767 pendingOptions.getCustomExitResId(),
768 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700769 break;
Chet Haase10e23ab2015-02-11 15:08:38 -0800770 case ActivityOptions.ANIM_CLIP_REVEAL:
771 service.mWindowManager.overridePendingAppTransitionClipReveal(
772 pendingOptions.getStartX(), pendingOptions.getStartY(),
773 pendingOptions.getWidth(), pendingOptions.getHeight());
774 if (intent.getSourceBounds() == null) {
775 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
776 pendingOptions.getStartY(),
777 pendingOptions.getStartX()+pendingOptions.getWidth(),
778 pendingOptions.getStartY()+pendingOptions.getHeight()));
779 }
780 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700781 case ActivityOptions.ANIM_SCALE_UP:
782 service.mWindowManager.overridePendingAppTransitionScaleUp(
783 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200784 pendingOptions.getWidth(), pendingOptions.getHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700785 if (intent.getSourceBounds() == null) {
786 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
787 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200788 pendingOptions.getStartX()+pendingOptions.getWidth(),
789 pendingOptions.getStartY()+pendingOptions.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700790 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700791 break;
Michael Jurka832cb222012-04-13 09:32:47 -0700792 case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
793 case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
794 boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700795 service.mWindowManager.overridePendingAppTransitionThumb(
796 pendingOptions.getThumbnail(),
797 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -0700798 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -0700799 scaleUp);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700800 if (intent.getSourceBounds() == null) {
801 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
802 pendingOptions.getStartY(),
803 pendingOptions.getStartX()
804 + pendingOptions.getThumbnail().getWidth(),
805 pendingOptions.getStartY()
806 + pendingOptions.getThumbnail().getHeight()));
807 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700808 break;
Winson Chunga4ccb862014-08-22 15:26:27 -0700809 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP:
810 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
811 service.mWindowManager.overridePendingAppTransitionAspectScaledThumb(
812 pendingOptions.getThumbnail(),
813 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200814 pendingOptions.getWidth(), pendingOptions.getHeight(),
Winson Chunga4ccb862014-08-22 15:26:27 -0700815 pendingOptions.getOnAnimationStartListener(),
816 (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP));
817 if (intent.getSourceBounds() == null) {
818 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
819 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200820 pendingOptions.getStartX() + pendingOptions.getWidth(),
821 pendingOptions.getStartY() + pendingOptions.getHeight()));
Winson Chunga4ccb862014-08-22 15:26:27 -0700822 }
823 break;
Craig Mautner233ceee2014-05-09 17:05:11 -0700824 default:
825 Slog.e(TAG, "applyOptionsLocked: Unknown animationType=" + animationType);
826 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700827 }
828 pendingOptions = null;
829 }
830 }
831
Adam Powellcfbe9be2013-11-06 14:58:58 -0800832 ActivityOptions getOptionsForTargetActivityLocked() {
833 return pendingOptions != null ? pendingOptions.forTargetActivity() : null;
834 }
835
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700836 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700837 if (pendingOptions != null) {
838 pendingOptions.abort();
839 pendingOptions = null;
840 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700841 }
842
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700843 ActivityOptions takeOptionsLocked() {
844 ActivityOptions opts = pendingOptions;
845 pendingOptions = null;
846 return opts;
847 }
848
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700849 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -0700850 if (uriPermissions != null) {
851 uriPermissions.removeUriPermissionsLocked();
852 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700853 }
854 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855
856 void pauseKeyDispatchingLocked() {
857 if (!keysPaused) {
858 keysPaused = true;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800859 service.mWindowManager.pauseKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800860 }
861 }
862
863 void resumeKeyDispatchingLocked() {
864 if (keysPaused) {
865 keysPaused = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800866 service.mWindowManager.resumeKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800867 }
868 }
869
Winson Chung740c3ac2014-11-12 16:14:38 -0800870 void updateThumbnailLocked(Bitmap newThumbnail, CharSequence description) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700871 if (newThumbnail != null) {
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700872 if (DEBUG_THUMBNAILS) Slog.i(TAG_THUMBNAILS,
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700873 "Setting thumbnail of " + this + " to " + newThumbnail);
Winson Chung096f36b2014-08-20 15:39:01 -0700874 boolean thumbnailUpdated = task.setLastThumbnail(newThumbnail);
875 if (thumbnailUpdated && isPersistable()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700876 mStackSupervisor.mService.notifyTaskPersisterLocked(task, false);
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700877 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700878 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700879 task.lastDescription = description;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700880 }
881
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700882 void startLaunchTickingLocked() {
883 if (ActivityManagerService.IS_USER_BUILD) {
884 return;
885 }
886 if (launchTickTime == 0) {
887 launchTickTime = SystemClock.uptimeMillis();
888 continueLaunchTickingLocked();
889 }
890 }
891
892 boolean continueLaunchTickingLocked() {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700893 if (launchTickTime == 0) {
894 return false;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700895 }
Wale Ogunwale7d701172015-03-11 15:36:30 -0700896
897 final ActivityStack stack = task.stack;
898 if (stack == null) {
899 return false;
900 }
901
902 Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG, this);
903 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
904 stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
905 return true;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700906 }
907
908 void finishLaunchTickingLocked() {
909 launchTickTime = 0;
Wale Ogunwale7d701172015-03-11 15:36:30 -0700910 final ActivityStack stack = task.stack;
911 if (stack != null) {
912 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
913 }
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700914 }
915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 // IApplicationToken
917
918 public boolean mayFreezeScreenLocked(ProcessRecord app) {
919 // Only freeze the screen if this activity is currently attached to
920 // an application, and that application is not blocked or unresponding.
921 // In any other case, we can't count on getting the screen unfrozen,
922 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -0800923 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
927 if (mayFreezeScreenLocked(app)) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800928 service.mWindowManager.startAppFreezingScreen(appToken, configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 }
930 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 public void stopFreezingScreenLocked(boolean force) {
933 if (force || frozenBeforeDestroy) {
934 frozenBeforeDestroy = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800935 service.mWindowManager.stopAppFreezingScreen(appToken, force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 }
937 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700938
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700939 public void reportFullyDrawnLocked() {
940 final long curTime = SystemClock.uptimeMillis();
941 if (displayStartTime != 0) {
942 reportLaunchTimeLocked(curTime);
943 }
Wale Ogunwale7d701172015-03-11 15:36:30 -0700944 final ActivityStack stack = task.stack;
945 if (fullyDrawnStartTime != 0 && stack != null) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700946 final long thisTime = curTime - fullyDrawnStartTime;
947 final long totalTime = stack.mFullyDrawnStartTime != 0
948 ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -0700949 if (SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -0700950 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700951 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME,
952 userId, System.identityHashCode(this), shortComponentName,
953 thisTime, totalTime);
954 StringBuilder sb = service.mStringBuilder;
955 sb.setLength(0);
956 sb.append("Fully drawn ");
957 sb.append(shortComponentName);
958 sb.append(": ");
959 TimeUtils.formatDuration(thisTime, sb);
960 if (thisTime != totalTime) {
961 sb.append(" (total ");
962 TimeUtils.formatDuration(totalTime, sb);
963 sb.append(")");
964 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800965 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700966 }
967 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -0700968 //service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700969 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700970 stack.mFullyDrawnStartTime = 0;
971 }
Wale Ogunwale7d701172015-03-11 15:36:30 -0700972 fullyDrawnStartTime = 0;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700973 }
974
975 private void reportLaunchTimeLocked(final long curTime) {
976 final ActivityStack stack = task.stack;
Wale Ogunwale7d701172015-03-11 15:36:30 -0700977 if (stack == null) {
978 return;
979 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700980 final long thisTime = curTime - displayStartTime;
981 final long totalTime = stack.mLaunchStartTime != 0
982 ? (curTime - stack.mLaunchStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -0700983 if (SHOW_ACTIVITY_START_TIME) {
Narayan Kamath7829c812015-06-08 17:39:43 +0100984 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700985 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
986 userId, System.identityHashCode(this), shortComponentName,
987 thisTime, totalTime);
988 StringBuilder sb = service.mStringBuilder;
989 sb.setLength(0);
990 sb.append("Displayed ");
991 sb.append(shortComponentName);
992 sb.append(": ");
993 TimeUtils.formatDuration(thisTime, sb);
994 if (thisTime != totalTime) {
995 sb.append(" (total ");
996 TimeUtils.formatDuration(totalTime, sb);
997 sb.append(")");
998 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800999 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001000 }
1001 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
1002 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001003 //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001004 }
1005 displayStartTime = 0;
1006 stack.mLaunchStartTime = 0;
1007 }
1008
Wale Ogunwale7d701172015-03-11 15:36:30 -07001009 void windowsDrawnLocked() {
1010 if (displayStartTime != 0) {
1011 reportLaunchTimeLocked(SystemClock.uptimeMillis());
1012 }
1013 mStackSupervisor.sendWaitingVisibleReportLocked(this);
1014 startTime = 0;
1015 finishLaunchTickingLocked();
1016 if (task != null) {
1017 task.hasBeenVisible = true;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001018 }
1019 }
1020
Wale Ogunwale7d701172015-03-11 15:36:30 -07001021 void windowsVisibleLocked() {
1022 mStackSupervisor.reportActivityVisibleLocked(this);
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001023 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this);
Wale Ogunwale7d701172015-03-11 15:36:30 -07001024 if (!nowVisible) {
1025 nowVisible = true;
1026 lastVisibleTime = SystemClock.uptimeMillis();
1027 if (!idle) {
1028 // Instead of doing the full stop routine here, let's just hide any activities
1029 // we now can, and let them stop when the normal idle happens.
1030 mStackSupervisor.processStoppingActivitiesLocked(false);
1031 } else {
1032 // If this activity was already idle, then we now need to make sure we perform
1033 // the full stop of any activities that are waiting to do so. This is because
1034 // we won't do that while they are still waiting for this one to become visible.
1035 final int size = mStackSupervisor.mWaitingVisibleActivities.size();
1036 if (size > 0) {
1037 for (int i = 0; i < size; i++) {
1038 ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i);
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001039 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "Was waiting for visible: " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001040 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001041 mStackSupervisor.mWaitingVisibleActivities.clear();
1042 mStackSupervisor.scheduleIdleLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001045 service.scheduleAppGcsLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 }
1047 }
1048
Wale Ogunwale7d701172015-03-11 15:36:30 -07001049 ActivityRecord getWaitingHistoryRecordLocked() {
riddle_hsudb46d6b2015-04-01 18:58:07 +08001050 // First find the real culprit... if this activity is waiting for
1051 // another activity to start or has stopped, then the key dispatching
1052 // timeout should not be caused by this.
Wale Ogunwale16a62792015-04-01 11:50:31 -07001053 if (mStackSupervisor.mWaitingVisibleActivities.contains(this) || stopped) {
Craig Mautner8f2adcb2014-04-07 22:21:33 +00001054 final ActivityStack stack = mStackSupervisor.getFocusedStack();
riddle_hsudb46d6b2015-04-01 18:58:07 +08001055 // Try to use the one which is closest to top.
1056 ActivityRecord r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -08001058 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001060 if (r != null) {
1061 return r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 }
1063 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001064 return this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 }
1066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 /**
1068 * This method will return true if the activity is either visible, is becoming visible, is
1069 * currently pausing, or is resumed.
1070 */
1071 public boolean isInterestingToUserLocked() {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001072 return visible || nowVisible || state == ActivityState.PAUSING ||
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 state == ActivityState.RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001074 }
1075
1076 public void setSleeping(boolean _sleeping) {
1077 if (sleeping == _sleeping) {
1078 return;
1079 }
1080 if (app != null && app.thread != null) {
1081 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -08001082 app.thread.scheduleSleeping(appToken, _sleeping);
Craig Mautner0eea92c2013-05-16 13:35:39 -07001083 if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
1084 mStackSupervisor.mGoingToSleepActivities.add(this);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001085 }
1086 sleeping = _sleeping;
1087 } catch (RemoteException e) {
Craig Mautner0eea92c2013-05-16 13:35:39 -07001088 Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001089 }
1090 }
1091 }
Craig Mautnerf81b90872013-02-26 13:02:43 -08001092
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001093 static void activityResumedLocked(IBinder token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001094 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Wale Ogunwale0fc365c2015-05-25 19:35:42 -07001095 if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r);
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001096 r.icicle = null;
1097 r.haveState = false;
1098 }
1099
Craig Mautnerd2328952013-03-05 12:46:26 -08001100 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001101 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Craig Mautnerd2328952013-03-05 12:46:26 -08001102 if (r == null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001103 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08001104 }
1105 final TaskRecord task = r.task;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001106 final int activityNdx = task.mActivities.indexOf(r);
1107 if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001108 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08001109 }
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001110 return task.taskId;
Craig Mautnerd2328952013-03-05 12:46:26 -08001111 }
1112
1113 static ActivityRecord isInStackLocked(IBinder token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001114 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Wale Ogunwale60454db2015-01-23 16:05:07 -08001115 return (r != null) ? r.task.stack.isInStackLocked(r) : null;
Craig Mautnerd2328952013-03-05 12:46:26 -08001116 }
1117
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001118 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -08001119 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
1120 if (r != null) {
1121 return r.task.stack;
1122 }
1123 return null;
1124 }
1125
Dianne Hackborn89ad4562014-08-24 16:45:38 -07001126 final boolean isDestroyable() {
1127 if (finishing || app == null || state == ActivityState.DESTROYING
1128 || state == ActivityState.DESTROYED) {
1129 // This would be redundant.
1130 return false;
1131 }
1132 if (task == null || task.stack == null || this == task.stack.mResumedActivity
1133 || this == task.stack.mPausingActivity || !haveState || !stopped) {
1134 // We're not ready for this kind of thing.
1135 return false;
1136 }
1137 if (visible) {
1138 // The user would notice this!
1139 return false;
1140 }
1141 return true;
1142 }
1143
Winson Chung3bad5cc02014-08-19 17:44:32 -07001144 private static String createImageFilename(long createTime, int taskId) {
1145 return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime +
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001146 TaskPersister.IMAGE_EXTENSION;
1147 }
1148
Craig Mautner648f69b2014-09-18 14:16:26 -07001149 void setTaskDescription(TaskDescription _taskDescription) {
1150 Bitmap icon;
1151 if (_taskDescription.getIconFilename() == null &&
1152 (icon = _taskDescription.getIcon()) != null) {
1153 final String iconFilename = createImageFilename(createTime, task.taskId);
1154 mStackSupervisor.mService.mTaskPersister.saveImage(icon, iconFilename);
1155 _taskDescription.setIconFilename(iconFilename);
1156 }
1157 taskDescription = _taskDescription;
1158 }
1159
Craig Mautner21d24a22014-04-23 11:45:37 -07001160 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
1161 out.attribute(null, ATTR_ID, String.valueOf(createTime));
1162 out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
1163 if (launchedFromPackage != null) {
1164 out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage);
1165 }
1166 if (resolvedType != null) {
1167 out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType);
1168 }
1169 out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified));
1170 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Winson Chung2cb86c72014-06-25 12:03:30 -07001171
Craig Mautner21d24a22014-04-23 11:45:37 -07001172 if (taskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001173 taskDescription.saveToXml(out);
Craig Mautner21d24a22014-04-23 11:45:37 -07001174 }
1175
1176 out.startTag(null, TAG_INTENT);
1177 intent.saveToXml(out);
1178 out.endTag(null, TAG_INTENT);
1179
1180 if (isPersistable() && persistentState != null) {
1181 out.startTag(null, TAG_PERSISTABLEBUNDLE);
1182 persistentState.saveToXml(out);
1183 out.endTag(null, TAG_PERSISTABLEBUNDLE);
1184 }
1185 }
1186
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001187 static ActivityRecord restoreFromXml(XmlPullParser in,
1188 ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07001189 Intent intent = null;
1190 PersistableBundle persistentState = null;
1191 int launchedFromUid = 0;
1192 String launchedFromPackage = null;
1193 String resolvedType = null;
1194 boolean componentSpecified = false;
1195 int userId = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07001196 long createTime = -1;
1197 final int outerDepth = in.getDepth();
Winson Chung2cb86c72014-06-25 12:03:30 -07001198 TaskDescription taskDescription = new TaskDescription();
Craig Mautner21d24a22014-04-23 11:45:37 -07001199
1200 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1201 final String attrName = in.getAttributeName(attrNdx);
1202 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001203 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
Wale Ogunwale18795a22014-12-03 11:38:33 -08001204 "ActivityRecord: attribute name=" + attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001205 if (ATTR_ID.equals(attrName)) {
1206 createTime = Long.valueOf(attrValue);
1207 } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
1208 launchedFromUid = Integer.valueOf(attrValue);
1209 } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
1210 launchedFromPackage = attrValue;
1211 } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
1212 resolvedType = attrValue;
1213 } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
1214 componentSpecified = Boolean.valueOf(attrValue);
1215 } else if (ATTR_USERID.equals(attrName)) {
1216 userId = Integer.valueOf(attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001217 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1218 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001219 } else {
1220 Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName);
1221 }
1222 }
1223
1224 int event;
1225 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
1226 (event != XmlPullParser.END_TAG || in.getDepth() < outerDepth)) {
1227 if (event == XmlPullParser.START_TAG) {
1228 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001229 if (TaskPersister.DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08001230 Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001231 if (TAG_INTENT.equals(name)) {
1232 intent = Intent.restoreFromXml(in);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001233 if (TaskPersister.DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08001234 Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07001235 } else if (TAG_PERSISTABLEBUNDLE.equals(name)) {
1236 persistentState = PersistableBundle.restoreFromXml(in);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001237 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
Craig Mautner21d24a22014-04-23 11:45:37 -07001238 "ActivityRecord: persistentState=" + persistentState);
1239 } else {
1240 Slog.w(TAG, "restoreActivity: unexpected name=" + name);
1241 XmlUtils.skipCurrentTag(in);
1242 }
1243 }
1244 }
1245
1246 if (intent == null) {
Craig Mautnere0129b32014-05-25 16:41:09 -07001247 throw new XmlPullParserException("restoreActivity error intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07001248 }
1249
1250 final ActivityManagerService service = stackSupervisor.mService;
1251 final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null,
Jeff Hao1b012d32014-08-20 10:35:34 -07001252 userId);
Craig Mautnere0129b32014-05-25 16:41:09 -07001253 if (aInfo == null) {
Craig Mautner77b04262014-06-27 15:22:12 -07001254 throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent +
1255 " resolvedType=" + resolvedType);
Craig Mautnere0129b32014-05-25 16:41:09 -07001256 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001257 final ActivityRecord r = new ActivityRecord(service, /*caller*/null, launchedFromUid,
1258 launchedFromPackage, intent, resolvedType, aInfo, service.getConfiguration(),
1259 null, null, 0, componentSpecified, stackSupervisor, null, null);
1260
1261 r.persistentState = persistentState;
Winson Chung2cb86c72014-06-25 12:03:30 -07001262 r.taskDescription = taskDescription;
Craig Mautner21d24a22014-04-23 11:45:37 -07001263 r.createTime = createTime;
1264
1265 return r;
1266 }
1267
1268 private static String activityTypeToString(int type) {
Craig Mautnerae7ecab2013-09-18 11:48:14 -07001269 switch (type) {
1270 case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE";
1271 case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE";
1272 case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE";
1273 default: return Integer.toString(type);
1274 }
1275 }
1276
Craig Mautnerf81b90872013-02-26 13:02:43 -08001277 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001279 if (stringName != null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001280 return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) +
Craig Mautnerf3333272013-04-22 10:55:53 -07001281 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001282 }
1283 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -08001284 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001285 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -07001286 sb.append(" u");
1287 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001288 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001289 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -08001290 stringName = sb.toString();
1291 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001292 }
1293}