blob: 85f49ed43ae4e5fd7b9a702329f68d60b1091563 [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
Craig Mautner21d24a22014-04-23 11:45:37 -070019import android.app.ActivityManager.TaskDescription;
Craig Mautnera0026042014-04-23 11:45:37 -070020import android.os.PersistableBundle;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -070021import android.os.Trace;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070022
Dianne Hackborn2d69d492012-04-06 16:24:14 -070023import com.android.internal.app.ResolverActivity;
Craig Mautner21d24a22014-04-23 11:45:37 -070024import com.android.internal.util.XmlUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import com.android.server.AttributeCache;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070026import com.android.server.am.ActivityStack.ActivityState;
Craig Mautner4a1cb222013-12-04 16:14:06 -080027import com.android.server.am.ActivityStackSupervisor.ActivityContainer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028
Dianne Hackborn7a2195c2012-03-19 17:38:00 -070029import android.app.ActivityOptions;
Craig Mautner05d6272ba2013-02-11 09:39:27 -080030import android.app.ResultInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.content.ComponentName;
32import android.content.Intent;
33import android.content.pm.ActivityInfo;
34import android.content.pm.ApplicationInfo;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -070035import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.content.res.Configuration;
37import android.graphics.Bitmap;
Dianne Hackbornd367ca82012-05-07 15:49:39 -070038import android.graphics.Rect;
Dianne Hackborn247fe742011-01-08 17:25:57 -080039import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.os.Bundle;
Dianne Hackbornbe707852011-11-11 14:32:10 -080041import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.os.Message;
43import android.os.Process;
Dianne Hackborn39792d22010-08-19 18:01:52 -070044import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import android.os.SystemClock;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070046import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import android.util.EventLog;
48import android.util.Log;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070049import android.util.Slog;
Dianne Hackborn0dad3642010-09-09 21:25:35 -070050import android.util.TimeUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import android.view.IApplicationToken;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -080052import android.view.WindowManager;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070053
Craig Mautner21d24a22014-04-23 11:45:37 -070054import org.xmlpull.v1.XmlPullParser;
55import org.xmlpull.v1.XmlPullParserException;
56import org.xmlpull.v1.XmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057
Craig Mautner21d24a22014-04-23 11:45:37 -070058import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import java.io.PrintWriter;
60import java.lang.ref.WeakReference;
61import java.util.ArrayList;
62import java.util.HashSet;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070063import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064
65/**
66 * An entry in the history stack, representing an activity.
67 */
Dianne Hackbornbe707852011-11-11 14:32:10 -080068final class ActivityRecord {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -070069 static final String TAG = ActivityManagerService.TAG;
70 static final boolean DEBUG_SAVED_STATE = ActivityStackSupervisor.DEBUG_SAVED_STATE;
Craig Mautner80259352013-09-28 12:35:25 -070071 final public static String RECENTS_PACKAGE_NAME = "com.android.systemui.recent";
Craig Mautnerb59dcfd2013-05-06 13:12:58 -070072
Craig Mautner21d24a22014-04-23 11:45:37 -070073 private static final String TAG_ACTIVITY = "activity";
74 private static final String ATTR_ID = "id";
75 private static final String TAG_INTENT = "intent";
76 private static final String ATTR_USERID = "user_id";
77 private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle";
78 private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid";
79 private static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package";
80 private static final String ATTR_RESOLVEDTYPE = "resolved_type";
81 private static final String ATTR_COMPONENTSPECIFIED = "component_specified";
Craig Mautner21d24a22014-04-23 11:45:37 -070082 private static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_";
83
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 final ActivityManagerService service; // owner
Dianne Hackbornbe707852011-11-11 14:32:10 -080085 final IApplicationToken.Stub appToken; // window manager token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 final ActivityInfo info; // all about me
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070087 final ApplicationInfo appInfo; // information about activity's app
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 final int launchedFromUid; // always the uid who started the activity.
Dianne Hackbornf265ea92013-01-31 15:00:51 -080089 final String launchedFromPackage; // always the package who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -070090 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 final Intent intent; // the original intent that generated us
92 final ComponentName realActivity; // the intent component, or target of an alias.
93 final String shortComponentName; // the short component name of the intent
94 final String resolvedType; // as per original caller;
95 final String packageName; // the package implementing intent's component
96 final String processName; // process where this component wants to run
97 final String taskAffinity; // as per ActivityInfo.taskAffinity
98 final boolean stateNotNeeded; // As per ActivityInfo.flags
Craig Mautner4addfc52013-06-25 08:05:45 -070099 boolean fullscreen; // covers the full screen?
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800100 final boolean noDisplay; // activity is not displayed?
The Android Open Source Project4df24232009-03-05 14:34:35 -0800101 final boolean componentSpecified; // did caller specifiy an explicit component?
Craig Mautner86d67a42013-05-14 10:34:38 -0700102
103 static final int APPLICATION_ACTIVITY_TYPE = 0;
104 static final int HOME_ACTIVITY_TYPE = 1;
105 static final int RECENTS_ACTIVITY_TYPE = 2;
Craig Mautner2c1faed2013-07-23 12:56:02 -0700106 int mActivityType;
Craig Mautner86d67a42013-05-14 10:34:38 -0700107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 CharSequence nonLocalizedLabel; // the label information from the package mgr.
109 int labelRes; // the label information from the package mgr.
110 int icon; // resource identifier of activity's icon.
Adam Powell04fe6eb2013-05-31 14:39:48 -0700111 int logo; // resource identifier of activity's logo.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 int theme; // resource identifier of activity's theme.
Dianne Hackborn247fe742011-01-08 17:25:57 -0800113 int realTheme; // actual theme resource we will use, never 0.
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800114 int windowFlags; // custom window flags for preview window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 TaskRecord task; // the task this is in.
Craig Mautner21d24a22014-04-23 11:45:37 -0700116 long createTime = System.currentTimeMillis();
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700117 long displayStartTime; // when we started launching this activity
118 long fullyDrawnStartTime; // when we started launching this activity
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700119 long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -0800120 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700121 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700122 long pauseTime; // last time we started pausing the activity
123 long launchTickTime; // base time for launch tick messages
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 Configuration configuration; // configuration activity was last running in
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700125 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700126 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 final String resultWho; // additional identifier for use by resultTo.
128 final int requestCode; // code given by requester (resultTo)
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800129 ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800131 ArrayList<Intent> newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700132 ActivityOptions pendingOptions; // most recently given options
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700134 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700135 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700136 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 Bundle icicle; // last saved activity state
Craig Mautnera0026042014-04-23 11:45:37 -0700138 PersistableBundle persistentState; // last persistently saved activity state
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 boolean frontOfTask; // is this the root activity of its task?
140 boolean launchFailed; // set if a launched failed, to abort on 2nd try
141 boolean haveState; // have we gotten the last activity state?
142 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700143 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 boolean finishing; // activity in pending finish list?
145 boolean configDestroy; // need to destroy due to config change?
146 int configChangeFlags; // which config values have changed
147 boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 int launchMode; // the launch mode activity attribute.
149 boolean visible; // does this activity's window need to be shown?
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800150 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 boolean waitingVisible; // true if waiting for a new act to become vis
152 boolean nowVisible; // is this activity's window visible?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 boolean idle; // has the activity gone idle?
154 boolean hasBeenLaunched;// has this activity ever been launched?
155 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400156 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400157 boolean forceNewConfig; // force re-create with new config next time
Dianne Hackborn07981492013-01-28 11:36:23 -0800158 int launchCount; // count of launches since last state
159 long lastLaunchTime; // time of last lauch of this activity
Craig Mautnerf4c909b2014-04-17 18:39:38 -0700160 ArrayList<ActivityContainer> mChildContainers = new ArrayList<ActivityContainer>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700162 String stringName; // for caching of toString().
Craig Mautnerde4ef022013-04-07 19:01:33 -0700163
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700164 private boolean inHistory; // are we in the history stack?
Craig Mautnerde4ef022013-04-07 19:01:33 -0700165 final ActivityStackSupervisor mStackSupervisor;
Craig Mautnera61bc652013-10-28 15:43:18 -0700166 boolean mStartingWindowShown = false;
Craig Mautnere0a38842013-12-16 16:14:02 -0800167 ActivityContainer mInitialActivityContainer;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700168
Craig Mautner21d24a22014-04-23 11:45:37 -0700169 TaskDescription taskDescription; // the recents information for this activity
Craig Mautnerbb742462014-07-07 15:28:55 -0700170 boolean mLaunchTaskBehind; // this activity is actively being launched with
171 // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed.
Craig Mautner2fbd7542014-03-21 09:34:07 -0700172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700174 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700175 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
176 pw.print(" processName="); pw.println(processName);
177 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Craig Mautnere11f2b72013-04-01 12:37:17 -0700178 pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800179 pw.print(" userId="); pw.println(userId);
180 pw.print(prefix); pw.print("app="); pw.println(app);
181 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700182 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
183 pw.print(" task="); pw.println(task);
184 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700185 pw.print(prefix); pw.print("realActivity=");
186 pw.println(realActivity.flattenToShortString());
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700187 if (appInfo != null) {
188 pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir);
189 if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) {
190 pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir);
191 }
192 pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800193 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700194 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
195 pw.print(" componentSpecified="); pw.print(componentSpecified);
Craig Mautner86d67a42013-05-14 10:34:38 -0700196 pw.print(" mActivityType="); pw.println(mActivityType);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800197 pw.print(prefix); pw.print("compat="); pw.print(compat);
198 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
199 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
200 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Dianne Hackborne17aeb32011-04-07 15:11:57 -0700201 pw.print(prefix); pw.print("config="); pw.println(configuration);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700202 if (resultTo != null || resultWho != null) {
203 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
204 pw.print(" resultWho="); pw.print(resultWho);
205 pw.print(" resultCode="); pw.println(requestCode);
206 }
Craig Mautneree2e45a2014-06-27 12:10:03 -0700207 if (taskDescription.getIcon() != null || taskDescription.getLabel() != null ||
208 taskDescription.getPrimaryColor() != 0) {
209 pw.print(prefix); pw.print("taskDescription:");
210 pw.print(" icon="); pw.print(taskDescription.getIcon());
211 pw.print(" label=\""); pw.print(taskDescription.getLabel()); pw.print("\"");
212 pw.print(" color=");
213 pw.println(Integer.toHexString(taskDescription.getPrimaryColor()));
214 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700215 if (results != null) {
216 pw.print(prefix); pw.print("results="); pw.println(results);
217 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700218 if (pendingResults != null && pendingResults.size() > 0) {
219 pw.print(prefix); pw.println("Pending Results:");
220 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
221 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
222 pw.print(prefix); pw.print(" - ");
223 if (pir == null) {
224 pw.println("null");
225 } else {
226 pw.println(pir);
227 pir.dump(pw, prefix + " ");
228 }
229 }
230 }
231 if (newIntents != null && newIntents.size() > 0) {
232 pw.print(prefix); pw.println("Pending New Intents:");
233 for (int i=0; i<newIntents.size(); i++) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800234 Intent intent = newIntents.get(i);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700235 pw.print(prefix); pw.print(" - ");
236 if (intent == null) {
237 pw.println("null");
238 } else {
239 pw.println(intent.toShortString(false, true, false, true));
240 }
241 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700242 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700243 if (pendingOptions != null) {
244 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
245 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700246 if (uriPermissions != null) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700247 uriPermissions.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700248 }
249 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800250 pw.print(" launchCount="); pw.print(launchCount);
251 pw.print(" lastLaunchTime=");
252 if (lastLaunchTime == 0) pw.print("0");
253 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
254 pw.println();
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700255 pw.print(prefix); pw.print("haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700256 pw.print(" icicle="); pw.println(icicle);
257 pw.print(prefix); pw.print("state="); pw.print(state);
258 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700259 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700260 pw.print(" finishing="); pw.println(finishing);
261 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
262 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700263 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800264 pw.print(" sleeping="); pw.print(sleeping);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700265 pw.print(" idle="); pw.println(idle);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800266 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
267 pw.print(" noDisplay="); pw.print(noDisplay);
268 pw.print(" immersive="); pw.print(immersive);
269 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800270 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400271 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700272 pw.print(prefix); pw.print("mActivityType=");
273 pw.println(activityTypeToString(mActivityType));
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700274 if (displayStartTime != 0 || startTime != 0) {
275 pw.print(prefix); pw.print("displayStartTime=");
276 if (displayStartTime == 0) pw.print("0");
277 else TimeUtils.formatDuration(displayStartTime, now, pw);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700278 pw.print(" startTime=");
279 if (startTime == 0) pw.print("0");
280 else TimeUtils.formatDuration(startTime, now, pw);
281 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700282 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800283 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700284 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800285 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700286 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700287 if (lastVisibleTime == 0) pw.print("0");
288 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
289 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700290 }
291 if (configDestroy || configChangeFlags != 0) {
292 pw.print(prefix); pw.print("configDestroy="); pw.print(configDestroy);
293 pw.print(" configChangeFlags=");
294 pw.println(Integer.toHexString(configChangeFlags));
295 }
296 if (connections != null) {
297 pw.print(prefix); pw.print("connections="); pw.println(connections);
298 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299 }
300
Dianne Hackbornbe707852011-11-11 14:32:10 -0800301 static class Token extends IApplicationToken.Stub {
302 final WeakReference<ActivityRecord> weakActivity;
303
304 Token(ActivityRecord activity) {
305 weakActivity = new WeakReference<ActivityRecord>(activity);
306 }
307
Craig Mautnerde4ef022013-04-07 19:01:33 -0700308 @Override public void windowsDrawn() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800309 ActivityRecord activity = weakActivity.get();
310 if (activity != null) {
311 activity.windowsDrawn();
312 }
313 }
314
Craig Mautnerde4ef022013-04-07 19:01:33 -0700315 @Override public void windowsVisible() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800316 ActivityRecord activity = weakActivity.get();
317 if (activity != null) {
318 activity.windowsVisible();
319 }
320 }
321
Craig Mautnerde4ef022013-04-07 19:01:33 -0700322 @Override public void windowsGone() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800323 ActivityRecord activity = weakActivity.get();
324 if (activity != null) {
325 activity.windowsGone();
326 }
327 }
328
Jeff Brownbd181bb2013-09-10 16:44:24 -0700329 @Override public boolean keyDispatchingTimedOut(String reason) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800330 ActivityRecord activity = weakActivity.get();
Jeff Brownbd181bb2013-09-10 16:44:24 -0700331 return activity != null && activity.keyDispatchingTimedOut(reason);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800332 }
333
Craig Mautnerde4ef022013-04-07 19:01:33 -0700334 @Override public long getKeyDispatchingTimeout() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800335 ActivityRecord activity = weakActivity.get();
336 if (activity != null) {
337 return activity.getKeyDispatchingTimeout();
338 }
339 return 0;
340 }
341
Craig Mautnerde4ef022013-04-07 19:01:33 -0700342 @Override
Dianne Hackbornbe707852011-11-11 14:32:10 -0800343 public String toString() {
344 StringBuilder sb = new StringBuilder(128);
345 sb.append("Token{");
346 sb.append(Integer.toHexString(System.identityHashCode(this)));
347 sb.append(' ');
348 sb.append(weakActivity.get());
349 sb.append('}');
350 return sb.toString();
351 }
352 }
353
354 static ActivityRecord forToken(IBinder token) {
355 try {
356 return token != null ? ((Token)token).weakActivity.get() : null;
357 } catch (ClassCastException e) {
358 Slog.w(ActivityManagerService.TAG, "Bad activity token: " + token, e);
359 return null;
360 }
361 }
362
Craig Mautnerac6f8432013-07-17 13:24:59 -0700363 boolean isNotResolverActivity() {
364 return !ResolverActivity.class.getName().equals(realActivity.getClassName());
365 }
366
Craig Mautnerd2328952013-03-05 12:46:26 -0800367 ActivityRecord(ActivityManagerService _service, ProcessRecord _caller,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800368 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700370 ActivityRecord _resultTo, String _resultWho, int _reqCode,
Craig Mautnere0a38842013-12-16 16:14:02 -0800371 boolean _componentSpecified, ActivityStackSupervisor supervisor,
Craig Mautner233ceee2014-05-09 17:05:11 -0700372 ActivityContainer container, Bundle options) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 service = _service;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800374 appToken = new Token(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 info = aInfo;
376 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800377 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700378 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 intent = _intent;
380 shortComponentName = _intent.getComponent().flattenToShortString();
381 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800382 componentSpecified = _componentSpecified;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 configuration = _configuration;
384 resultTo = _resultTo;
385 resultWho = _resultWho;
386 requestCode = _reqCode;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700387 state = ActivityState.INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 frontOfTask = false;
389 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700391 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 finishing = false;
393 configDestroy = false;
394 keysPaused = false;
395 inHistory = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 visible = true;
397 waitingVisible = false;
398 nowVisible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 idle = false;
400 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700401 mStackSupervisor = supervisor;
Craig Mautnere0a38842013-12-16 16:14:02 -0800402 mInitialActivityContainer = container;
Craig Mautner233ceee2014-05-09 17:05:11 -0700403 if (options != null) {
404 pendingOptions = new ActivityOptions(options);
Craig Mautnerbb742462014-07-07 15:28:55 -0700405 mLaunchTaskBehind = pendingOptions.getLaunchTaskBehind();
Craig Mautner233ceee2014-05-09 17:05:11 -0700406 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700408 // This starts out true, since the initial state of an activity
409 // is that we have everything, and we shouldn't never consider it
410 // lacking in state to be removed if it dies.
411 haveState = true;
412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 if (aInfo != null) {
414 if (aInfo.targetActivity == null
415 || aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE
416 || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
417 realActivity = _intent.getComponent();
418 } else {
419 realActivity = new ComponentName(aInfo.packageName,
420 aInfo.targetActivity);
421 }
422 taskAffinity = aInfo.taskAffinity;
423 stateNotNeeded = (aInfo.flags&
424 ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700425 appInfo = aInfo.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 nonLocalizedLabel = aInfo.nonLocalizedLabel;
427 labelRes = aInfo.labelRes;
428 if (nonLocalizedLabel == null && labelRes == 0) {
429 ApplicationInfo app = aInfo.applicationInfo;
430 nonLocalizedLabel = app.nonLocalizedLabel;
431 labelRes = app.labelRes;
432 }
433 icon = aInfo.getIconResource();
Adam Powell04fe6eb2013-05-31 14:39:48 -0700434 logo = aInfo.getLogoResource();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 theme = aInfo.getThemeResource();
Dianne Hackborn247fe742011-01-08 17:25:57 -0800436 realTheme = theme;
437 if (realTheme == 0) {
438 realTheme = aInfo.applicationInfo.targetSdkVersion
439 < Build.VERSION_CODES.HONEYCOMB
440 ? android.R.style.Theme
441 : android.R.style.Theme_Holo;
442 }
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800443 if ((aInfo.flags&ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
444 windowFlags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
445 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0
447 && _caller != null
448 && (aInfo.applicationInfo.uid == Process.SYSTEM_UID
449 || aInfo.applicationInfo.uid == _caller.info.uid)) {
450 processName = _caller.processName;
451 } else {
452 processName = aInfo.processName;
453 }
454
455 if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
456 intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
457 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 packageName = aInfo.applicationInfo.packageName;
460 launchMode = aInfo.launchMode;
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700463 realTheme, com.android.internal.R.styleable.Window, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 fullscreen = ent != null && !ent.array.getBoolean(
465 com.android.internal.R.styleable.Window_windowIsFloating, false)
466 && !ent.array.getBoolean(
467 com.android.internal.R.styleable.Window_windowIsTranslucent, false);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800468 noDisplay = ent != null && ent.array.getBoolean(
469 com.android.internal.R.styleable.Window_windowNoDisplay, false);
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700470
Craig Mautner80259352013-09-28 12:35:25 -0700471 if ((!_componentSpecified || _launchedFromUid == Process.myUid()
Craig Mautner86d67a42013-05-14 10:34:38 -0700472 || _launchedFromUid == 0) &&
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700473 Intent.ACTION_MAIN.equals(_intent.getAction()) &&
474 _intent.hasCategory(Intent.CATEGORY_HOME) &&
475 _intent.getCategories().size() == 1 &&
476 _intent.getData() == null &&
477 _intent.getType() == null &&
Craig Mautner80259352013-09-28 12:35:25 -0700478 (intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 &&
479 isNotResolverActivity()) {
Craig Mautner86d67a42013-05-14 10:34:38 -0700480 // This sure looks like a home activity!
481 mActivityType = HOME_ACTIVITY_TYPE;
Craig Mautner80259352013-09-28 12:35:25 -0700482 } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) {
Craig Mautner86d67a42013-05-14 10:34:38 -0700483 mActivityType = RECENTS_ACTIVITY_TYPE;
484 } else {
485 mActivityType = APPLICATION_ACTIVITY_TYPE;
486 }
Daniel Sandler69a48172010-06-23 16:29:36 -0400487
488 immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 } else {
490 realActivity = null;
491 taskAffinity = null;
492 stateNotNeeded = false;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700493 appInfo = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 processName = null;
495 packageName = null;
496 fullscreen = true;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800497 noDisplay = false;
Craig Mautner86d67a42013-05-14 10:34:38 -0700498 mActivityType = APPLICATION_ACTIVITY_TYPE;
Daniel Sandler69a48172010-06-23 16:29:36 -0400499 immersive = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 }
501 }
502
Craig Mautnera228ae92014-07-09 05:44:55 -0700503 void setTask(TaskRecord newTask, TaskRecord taskToAffiliateWith) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700504 if (task != null && task.removeActivity(this)) {
Craig Mautner19d9bd52013-10-21 20:05:26 -0700505 if (task != newTask) {
Craig Mautner41db4a72014-05-07 17:20:56 -0700506 task.stack.removeTask(task);
Craig Mautner19d9bd52013-10-21 20:05:26 -0700507 } else {
508 Slog.d(TAG, "!!! REMOVE THIS LOG !!! setTask: nearly removed stack=" +
509 (newTask == null ? null : newTask.stack));
510 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700511 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700512 task = newTask;
Craig Mautnera228ae92014-07-09 05:44:55 -0700513 setTaskToAffiliateWith(taskToAffiliateWith);
514 }
515
516 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
517 if (taskToAffiliateWith != null &&
518 launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE &&
519 launchMode != ActivityInfo.LAUNCH_SINGLE_TASK) {
520 task.setTaskToAffiliateWith(taskToAffiliateWith);
521 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700522 }
523
Craig Mautner5eda9b32013-07-02 11:58:16 -0700524 boolean changeWindowTranslucency(boolean toOpaque) {
525 if (fullscreen == toOpaque) {
526 return false;
527 }
Craig Mautner4addfc52013-06-25 08:05:45 -0700528
Craig Mautner5eda9b32013-07-02 11:58:16 -0700529 // Keep track of the number of fullscreen activities in this task.
530 task.numFullscreen += toOpaque ? +1 : -1;
531
532 fullscreen = toOpaque;
533 return true;
Craig Mautner4addfc52013-06-25 08:05:45 -0700534 }
535
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700536 void putInHistory() {
537 if (!inHistory) {
538 inHistory = true;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700539 }
540 }
541
542 void takeFromHistory() {
543 if (inHistory) {
544 inHistory = false;
545 if (task != null && !finishing) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800546 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700547 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700548 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700549 }
550 }
551
552 boolean isInHistory() {
553 return inHistory;
554 }
555
Craig Mautner86d67a42013-05-14 10:34:38 -0700556 boolean isHomeActivity() {
557 return mActivityType == HOME_ACTIVITY_TYPE;
558 }
559
560 boolean isRecentsActivity() {
561 return mActivityType == RECENTS_ACTIVITY_TYPE;
562 }
563
564 boolean isApplicationActivity() {
565 return mActivityType == APPLICATION_ACTIVITY_TYPE;
566 }
567
Craig Mautner21d24a22014-04-23 11:45:37 -0700568 boolean isPersistable() {
Craig Mautner43e52ed2014-06-16 17:18:52 -0700569 return (info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY ||
570 info.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS) &&
571 (intent == null ||
572 (intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
Craig Mautner21d24a22014-04-23 11:45:37 -0700573 }
574
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800575 void makeFinishing() {
576 if (!finishing) {
577 finishing = true;
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700578 if (stopped) {
579 clearOptionsLocked();
580 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800581 }
582 }
583
Dianne Hackborn7e269642010-08-25 19:50:20 -0700584 UriPermissionOwner getUriPermissionsLocked() {
585 if (uriPermissions == null) {
586 uriPermissions = new UriPermissionOwner(service, this);
587 }
588 return uriPermissions;
589 }
590
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700591 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 int requestCode, int resultCode,
593 Intent resultData) {
594 ActivityResult r = new ActivityResult(from, resultWho,
John Spurlock8a985d22014-02-25 09:40:05 -0500595 requestCode, resultCode, resultData);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800597 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 }
599 results.add(r);
600 }
601
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700602 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 int requestCode) {
604 if (results != null) {
605 for (int i=results.size()-1; i>=0; i--) {
606 ActivityResult r = (ActivityResult)results.get(i);
607 if (r.mFrom != from) continue;
608 if (r.mResultWho == null) {
609 if (resultWho != null) continue;
610 } else {
611 if (!r.mResultWho.equals(resultWho)) continue;
612 }
613 if (r.mRequestCode != requestCode) continue;
614
615 results.remove(i);
616 }
617 }
618 }
619
620 void addNewIntentLocked(Intent intent) {
621 if (newIntents == null) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800622 newIntents = new ArrayList<Intent>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 }
624 newIntents.add(intent);
625 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700626
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700627 /**
628 * Deliver a new Intent to an existing activity, so that its onNewIntent()
629 * method will be called at the proper time.
630 */
Dianne Hackborn39792d22010-08-19 18:01:52 -0700631 final void deliverNewIntentLocked(int callingUid, Intent intent) {
Dianne Hackborn514074f2013-02-11 10:52:46 -0800632 // The activity now gets access to the data associated with this Intent.
633 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
Nicolas Prevotc6cf95c2014-05-29 11:30:36 +0100634 intent, getUriPermissionsLocked(), userId);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700635 // We want to immediately deliver the intent to the activity if
636 // it is currently the top resumed activity... however, if the
637 // device is sleeping, then all activities are stopped, so in that
638 // case we will deliver it if this is the current top activity on its
639 // stack.
Craig Mautner86d67a42013-05-14 10:34:38 -0700640 boolean unsent = true;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700641 if ((state == ActivityState.RESUMED || (service.isSleeping()
Craig Mautnerd2328952013-03-05 12:46:26 -0800642 && task.stack.topRunningActivityLocked(null) == this))
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700643 && app != null && app.thread != null) {
644 try {
645 ArrayList<Intent> ar = new ArrayList<Intent>();
Dianne Hackborn39792d22010-08-19 18:01:52 -0700646 intent = new Intent(intent);
647 ar.add(intent);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800648 app.thread.scheduleNewIntent(ar, appToken);
Craig Mautner86d67a42013-05-14 10:34:38 -0700649 unsent = false;
Dianne Hackborn39792d22010-08-19 18:01:52 -0700650 } catch (RemoteException e) {
651 Slog.w(ActivityManagerService.TAG,
652 "Exception thrown sending new intent to " + this, e);
653 } catch (NullPointerException e) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700654 Slog.w(ActivityManagerService.TAG,
655 "Exception thrown sending new intent to " + this, e);
656 }
657 }
Craig Mautner86d67a42013-05-14 10:34:38 -0700658 if (unsent) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700659 addNewIntentLocked(new Intent(intent));
660 }
661 }
662
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700663 void updateOptionsLocked(Bundle options) {
664 if (options != null) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700665 if (pendingOptions != null) {
666 pendingOptions.abort();
667 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700668 pendingOptions = new ActivityOptions(options);
669 }
670 }
671
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700672 void updateOptionsLocked(ActivityOptions options) {
673 if (options != null) {
674 if (pendingOptions != null) {
675 pendingOptions.abort();
676 }
677 pendingOptions = options;
678 }
679 }
680
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700681 void applyOptionsLocked() {
George Mount2c92c972014-03-20 09:38:23 -0700682 if (pendingOptions != null
683 && pendingOptions.getAnimationType() != ActivityOptions.ANIM_SCENE_TRANSITION) {
Michael Jurka21385cd2012-05-03 10:57:31 -0700684 final int animationType = pendingOptions.getAnimationType();
685 switch (animationType) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700686 case ActivityOptions.ANIM_CUSTOM:
687 service.mWindowManager.overridePendingAppTransition(
688 pendingOptions.getPackageName(),
689 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -0700690 pendingOptions.getCustomExitResId(),
691 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700692 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700693 case ActivityOptions.ANIM_SCALE_UP:
694 service.mWindowManager.overridePendingAppTransitionScaleUp(
695 pendingOptions.getStartX(), pendingOptions.getStartY(),
696 pendingOptions.getStartWidth(), pendingOptions.getStartHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700697 if (intent.getSourceBounds() == null) {
698 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
699 pendingOptions.getStartY(),
700 pendingOptions.getStartX()+pendingOptions.getStartWidth(),
701 pendingOptions.getStartY()+pendingOptions.getStartHeight()));
702 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700703 break;
Michael Jurka832cb222012-04-13 09:32:47 -0700704 case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
705 case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
706 boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700707 service.mWindowManager.overridePendingAppTransitionThumb(
708 pendingOptions.getThumbnail(),
709 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -0700710 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -0700711 scaleUp);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700712 if (intent.getSourceBounds() == null) {
713 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
714 pendingOptions.getStartY(),
715 pendingOptions.getStartX()
716 + pendingOptions.getThumbnail().getWidth(),
717 pendingOptions.getStartY()
718 + pendingOptions.getThumbnail().getHeight()));
719 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700720 break;
Craig Mautner233ceee2014-05-09 17:05:11 -0700721 default:
722 Slog.e(TAG, "applyOptionsLocked: Unknown animationType=" + animationType);
723 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700724 }
725 pendingOptions = null;
726 }
727 }
728
Adam Powellcfbe9be2013-11-06 14:58:58 -0800729 ActivityOptions getOptionsForTargetActivityLocked() {
730 return pendingOptions != null ? pendingOptions.forTargetActivity() : null;
731 }
732
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700733 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700734 if (pendingOptions != null) {
735 pendingOptions.abort();
736 pendingOptions = null;
737 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700738 }
739
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700740 ActivityOptions takeOptionsLocked() {
741 ActivityOptions opts = pendingOptions;
742 pendingOptions = null;
743 return opts;
744 }
745
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700746 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -0700747 if (uriPermissions != null) {
748 uriPermissions.removeUriPermissionsLocked();
749 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700750 }
751 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752
753 void pauseKeyDispatchingLocked() {
754 if (!keysPaused) {
755 keysPaused = true;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800756 service.mWindowManager.pauseKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 }
758 }
759
760 void resumeKeyDispatchingLocked() {
761 if (keysPaused) {
762 keysPaused = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800763 service.mWindowManager.resumeKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 }
765 }
766
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700767 void updateThumbnail(Bitmap newThumbnail, CharSequence description) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700768 if (newThumbnail != null) {
769 if (ActivityManagerService.DEBUG_THUMBNAILS) Slog.i(ActivityManagerService.TAG,
770 "Setting thumbnail of " + this + " to " + newThumbnail);
771 task.setLastThumbnail(newThumbnail);
772 if (isPersistable()) {
773 mStackSupervisor.mService.notifyTaskPersisterLocked(task, false);
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700774 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700775 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700776 task.lastDescription = description;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700777 }
778
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700779 void startLaunchTickingLocked() {
780 if (ActivityManagerService.IS_USER_BUILD) {
781 return;
782 }
783 if (launchTickTime == 0) {
784 launchTickTime = SystemClock.uptimeMillis();
785 continueLaunchTickingLocked();
786 }
787 }
788
789 boolean continueLaunchTickingLocked() {
790 if (launchTickTime != 0) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800791 final ActivityStack stack = task.stack;
Craig Mautnerf7bfefb2013-05-16 17:30:44 -0700792 Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG, this);
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700793 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
794 stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
795 return true;
796 }
797 return false;
798 }
799
800 void finishLaunchTickingLocked() {
801 launchTickTime = 0;
Craig Mautnerd2328952013-03-05 12:46:26 -0800802 task.stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700803 }
804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 // IApplicationToken
806
807 public boolean mayFreezeScreenLocked(ProcessRecord app) {
808 // Only freeze the screen if this activity is currently attached to
809 // an application, and that application is not blocked or unresponding.
810 // In any other case, we can't count on getting the screen unfrozen,
811 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -0800812 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800815 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
816 if (mayFreezeScreenLocked(app)) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800817 service.mWindowManager.startAppFreezingScreen(appToken, configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800818 }
819 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 public void stopFreezingScreenLocked(boolean force) {
822 if (force || frozenBeforeDestroy) {
823 frozenBeforeDestroy = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800824 service.mWindowManager.stopAppFreezingScreen(appToken, force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 }
826 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700827
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700828 public void reportFullyDrawnLocked() {
829 final long curTime = SystemClock.uptimeMillis();
830 if (displayStartTime != 0) {
831 reportLaunchTimeLocked(curTime);
832 }
833 if (fullyDrawnStartTime != 0) {
834 final ActivityStack stack = task.stack;
835 final long thisTime = curTime - fullyDrawnStartTime;
836 final long totalTime = stack.mFullyDrawnStartTime != 0
837 ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
838 if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -0700839 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700840 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME,
841 userId, System.identityHashCode(this), shortComponentName,
842 thisTime, totalTime);
843 StringBuilder sb = service.mStringBuilder;
844 sb.setLength(0);
845 sb.append("Fully drawn ");
846 sb.append(shortComponentName);
847 sb.append(": ");
848 TimeUtils.formatDuration(thisTime, sb);
849 if (thisTime != totalTime) {
850 sb.append(" (total ");
851 TimeUtils.formatDuration(totalTime, sb);
852 sb.append(")");
853 }
854 Log.i(ActivityManagerService.TAG, sb.toString());
855 }
856 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -0700857 //service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700858 }
859 fullyDrawnStartTime = 0;
860 stack.mFullyDrawnStartTime = 0;
861 }
862 }
863
864 private void reportLaunchTimeLocked(final long curTime) {
865 final ActivityStack stack = task.stack;
866 final long thisTime = curTime - displayStartTime;
867 final long totalTime = stack.mLaunchStartTime != 0
868 ? (curTime - stack.mLaunchStartTime) : thisTime;
869 if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -0700870 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700871 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
872 userId, System.identityHashCode(this), shortComponentName,
873 thisTime, totalTime);
874 StringBuilder sb = service.mStringBuilder;
875 sb.setLength(0);
876 sb.append("Displayed ");
877 sb.append(shortComponentName);
878 sb.append(": ");
879 TimeUtils.formatDuration(thisTime, sb);
880 if (thisTime != totalTime) {
881 sb.append(" (total ");
882 TimeUtils.formatDuration(totalTime, sb);
883 sb.append(")");
884 }
885 Log.i(ActivityManagerService.TAG, sb.toString());
886 }
887 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
888 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -0700889 //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700890 }
891 displayStartTime = 0;
892 stack.mLaunchStartTime = 0;
893 }
894
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700895 public void windowsDrawn() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896 synchronized(service) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700897 if (displayStartTime != 0) {
898 reportLaunchTimeLocked(SystemClock.uptimeMillis());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800899 }
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700900 startTime = 0;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700901 finishLaunchTickingLocked();
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700902 if (task != null) {
903 task.hasBeenVisible = true;
904 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700905 }
906 }
907
908 public void windowsVisible() {
909 synchronized(service) {
Craig Mautnerce5f3cb2013-04-22 08:58:54 -0700910 mStackSupervisor.reportActivityVisibleLocked(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
912 ActivityManagerService.TAG, "windowsVisible(): " + this);
913 if (!nowVisible) {
914 nowVisible = true;
Dianne Hackborn50685602011-12-01 12:23:37 -0800915 lastVisibleTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 if (!idle) {
917 // Instead of doing the full stop routine here, let's just
918 // hide any activities we now can, and let them stop when
919 // the normal idle happens.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700920 mStackSupervisor.processStoppingActivitiesLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 } else {
922 // If this activity was already idle, then we now need to
923 // make sure we perform the full stop of any activities
924 // that are waiting to do so. This is because we won't
925 // do that while they are still waiting for this one to
926 // become visible.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700927 final int N = mStackSupervisor.mWaitingVisibleActivities.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 if (N > 0) {
929 for (int i=0; i<N; i++) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700930 ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 r.waitingVisible = false;
932 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
933 ActivityManagerService.TAG,
934 "Was waiting for visible: " + r);
935 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700936 mStackSupervisor.mWaitingVisibleActivities.clear();
Craig Mautnerf3333272013-04-22 10:55:53 -0700937 mStackSupervisor.scheduleIdleLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 }
939 }
940 service.scheduleAppGcsLocked();
941 }
942 }
943 }
944
945 public void windowsGone() {
946 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
947 ActivityManagerService.TAG, "windowsGone(): " + this);
948 nowVisible = false;
949 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700950
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700951 private ActivityRecord getWaitingHistoryRecordLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 // First find the real culprit... if we are waiting
953 // for another app to start, then we have paused dispatching
954 // for this activity.
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700955 ActivityRecord r = this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 if (r.waitingVisible) {
Craig Mautner8f2adcb2014-04-07 22:21:33 +0000957 final ActivityStack stack = mStackSupervisor.getFocusedStack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 // Hmmm, who might we be waiting for?
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700959 r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -0800961 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962 }
963 // Both of those null? Fall back to 'this' again
964 if (r == null) {
965 r = this;
966 }
967 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 return r;
970 }
971
Jeff Brownbd181bb2013-09-10 16:44:24 -0700972 public boolean keyDispatchingTimedOut(String reason) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700973 ActivityRecord r;
Michael Wright7dd5bb12013-02-27 17:07:29 -0800974 ProcessRecord anrApp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 synchronized(service) {
Dianne Hackbornad5499d2010-03-29 18:08:45 -0700976 r = getWaitingHistoryRecordLocked();
Michael Wright7dd5bb12013-02-27 17:07:29 -0800977 anrApp = r != null ? r.app : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 }
Jeff Brownbd181bb2013-09-10 16:44:24 -0700979 return service.inputDispatchingTimedOut(anrApp, r, this, false, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 /** Returns the key dispatching timeout for this application token. */
983 public long getKeyDispatchingTimeout() {
984 synchronized(service) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700985 ActivityRecord r = getWaitingHistoryRecordLocked();
Michael Wright7dd5bb12013-02-27 17:07:29 -0800986 return ActivityManagerService.getInputDispatchingTimeoutLocked(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 }
988 }
989
990 /**
991 * This method will return true if the activity is either visible, is becoming visible, is
992 * currently pausing, or is resumed.
993 */
994 public boolean isInterestingToUserLocked() {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700995 return visible || nowVisible || state == ActivityState.PAUSING ||
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800996 state == ActivityState.RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800997 }
998
999 public void setSleeping(boolean _sleeping) {
1000 if (sleeping == _sleeping) {
1001 return;
1002 }
1003 if (app != null && app.thread != null) {
1004 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -08001005 app.thread.scheduleSleeping(appToken, _sleeping);
Craig Mautner0eea92c2013-05-16 13:35:39 -07001006 if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
1007 mStackSupervisor.mGoingToSleepActivities.add(this);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001008 }
1009 sleeping = _sleeping;
1010 } catch (RemoteException e) {
Craig Mautner0eea92c2013-05-16 13:35:39 -07001011 Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001012 }
1013 }
1014 }
Craig Mautnerf81b90872013-02-26 13:02:43 -08001015
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001016 static void activityResumedLocked(IBinder token) {
1017 final ActivityRecord r = ActivityRecord.forToken(token);
1018 if (DEBUG_SAVED_STATE) Slog.i(TAG, "Resumed activity; dropping state of: " + r);
1019 r.icicle = null;
1020 r.haveState = false;
1021 }
1022
Craig Mautnerd2328952013-03-05 12:46:26 -08001023 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
1024 final ActivityRecord r = ActivityRecord.forToken(token);
1025 if (r == null) {
1026 return -1;
1027 }
1028 final TaskRecord task = r.task;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001029 final int activityNdx = task.mActivities.indexOf(r);
1030 if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) {
1031 return -1;
Craig Mautnerd2328952013-03-05 12:46:26 -08001032 }
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001033 return task.taskId;
Craig Mautnerd2328952013-03-05 12:46:26 -08001034 }
1035
1036 static ActivityRecord isInStackLocked(IBinder token) {
1037 final ActivityRecord r = ActivityRecord.forToken(token);
1038 if (r != null) {
1039 return r.task.stack.isInStackLocked(token);
1040 }
1041 return null;
1042 }
1043
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001044 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -08001045 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
1046 if (r != null) {
1047 return r.task.stack;
1048 }
1049 return null;
1050 }
1051
Craig Mautnera228ae92014-07-09 05:44:55 -07001052 private static String createImageFilename(ActivityRecord r, int taskId) {
1053 return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + r.createTime +
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001054 TaskPersister.IMAGE_EXTENSION;
1055 }
1056
Craig Mautner21d24a22014-04-23 11:45:37 -07001057 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
1058 out.attribute(null, ATTR_ID, String.valueOf(createTime));
1059 out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
1060 if (launchedFromPackage != null) {
1061 out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage);
1062 }
1063 if (resolvedType != null) {
1064 out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType);
1065 }
1066 out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified));
1067 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Winson Chung2cb86c72014-06-25 12:03:30 -07001068
Craig Mautner21d24a22014-04-23 11:45:37 -07001069 if (taskDescription != null) {
Craig Mautnera228ae92014-07-09 05:44:55 -07001070 task.saveTaskDescription(taskDescription, createImageFilename(this, task.taskId),
1071 out);
Craig Mautner21d24a22014-04-23 11:45:37 -07001072 }
1073
1074 out.startTag(null, TAG_INTENT);
1075 intent.saveToXml(out);
1076 out.endTag(null, TAG_INTENT);
1077
1078 if (isPersistable() && persistentState != null) {
1079 out.startTag(null, TAG_PERSISTABLEBUNDLE);
1080 persistentState.saveToXml(out);
1081 out.endTag(null, TAG_PERSISTABLEBUNDLE);
1082 }
1083 }
1084
1085 static ActivityRecord restoreFromXml(XmlPullParser in, int taskId,
1086 ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
1087 Intent intent = null;
1088 PersistableBundle persistentState = null;
1089 int launchedFromUid = 0;
1090 String launchedFromPackage = null;
1091 String resolvedType = null;
1092 boolean componentSpecified = false;
1093 int userId = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07001094 long createTime = -1;
1095 final int outerDepth = in.getDepth();
Winson Chung2cb86c72014-06-25 12:03:30 -07001096 TaskDescription taskDescription = new TaskDescription();
Craig Mautner21d24a22014-04-23 11:45:37 -07001097
1098 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1099 final String attrName = in.getAttributeName(attrNdx);
1100 final String attrValue = in.getAttributeValue(attrNdx);
1101 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "ActivityRecord: attribute name=" +
1102 attrName + " value=" + attrValue);
1103 if (ATTR_ID.equals(attrName)) {
1104 createTime = Long.valueOf(attrValue);
1105 } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
1106 launchedFromUid = Integer.valueOf(attrValue);
1107 } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
1108 launchedFromPackage = attrValue;
1109 } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
1110 resolvedType = attrValue;
1111 } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
1112 componentSpecified = Boolean.valueOf(attrValue);
1113 } else if (ATTR_USERID.equals(attrName)) {
1114 userId = Integer.valueOf(attrValue);
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001115 } else if (TaskRecord.readTaskDescriptionAttribute(taskDescription, attrName,
Winson Chung2cb86c72014-06-25 12:03:30 -07001116 attrValue)) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001117 // Completed in TaskRecord.readTaskDescriptionAttribute()
Craig Mautner21d24a22014-04-23 11:45:37 -07001118 } else {
1119 Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName);
1120 }
1121 }
1122
1123 int event;
1124 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
1125 (event != XmlPullParser.END_TAG || in.getDepth() < outerDepth)) {
1126 if (event == XmlPullParser.START_TAG) {
1127 final String name = in.getName();
1128 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
1129 "ActivityRecord: START_TAG name=" + name);
1130 if (TAG_INTENT.equals(name)) {
1131 intent = Intent.restoreFromXml(in);
1132 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
1133 "ActivityRecord: intent=" + intent);
1134 } else if (TAG_PERSISTABLEBUNDLE.equals(name)) {
1135 persistentState = PersistableBundle.restoreFromXml(in);
1136 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
1137 "ActivityRecord: persistentState=" + persistentState);
1138 } else {
1139 Slog.w(TAG, "restoreActivity: unexpected name=" + name);
1140 XmlUtils.skipCurrentTag(in);
1141 }
1142 }
1143 }
1144
1145 if (intent == null) {
Craig Mautnere0129b32014-05-25 16:41:09 -07001146 throw new XmlPullParserException("restoreActivity error intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07001147 }
1148
1149 final ActivityManagerService service = stackSupervisor.mService;
1150 final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null,
1151 null, userId);
Craig Mautnere0129b32014-05-25 16:41:09 -07001152 if (aInfo == null) {
Craig Mautner77b04262014-06-27 15:22:12 -07001153 throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent +
1154 " resolvedType=" + resolvedType);
Craig Mautnere0129b32014-05-25 16:41:09 -07001155 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001156 final ActivityRecord r = new ActivityRecord(service, /*caller*/null, launchedFromUid,
1157 launchedFromPackage, intent, resolvedType, aInfo, service.getConfiguration(),
1158 null, null, 0, componentSpecified, stackSupervisor, null, null);
1159
1160 r.persistentState = persistentState;
1161
Craig Mautner21d24a22014-04-23 11:45:37 -07001162 if (createTime >= 0) {
Craig Mautnera228ae92014-07-09 05:44:55 -07001163 taskDescription.setIcon(TaskPersister.restoreImage(createImageFilename(r, taskId)));
Craig Mautner21d24a22014-04-23 11:45:37 -07001164 }
Winson Chung2cb86c72014-06-25 12:03:30 -07001165 r.taskDescription = taskDescription;
Craig Mautner21d24a22014-04-23 11:45:37 -07001166 r.createTime = createTime;
1167
1168 return r;
1169 }
1170
1171 private static String activityTypeToString(int type) {
Craig Mautnerae7ecab2013-09-18 11:48:14 -07001172 switch (type) {
1173 case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE";
1174 case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE";
1175 case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE";
1176 default: return Integer.toString(type);
1177 }
1178 }
1179
Craig Mautnerf81b90872013-02-26 13:02:43 -08001180 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001181 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001182 if (stringName != null) {
Craig Mautnerf3333272013-04-22 10:55:53 -07001183 return stringName + " t" + (task == null ? -1 : task.taskId) +
1184 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001185 }
1186 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -08001187 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001188 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -07001189 sb.append(" u");
1190 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001191 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001192 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -08001193 stringName = sb.toString();
1194 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001195 }
1196}