blob: ed26e0ce6b18962ad6a5ffa1223296ca63f02df7 [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 Ogunwale4cea0f52015-12-25 06:30:31 -080019import static android.app.ActivityManager.StackId;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080020import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Wale Ogunwale513346d2016-01-27 10:55:01 -080021import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS;
Wale Ogunwale6cae7652015-12-26 07:36:26 -080022import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE;
Wale Ogunwaled26176f2016-01-25 20:04:04 -080023import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080024import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION;
25import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE;
26import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH;
27import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_THUMBNAILS;
28import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES;
29import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH;
30import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_THUMBNAILS;
31import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
32import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Wale Ogunwale18795a22014-12-03 11:38:33 -080033import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
34
Craig Mautner21d24a22014-04-23 11:45:37 -070035import android.app.ActivityManager.TaskDescription;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -070036import android.app.ActivityOptions;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080037import android.app.PendingIntent;
Craig Mautner05d6272ba2013-02-11 09:39:27 -080038import android.app.ResultInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.content.ComponentName;
40import android.content.Intent;
41import android.content.pm.ActivityInfo;
42import android.content.pm.ApplicationInfo;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -070043import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.content.res.Configuration;
45import android.graphics.Bitmap;
Dianne Hackbornd367ca82012-05-07 15:49:39 -070046import android.graphics.Rect;
Dianne Hackborn247fe742011-01-08 17:25:57 -080047import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.os.Bundle;
Dianne Hackbornbe707852011-11-11 14:32:10 -080049import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.os.Message;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080051import android.os.PersistableBundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import android.os.Process;
Dianne Hackborn39792d22010-08-19 18:01:52 -070053import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.os.SystemClock;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080055import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070056import android.os.UserHandle;
Amith Yamasani0af6fa72016-01-17 15:36:19 -080057import android.service.voice.IVoiceInteractionSession;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.util.EventLog;
59import android.util.Log;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070060import android.util.Slog;
Dianne Hackborn0dad3642010-09-09 21:25:35 -070061import android.util.TimeUtils;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -070062import android.view.AppTransitionAnimationSpec;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.view.IApplicationToken;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -080064import android.view.WindowManager;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070065
Filip Gruszczynski3d026712015-12-16 13:46:38 -080066import com.android.internal.app.ResolverActivity;
67import com.android.internal.content.ReferrerIntent;
68import com.android.internal.util.XmlUtils;
69import com.android.server.AttributeCache;
70import com.android.server.am.ActivityStack.ActivityState;
71import com.android.server.am.ActivityStackSupervisor.ActivityContainer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072
Suprabh Shukla23593142015-11-03 17:31:15 -080073import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -070074import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import java.io.PrintWriter;
76import java.lang.ref.WeakReference;
77import java.util.ArrayList;
78import java.util.HashSet;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070079import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080
Filip Gruszczynski3d026712015-12-16 13:46:38 -080081import org.xmlpull.v1.XmlPullParser;
82import org.xmlpull.v1.XmlPullParserException;
83import org.xmlpull.v1.XmlSerializer;
84
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085/**
86 * An entry in the history stack, representing an activity.
87 */
Dianne Hackbornbe707852011-11-11 14:32:10 -080088final class ActivityRecord {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080089 private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityRecord" : TAG_AM;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -070090 private static final String TAG_STATES = TAG + POSTFIX_STATES;
Wale Ogunwaleee006da2015-03-30 14:49:25 -070091 private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH;
92 private static final String TAG_THUMBNAILS = TAG + POSTFIX_THUMBNAILS;
Wale Ogunwalee23149f2015-03-06 15:39:44 -080093
Wale Ogunwale3ab9a272015-03-16 09:55:45 -070094 private static final boolean SHOW_ACTIVITY_START_TIME = true;
Winson Chung740c3ac2014-11-12 16:14:38 -080095 final public static String RECENTS_PACKAGE_NAME = "com.android.systemui.recents";
Craig Mautnerb59dcfd2013-05-06 13:12:58 -070096
Craig Mautner21d24a22014-04-23 11:45:37 -070097 private static final String ATTR_ID = "id";
98 private static final String TAG_INTENT = "intent";
99 private static final String ATTR_USERID = "user_id";
100 private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle";
101 private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700102 private static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package";
Craig Mautner21d24a22014-04-23 11:45:37 -0700103 private static final String ATTR_RESOLVEDTYPE = "resolved_type";
104 private static final String ATTR_COMPONENTSPECIFIED = "component_specified";
Dianne Hackborn337abb32014-09-24 12:44:29 -0700105 static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_";
Craig Mautner21d24a22014-04-23 11:45:37 -0700106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 final ActivityManagerService service; // owner
Dianne Hackbornbe707852011-11-11 14:32:10 -0800108 final IApplicationToken.Stub appToken; // window manager token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 final ActivityInfo info; // all about me
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700110 final ApplicationInfo appInfo; // information about activity's app
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700111 final int launchedFromUid; // always the uid who started the activity.
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800112 final String launchedFromPackage; // always the package who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -0700113 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 final Intent intent; // the original intent that generated us
115 final ComponentName realActivity; // the intent component, or target of an alias.
116 final String shortComponentName; // the short component name of the intent
117 final String resolvedType; // as per original caller;
118 final String packageName; // the package implementing intent's component
119 final String processName; // process where this component wants to run
120 final String taskAffinity; // as per ActivityInfo.taskAffinity
121 final boolean stateNotNeeded; // As per ActivityInfo.flags
Craig Mautner4addfc52013-06-25 08:05:45 -0700122 boolean fullscreen; // covers the full screen?
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800123 final boolean noDisplay; // activity is not displayed?
The Android Open Source Project4df24232009-03-05 14:34:35 -0800124 final boolean componentSpecified; // did caller specifiy an explicit component?
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700125 final boolean rootVoiceInteraction; // was this the root activity of a voice interaction?
Craig Mautner86d67a42013-05-14 10:34:38 -0700126
127 static final int APPLICATION_ACTIVITY_TYPE = 0;
128 static final int HOME_ACTIVITY_TYPE = 1;
129 static final int RECENTS_ACTIVITY_TYPE = 2;
Craig Mautner2c1faed2013-07-23 12:56:02 -0700130 int mActivityType;
Craig Mautner86d67a42013-05-14 10:34:38 -0700131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 CharSequence nonLocalizedLabel; // the label information from the package mgr.
133 int labelRes; // the label information from the package mgr.
134 int icon; // resource identifier of activity's icon.
Adam Powell04fe6eb2013-05-31 14:39:48 -0700135 int logo; // resource identifier of activity's logo.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 int theme; // resource identifier of activity's theme.
Dianne Hackborn247fe742011-01-08 17:25:57 -0800137 int realTheme; // actual theme resource we will use, never 0.
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800138 int windowFlags; // custom window flags for preview window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 TaskRecord task; // the task this is in.
Craig Mautner21d24a22014-04-23 11:45:37 -0700140 long createTime = System.currentTimeMillis();
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700141 long displayStartTime; // when we started launching this activity
142 long fullyDrawnStartTime; // when we started launching this activity
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700143 long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -0800144 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700145 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700146 long pauseTime; // last time we started pausing the activity
147 long launchTickTime; // base time for launch tick messages
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 Configuration configuration; // configuration activity was last running in
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700149 // Overridden configuration by the activity task
150 // WARNING: Reference points to {@link TaskRecord#mOverrideConfig}, so its internal state
Wale Ogunwale60454db2015-01-23 16:05:07 -0800151 // should never be altered directly.
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700152 Configuration taskConfigOverride;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700153 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700154 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 final String resultWho; // additional identifier for use by resultTo.
156 final int requestCode; // code given by requester (resultTo)
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800157 ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800159 ArrayList<ReferrerIntent> newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700160 ActivityOptions pendingOptions; // most recently given options
George Mount6ba042b2014-07-28 11:12:28 -0700161 ActivityOptions returningOptions; // options that are coming back via convertToTranslucent
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700162 AppTimeTracker appTimeTracker; // set if we are tracking the time in this app/task/activity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700164 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700165 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700166 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 Bundle icicle; // last saved activity state
Craig Mautnera0026042014-04-23 11:45:37 -0700168 PersistableBundle persistentState; // last persistently saved activity state
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 boolean frontOfTask; // is this the root activity of its task?
170 boolean launchFailed; // set if a launched failed, to abort on 2nd try
171 boolean haveState; // have we gotten the last activity state?
172 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700173 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 boolean finishing; // activity in pending finish list?
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800175 boolean deferRelaunchUntilPaused; // relaunch of activity is being deferred until pause is
176 // completed
177 boolean preserveWindowOnDeferredRelaunch; // activity windows are preserved on deferred relaunch
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 int configChangeFlags; // which config values have changed
179 boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 int launchMode; // the launch mode activity attribute.
181 boolean visible; // does this activity's window need to be shown?
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800182 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 boolean nowVisible; // is this activity's window visible?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 boolean idle; // has the activity gone idle?
185 boolean hasBeenLaunched;// has this activity ever been launched?
186 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400187 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400188 boolean forceNewConfig; // force re-create with new config next time
Dianne Hackborn07981492013-01-28 11:36:23 -0800189 int launchCount; // count of launches since last state
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800190 long lastLaunchTime; // time of last launch of this activity
Ruben Brunkdd18a0b2015-12-04 16:16:31 -0800191 boolean isVrActivity; // is the activity running in VR mode?
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800192 ArrayList<ActivityContainer> mChildContainers = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700194 String stringName; // for caching of toString().
Craig Mautnerde4ef022013-04-07 19:01:33 -0700195
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700196 private boolean inHistory; // are we in the history stack?
Craig Mautnerde4ef022013-04-07 19:01:33 -0700197 final ActivityStackSupervisor mStackSupervisor;
Craig Mautnera61bc652013-10-28 15:43:18 -0700198 boolean mStartingWindowShown = false;
Jorim Jaggic2f262b2015-12-07 16:59:10 -0800199 boolean mUpdateTaskThumbnailWhenHidden;
Craig Mautnere0a38842013-12-16 16:14:02 -0800200 ActivityContainer mInitialActivityContainer;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700201
Craig Mautner21d24a22014-04-23 11:45:37 -0700202 TaskDescription taskDescription; // the recents information for this activity
Craig Mautnerbb742462014-07-07 15:28:55 -0700203 boolean mLaunchTaskBehind; // this activity is actively being launched with
204 // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed.
Craig Mautner2fbd7542014-03-21 09:34:07 -0700205
Filip Gruszczynski23493322015-07-29 17:02:59 -0700206 // These configurations are collected from application's resources based on size-sensitive
207 // qualifiers. For example, layout-w800dp will be added to mHorizontalSizeConfigurations as 800
208 // and drawable-sw400dp will be added to both as 400.
209 private int[] mVerticalSizeConfigurations;
210 private int[] mHorizontalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700211 private int[] mSmallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700212
Amith Yamasani0af6fa72016-01-17 15:36:19 -0800213 boolean pendingVoiceInteractionStart; // Waiting for activity-invoked voice session
214 IVoiceInteractionSession voiceSession; // Voice interaction session for this activity
215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700217 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700218 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
219 pw.print(" processName="); pw.println(processName);
220 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Craig Mautnere11f2b72013-04-01 12:37:17 -0700221 pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800222 pw.print(" userId="); pw.println(userId);
223 pw.print(prefix); pw.print("app="); pw.println(app);
224 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700225 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
226 pw.print(" task="); pw.println(task);
227 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700228 pw.print(prefix); pw.print("realActivity=");
229 pw.println(realActivity.flattenToShortString());
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700230 if (appInfo != null) {
231 pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir);
232 if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) {
233 pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir);
234 }
235 pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800236 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700237 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
238 pw.print(" componentSpecified="); pw.print(componentSpecified);
Craig Mautner86d67a42013-05-14 10:34:38 -0700239 pw.print(" mActivityType="); pw.println(mActivityType);
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700240 if (rootVoiceInteraction) {
241 pw.print(prefix); pw.print("rootVoiceInteraction="); pw.println(rootVoiceInteraction);
242 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800243 pw.print(prefix); pw.print("compat="); pw.print(compat);
244 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
245 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
246 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Dianne Hackborne17aeb32011-04-07 15:11:57 -0700247 pw.print(prefix); pw.print("config="); pw.println(configuration);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700248 pw.print(prefix); pw.print("taskConfigOverride="); pw.println(taskConfigOverride);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700249 if (resultTo != null || resultWho != null) {
250 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
251 pw.print(" resultWho="); pw.print(resultWho);
252 pw.print(" resultCode="); pw.println(requestCode);
253 }
Craig Mautner29c58ca2014-10-14 16:17:06 -0700254 if (taskDescription != null) {
255 final String iconFilename = taskDescription.getIconFilename();
256 if (iconFilename != null || taskDescription.getLabel() != null ||
257 taskDescription.getPrimaryColor() != 0) {
258 pw.print(prefix); pw.print("taskDescription:");
259 pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename());
260 pw.print(" label=\""); pw.print(taskDescription.getLabel());
261 pw.print("\"");
262 pw.print(" color=");
263 pw.println(Integer.toHexString(taskDescription.getPrimaryColor()));
264 }
265 if (iconFilename == null && taskDescription.getIcon() != null) {
266 pw.print(prefix); pw.println("taskDescription contains Bitmap");
267 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700268 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700269 if (results != null) {
270 pw.print(prefix); pw.print("results="); pw.println(results);
271 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700272 if (pendingResults != null && pendingResults.size() > 0) {
273 pw.print(prefix); pw.println("Pending Results:");
274 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
275 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
276 pw.print(prefix); pw.print(" - ");
277 if (pir == null) {
278 pw.println("null");
279 } else {
280 pw.println(pir);
281 pir.dump(pw, prefix + " ");
282 }
283 }
284 }
285 if (newIntents != null && newIntents.size() > 0) {
286 pw.print(prefix); pw.println("Pending New Intents:");
287 for (int i=0; i<newIntents.size(); i++) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800288 Intent intent = newIntents.get(i);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700289 pw.print(prefix); pw.print(" - ");
290 if (intent == null) {
291 pw.println("null");
292 } else {
293 pw.println(intent.toShortString(false, true, false, true));
294 }
295 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700296 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700297 if (pendingOptions != null) {
298 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
299 }
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700300 if (appTimeTracker != null) {
301 appTimeTracker.dumpWithHeader(pw, prefix, false);
302 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700303 if (uriPermissions != null) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700304 uriPermissions.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700305 }
306 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800307 pw.print(" launchCount="); pw.print(launchCount);
308 pw.print(" lastLaunchTime=");
309 if (lastLaunchTime == 0) pw.print("0");
310 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
311 pw.println();
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700312 pw.print(prefix); pw.print("haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700313 pw.print(" icicle="); pw.println(icicle);
314 pw.print(prefix); pw.print("state="); pw.print(state);
315 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700316 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700317 pw.print(" finishing="); pw.println(finishing);
318 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
319 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700320 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800321 pw.print(" sleeping="); pw.print(sleeping);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700322 pw.print(" idle="); pw.println(idle);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800323 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
324 pw.print(" noDisplay="); pw.print(noDisplay);
325 pw.print(" immersive="); pw.print(immersive);
326 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800327 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400328 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700329 pw.print(prefix); pw.print("mActivityType=");
330 pw.println(activityTypeToString(mActivityType));
Ruben Brunkdd18a0b2015-12-04 16:16:31 -0800331 pw.print(prefix); pw.print("vrMode="); pw.println(isVrActivity);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700332 if (displayStartTime != 0 || startTime != 0) {
333 pw.print(prefix); pw.print("displayStartTime=");
334 if (displayStartTime == 0) pw.print("0");
335 else TimeUtils.formatDuration(displayStartTime, now, pw);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700336 pw.print(" startTime=");
337 if (startTime == 0) pw.print("0");
338 else TimeUtils.formatDuration(startTime, now, pw);
339 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700340 }
Craig Mautner8c14c152015-01-15 17:32:07 -0800341 final boolean waitingVisible = mStackSupervisor.mWaitingVisibleActivities.contains(this);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800342 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700343 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800344 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700345 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700346 if (lastVisibleTime == 0) pw.print("0");
347 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
348 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700349 }
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800350 if (deferRelaunchUntilPaused || configChangeFlags != 0) {
351 pw.print(prefix); pw.print("deferRelaunchUntilPaused="); pw.print(deferRelaunchUntilPaused);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700352 pw.print(" configChangeFlags=");
353 pw.println(Integer.toHexString(configChangeFlags));
354 }
355 if (connections != null) {
356 pw.print(prefix); pw.print("connections="); pw.println(connections);
357 }
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800358 if (info != null) {
359 pw.println(prefix + "resizeMode=" + ActivityInfo.resizeModeToString(info.resizeMode));
360 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 }
362
Filip Gruszczynski23493322015-07-29 17:02:59 -0700363 public boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) {
364 return crossesSizeThreshold(mHorizontalSizeConfigurations, firstDp, secondDp);
365 }
366
367 public boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) {
368 return crossesSizeThreshold(mVerticalSizeConfigurations, firstDp, secondDp);
369 }
370
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700371 public boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) {
372 return crossesSizeThreshold(mSmallestSizeConfigurations, firstDp, secondDp);
373 }
374
Filip Gruszczynski23493322015-07-29 17:02:59 -0700375 /**
376 * The purpose of this method is to decide whether the activity needs to be relaunched upon
377 * changing its size. In most cases the activities don't need to be relaunched, if the resize
378 * is small, all the activity content has to do is relayout itself within new bounds. There are
379 * cases however, where the activity's content would be completely changed in the new size and
380 * the full relaunch is required.
381 *
382 * The activity will report to us vertical and horizontal thresholds after which a relaunch is
383 * required. These thresholds are collected from the application resource qualifiers. For
384 * example, if application has layout-w600dp resource directory, then it needs a relaunch when
385 * we resize from width of 650dp to 550dp, as it crosses the 600dp threshold. However, if
386 * it resizes width from 620dp to 700dp, it won't be relaunched as it stays on the same side
387 * of the threshold.
388 */
389 private static boolean crossesSizeThreshold(int[] thresholds, int firstDp,
390 int secondDp) {
391 if (thresholds == null) {
392 return false;
393 }
394 for (int i = thresholds.length - 1; i >= 0; i--) {
395 final int threshold = thresholds[i];
396 if ((firstDp < threshold && secondDp >= threshold)
397 || (firstDp >= threshold && secondDp < threshold)) {
398 return true;
399 }
400 }
401 return false;
402 }
403
404 public void setSizeConfigurations(int[] horizontalSizeConfiguration,
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700405 int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700406 mHorizontalSizeConfigurations = horizontalSizeConfiguration;
407 mVerticalSizeConfigurations = verticalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700408 mSmallestSizeConfigurations = smallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700409 }
410
Filip Gruszczynskica664812015-12-04 12:43:36 -0800411 void scheduleConfigurationChanged(Configuration config, boolean reportToActivity) {
412 if (app != null && app.thread != null) {
413 try {
414 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + this + " " +
415 "reportToActivity=" + reportToActivity + " and config: " + config);
416 app.thread.scheduleActivityConfigurationChanged(
417 appToken, new Configuration(config), reportToActivity);
418 } catch (RemoteException e) {
419 // If process died, whatever.
420 }
421 }
422 }
423
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800424 boolean isFreeform() {
425 return task != null && task.stack != null
426 && task.stack.mStackId == FREEFORM_WORKSPACE_STACK_ID;
427 }
428
Dianne Hackbornbe707852011-11-11 14:32:10 -0800429 static class Token extends IApplicationToken.Stub {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700430 private final WeakReference<ActivityRecord> weakActivity;
431 private final ActivityManagerService mService;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800432
Wale Ogunwale7d701172015-03-11 15:36:30 -0700433 Token(ActivityRecord activity, ActivityManagerService service) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800434 weakActivity = new WeakReference<>(activity);
Wale Ogunwale7d701172015-03-11 15:36:30 -0700435 mService = service;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800436 }
437
Wale Ogunwale7d701172015-03-11 15:36:30 -0700438 @Override
439 public void windowsDrawn() {
440 synchronized (mService) {
441 ActivityRecord r = tokenToActivityRecordLocked(this);
442 if (r != null) {
443 r.windowsDrawnLocked();
444 }
Dianne Hackbornbe707852011-11-11 14:32:10 -0800445 }
446 }
447
Wale Ogunwale7d701172015-03-11 15:36:30 -0700448 @Override
449 public void windowsVisible() {
450 synchronized (mService) {
451 ActivityRecord r = tokenToActivityRecordLocked(this);
452 if (r != null) {
453 r.windowsVisibleLocked();
454 }
Dianne Hackbornbe707852011-11-11 14:32:10 -0800455 }
456 }
457
Wale Ogunwale7d701172015-03-11 15:36:30 -0700458 @Override
459 public void windowsGone() {
460 synchronized (mService) {
461 ActivityRecord r = tokenToActivityRecordLocked(this);
462 if (r != null) {
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700463 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + r);
Wale Ogunwale7d701172015-03-11 15:36:30 -0700464 r.nowVisible = false;
465 return;
466 }
Dianne Hackbornbe707852011-11-11 14:32:10 -0800467 }
468 }
469
Wale Ogunwale7d701172015-03-11 15:36:30 -0700470 @Override
471 public boolean keyDispatchingTimedOut(String reason) {
472 ActivityRecord r;
473 ActivityRecord anrActivity;
474 ProcessRecord anrApp;
475 synchronized (mService) {
476 r = tokenToActivityRecordLocked(this);
477 if (r == null) {
478 return false;
479 }
480 anrActivity = r.getWaitingHistoryRecordLocked();
481 anrApp = r != null ? r.app : null;
482 }
483 return mService.inputDispatchingTimedOut(anrApp, anrActivity, r, false, reason);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800484 }
485
Wale Ogunwale7d701172015-03-11 15:36:30 -0700486 @Override
487 public long getKeyDispatchingTimeout() {
488 synchronized (mService) {
489 ActivityRecord r = tokenToActivityRecordLocked(this);
490 if (r == null) {
491 return 0;
492 }
493 r = r.getWaitingHistoryRecordLocked();
494 return ActivityManagerService.getInputDispatchingTimeoutLocked(r);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800495 }
Wale Ogunwale7d701172015-03-11 15:36:30 -0700496 }
497
498 private static final ActivityRecord tokenToActivityRecordLocked(Token token) {
499 if (token == null) {
500 return null;
501 }
502 ActivityRecord r = token.weakActivity.get();
503 if (r == null || r.task == null || r.task.stack == null) {
504 return null;
505 }
506 return r;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800507 }
508
Craig Mautnerde4ef022013-04-07 19:01:33 -0700509 @Override
Dianne Hackbornbe707852011-11-11 14:32:10 -0800510 public String toString() {
511 StringBuilder sb = new StringBuilder(128);
512 sb.append("Token{");
513 sb.append(Integer.toHexString(System.identityHashCode(this)));
514 sb.append(' ');
515 sb.append(weakActivity.get());
516 sb.append('}');
517 return sb.toString();
518 }
519 }
520
Wale Ogunwale7d701172015-03-11 15:36:30 -0700521 static ActivityRecord forTokenLocked(IBinder token) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800522 try {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700523 return Token.tokenToActivityRecordLocked((Token)token);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800524 } catch (ClassCastException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800525 Slog.w(TAG, "Bad activity token: " + token, e);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800526 return null;
527 }
528 }
529
Chong Zhang85ee6542015-10-02 13:36:38 -0700530 boolean isResolverActivity() {
531 return ResolverActivity.class.getName().equals(realActivity.getClassName());
Craig Mautnerac6f8432013-07-17 13:24:59 -0700532 }
533
Craig Mautnerd2328952013-03-05 12:46:26 -0800534 ActivityRecord(ActivityManagerService _service, ProcessRecord _caller,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800535 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700537 ActivityRecord _resultTo, String _resultWho, int _reqCode,
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700538 boolean _componentSpecified, boolean _rootVoiceInteraction,
539 ActivityStackSupervisor supervisor,
Chong Zhang280d3322015-11-03 17:27:26 -0800540 ActivityContainer container, ActivityOptions options) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 service = _service;
Wale Ogunwale7d701172015-03-11 15:36:30 -0700542 appToken = new Token(this, service);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 info = aInfo;
544 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800545 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700546 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 intent = _intent;
548 shortComponentName = _intent.getComponent().flattenToShortString();
549 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800550 componentSpecified = _componentSpecified;
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700551 rootVoiceInteraction = _rootVoiceInteraction;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 configuration = _configuration;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700553 taskConfigOverride = Configuration.EMPTY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 resultTo = _resultTo;
555 resultWho = _resultWho;
556 requestCode = _reqCode;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700557 state = ActivityState.INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 frontOfTask = false;
559 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700561 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 finishing = false;
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800563 deferRelaunchUntilPaused = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 keysPaused = false;
565 inHistory = false;
Chong Zhanga48ef662015-08-18 19:21:47 -0700566 visible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 nowVisible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 idle = false;
569 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700570 mStackSupervisor = supervisor;
Craig Mautnere0a38842013-12-16 16:14:02 -0800571 mInitialActivityContainer = container;
Craig Mautner233ceee2014-05-09 17:05:11 -0700572 if (options != null) {
Chong Zhang280d3322015-11-03 17:27:26 -0800573 pendingOptions = options;
Craig Mautnerbb742462014-07-07 15:28:55 -0700574 mLaunchTaskBehind = pendingOptions.getLaunchTaskBehind();
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700575 PendingIntent usageReport = pendingOptions.getUsageTimeReport();
576 if (usageReport != null) {
577 appTimeTracker = new AppTimeTracker(usageReport);
578 }
Craig Mautner233ceee2014-05-09 17:05:11 -0700579 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700581 // This starts out true, since the initial state of an activity
582 // is that we have everything, and we shouldn't never consider it
583 // lacking in state to be removed if it dies.
584 haveState = true;
585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 if (aInfo != null) {
587 if (aInfo.targetActivity == null
588 || aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE
589 || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
590 realActivity = _intent.getComponent();
591 } else {
592 realActivity = new ComponentName(aInfo.packageName,
593 aInfo.targetActivity);
594 }
595 taskAffinity = aInfo.taskAffinity;
596 stateNotNeeded = (aInfo.flags&
597 ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700598 appInfo = aInfo.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 nonLocalizedLabel = aInfo.nonLocalizedLabel;
600 labelRes = aInfo.labelRes;
601 if (nonLocalizedLabel == null && labelRes == 0) {
602 ApplicationInfo app = aInfo.applicationInfo;
603 nonLocalizedLabel = app.nonLocalizedLabel;
604 labelRes = app.labelRes;
605 }
606 icon = aInfo.getIconResource();
Adam Powell04fe6eb2013-05-31 14:39:48 -0700607 logo = aInfo.getLogoResource();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 theme = aInfo.getThemeResource();
Dianne Hackborn247fe742011-01-08 17:25:57 -0800609 realTheme = theme;
610 if (realTheme == 0) {
611 realTheme = aInfo.applicationInfo.targetSdkVersion
612 < Build.VERSION_CODES.HONEYCOMB
613 ? android.R.style.Theme
614 : android.R.style.Theme_Holo;
615 }
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800616 if ((aInfo.flags&ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
617 windowFlags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
618 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0
620 && _caller != null
621 && (aInfo.applicationInfo.uid == Process.SYSTEM_UID
622 || aInfo.applicationInfo.uid == _caller.info.uid)) {
623 processName = _caller.processName;
624 } else {
625 processName = aInfo.processName;
626 }
627
628 if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
629 intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
630 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 packageName = aInfo.applicationInfo.packageName;
633 launchMode = aInfo.launchMode;
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700636 realTheme, com.android.internal.R.styleable.Window, userId);
Dianne Hackbornb795d7c2015-07-28 17:40:06 -0700637 final boolean translucent = ent != null && (ent.array.getBoolean(
Filip Gruszczynski23958c62015-02-23 18:05:27 -0800638 com.android.internal.R.styleable.Window_windowIsTranslucent, false)
639 || (!ent.array.hasValue(
640 com.android.internal.R.styleable.Window_windowIsTranslucent)
641 && ent.array.getBoolean(
642 com.android.internal.R.styleable.Window_windowSwipeToDismiss,
Dianne Hackbornb795d7c2015-07-28 17:40:06 -0700643 false)));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 fullscreen = ent != null && !ent.array.getBoolean(
645 com.android.internal.R.styleable.Window_windowIsFloating, false)
Filip Gruszczynski23958c62015-02-23 18:05:27 -0800646 && !translucent;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800647 noDisplay = ent != null && ent.array.getBoolean(
648 com.android.internal.R.styleable.Window_windowNoDisplay, false);
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700649
Craig Mautner80259352013-09-28 12:35:25 -0700650 if ((!_componentSpecified || _launchedFromUid == Process.myUid()
Craig Mautner86d67a42013-05-14 10:34:38 -0700651 || _launchedFromUid == 0) &&
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700652 Intent.ACTION_MAIN.equals(_intent.getAction()) &&
653 _intent.hasCategory(Intent.CATEGORY_HOME) &&
654 _intent.getCategories().size() == 1 &&
655 _intent.getData() == null &&
656 _intent.getType() == null &&
Craig Mautner80259352013-09-28 12:35:25 -0700657 (intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 &&
Chong Zhang85ee6542015-10-02 13:36:38 -0700658 !isResolverActivity()) {
Craig Mautner86d67a42013-05-14 10:34:38 -0700659 // This sure looks like a home activity!
660 mActivityType = HOME_ACTIVITY_TYPE;
Craig Mautner80259352013-09-28 12:35:25 -0700661 } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) {
Craig Mautner86d67a42013-05-14 10:34:38 -0700662 mActivityType = RECENTS_ACTIVITY_TYPE;
663 } else {
664 mActivityType = APPLICATION_ACTIVITY_TYPE;
665 }
Daniel Sandler69a48172010-06-23 16:29:36 -0400666
667 immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0;
Ruben Brunkdd18a0b2015-12-04 16:16:31 -0800668 isVrActivity = (aInfo.flags & ActivityInfo.FLAG_ENABLE_VR_MODE) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 } else {
670 realActivity = null;
671 taskAffinity = null;
672 stateNotNeeded = false;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700673 appInfo = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 processName = null;
675 packageName = null;
676 fullscreen = true;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800677 noDisplay = false;
Craig Mautner86d67a42013-05-14 10:34:38 -0700678 mActivityType = APPLICATION_ACTIVITY_TYPE;
Daniel Sandler69a48172010-06-23 16:29:36 -0400679 immersive = false;
Ruben Brunkdd18a0b2015-12-04 16:16:31 -0800680 isVrActivity = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 }
682 }
683
Craig Mautnera228ae92014-07-09 05:44:55 -0700684 void setTask(TaskRecord newTask, TaskRecord taskToAffiliateWith) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700685 if (task != null && task.removeActivity(this) && task != newTask && task.stack != null) {
686 task.stack.removeTask(task, "setTask");
Craig Mautnerde4ef022013-04-07 19:01:33 -0700687 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700688 task = newTask;
Craig Mautnera228ae92014-07-09 05:44:55 -0700689 setTaskToAffiliateWith(taskToAffiliateWith);
690 }
691
692 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
693 if (taskToAffiliateWith != null &&
694 launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE &&
695 launchMode != ActivityInfo.LAUNCH_SINGLE_TASK) {
696 task.setTaskToAffiliateWith(taskToAffiliateWith);
697 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700698 }
699
Craig Mautner5eda9b32013-07-02 11:58:16 -0700700 boolean changeWindowTranslucency(boolean toOpaque) {
701 if (fullscreen == toOpaque) {
702 return false;
703 }
Craig Mautner4addfc52013-06-25 08:05:45 -0700704
Craig Mautner5eda9b32013-07-02 11:58:16 -0700705 // Keep track of the number of fullscreen activities in this task.
706 task.numFullscreen += toOpaque ? +1 : -1;
707
708 fullscreen = toOpaque;
709 return true;
Craig Mautner4addfc52013-06-25 08:05:45 -0700710 }
711
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700712 void putInHistory() {
713 if (!inHistory) {
714 inHistory = true;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700715 }
716 }
717
718 void takeFromHistory() {
719 if (inHistory) {
720 inHistory = false;
721 if (task != null && !finishing) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800722 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700723 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700724 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700725 }
726 }
727
728 boolean isInHistory() {
729 return inHistory;
730 }
731
Wale Ogunwale7d701172015-03-11 15:36:30 -0700732 boolean isInStackLocked() {
733 return task != null && task.stack != null && task.stack.isInStackLocked(this) != null;
734 }
735
Craig Mautner86d67a42013-05-14 10:34:38 -0700736 boolean isHomeActivity() {
737 return mActivityType == HOME_ACTIVITY_TYPE;
738 }
739
740 boolean isRecentsActivity() {
741 return mActivityType == RECENTS_ACTIVITY_TYPE;
742 }
743
744 boolean isApplicationActivity() {
745 return mActivityType == APPLICATION_ACTIVITY_TYPE;
746 }
747
Craig Mautner21d24a22014-04-23 11:45:37 -0700748 boolean isPersistable() {
Craig Mautner43e52ed2014-06-16 17:18:52 -0700749 return (info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY ||
750 info.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS) &&
751 (intent == null ||
752 (intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
Craig Mautner21d24a22014-04-23 11:45:37 -0700753 }
754
Wale Ogunwale4cea0f52015-12-25 06:30:31 -0800755 boolean isFocusable() {
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800756 return StackId.canReceiveKeys(task.stack.mStackId) || isAlwaysFocusable();
757 }
758
759 boolean isResizeable() {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800760 return !isHomeActivity() && ActivityInfo.isResizeableMode(info.resizeMode);
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800761 }
762
Wale Ogunwale513346d2016-01-27 10:55:01 -0800763 boolean isResizeableOrForced() {
764 return !isHomeActivity() && (isResizeable() || service.mForceResizableActivities);
765 }
766
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800767 boolean supportsPictureInPicture() {
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800768 return !isHomeActivity() && info.resizeMode == RESIZE_MODE_RESIZEABLE_AND_PIPABLE;
769 }
770
Wale Ogunwale513346d2016-01-27 10:55:01 -0800771 boolean canGoInDockedStack() {
772 return !isHomeActivity()
773 && (isResizeableOrForced() || info.resizeMode == RESIZE_MODE_CROP_WINDOWS);
774 }
775
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800776 boolean isAlwaysFocusable() {
777 return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0;
Wale Ogunwale4cea0f52015-12-25 06:30:31 -0800778 }
779
Wale Ogunwale7d701172015-03-11 15:36:30 -0700780 void makeFinishingLocked() {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800781 if (!finishing) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700782 if (task != null && task.stack != null
783 && this == task.stack.getVisibleBehindActivity()) {
Jose Lima34ff4922014-08-18 15:19:41 -0700784 // A finishing activity should not remain as visible in the background
785 mStackSupervisor.requestVisibleBehindLocked(this, false);
786 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800787 finishing = true;
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700788 if (stopped) {
789 clearOptionsLocked();
790 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800791 }
792 }
793
Dianne Hackborn7e269642010-08-25 19:50:20 -0700794 UriPermissionOwner getUriPermissionsLocked() {
795 if (uriPermissions == null) {
796 uriPermissions = new UriPermissionOwner(service, this);
797 }
798 return uriPermissions;
799 }
800
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700801 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800802 int requestCode, int resultCode,
803 Intent resultData) {
804 ActivityResult r = new ActivityResult(from, resultWho,
John Spurlock8a985d22014-02-25 09:40:05 -0500805 requestCode, resultCode, resultData);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800807 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 }
809 results.add(r);
810 }
811
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700812 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 int requestCode) {
814 if (results != null) {
815 for (int i=results.size()-1; i>=0; i--) {
816 ActivityResult r = (ActivityResult)results.get(i);
817 if (r.mFrom != from) continue;
818 if (r.mResultWho == null) {
819 if (resultWho != null) continue;
820 } else {
821 if (!r.mResultWho.equals(resultWho)) continue;
822 }
823 if (r.mRequestCode != requestCode) continue;
824
825 results.remove(i);
826 }
827 }
828 }
829
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800830 void addNewIntentLocked(ReferrerIntent intent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 if (newIntents == null) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800832 newIntents = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 }
834 newIntents.add(intent);
835 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700836
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700837 /**
838 * Deliver a new Intent to an existing activity, so that its onNewIntent()
839 * method will be called at the proper time.
840 */
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800841 final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) {
Dianne Hackborn514074f2013-02-11 10:52:46 -0800842 // The activity now gets access to the data associated with this Intent.
843 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
Nicolas Prevotc6cf95c2014-05-29 11:30:36 +0100844 intent, getUriPermissionsLocked(), userId);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700845 // We want to immediately deliver the intent to the activity if
846 // it is currently the top resumed activity... however, if the
847 // device is sleeping, then all activities are stopped, so in that
848 // case we will deliver it if this is the current top activity on its
849 // stack.
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800850 final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
Craig Mautner86d67a42013-05-14 10:34:38 -0700851 boolean unsent = true;
Wale Ogunwale7d701172015-03-11 15:36:30 -0700852 if ((state == ActivityState.RESUMED
853 || (service.isSleeping() && task.stack != null
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -0700854 && task.stack.topRunningActivityLocked() == this))
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700855 && app != null && app.thread != null) {
856 try {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800857 ArrayList<ReferrerIntent> ar = new ArrayList<>(1);
858 ar.add(rintent);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800859 app.thread.scheduleNewIntent(ar, appToken);
Craig Mautner86d67a42013-05-14 10:34:38 -0700860 unsent = false;
Dianne Hackborn39792d22010-08-19 18:01:52 -0700861 } catch (RemoteException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800862 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn39792d22010-08-19 18:01:52 -0700863 } catch (NullPointerException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800864 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700865 }
866 }
Craig Mautner86d67a42013-05-14 10:34:38 -0700867 if (unsent) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800868 addNewIntentLocked(rintent);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700869 }
870 }
871
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700872 void updateOptionsLocked(ActivityOptions options) {
873 if (options != null) {
874 if (pendingOptions != null) {
875 pendingOptions.abort();
876 }
877 pendingOptions = options;
878 }
879 }
880
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700881 void applyOptionsLocked() {
George Mount2c92c972014-03-20 09:38:23 -0700882 if (pendingOptions != null
883 && pendingOptions.getAnimationType() != ActivityOptions.ANIM_SCENE_TRANSITION) {
Michael Jurka21385cd2012-05-03 10:57:31 -0700884 final int animationType = pendingOptions.getAnimationType();
885 switch (animationType) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700886 case ActivityOptions.ANIM_CUSTOM:
887 service.mWindowManager.overridePendingAppTransition(
888 pendingOptions.getPackageName(),
889 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -0700890 pendingOptions.getCustomExitResId(),
891 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700892 break;
Chet Haase10e23ab2015-02-11 15:08:38 -0800893 case ActivityOptions.ANIM_CLIP_REVEAL:
894 service.mWindowManager.overridePendingAppTransitionClipReveal(
895 pendingOptions.getStartX(), pendingOptions.getStartY(),
896 pendingOptions.getWidth(), pendingOptions.getHeight());
897 if (intent.getSourceBounds() == null) {
898 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
899 pendingOptions.getStartY(),
900 pendingOptions.getStartX()+pendingOptions.getWidth(),
901 pendingOptions.getStartY()+pendingOptions.getHeight()));
902 }
903 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700904 case ActivityOptions.ANIM_SCALE_UP:
905 service.mWindowManager.overridePendingAppTransitionScaleUp(
906 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200907 pendingOptions.getWidth(), pendingOptions.getHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700908 if (intent.getSourceBounds() == null) {
909 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
910 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200911 pendingOptions.getStartX()+pendingOptions.getWidth(),
912 pendingOptions.getStartY()+pendingOptions.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700913 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700914 break;
Michael Jurka832cb222012-04-13 09:32:47 -0700915 case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
916 case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
917 boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700918 service.mWindowManager.overridePendingAppTransitionThumb(
919 pendingOptions.getThumbnail(),
920 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -0700921 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -0700922 scaleUp);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700923 if (intent.getSourceBounds() == null) {
924 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
925 pendingOptions.getStartY(),
926 pendingOptions.getStartX()
927 + pendingOptions.getThumbnail().getWidth(),
928 pendingOptions.getStartY()
929 + pendingOptions.getThumbnail().getHeight()));
930 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700931 break;
Winson Chunga4ccb862014-08-22 15:26:27 -0700932 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP:
933 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700934 final AppTransitionAnimationSpec[] specs = pendingOptions.getAnimSpecs();
935 if (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN
936 && specs != null) {
937 service.mWindowManager.overridePendingAppTransitionMultiThumb(
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700938 specs, pendingOptions.getOnAnimationStartListener(),
939 pendingOptions.getAnimationFinishedListener(), false);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700940 } else {
941 service.mWindowManager.overridePendingAppTransitionAspectScaledThumb(
942 pendingOptions.getThumbnail(),
943 pendingOptions.getStartX(), pendingOptions.getStartY(),
944 pendingOptions.getWidth(), pendingOptions.getHeight(),
945 pendingOptions.getOnAnimationStartListener(),
946 (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP));
947 if (intent.getSourceBounds() == null) {
948 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
949 pendingOptions.getStartY(),
950 pendingOptions.getStartX() + pendingOptions.getWidth(),
951 pendingOptions.getStartY() + pendingOptions.getHeight()));
952 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700953 }
954 break;
Craig Mautner233ceee2014-05-09 17:05:11 -0700955 default:
956 Slog.e(TAG, "applyOptionsLocked: Unknown animationType=" + animationType);
957 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700958 }
959 pendingOptions = null;
960 }
961 }
962
Adam Powellcfbe9be2013-11-06 14:58:58 -0800963 ActivityOptions getOptionsForTargetActivityLocked() {
964 return pendingOptions != null ? pendingOptions.forTargetActivity() : null;
965 }
966
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700967 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700968 if (pendingOptions != null) {
969 pendingOptions.abort();
970 pendingOptions = null;
971 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700972 }
973
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700974 ActivityOptions takeOptionsLocked() {
975 ActivityOptions opts = pendingOptions;
976 pendingOptions = null;
977 return opts;
978 }
979
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700980 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -0700981 if (uriPermissions != null) {
982 uriPermissions.removeUriPermissionsLocked();
983 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700984 }
985 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986
987 void pauseKeyDispatchingLocked() {
988 if (!keysPaused) {
989 keysPaused = true;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800990 service.mWindowManager.pauseKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 }
992 }
993
994 void resumeKeyDispatchingLocked() {
995 if (keysPaused) {
996 keysPaused = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800997 service.mWindowManager.resumeKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 }
999 }
1000
Winson Chung740c3ac2014-11-12 16:14:38 -08001001 void updateThumbnailLocked(Bitmap newThumbnail, CharSequence description) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001002 if (newThumbnail != null) {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001003 if (DEBUG_THUMBNAILS) Slog.i(TAG_THUMBNAILS,
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001004 "Setting thumbnail of " + this + " to " + newThumbnail);
Winsonc809cbb2015-11-02 12:06:15 -08001005 boolean thumbnailUpdated = task.setLastThumbnailLocked(newThumbnail);
Winson Chung096f36b2014-08-20 15:39:01 -07001006 if (thumbnailUpdated && isPersistable()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001007 mStackSupervisor.mService.notifyTaskPersisterLocked(task, false);
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001008 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001009 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001010 task.lastDescription = description;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001011 }
1012
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001013 void startLaunchTickingLocked() {
1014 if (ActivityManagerService.IS_USER_BUILD) {
1015 return;
1016 }
1017 if (launchTickTime == 0) {
1018 launchTickTime = SystemClock.uptimeMillis();
1019 continueLaunchTickingLocked();
1020 }
1021 }
1022
1023 boolean continueLaunchTickingLocked() {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001024 if (launchTickTime == 0) {
1025 return false;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001026 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001027
1028 final ActivityStack stack = task.stack;
1029 if (stack == null) {
1030 return false;
1031 }
1032
1033 Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG, this);
1034 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
1035 stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
1036 return true;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001037 }
1038
1039 void finishLaunchTickingLocked() {
1040 launchTickTime = 0;
Wale Ogunwale7d701172015-03-11 15:36:30 -07001041 final ActivityStack stack = task.stack;
1042 if (stack != null) {
1043 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
1044 }
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001045 }
1046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 // IApplicationToken
1048
1049 public boolean mayFreezeScreenLocked(ProcessRecord app) {
1050 // Only freeze the screen if this activity is currently attached to
1051 // an application, and that application is not blocked or unresponding.
1052 // In any other case, we can't count on getting the screen unfrozen,
1053 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -08001054 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
1058 if (mayFreezeScreenLocked(app)) {
Dianne Hackbornbe707852011-11-11 14:32:10 -08001059 service.mWindowManager.startAppFreezingScreen(appToken, configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 }
1061 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 public void stopFreezingScreenLocked(boolean force) {
1064 if (force || frozenBeforeDestroy) {
1065 frozenBeforeDestroy = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -08001066 service.mWindowManager.stopAppFreezingScreen(appToken, force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 }
1068 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001069
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001070 public void reportFullyDrawnLocked() {
1071 final long curTime = SystemClock.uptimeMillis();
1072 if (displayStartTime != 0) {
1073 reportLaunchTimeLocked(curTime);
1074 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001075 final ActivityStack stack = task.stack;
1076 if (fullyDrawnStartTime != 0 && stack != null) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001077 final long thisTime = curTime - fullyDrawnStartTime;
1078 final long totalTime = stack.mFullyDrawnStartTime != 0
1079 ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07001080 if (SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -07001081 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001082 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME,
1083 userId, System.identityHashCode(this), shortComponentName,
1084 thisTime, totalTime);
1085 StringBuilder sb = service.mStringBuilder;
1086 sb.setLength(0);
1087 sb.append("Fully drawn ");
1088 sb.append(shortComponentName);
1089 sb.append(": ");
1090 TimeUtils.formatDuration(thisTime, sb);
1091 if (thisTime != totalTime) {
1092 sb.append(" (total ");
1093 TimeUtils.formatDuration(totalTime, sb);
1094 sb.append(")");
1095 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001096 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001097 }
1098 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001099 //service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001100 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001101 stack.mFullyDrawnStartTime = 0;
1102 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001103 fullyDrawnStartTime = 0;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001104 }
1105
1106 private void reportLaunchTimeLocked(final long curTime) {
1107 final ActivityStack stack = task.stack;
Wale Ogunwale7d701172015-03-11 15:36:30 -07001108 if (stack == null) {
1109 return;
1110 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001111 final long thisTime = curTime - displayStartTime;
1112 final long totalTime = stack.mLaunchStartTime != 0
1113 ? (curTime - stack.mLaunchStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07001114 if (SHOW_ACTIVITY_START_TIME) {
Narayan Kamath7829c812015-06-08 17:39:43 +01001115 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001116 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
1117 userId, System.identityHashCode(this), shortComponentName,
1118 thisTime, totalTime);
1119 StringBuilder sb = service.mStringBuilder;
1120 sb.setLength(0);
1121 sb.append("Displayed ");
1122 sb.append(shortComponentName);
1123 sb.append(": ");
1124 TimeUtils.formatDuration(thisTime, sb);
1125 if (thisTime != totalTime) {
1126 sb.append(" (total ");
1127 TimeUtils.formatDuration(totalTime, sb);
1128 sb.append(")");
1129 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001130 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001131 }
1132 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
1133 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001134 //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001135 }
1136 displayStartTime = 0;
1137 stack.mLaunchStartTime = 0;
1138 }
1139
Wale Ogunwale7d701172015-03-11 15:36:30 -07001140 void windowsDrawnLocked() {
1141 if (displayStartTime != 0) {
1142 reportLaunchTimeLocked(SystemClock.uptimeMillis());
1143 }
1144 mStackSupervisor.sendWaitingVisibleReportLocked(this);
1145 startTime = 0;
1146 finishLaunchTickingLocked();
1147 if (task != null) {
1148 task.hasBeenVisible = true;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001149 }
1150 }
1151
Wale Ogunwale7d701172015-03-11 15:36:30 -07001152 void windowsVisibleLocked() {
1153 mStackSupervisor.reportActivityVisibleLocked(this);
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001154 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this);
Wale Ogunwale7d701172015-03-11 15:36:30 -07001155 if (!nowVisible) {
1156 nowVisible = true;
1157 lastVisibleTime = SystemClock.uptimeMillis();
1158 if (!idle) {
1159 // Instead of doing the full stop routine here, let's just hide any activities
1160 // we now can, and let them stop when the normal idle happens.
1161 mStackSupervisor.processStoppingActivitiesLocked(false);
1162 } else {
1163 // If this activity was already idle, then we now need to make sure we perform
1164 // the full stop of any activities that are waiting to do so. This is because
1165 // we won't do that while they are still waiting for this one to become visible.
1166 final int size = mStackSupervisor.mWaitingVisibleActivities.size();
1167 if (size > 0) {
1168 for (int i = 0; i < size; i++) {
1169 ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i);
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001170 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "Was waiting for visible: " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001172 mStackSupervisor.mWaitingVisibleActivities.clear();
1173 mStackSupervisor.scheduleIdleLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001176 service.scheduleAppGcsLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 }
1178 }
1179
Wale Ogunwale7d701172015-03-11 15:36:30 -07001180 ActivityRecord getWaitingHistoryRecordLocked() {
riddle_hsudb46d6b2015-04-01 18:58:07 +08001181 // First find the real culprit... if this activity is waiting for
1182 // another activity to start or has stopped, then the key dispatching
1183 // timeout should not be caused by this.
Wale Ogunwale16a62792015-04-01 11:50:31 -07001184 if (mStackSupervisor.mWaitingVisibleActivities.contains(this) || stopped) {
Craig Mautner8f2adcb2014-04-07 22:21:33 +00001185 final ActivityStack stack = mStackSupervisor.getFocusedStack();
riddle_hsudb46d6b2015-04-01 18:58:07 +08001186 // Try to use the one which is closest to top.
1187 ActivityRecord r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -08001189 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001190 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001191 if (r != null) {
1192 return r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 }
1194 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001195 return this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001196 }
1197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 /**
1199 * This method will return true if the activity is either visible, is becoming visible, is
1200 * currently pausing, or is resumed.
1201 */
1202 public boolean isInterestingToUserLocked() {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001203 return visible || nowVisible || state == ActivityState.PAUSING ||
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001204 state == ActivityState.RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001205 }
1206
1207 public void setSleeping(boolean _sleeping) {
1208 if (sleeping == _sleeping) {
1209 return;
1210 }
1211 if (app != null && app.thread != null) {
1212 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -08001213 app.thread.scheduleSleeping(appToken, _sleeping);
Craig Mautner0eea92c2013-05-16 13:35:39 -07001214 if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
1215 mStackSupervisor.mGoingToSleepActivities.add(this);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001216 }
1217 sleeping = _sleeping;
1218 } catch (RemoteException e) {
Craig Mautner0eea92c2013-05-16 13:35:39 -07001219 Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001220 }
1221 }
1222 }
Craig Mautnerf81b90872013-02-26 13:02:43 -08001223
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001224 static void activityResumedLocked(IBinder token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001225 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Wale Ogunwale0fc365c2015-05-25 19:35:42 -07001226 if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r);
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001227 r.icicle = null;
1228 r.haveState = false;
1229 }
1230
Craig Mautnerd2328952013-03-05 12:46:26 -08001231 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001232 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Craig Mautnerd2328952013-03-05 12:46:26 -08001233 if (r == null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001234 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08001235 }
1236 final TaskRecord task = r.task;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001237 final int activityNdx = task.mActivities.indexOf(r);
1238 if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001239 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08001240 }
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001241 return task.taskId;
Craig Mautnerd2328952013-03-05 12:46:26 -08001242 }
1243
1244 static ActivityRecord isInStackLocked(IBinder token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001245 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Wale Ogunwale60454db2015-01-23 16:05:07 -08001246 return (r != null) ? r.task.stack.isInStackLocked(r) : null;
Craig Mautnerd2328952013-03-05 12:46:26 -08001247 }
1248
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001249 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -08001250 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
1251 if (r != null) {
1252 return r.task.stack;
1253 }
1254 return null;
1255 }
1256
Dianne Hackborn89ad4562014-08-24 16:45:38 -07001257 final boolean isDestroyable() {
1258 if (finishing || app == null || state == ActivityState.DESTROYING
1259 || state == ActivityState.DESTROYED) {
1260 // This would be redundant.
1261 return false;
1262 }
1263 if (task == null || task.stack == null || this == task.stack.mResumedActivity
1264 || this == task.stack.mPausingActivity || !haveState || !stopped) {
1265 // We're not ready for this kind of thing.
1266 return false;
1267 }
1268 if (visible) {
1269 // The user would notice this!
1270 return false;
1271 }
1272 return true;
1273 }
1274
Winson Chung3bad5cc02014-08-19 17:44:32 -07001275 private static String createImageFilename(long createTime, int taskId) {
1276 return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime +
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001277 TaskPersister.IMAGE_EXTENSION;
1278 }
1279
Craig Mautner648f69b2014-09-18 14:16:26 -07001280 void setTaskDescription(TaskDescription _taskDescription) {
1281 Bitmap icon;
1282 if (_taskDescription.getIconFilename() == null &&
1283 (icon = _taskDescription.getIcon()) != null) {
1284 final String iconFilename = createImageFilename(createTime, task.taskId);
Suprabh Shukla23593142015-11-03 17:31:15 -08001285 final File iconFile = new File(TaskPersister.getUserImagesDir(userId), iconFilename);
1286 final String iconFilePath = iconFile.getAbsolutePath();
Suprabh Shukla09a88f52015-12-02 14:36:31 -08001287 service.mRecentTasks.saveImage(icon, iconFilePath);
Suprabh Shukla23593142015-11-03 17:31:15 -08001288 _taskDescription.setIconFilename(iconFilePath);
Craig Mautner648f69b2014-09-18 14:16:26 -07001289 }
1290 taskDescription = _taskDescription;
1291 }
1292
Amith Yamasani0af6fa72016-01-17 15:36:19 -08001293 void setVoiceSessionLocked(IVoiceInteractionSession session) {
1294 voiceSession = session;
1295 pendingVoiceInteractionStart = false;
1296 }
1297
1298 void clearVoiceSessionLocked() {
1299 voiceSession = null;
1300 pendingVoiceInteractionStart = false;
1301 }
1302
Craig Mautner21d24a22014-04-23 11:45:37 -07001303 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
1304 out.attribute(null, ATTR_ID, String.valueOf(createTime));
1305 out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
1306 if (launchedFromPackage != null) {
1307 out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage);
1308 }
1309 if (resolvedType != null) {
1310 out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType);
1311 }
1312 out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified));
1313 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Winson Chung2cb86c72014-06-25 12:03:30 -07001314
Craig Mautner21d24a22014-04-23 11:45:37 -07001315 if (taskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001316 taskDescription.saveToXml(out);
Craig Mautner21d24a22014-04-23 11:45:37 -07001317 }
1318
1319 out.startTag(null, TAG_INTENT);
1320 intent.saveToXml(out);
1321 out.endTag(null, TAG_INTENT);
1322
1323 if (isPersistable() && persistentState != null) {
1324 out.startTag(null, TAG_PERSISTABLEBUNDLE);
1325 persistentState.saveToXml(out);
1326 out.endTag(null, TAG_PERSISTABLEBUNDLE);
1327 }
1328 }
1329
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001330 static ActivityRecord restoreFromXml(XmlPullParser in,
1331 ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07001332 Intent intent = null;
1333 PersistableBundle persistentState = null;
1334 int launchedFromUid = 0;
1335 String launchedFromPackage = null;
1336 String resolvedType = null;
1337 boolean componentSpecified = false;
1338 int userId = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07001339 long createTime = -1;
1340 final int outerDepth = in.getDepth();
Winson Chung2cb86c72014-06-25 12:03:30 -07001341 TaskDescription taskDescription = new TaskDescription();
Craig Mautner21d24a22014-04-23 11:45:37 -07001342
1343 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1344 final String attrName = in.getAttributeName(attrNdx);
1345 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001346 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
Wale Ogunwale18795a22014-12-03 11:38:33 -08001347 "ActivityRecord: attribute name=" + attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001348 if (ATTR_ID.equals(attrName)) {
1349 createTime = Long.valueOf(attrValue);
1350 } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
1351 launchedFromUid = Integer.valueOf(attrValue);
1352 } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
1353 launchedFromPackage = attrValue;
1354 } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
1355 resolvedType = attrValue;
1356 } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
1357 componentSpecified = Boolean.valueOf(attrValue);
1358 } else if (ATTR_USERID.equals(attrName)) {
1359 userId = Integer.valueOf(attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001360 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1361 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001362 } else {
1363 Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName);
1364 }
1365 }
1366
1367 int event;
1368 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07001369 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001370 if (event == XmlPullParser.START_TAG) {
1371 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001372 if (TaskPersister.DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08001373 Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001374 if (TAG_INTENT.equals(name)) {
1375 intent = Intent.restoreFromXml(in);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001376 if (TaskPersister.DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08001377 Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07001378 } else if (TAG_PERSISTABLEBUNDLE.equals(name)) {
1379 persistentState = PersistableBundle.restoreFromXml(in);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001380 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
Craig Mautner21d24a22014-04-23 11:45:37 -07001381 "ActivityRecord: persistentState=" + persistentState);
1382 } else {
1383 Slog.w(TAG, "restoreActivity: unexpected name=" + name);
1384 XmlUtils.skipCurrentTag(in);
1385 }
1386 }
1387 }
1388
1389 if (intent == null) {
Craig Mautnere0129b32014-05-25 16:41:09 -07001390 throw new XmlPullParserException("restoreActivity error intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07001391 }
1392
1393 final ActivityManagerService service = stackSupervisor.mService;
1394 final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null,
Jeff Hao1b012d32014-08-20 10:35:34 -07001395 userId);
Craig Mautnere0129b32014-05-25 16:41:09 -07001396 if (aInfo == null) {
Craig Mautner77b04262014-06-27 15:22:12 -07001397 throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent +
1398 " resolvedType=" + resolvedType);
Craig Mautnere0129b32014-05-25 16:41:09 -07001399 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001400 final ActivityRecord r = new ActivityRecord(service, /*caller*/null, launchedFromUid,
1401 launchedFromPackage, intent, resolvedType, aInfo, service.getConfiguration(),
Dianne Hackbornfb81d092015-08-03 17:14:46 -07001402 null, null, 0, componentSpecified, false, stackSupervisor, null, null);
Craig Mautner21d24a22014-04-23 11:45:37 -07001403
1404 r.persistentState = persistentState;
Winson Chung2cb86c72014-06-25 12:03:30 -07001405 r.taskDescription = taskDescription;
Craig Mautner21d24a22014-04-23 11:45:37 -07001406 r.createTime = createTime;
1407
1408 return r;
1409 }
1410
1411 private static String activityTypeToString(int type) {
Craig Mautnerae7ecab2013-09-18 11:48:14 -07001412 switch (type) {
1413 case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE";
1414 case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE";
1415 case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE";
1416 default: return Integer.toString(type);
1417 }
1418 }
1419
Craig Mautnerf81b90872013-02-26 13:02:43 -08001420 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001421 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001422 if (stringName != null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001423 return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) +
Craig Mautnerf3333272013-04-22 10:55:53 -07001424 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001425 }
1426 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -08001427 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001428 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -07001429 sb.append(" u");
1430 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001431 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001432 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -08001433 stringName = sb.toString();
1434 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 }
1436}