blob: d16eab6850a99083f45dc4761ecefd4c669347d4 [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 Ogunwale60454db2015-01-23 16:05:07 -0800133 // Overridden configuration by the activity stack
134 // WARNING: Reference points to {@link ActivityStack#mOverrideConfig}, so its internal state
135 // should never be altered directly.
136 Configuration stackConfigOverride;
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 Ogunwale60454db2015-01-23 16:05:07 -0800215 pw.print(prefix); pw.print("stackConfigOverride="); pw.println(stackConfigOverride);
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 Ogunwale60454db2015-01-23 16:05:07 -0800448 stackConfigOverride = (container != null)
449 ? container.mStack.mOverrideConfig : Configuration.EMPTY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 resultTo = _resultTo;
451 resultWho = _resultWho;
452 requestCode = _reqCode;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700453 state = ActivityState.INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 frontOfTask = false;
455 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700457 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 finishing = false;
459 configDestroy = false;
460 keysPaused = false;
461 inHistory = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 visible = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 nowVisible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 idle = false;
465 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700466 mStackSupervisor = supervisor;
Craig Mautnere0a38842013-12-16 16:14:02 -0800467 mInitialActivityContainer = container;
Craig Mautner233ceee2014-05-09 17:05:11 -0700468 if (options != null) {
469 pendingOptions = new ActivityOptions(options);
Craig Mautnerbb742462014-07-07 15:28:55 -0700470 mLaunchTaskBehind = pendingOptions.getLaunchTaskBehind();
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700471 PendingIntent usageReport = pendingOptions.getUsageTimeReport();
472 if (usageReport != null) {
473 appTimeTracker = new AppTimeTracker(usageReport);
474 }
Craig Mautner233ceee2014-05-09 17:05:11 -0700475 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700477 // This starts out true, since the initial state of an activity
478 // is that we have everything, and we shouldn't never consider it
479 // lacking in state to be removed if it dies.
480 haveState = true;
481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 if (aInfo != null) {
483 if (aInfo.targetActivity == null
484 || aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE
485 || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
486 realActivity = _intent.getComponent();
487 } else {
488 realActivity = new ComponentName(aInfo.packageName,
489 aInfo.targetActivity);
490 }
491 taskAffinity = aInfo.taskAffinity;
492 stateNotNeeded = (aInfo.flags&
493 ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700494 appInfo = aInfo.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 nonLocalizedLabel = aInfo.nonLocalizedLabel;
496 labelRes = aInfo.labelRes;
497 if (nonLocalizedLabel == null && labelRes == 0) {
498 ApplicationInfo app = aInfo.applicationInfo;
499 nonLocalizedLabel = app.nonLocalizedLabel;
500 labelRes = app.labelRes;
501 }
502 icon = aInfo.getIconResource();
Adam Powell04fe6eb2013-05-31 14:39:48 -0700503 logo = aInfo.getLogoResource();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 theme = aInfo.getThemeResource();
Dianne Hackborn247fe742011-01-08 17:25:57 -0800505 realTheme = theme;
506 if (realTheme == 0) {
507 realTheme = aInfo.applicationInfo.targetSdkVersion
508 < Build.VERSION_CODES.HONEYCOMB
509 ? android.R.style.Theme
510 : android.R.style.Theme_Holo;
511 }
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800512 if ((aInfo.flags&ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
513 windowFlags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
514 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0
516 && _caller != null
517 && (aInfo.applicationInfo.uid == Process.SYSTEM_UID
518 || aInfo.applicationInfo.uid == _caller.info.uid)) {
519 processName = _caller.processName;
520 } else {
521 processName = aInfo.processName;
522 }
523
524 if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
525 intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
526 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 packageName = aInfo.applicationInfo.packageName;
529 launchMode = aInfo.launchMode;
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700532 realTheme, com.android.internal.R.styleable.Window, userId);
Filip Gruszczynski23958c62015-02-23 18:05:27 -0800533 final boolean translucent = ent.array.getBoolean(
534 com.android.internal.R.styleable.Window_windowIsTranslucent, false)
535 || (!ent.array.hasValue(
536 com.android.internal.R.styleable.Window_windowIsTranslucent)
537 && ent.array.getBoolean(
538 com.android.internal.R.styleable.Window_windowSwipeToDismiss,
539 false));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 fullscreen = ent != null && !ent.array.getBoolean(
541 com.android.internal.R.styleable.Window_windowIsFloating, false)
Filip Gruszczynski23958c62015-02-23 18:05:27 -0800542 && !translucent;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800543 noDisplay = ent != null && ent.array.getBoolean(
544 com.android.internal.R.styleable.Window_windowNoDisplay, false);
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700545
Craig Mautner80259352013-09-28 12:35:25 -0700546 if ((!_componentSpecified || _launchedFromUid == Process.myUid()
Craig Mautner86d67a42013-05-14 10:34:38 -0700547 || _launchedFromUid == 0) &&
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700548 Intent.ACTION_MAIN.equals(_intent.getAction()) &&
549 _intent.hasCategory(Intent.CATEGORY_HOME) &&
550 _intent.getCategories().size() == 1 &&
551 _intent.getData() == null &&
552 _intent.getType() == null &&
Craig Mautner80259352013-09-28 12:35:25 -0700553 (intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 &&
554 isNotResolverActivity()) {
Craig Mautner86d67a42013-05-14 10:34:38 -0700555 // This sure looks like a home activity!
556 mActivityType = HOME_ACTIVITY_TYPE;
Craig Mautner80259352013-09-28 12:35:25 -0700557 } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) {
Craig Mautner86d67a42013-05-14 10:34:38 -0700558 mActivityType = RECENTS_ACTIVITY_TYPE;
559 } else {
560 mActivityType = APPLICATION_ACTIVITY_TYPE;
561 }
Daniel Sandler69a48172010-06-23 16:29:36 -0400562
563 immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 } else {
565 realActivity = null;
566 taskAffinity = null;
567 stateNotNeeded = false;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700568 appInfo = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 processName = null;
570 packageName = null;
571 fullscreen = true;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800572 noDisplay = false;
Craig Mautner86d67a42013-05-14 10:34:38 -0700573 mActivityType = APPLICATION_ACTIVITY_TYPE;
Daniel Sandler69a48172010-06-23 16:29:36 -0400574 immersive = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 }
576 }
577
Craig Mautnera228ae92014-07-09 05:44:55 -0700578 void setTask(TaskRecord newTask, TaskRecord taskToAffiliateWith) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700579 if (task != null && task.removeActivity(this) && task != newTask && task.stack != null) {
580 task.stack.removeTask(task, "setTask");
Craig Mautnerde4ef022013-04-07 19:01:33 -0700581 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700582 task = newTask;
Craig Mautnera228ae92014-07-09 05:44:55 -0700583 setTaskToAffiliateWith(taskToAffiliateWith);
584 }
585
586 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
587 if (taskToAffiliateWith != null &&
588 launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE &&
589 launchMode != ActivityInfo.LAUNCH_SINGLE_TASK) {
590 task.setTaskToAffiliateWith(taskToAffiliateWith);
591 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700592 }
593
Craig Mautner5eda9b32013-07-02 11:58:16 -0700594 boolean changeWindowTranslucency(boolean toOpaque) {
595 if (fullscreen == toOpaque) {
596 return false;
597 }
Craig Mautner4addfc52013-06-25 08:05:45 -0700598
Craig Mautner5eda9b32013-07-02 11:58:16 -0700599 // Keep track of the number of fullscreen activities in this task.
600 task.numFullscreen += toOpaque ? +1 : -1;
601
602 fullscreen = toOpaque;
603 return true;
Craig Mautner4addfc52013-06-25 08:05:45 -0700604 }
605
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700606 void putInHistory() {
607 if (!inHistory) {
608 inHistory = true;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700609 }
610 }
611
612 void takeFromHistory() {
613 if (inHistory) {
614 inHistory = false;
615 if (task != null && !finishing) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800616 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700617 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700618 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700619 }
620 }
621
622 boolean isInHistory() {
623 return inHistory;
624 }
625
Wale Ogunwale7d701172015-03-11 15:36:30 -0700626 boolean isInStackLocked() {
627 return task != null && task.stack != null && task.stack.isInStackLocked(this) != null;
628 }
629
Craig Mautner86d67a42013-05-14 10:34:38 -0700630 boolean isHomeActivity() {
631 return mActivityType == HOME_ACTIVITY_TYPE;
632 }
633
634 boolean isRecentsActivity() {
635 return mActivityType == RECENTS_ACTIVITY_TYPE;
636 }
637
638 boolean isApplicationActivity() {
639 return mActivityType == APPLICATION_ACTIVITY_TYPE;
640 }
641
Craig Mautner21d24a22014-04-23 11:45:37 -0700642 boolean isPersistable() {
Craig Mautner43e52ed2014-06-16 17:18:52 -0700643 return (info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY ||
644 info.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS) &&
645 (intent == null ||
646 (intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
Craig Mautner21d24a22014-04-23 11:45:37 -0700647 }
648
Wale Ogunwale7d701172015-03-11 15:36:30 -0700649 void makeFinishingLocked() {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800650 if (!finishing) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700651 if (task != null && task.stack != null
652 && this == task.stack.getVisibleBehindActivity()) {
Jose Lima34ff4922014-08-18 15:19:41 -0700653 // A finishing activity should not remain as visible in the background
654 mStackSupervisor.requestVisibleBehindLocked(this, false);
655 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800656 finishing = true;
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700657 if (stopped) {
658 clearOptionsLocked();
659 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800660 }
661 }
662
Dianne Hackborn7e269642010-08-25 19:50:20 -0700663 UriPermissionOwner getUriPermissionsLocked() {
664 if (uriPermissions == null) {
665 uriPermissions = new UriPermissionOwner(service, this);
666 }
667 return uriPermissions;
668 }
669
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700670 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671 int requestCode, int resultCode,
672 Intent resultData) {
673 ActivityResult r = new ActivityResult(from, resultWho,
John Spurlock8a985d22014-02-25 09:40:05 -0500674 requestCode, resultCode, resultData);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800676 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 }
678 results.add(r);
679 }
680
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700681 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 int requestCode) {
683 if (results != null) {
684 for (int i=results.size()-1; i>=0; i--) {
685 ActivityResult r = (ActivityResult)results.get(i);
686 if (r.mFrom != from) continue;
687 if (r.mResultWho == null) {
688 if (resultWho != null) continue;
689 } else {
690 if (!r.mResultWho.equals(resultWho)) continue;
691 }
692 if (r.mRequestCode != requestCode) continue;
693
694 results.remove(i);
695 }
696 }
697 }
698
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800699 void addNewIntentLocked(ReferrerIntent intent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700 if (newIntents == null) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800701 newIntents = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702 }
703 newIntents.add(intent);
704 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700705
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700706 /**
707 * Deliver a new Intent to an existing activity, so that its onNewIntent()
708 * method will be called at the proper time.
709 */
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800710 final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) {
Dianne Hackborn514074f2013-02-11 10:52:46 -0800711 // The activity now gets access to the data associated with this Intent.
712 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
Nicolas Prevotc6cf95c2014-05-29 11:30:36 +0100713 intent, getUriPermissionsLocked(), userId);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700714 // We want to immediately deliver the intent to the activity if
715 // it is currently the top resumed activity... however, if the
716 // device is sleeping, then all activities are stopped, so in that
717 // case we will deliver it if this is the current top activity on its
718 // stack.
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800719 final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
Craig Mautner86d67a42013-05-14 10:34:38 -0700720 boolean unsent = true;
Wale Ogunwale7d701172015-03-11 15:36:30 -0700721 if ((state == ActivityState.RESUMED
722 || (service.isSleeping() && task.stack != null
723 && task.stack.topRunningActivityLocked(null) == this))
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700724 && app != null && app.thread != null) {
725 try {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800726 ArrayList<ReferrerIntent> ar = new ArrayList<>(1);
727 ar.add(rintent);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800728 app.thread.scheduleNewIntent(ar, appToken);
Craig Mautner86d67a42013-05-14 10:34:38 -0700729 unsent = false;
Dianne Hackborn39792d22010-08-19 18:01:52 -0700730 } catch (RemoteException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800731 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn39792d22010-08-19 18:01:52 -0700732 } catch (NullPointerException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800733 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700734 }
735 }
Craig Mautner86d67a42013-05-14 10:34:38 -0700736 if (unsent) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800737 addNewIntentLocked(rintent);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700738 }
739 }
740
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700741 void updateOptionsLocked(Bundle options) {
742 if (options != null) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700743 if (pendingOptions != null) {
744 pendingOptions.abort();
745 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700746 pendingOptions = new ActivityOptions(options);
747 }
748 }
749
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700750 void updateOptionsLocked(ActivityOptions options) {
751 if (options != null) {
752 if (pendingOptions != null) {
753 pendingOptions.abort();
754 }
755 pendingOptions = options;
756 }
757 }
758
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700759 void applyOptionsLocked() {
George Mount2c92c972014-03-20 09:38:23 -0700760 if (pendingOptions != null
761 && pendingOptions.getAnimationType() != ActivityOptions.ANIM_SCENE_TRANSITION) {
Michael Jurka21385cd2012-05-03 10:57:31 -0700762 final int animationType = pendingOptions.getAnimationType();
763 switch (animationType) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700764 case ActivityOptions.ANIM_CUSTOM:
765 service.mWindowManager.overridePendingAppTransition(
766 pendingOptions.getPackageName(),
767 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -0700768 pendingOptions.getCustomExitResId(),
769 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700770 break;
Chet Haase10e23ab2015-02-11 15:08:38 -0800771 case ActivityOptions.ANIM_CLIP_REVEAL:
772 service.mWindowManager.overridePendingAppTransitionClipReveal(
773 pendingOptions.getStartX(), pendingOptions.getStartY(),
774 pendingOptions.getWidth(), pendingOptions.getHeight());
775 if (intent.getSourceBounds() == null) {
776 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
777 pendingOptions.getStartY(),
778 pendingOptions.getStartX()+pendingOptions.getWidth(),
779 pendingOptions.getStartY()+pendingOptions.getHeight()));
780 }
781 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700782 case ActivityOptions.ANIM_SCALE_UP:
783 service.mWindowManager.overridePendingAppTransitionScaleUp(
784 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200785 pendingOptions.getWidth(), pendingOptions.getHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700786 if (intent.getSourceBounds() == null) {
787 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
788 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200789 pendingOptions.getStartX()+pendingOptions.getWidth(),
790 pendingOptions.getStartY()+pendingOptions.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700791 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700792 break;
Michael Jurka832cb222012-04-13 09:32:47 -0700793 case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
794 case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
795 boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700796 service.mWindowManager.overridePendingAppTransitionThumb(
797 pendingOptions.getThumbnail(),
798 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -0700799 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -0700800 scaleUp);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700801 if (intent.getSourceBounds() == null) {
802 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
803 pendingOptions.getStartY(),
804 pendingOptions.getStartX()
805 + pendingOptions.getThumbnail().getWidth(),
806 pendingOptions.getStartY()
807 + pendingOptions.getThumbnail().getHeight()));
808 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700809 break;
Winson Chunga4ccb862014-08-22 15:26:27 -0700810 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP:
811 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
812 service.mWindowManager.overridePendingAppTransitionAspectScaledThumb(
813 pendingOptions.getThumbnail(),
814 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200815 pendingOptions.getWidth(), pendingOptions.getHeight(),
Winson Chunga4ccb862014-08-22 15:26:27 -0700816 pendingOptions.getOnAnimationStartListener(),
817 (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP));
818 if (intent.getSourceBounds() == null) {
819 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
820 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200821 pendingOptions.getStartX() + pendingOptions.getWidth(),
822 pendingOptions.getStartY() + pendingOptions.getHeight()));
Winson Chunga4ccb862014-08-22 15:26:27 -0700823 }
824 break;
Craig Mautner233ceee2014-05-09 17:05:11 -0700825 default:
826 Slog.e(TAG, "applyOptionsLocked: Unknown animationType=" + animationType);
827 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700828 }
829 pendingOptions = null;
830 }
831 }
832
Adam Powellcfbe9be2013-11-06 14:58:58 -0800833 ActivityOptions getOptionsForTargetActivityLocked() {
834 return pendingOptions != null ? pendingOptions.forTargetActivity() : null;
835 }
836
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700837 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700838 if (pendingOptions != null) {
839 pendingOptions.abort();
840 pendingOptions = null;
841 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700842 }
843
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700844 ActivityOptions takeOptionsLocked() {
845 ActivityOptions opts = pendingOptions;
846 pendingOptions = null;
847 return opts;
848 }
849
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700850 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -0700851 if (uriPermissions != null) {
852 uriPermissions.removeUriPermissionsLocked();
853 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700854 }
855 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800856
857 void pauseKeyDispatchingLocked() {
858 if (!keysPaused) {
859 keysPaused = true;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800860 service.mWindowManager.pauseKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 }
862 }
863
864 void resumeKeyDispatchingLocked() {
865 if (keysPaused) {
866 keysPaused = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800867 service.mWindowManager.resumeKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868 }
869 }
870
Winson Chung740c3ac2014-11-12 16:14:38 -0800871 void updateThumbnailLocked(Bitmap newThumbnail, CharSequence description) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700872 if (newThumbnail != null) {
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700873 if (DEBUG_THUMBNAILS) Slog.i(TAG_THUMBNAILS,
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700874 "Setting thumbnail of " + this + " to " + newThumbnail);
Winson Chung096f36b2014-08-20 15:39:01 -0700875 boolean thumbnailUpdated = task.setLastThumbnail(newThumbnail);
876 if (thumbnailUpdated && isPersistable()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700877 mStackSupervisor.mService.notifyTaskPersisterLocked(task, false);
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700878 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700879 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700880 task.lastDescription = description;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700881 }
882
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700883 void startLaunchTickingLocked() {
884 if (ActivityManagerService.IS_USER_BUILD) {
885 return;
886 }
887 if (launchTickTime == 0) {
888 launchTickTime = SystemClock.uptimeMillis();
889 continueLaunchTickingLocked();
890 }
891 }
892
893 boolean continueLaunchTickingLocked() {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700894 if (launchTickTime == 0) {
895 return false;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700896 }
Wale Ogunwale7d701172015-03-11 15:36:30 -0700897
898 final ActivityStack stack = task.stack;
899 if (stack == null) {
900 return false;
901 }
902
903 Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG, this);
904 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
905 stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
906 return true;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700907 }
908
909 void finishLaunchTickingLocked() {
910 launchTickTime = 0;
Wale Ogunwale7d701172015-03-11 15:36:30 -0700911 final ActivityStack stack = task.stack;
912 if (stack != null) {
913 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
914 }
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700915 }
916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 // IApplicationToken
918
919 public boolean mayFreezeScreenLocked(ProcessRecord app) {
920 // Only freeze the screen if this activity is currently attached to
921 // an application, and that application is not blocked or unresponding.
922 // In any other case, we can't count on getting the screen unfrozen,
923 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -0800924 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
928 if (mayFreezeScreenLocked(app)) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800929 service.mWindowManager.startAppFreezingScreen(appToken, configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 }
931 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 public void stopFreezingScreenLocked(boolean force) {
934 if (force || frozenBeforeDestroy) {
935 frozenBeforeDestroy = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800936 service.mWindowManager.stopAppFreezingScreen(appToken, force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 }
938 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700939
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700940 public void reportFullyDrawnLocked() {
941 final long curTime = SystemClock.uptimeMillis();
942 if (displayStartTime != 0) {
943 reportLaunchTimeLocked(curTime);
944 }
Wale Ogunwale7d701172015-03-11 15:36:30 -0700945 final ActivityStack stack = task.stack;
946 if (fullyDrawnStartTime != 0 && stack != null) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700947 final long thisTime = curTime - fullyDrawnStartTime;
948 final long totalTime = stack.mFullyDrawnStartTime != 0
949 ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -0700950 if (SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -0700951 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700952 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME,
953 userId, System.identityHashCode(this), shortComponentName,
954 thisTime, totalTime);
955 StringBuilder sb = service.mStringBuilder;
956 sb.setLength(0);
957 sb.append("Fully drawn ");
958 sb.append(shortComponentName);
959 sb.append(": ");
960 TimeUtils.formatDuration(thisTime, sb);
961 if (thisTime != totalTime) {
962 sb.append(" (total ");
963 TimeUtils.formatDuration(totalTime, sb);
964 sb.append(")");
965 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800966 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700967 }
968 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -0700969 //service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700970 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700971 stack.mFullyDrawnStartTime = 0;
972 }
Wale Ogunwale7d701172015-03-11 15:36:30 -0700973 fullyDrawnStartTime = 0;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700974 }
975
976 private void reportLaunchTimeLocked(final long curTime) {
977 final ActivityStack stack = task.stack;
Wale Ogunwale7d701172015-03-11 15:36:30 -0700978 if (stack == null) {
979 return;
980 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700981 final long thisTime = curTime - displayStartTime;
982 final long totalTime = stack.mLaunchStartTime != 0
983 ? (curTime - stack.mLaunchStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -0700984 if (SHOW_ACTIVITY_START_TIME) {
Narayan Kamath7829c812015-06-08 17:39:43 +0100985 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700986 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
987 userId, System.identityHashCode(this), shortComponentName,
988 thisTime, totalTime);
989 StringBuilder sb = service.mStringBuilder;
990 sb.setLength(0);
991 sb.append("Displayed ");
992 sb.append(shortComponentName);
993 sb.append(": ");
994 TimeUtils.formatDuration(thisTime, sb);
995 if (thisTime != totalTime) {
996 sb.append(" (total ");
997 TimeUtils.formatDuration(totalTime, sb);
998 sb.append(")");
999 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001000 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001001 }
1002 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
1003 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001004 //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001005 }
1006 displayStartTime = 0;
1007 stack.mLaunchStartTime = 0;
1008 }
1009
Wale Ogunwale7d701172015-03-11 15:36:30 -07001010 void windowsDrawnLocked() {
1011 if (displayStartTime != 0) {
1012 reportLaunchTimeLocked(SystemClock.uptimeMillis());
1013 }
1014 mStackSupervisor.sendWaitingVisibleReportLocked(this);
1015 startTime = 0;
1016 finishLaunchTickingLocked();
1017 if (task != null) {
1018 task.hasBeenVisible = true;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001019 }
1020 }
1021
Wale Ogunwale7d701172015-03-11 15:36:30 -07001022 void windowsVisibleLocked() {
1023 mStackSupervisor.reportActivityVisibleLocked(this);
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001024 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this);
Wale Ogunwale7d701172015-03-11 15:36:30 -07001025 if (!nowVisible) {
1026 nowVisible = true;
1027 lastVisibleTime = SystemClock.uptimeMillis();
1028 if (!idle) {
1029 // Instead of doing the full stop routine here, let's just hide any activities
1030 // we now can, and let them stop when the normal idle happens.
1031 mStackSupervisor.processStoppingActivitiesLocked(false);
1032 } else {
1033 // If this activity was already idle, then we now need to make sure we perform
1034 // the full stop of any activities that are waiting to do so. This is because
1035 // we won't do that while they are still waiting for this one to become visible.
1036 final int size = mStackSupervisor.mWaitingVisibleActivities.size();
1037 if (size > 0) {
1038 for (int i = 0; i < size; i++) {
1039 ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i);
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001040 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "Was waiting for visible: " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001042 mStackSupervisor.mWaitingVisibleActivities.clear();
1043 mStackSupervisor.scheduleIdleLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001046 service.scheduleAppGcsLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 }
1048 }
1049
Wale Ogunwale7d701172015-03-11 15:36:30 -07001050 ActivityRecord getWaitingHistoryRecordLocked() {
riddle_hsudb46d6b2015-04-01 18:58:07 +08001051 // First find the real culprit... if this activity is waiting for
1052 // another activity to start or has stopped, then the key dispatching
1053 // timeout should not be caused by this.
Wale Ogunwale16a62792015-04-01 11:50:31 -07001054 if (mStackSupervisor.mWaitingVisibleActivities.contains(this) || stopped) {
Craig Mautner8f2adcb2014-04-07 22:21:33 +00001055 final ActivityStack stack = mStackSupervisor.getFocusedStack();
riddle_hsudb46d6b2015-04-01 18:58:07 +08001056 // Try to use the one which is closest to top.
1057 ActivityRecord r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -08001059 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001061 if (r != null) {
1062 return r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 }
1064 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001065 return this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 }
1067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 /**
1069 * This method will return true if the activity is either visible, is becoming visible, is
1070 * currently pausing, or is resumed.
1071 */
1072 public boolean isInterestingToUserLocked() {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001073 return visible || nowVisible || state == ActivityState.PAUSING ||
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 state == ActivityState.RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001075 }
1076
1077 public void setSleeping(boolean _sleeping) {
1078 if (sleeping == _sleeping) {
1079 return;
1080 }
1081 if (app != null && app.thread != null) {
1082 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -08001083 app.thread.scheduleSleeping(appToken, _sleeping);
Craig Mautner0eea92c2013-05-16 13:35:39 -07001084 if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
1085 mStackSupervisor.mGoingToSleepActivities.add(this);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001086 }
1087 sleeping = _sleeping;
1088 } catch (RemoteException e) {
Craig Mautner0eea92c2013-05-16 13:35:39 -07001089 Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001090 }
1091 }
1092 }
Craig Mautnerf81b90872013-02-26 13:02:43 -08001093
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001094 static void activityResumedLocked(IBinder token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001095 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Wale Ogunwale0fc365c2015-05-25 19:35:42 -07001096 if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r);
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001097 r.icicle = null;
1098 r.haveState = false;
1099 }
1100
Craig Mautnerd2328952013-03-05 12:46:26 -08001101 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001102 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Craig Mautnerd2328952013-03-05 12:46:26 -08001103 if (r == null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001104 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08001105 }
1106 final TaskRecord task = r.task;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001107 final int activityNdx = task.mActivities.indexOf(r);
1108 if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001109 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08001110 }
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001111 return task.taskId;
Craig Mautnerd2328952013-03-05 12:46:26 -08001112 }
1113
1114 static ActivityRecord isInStackLocked(IBinder token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001115 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Wale Ogunwale60454db2015-01-23 16:05:07 -08001116 return (r != null) ? r.task.stack.isInStackLocked(r) : null;
Craig Mautnerd2328952013-03-05 12:46:26 -08001117 }
1118
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001119 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -08001120 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
1121 if (r != null) {
1122 return r.task.stack;
1123 }
1124 return null;
1125 }
1126
Dianne Hackborn89ad4562014-08-24 16:45:38 -07001127 final boolean isDestroyable() {
1128 if (finishing || app == null || state == ActivityState.DESTROYING
1129 || state == ActivityState.DESTROYED) {
1130 // This would be redundant.
1131 return false;
1132 }
1133 if (task == null || task.stack == null || this == task.stack.mResumedActivity
1134 || this == task.stack.mPausingActivity || !haveState || !stopped) {
1135 // We're not ready for this kind of thing.
1136 return false;
1137 }
1138 if (visible) {
1139 // The user would notice this!
1140 return false;
1141 }
1142 return true;
1143 }
1144
Winson Chung3bad5cc02014-08-19 17:44:32 -07001145 private static String createImageFilename(long createTime, int taskId) {
1146 return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime +
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001147 TaskPersister.IMAGE_EXTENSION;
1148 }
1149
Craig Mautner648f69b2014-09-18 14:16:26 -07001150 void setTaskDescription(TaskDescription _taskDescription) {
1151 Bitmap icon;
1152 if (_taskDescription.getIconFilename() == null &&
1153 (icon = _taskDescription.getIcon()) != null) {
1154 final String iconFilename = createImageFilename(createTime, task.taskId);
1155 mStackSupervisor.mService.mTaskPersister.saveImage(icon, iconFilename);
1156 _taskDescription.setIconFilename(iconFilename);
1157 }
1158 taskDescription = _taskDescription;
1159 }
1160
Craig Mautner21d24a22014-04-23 11:45:37 -07001161 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
1162 out.attribute(null, ATTR_ID, String.valueOf(createTime));
1163 out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
1164 if (launchedFromPackage != null) {
1165 out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage);
1166 }
1167 if (resolvedType != null) {
1168 out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType);
1169 }
1170 out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified));
1171 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Winson Chung2cb86c72014-06-25 12:03:30 -07001172
Craig Mautner21d24a22014-04-23 11:45:37 -07001173 if (taskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001174 taskDescription.saveToXml(out);
Craig Mautner21d24a22014-04-23 11:45:37 -07001175 }
1176
1177 out.startTag(null, TAG_INTENT);
1178 intent.saveToXml(out);
1179 out.endTag(null, TAG_INTENT);
1180
1181 if (isPersistable() && persistentState != null) {
1182 out.startTag(null, TAG_PERSISTABLEBUNDLE);
1183 persistentState.saveToXml(out);
1184 out.endTag(null, TAG_PERSISTABLEBUNDLE);
1185 }
1186 }
1187
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001188 static ActivityRecord restoreFromXml(XmlPullParser in,
1189 ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07001190 Intent intent = null;
1191 PersistableBundle persistentState = null;
1192 int launchedFromUid = 0;
1193 String launchedFromPackage = null;
1194 String resolvedType = null;
1195 boolean componentSpecified = false;
1196 int userId = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07001197 long createTime = -1;
1198 final int outerDepth = in.getDepth();
Winson Chung2cb86c72014-06-25 12:03:30 -07001199 TaskDescription taskDescription = new TaskDescription();
Craig Mautner21d24a22014-04-23 11:45:37 -07001200
1201 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1202 final String attrName = in.getAttributeName(attrNdx);
1203 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001204 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
Wale Ogunwale18795a22014-12-03 11:38:33 -08001205 "ActivityRecord: attribute name=" + attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001206 if (ATTR_ID.equals(attrName)) {
1207 createTime = Long.valueOf(attrValue);
1208 } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
1209 launchedFromUid = Integer.valueOf(attrValue);
1210 } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
1211 launchedFromPackage = attrValue;
1212 } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
1213 resolvedType = attrValue;
1214 } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
1215 componentSpecified = Boolean.valueOf(attrValue);
1216 } else if (ATTR_USERID.equals(attrName)) {
1217 userId = Integer.valueOf(attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001218 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1219 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001220 } else {
1221 Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName);
1222 }
1223 }
1224
1225 int event;
1226 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
1227 (event != XmlPullParser.END_TAG || in.getDepth() < outerDepth)) {
1228 if (event == XmlPullParser.START_TAG) {
1229 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001230 if (TaskPersister.DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08001231 Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001232 if (TAG_INTENT.equals(name)) {
1233 intent = Intent.restoreFromXml(in);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001234 if (TaskPersister.DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08001235 Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07001236 } else if (TAG_PERSISTABLEBUNDLE.equals(name)) {
1237 persistentState = PersistableBundle.restoreFromXml(in);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001238 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
Craig Mautner21d24a22014-04-23 11:45:37 -07001239 "ActivityRecord: persistentState=" + persistentState);
1240 } else {
1241 Slog.w(TAG, "restoreActivity: unexpected name=" + name);
1242 XmlUtils.skipCurrentTag(in);
1243 }
1244 }
1245 }
1246
1247 if (intent == null) {
Craig Mautnere0129b32014-05-25 16:41:09 -07001248 throw new XmlPullParserException("restoreActivity error intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07001249 }
1250
1251 final ActivityManagerService service = stackSupervisor.mService;
1252 final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null,
Jeff Hao1b012d32014-08-20 10:35:34 -07001253 userId);
Craig Mautnere0129b32014-05-25 16:41:09 -07001254 if (aInfo == null) {
Craig Mautner77b04262014-06-27 15:22:12 -07001255 throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent +
1256 " resolvedType=" + resolvedType);
Craig Mautnere0129b32014-05-25 16:41:09 -07001257 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001258 final ActivityRecord r = new ActivityRecord(service, /*caller*/null, launchedFromUid,
1259 launchedFromPackage, intent, resolvedType, aInfo, service.getConfiguration(),
1260 null, null, 0, componentSpecified, stackSupervisor, null, null);
1261
1262 r.persistentState = persistentState;
Winson Chung2cb86c72014-06-25 12:03:30 -07001263 r.taskDescription = taskDescription;
Craig Mautner21d24a22014-04-23 11:45:37 -07001264 r.createTime = createTime;
1265
1266 return r;
1267 }
1268
1269 private static String activityTypeToString(int type) {
Craig Mautnerae7ecab2013-09-18 11:48:14 -07001270 switch (type) {
1271 case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE";
1272 case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE";
1273 case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE";
1274 default: return Integer.toString(type);
1275 }
1276 }
1277
Craig Mautnerf81b90872013-02-26 13:02:43 -08001278 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001279 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001280 if (stringName != null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001281 return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) +
Craig Mautnerf3333272013-04-22 10:55:53 -07001282 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001283 }
1284 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -08001285 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001286 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -07001287 sb.append(" u");
1288 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001289 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001290 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -08001291 stringName = sb.toString();
1292 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001293 }
1294}