blob: d5e40cf4de7a72d388b07f17dfb5fe862aeef7ad [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 Ogunwale22e25262016-02-01 10:32:02 -080021import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Wale Ogunwale513346d2016-01-27 10:55:01 -080022import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS;
Wale Ogunwale6cae7652015-12-26 07:36:26 -080023import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE;
Wale Ogunwaled26176f2016-01-25 20:04:04 -080024import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080025import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION;
26import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE;
27import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH;
28import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_THUMBNAILS;
29import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES;
30import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH;
31import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_THUMBNAILS;
32import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
33import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Wale Ogunwale18795a22014-12-03 11:38:33 -080034import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
35
Craig Mautner21d24a22014-04-23 11:45:37 -070036import android.app.ActivityManager.TaskDescription;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -070037import android.app.ActivityOptions;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080038import android.app.PendingIntent;
Craig Mautner05d6272ba2013-02-11 09:39:27 -080039import android.app.ResultInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.content.ComponentName;
41import android.content.Intent;
42import android.content.pm.ActivityInfo;
43import android.content.pm.ApplicationInfo;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -070044import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import android.content.res.Configuration;
46import android.graphics.Bitmap;
Dianne Hackbornd367ca82012-05-07 15:49:39 -070047import android.graphics.Rect;
Dianne Hackborn247fe742011-01-08 17:25:57 -080048import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.os.Bundle;
Dianne Hackbornbe707852011-11-11 14:32:10 -080050import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import android.os.Message;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080052import android.os.PersistableBundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import android.os.Process;
Dianne Hackborn39792d22010-08-19 18:01:52 -070054import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.os.SystemClock;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080056import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070057import android.os.UserHandle;
Amith Yamasani0af6fa72016-01-17 15:36:19 -080058import android.service.voice.IVoiceInteractionSession;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import android.util.EventLog;
60import android.util.Log;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070061import android.util.Slog;
Dianne Hackborn0dad3642010-09-09 21:25:35 -070062import android.util.TimeUtils;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -070063import android.view.AppTransitionAnimationSpec;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.view.IApplicationToken;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -080065import android.view.WindowManager;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070066
Filip Gruszczynski3d026712015-12-16 13:46:38 -080067import com.android.internal.app.ResolverActivity;
68import com.android.internal.content.ReferrerIntent;
69import com.android.internal.util.XmlUtils;
70import com.android.server.AttributeCache;
71import com.android.server.am.ActivityStack.ActivityState;
72import com.android.server.am.ActivityStackSupervisor.ActivityContainer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073
Suprabh Shukla23593142015-11-03 17:31:15 -080074import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -070075import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import java.io.PrintWriter;
77import java.lang.ref.WeakReference;
78import java.util.ArrayList;
79import java.util.HashSet;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070080import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081
Filip Gruszczynski3d026712015-12-16 13:46:38 -080082import org.xmlpull.v1.XmlPullParser;
83import org.xmlpull.v1.XmlPullParserException;
84import org.xmlpull.v1.XmlSerializer;
85
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086/**
87 * An entry in the history stack, representing an activity.
88 */
Dianne Hackbornbe707852011-11-11 14:32:10 -080089final class ActivityRecord {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080090 private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityRecord" : TAG_AM;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -070091 private static final String TAG_STATES = TAG + POSTFIX_STATES;
Wale Ogunwaleee006da2015-03-30 14:49:25 -070092 private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH;
93 private static final String TAG_THUMBNAILS = TAG + POSTFIX_THUMBNAILS;
Wale Ogunwalee23149f2015-03-06 15:39:44 -080094
Wale Ogunwale3ab9a272015-03-16 09:55:45 -070095 private static final boolean SHOW_ACTIVITY_START_TIME = true;
Winson Chung740c3ac2014-11-12 16:14:38 -080096 final public static String RECENTS_PACKAGE_NAME = "com.android.systemui.recents";
Craig Mautnerb59dcfd2013-05-06 13:12:58 -070097
Craig Mautner21d24a22014-04-23 11:45:37 -070098 private static final String ATTR_ID = "id";
99 private static final String TAG_INTENT = "intent";
100 private static final String ATTR_USERID = "user_id";
101 private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle";
102 private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700103 private static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package";
Craig Mautner21d24a22014-04-23 11:45:37 -0700104 private static final String ATTR_RESOLVEDTYPE = "resolved_type";
105 private static final String ATTR_COMPONENTSPECIFIED = "component_specified";
Dianne Hackborn337abb32014-09-24 12:44:29 -0700106 static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_";
Craig Mautner21d24a22014-04-23 11:45:37 -0700107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 final ActivityManagerService service; // owner
Dianne Hackbornbe707852011-11-11 14:32:10 -0800109 final IApplicationToken.Stub appToken; // window manager token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 final ActivityInfo info; // all about me
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700111 final ApplicationInfo appInfo; // information about activity's app
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700112 final int launchedFromUid; // always the uid who started the activity.
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800113 final String launchedFromPackage; // always the package who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -0700114 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 final Intent intent; // the original intent that generated us
116 final ComponentName realActivity; // the intent component, or target of an alias.
117 final String shortComponentName; // the short component name of the intent
118 final String resolvedType; // as per original caller;
119 final String packageName; // the package implementing intent's component
120 final String processName; // process where this component wants to run
121 final String taskAffinity; // as per ActivityInfo.taskAffinity
122 final boolean stateNotNeeded; // As per ActivityInfo.flags
Craig Mautner4addfc52013-06-25 08:05:45 -0700123 boolean fullscreen; // covers the full screen?
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800124 final boolean noDisplay; // activity is not displayed?
The Android Open Source Project4df24232009-03-05 14:34:35 -0800125 final boolean componentSpecified; // did caller specifiy an explicit component?
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700126 final boolean rootVoiceInteraction; // was this the root activity of a voice interaction?
Craig Mautner86d67a42013-05-14 10:34:38 -0700127
128 static final int APPLICATION_ACTIVITY_TYPE = 0;
129 static final int HOME_ACTIVITY_TYPE = 1;
130 static final int RECENTS_ACTIVITY_TYPE = 2;
Craig Mautner2c1faed2013-07-23 12:56:02 -0700131 int mActivityType;
Craig Mautner86d67a42013-05-14 10:34:38 -0700132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 CharSequence nonLocalizedLabel; // the label information from the package mgr.
134 int labelRes; // the label information from the package mgr.
135 int icon; // resource identifier of activity's icon.
Adam Powell04fe6eb2013-05-31 14:39:48 -0700136 int logo; // resource identifier of activity's logo.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 int theme; // resource identifier of activity's theme.
Dianne Hackborn247fe742011-01-08 17:25:57 -0800138 int realTheme; // actual theme resource we will use, never 0.
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800139 int windowFlags; // custom window flags for preview window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 TaskRecord task; // the task this is in.
Craig Mautner21d24a22014-04-23 11:45:37 -0700141 long createTime = System.currentTimeMillis();
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700142 long displayStartTime; // when we started launching this activity
143 long fullyDrawnStartTime; // when we started launching this activity
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700144 long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -0800145 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700146 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700147 long pauseTime; // last time we started pausing the activity
148 long launchTickTime; // base time for launch tick messages
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 Configuration configuration; // configuration activity was last running in
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700150 // Overridden configuration by the activity task
151 // WARNING: Reference points to {@link TaskRecord#mOverrideConfig}, so its internal state
Wale Ogunwale60454db2015-01-23 16:05:07 -0800152 // should never be altered directly.
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700153 Configuration taskConfigOverride;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700154 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700155 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 final String resultWho; // additional identifier for use by resultTo.
157 final int requestCode; // code given by requester (resultTo)
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800158 ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800160 ArrayList<ReferrerIntent> newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700161 ActivityOptions pendingOptions; // most recently given options
George Mount6ba042b2014-07-28 11:12:28 -0700162 ActivityOptions returningOptions; // options that are coming back via convertToTranslucent
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700163 AppTimeTracker appTimeTracker; // set if we are tracking the time in this app/task/activity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700165 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700166 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700167 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 Bundle icicle; // last saved activity state
Craig Mautnera0026042014-04-23 11:45:37 -0700169 PersistableBundle persistentState; // last persistently saved activity state
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 boolean frontOfTask; // is this the root activity of its task?
171 boolean launchFailed; // set if a launched failed, to abort on 2nd try
172 boolean haveState; // have we gotten the last activity state?
173 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700174 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 boolean finishing; // activity in pending finish list?
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800176 boolean deferRelaunchUntilPaused; // relaunch of activity is being deferred until pause is
177 // completed
178 boolean preserveWindowOnDeferredRelaunch; // activity windows are preserved on deferred relaunch
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 int configChangeFlags; // which config values have changed
180 boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 int launchMode; // the launch mode activity attribute.
182 boolean visible; // does this activity's window need to be shown?
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800183 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 boolean nowVisible; // is this activity's window visible?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 boolean idle; // has the activity gone idle?
186 boolean hasBeenLaunched;// has this activity ever been launched?
187 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400188 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400189 boolean forceNewConfig; // force re-create with new config next time
Dianne Hackborn07981492013-01-28 11:36:23 -0800190 int launchCount; // count of launches since last state
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800191 long lastLaunchTime; // time of last launch of this activity
Ruben Brunkdd18a0b2015-12-04 16:16:31 -0800192 boolean isVrActivity; // is the activity running in VR mode?
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800193 ArrayList<ActivityContainer> mChildContainers = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700195 String stringName; // for caching of toString().
Craig Mautnerde4ef022013-04-07 19:01:33 -0700196
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700197 private boolean inHistory; // are we in the history stack?
Craig Mautnerde4ef022013-04-07 19:01:33 -0700198 final ActivityStackSupervisor mStackSupervisor;
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800199
200 static final int STARTING_WINDOW_NOT_SHOWN = 0;
201 static final int STARTING_WINDOW_SHOWN = 1;
202 static final int STARTING_WINDOW_REMOVED = 2;
203 int mStartingWindowState = STARTING_WINDOW_NOT_SHOWN;
204
Jorim Jaggic2f262b2015-12-07 16:59:10 -0800205 boolean mUpdateTaskThumbnailWhenHidden;
Craig Mautnere0a38842013-12-16 16:14:02 -0800206 ActivityContainer mInitialActivityContainer;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700207
Craig Mautner21d24a22014-04-23 11:45:37 -0700208 TaskDescription taskDescription; // the recents information for this activity
Craig Mautnerbb742462014-07-07 15:28:55 -0700209 boolean mLaunchTaskBehind; // this activity is actively being launched with
210 // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed.
Craig Mautner2fbd7542014-03-21 09:34:07 -0700211
Filip Gruszczynski23493322015-07-29 17:02:59 -0700212 // These configurations are collected from application's resources based on size-sensitive
213 // qualifiers. For example, layout-w800dp will be added to mHorizontalSizeConfigurations as 800
214 // and drawable-sw400dp will be added to both as 400.
215 private int[] mVerticalSizeConfigurations;
216 private int[] mHorizontalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700217 private int[] mSmallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700218
Amith Yamasani0af6fa72016-01-17 15:36:19 -0800219 boolean pendingVoiceInteractionStart; // Waiting for activity-invoked voice session
220 IVoiceInteractionSession voiceSession; // Voice interaction session for this activity
221
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800222 private static String startingWindowStateToString(int state) {
223 switch (state) {
224 case STARTING_WINDOW_NOT_SHOWN:
225 return "STARTING_WINDOW_NOT_SHOWN";
226 case STARTING_WINDOW_SHOWN:
227 return "STARTING_WINDOW_SHOWN";
228 case STARTING_WINDOW_REMOVED:
229 return "STARTING_WINDOW_REMOVED";
230 default:
231 return "unknown state=" + state;
232 }
233 }
234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700236 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700237 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
238 pw.print(" processName="); pw.println(processName);
239 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Craig Mautnere11f2b72013-04-01 12:37:17 -0700240 pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800241 pw.print(" userId="); pw.println(userId);
242 pw.print(prefix); pw.print("app="); pw.println(app);
243 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700244 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
245 pw.print(" task="); pw.println(task);
246 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700247 pw.print(prefix); pw.print("realActivity=");
248 pw.println(realActivity.flattenToShortString());
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700249 if (appInfo != null) {
250 pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir);
251 if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) {
252 pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir);
253 }
254 pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800255 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700256 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
257 pw.print(" componentSpecified="); pw.print(componentSpecified);
Craig Mautner86d67a42013-05-14 10:34:38 -0700258 pw.print(" mActivityType="); pw.println(mActivityType);
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700259 if (rootVoiceInteraction) {
260 pw.print(prefix); pw.print("rootVoiceInteraction="); pw.println(rootVoiceInteraction);
261 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800262 pw.print(prefix); pw.print("compat="); pw.print(compat);
263 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
264 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
265 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Dianne Hackborne17aeb32011-04-07 15:11:57 -0700266 pw.print(prefix); pw.print("config="); pw.println(configuration);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700267 pw.print(prefix); pw.print("taskConfigOverride="); pw.println(taskConfigOverride);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700268 if (resultTo != null || resultWho != null) {
269 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
270 pw.print(" resultWho="); pw.print(resultWho);
271 pw.print(" resultCode="); pw.println(requestCode);
272 }
Craig Mautner29c58ca2014-10-14 16:17:06 -0700273 if (taskDescription != null) {
274 final String iconFilename = taskDescription.getIconFilename();
275 if (iconFilename != null || taskDescription.getLabel() != null ||
276 taskDescription.getPrimaryColor() != 0) {
277 pw.print(prefix); pw.print("taskDescription:");
278 pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename());
279 pw.print(" label=\""); pw.print(taskDescription.getLabel());
280 pw.print("\"");
281 pw.print(" color=");
282 pw.println(Integer.toHexString(taskDescription.getPrimaryColor()));
283 }
284 if (iconFilename == null && taskDescription.getIcon() != null) {
285 pw.print(prefix); pw.println("taskDescription contains Bitmap");
286 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700287 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700288 if (results != null) {
289 pw.print(prefix); pw.print("results="); pw.println(results);
290 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700291 if (pendingResults != null && pendingResults.size() > 0) {
292 pw.print(prefix); pw.println("Pending Results:");
293 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
294 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
295 pw.print(prefix); pw.print(" - ");
296 if (pir == null) {
297 pw.println("null");
298 } else {
299 pw.println(pir);
300 pir.dump(pw, prefix + " ");
301 }
302 }
303 }
304 if (newIntents != null && newIntents.size() > 0) {
305 pw.print(prefix); pw.println("Pending New Intents:");
306 for (int i=0; i<newIntents.size(); i++) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800307 Intent intent = newIntents.get(i);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700308 pw.print(prefix); pw.print(" - ");
309 if (intent == null) {
310 pw.println("null");
311 } else {
312 pw.println(intent.toShortString(false, true, false, true));
313 }
314 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700315 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700316 if (pendingOptions != null) {
317 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
318 }
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700319 if (appTimeTracker != null) {
320 appTimeTracker.dumpWithHeader(pw, prefix, false);
321 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700322 if (uriPermissions != null) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700323 uriPermissions.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700324 }
325 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800326 pw.print(" launchCount="); pw.print(launchCount);
327 pw.print(" lastLaunchTime=");
328 if (lastLaunchTime == 0) pw.print("0");
329 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
330 pw.println();
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700331 pw.print(prefix); pw.print("haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700332 pw.print(" icicle="); pw.println(icicle);
333 pw.print(prefix); pw.print("state="); pw.print(state);
334 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700335 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700336 pw.print(" finishing="); pw.println(finishing);
337 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
338 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700339 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800340 pw.print(" sleeping="); pw.print(sleeping);
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800341 pw.print(" idle="); pw.print(idle);
342 pw.print(" mStartingWindowState=");
343 pw.println(startingWindowStateToString(mStartingWindowState));
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800344 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
345 pw.print(" noDisplay="); pw.print(noDisplay);
346 pw.print(" immersive="); pw.print(immersive);
347 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800348 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400349 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700350 pw.print(prefix); pw.print("mActivityType=");
351 pw.println(activityTypeToString(mActivityType));
Ruben Brunkdd18a0b2015-12-04 16:16:31 -0800352 pw.print(prefix); pw.print("vrMode="); pw.println(isVrActivity);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700353 if (displayStartTime != 0 || startTime != 0) {
354 pw.print(prefix); pw.print("displayStartTime=");
355 if (displayStartTime == 0) pw.print("0");
356 else TimeUtils.formatDuration(displayStartTime, now, pw);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700357 pw.print(" startTime=");
358 if (startTime == 0) pw.print("0");
359 else TimeUtils.formatDuration(startTime, now, pw);
360 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700361 }
Craig Mautner8c14c152015-01-15 17:32:07 -0800362 final boolean waitingVisible = mStackSupervisor.mWaitingVisibleActivities.contains(this);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800363 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700364 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800365 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700366 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700367 if (lastVisibleTime == 0) pw.print("0");
368 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
369 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700370 }
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800371 if (deferRelaunchUntilPaused || configChangeFlags != 0) {
372 pw.print(prefix); pw.print("deferRelaunchUntilPaused="); pw.print(deferRelaunchUntilPaused);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700373 pw.print(" configChangeFlags=");
374 pw.println(Integer.toHexString(configChangeFlags));
375 }
376 if (connections != null) {
377 pw.print(prefix); pw.print("connections="); pw.println(connections);
378 }
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800379 if (info != null) {
380 pw.println(prefix + "resizeMode=" + ActivityInfo.resizeModeToString(info.resizeMode));
381 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 }
383
Filip Gruszczynski23493322015-07-29 17:02:59 -0700384 public boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) {
385 return crossesSizeThreshold(mHorizontalSizeConfigurations, firstDp, secondDp);
386 }
387
388 public boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) {
389 return crossesSizeThreshold(mVerticalSizeConfigurations, firstDp, secondDp);
390 }
391
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700392 public boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) {
393 return crossesSizeThreshold(mSmallestSizeConfigurations, firstDp, secondDp);
394 }
395
Filip Gruszczynski23493322015-07-29 17:02:59 -0700396 /**
397 * The purpose of this method is to decide whether the activity needs to be relaunched upon
398 * changing its size. In most cases the activities don't need to be relaunched, if the resize
399 * is small, all the activity content has to do is relayout itself within new bounds. There are
400 * cases however, where the activity's content would be completely changed in the new size and
401 * the full relaunch is required.
402 *
403 * The activity will report to us vertical and horizontal thresholds after which a relaunch is
404 * required. These thresholds are collected from the application resource qualifiers. For
405 * example, if application has layout-w600dp resource directory, then it needs a relaunch when
406 * we resize from width of 650dp to 550dp, as it crosses the 600dp threshold. However, if
407 * it resizes width from 620dp to 700dp, it won't be relaunched as it stays on the same side
408 * of the threshold.
409 */
410 private static boolean crossesSizeThreshold(int[] thresholds, int firstDp,
411 int secondDp) {
412 if (thresholds == null) {
413 return false;
414 }
415 for (int i = thresholds.length - 1; i >= 0; i--) {
416 final int threshold = thresholds[i];
417 if ((firstDp < threshold && secondDp >= threshold)
418 || (firstDp >= threshold && secondDp < threshold)) {
419 return true;
420 }
421 }
422 return false;
423 }
424
425 public void setSizeConfigurations(int[] horizontalSizeConfiguration,
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700426 int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700427 mHorizontalSizeConfigurations = horizontalSizeConfiguration;
428 mVerticalSizeConfigurations = verticalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700429 mSmallestSizeConfigurations = smallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700430 }
431
Filip Gruszczynskica664812015-12-04 12:43:36 -0800432 void scheduleConfigurationChanged(Configuration config, boolean reportToActivity) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800433 if (app == null || app.thread == null) {
434 return;
435 }
436 try {
437 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + this + " " +
438 "reportToActivity=" + reportToActivity + " and config: " + config);
439 app.thread.scheduleActivityConfigurationChanged(
440 appToken, new Configuration(config), reportToActivity);
441 } catch (RemoteException e) {
442 // If process died, whatever.
443 }
444 }
445
446 void scheduleMultiWindowChanged() {
447 if (task == null || task.stack == null || app == null || app.thread == null) {
448 return;
449 }
450 try {
451 // An activity is considered to be in multi-window mode if its task isn't fullscreen.
452 app.thread.scheduleMultiWindowChanged(appToken, !task.mFullscreen);
453 } catch (Exception e) {
454 // If process died, I don't care.
455 }
456 }
457
458 void schedulePictureInPictureChanged() {
459 if (task == null || task.stack == null || app == null || app.thread == null) {
460 return;
461 }
462 try {
463 app.thread.schedulePictureInPictureChanged(
464 appToken, task.stack.mStackId == PINNED_STACK_ID);
465 } catch (Exception e) {
466 // If process died, no one cares.
Filip Gruszczynskica664812015-12-04 12:43:36 -0800467 }
468 }
469
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800470 boolean isFreeform() {
471 return task != null && task.stack != null
472 && task.stack.mStackId == FREEFORM_WORKSPACE_STACK_ID;
473 }
474
Dianne Hackbornbe707852011-11-11 14:32:10 -0800475 static class Token extends IApplicationToken.Stub {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700476 private final WeakReference<ActivityRecord> weakActivity;
477 private final ActivityManagerService mService;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800478
Wale Ogunwale7d701172015-03-11 15:36:30 -0700479 Token(ActivityRecord activity, ActivityManagerService service) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800480 weakActivity = new WeakReference<>(activity);
Wale Ogunwale7d701172015-03-11 15:36:30 -0700481 mService = service;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800482 }
483
Wale Ogunwale7d701172015-03-11 15:36:30 -0700484 @Override
485 public void windowsDrawn() {
486 synchronized (mService) {
487 ActivityRecord r = tokenToActivityRecordLocked(this);
488 if (r != null) {
489 r.windowsDrawnLocked();
490 }
Dianne Hackbornbe707852011-11-11 14:32:10 -0800491 }
492 }
493
Wale Ogunwale7d701172015-03-11 15:36:30 -0700494 @Override
495 public void windowsVisible() {
496 synchronized (mService) {
497 ActivityRecord r = tokenToActivityRecordLocked(this);
498 if (r != null) {
499 r.windowsVisibleLocked();
500 }
Dianne Hackbornbe707852011-11-11 14:32:10 -0800501 }
502 }
503
Wale Ogunwale7d701172015-03-11 15:36:30 -0700504 @Override
505 public void windowsGone() {
506 synchronized (mService) {
507 ActivityRecord r = tokenToActivityRecordLocked(this);
508 if (r != null) {
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700509 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + r);
Wale Ogunwale7d701172015-03-11 15:36:30 -0700510 r.nowVisible = false;
511 return;
512 }
Dianne Hackbornbe707852011-11-11 14:32:10 -0800513 }
514 }
515
Wale Ogunwale7d701172015-03-11 15:36:30 -0700516 @Override
517 public boolean keyDispatchingTimedOut(String reason) {
518 ActivityRecord r;
519 ActivityRecord anrActivity;
520 ProcessRecord anrApp;
521 synchronized (mService) {
522 r = tokenToActivityRecordLocked(this);
523 if (r == null) {
524 return false;
525 }
526 anrActivity = r.getWaitingHistoryRecordLocked();
527 anrApp = r != null ? r.app : null;
528 }
529 return mService.inputDispatchingTimedOut(anrApp, anrActivity, r, false, reason);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800530 }
531
Wale Ogunwale7d701172015-03-11 15:36:30 -0700532 @Override
533 public long getKeyDispatchingTimeout() {
534 synchronized (mService) {
535 ActivityRecord r = tokenToActivityRecordLocked(this);
536 if (r == null) {
537 return 0;
538 }
539 r = r.getWaitingHistoryRecordLocked();
540 return ActivityManagerService.getInputDispatchingTimeoutLocked(r);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800541 }
Wale Ogunwale7d701172015-03-11 15:36:30 -0700542 }
543
544 private static final ActivityRecord tokenToActivityRecordLocked(Token token) {
545 if (token == null) {
546 return null;
547 }
548 ActivityRecord r = token.weakActivity.get();
549 if (r == null || r.task == null || r.task.stack == null) {
550 return null;
551 }
552 return r;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800553 }
554
Craig Mautnerde4ef022013-04-07 19:01:33 -0700555 @Override
Dianne Hackbornbe707852011-11-11 14:32:10 -0800556 public String toString() {
557 StringBuilder sb = new StringBuilder(128);
558 sb.append("Token{");
559 sb.append(Integer.toHexString(System.identityHashCode(this)));
560 sb.append(' ');
561 sb.append(weakActivity.get());
562 sb.append('}');
563 return sb.toString();
564 }
565 }
566
Wale Ogunwale7d701172015-03-11 15:36:30 -0700567 static ActivityRecord forTokenLocked(IBinder token) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800568 try {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700569 return Token.tokenToActivityRecordLocked((Token)token);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800570 } catch (ClassCastException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800571 Slog.w(TAG, "Bad activity token: " + token, e);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800572 return null;
573 }
574 }
575
Chong Zhang85ee6542015-10-02 13:36:38 -0700576 boolean isResolverActivity() {
577 return ResolverActivity.class.getName().equals(realActivity.getClassName());
Craig Mautnerac6f8432013-07-17 13:24:59 -0700578 }
579
Craig Mautnerd2328952013-03-05 12:46:26 -0800580 ActivityRecord(ActivityManagerService _service, ProcessRecord _caller,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800581 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700583 ActivityRecord _resultTo, String _resultWho, int _reqCode,
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700584 boolean _componentSpecified, boolean _rootVoiceInteraction,
585 ActivityStackSupervisor supervisor,
Chong Zhang280d3322015-11-03 17:27:26 -0800586 ActivityContainer container, ActivityOptions options) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 service = _service;
Wale Ogunwale7d701172015-03-11 15:36:30 -0700588 appToken = new Token(this, service);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 info = aInfo;
590 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800591 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700592 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 intent = _intent;
594 shortComponentName = _intent.getComponent().flattenToShortString();
595 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800596 componentSpecified = _componentSpecified;
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700597 rootVoiceInteraction = _rootVoiceInteraction;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 configuration = _configuration;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700599 taskConfigOverride = Configuration.EMPTY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 resultTo = _resultTo;
601 resultWho = _resultWho;
602 requestCode = _reqCode;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700603 state = ActivityState.INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 frontOfTask = false;
605 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700607 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 finishing = false;
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800609 deferRelaunchUntilPaused = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 keysPaused = false;
611 inHistory = false;
Chong Zhanga48ef662015-08-18 19:21:47 -0700612 visible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 nowVisible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 idle = false;
615 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700616 mStackSupervisor = supervisor;
Craig Mautnere0a38842013-12-16 16:14:02 -0800617 mInitialActivityContainer = container;
Craig Mautner233ceee2014-05-09 17:05:11 -0700618 if (options != null) {
Chong Zhang280d3322015-11-03 17:27:26 -0800619 pendingOptions = options;
Craig Mautnerbb742462014-07-07 15:28:55 -0700620 mLaunchTaskBehind = pendingOptions.getLaunchTaskBehind();
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700621 PendingIntent usageReport = pendingOptions.getUsageTimeReport();
622 if (usageReport != null) {
623 appTimeTracker = new AppTimeTracker(usageReport);
624 }
Craig Mautner233ceee2014-05-09 17:05:11 -0700625 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700627 // This starts out true, since the initial state of an activity
628 // is that we have everything, and we shouldn't never consider it
629 // lacking in state to be removed if it dies.
630 haveState = true;
631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 if (aInfo != null) {
Chong Zhang6bdc7e12016-02-01 14:33:53 -0800633 // If the class name in the intent doesn't match that of the target, this is
634 // probably an alias. We have to create a new ComponentName object to keep track
635 // of the real activity name, so that FLAG_ACTIVITY_CLEAR_TOP is handled properly.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 if (aInfo.targetActivity == null
Chong Zhang6bdc7e12016-02-01 14:33:53 -0800637 || (aInfo.targetActivity.equals(_intent.getComponent().getClassName())
638 && (aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE
639 || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP))) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 realActivity = _intent.getComponent();
641 } else {
Chong Zhang6bdc7e12016-02-01 14:33:53 -0800642 realActivity = new ComponentName(aInfo.packageName, aInfo.targetActivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 }
644 taskAffinity = aInfo.taskAffinity;
645 stateNotNeeded = (aInfo.flags&
646 ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700647 appInfo = aInfo.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800648 nonLocalizedLabel = aInfo.nonLocalizedLabel;
649 labelRes = aInfo.labelRes;
650 if (nonLocalizedLabel == null && labelRes == 0) {
651 ApplicationInfo app = aInfo.applicationInfo;
652 nonLocalizedLabel = app.nonLocalizedLabel;
653 labelRes = app.labelRes;
654 }
655 icon = aInfo.getIconResource();
Adam Powell04fe6eb2013-05-31 14:39:48 -0700656 logo = aInfo.getLogoResource();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657 theme = aInfo.getThemeResource();
Dianne Hackborn247fe742011-01-08 17:25:57 -0800658 realTheme = theme;
659 if (realTheme == 0) {
660 realTheme = aInfo.applicationInfo.targetSdkVersion
661 < Build.VERSION_CODES.HONEYCOMB
662 ? android.R.style.Theme
663 : android.R.style.Theme_Holo;
664 }
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800665 if ((aInfo.flags&ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
666 windowFlags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
667 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0
669 && _caller != null
670 && (aInfo.applicationInfo.uid == Process.SYSTEM_UID
671 || aInfo.applicationInfo.uid == _caller.info.uid)) {
672 processName = _caller.processName;
673 } else {
674 processName = aInfo.processName;
675 }
676
677 if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
678 intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
679 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 packageName = aInfo.applicationInfo.packageName;
682 launchMode = aInfo.launchMode;
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700685 realTheme, com.android.internal.R.styleable.Window, userId);
Dianne Hackbornb795d7c2015-07-28 17:40:06 -0700686 final boolean translucent = ent != null && (ent.array.getBoolean(
Filip Gruszczynski23958c62015-02-23 18:05:27 -0800687 com.android.internal.R.styleable.Window_windowIsTranslucent, false)
688 || (!ent.array.hasValue(
689 com.android.internal.R.styleable.Window_windowIsTranslucent)
690 && ent.array.getBoolean(
691 com.android.internal.R.styleable.Window_windowSwipeToDismiss,
Dianne Hackbornb795d7c2015-07-28 17:40:06 -0700692 false)));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 fullscreen = ent != null && !ent.array.getBoolean(
694 com.android.internal.R.styleable.Window_windowIsFloating, false)
Filip Gruszczynski23958c62015-02-23 18:05:27 -0800695 && !translucent;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800696 noDisplay = ent != null && ent.array.getBoolean(
697 com.android.internal.R.styleable.Window_windowNoDisplay, false);
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700698
Craig Mautner80259352013-09-28 12:35:25 -0700699 if ((!_componentSpecified || _launchedFromUid == Process.myUid()
Craig Mautner86d67a42013-05-14 10:34:38 -0700700 || _launchedFromUid == 0) &&
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700701 Intent.ACTION_MAIN.equals(_intent.getAction()) &&
702 _intent.hasCategory(Intent.CATEGORY_HOME) &&
703 _intent.getCategories().size() == 1 &&
704 _intent.getData() == null &&
705 _intent.getType() == null &&
Chong Zhang85ee6542015-10-02 13:36:38 -0700706 !isResolverActivity()) {
Craig Mautner86d67a42013-05-14 10:34:38 -0700707 // This sure looks like a home activity!
708 mActivityType = HOME_ACTIVITY_TYPE;
Craig Mautner80259352013-09-28 12:35:25 -0700709 } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) {
Craig Mautner86d67a42013-05-14 10:34:38 -0700710 mActivityType = RECENTS_ACTIVITY_TYPE;
711 } else {
712 mActivityType = APPLICATION_ACTIVITY_TYPE;
713 }
Daniel Sandler69a48172010-06-23 16:29:36 -0400714
715 immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0;
Ruben Brunkdd18a0b2015-12-04 16:16:31 -0800716 isVrActivity = (aInfo.flags & ActivityInfo.FLAG_ENABLE_VR_MODE) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 } else {
718 realActivity = null;
719 taskAffinity = null;
720 stateNotNeeded = false;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700721 appInfo = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 processName = null;
723 packageName = null;
724 fullscreen = true;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800725 noDisplay = false;
Craig Mautner86d67a42013-05-14 10:34:38 -0700726 mActivityType = APPLICATION_ACTIVITY_TYPE;
Daniel Sandler69a48172010-06-23 16:29:36 -0400727 immersive = false;
Ruben Brunkdd18a0b2015-12-04 16:16:31 -0800728 isVrActivity = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 }
730 }
731
Craig Mautnera228ae92014-07-09 05:44:55 -0700732 void setTask(TaskRecord newTask, TaskRecord taskToAffiliateWith) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700733 if (task != null && task.removeActivity(this) && task != newTask && task.stack != null) {
734 task.stack.removeTask(task, "setTask");
Craig Mautnerde4ef022013-04-07 19:01:33 -0700735 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700736 task = newTask;
Craig Mautnera228ae92014-07-09 05:44:55 -0700737 setTaskToAffiliateWith(taskToAffiliateWith);
738 }
739
740 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
741 if (taskToAffiliateWith != null &&
742 launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE &&
743 launchMode != ActivityInfo.LAUNCH_SINGLE_TASK) {
744 task.setTaskToAffiliateWith(taskToAffiliateWith);
745 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700746 }
747
Craig Mautner5eda9b32013-07-02 11:58:16 -0700748 boolean changeWindowTranslucency(boolean toOpaque) {
749 if (fullscreen == toOpaque) {
750 return false;
751 }
Craig Mautner4addfc52013-06-25 08:05:45 -0700752
Craig Mautner5eda9b32013-07-02 11:58:16 -0700753 // Keep track of the number of fullscreen activities in this task.
754 task.numFullscreen += toOpaque ? +1 : -1;
755
756 fullscreen = toOpaque;
757 return true;
Craig Mautner4addfc52013-06-25 08:05:45 -0700758 }
759
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700760 void putInHistory() {
761 if (!inHistory) {
762 inHistory = true;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700763 }
764 }
765
766 void takeFromHistory() {
767 if (inHistory) {
768 inHistory = false;
769 if (task != null && !finishing) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800770 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700771 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700772 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700773 }
774 }
775
776 boolean isInHistory() {
777 return inHistory;
778 }
779
Wale Ogunwale7d701172015-03-11 15:36:30 -0700780 boolean isInStackLocked() {
781 return task != null && task.stack != null && task.stack.isInStackLocked(this) != null;
782 }
783
Craig Mautner86d67a42013-05-14 10:34:38 -0700784 boolean isHomeActivity() {
785 return mActivityType == HOME_ACTIVITY_TYPE;
786 }
787
788 boolean isRecentsActivity() {
789 return mActivityType == RECENTS_ACTIVITY_TYPE;
790 }
791
792 boolean isApplicationActivity() {
793 return mActivityType == APPLICATION_ACTIVITY_TYPE;
794 }
795
Craig Mautner21d24a22014-04-23 11:45:37 -0700796 boolean isPersistable() {
Craig Mautner43e52ed2014-06-16 17:18:52 -0700797 return (info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY ||
798 info.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS) &&
799 (intent == null ||
800 (intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
Craig Mautner21d24a22014-04-23 11:45:37 -0700801 }
802
Wale Ogunwale4cea0f52015-12-25 06:30:31 -0800803 boolean isFocusable() {
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800804 return StackId.canReceiveKeys(task.stack.mStackId) || isAlwaysFocusable();
805 }
806
807 boolean isResizeable() {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800808 return !isHomeActivity() && ActivityInfo.isResizeableMode(info.resizeMode);
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800809 }
810
Wale Ogunwale513346d2016-01-27 10:55:01 -0800811 boolean isResizeableOrForced() {
812 return !isHomeActivity() && (isResizeable() || service.mForceResizableActivities);
813 }
814
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800815 boolean supportsPictureInPicture() {
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800816 return !isHomeActivity() && info.resizeMode == RESIZE_MODE_RESIZEABLE_AND_PIPABLE;
817 }
818
Wale Ogunwale513346d2016-01-27 10:55:01 -0800819 boolean canGoInDockedStack() {
820 return !isHomeActivity()
821 && (isResizeableOrForced() || info.resizeMode == RESIZE_MODE_CROP_WINDOWS);
822 }
823
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800824 boolean isAlwaysFocusable() {
825 return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0;
Wale Ogunwale4cea0f52015-12-25 06:30:31 -0800826 }
827
Wale Ogunwale7d701172015-03-11 15:36:30 -0700828 void makeFinishingLocked() {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800829 if (!finishing) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700830 if (task != null && task.stack != null
831 && this == task.stack.getVisibleBehindActivity()) {
Jose Lima34ff4922014-08-18 15:19:41 -0700832 // A finishing activity should not remain as visible in the background
833 mStackSupervisor.requestVisibleBehindLocked(this, false);
834 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800835 finishing = true;
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700836 if (stopped) {
837 clearOptionsLocked();
838 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800839 }
840 }
841
Dianne Hackborn7e269642010-08-25 19:50:20 -0700842 UriPermissionOwner getUriPermissionsLocked() {
843 if (uriPermissions == null) {
844 uriPermissions = new UriPermissionOwner(service, this);
845 }
846 return uriPermissions;
847 }
848
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700849 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 int requestCode, int resultCode,
851 Intent resultData) {
852 ActivityResult r = new ActivityResult(from, resultWho,
John Spurlock8a985d22014-02-25 09:40:05 -0500853 requestCode, resultCode, resultData);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800855 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800856 }
857 results.add(r);
858 }
859
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700860 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 int requestCode) {
862 if (results != null) {
863 for (int i=results.size()-1; i>=0; i--) {
864 ActivityResult r = (ActivityResult)results.get(i);
865 if (r.mFrom != from) continue;
866 if (r.mResultWho == null) {
867 if (resultWho != null) continue;
868 } else {
869 if (!r.mResultWho.equals(resultWho)) continue;
870 }
871 if (r.mRequestCode != requestCode) continue;
872
873 results.remove(i);
874 }
875 }
876 }
877
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800878 void addNewIntentLocked(ReferrerIntent intent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879 if (newIntents == null) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800880 newIntents = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881 }
882 newIntents.add(intent);
883 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700884
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700885 /**
886 * Deliver a new Intent to an existing activity, so that its onNewIntent()
887 * method will be called at the proper time.
888 */
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800889 final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) {
Dianne Hackborn514074f2013-02-11 10:52:46 -0800890 // The activity now gets access to the data associated with this Intent.
891 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
Nicolas Prevotc6cf95c2014-05-29 11:30:36 +0100892 intent, getUriPermissionsLocked(), userId);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700893 // We want to immediately deliver the intent to the activity if
894 // it is currently the top resumed activity... however, if the
895 // device is sleeping, then all activities are stopped, so in that
896 // case we will deliver it if this is the current top activity on its
897 // stack.
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800898 final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
Craig Mautner86d67a42013-05-14 10:34:38 -0700899 boolean unsent = true;
Wale Ogunwale7d701172015-03-11 15:36:30 -0700900 if ((state == ActivityState.RESUMED
901 || (service.isSleeping() && task.stack != null
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -0700902 && task.stack.topRunningActivityLocked() == this))
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700903 && app != null && app.thread != null) {
904 try {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800905 ArrayList<ReferrerIntent> ar = new ArrayList<>(1);
906 ar.add(rintent);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800907 app.thread.scheduleNewIntent(ar, appToken);
Craig Mautner86d67a42013-05-14 10:34:38 -0700908 unsent = false;
Dianne Hackborn39792d22010-08-19 18:01:52 -0700909 } catch (RemoteException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800910 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn39792d22010-08-19 18:01:52 -0700911 } catch (NullPointerException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800912 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700913 }
914 }
Craig Mautner86d67a42013-05-14 10:34:38 -0700915 if (unsent) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800916 addNewIntentLocked(rintent);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700917 }
918 }
919
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700920 void updateOptionsLocked(ActivityOptions options) {
921 if (options != null) {
922 if (pendingOptions != null) {
923 pendingOptions.abort();
924 }
925 pendingOptions = options;
926 }
927 }
928
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700929 void applyOptionsLocked() {
George Mount2c92c972014-03-20 09:38:23 -0700930 if (pendingOptions != null
931 && pendingOptions.getAnimationType() != ActivityOptions.ANIM_SCENE_TRANSITION) {
Michael Jurka21385cd2012-05-03 10:57:31 -0700932 final int animationType = pendingOptions.getAnimationType();
933 switch (animationType) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700934 case ActivityOptions.ANIM_CUSTOM:
935 service.mWindowManager.overridePendingAppTransition(
936 pendingOptions.getPackageName(),
937 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -0700938 pendingOptions.getCustomExitResId(),
939 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700940 break;
Chet Haase10e23ab2015-02-11 15:08:38 -0800941 case ActivityOptions.ANIM_CLIP_REVEAL:
942 service.mWindowManager.overridePendingAppTransitionClipReveal(
943 pendingOptions.getStartX(), pendingOptions.getStartY(),
944 pendingOptions.getWidth(), pendingOptions.getHeight());
945 if (intent.getSourceBounds() == null) {
946 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
947 pendingOptions.getStartY(),
948 pendingOptions.getStartX()+pendingOptions.getWidth(),
949 pendingOptions.getStartY()+pendingOptions.getHeight()));
950 }
951 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700952 case ActivityOptions.ANIM_SCALE_UP:
953 service.mWindowManager.overridePendingAppTransitionScaleUp(
954 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200955 pendingOptions.getWidth(), pendingOptions.getHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700956 if (intent.getSourceBounds() == null) {
957 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
958 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200959 pendingOptions.getStartX()+pendingOptions.getWidth(),
960 pendingOptions.getStartY()+pendingOptions.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700961 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700962 break;
Michael Jurka832cb222012-04-13 09:32:47 -0700963 case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
964 case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
965 boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700966 service.mWindowManager.overridePendingAppTransitionThumb(
967 pendingOptions.getThumbnail(),
968 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -0700969 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -0700970 scaleUp);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700971 if (intent.getSourceBounds() == null) {
972 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
973 pendingOptions.getStartY(),
974 pendingOptions.getStartX()
975 + pendingOptions.getThumbnail().getWidth(),
976 pendingOptions.getStartY()
977 + pendingOptions.getThumbnail().getHeight()));
978 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700979 break;
Winson Chunga4ccb862014-08-22 15:26:27 -0700980 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP:
981 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700982 final AppTransitionAnimationSpec[] specs = pendingOptions.getAnimSpecs();
983 if (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN
984 && specs != null) {
985 service.mWindowManager.overridePendingAppTransitionMultiThumb(
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700986 specs, pendingOptions.getOnAnimationStartListener(),
987 pendingOptions.getAnimationFinishedListener(), false);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700988 } else {
989 service.mWindowManager.overridePendingAppTransitionAspectScaledThumb(
990 pendingOptions.getThumbnail(),
991 pendingOptions.getStartX(), pendingOptions.getStartY(),
992 pendingOptions.getWidth(), pendingOptions.getHeight(),
993 pendingOptions.getOnAnimationStartListener(),
994 (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP));
995 if (intent.getSourceBounds() == null) {
996 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
997 pendingOptions.getStartY(),
998 pendingOptions.getStartX() + pendingOptions.getWidth(),
999 pendingOptions.getStartY() + pendingOptions.getHeight()));
1000 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001001 }
1002 break;
Craig Mautner233ceee2014-05-09 17:05:11 -07001003 default:
1004 Slog.e(TAG, "applyOptionsLocked: Unknown animationType=" + animationType);
1005 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001006 }
1007 pendingOptions = null;
1008 }
1009 }
1010
Adam Powellcfbe9be2013-11-06 14:58:58 -08001011 ActivityOptions getOptionsForTargetActivityLocked() {
1012 return pendingOptions != null ? pendingOptions.forTargetActivity() : null;
1013 }
1014
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001015 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001016 if (pendingOptions != null) {
1017 pendingOptions.abort();
1018 pendingOptions = null;
1019 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001020 }
1021
Dianne Hackborn9622ca42012-10-23 18:56:33 -07001022 ActivityOptions takeOptionsLocked() {
1023 ActivityOptions opts = pendingOptions;
1024 pendingOptions = null;
1025 return opts;
1026 }
1027
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001028 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -07001029 if (uriPermissions != null) {
1030 uriPermissions.removeUriPermissionsLocked();
1031 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001032 }
1033 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034
1035 void pauseKeyDispatchingLocked() {
1036 if (!keysPaused) {
1037 keysPaused = true;
Dianne Hackbornbe707852011-11-11 14:32:10 -08001038 service.mWindowManager.pauseKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 }
1040 }
1041
1042 void resumeKeyDispatchingLocked() {
1043 if (keysPaused) {
1044 keysPaused = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -08001045 service.mWindowManager.resumeKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 }
1047 }
1048
Winson Chung740c3ac2014-11-12 16:14:38 -08001049 void updateThumbnailLocked(Bitmap newThumbnail, CharSequence description) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001050 if (newThumbnail != null) {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001051 if (DEBUG_THUMBNAILS) Slog.i(TAG_THUMBNAILS,
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001052 "Setting thumbnail of " + this + " to " + newThumbnail);
Winsonc809cbb2015-11-02 12:06:15 -08001053 boolean thumbnailUpdated = task.setLastThumbnailLocked(newThumbnail);
Winson Chung096f36b2014-08-20 15:39:01 -07001054 if (thumbnailUpdated && isPersistable()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001055 mStackSupervisor.mService.notifyTaskPersisterLocked(task, false);
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001056 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001057 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001058 task.lastDescription = description;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001059 }
1060
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001061 void startLaunchTickingLocked() {
1062 if (ActivityManagerService.IS_USER_BUILD) {
1063 return;
1064 }
1065 if (launchTickTime == 0) {
1066 launchTickTime = SystemClock.uptimeMillis();
1067 continueLaunchTickingLocked();
1068 }
1069 }
1070
1071 boolean continueLaunchTickingLocked() {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001072 if (launchTickTime == 0) {
1073 return false;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001074 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001075
1076 final ActivityStack stack = task.stack;
1077 if (stack == null) {
1078 return false;
1079 }
1080
1081 Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG, this);
1082 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
1083 stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
1084 return true;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001085 }
1086
1087 void finishLaunchTickingLocked() {
1088 launchTickTime = 0;
Wale Ogunwale7d701172015-03-11 15:36:30 -07001089 final ActivityStack stack = task.stack;
1090 if (stack != null) {
1091 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
1092 }
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001093 }
1094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 // IApplicationToken
1096
1097 public boolean mayFreezeScreenLocked(ProcessRecord app) {
1098 // Only freeze the screen if this activity is currently attached to
1099 // an application, and that application is not blocked or unresponding.
1100 // In any other case, we can't count on getting the screen unfrozen,
1101 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -08001102 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
1106 if (mayFreezeScreenLocked(app)) {
Dianne Hackbornbe707852011-11-11 14:32:10 -08001107 service.mWindowManager.startAppFreezingScreen(appToken, configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 }
1109 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 public void stopFreezingScreenLocked(boolean force) {
1112 if (force || frozenBeforeDestroy) {
1113 frozenBeforeDestroy = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -08001114 service.mWindowManager.stopAppFreezingScreen(appToken, force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 }
1116 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001117
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001118 public void reportFullyDrawnLocked() {
1119 final long curTime = SystemClock.uptimeMillis();
1120 if (displayStartTime != 0) {
1121 reportLaunchTimeLocked(curTime);
1122 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001123 final ActivityStack stack = task.stack;
1124 if (fullyDrawnStartTime != 0 && stack != null) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001125 final long thisTime = curTime - fullyDrawnStartTime;
1126 final long totalTime = stack.mFullyDrawnStartTime != 0
1127 ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07001128 if (SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -07001129 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001130 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME,
1131 userId, System.identityHashCode(this), shortComponentName,
1132 thisTime, totalTime);
1133 StringBuilder sb = service.mStringBuilder;
1134 sb.setLength(0);
1135 sb.append("Fully drawn ");
1136 sb.append(shortComponentName);
1137 sb.append(": ");
1138 TimeUtils.formatDuration(thisTime, sb);
1139 if (thisTime != totalTime) {
1140 sb.append(" (total ");
1141 TimeUtils.formatDuration(totalTime, sb);
1142 sb.append(")");
1143 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001144 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001145 }
1146 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001147 //service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001148 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001149 stack.mFullyDrawnStartTime = 0;
1150 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001151 fullyDrawnStartTime = 0;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001152 }
1153
1154 private void reportLaunchTimeLocked(final long curTime) {
1155 final ActivityStack stack = task.stack;
Wale Ogunwale7d701172015-03-11 15:36:30 -07001156 if (stack == null) {
1157 return;
1158 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001159 final long thisTime = curTime - displayStartTime;
1160 final long totalTime = stack.mLaunchStartTime != 0
1161 ? (curTime - stack.mLaunchStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07001162 if (SHOW_ACTIVITY_START_TIME) {
Narayan Kamath7829c812015-06-08 17:39:43 +01001163 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001164 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
1165 userId, System.identityHashCode(this), shortComponentName,
1166 thisTime, totalTime);
1167 StringBuilder sb = service.mStringBuilder;
1168 sb.setLength(0);
1169 sb.append("Displayed ");
1170 sb.append(shortComponentName);
1171 sb.append(": ");
1172 TimeUtils.formatDuration(thisTime, sb);
1173 if (thisTime != totalTime) {
1174 sb.append(" (total ");
1175 TimeUtils.formatDuration(totalTime, sb);
1176 sb.append(")");
1177 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001178 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001179 }
1180 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
1181 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001182 //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001183 }
1184 displayStartTime = 0;
1185 stack.mLaunchStartTime = 0;
1186 }
1187
Wale Ogunwale7d701172015-03-11 15:36:30 -07001188 void windowsDrawnLocked() {
Jorim Jaggi275561a2016-02-23 10:11:02 -05001189 mStackSupervisor.mActivityMetricsLogger.notifyWindowsDrawn();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001190 if (displayStartTime != 0) {
1191 reportLaunchTimeLocked(SystemClock.uptimeMillis());
1192 }
1193 mStackSupervisor.sendWaitingVisibleReportLocked(this);
1194 startTime = 0;
1195 finishLaunchTickingLocked();
1196 if (task != null) {
1197 task.hasBeenVisible = true;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001198 }
1199 }
1200
Wale Ogunwale7d701172015-03-11 15:36:30 -07001201 void windowsVisibleLocked() {
1202 mStackSupervisor.reportActivityVisibleLocked(this);
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001203 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this);
Wale Ogunwale7d701172015-03-11 15:36:30 -07001204 if (!nowVisible) {
1205 nowVisible = true;
1206 lastVisibleTime = SystemClock.uptimeMillis();
1207 if (!idle) {
1208 // Instead of doing the full stop routine here, let's just hide any activities
1209 // we now can, and let them stop when the normal idle happens.
1210 mStackSupervisor.processStoppingActivitiesLocked(false);
1211 } else {
1212 // If this activity was already idle, then we now need to make sure we perform
1213 // the full stop of any activities that are waiting to do so. This is because
1214 // we won't do that while they are still waiting for this one to become visible.
1215 final int size = mStackSupervisor.mWaitingVisibleActivities.size();
1216 if (size > 0) {
1217 for (int i = 0; i < size; i++) {
1218 ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i);
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001219 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "Was waiting for visible: " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001220 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001221 mStackSupervisor.mWaitingVisibleActivities.clear();
1222 mStackSupervisor.scheduleIdleLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001225 service.scheduleAppGcsLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 }
1227 }
1228
Wale Ogunwale7d701172015-03-11 15:36:30 -07001229 ActivityRecord getWaitingHistoryRecordLocked() {
riddle_hsudb46d6b2015-04-01 18:58:07 +08001230 // First find the real culprit... if this activity is waiting for
1231 // another activity to start or has stopped, then the key dispatching
1232 // timeout should not be caused by this.
Wale Ogunwale16a62792015-04-01 11:50:31 -07001233 if (mStackSupervisor.mWaitingVisibleActivities.contains(this) || stopped) {
Craig Mautner8f2adcb2014-04-07 22:21:33 +00001234 final ActivityStack stack = mStackSupervisor.getFocusedStack();
riddle_hsudb46d6b2015-04-01 18:58:07 +08001235 // Try to use the one which is closest to top.
1236 ActivityRecord r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -08001238 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001240 if (r != null) {
1241 return r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 }
1243 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001244 return this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001245 }
1246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 /**
1248 * This method will return true if the activity is either visible, is becoming visible, is
1249 * currently pausing, or is resumed.
1250 */
1251 public boolean isInterestingToUserLocked() {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001252 return visible || nowVisible || state == ActivityState.PAUSING ||
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 state == ActivityState.RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001254 }
1255
1256 public void setSleeping(boolean _sleeping) {
1257 if (sleeping == _sleeping) {
1258 return;
1259 }
1260 if (app != null && app.thread != null) {
1261 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -08001262 app.thread.scheduleSleeping(appToken, _sleeping);
Craig Mautner0eea92c2013-05-16 13:35:39 -07001263 if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
1264 mStackSupervisor.mGoingToSleepActivities.add(this);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001265 }
1266 sleeping = _sleeping;
1267 } catch (RemoteException e) {
Craig Mautner0eea92c2013-05-16 13:35:39 -07001268 Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001269 }
1270 }
1271 }
Craig Mautnerf81b90872013-02-26 13:02:43 -08001272
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001273 static void activityResumedLocked(IBinder token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001274 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Wale Ogunwale0fc365c2015-05-25 19:35:42 -07001275 if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r);
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001276 r.icicle = null;
1277 r.haveState = false;
1278 }
1279
Craig Mautnerd2328952013-03-05 12:46:26 -08001280 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001281 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Craig Mautnerd2328952013-03-05 12:46:26 -08001282 if (r == null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001283 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08001284 }
1285 final TaskRecord task = r.task;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001286 final int activityNdx = task.mActivities.indexOf(r);
1287 if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001288 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08001289 }
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001290 return task.taskId;
Craig Mautnerd2328952013-03-05 12:46:26 -08001291 }
1292
1293 static ActivityRecord isInStackLocked(IBinder token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001294 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Wale Ogunwale60454db2015-01-23 16:05:07 -08001295 return (r != null) ? r.task.stack.isInStackLocked(r) : null;
Craig Mautnerd2328952013-03-05 12:46:26 -08001296 }
1297
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001298 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -08001299 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
1300 if (r != null) {
1301 return r.task.stack;
1302 }
1303 return null;
1304 }
1305
Dianne Hackborn89ad4562014-08-24 16:45:38 -07001306 final boolean isDestroyable() {
1307 if (finishing || app == null || state == ActivityState.DESTROYING
1308 || state == ActivityState.DESTROYED) {
1309 // This would be redundant.
1310 return false;
1311 }
1312 if (task == null || task.stack == null || this == task.stack.mResumedActivity
1313 || this == task.stack.mPausingActivity || !haveState || !stopped) {
1314 // We're not ready for this kind of thing.
1315 return false;
1316 }
1317 if (visible) {
1318 // The user would notice this!
1319 return false;
1320 }
1321 return true;
1322 }
1323
Winson Chung3bad5cc02014-08-19 17:44:32 -07001324 private static String createImageFilename(long createTime, int taskId) {
1325 return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime +
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001326 TaskPersister.IMAGE_EXTENSION;
1327 }
1328
Craig Mautner648f69b2014-09-18 14:16:26 -07001329 void setTaskDescription(TaskDescription _taskDescription) {
1330 Bitmap icon;
1331 if (_taskDescription.getIconFilename() == null &&
1332 (icon = _taskDescription.getIcon()) != null) {
1333 final String iconFilename = createImageFilename(createTime, task.taskId);
Suprabh Shukla23593142015-11-03 17:31:15 -08001334 final File iconFile = new File(TaskPersister.getUserImagesDir(userId), iconFilename);
1335 final String iconFilePath = iconFile.getAbsolutePath();
Suprabh Shukla09a88f52015-12-02 14:36:31 -08001336 service.mRecentTasks.saveImage(icon, iconFilePath);
Suprabh Shukla23593142015-11-03 17:31:15 -08001337 _taskDescription.setIconFilename(iconFilePath);
Craig Mautner648f69b2014-09-18 14:16:26 -07001338 }
1339 taskDescription = _taskDescription;
1340 }
1341
Amith Yamasani0af6fa72016-01-17 15:36:19 -08001342 void setVoiceSessionLocked(IVoiceInteractionSession session) {
1343 voiceSession = session;
1344 pendingVoiceInteractionStart = false;
1345 }
1346
1347 void clearVoiceSessionLocked() {
1348 voiceSession = null;
1349 pendingVoiceInteractionStart = false;
1350 }
1351
Craig Mautner21d24a22014-04-23 11:45:37 -07001352 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
1353 out.attribute(null, ATTR_ID, String.valueOf(createTime));
1354 out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
1355 if (launchedFromPackage != null) {
1356 out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage);
1357 }
1358 if (resolvedType != null) {
1359 out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType);
1360 }
1361 out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified));
1362 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Winson Chung2cb86c72014-06-25 12:03:30 -07001363
Craig Mautner21d24a22014-04-23 11:45:37 -07001364 if (taskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001365 taskDescription.saveToXml(out);
Craig Mautner21d24a22014-04-23 11:45:37 -07001366 }
1367
1368 out.startTag(null, TAG_INTENT);
1369 intent.saveToXml(out);
1370 out.endTag(null, TAG_INTENT);
1371
1372 if (isPersistable() && persistentState != null) {
1373 out.startTag(null, TAG_PERSISTABLEBUNDLE);
1374 persistentState.saveToXml(out);
1375 out.endTag(null, TAG_PERSISTABLEBUNDLE);
1376 }
1377 }
1378
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001379 static ActivityRecord restoreFromXml(XmlPullParser in,
1380 ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07001381 Intent intent = null;
1382 PersistableBundle persistentState = null;
1383 int launchedFromUid = 0;
1384 String launchedFromPackage = null;
1385 String resolvedType = null;
1386 boolean componentSpecified = false;
1387 int userId = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07001388 long createTime = -1;
1389 final int outerDepth = in.getDepth();
Winson Chung2cb86c72014-06-25 12:03:30 -07001390 TaskDescription taskDescription = new TaskDescription();
Craig Mautner21d24a22014-04-23 11:45:37 -07001391
1392 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1393 final String attrName = in.getAttributeName(attrNdx);
1394 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001395 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
Wale Ogunwale18795a22014-12-03 11:38:33 -08001396 "ActivityRecord: attribute name=" + attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001397 if (ATTR_ID.equals(attrName)) {
1398 createTime = Long.valueOf(attrValue);
1399 } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
1400 launchedFromUid = Integer.valueOf(attrValue);
1401 } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
1402 launchedFromPackage = attrValue;
1403 } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
1404 resolvedType = attrValue;
1405 } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
1406 componentSpecified = Boolean.valueOf(attrValue);
1407 } else if (ATTR_USERID.equals(attrName)) {
1408 userId = Integer.valueOf(attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001409 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1410 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001411 } else {
1412 Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName);
1413 }
1414 }
1415
1416 int event;
1417 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07001418 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001419 if (event == XmlPullParser.START_TAG) {
1420 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001421 if (TaskPersister.DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08001422 Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001423 if (TAG_INTENT.equals(name)) {
1424 intent = Intent.restoreFromXml(in);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001425 if (TaskPersister.DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08001426 Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07001427 } else if (TAG_PERSISTABLEBUNDLE.equals(name)) {
1428 persistentState = PersistableBundle.restoreFromXml(in);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001429 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
Craig Mautner21d24a22014-04-23 11:45:37 -07001430 "ActivityRecord: persistentState=" + persistentState);
1431 } else {
1432 Slog.w(TAG, "restoreActivity: unexpected name=" + name);
1433 XmlUtils.skipCurrentTag(in);
1434 }
1435 }
1436 }
1437
1438 if (intent == null) {
Craig Mautnere0129b32014-05-25 16:41:09 -07001439 throw new XmlPullParserException("restoreActivity error intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07001440 }
1441
1442 final ActivityManagerService service = stackSupervisor.mService;
1443 final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null,
Jeff Hao1b012d32014-08-20 10:35:34 -07001444 userId);
Craig Mautnere0129b32014-05-25 16:41:09 -07001445 if (aInfo == null) {
Craig Mautner77b04262014-06-27 15:22:12 -07001446 throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent +
1447 " resolvedType=" + resolvedType);
Craig Mautnere0129b32014-05-25 16:41:09 -07001448 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001449 final ActivityRecord r = new ActivityRecord(service, /*caller*/null, launchedFromUid,
1450 launchedFromPackage, intent, resolvedType, aInfo, service.getConfiguration(),
Dianne Hackbornfb81d092015-08-03 17:14:46 -07001451 null, null, 0, componentSpecified, false, stackSupervisor, null, null);
Craig Mautner21d24a22014-04-23 11:45:37 -07001452
1453 r.persistentState = persistentState;
Winson Chung2cb86c72014-06-25 12:03:30 -07001454 r.taskDescription = taskDescription;
Craig Mautner21d24a22014-04-23 11:45:37 -07001455 r.createTime = createTime;
1456
1457 return r;
1458 }
1459
1460 private static String activityTypeToString(int type) {
Craig Mautnerae7ecab2013-09-18 11:48:14 -07001461 switch (type) {
1462 case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE";
1463 case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE";
1464 case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE";
1465 default: return Integer.toString(type);
1466 }
1467 }
1468
Craig Mautnerf81b90872013-02-26 13:02:43 -08001469 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001470 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001471 if (stringName != null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001472 return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) +
Craig Mautnerf3333272013-04-22 10:55:53 -07001473 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001474 }
1475 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -08001476 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001477 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -07001478 sb.append(" u");
1479 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001480 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001481 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -08001482 stringName = sb.toString();
1483 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001484 }
1485}