blob: 589563333dfa5c3e166319c77f8a150c9550b34f [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;
Wale Ogunwale826c7062016-09-13 08:25:54 -070020import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080021import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Wale Ogunwale22e25262016-02-01 10:32:02 -080022import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Wale Ogunwale513346d2016-01-27 10:55:01 -080023import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS;
Wale Ogunwale6cae7652015-12-26 07:36:26 -080024import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE;
Jorim Jaggicd13d332016-04-27 15:40:20 -070025import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
Wale Ogunwaled26176f2016-01-25 20:04:04 -080026import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080027import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080028import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH;
29import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_THUMBNAILS;
30import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES;
31import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH;
32import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_THUMBNAILS;
33import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
34import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Wale Ogunwale18795a22014-12-03 11:38:33 -080035import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
36
Craig Mautner21d24a22014-04-23 11:45:37 -070037import android.app.ActivityManager.TaskDescription;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -070038import android.app.ActivityOptions;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080039import android.app.PendingIntent;
Craig Mautner05d6272ba2013-02-11 09:39:27 -080040import android.app.ResultInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.content.ComponentName;
42import android.content.Intent;
43import android.content.pm.ActivityInfo;
44import android.content.pm.ApplicationInfo;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -070045import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import android.content.res.Configuration;
47import android.graphics.Bitmap;
Dianne Hackbornd367ca82012-05-07 15:49:39 -070048import android.graphics.Rect;
Dianne Hackborn247fe742011-01-08 17:25:57 -080049import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.os.Bundle;
Dianne Hackbornbe707852011-11-11 14:32:10 -080051import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import android.os.Message;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080053import android.os.PersistableBundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.os.Process;
Dianne Hackborn39792d22010-08-19 18:01:52 -070055import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.os.SystemClock;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080057import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070058import android.os.UserHandle;
Amith Yamasani0af6fa72016-01-17 15:36:19 -080059import android.service.voice.IVoiceInteractionSession;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.util.EventLog;
61import android.util.Log;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070062import android.util.Slog;
Dianne Hackborn0dad3642010-09-09 21:25:35 -070063import android.util.TimeUtils;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -070064import android.view.AppTransitionAnimationSpec;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import android.view.IApplicationToken;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -080066import android.view.WindowManager;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070067
Filip Gruszczynski3d026712015-12-16 13:46:38 -080068import com.android.internal.app.ResolverActivity;
69import com.android.internal.content.ReferrerIntent;
70import com.android.internal.util.XmlUtils;
71import com.android.server.AttributeCache;
72import com.android.server.am.ActivityStack.ActivityState;
73import com.android.server.am.ActivityStackSupervisor.ActivityContainer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074
Suprabh Shukla23593142015-11-03 17:31:15 -080075import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -070076import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077import java.io.PrintWriter;
78import java.lang.ref.WeakReference;
79import java.util.ArrayList;
Todd Kennedy39bfee52016-02-24 10:28:21 -080080import java.util.Arrays;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081import java.util.HashSet;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070082import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083
Filip Gruszczynski3d026712015-12-16 13:46:38 -080084import org.xmlpull.v1.XmlPullParser;
85import org.xmlpull.v1.XmlPullParserException;
86import org.xmlpull.v1.XmlSerializer;
87
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088/**
89 * An entry in the history stack, representing an activity.
90 */
Dianne Hackbornbe707852011-11-11 14:32:10 -080091final class ActivityRecord {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080092 private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityRecord" : TAG_AM;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -070093 private static final String TAG_STATES = TAG + POSTFIX_STATES;
Wale Ogunwaleee006da2015-03-30 14:49:25 -070094 private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH;
95 private static final String TAG_THUMBNAILS = TAG + POSTFIX_THUMBNAILS;
Wale Ogunwalee23149f2015-03-06 15:39:44 -080096
Wale Ogunwale3ab9a272015-03-16 09:55:45 -070097 private static final boolean SHOW_ACTIVITY_START_TIME = true;
Winson Chung740c3ac2014-11-12 16:14:38 -080098 final public static String RECENTS_PACKAGE_NAME = "com.android.systemui.recents";
Craig Mautnerb59dcfd2013-05-06 13:12:58 -070099
Craig Mautner21d24a22014-04-23 11:45:37 -0700100 private static final String ATTR_ID = "id";
101 private static final String TAG_INTENT = "intent";
102 private static final String ATTR_USERID = "user_id";
103 private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle";
104 private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700105 private static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package";
Craig Mautner21d24a22014-04-23 11:45:37 -0700106 private static final String ATTR_RESOLVEDTYPE = "resolved_type";
107 private static final String ATTR_COMPONENTSPECIFIED = "component_specified";
Dianne Hackborn337abb32014-09-24 12:44:29 -0700108 static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_";
Craig Mautner21d24a22014-04-23 11:45:37 -0700109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 final ActivityManagerService service; // owner
Dianne Hackbornbe707852011-11-11 14:32:10 -0800111 final IApplicationToken.Stub appToken; // window manager token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 final ActivityInfo info; // all about me
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700113 final ApplicationInfo appInfo; // information about activity's app
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700114 final int launchedFromUid; // always the uid who started the activity.
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800115 final String launchedFromPackage; // always the package who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -0700116 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 final Intent intent; // the original intent that generated us
118 final ComponentName realActivity; // the intent component, or target of an alias.
119 final String shortComponentName; // the short component name of the intent
120 final String resolvedType; // as per original caller;
121 final String packageName; // the package implementing intent's component
122 final String processName; // process where this component wants to run
123 final String taskAffinity; // as per ActivityInfo.taskAffinity
124 final boolean stateNotNeeded; // As per ActivityInfo.flags
Craig Mautner4addfc52013-06-25 08:05:45 -0700125 boolean fullscreen; // covers the full screen?
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800126 final boolean noDisplay; // activity is not displayed?
Ruben Brunke24b9a62016-02-16 21:38:24 -0800127 final boolean componentSpecified; // did caller specify an explicit component?
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700128 final boolean rootVoiceInteraction; // was this the root activity of a voice interaction?
Craig Mautner86d67a42013-05-14 10:34:38 -0700129
130 static final int APPLICATION_ACTIVITY_TYPE = 0;
131 static final int HOME_ACTIVITY_TYPE = 1;
132 static final int RECENTS_ACTIVITY_TYPE = 2;
Craig Mautner2c1faed2013-07-23 12:56:02 -0700133 int mActivityType;
Craig Mautner86d67a42013-05-14 10:34:38 -0700134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 CharSequence nonLocalizedLabel; // the label information from the package mgr.
136 int labelRes; // the label information from the package mgr.
137 int icon; // resource identifier of activity's icon.
Adam Powell04fe6eb2013-05-31 14:39:48 -0700138 int logo; // resource identifier of activity's logo.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 int theme; // resource identifier of activity's theme.
Dianne Hackborn247fe742011-01-08 17:25:57 -0800140 int realTheme; // actual theme resource we will use, never 0.
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800141 int windowFlags; // custom window flags for preview window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 TaskRecord task; // the task this is in.
Craig Mautner21d24a22014-04-23 11:45:37 -0700143 long createTime = System.currentTimeMillis();
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700144 long displayStartTime; // when we started launching this activity
145 long fullyDrawnStartTime; // when we started launching this activity
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700146 long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -0800147 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700148 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700149 long pauseTime; // last time we started pausing the activity
150 long launchTickTime; // base time for launch tick messages
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 Configuration configuration; // configuration activity was last running in
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700152 // Overridden configuration by the activity task
153 // WARNING: Reference points to {@link TaskRecord#mOverrideConfig}, so its internal state
Wale Ogunwale60454db2015-01-23 16:05:07 -0800154 // should never be altered directly.
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700155 Configuration taskConfigOverride;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700156 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700157 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 final String resultWho; // additional identifier for use by resultTo.
159 final int requestCode; // code given by requester (resultTo)
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800160 ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800162 ArrayList<ReferrerIntent> newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700163 ActivityOptions pendingOptions; // most recently given options
George Mount6ba042b2014-07-28 11:12:28 -0700164 ActivityOptions returningOptions; // options that are coming back via convertToTranslucent
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700165 AppTimeTracker appTimeTracker; // set if we are tracking the time in this app/task/activity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700167 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700168 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700169 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 Bundle icicle; // last saved activity state
Craig Mautnera0026042014-04-23 11:45:37 -0700171 PersistableBundle persistentState; // last persistently saved activity state
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 boolean frontOfTask; // is this the root activity of its task?
173 boolean launchFailed; // set if a launched failed, to abort on 2nd try
174 boolean haveState; // have we gotten the last activity state?
175 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700176 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 boolean finishing; // activity in pending finish list?
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800178 boolean deferRelaunchUntilPaused; // relaunch of activity is being deferred until pause is
179 // completed
180 boolean preserveWindowOnDeferredRelaunch; // activity windows are preserved on deferred relaunch
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 int configChangeFlags; // which config values have changed
182 boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 int launchMode; // the launch mode activity attribute.
184 boolean visible; // does this activity's window need to be shown?
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800185 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 boolean nowVisible; // is this activity's window visible?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 boolean idle; // has the activity gone idle?
188 boolean hasBeenLaunched;// has this activity ever been launched?
189 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400190 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400191 boolean forceNewConfig; // force re-create with new config next time
Dianne Hackborn07981492013-01-28 11:36:23 -0800192 int launchCount; // count of launches since last state
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800193 long lastLaunchTime; // time of last launch of this activity
Ruben Brunke24b9a62016-02-16 21:38:24 -0800194 ComponentName requestedVrComponent; // the requested component for handling VR mode.
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800195 ArrayList<ActivityContainer> mChildContainers = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700197 String stringName; // for caching of toString().
Craig Mautnerde4ef022013-04-07 19:01:33 -0700198
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700199 private boolean inHistory; // are we in the history stack?
Craig Mautnerde4ef022013-04-07 19:01:33 -0700200 final ActivityStackSupervisor mStackSupervisor;
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800201
202 static final int STARTING_WINDOW_NOT_SHOWN = 0;
203 static final int STARTING_WINDOW_SHOWN = 1;
204 static final int STARTING_WINDOW_REMOVED = 2;
205 int mStartingWindowState = STARTING_WINDOW_NOT_SHOWN;
Wale Ogunwale3b232392016-05-13 15:37:13 -0700206 boolean mTaskOverlay = false; // Task is always on-top of other activities in the task.
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800207
Jorim Jaggic2f262b2015-12-07 16:59:10 -0800208 boolean mUpdateTaskThumbnailWhenHidden;
Craig Mautnere0a38842013-12-16 16:14:02 -0800209 ActivityContainer mInitialActivityContainer;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700210
Craig Mautner21d24a22014-04-23 11:45:37 -0700211 TaskDescription taskDescription; // the recents information for this activity
Craig Mautnerbb742462014-07-07 15:28:55 -0700212 boolean mLaunchTaskBehind; // this activity is actively being launched with
213 // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed.
Craig Mautner2fbd7542014-03-21 09:34:07 -0700214
Filip Gruszczynski23493322015-07-29 17:02:59 -0700215 // These configurations are collected from application's resources based on size-sensitive
216 // qualifiers. For example, layout-w800dp will be added to mHorizontalSizeConfigurations as 800
217 // and drawable-sw400dp will be added to both as 400.
218 private int[] mVerticalSizeConfigurations;
219 private int[] mHorizontalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700220 private int[] mSmallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700221
Amith Yamasani0af6fa72016-01-17 15:36:19 -0800222 boolean pendingVoiceInteractionStart; // Waiting for activity-invoked voice session
223 IVoiceInteractionSession voiceSession; // Voice interaction session for this activity
224
Robert Carrd2265122016-08-05 10:25:21 -0700225 // A hint to override the window specified rotation animation, or -1
226 // to use the window specified value. We use this so that
227 // we can select the right animation in the cases of starting
228 // windows, where the app hasn't had time to set a value
229 // on the window.
230 int mRotationAnimationHint = -1;
Robert Carrfd10cd12016-06-29 16:41:50 -0700231
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800232 private static String startingWindowStateToString(int state) {
233 switch (state) {
234 case STARTING_WINDOW_NOT_SHOWN:
235 return "STARTING_WINDOW_NOT_SHOWN";
236 case STARTING_WINDOW_SHOWN:
237 return "STARTING_WINDOW_SHOWN";
238 case STARTING_WINDOW_REMOVED:
239 return "STARTING_WINDOW_REMOVED";
240 default:
241 return "unknown state=" + state;
242 }
243 }
244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700246 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700247 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
248 pw.print(" processName="); pw.println(processName);
249 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Craig Mautnere11f2b72013-04-01 12:37:17 -0700250 pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800251 pw.print(" userId="); pw.println(userId);
252 pw.print(prefix); pw.print("app="); pw.println(app);
253 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700254 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
255 pw.print(" task="); pw.println(task);
256 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700257 pw.print(prefix); pw.print("realActivity=");
258 pw.println(realActivity.flattenToShortString());
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700259 if (appInfo != null) {
260 pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir);
261 if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) {
262 pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir);
263 }
264 pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir);
Todd Kennedy39bfee52016-02-24 10:28:21 -0800265 if (appInfo.splitSourceDirs != null) {
266 pw.print(prefix); pw.print("splitDir=");
267 pw.println(Arrays.toString(appInfo.splitSourceDirs));
268 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800269 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700270 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
271 pw.print(" componentSpecified="); pw.print(componentSpecified);
Craig Mautner86d67a42013-05-14 10:34:38 -0700272 pw.print(" mActivityType="); pw.println(mActivityType);
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700273 if (rootVoiceInteraction) {
274 pw.print(prefix); pw.print("rootVoiceInteraction="); pw.println(rootVoiceInteraction);
275 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800276 pw.print(prefix); pw.print("compat="); pw.print(compat);
277 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
278 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
279 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Dianne Hackborne17aeb32011-04-07 15:11:57 -0700280 pw.print(prefix); pw.print("config="); pw.println(configuration);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700281 pw.print(prefix); pw.print("taskConfigOverride="); pw.println(taskConfigOverride);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700282 if (resultTo != null || resultWho != null) {
283 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
284 pw.print(" resultWho="); pw.print(resultWho);
285 pw.print(" resultCode="); pw.println(requestCode);
286 }
Craig Mautner29c58ca2014-10-14 16:17:06 -0700287 if (taskDescription != null) {
288 final String iconFilename = taskDescription.getIconFilename();
289 if (iconFilename != null || taskDescription.getLabel() != null ||
290 taskDescription.getPrimaryColor() != 0) {
291 pw.print(prefix); pw.print("taskDescription:");
292 pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename());
293 pw.print(" label=\""); pw.print(taskDescription.getLabel());
294 pw.print("\"");
295 pw.print(" color=");
296 pw.println(Integer.toHexString(taskDescription.getPrimaryColor()));
297 }
298 if (iconFilename == null && taskDescription.getIcon() != null) {
299 pw.print(prefix); pw.println("taskDescription contains Bitmap");
300 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700301 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700302 if (results != null) {
303 pw.print(prefix); pw.print("results="); pw.println(results);
304 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700305 if (pendingResults != null && pendingResults.size() > 0) {
306 pw.print(prefix); pw.println("Pending Results:");
307 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
308 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
309 pw.print(prefix); pw.print(" - ");
310 if (pir == null) {
311 pw.println("null");
312 } else {
313 pw.println(pir);
314 pir.dump(pw, prefix + " ");
315 }
316 }
317 }
318 if (newIntents != null && newIntents.size() > 0) {
319 pw.print(prefix); pw.println("Pending New Intents:");
320 for (int i=0; i<newIntents.size(); i++) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800321 Intent intent = newIntents.get(i);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700322 pw.print(prefix); pw.print(" - ");
323 if (intent == null) {
324 pw.println("null");
325 } else {
326 pw.println(intent.toShortString(false, true, false, true));
327 }
328 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700329 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700330 if (pendingOptions != null) {
331 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
332 }
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700333 if (appTimeTracker != null) {
334 appTimeTracker.dumpWithHeader(pw, prefix, false);
335 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700336 if (uriPermissions != null) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700337 uriPermissions.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700338 }
339 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800340 pw.print(" launchCount="); pw.print(launchCount);
341 pw.print(" lastLaunchTime=");
342 if (lastLaunchTime == 0) pw.print("0");
343 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
344 pw.println();
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700345 pw.print(prefix); pw.print("haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700346 pw.print(" icicle="); pw.println(icicle);
347 pw.print(prefix); pw.print("state="); pw.print(state);
348 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700349 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700350 pw.print(" finishing="); pw.println(finishing);
351 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
352 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700353 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800354 pw.print(" sleeping="); pw.print(sleeping);
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800355 pw.print(" idle="); pw.print(idle);
356 pw.print(" mStartingWindowState=");
357 pw.println(startingWindowStateToString(mStartingWindowState));
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800358 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
359 pw.print(" noDisplay="); pw.print(noDisplay);
360 pw.print(" immersive="); pw.print(immersive);
361 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800362 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400363 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700364 pw.print(prefix); pw.print("mActivityType=");
365 pw.println(activityTypeToString(mActivityType));
Ruben Brunke24b9a62016-02-16 21:38:24 -0800366 if (requestedVrComponent != null) {
367 pw.print(prefix);
368 pw.print("requestedVrComponent=");
369 pw.println(requestedVrComponent);
370 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700371 if (displayStartTime != 0 || startTime != 0) {
372 pw.print(prefix); pw.print("displayStartTime=");
373 if (displayStartTime == 0) pw.print("0");
374 else TimeUtils.formatDuration(displayStartTime, now, pw);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700375 pw.print(" startTime=");
376 if (startTime == 0) pw.print("0");
377 else TimeUtils.formatDuration(startTime, now, pw);
378 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700379 }
Craig Mautner8c14c152015-01-15 17:32:07 -0800380 final boolean waitingVisible = mStackSupervisor.mWaitingVisibleActivities.contains(this);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800381 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700382 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800383 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700384 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700385 if (lastVisibleTime == 0) pw.print("0");
386 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
387 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700388 }
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800389 if (deferRelaunchUntilPaused || configChangeFlags != 0) {
390 pw.print(prefix); pw.print("deferRelaunchUntilPaused="); pw.print(deferRelaunchUntilPaused);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700391 pw.print(" configChangeFlags=");
392 pw.println(Integer.toHexString(configChangeFlags));
393 }
394 if (connections != null) {
395 pw.print(prefix); pw.print("connections="); pw.println(connections);
396 }
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800397 if (info != null) {
398 pw.println(prefix + "resizeMode=" + ActivityInfo.resizeModeToString(info.resizeMode));
399 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 }
401
Filip Gruszczynski23493322015-07-29 17:02:59 -0700402 public boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) {
403 return crossesSizeThreshold(mHorizontalSizeConfigurations, firstDp, secondDp);
404 }
405
406 public boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) {
407 return crossesSizeThreshold(mVerticalSizeConfigurations, firstDp, secondDp);
408 }
409
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700410 public boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) {
411 return crossesSizeThreshold(mSmallestSizeConfigurations, firstDp, secondDp);
412 }
413
Filip Gruszczynski23493322015-07-29 17:02:59 -0700414 /**
415 * The purpose of this method is to decide whether the activity needs to be relaunched upon
416 * changing its size. In most cases the activities don't need to be relaunched, if the resize
417 * is small, all the activity content has to do is relayout itself within new bounds. There are
418 * cases however, where the activity's content would be completely changed in the new size and
419 * the full relaunch is required.
420 *
421 * The activity will report to us vertical and horizontal thresholds after which a relaunch is
422 * required. These thresholds are collected from the application resource qualifiers. For
423 * example, if application has layout-w600dp resource directory, then it needs a relaunch when
424 * we resize from width of 650dp to 550dp, as it crosses the 600dp threshold. However, if
425 * it resizes width from 620dp to 700dp, it won't be relaunched as it stays on the same side
426 * of the threshold.
427 */
428 private static boolean crossesSizeThreshold(int[] thresholds, int firstDp,
429 int secondDp) {
430 if (thresholds == null) {
431 return false;
432 }
433 for (int i = thresholds.length - 1; i >= 0; i--) {
434 final int threshold = thresholds[i];
435 if ((firstDp < threshold && secondDp >= threshold)
436 || (firstDp >= threshold && secondDp < threshold)) {
437 return true;
438 }
439 }
440 return false;
441 }
442
443 public void setSizeConfigurations(int[] horizontalSizeConfiguration,
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700444 int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700445 mHorizontalSizeConfigurations = horizontalSizeConfiguration;
446 mVerticalSizeConfigurations = verticalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700447 mSmallestSizeConfigurations = smallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700448 }
449
Filip Gruszczynskica664812015-12-04 12:43:36 -0800450 void scheduleConfigurationChanged(Configuration config, boolean reportToActivity) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800451 if (app == null || app.thread == null) {
452 return;
453 }
454 try {
Chong Zhang6be533e2016-06-17 16:24:21 -0700455 // Make sure fontScale is always equal to global. For fullscreen apps, config is
456 // the shared EMPTY config, which has default fontScale of 1.0. We don't want it
457 // to be applied as an override config.
458 Configuration overrideConfig = new Configuration(config);
459 overrideConfig.fontScale = service.mConfiguration.fontScale;
460
Wale Ogunwale22e25262016-02-01 10:32:02 -0800461 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + this + " " +
Chong Zhang6be533e2016-06-17 16:24:21 -0700462 "reportToActivity=" + reportToActivity + " and config: " + overrideConfig);
463
Wale Ogunwale22e25262016-02-01 10:32:02 -0800464 app.thread.scheduleActivityConfigurationChanged(
Chong Zhang6be533e2016-06-17 16:24:21 -0700465 appToken, overrideConfig, reportToActivity);
Wale Ogunwale22e25262016-02-01 10:32:02 -0800466 } catch (RemoteException e) {
467 // If process died, whatever.
468 }
469 }
470
Andrii Kulian933076d2016-03-29 17:04:42 -0700471 void scheduleMultiWindowModeChanged() {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800472 if (task == null || task.stack == null || app == null || app.thread == null) {
473 return;
474 }
475 try {
476 // An activity is considered to be in multi-window mode if its task isn't fullscreen.
Andrii Kulian933076d2016-03-29 17:04:42 -0700477 app.thread.scheduleMultiWindowModeChanged(appToken, !task.mFullscreen);
Wale Ogunwale22e25262016-02-01 10:32:02 -0800478 } catch (Exception e) {
479 // If process died, I don't care.
480 }
481 }
482
Andrii Kulian933076d2016-03-29 17:04:42 -0700483 void schedulePictureInPictureModeChanged() {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800484 if (task == null || task.stack == null || app == null || app.thread == null) {
485 return;
486 }
487 try {
Andrii Kulian933076d2016-03-29 17:04:42 -0700488 app.thread.schedulePictureInPictureModeChanged(
Wale Ogunwale22e25262016-02-01 10:32:02 -0800489 appToken, task.stack.mStackId == PINNED_STACK_ID);
490 } catch (Exception e) {
491 // If process died, no one cares.
Filip Gruszczynskica664812015-12-04 12:43:36 -0800492 }
493 }
494
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800495 boolean isFreeform() {
496 return task != null && task.stack != null
497 && task.stack.mStackId == FREEFORM_WORKSPACE_STACK_ID;
498 }
499
Dianne Hackbornbe707852011-11-11 14:32:10 -0800500 static class Token extends IApplicationToken.Stub {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700501 private final WeakReference<ActivityRecord> weakActivity;
502 private final ActivityManagerService mService;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800503
Wale Ogunwale7d701172015-03-11 15:36:30 -0700504 Token(ActivityRecord activity, ActivityManagerService service) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800505 weakActivity = new WeakReference<>(activity);
Wale Ogunwale7d701172015-03-11 15:36:30 -0700506 mService = service;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800507 }
508
Wale Ogunwale7d701172015-03-11 15:36:30 -0700509 @Override
510 public void windowsDrawn() {
511 synchronized (mService) {
512 ActivityRecord r = tokenToActivityRecordLocked(this);
513 if (r != null) {
514 r.windowsDrawnLocked();
515 }
Dianne Hackbornbe707852011-11-11 14:32:10 -0800516 }
517 }
518
Wale Ogunwale7d701172015-03-11 15:36:30 -0700519 @Override
520 public void windowsVisible() {
521 synchronized (mService) {
522 ActivityRecord r = tokenToActivityRecordLocked(this);
523 if (r != null) {
524 r.windowsVisibleLocked();
525 }
Dianne Hackbornbe707852011-11-11 14:32:10 -0800526 }
527 }
528
Wale Ogunwale7d701172015-03-11 15:36:30 -0700529 @Override
530 public void windowsGone() {
531 synchronized (mService) {
532 ActivityRecord r = tokenToActivityRecordLocked(this);
533 if (r != null) {
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700534 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + r);
Wale Ogunwale7d701172015-03-11 15:36:30 -0700535 r.nowVisible = false;
536 return;
537 }
Dianne Hackbornbe707852011-11-11 14:32:10 -0800538 }
539 }
540
Wale Ogunwale7d701172015-03-11 15:36:30 -0700541 @Override
542 public boolean keyDispatchingTimedOut(String reason) {
543 ActivityRecord r;
544 ActivityRecord anrActivity;
545 ProcessRecord anrApp;
546 synchronized (mService) {
547 r = tokenToActivityRecordLocked(this);
548 if (r == null) {
549 return false;
550 }
551 anrActivity = r.getWaitingHistoryRecordLocked();
552 anrApp = r != null ? r.app : null;
553 }
554 return mService.inputDispatchingTimedOut(anrApp, anrActivity, r, false, reason);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800555 }
556
Wale Ogunwale7d701172015-03-11 15:36:30 -0700557 @Override
558 public long getKeyDispatchingTimeout() {
559 synchronized (mService) {
560 ActivityRecord r = tokenToActivityRecordLocked(this);
561 if (r == null) {
562 return 0;
563 }
564 r = r.getWaitingHistoryRecordLocked();
565 return ActivityManagerService.getInputDispatchingTimeoutLocked(r);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800566 }
Wale Ogunwale7d701172015-03-11 15:36:30 -0700567 }
568
569 private static final ActivityRecord tokenToActivityRecordLocked(Token token) {
570 if (token == null) {
571 return null;
572 }
573 ActivityRecord r = token.weakActivity.get();
574 if (r == null || r.task == null || r.task.stack == null) {
575 return null;
576 }
577 return r;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800578 }
579
Craig Mautnerde4ef022013-04-07 19:01:33 -0700580 @Override
Dianne Hackbornbe707852011-11-11 14:32:10 -0800581 public String toString() {
582 StringBuilder sb = new StringBuilder(128);
583 sb.append("Token{");
584 sb.append(Integer.toHexString(System.identityHashCode(this)));
585 sb.append(' ');
586 sb.append(weakActivity.get());
587 sb.append('}');
588 return sb.toString();
589 }
590 }
591
Wale Ogunwale7d701172015-03-11 15:36:30 -0700592 static ActivityRecord forTokenLocked(IBinder token) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800593 try {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700594 return Token.tokenToActivityRecordLocked((Token)token);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800595 } catch (ClassCastException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800596 Slog.w(TAG, "Bad activity token: " + token, e);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800597 return null;
598 }
599 }
600
Chong Zhang85ee6542015-10-02 13:36:38 -0700601 boolean isResolverActivity() {
602 return ResolverActivity.class.getName().equals(realActivity.getClassName());
Craig Mautnerac6f8432013-07-17 13:24:59 -0700603 }
604
Craig Mautnerd2328952013-03-05 12:46:26 -0800605 ActivityRecord(ActivityManagerService _service, ProcessRecord _caller,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800606 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700608 ActivityRecord _resultTo, String _resultWho, int _reqCode,
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700609 boolean _componentSpecified, boolean _rootVoiceInteraction,
610 ActivityStackSupervisor supervisor,
Wale Ogunwale1affbbc2016-05-01 09:03:52 -0700611 ActivityContainer container, ActivityOptions options, ActivityRecord sourceRecord) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 service = _service;
Wale Ogunwale7d701172015-03-11 15:36:30 -0700613 appToken = new Token(this, service);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 info = aInfo;
615 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800616 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700617 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 intent = _intent;
619 shortComponentName = _intent.getComponent().flattenToShortString();
620 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800621 componentSpecified = _componentSpecified;
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700622 rootVoiceInteraction = _rootVoiceInteraction;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 configuration = _configuration;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700624 taskConfigOverride = Configuration.EMPTY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 resultTo = _resultTo;
626 resultWho = _resultWho;
627 requestCode = _reqCode;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700628 state = ActivityState.INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 frontOfTask = false;
630 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700632 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 finishing = false;
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800634 deferRelaunchUntilPaused = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 keysPaused = false;
636 inHistory = false;
Chong Zhanga48ef662015-08-18 19:21:47 -0700637 visible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 nowVisible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 idle = false;
640 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700641 mStackSupervisor = supervisor;
Craig Mautnere0a38842013-12-16 16:14:02 -0800642 mInitialActivityContainer = container;
Craig Mautner233ceee2014-05-09 17:05:11 -0700643 if (options != null) {
Chong Zhang280d3322015-11-03 17:27:26 -0800644 pendingOptions = options;
Craig Mautnerbb742462014-07-07 15:28:55 -0700645 mLaunchTaskBehind = pendingOptions.getLaunchTaskBehind();
Robert Carrfd10cd12016-06-29 16:41:50 -0700646 mRotationAnimationHint = pendingOptions.getRotationAnimationHint();
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700647 PendingIntent usageReport = pendingOptions.getUsageTimeReport();
648 if (usageReport != null) {
649 appTimeTracker = new AppTimeTracker(usageReport);
650 }
Craig Mautner233ceee2014-05-09 17:05:11 -0700651 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700653 // This starts out true, since the initial state of an activity
654 // is that we have everything, and we shouldn't never consider it
655 // lacking in state to be removed if it dies.
656 haveState = true;
657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 if (aInfo != null) {
Chong Zhang6bdc7e12016-02-01 14:33:53 -0800659 // If the class name in the intent doesn't match that of the target, this is
660 // probably an alias. We have to create a new ComponentName object to keep track
661 // of the real activity name, so that FLAG_ACTIVITY_CLEAR_TOP is handled properly.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 if (aInfo.targetActivity == null
Chong Zhang6bdc7e12016-02-01 14:33:53 -0800663 || (aInfo.targetActivity.equals(_intent.getComponent().getClassName())
664 && (aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE
665 || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP))) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 realActivity = _intent.getComponent();
667 } else {
Chong Zhang6bdc7e12016-02-01 14:33:53 -0800668 realActivity = new ComponentName(aInfo.packageName, aInfo.targetActivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 }
670 taskAffinity = aInfo.taskAffinity;
671 stateNotNeeded = (aInfo.flags&
672 ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700673 appInfo = aInfo.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 nonLocalizedLabel = aInfo.nonLocalizedLabel;
675 labelRes = aInfo.labelRes;
676 if (nonLocalizedLabel == null && labelRes == 0) {
677 ApplicationInfo app = aInfo.applicationInfo;
678 nonLocalizedLabel = app.nonLocalizedLabel;
679 labelRes = app.labelRes;
680 }
681 icon = aInfo.getIconResource();
Adam Powell04fe6eb2013-05-31 14:39:48 -0700682 logo = aInfo.getLogoResource();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 theme = aInfo.getThemeResource();
Dianne Hackborn247fe742011-01-08 17:25:57 -0800684 realTheme = theme;
685 if (realTheme == 0) {
686 realTheme = aInfo.applicationInfo.targetSdkVersion
687 < Build.VERSION_CODES.HONEYCOMB
688 ? android.R.style.Theme
689 : android.R.style.Theme_Holo;
690 }
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800691 if ((aInfo.flags&ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
692 windowFlags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
693 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0
695 && _caller != null
696 && (aInfo.applicationInfo.uid == Process.SYSTEM_UID
697 || aInfo.applicationInfo.uid == _caller.info.uid)) {
698 processName = _caller.processName;
699 } else {
700 processName = aInfo.processName;
701 }
702
703 if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
704 intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
705 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 packageName = aInfo.applicationInfo.packageName;
708 launchMode = aInfo.launchMode;
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700711 realTheme, com.android.internal.R.styleable.Window, userId);
Dianne Hackbornb795d7c2015-07-28 17:40:06 -0700712 final boolean translucent = ent != null && (ent.array.getBoolean(
Filip Gruszczynski23958c62015-02-23 18:05:27 -0800713 com.android.internal.R.styleable.Window_windowIsTranslucent, false)
714 || (!ent.array.hasValue(
715 com.android.internal.R.styleable.Window_windowIsTranslucent)
716 && ent.array.getBoolean(
717 com.android.internal.R.styleable.Window_windowSwipeToDismiss,
Dianne Hackbornb795d7c2015-07-28 17:40:06 -0700718 false)));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719 fullscreen = ent != null && !ent.array.getBoolean(
720 com.android.internal.R.styleable.Window_windowIsFloating, false)
Filip Gruszczynski23958c62015-02-23 18:05:27 -0800721 && !translucent;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800722 noDisplay = ent != null && ent.array.getBoolean(
723 com.android.internal.R.styleable.Window_windowNoDisplay, false);
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700724
Wale Ogunwale1affbbc2016-05-01 09:03:52 -0700725 setActivityType(_componentSpecified, _launchedFromUid, _intent, sourceRecord);
Daniel Sandler69a48172010-06-23 16:29:36 -0400726
727 immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0;
Ruben Brunkf56c9f42016-04-22 18:20:55 -0700728
729 requestedVrComponent = (aInfo.requestedVrComponent == null) ?
730 null : ComponentName.unflattenFromString(aInfo.requestedVrComponent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 } else {
732 realActivity = null;
733 taskAffinity = null;
734 stateNotNeeded = false;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700735 appInfo = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 processName = null;
737 packageName = null;
738 fullscreen = true;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800739 noDisplay = false;
Craig Mautner86d67a42013-05-14 10:34:38 -0700740 mActivityType = APPLICATION_ACTIVITY_TYPE;
Daniel Sandler69a48172010-06-23 16:29:36 -0400741 immersive = false;
Ruben Brunkf56c9f42016-04-22 18:20:55 -0700742 requestedVrComponent = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 }
744 }
745
Wale Ogunwale1affbbc2016-05-01 09:03:52 -0700746 private boolean isHomeIntent(Intent intent) {
747 return Intent.ACTION_MAIN.equals(intent.getAction())
748 && intent.hasCategory(Intent.CATEGORY_HOME)
749 && intent.getCategories().size() == 1
750 && intent.getData() == null
751 && intent.getType() == null;
752 }
753
Chong Zhang813be132016-08-25 12:12:33 -0700754 static boolean isMainIntent(Intent intent) {
755 return Intent.ACTION_MAIN.equals(intent.getAction())
756 && intent.hasCategory(Intent.CATEGORY_LAUNCHER)
757 && intent.getCategories().size() == 1
758 && intent.getData() == null
759 && intent.getType() == null;
760 }
761
Wale Ogunwale1affbbc2016-05-01 09:03:52 -0700762 private boolean canLaunchHomeActivity(int uid, ActivityRecord sourceRecord) {
763 if (uid == Process.myUid() || uid == 0) {
764 // System process can launch home activity.
765 return true;
766 }
767 // Resolver activity can launch home activity.
768 return sourceRecord != null && sourceRecord.isResolverActivity();
769 }
770
771 private void setActivityType(boolean componentSpecified,
772 int launchedFromUid, Intent intent, ActivityRecord sourceRecord) {
773 if ((!componentSpecified || canLaunchHomeActivity(launchedFromUid, sourceRecord))
774 && isHomeIntent(intent) && !isResolverActivity()) {
775 // This sure looks like a home activity!
776 mActivityType = HOME_ACTIVITY_TYPE;
777 } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) {
778 mActivityType = RECENTS_ACTIVITY_TYPE;
779 } else {
780 mActivityType = APPLICATION_ACTIVITY_TYPE;
781 }
782 }
783
Craig Mautnera228ae92014-07-09 05:44:55 -0700784 void setTask(TaskRecord newTask, TaskRecord taskToAffiliateWith) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700785 if (task != null && task.removeActivity(this) && task != newTask && task.stack != null) {
786 task.stack.removeTask(task, "setTask");
Craig Mautnerde4ef022013-04-07 19:01:33 -0700787 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700788 task = newTask;
Craig Mautnera228ae92014-07-09 05:44:55 -0700789 setTaskToAffiliateWith(taskToAffiliateWith);
790 }
791
792 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
793 if (taskToAffiliateWith != null &&
794 launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE &&
795 launchMode != ActivityInfo.LAUNCH_SINGLE_TASK) {
796 task.setTaskToAffiliateWith(taskToAffiliateWith);
797 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700798 }
799
Craig Mautner5eda9b32013-07-02 11:58:16 -0700800 boolean changeWindowTranslucency(boolean toOpaque) {
801 if (fullscreen == toOpaque) {
802 return false;
803 }
Craig Mautner4addfc52013-06-25 08:05:45 -0700804
Craig Mautner5eda9b32013-07-02 11:58:16 -0700805 // Keep track of the number of fullscreen activities in this task.
806 task.numFullscreen += toOpaque ? +1 : -1;
807
808 fullscreen = toOpaque;
809 return true;
Craig Mautner4addfc52013-06-25 08:05:45 -0700810 }
811
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700812 void putInHistory() {
813 if (!inHistory) {
814 inHistory = true;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700815 }
816 }
817
818 void takeFromHistory() {
819 if (inHistory) {
820 inHistory = false;
821 if (task != null && !finishing) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800822 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700823 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700824 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700825 }
826 }
827
828 boolean isInHistory() {
829 return inHistory;
830 }
831
Wale Ogunwale7d701172015-03-11 15:36:30 -0700832 boolean isInStackLocked() {
833 return task != null && task.stack != null && task.stack.isInStackLocked(this) != null;
834 }
835
Craig Mautner86d67a42013-05-14 10:34:38 -0700836 boolean isHomeActivity() {
837 return mActivityType == HOME_ACTIVITY_TYPE;
838 }
839
840 boolean isRecentsActivity() {
841 return mActivityType == RECENTS_ACTIVITY_TYPE;
842 }
843
844 boolean isApplicationActivity() {
845 return mActivityType == APPLICATION_ACTIVITY_TYPE;
846 }
847
Craig Mautner21d24a22014-04-23 11:45:37 -0700848 boolean isPersistable() {
Craig Mautner43e52ed2014-06-16 17:18:52 -0700849 return (info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY ||
850 info.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS) &&
851 (intent == null ||
852 (intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
Craig Mautner21d24a22014-04-23 11:45:37 -0700853 }
854
Wale Ogunwale4cea0f52015-12-25 06:30:31 -0800855 boolean isFocusable() {
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800856 return StackId.canReceiveKeys(task.stack.mStackId) || isAlwaysFocusable();
857 }
858
859 boolean isResizeable() {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800860 return !isHomeActivity() && ActivityInfo.isResizeableMode(info.resizeMode);
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800861 }
862
Wale Ogunwale513346d2016-01-27 10:55:01 -0800863 boolean isResizeableOrForced() {
864 return !isHomeActivity() && (isResizeable() || service.mForceResizableActivities);
865 }
866
Jorim Jaggicd13d332016-04-27 15:40:20 -0700867 boolean isNonResizableOrForced() {
868 return !isHomeActivity() && info.resizeMode != RESIZE_MODE_RESIZEABLE
869 && info.resizeMode != RESIZE_MODE_RESIZEABLE_AND_PIPABLE;
870 }
871
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800872 boolean supportsPictureInPicture() {
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800873 return !isHomeActivity() && info.resizeMode == RESIZE_MODE_RESIZEABLE_AND_PIPABLE;
874 }
875
Wale Ogunwale513346d2016-01-27 10:55:01 -0800876 boolean canGoInDockedStack() {
877 return !isHomeActivity()
878 && (isResizeableOrForced() || info.resizeMode == RESIZE_MODE_CROP_WINDOWS);
879 }
880
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800881 boolean isAlwaysFocusable() {
882 return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0;
Wale Ogunwale4cea0f52015-12-25 06:30:31 -0800883 }
884
Wale Ogunwale7d701172015-03-11 15:36:30 -0700885 void makeFinishingLocked() {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800886 if (!finishing) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700887 if (task != null && task.stack != null
888 && this == task.stack.getVisibleBehindActivity()) {
Jose Lima34ff4922014-08-18 15:19:41 -0700889 // A finishing activity should not remain as visible in the background
890 mStackSupervisor.requestVisibleBehindLocked(this, false);
891 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800892 finishing = true;
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700893 if (stopped) {
894 clearOptionsLocked();
895 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800896 }
897 }
898
Dianne Hackborn7e269642010-08-25 19:50:20 -0700899 UriPermissionOwner getUriPermissionsLocked() {
900 if (uriPermissions == null) {
901 uriPermissions = new UriPermissionOwner(service, this);
902 }
903 return uriPermissions;
904 }
905
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700906 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800907 int requestCode, int resultCode,
908 Intent resultData) {
909 ActivityResult r = new ActivityResult(from, resultWho,
John Spurlock8a985d22014-02-25 09:40:05 -0500910 requestCode, resultCode, resultData);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800912 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 }
914 results.add(r);
915 }
916
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700917 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800918 int requestCode) {
919 if (results != null) {
920 for (int i=results.size()-1; i>=0; i--) {
921 ActivityResult r = (ActivityResult)results.get(i);
922 if (r.mFrom != from) continue;
923 if (r.mResultWho == null) {
924 if (resultWho != null) continue;
925 } else {
926 if (!r.mResultWho.equals(resultWho)) continue;
927 }
928 if (r.mRequestCode != requestCode) continue;
929
930 results.remove(i);
931 }
932 }
933 }
934
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800935 void addNewIntentLocked(ReferrerIntent intent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 if (newIntents == null) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800937 newIntents = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 }
939 newIntents.add(intent);
940 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700941
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700942 /**
943 * Deliver a new Intent to an existing activity, so that its onNewIntent()
944 * method will be called at the proper time.
945 */
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800946 final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) {
Dianne Hackborn514074f2013-02-11 10:52:46 -0800947 // The activity now gets access to the data associated with this Intent.
948 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
Nicolas Prevotc6cf95c2014-05-29 11:30:36 +0100949 intent, getUriPermissionsLocked(), userId);
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800950 final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
Craig Mautner86d67a42013-05-14 10:34:38 -0700951 boolean unsent = true;
Wale Ogunwale826c7062016-09-13 08:25:54 -0700952 final ActivityStack stack = task.stack;
953 final boolean isTopActivityInStack =
954 stack != null && stack.topRunningActivityLocked() == this;
955 final boolean isTopActivityWhileSleeping =
956 service.isSleepingLocked() && isTopActivityInStack;
957 final boolean isTopActivityInMinimizedDockedStack = isTopActivityInStack
958 && stack.mStackId == DOCKED_STACK_ID && mStackSupervisor.mIsDockMinimized
959 && state == ActivityState.PAUSED;
960
961 // We want to immediately deliver the intent to the activity if:
962 // - It is the resumed activity.
963 // - The device is sleeping and it is the top activity behind the lock screen (b/6700897).
964 // - It is the top activity in a minimized docked stack. In this case the activity will be
965 // temporarily resumed then paused again on the client side.
966 if ((state == ActivityState.RESUMED || isTopActivityWhileSleeping
967 || isTopActivityInMinimizedDockedStack) && app != null && app.thread != null) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700968 try {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800969 ArrayList<ReferrerIntent> ar = new ArrayList<>(1);
970 ar.add(rintent);
Wale Ogunwale826c7062016-09-13 08:25:54 -0700971 app.thread.scheduleNewIntent(
972 ar, appToken, isTopActivityInMinimizedDockedStack /* andPause */);
Craig Mautner86d67a42013-05-14 10:34:38 -0700973 unsent = false;
Dianne Hackborn39792d22010-08-19 18:01:52 -0700974 } catch (RemoteException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800975 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn39792d22010-08-19 18:01:52 -0700976 } catch (NullPointerException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800977 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700978 }
979 }
Craig Mautner86d67a42013-05-14 10:34:38 -0700980 if (unsent) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800981 addNewIntentLocked(rintent);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700982 }
983 }
984
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700985 void updateOptionsLocked(ActivityOptions options) {
986 if (options != null) {
987 if (pendingOptions != null) {
988 pendingOptions.abort();
989 }
990 pendingOptions = options;
991 }
992 }
993
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700994 void applyOptionsLocked() {
George Mount2c92c972014-03-20 09:38:23 -0700995 if (pendingOptions != null
996 && pendingOptions.getAnimationType() != ActivityOptions.ANIM_SCENE_TRANSITION) {
Michael Jurka21385cd2012-05-03 10:57:31 -0700997 final int animationType = pendingOptions.getAnimationType();
998 switch (animationType) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700999 case ActivityOptions.ANIM_CUSTOM:
1000 service.mWindowManager.overridePendingAppTransition(
1001 pendingOptions.getPackageName(),
1002 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -07001003 pendingOptions.getCustomExitResId(),
1004 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001005 break;
Chet Haase10e23ab2015-02-11 15:08:38 -08001006 case ActivityOptions.ANIM_CLIP_REVEAL:
1007 service.mWindowManager.overridePendingAppTransitionClipReveal(
1008 pendingOptions.getStartX(), pendingOptions.getStartY(),
1009 pendingOptions.getWidth(), pendingOptions.getHeight());
1010 if (intent.getSourceBounds() == null) {
1011 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1012 pendingOptions.getStartY(),
1013 pendingOptions.getStartX()+pendingOptions.getWidth(),
1014 pendingOptions.getStartY()+pendingOptions.getHeight()));
1015 }
1016 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001017 case ActivityOptions.ANIM_SCALE_UP:
1018 service.mWindowManager.overridePendingAppTransitionScaleUp(
1019 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001020 pendingOptions.getWidth(), pendingOptions.getHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001021 if (intent.getSourceBounds() == null) {
1022 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1023 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001024 pendingOptions.getStartX()+pendingOptions.getWidth(),
1025 pendingOptions.getStartY()+pendingOptions.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001026 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001027 break;
Michael Jurka832cb222012-04-13 09:32:47 -07001028 case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
1029 case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
1030 boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001031 service.mWindowManager.overridePendingAppTransitionThumb(
1032 pendingOptions.getThumbnail(),
1033 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -07001034 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -07001035 scaleUp);
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001036 if (intent.getSourceBounds() == null) {
1037 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1038 pendingOptions.getStartY(),
1039 pendingOptions.getStartX()
1040 + pendingOptions.getThumbnail().getWidth(),
1041 pendingOptions.getStartY()
1042 + pendingOptions.getThumbnail().getHeight()));
1043 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001044 break;
Winson Chunga4ccb862014-08-22 15:26:27 -07001045 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP:
1046 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001047 final AppTransitionAnimationSpec[] specs = pendingOptions.getAnimSpecs();
1048 if (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN
1049 && specs != null) {
1050 service.mWindowManager.overridePendingAppTransitionMultiThumb(
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001051 specs, pendingOptions.getOnAnimationStartListener(),
1052 pendingOptions.getAnimationFinishedListener(), false);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001053 } else {
1054 service.mWindowManager.overridePendingAppTransitionAspectScaledThumb(
1055 pendingOptions.getThumbnail(),
1056 pendingOptions.getStartX(), pendingOptions.getStartY(),
1057 pendingOptions.getWidth(), pendingOptions.getHeight(),
1058 pendingOptions.getOnAnimationStartListener(),
1059 (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP));
1060 if (intent.getSourceBounds() == null) {
1061 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1062 pendingOptions.getStartY(),
1063 pendingOptions.getStartX() + pendingOptions.getWidth(),
1064 pendingOptions.getStartY() + pendingOptions.getHeight()));
1065 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001066 }
1067 break;
Craig Mautner233ceee2014-05-09 17:05:11 -07001068 default:
1069 Slog.e(TAG, "applyOptionsLocked: Unknown animationType=" + animationType);
1070 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001071 }
1072 pendingOptions = null;
1073 }
1074 }
1075
Adam Powellcfbe9be2013-11-06 14:58:58 -08001076 ActivityOptions getOptionsForTargetActivityLocked() {
1077 return pendingOptions != null ? pendingOptions.forTargetActivity() : null;
1078 }
1079
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001080 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001081 if (pendingOptions != null) {
1082 pendingOptions.abort();
1083 pendingOptions = null;
1084 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001085 }
1086
Dianne Hackborn9622ca42012-10-23 18:56:33 -07001087 ActivityOptions takeOptionsLocked() {
1088 ActivityOptions opts = pendingOptions;
1089 pendingOptions = null;
1090 return opts;
1091 }
1092
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001093 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -07001094 if (uriPermissions != null) {
1095 uriPermissions.removeUriPermissionsLocked();
1096 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001097 }
1098 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099
1100 void pauseKeyDispatchingLocked() {
1101 if (!keysPaused) {
1102 keysPaused = true;
Dianne Hackbornbe707852011-11-11 14:32:10 -08001103 service.mWindowManager.pauseKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 }
1105 }
1106
1107 void resumeKeyDispatchingLocked() {
1108 if (keysPaused) {
1109 keysPaused = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -08001110 service.mWindowManager.resumeKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 }
1112 }
1113
Winson Chung740c3ac2014-11-12 16:14:38 -08001114 void updateThumbnailLocked(Bitmap newThumbnail, CharSequence description) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001115 if (newThumbnail != null) {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001116 if (DEBUG_THUMBNAILS) Slog.i(TAG_THUMBNAILS,
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001117 "Setting thumbnail of " + this + " to " + newThumbnail);
Winsonc809cbb2015-11-02 12:06:15 -08001118 boolean thumbnailUpdated = task.setLastThumbnailLocked(newThumbnail);
Winson Chung096f36b2014-08-20 15:39:01 -07001119 if (thumbnailUpdated && isPersistable()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001120 mStackSupervisor.mService.notifyTaskPersisterLocked(task, false);
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001121 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001122 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001123 task.lastDescription = description;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001124 }
1125
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001126 void startLaunchTickingLocked() {
1127 if (ActivityManagerService.IS_USER_BUILD) {
1128 return;
1129 }
1130 if (launchTickTime == 0) {
1131 launchTickTime = SystemClock.uptimeMillis();
1132 continueLaunchTickingLocked();
1133 }
1134 }
1135
1136 boolean continueLaunchTickingLocked() {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001137 if (launchTickTime == 0) {
1138 return false;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001139 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001140
1141 final ActivityStack stack = task.stack;
1142 if (stack == null) {
1143 return false;
1144 }
1145
1146 Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG, this);
1147 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
1148 stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
1149 return true;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001150 }
1151
1152 void finishLaunchTickingLocked() {
1153 launchTickTime = 0;
Wale Ogunwale7d701172015-03-11 15:36:30 -07001154 final ActivityStack stack = task.stack;
1155 if (stack != null) {
1156 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
1157 }
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001158 }
1159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 // IApplicationToken
1161
1162 public boolean mayFreezeScreenLocked(ProcessRecord app) {
1163 // Only freeze the screen if this activity is currently attached to
1164 // an application, and that application is not blocked or unresponding.
1165 // In any other case, we can't count on getting the screen unfrozen,
1166 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -08001167 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
1171 if (mayFreezeScreenLocked(app)) {
Dianne Hackbornbe707852011-11-11 14:32:10 -08001172 service.mWindowManager.startAppFreezingScreen(appToken, configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 }
1174 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 public void stopFreezingScreenLocked(boolean force) {
1177 if (force || frozenBeforeDestroy) {
1178 frozenBeforeDestroy = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -08001179 service.mWindowManager.stopAppFreezingScreen(appToken, force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180 }
1181 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001182
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001183 public void reportFullyDrawnLocked() {
1184 final long curTime = SystemClock.uptimeMillis();
1185 if (displayStartTime != 0) {
1186 reportLaunchTimeLocked(curTime);
1187 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001188 final ActivityStack stack = task.stack;
1189 if (fullyDrawnStartTime != 0 && stack != null) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001190 final long thisTime = curTime - fullyDrawnStartTime;
1191 final long totalTime = stack.mFullyDrawnStartTime != 0
1192 ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07001193 if (SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -07001194 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001195 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME,
1196 userId, System.identityHashCode(this), shortComponentName,
1197 thisTime, totalTime);
1198 StringBuilder sb = service.mStringBuilder;
1199 sb.setLength(0);
1200 sb.append("Fully drawn ");
1201 sb.append(shortComponentName);
1202 sb.append(": ");
1203 TimeUtils.formatDuration(thisTime, sb);
1204 if (thisTime != totalTime) {
1205 sb.append(" (total ");
1206 TimeUtils.formatDuration(totalTime, sb);
1207 sb.append(")");
1208 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001209 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001210 }
1211 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001212 //service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001213 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001214 stack.mFullyDrawnStartTime = 0;
1215 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001216 fullyDrawnStartTime = 0;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001217 }
1218
1219 private void reportLaunchTimeLocked(final long curTime) {
1220 final ActivityStack stack = task.stack;
Wale Ogunwale7d701172015-03-11 15:36:30 -07001221 if (stack == null) {
1222 return;
1223 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001224 final long thisTime = curTime - displayStartTime;
1225 final long totalTime = stack.mLaunchStartTime != 0
1226 ? (curTime - stack.mLaunchStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07001227 if (SHOW_ACTIVITY_START_TIME) {
Narayan Kamath7829c812015-06-08 17:39:43 +01001228 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001229 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
1230 userId, System.identityHashCode(this), shortComponentName,
1231 thisTime, totalTime);
1232 StringBuilder sb = service.mStringBuilder;
1233 sb.setLength(0);
1234 sb.append("Displayed ");
1235 sb.append(shortComponentName);
1236 sb.append(": ");
1237 TimeUtils.formatDuration(thisTime, sb);
1238 if (thisTime != totalTime) {
1239 sb.append(" (total ");
1240 TimeUtils.formatDuration(totalTime, sb);
1241 sb.append(")");
1242 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001243 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001244 }
1245 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
1246 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001247 //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001248 }
1249 displayStartTime = 0;
1250 stack.mLaunchStartTime = 0;
1251 }
1252
Wale Ogunwale7d701172015-03-11 15:36:30 -07001253 void windowsDrawnLocked() {
Jorim Jaggi275561a2016-02-23 10:11:02 -05001254 mStackSupervisor.mActivityMetricsLogger.notifyWindowsDrawn();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001255 if (displayStartTime != 0) {
Chong Zhang5022da32016-06-21 16:31:37 -07001256 reportLaunchTimeLocked(SystemClock.uptimeMillis());
Wale Ogunwale7d701172015-03-11 15:36:30 -07001257 }
1258 mStackSupervisor.sendWaitingVisibleReportLocked(this);
1259 startTime = 0;
1260 finishLaunchTickingLocked();
1261 if (task != null) {
1262 task.hasBeenVisible = true;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001263 }
1264 }
1265
Wale Ogunwale7d701172015-03-11 15:36:30 -07001266 void windowsVisibleLocked() {
1267 mStackSupervisor.reportActivityVisibleLocked(this);
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001268 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this);
Wale Ogunwale7d701172015-03-11 15:36:30 -07001269 if (!nowVisible) {
1270 nowVisible = true;
1271 lastVisibleTime = SystemClock.uptimeMillis();
1272 if (!idle) {
1273 // Instead of doing the full stop routine here, let's just hide any activities
1274 // we now can, and let them stop when the normal idle happens.
1275 mStackSupervisor.processStoppingActivitiesLocked(false);
1276 } else {
1277 // If this activity was already idle, then we now need to make sure we perform
1278 // the full stop of any activities that are waiting to do so. This is because
1279 // we won't do that while they are still waiting for this one to become visible.
1280 final int size = mStackSupervisor.mWaitingVisibleActivities.size();
1281 if (size > 0) {
1282 for (int i = 0; i < size; i++) {
1283 ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i);
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001284 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "Was waiting for visible: " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001286 mStackSupervisor.mWaitingVisibleActivities.clear();
1287 mStackSupervisor.scheduleIdleLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001288 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001289 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001290 service.scheduleAppGcsLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291 }
1292 }
1293
Wale Ogunwale7d701172015-03-11 15:36:30 -07001294 ActivityRecord getWaitingHistoryRecordLocked() {
riddle_hsudb46d6b2015-04-01 18:58:07 +08001295 // First find the real culprit... if this activity is waiting for
1296 // another activity to start or has stopped, then the key dispatching
1297 // timeout should not be caused by this.
Wale Ogunwale16a62792015-04-01 11:50:31 -07001298 if (mStackSupervisor.mWaitingVisibleActivities.contains(this) || stopped) {
Craig Mautner8f2adcb2014-04-07 22:21:33 +00001299 final ActivityStack stack = mStackSupervisor.getFocusedStack();
riddle_hsudb46d6b2015-04-01 18:58:07 +08001300 // Try to use the one which is closest to top.
1301 ActivityRecord r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001302 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -08001303 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001304 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001305 if (r != null) {
1306 return r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 }
1308 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001309 return this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 }
1311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312 /**
1313 * This method will return true if the activity is either visible, is becoming visible, is
1314 * currently pausing, or is resumed.
1315 */
1316 public boolean isInterestingToUserLocked() {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001317 return visible || nowVisible || state == ActivityState.PAUSING ||
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001318 state == ActivityState.RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001319 }
1320
Wale Ogunwale3e997362016-09-06 10:37:56 -07001321 void setSleeping(boolean _sleeping) {
1322 setSleeping(_sleeping, false);
1323 }
1324
1325 void setSleeping(boolean _sleeping, boolean force) {
1326 if (!force && sleeping == _sleeping) {
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001327 return;
1328 }
1329 if (app != null && app.thread != null) {
1330 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -08001331 app.thread.scheduleSleeping(appToken, _sleeping);
Craig Mautner0eea92c2013-05-16 13:35:39 -07001332 if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
1333 mStackSupervisor.mGoingToSleepActivities.add(this);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001334 }
1335 sleeping = _sleeping;
1336 } catch (RemoteException e) {
Craig Mautner0eea92c2013-05-16 13:35:39 -07001337 Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001338 }
1339 }
1340 }
Craig Mautnerf81b90872013-02-26 13:02:43 -08001341
Craig Mautnerd2328952013-03-05 12:46:26 -08001342 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001343 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Craig Mautnerd2328952013-03-05 12:46:26 -08001344 if (r == null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001345 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08001346 }
1347 final TaskRecord task = r.task;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001348 final int activityNdx = task.mActivities.indexOf(r);
1349 if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001350 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08001351 }
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001352 return task.taskId;
Craig Mautnerd2328952013-03-05 12:46:26 -08001353 }
1354
1355 static ActivityRecord isInStackLocked(IBinder token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001356 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Wale Ogunwale60454db2015-01-23 16:05:07 -08001357 return (r != null) ? r.task.stack.isInStackLocked(r) : null;
Craig Mautnerd2328952013-03-05 12:46:26 -08001358 }
1359
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001360 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -08001361 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
1362 if (r != null) {
1363 return r.task.stack;
1364 }
1365 return null;
1366 }
1367
Dianne Hackborn89ad4562014-08-24 16:45:38 -07001368 final boolean isDestroyable() {
1369 if (finishing || app == null || state == ActivityState.DESTROYING
1370 || state == ActivityState.DESTROYED) {
1371 // This would be redundant.
1372 return false;
1373 }
1374 if (task == null || task.stack == null || this == task.stack.mResumedActivity
1375 || this == task.stack.mPausingActivity || !haveState || !stopped) {
1376 // We're not ready for this kind of thing.
1377 return false;
1378 }
1379 if (visible) {
1380 // The user would notice this!
1381 return false;
1382 }
1383 return true;
1384 }
1385
Winson Chung3bad5cc02014-08-19 17:44:32 -07001386 private static String createImageFilename(long createTime, int taskId) {
1387 return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime +
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001388 TaskPersister.IMAGE_EXTENSION;
1389 }
1390
Craig Mautner648f69b2014-09-18 14:16:26 -07001391 void setTaskDescription(TaskDescription _taskDescription) {
1392 Bitmap icon;
1393 if (_taskDescription.getIconFilename() == null &&
1394 (icon = _taskDescription.getIcon()) != null) {
1395 final String iconFilename = createImageFilename(createTime, task.taskId);
Suprabh Shukla23593142015-11-03 17:31:15 -08001396 final File iconFile = new File(TaskPersister.getUserImagesDir(userId), iconFilename);
1397 final String iconFilePath = iconFile.getAbsolutePath();
Suprabh Shukla09a88f52015-12-02 14:36:31 -08001398 service.mRecentTasks.saveImage(icon, iconFilePath);
Suprabh Shukla23593142015-11-03 17:31:15 -08001399 _taskDescription.setIconFilename(iconFilePath);
Craig Mautner648f69b2014-09-18 14:16:26 -07001400 }
1401 taskDescription = _taskDescription;
1402 }
1403
Amith Yamasani0af6fa72016-01-17 15:36:19 -08001404 void setVoiceSessionLocked(IVoiceInteractionSession session) {
1405 voiceSession = session;
1406 pendingVoiceInteractionStart = false;
1407 }
1408
1409 void clearVoiceSessionLocked() {
1410 voiceSession = null;
1411 pendingVoiceInteractionStart = false;
1412 }
1413
Wale Ogunwale3b232392016-05-13 15:37:13 -07001414 void showStartingWindow(ActivityRecord prev, boolean createIfNeeded) {
1415 final CompatibilityInfo compatInfo =
1416 service.compatibilityInfoForPackageLocked(info.applicationInfo);
1417 final boolean shown = service.mWindowManager.setAppStartingWindow(
1418 appToken, packageName, theme, compatInfo, nonLocalizedLabel, labelRes, icon,
1419 logo, windowFlags, prev != null ? prev.appToken : null, createIfNeeded);
1420 if (shown) {
1421 mStartingWindowState = STARTING_WINDOW_SHOWN;
1422 }
1423 }
1424
Craig Mautner21d24a22014-04-23 11:45:37 -07001425 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
1426 out.attribute(null, ATTR_ID, String.valueOf(createTime));
1427 out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
1428 if (launchedFromPackage != null) {
1429 out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage);
1430 }
1431 if (resolvedType != null) {
1432 out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType);
1433 }
1434 out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified));
1435 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Winson Chung2cb86c72014-06-25 12:03:30 -07001436
Craig Mautner21d24a22014-04-23 11:45:37 -07001437 if (taskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001438 taskDescription.saveToXml(out);
Craig Mautner21d24a22014-04-23 11:45:37 -07001439 }
1440
1441 out.startTag(null, TAG_INTENT);
1442 intent.saveToXml(out);
1443 out.endTag(null, TAG_INTENT);
1444
1445 if (isPersistable() && persistentState != null) {
1446 out.startTag(null, TAG_PERSISTABLEBUNDLE);
1447 persistentState.saveToXml(out);
1448 out.endTag(null, TAG_PERSISTABLEBUNDLE);
1449 }
1450 }
1451
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001452 static ActivityRecord restoreFromXml(XmlPullParser in,
1453 ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07001454 Intent intent = null;
1455 PersistableBundle persistentState = null;
1456 int launchedFromUid = 0;
1457 String launchedFromPackage = null;
1458 String resolvedType = null;
1459 boolean componentSpecified = false;
1460 int userId = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07001461 long createTime = -1;
1462 final int outerDepth = in.getDepth();
Winson Chung2cb86c72014-06-25 12:03:30 -07001463 TaskDescription taskDescription = new TaskDescription();
Craig Mautner21d24a22014-04-23 11:45:37 -07001464
1465 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1466 final String attrName = in.getAttributeName(attrNdx);
1467 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001468 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
Wale Ogunwale18795a22014-12-03 11:38:33 -08001469 "ActivityRecord: attribute name=" + attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001470 if (ATTR_ID.equals(attrName)) {
1471 createTime = Long.valueOf(attrValue);
1472 } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001473 launchedFromUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001474 } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
1475 launchedFromPackage = attrValue;
1476 } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
1477 resolvedType = attrValue;
1478 } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
1479 componentSpecified = Boolean.valueOf(attrValue);
1480 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001481 userId = Integer.parseInt(attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001482 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1483 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001484 } else {
1485 Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName);
1486 }
1487 }
1488
1489 int event;
1490 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07001491 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001492 if (event == XmlPullParser.START_TAG) {
1493 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001494 if (TaskPersister.DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08001495 Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001496 if (TAG_INTENT.equals(name)) {
1497 intent = Intent.restoreFromXml(in);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001498 if (TaskPersister.DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08001499 Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07001500 } else if (TAG_PERSISTABLEBUNDLE.equals(name)) {
1501 persistentState = PersistableBundle.restoreFromXml(in);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001502 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
Craig Mautner21d24a22014-04-23 11:45:37 -07001503 "ActivityRecord: persistentState=" + persistentState);
1504 } else {
1505 Slog.w(TAG, "restoreActivity: unexpected name=" + name);
1506 XmlUtils.skipCurrentTag(in);
1507 }
1508 }
1509 }
1510
1511 if (intent == null) {
Craig Mautnere0129b32014-05-25 16:41:09 -07001512 throw new XmlPullParserException("restoreActivity error intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07001513 }
1514
1515 final ActivityManagerService service = stackSupervisor.mService;
1516 final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null,
Jeff Hao1b012d32014-08-20 10:35:34 -07001517 userId);
Craig Mautnere0129b32014-05-25 16:41:09 -07001518 if (aInfo == null) {
Craig Mautner77b04262014-06-27 15:22:12 -07001519 throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent +
1520 " resolvedType=" + resolvedType);
Craig Mautnere0129b32014-05-25 16:41:09 -07001521 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001522 final ActivityRecord r = new ActivityRecord(service, /*caller*/null, launchedFromUid,
1523 launchedFromPackage, intent, resolvedType, aInfo, service.getConfiguration(),
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001524 null, null, 0, componentSpecified, false, stackSupervisor, null, null, null);
Craig Mautner21d24a22014-04-23 11:45:37 -07001525
1526 r.persistentState = persistentState;
Winson Chung2cb86c72014-06-25 12:03:30 -07001527 r.taskDescription = taskDescription;
Craig Mautner21d24a22014-04-23 11:45:37 -07001528 r.createTime = createTime;
1529
1530 return r;
1531 }
1532
1533 private static String activityTypeToString(int type) {
Craig Mautnerae7ecab2013-09-18 11:48:14 -07001534 switch (type) {
1535 case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE";
1536 case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE";
1537 case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE";
1538 default: return Integer.toString(type);
1539 }
1540 }
1541
Craig Mautnerf81b90872013-02-26 13:02:43 -08001542 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001543 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001544 if (stringName != null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001545 return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) +
Craig Mautnerf3333272013-04-22 10:55:53 -07001546 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001547 }
1548 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -08001549 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001550 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -07001551 sb.append(" u");
1552 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001553 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001554 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -08001555 stringName = sb.toString();
1556 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 }
1558}