blob: cb780b1351eebb5d4e83bef5d7d67a370f215efa [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 Ogunwale18795a22014-12-03 11:38:33 -080019import static com.android.server.am.TaskPersister.DEBUG_PERSISTER;
20import static com.android.server.am.TaskPersister.DEBUG_RESTORER;
21import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
22
Craig Mautner21d24a22014-04-23 11:45:37 -070023import android.app.ActivityManager.TaskDescription;
Craig Mautnera0026042014-04-23 11:45:37 -070024import android.os.PersistableBundle;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -070025import android.os.Trace;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070026
Dianne Hackborn2d69d492012-04-06 16:24:14 -070027import com.android.internal.app.ResolverActivity;
Dianne Hackborn85d558c2014-11-04 10:31:54 -080028import com.android.internal.content.ReferrerIntent;
Craig Mautner21d24a22014-04-23 11:45:37 -070029import com.android.internal.util.XmlUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import com.android.server.AttributeCache;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070031import com.android.server.am.ActivityStack.ActivityState;
Craig Mautner4a1cb222013-12-04 16:14:06 -080032import com.android.server.am.ActivityStackSupervisor.ActivityContainer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
Dianne Hackborn7a2195c2012-03-19 17:38:00 -070034import android.app.ActivityOptions;
Craig Mautner05d6272ba2013-02-11 09:39:27 -080035import android.app.ResultInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.content.ComponentName;
37import android.content.Intent;
38import android.content.pm.ActivityInfo;
39import android.content.pm.ApplicationInfo;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -070040import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.content.res.Configuration;
42import android.graphics.Bitmap;
Dianne Hackbornd367ca82012-05-07 15:49:39 -070043import android.graphics.Rect;
Dianne Hackborn247fe742011-01-08 17:25:57 -080044import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import android.os.Bundle;
Dianne Hackbornbe707852011-11-11 14:32:10 -080046import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import android.os.Message;
48import android.os.Process;
Dianne Hackborn39792d22010-08-19 18:01:52 -070049import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.os.SystemClock;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070051import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import android.util.EventLog;
53import android.util.Log;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070054import android.util.Slog;
Dianne Hackborn0dad3642010-09-09 21:25:35 -070055import android.util.TimeUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.view.IApplicationToken;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -080057import android.view.WindowManager;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070058
Craig Mautner21d24a22014-04-23 11:45:37 -070059import org.xmlpull.v1.XmlPullParser;
60import org.xmlpull.v1.XmlPullParserException;
61import org.xmlpull.v1.XmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062
Craig Mautner21d24a22014-04-23 11:45:37 -070063import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import java.io.PrintWriter;
65import java.lang.ref.WeakReference;
66import java.util.ArrayList;
67import java.util.HashSet;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070068import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069
70/**
71 * An entry in the history stack, representing an activity.
72 */
Dianne Hackbornbe707852011-11-11 14:32:10 -080073final class ActivityRecord {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -070074 static final String TAG = ActivityManagerService.TAG;
75 static final boolean DEBUG_SAVED_STATE = ActivityStackSupervisor.DEBUG_SAVED_STATE;
Winson Chung740c3ac2014-11-12 16:14:38 -080076 final public static String RECENTS_PACKAGE_NAME = "com.android.systemui.recents";
Craig Mautnerb59dcfd2013-05-06 13:12:58 -070077
Craig Mautner21d24a22014-04-23 11:45:37 -070078 private static final String TAG_ACTIVITY = "activity";
79 private static final String ATTR_ID = "id";
80 private static final String TAG_INTENT = "intent";
81 private static final String ATTR_USERID = "user_id";
82 private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle";
83 private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid";
Wale Ogunwale92dd1ab2015-01-15 15:36:48 -080084 static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package";
Craig Mautner21d24a22014-04-23 11:45:37 -070085 private static final String ATTR_RESOLVEDTYPE = "resolved_type";
86 private static final String ATTR_COMPONENTSPECIFIED = "component_specified";
Dianne Hackborn337abb32014-09-24 12:44:29 -070087 static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_";
Craig Mautner21d24a22014-04-23 11:45:37 -070088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 final ActivityManagerService service; // owner
Dianne Hackbornbe707852011-11-11 14:32:10 -080090 final IApplicationToken.Stub appToken; // window manager token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 final ActivityInfo info; // all about me
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070092 final ApplicationInfo appInfo; // information about activity's app
Wale Ogunwale92dd1ab2015-01-15 15:36:48 -080093 int launchedFromUid; // always the uid who started the activity.
Dianne Hackbornf265ea92013-01-31 15:00:51 -080094 final String launchedFromPackage; // always the package who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -070095 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 final Intent intent; // the original intent that generated us
97 final ComponentName realActivity; // the intent component, or target of an alias.
98 final String shortComponentName; // the short component name of the intent
99 final String resolvedType; // as per original caller;
100 final String packageName; // the package implementing intent's component
101 final String processName; // process where this component wants to run
102 final String taskAffinity; // as per ActivityInfo.taskAffinity
103 final boolean stateNotNeeded; // As per ActivityInfo.flags
Craig Mautner4addfc52013-06-25 08:05:45 -0700104 boolean fullscreen; // covers the full screen?
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800105 final boolean noDisplay; // activity is not displayed?
The Android Open Source Project4df24232009-03-05 14:34:35 -0800106 final boolean componentSpecified; // did caller specifiy an explicit component?
Craig Mautner86d67a42013-05-14 10:34:38 -0700107
108 static final int APPLICATION_ACTIVITY_TYPE = 0;
109 static final int HOME_ACTIVITY_TYPE = 1;
110 static final int RECENTS_ACTIVITY_TYPE = 2;
Craig Mautner2c1faed2013-07-23 12:56:02 -0700111 int mActivityType;
Craig Mautner86d67a42013-05-14 10:34:38 -0700112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 CharSequence nonLocalizedLabel; // the label information from the package mgr.
114 int labelRes; // the label information from the package mgr.
115 int icon; // resource identifier of activity's icon.
Adam Powell04fe6eb2013-05-31 14:39:48 -0700116 int logo; // resource identifier of activity's logo.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 int theme; // resource identifier of activity's theme.
Dianne Hackborn247fe742011-01-08 17:25:57 -0800118 int realTheme; // actual theme resource we will use, never 0.
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800119 int windowFlags; // custom window flags for preview window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 TaskRecord task; // the task this is in.
Craig Mautner21d24a22014-04-23 11:45:37 -0700121 long createTime = System.currentTimeMillis();
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700122 long displayStartTime; // when we started launching this activity
123 long fullyDrawnStartTime; // when we started launching this activity
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700124 long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -0800125 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700126 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700127 long pauseTime; // last time we started pausing the activity
128 long launchTickTime; // base time for launch tick messages
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 Configuration configuration; // configuration activity was last running in
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700130 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700131 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 final String resultWho; // additional identifier for use by resultTo.
133 final int requestCode; // code given by requester (resultTo)
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800134 ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800136 ArrayList<ReferrerIntent> newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700137 ActivityOptions pendingOptions; // most recently given options
George Mount6ba042b2014-07-28 11:12:28 -0700138 ActivityOptions returningOptions; // options that are coming back via convertToTranslucent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700140 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700141 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700142 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 Bundle icicle; // last saved activity state
Craig Mautnera0026042014-04-23 11:45:37 -0700144 PersistableBundle persistentState; // last persistently saved activity state
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 boolean frontOfTask; // is this the root activity of its task?
146 boolean launchFailed; // set if a launched failed, to abort on 2nd try
147 boolean haveState; // have we gotten the last activity state?
148 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700149 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 boolean finishing; // activity in pending finish list?
151 boolean configDestroy; // need to destroy due to config change?
152 int configChangeFlags; // which config values have changed
153 boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 int launchMode; // the launch mode activity attribute.
155 boolean visible; // does this activity's window need to be shown?
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800156 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 boolean waitingVisible; // true if waiting for a new act to become vis
158 boolean nowVisible; // is this activity's window visible?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 boolean idle; // has the activity gone idle?
160 boolean hasBeenLaunched;// has this activity ever been launched?
161 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400162 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400163 boolean forceNewConfig; // force re-create with new config next time
Dianne Hackborn07981492013-01-28 11:36:23 -0800164 int launchCount; // count of launches since last state
165 long lastLaunchTime; // time of last lauch of this activity
Craig Mautnerf4c909b2014-04-17 18:39:38 -0700166 ArrayList<ActivityContainer> mChildContainers = new ArrayList<ActivityContainer>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700168 String stringName; // for caching of toString().
Craig Mautnerde4ef022013-04-07 19:01:33 -0700169
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700170 private boolean inHistory; // are we in the history stack?
Craig Mautnerde4ef022013-04-07 19:01:33 -0700171 final ActivityStackSupervisor mStackSupervisor;
Craig Mautnera61bc652013-10-28 15:43:18 -0700172 boolean mStartingWindowShown = false;
Craig Mautnere0a38842013-12-16 16:14:02 -0800173 ActivityContainer mInitialActivityContainer;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700174
Craig Mautner21d24a22014-04-23 11:45:37 -0700175 TaskDescription taskDescription; // the recents information for this activity
Craig Mautnerbb742462014-07-07 15:28:55 -0700176 boolean mLaunchTaskBehind; // this activity is actively being launched with
177 // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed.
Craig Mautner2fbd7542014-03-21 09:34:07 -0700178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700180 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700181 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
182 pw.print(" processName="); pw.println(processName);
183 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Craig Mautnere11f2b72013-04-01 12:37:17 -0700184 pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800185 pw.print(" userId="); pw.println(userId);
186 pw.print(prefix); pw.print("app="); pw.println(app);
187 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700188 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
189 pw.print(" task="); pw.println(task);
190 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700191 pw.print(prefix); pw.print("realActivity=");
192 pw.println(realActivity.flattenToShortString());
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700193 if (appInfo != null) {
194 pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir);
195 if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) {
196 pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir);
197 }
198 pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800199 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700200 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
201 pw.print(" componentSpecified="); pw.print(componentSpecified);
Craig Mautner86d67a42013-05-14 10:34:38 -0700202 pw.print(" mActivityType="); pw.println(mActivityType);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800203 pw.print(prefix); pw.print("compat="); pw.print(compat);
204 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
205 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
206 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Dianne Hackborne17aeb32011-04-07 15:11:57 -0700207 pw.print(prefix); pw.print("config="); pw.println(configuration);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700208 if (resultTo != null || resultWho != null) {
209 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
210 pw.print(" resultWho="); pw.print(resultWho);
211 pw.print(" resultCode="); pw.println(requestCode);
212 }
Craig Mautner29c58ca2014-10-14 16:17:06 -0700213 if (taskDescription != null) {
214 final String iconFilename = taskDescription.getIconFilename();
215 if (iconFilename != null || taskDescription.getLabel() != null ||
216 taskDescription.getPrimaryColor() != 0) {
217 pw.print(prefix); pw.print("taskDescription:");
218 pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename());
219 pw.print(" label=\""); pw.print(taskDescription.getLabel());
220 pw.print("\"");
221 pw.print(" color=");
222 pw.println(Integer.toHexString(taskDescription.getPrimaryColor()));
223 }
224 if (iconFilename == null && taskDescription.getIcon() != null) {
225 pw.print(prefix); pw.println("taskDescription contains Bitmap");
226 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700227 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700228 if (results != null) {
229 pw.print(prefix); pw.print("results="); pw.println(results);
230 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700231 if (pendingResults != null && pendingResults.size() > 0) {
232 pw.print(prefix); pw.println("Pending Results:");
233 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
234 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
235 pw.print(prefix); pw.print(" - ");
236 if (pir == null) {
237 pw.println("null");
238 } else {
239 pw.println(pir);
240 pir.dump(pw, prefix + " ");
241 }
242 }
243 }
244 if (newIntents != null && newIntents.size() > 0) {
245 pw.print(prefix); pw.println("Pending New Intents:");
246 for (int i=0; i<newIntents.size(); i++) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800247 Intent intent = newIntents.get(i);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700248 pw.print(prefix); pw.print(" - ");
249 if (intent == null) {
250 pw.println("null");
251 } else {
252 pw.println(intent.toShortString(false, true, false, true));
253 }
254 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700255 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700256 if (pendingOptions != null) {
257 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
258 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700259 if (uriPermissions != null) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700260 uriPermissions.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700261 }
262 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800263 pw.print(" launchCount="); pw.print(launchCount);
264 pw.print(" lastLaunchTime=");
265 if (lastLaunchTime == 0) pw.print("0");
266 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
267 pw.println();
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700268 pw.print(prefix); pw.print("haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700269 pw.print(" icicle="); pw.println(icicle);
270 pw.print(prefix); pw.print("state="); pw.print(state);
271 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700272 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700273 pw.print(" finishing="); pw.println(finishing);
274 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
275 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700276 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800277 pw.print(" sleeping="); pw.print(sleeping);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700278 pw.print(" idle="); pw.println(idle);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800279 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
280 pw.print(" noDisplay="); pw.print(noDisplay);
281 pw.print(" immersive="); pw.print(immersive);
282 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800283 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400284 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700285 pw.print(prefix); pw.print("mActivityType=");
286 pw.println(activityTypeToString(mActivityType));
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700287 if (displayStartTime != 0 || startTime != 0) {
288 pw.print(prefix); pw.print("displayStartTime=");
289 if (displayStartTime == 0) pw.print("0");
290 else TimeUtils.formatDuration(displayStartTime, now, pw);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700291 pw.print(" startTime=");
292 if (startTime == 0) pw.print("0");
293 else TimeUtils.formatDuration(startTime, now, pw);
294 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700295 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800296 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700297 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800298 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700299 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700300 if (lastVisibleTime == 0) pw.print("0");
301 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
302 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700303 }
304 if (configDestroy || configChangeFlags != 0) {
305 pw.print(prefix); pw.print("configDestroy="); pw.print(configDestroy);
306 pw.print(" configChangeFlags=");
307 pw.println(Integer.toHexString(configChangeFlags));
308 }
309 if (connections != null) {
310 pw.print(prefix); pw.print("connections="); pw.println(connections);
311 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 }
313
Dianne Hackbornbe707852011-11-11 14:32:10 -0800314 static class Token extends IApplicationToken.Stub {
315 final WeakReference<ActivityRecord> weakActivity;
316
317 Token(ActivityRecord activity) {
318 weakActivity = new WeakReference<ActivityRecord>(activity);
319 }
320
Craig Mautnerde4ef022013-04-07 19:01:33 -0700321 @Override public void windowsDrawn() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800322 ActivityRecord activity = weakActivity.get();
323 if (activity != null) {
324 activity.windowsDrawn();
325 }
326 }
327
Craig Mautnerde4ef022013-04-07 19:01:33 -0700328 @Override public void windowsVisible() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800329 ActivityRecord activity = weakActivity.get();
330 if (activity != null) {
331 activity.windowsVisible();
332 }
333 }
334
Craig Mautnerde4ef022013-04-07 19:01:33 -0700335 @Override public void windowsGone() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800336 ActivityRecord activity = weakActivity.get();
337 if (activity != null) {
338 activity.windowsGone();
339 }
340 }
341
Jeff Brownbd181bb2013-09-10 16:44:24 -0700342 @Override public boolean keyDispatchingTimedOut(String reason) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800343 ActivityRecord activity = weakActivity.get();
Jeff Brownbd181bb2013-09-10 16:44:24 -0700344 return activity != null && activity.keyDispatchingTimedOut(reason);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800345 }
346
Craig Mautnerde4ef022013-04-07 19:01:33 -0700347 @Override public long getKeyDispatchingTimeout() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800348 ActivityRecord activity = weakActivity.get();
349 if (activity != null) {
350 return activity.getKeyDispatchingTimeout();
351 }
352 return 0;
353 }
354
Craig Mautnerde4ef022013-04-07 19:01:33 -0700355 @Override
Dianne Hackbornbe707852011-11-11 14:32:10 -0800356 public String toString() {
357 StringBuilder sb = new StringBuilder(128);
358 sb.append("Token{");
359 sb.append(Integer.toHexString(System.identityHashCode(this)));
360 sb.append(' ');
361 sb.append(weakActivity.get());
362 sb.append('}');
363 return sb.toString();
364 }
365 }
366
367 static ActivityRecord forToken(IBinder token) {
368 try {
369 return token != null ? ((Token)token).weakActivity.get() : null;
370 } catch (ClassCastException e) {
371 Slog.w(ActivityManagerService.TAG, "Bad activity token: " + token, e);
372 return null;
373 }
374 }
375
Craig Mautnerac6f8432013-07-17 13:24:59 -0700376 boolean isNotResolverActivity() {
377 return !ResolverActivity.class.getName().equals(realActivity.getClassName());
378 }
379
Craig Mautnerd2328952013-03-05 12:46:26 -0800380 ActivityRecord(ActivityManagerService _service, ProcessRecord _caller,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800381 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700383 ActivityRecord _resultTo, String _resultWho, int _reqCode,
Craig Mautnere0a38842013-12-16 16:14:02 -0800384 boolean _componentSpecified, ActivityStackSupervisor supervisor,
Craig Mautner233ceee2014-05-09 17:05:11 -0700385 ActivityContainer container, Bundle options) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 service = _service;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800387 appToken = new Token(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 info = aInfo;
389 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800390 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700391 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 intent = _intent;
393 shortComponentName = _intent.getComponent().flattenToShortString();
394 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800395 componentSpecified = _componentSpecified;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 configuration = _configuration;
397 resultTo = _resultTo;
398 resultWho = _resultWho;
399 requestCode = _reqCode;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700400 state = ActivityState.INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 frontOfTask = false;
402 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700404 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 finishing = false;
406 configDestroy = false;
407 keysPaused = false;
408 inHistory = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 visible = true;
410 waitingVisible = false;
411 nowVisible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 idle = false;
413 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700414 mStackSupervisor = supervisor;
Craig Mautnere0a38842013-12-16 16:14:02 -0800415 mInitialActivityContainer = container;
Craig Mautner233ceee2014-05-09 17:05:11 -0700416 if (options != null) {
417 pendingOptions = new ActivityOptions(options);
Craig Mautnerbb742462014-07-07 15:28:55 -0700418 mLaunchTaskBehind = pendingOptions.getLaunchTaskBehind();
Craig Mautner233ceee2014-05-09 17:05:11 -0700419 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700421 // This starts out true, since the initial state of an activity
422 // is that we have everything, and we shouldn't never consider it
423 // lacking in state to be removed if it dies.
424 haveState = true;
425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 if (aInfo != null) {
427 if (aInfo.targetActivity == null
428 || aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE
429 || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
430 realActivity = _intent.getComponent();
431 } else {
432 realActivity = new ComponentName(aInfo.packageName,
433 aInfo.targetActivity);
434 }
435 taskAffinity = aInfo.taskAffinity;
436 stateNotNeeded = (aInfo.flags&
437 ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700438 appInfo = aInfo.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 nonLocalizedLabel = aInfo.nonLocalizedLabel;
440 labelRes = aInfo.labelRes;
441 if (nonLocalizedLabel == null && labelRes == 0) {
442 ApplicationInfo app = aInfo.applicationInfo;
443 nonLocalizedLabel = app.nonLocalizedLabel;
444 labelRes = app.labelRes;
445 }
446 icon = aInfo.getIconResource();
Adam Powell04fe6eb2013-05-31 14:39:48 -0700447 logo = aInfo.getLogoResource();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 theme = aInfo.getThemeResource();
Dianne Hackborn247fe742011-01-08 17:25:57 -0800449 realTheme = theme;
450 if (realTheme == 0) {
451 realTheme = aInfo.applicationInfo.targetSdkVersion
452 < Build.VERSION_CODES.HONEYCOMB
453 ? android.R.style.Theme
454 : android.R.style.Theme_Holo;
455 }
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800456 if ((aInfo.flags&ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
457 windowFlags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
458 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0
460 && _caller != null
461 && (aInfo.applicationInfo.uid == Process.SYSTEM_UID
462 || aInfo.applicationInfo.uid == _caller.info.uid)) {
463 processName = _caller.processName;
464 } else {
465 processName = aInfo.processName;
466 }
467
468 if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
469 intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
470 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 packageName = aInfo.applicationInfo.packageName;
473 launchMode = aInfo.launchMode;
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700476 realTheme, com.android.internal.R.styleable.Window, userId);
Filip Gruszczynski23958c62015-02-23 18:05:27 -0800477 final boolean translucent = ent.array.getBoolean(
478 com.android.internal.R.styleable.Window_windowIsTranslucent, false)
479 || (!ent.array.hasValue(
480 com.android.internal.R.styleable.Window_windowIsTranslucent)
481 && ent.array.getBoolean(
482 com.android.internal.R.styleable.Window_windowSwipeToDismiss,
483 false));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 fullscreen = ent != null && !ent.array.getBoolean(
485 com.android.internal.R.styleable.Window_windowIsFloating, false)
Filip Gruszczynski23958c62015-02-23 18:05:27 -0800486 && !translucent;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800487 noDisplay = ent != null && ent.array.getBoolean(
488 com.android.internal.R.styleable.Window_windowNoDisplay, false);
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700489
Craig Mautner80259352013-09-28 12:35:25 -0700490 if ((!_componentSpecified || _launchedFromUid == Process.myUid()
Craig Mautner86d67a42013-05-14 10:34:38 -0700491 || _launchedFromUid == 0) &&
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700492 Intent.ACTION_MAIN.equals(_intent.getAction()) &&
493 _intent.hasCategory(Intent.CATEGORY_HOME) &&
494 _intent.getCategories().size() == 1 &&
495 _intent.getData() == null &&
496 _intent.getType() == null &&
Craig Mautner80259352013-09-28 12:35:25 -0700497 (intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 &&
498 isNotResolverActivity()) {
Craig Mautner86d67a42013-05-14 10:34:38 -0700499 // This sure looks like a home activity!
500 mActivityType = HOME_ACTIVITY_TYPE;
Craig Mautner80259352013-09-28 12:35:25 -0700501 } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) {
Craig Mautner86d67a42013-05-14 10:34:38 -0700502 mActivityType = RECENTS_ACTIVITY_TYPE;
503 } else {
504 mActivityType = APPLICATION_ACTIVITY_TYPE;
505 }
Daniel Sandler69a48172010-06-23 16:29:36 -0400506
507 immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 } else {
509 realActivity = null;
510 taskAffinity = null;
511 stateNotNeeded = false;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700512 appInfo = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 processName = null;
514 packageName = null;
515 fullscreen = true;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800516 noDisplay = false;
Craig Mautner86d67a42013-05-14 10:34:38 -0700517 mActivityType = APPLICATION_ACTIVITY_TYPE;
Daniel Sandler69a48172010-06-23 16:29:36 -0400518 immersive = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 }
520 }
521
Craig Mautnera228ae92014-07-09 05:44:55 -0700522 void setTask(TaskRecord newTask, TaskRecord taskToAffiliateWith) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700523 if (task != null && task.removeActivity(this)) {
Craig Mautner19d9bd52013-10-21 20:05:26 -0700524 if (task != newTask) {
Craig Mautner299f9602015-01-26 09:47:33 -0800525 task.stack.removeTask(task, "setTask");
Craig Mautner19d9bd52013-10-21 20:05:26 -0700526 } else {
527 Slog.d(TAG, "!!! REMOVE THIS LOG !!! setTask: nearly removed stack=" +
528 (newTask == null ? null : newTask.stack));
529 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700530 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700531 task = newTask;
Craig Mautnera228ae92014-07-09 05:44:55 -0700532 setTaskToAffiliateWith(taskToAffiliateWith);
533 }
534
535 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
536 if (taskToAffiliateWith != null &&
537 launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE &&
538 launchMode != ActivityInfo.LAUNCH_SINGLE_TASK) {
539 task.setTaskToAffiliateWith(taskToAffiliateWith);
540 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700541 }
542
Craig Mautner5eda9b32013-07-02 11:58:16 -0700543 boolean changeWindowTranslucency(boolean toOpaque) {
544 if (fullscreen == toOpaque) {
545 return false;
546 }
Craig Mautner4addfc52013-06-25 08:05:45 -0700547
Craig Mautner5eda9b32013-07-02 11:58:16 -0700548 // Keep track of the number of fullscreen activities in this task.
549 task.numFullscreen += toOpaque ? +1 : -1;
550
551 fullscreen = toOpaque;
552 return true;
Craig Mautner4addfc52013-06-25 08:05:45 -0700553 }
554
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700555 void putInHistory() {
556 if (!inHistory) {
557 inHistory = true;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700558 }
559 }
560
561 void takeFromHistory() {
562 if (inHistory) {
563 inHistory = false;
564 if (task != null && !finishing) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800565 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700566 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700567 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700568 }
569 }
570
571 boolean isInHistory() {
572 return inHistory;
573 }
574
Craig Mautner86d67a42013-05-14 10:34:38 -0700575 boolean isHomeActivity() {
576 return mActivityType == HOME_ACTIVITY_TYPE;
577 }
578
579 boolean isRecentsActivity() {
580 return mActivityType == RECENTS_ACTIVITY_TYPE;
581 }
582
583 boolean isApplicationActivity() {
584 return mActivityType == APPLICATION_ACTIVITY_TYPE;
585 }
586
Craig Mautner21d24a22014-04-23 11:45:37 -0700587 boolean isPersistable() {
Craig Mautner43e52ed2014-06-16 17:18:52 -0700588 return (info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY ||
589 info.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS) &&
590 (intent == null ||
591 (intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
Craig Mautner21d24a22014-04-23 11:45:37 -0700592 }
593
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800594 void makeFinishing() {
595 if (!finishing) {
Jose Lima34ff4922014-08-18 15:19:41 -0700596 if (this == task.stack.getVisibleBehindActivity()) {
597 // A finishing activity should not remain as visible in the background
598 mStackSupervisor.requestVisibleBehindLocked(this, false);
599 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800600 finishing = true;
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700601 if (stopped) {
602 clearOptionsLocked();
603 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800604 }
605 }
606
Dianne Hackborn7e269642010-08-25 19:50:20 -0700607 UriPermissionOwner getUriPermissionsLocked() {
608 if (uriPermissions == null) {
609 uriPermissions = new UriPermissionOwner(service, this);
610 }
611 return uriPermissions;
612 }
613
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700614 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615 int requestCode, int resultCode,
616 Intent resultData) {
617 ActivityResult r = new ActivityResult(from, resultWho,
John Spurlock8a985d22014-02-25 09:40:05 -0500618 requestCode, resultCode, resultData);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800620 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 }
622 results.add(r);
623 }
624
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700625 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 int requestCode) {
627 if (results != null) {
628 for (int i=results.size()-1; i>=0; i--) {
629 ActivityResult r = (ActivityResult)results.get(i);
630 if (r.mFrom != from) continue;
631 if (r.mResultWho == null) {
632 if (resultWho != null) continue;
633 } else {
634 if (!r.mResultWho.equals(resultWho)) continue;
635 }
636 if (r.mRequestCode != requestCode) continue;
637
638 results.remove(i);
639 }
640 }
641 }
642
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800643 void addNewIntentLocked(ReferrerIntent intent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 if (newIntents == null) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800645 newIntents = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800646 }
647 newIntents.add(intent);
648 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700649
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700650 /**
651 * Deliver a new Intent to an existing activity, so that its onNewIntent()
652 * method will be called at the proper time.
653 */
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800654 final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) {
Dianne Hackborn514074f2013-02-11 10:52:46 -0800655 // The activity now gets access to the data associated with this Intent.
656 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
Nicolas Prevotc6cf95c2014-05-29 11:30:36 +0100657 intent, getUriPermissionsLocked(), userId);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700658 // We want to immediately deliver the intent to the activity if
659 // it is currently the top resumed activity... however, if the
660 // device is sleeping, then all activities are stopped, so in that
661 // case we will deliver it if this is the current top activity on its
662 // stack.
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800663 final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
Craig Mautner86d67a42013-05-14 10:34:38 -0700664 boolean unsent = true;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700665 if ((state == ActivityState.RESUMED || (service.isSleeping()
Craig Mautnerd2328952013-03-05 12:46:26 -0800666 && task.stack.topRunningActivityLocked(null) == this))
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700667 && app != null && app.thread != null) {
668 try {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800669 ArrayList<ReferrerIntent> ar = new ArrayList<>(1);
670 ar.add(rintent);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800671 app.thread.scheduleNewIntent(ar, appToken);
Craig Mautner86d67a42013-05-14 10:34:38 -0700672 unsent = false;
Dianne Hackborn39792d22010-08-19 18:01:52 -0700673 } catch (RemoteException e) {
674 Slog.w(ActivityManagerService.TAG,
675 "Exception thrown sending new intent to " + this, e);
676 } catch (NullPointerException e) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700677 Slog.w(ActivityManagerService.TAG,
678 "Exception thrown sending new intent to " + this, e);
679 }
680 }
Craig Mautner86d67a42013-05-14 10:34:38 -0700681 if (unsent) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800682 addNewIntentLocked(rintent);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700683 }
684 }
685
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700686 void updateOptionsLocked(Bundle options) {
687 if (options != null) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700688 if (pendingOptions != null) {
689 pendingOptions.abort();
690 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700691 pendingOptions = new ActivityOptions(options);
692 }
693 }
694
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700695 void updateOptionsLocked(ActivityOptions options) {
696 if (options != null) {
697 if (pendingOptions != null) {
698 pendingOptions.abort();
699 }
700 pendingOptions = options;
701 }
702 }
703
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700704 void applyOptionsLocked() {
George Mount2c92c972014-03-20 09:38:23 -0700705 if (pendingOptions != null
706 && pendingOptions.getAnimationType() != ActivityOptions.ANIM_SCENE_TRANSITION) {
Michael Jurka21385cd2012-05-03 10:57:31 -0700707 final int animationType = pendingOptions.getAnimationType();
708 switch (animationType) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700709 case ActivityOptions.ANIM_CUSTOM:
710 service.mWindowManager.overridePendingAppTransition(
711 pendingOptions.getPackageName(),
712 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -0700713 pendingOptions.getCustomExitResId(),
714 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700715 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700716 case ActivityOptions.ANIM_SCALE_UP:
717 service.mWindowManager.overridePendingAppTransitionScaleUp(
718 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200719 pendingOptions.getWidth(), pendingOptions.getHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700720 if (intent.getSourceBounds() == null) {
721 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
722 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200723 pendingOptions.getStartX()+pendingOptions.getWidth(),
724 pendingOptions.getStartY()+pendingOptions.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700725 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700726 break;
Michael Jurka832cb222012-04-13 09:32:47 -0700727 case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
728 case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
729 boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700730 service.mWindowManager.overridePendingAppTransitionThumb(
731 pendingOptions.getThumbnail(),
732 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -0700733 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -0700734 scaleUp);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700735 if (intent.getSourceBounds() == null) {
736 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
737 pendingOptions.getStartY(),
738 pendingOptions.getStartX()
739 + pendingOptions.getThumbnail().getWidth(),
740 pendingOptions.getStartY()
741 + pendingOptions.getThumbnail().getHeight()));
742 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700743 break;
Winson Chunga4ccb862014-08-22 15:26:27 -0700744 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP:
745 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
746 service.mWindowManager.overridePendingAppTransitionAspectScaledThumb(
747 pendingOptions.getThumbnail(),
748 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200749 pendingOptions.getWidth(), pendingOptions.getHeight(),
Winson Chunga4ccb862014-08-22 15:26:27 -0700750 pendingOptions.getOnAnimationStartListener(),
751 (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP));
752 if (intent.getSourceBounds() == null) {
753 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
754 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200755 pendingOptions.getStartX() + pendingOptions.getWidth(),
756 pendingOptions.getStartY() + pendingOptions.getHeight()));
Winson Chunga4ccb862014-08-22 15:26:27 -0700757 }
758 break;
Craig Mautner233ceee2014-05-09 17:05:11 -0700759 default:
760 Slog.e(TAG, "applyOptionsLocked: Unknown animationType=" + animationType);
761 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700762 }
763 pendingOptions = null;
764 }
765 }
766
Adam Powellcfbe9be2013-11-06 14:58:58 -0800767 ActivityOptions getOptionsForTargetActivityLocked() {
768 return pendingOptions != null ? pendingOptions.forTargetActivity() : null;
769 }
770
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700771 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700772 if (pendingOptions != null) {
773 pendingOptions.abort();
774 pendingOptions = null;
775 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700776 }
777
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700778 ActivityOptions takeOptionsLocked() {
779 ActivityOptions opts = pendingOptions;
780 pendingOptions = null;
781 return opts;
782 }
783
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700784 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -0700785 if (uriPermissions != null) {
786 uriPermissions.removeUriPermissionsLocked();
787 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700788 }
789 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800790
791 void pauseKeyDispatchingLocked() {
792 if (!keysPaused) {
793 keysPaused = true;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800794 service.mWindowManager.pauseKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800795 }
796 }
797
798 void resumeKeyDispatchingLocked() {
799 if (keysPaused) {
800 keysPaused = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800801 service.mWindowManager.resumeKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800802 }
803 }
804
Winson Chung740c3ac2014-11-12 16:14:38 -0800805 void updateThumbnailLocked(Bitmap newThumbnail, CharSequence description) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700806 if (newThumbnail != null) {
807 if (ActivityManagerService.DEBUG_THUMBNAILS) Slog.i(ActivityManagerService.TAG,
808 "Setting thumbnail of " + this + " to " + newThumbnail);
Winson Chung096f36b2014-08-20 15:39:01 -0700809 boolean thumbnailUpdated = task.setLastThumbnail(newThumbnail);
810 if (thumbnailUpdated && isPersistable()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700811 mStackSupervisor.mService.notifyTaskPersisterLocked(task, false);
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700812 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700813 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700814 task.lastDescription = description;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700815 }
816
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700817 void startLaunchTickingLocked() {
818 if (ActivityManagerService.IS_USER_BUILD) {
819 return;
820 }
821 if (launchTickTime == 0) {
822 launchTickTime = SystemClock.uptimeMillis();
823 continueLaunchTickingLocked();
824 }
825 }
826
827 boolean continueLaunchTickingLocked() {
828 if (launchTickTime != 0) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800829 final ActivityStack stack = task.stack;
Craig Mautnerf7bfefb2013-05-16 17:30:44 -0700830 Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG, this);
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700831 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
832 stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
833 return true;
834 }
835 return false;
836 }
837
838 void finishLaunchTickingLocked() {
839 launchTickTime = 0;
Craig Mautnerd2328952013-03-05 12:46:26 -0800840 task.stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700841 }
842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843 // IApplicationToken
844
845 public boolean mayFreezeScreenLocked(ProcessRecord app) {
846 // Only freeze the screen if this activity is currently attached to
847 // an application, and that application is not blocked or unresponding.
848 // In any other case, we can't count on getting the screen unfrozen,
849 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -0800850 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800851 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
854 if (mayFreezeScreenLocked(app)) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800855 service.mWindowManager.startAppFreezingScreen(appToken, configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800856 }
857 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800859 public void stopFreezingScreenLocked(boolean force) {
860 if (force || frozenBeforeDestroy) {
861 frozenBeforeDestroy = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800862 service.mWindowManager.stopAppFreezingScreen(appToken, force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800863 }
864 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700865
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700866 public void reportFullyDrawnLocked() {
867 final long curTime = SystemClock.uptimeMillis();
868 if (displayStartTime != 0) {
869 reportLaunchTimeLocked(curTime);
870 }
871 if (fullyDrawnStartTime != 0) {
872 final ActivityStack stack = task.stack;
873 final long thisTime = curTime - fullyDrawnStartTime;
874 final long totalTime = stack.mFullyDrawnStartTime != 0
875 ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
876 if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -0700877 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700878 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME,
879 userId, System.identityHashCode(this), shortComponentName,
880 thisTime, totalTime);
881 StringBuilder sb = service.mStringBuilder;
882 sb.setLength(0);
883 sb.append("Fully drawn ");
884 sb.append(shortComponentName);
885 sb.append(": ");
886 TimeUtils.formatDuration(thisTime, sb);
887 if (thisTime != totalTime) {
888 sb.append(" (total ");
889 TimeUtils.formatDuration(totalTime, sb);
890 sb.append(")");
891 }
892 Log.i(ActivityManagerService.TAG, sb.toString());
893 }
894 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -0700895 //service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700896 }
897 fullyDrawnStartTime = 0;
898 stack.mFullyDrawnStartTime = 0;
899 }
900 }
901
902 private void reportLaunchTimeLocked(final long curTime) {
903 final ActivityStack stack = task.stack;
904 final long thisTime = curTime - displayStartTime;
905 final long totalTime = stack.mLaunchStartTime != 0
906 ? (curTime - stack.mLaunchStartTime) : thisTime;
907 if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -0700908 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700909 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
910 userId, System.identityHashCode(this), shortComponentName,
911 thisTime, totalTime);
912 StringBuilder sb = service.mStringBuilder;
913 sb.setLength(0);
914 sb.append("Displayed ");
915 sb.append(shortComponentName);
916 sb.append(": ");
917 TimeUtils.formatDuration(thisTime, sb);
918 if (thisTime != totalTime) {
919 sb.append(" (total ");
920 TimeUtils.formatDuration(totalTime, sb);
921 sb.append(")");
922 }
923 Log.i(ActivityManagerService.TAG, sb.toString());
924 }
925 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
926 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -0700927 //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700928 }
929 displayStartTime = 0;
930 stack.mLaunchStartTime = 0;
931 }
932
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700933 public void windowsDrawn() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 synchronized(service) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700935 if (displayStartTime != 0) {
936 reportLaunchTimeLocked(SystemClock.uptimeMillis());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 }
Dianne Hackborn6cfbb712014-09-17 12:47:35 -0700938 mStackSupervisor.sendWaitingVisibleReportLocked(this);
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700939 startTime = 0;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700940 finishLaunchTickingLocked();
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700941 if (task != null) {
942 task.hasBeenVisible = true;
943 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700944 }
945 }
946
947 public void windowsVisible() {
948 synchronized(service) {
Craig Mautnerce5f3cb2013-04-22 08:58:54 -0700949 mStackSupervisor.reportActivityVisibleLocked(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
951 ActivityManagerService.TAG, "windowsVisible(): " + this);
952 if (!nowVisible) {
953 nowVisible = true;
Dianne Hackborn50685602011-12-01 12:23:37 -0800954 lastVisibleTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 if (!idle) {
956 // Instead of doing the full stop routine here, let's just
957 // hide any activities we now can, and let them stop when
958 // the normal idle happens.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700959 mStackSupervisor.processStoppingActivitiesLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 } else {
961 // If this activity was already idle, then we now need to
962 // make sure we perform the full stop of any activities
963 // that are waiting to do so. This is because we won't
964 // do that while they are still waiting for this one to
965 // become visible.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700966 final int N = mStackSupervisor.mWaitingVisibleActivities.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800967 if (N > 0) {
968 for (int i=0; i<N; i++) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700969 ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 r.waitingVisible = false;
971 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
972 ActivityManagerService.TAG,
973 "Was waiting for visible: " + r);
974 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700975 mStackSupervisor.mWaitingVisibleActivities.clear();
Craig Mautnerf3333272013-04-22 10:55:53 -0700976 mStackSupervisor.scheduleIdleLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 }
978 }
979 service.scheduleAppGcsLocked();
980 }
981 }
982 }
983
984 public void windowsGone() {
985 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
986 ActivityManagerService.TAG, "windowsGone(): " + this);
987 nowVisible = false;
988 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700989
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700990 private ActivityRecord getWaitingHistoryRecordLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 // First find the real culprit... if we are waiting
992 // for another app to start, then we have paused dispatching
993 // for this activity.
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700994 ActivityRecord r = this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 if (r.waitingVisible) {
Craig Mautner8f2adcb2014-04-07 22:21:33 +0000996 final ActivityStack stack = mStackSupervisor.getFocusedStack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997 // Hmmm, who might we be waiting for?
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700998 r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800999 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -08001000 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 }
1002 // Both of those null? Fall back to 'this' again
1003 if (r == null) {
1004 r = this;
1005 }
1006 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001008 return r;
1009 }
1010
Jeff Brownbd181bb2013-09-10 16:44:24 -07001011 public boolean keyDispatchingTimedOut(String reason) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001012 ActivityRecord r;
Michael Wright7dd5bb12013-02-27 17:07:29 -08001013 ProcessRecord anrApp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 synchronized(service) {
Dianne Hackbornad5499d2010-03-29 18:08:45 -07001015 r = getWaitingHistoryRecordLocked();
Michael Wright7dd5bb12013-02-27 17:07:29 -08001016 anrApp = r != null ? r.app : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 }
Jeff Brownbd181bb2013-09-10 16:44:24 -07001018 return service.inputDispatchingTimedOut(anrApp, r, this, false, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001019 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001021 /** Returns the key dispatching timeout for this application token. */
1022 public long getKeyDispatchingTimeout() {
1023 synchronized(service) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001024 ActivityRecord r = getWaitingHistoryRecordLocked();
Michael Wright7dd5bb12013-02-27 17:07:29 -08001025 return ActivityManagerService.getInputDispatchingTimeoutLocked(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001026 }
1027 }
1028
1029 /**
1030 * This method will return true if the activity is either visible, is becoming visible, is
1031 * currently pausing, or is resumed.
1032 */
1033 public boolean isInterestingToUserLocked() {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001034 return visible || nowVisible || state == ActivityState.PAUSING ||
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 state == ActivityState.RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001036 }
1037
1038 public void setSleeping(boolean _sleeping) {
1039 if (sleeping == _sleeping) {
1040 return;
1041 }
1042 if (app != null && app.thread != null) {
1043 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -08001044 app.thread.scheduleSleeping(appToken, _sleeping);
Craig Mautner0eea92c2013-05-16 13:35:39 -07001045 if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
1046 mStackSupervisor.mGoingToSleepActivities.add(this);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001047 }
1048 sleeping = _sleeping;
1049 } catch (RemoteException e) {
Craig Mautner0eea92c2013-05-16 13:35:39 -07001050 Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001051 }
1052 }
1053 }
Craig Mautnerf81b90872013-02-26 13:02:43 -08001054
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001055 static void activityResumedLocked(IBinder token) {
1056 final ActivityRecord r = ActivityRecord.forToken(token);
1057 if (DEBUG_SAVED_STATE) Slog.i(TAG, "Resumed activity; dropping state of: " + r);
1058 r.icicle = null;
1059 r.haveState = false;
1060 }
1061
Craig Mautnerd2328952013-03-05 12:46:26 -08001062 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
1063 final ActivityRecord r = ActivityRecord.forToken(token);
1064 if (r == null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001065 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08001066 }
1067 final TaskRecord task = r.task;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001068 final int activityNdx = task.mActivities.indexOf(r);
1069 if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001070 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08001071 }
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001072 return task.taskId;
Craig Mautnerd2328952013-03-05 12:46:26 -08001073 }
1074
1075 static ActivityRecord isInStackLocked(IBinder token) {
1076 final ActivityRecord r = ActivityRecord.forToken(token);
1077 if (r != null) {
1078 return r.task.stack.isInStackLocked(token);
1079 }
1080 return null;
1081 }
1082
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001083 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -08001084 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
1085 if (r != null) {
1086 return r.task.stack;
1087 }
1088 return null;
1089 }
1090
Dianne Hackborn89ad4562014-08-24 16:45:38 -07001091 final boolean isDestroyable() {
1092 if (finishing || app == null || state == ActivityState.DESTROYING
1093 || state == ActivityState.DESTROYED) {
1094 // This would be redundant.
1095 return false;
1096 }
1097 if (task == null || task.stack == null || this == task.stack.mResumedActivity
1098 || this == task.stack.mPausingActivity || !haveState || !stopped) {
1099 // We're not ready for this kind of thing.
1100 return false;
1101 }
1102 if (visible) {
1103 // The user would notice this!
1104 return false;
1105 }
1106 return true;
1107 }
1108
Winson Chung3bad5cc02014-08-19 17:44:32 -07001109 private static String createImageFilename(long createTime, int taskId) {
1110 return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime +
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001111 TaskPersister.IMAGE_EXTENSION;
1112 }
1113
Craig Mautner648f69b2014-09-18 14:16:26 -07001114 void setTaskDescription(TaskDescription _taskDescription) {
1115 Bitmap icon;
1116 if (_taskDescription.getIconFilename() == null &&
1117 (icon = _taskDescription.getIcon()) != null) {
1118 final String iconFilename = createImageFilename(createTime, task.taskId);
1119 mStackSupervisor.mService.mTaskPersister.saveImage(icon, iconFilename);
1120 _taskDescription.setIconFilename(iconFilename);
1121 }
1122 taskDescription = _taskDescription;
1123 }
1124
Craig Mautner21d24a22014-04-23 11:45:37 -07001125 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
1126 out.attribute(null, ATTR_ID, String.valueOf(createTime));
1127 out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
1128 if (launchedFromPackage != null) {
1129 out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage);
1130 }
1131 if (resolvedType != null) {
1132 out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType);
1133 }
1134 out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified));
1135 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Winson Chung2cb86c72014-06-25 12:03:30 -07001136
Craig Mautner21d24a22014-04-23 11:45:37 -07001137 if (taskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001138 taskDescription.saveToXml(out);
Craig Mautner21d24a22014-04-23 11:45:37 -07001139 }
1140
1141 out.startTag(null, TAG_INTENT);
1142 intent.saveToXml(out);
1143 out.endTag(null, TAG_INTENT);
1144
1145 if (isPersistable() && persistentState != null) {
1146 out.startTag(null, TAG_PERSISTABLEBUNDLE);
1147 persistentState.saveToXml(out);
1148 out.endTag(null, TAG_PERSISTABLEBUNDLE);
1149 }
1150 }
1151
Wale Ogunwale92dd1ab2015-01-15 15:36:48 -08001152 static ActivityRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
1153 throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07001154 Intent intent = null;
1155 PersistableBundle persistentState = null;
1156 int launchedFromUid = 0;
1157 String launchedFromPackage = null;
1158 String resolvedType = null;
1159 boolean componentSpecified = false;
1160 int userId = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07001161 long createTime = -1;
1162 final int outerDepth = in.getDepth();
Winson Chung2cb86c72014-06-25 12:03:30 -07001163 TaskDescription taskDescription = new TaskDescription();
Craig Mautner21d24a22014-04-23 11:45:37 -07001164
1165 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1166 final String attrName = in.getAttributeName(attrNdx);
1167 final String attrValue = in.getAttributeValue(attrNdx);
Wale Ogunwale18795a22014-12-03 11:38:33 -08001168 if (DEBUG_PERSISTER || DEBUG_RESTORER) Slog.d(TaskPersister.TAG,
1169 "ActivityRecord: attribute name=" + attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001170 if (ATTR_ID.equals(attrName)) {
1171 createTime = Long.valueOf(attrValue);
1172 } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
1173 launchedFromUid = Integer.valueOf(attrValue);
1174 } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
1175 launchedFromPackage = attrValue;
1176 } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
1177 resolvedType = attrValue;
1178 } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
1179 componentSpecified = Boolean.valueOf(attrValue);
1180 } else if (ATTR_USERID.equals(attrName)) {
1181 userId = Integer.valueOf(attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001182 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1183 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001184 } else {
1185 Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName);
1186 }
1187 }
1188
1189 int event;
1190 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
1191 (event != XmlPullParser.END_TAG || in.getDepth() < outerDepth)) {
1192 if (event == XmlPullParser.START_TAG) {
1193 final String name = in.getName();
Wale Ogunwale18795a22014-12-03 11:38:33 -08001194 if (DEBUG_PERSISTER || DEBUG_RESTORER)
1195 Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001196 if (TAG_INTENT.equals(name)) {
1197 intent = Intent.restoreFromXml(in);
Wale Ogunwale18795a22014-12-03 11:38:33 -08001198 if (DEBUG_PERSISTER || DEBUG_RESTORER)
1199 Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07001200 } else if (TAG_PERSISTABLEBUNDLE.equals(name)) {
1201 persistentState = PersistableBundle.restoreFromXml(in);
Wale Ogunwale18795a22014-12-03 11:38:33 -08001202 if (DEBUG_PERSISTER || DEBUG_RESTORER) Slog.d(TaskPersister.TAG,
Craig Mautner21d24a22014-04-23 11:45:37 -07001203 "ActivityRecord: persistentState=" + persistentState);
1204 } else {
1205 Slog.w(TAG, "restoreActivity: unexpected name=" + name);
1206 XmlUtils.skipCurrentTag(in);
1207 }
1208 }
1209 }
1210
1211 if (intent == null) {
Craig Mautnere0129b32014-05-25 16:41:09 -07001212 throw new XmlPullParserException("restoreActivity error intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07001213 }
1214
1215 final ActivityManagerService service = stackSupervisor.mService;
1216 final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null,
Jeff Hao1b012d32014-08-20 10:35:34 -07001217 userId);
Craig Mautnere0129b32014-05-25 16:41:09 -07001218 if (aInfo == null) {
Craig Mautner77b04262014-06-27 15:22:12 -07001219 throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent +
1220 " resolvedType=" + resolvedType);
Craig Mautnere0129b32014-05-25 16:41:09 -07001221 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001222 final ActivityRecord r = new ActivityRecord(service, /*caller*/null, launchedFromUid,
1223 launchedFromPackage, intent, resolvedType, aInfo, service.getConfiguration(),
1224 null, null, 0, componentSpecified, stackSupervisor, null, null);
1225
1226 r.persistentState = persistentState;
Winson Chung2cb86c72014-06-25 12:03:30 -07001227 r.taskDescription = taskDescription;
Craig Mautner21d24a22014-04-23 11:45:37 -07001228 r.createTime = createTime;
1229
1230 return r;
1231 }
1232
1233 private static String activityTypeToString(int type) {
Craig Mautnerae7ecab2013-09-18 11:48:14 -07001234 switch (type) {
1235 case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE";
1236 case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE";
1237 case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE";
1238 default: return Integer.toString(type);
1239 }
1240 }
1241
Craig Mautnerf81b90872013-02-26 13:02:43 -08001242 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001244 if (stringName != null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001245 return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) +
Craig Mautnerf3333272013-04-22 10:55:53 -07001246 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001247 }
1248 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -08001249 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001250 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -07001251 sb.append(" u");
1252 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001253 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001254 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -08001255 stringName = sb.toString();
1256 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 }
1258}