blob: 1a0e45ee4177bf96d78e70b2df6af7d2b0351064 [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";
Dianne Hackborn337abb32014-09-24 12:44:29 -070082 static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_";
Craig Mautner21d24a22014-04-23 11:45:37 -070083
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
George Mount6ba042b2014-07-28 11:12:28 -0700133 ActivityOptions returningOptions; // options that are coming back via convertToTranslucent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700135 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700136 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700137 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 Bundle icicle; // last saved activity state
Craig Mautnera0026042014-04-23 11:45:37 -0700139 PersistableBundle persistentState; // last persistently saved activity state
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 boolean frontOfTask; // is this the root activity of its task?
141 boolean launchFailed; // set if a launched failed, to abort on 2nd try
142 boolean haveState; // have we gotten the last activity state?
143 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700144 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 boolean finishing; // activity in pending finish list?
146 boolean configDestroy; // need to destroy due to config change?
147 int configChangeFlags; // which config values have changed
148 boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 int launchMode; // the launch mode activity attribute.
150 boolean visible; // does this activity's window need to be shown?
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800151 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 boolean waitingVisible; // true if waiting for a new act to become vis
153 boolean nowVisible; // is this activity's window visible?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 boolean idle; // has the activity gone idle?
155 boolean hasBeenLaunched;// has this activity ever been launched?
156 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400157 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400158 boolean forceNewConfig; // force re-create with new config next time
Dianne Hackborn07981492013-01-28 11:36:23 -0800159 int launchCount; // count of launches since last state
160 long lastLaunchTime; // time of last lauch of this activity
Craig Mautnerf4c909b2014-04-17 18:39:38 -0700161 ArrayList<ActivityContainer> mChildContainers = new ArrayList<ActivityContainer>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700163 String stringName; // for caching of toString().
Craig Mautnerde4ef022013-04-07 19:01:33 -0700164
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700165 private boolean inHistory; // are we in the history stack?
Craig Mautnerde4ef022013-04-07 19:01:33 -0700166 final ActivityStackSupervisor mStackSupervisor;
Craig Mautnera61bc652013-10-28 15:43:18 -0700167 boolean mStartingWindowShown = false;
Craig Mautnere0a38842013-12-16 16:14:02 -0800168 ActivityContainer mInitialActivityContainer;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700169
Craig Mautner21d24a22014-04-23 11:45:37 -0700170 TaskDescription taskDescription; // the recents information for this activity
Craig Mautnerbb742462014-07-07 15:28:55 -0700171 boolean mLaunchTaskBehind; // this activity is actively being launched with
172 // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed.
Craig Mautner2fbd7542014-03-21 09:34:07 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700175 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700176 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
177 pw.print(" processName="); pw.println(processName);
178 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Craig Mautnere11f2b72013-04-01 12:37:17 -0700179 pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800180 pw.print(" userId="); pw.println(userId);
181 pw.print(prefix); pw.print("app="); pw.println(app);
182 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700183 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
184 pw.print(" task="); pw.println(task);
185 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700186 pw.print(prefix); pw.print("realActivity=");
187 pw.println(realActivity.flattenToShortString());
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700188 if (appInfo != null) {
189 pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir);
190 if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) {
191 pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir);
192 }
193 pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800194 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700195 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
196 pw.print(" componentSpecified="); pw.print(componentSpecified);
Craig Mautner86d67a42013-05-14 10:34:38 -0700197 pw.print(" mActivityType="); pw.println(mActivityType);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800198 pw.print(prefix); pw.print("compat="); pw.print(compat);
199 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
200 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
201 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Dianne Hackborne17aeb32011-04-07 15:11:57 -0700202 pw.print(prefix); pw.print("config="); pw.println(configuration);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700203 if (resultTo != null || resultWho != null) {
204 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
205 pw.print(" resultWho="); pw.print(resultWho);
206 pw.print(" resultCode="); pw.println(requestCode);
207 }
Craig Mautner29c58ca2014-10-14 16:17:06 -0700208 if (taskDescription != null) {
209 final String iconFilename = taskDescription.getIconFilename();
210 if (iconFilename != null || taskDescription.getLabel() != null ||
211 taskDescription.getPrimaryColor() != 0) {
212 pw.print(prefix); pw.print("taskDescription:");
213 pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename());
214 pw.print(" label=\""); pw.print(taskDescription.getLabel());
215 pw.print("\"");
216 pw.print(" color=");
217 pw.println(Integer.toHexString(taskDescription.getPrimaryColor()));
218 }
219 if (iconFilename == null && taskDescription.getIcon() != null) {
220 pw.print(prefix); pw.println("taskDescription contains Bitmap");
221 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700222 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700223 if (results != null) {
224 pw.print(prefix); pw.print("results="); pw.println(results);
225 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700226 if (pendingResults != null && pendingResults.size() > 0) {
227 pw.print(prefix); pw.println("Pending Results:");
228 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
229 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
230 pw.print(prefix); pw.print(" - ");
231 if (pir == null) {
232 pw.println("null");
233 } else {
234 pw.println(pir);
235 pir.dump(pw, prefix + " ");
236 }
237 }
238 }
239 if (newIntents != null && newIntents.size() > 0) {
240 pw.print(prefix); pw.println("Pending New Intents:");
241 for (int i=0; i<newIntents.size(); i++) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800242 Intent intent = newIntents.get(i);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700243 pw.print(prefix); pw.print(" - ");
244 if (intent == null) {
245 pw.println("null");
246 } else {
247 pw.println(intent.toShortString(false, true, false, true));
248 }
249 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700250 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700251 if (pendingOptions != null) {
252 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
253 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700254 if (uriPermissions != null) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700255 uriPermissions.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700256 }
257 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800258 pw.print(" launchCount="); pw.print(launchCount);
259 pw.print(" lastLaunchTime=");
260 if (lastLaunchTime == 0) pw.print("0");
261 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
262 pw.println();
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700263 pw.print(prefix); pw.print("haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700264 pw.print(" icicle="); pw.println(icicle);
265 pw.print(prefix); pw.print("state="); pw.print(state);
266 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700267 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700268 pw.print(" finishing="); pw.println(finishing);
269 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
270 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700271 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800272 pw.print(" sleeping="); pw.print(sleeping);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700273 pw.print(" idle="); pw.println(idle);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800274 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
275 pw.print(" noDisplay="); pw.print(noDisplay);
276 pw.print(" immersive="); pw.print(immersive);
277 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800278 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400279 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700280 pw.print(prefix); pw.print("mActivityType=");
281 pw.println(activityTypeToString(mActivityType));
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700282 if (displayStartTime != 0 || startTime != 0) {
283 pw.print(prefix); pw.print("displayStartTime=");
284 if (displayStartTime == 0) pw.print("0");
285 else TimeUtils.formatDuration(displayStartTime, now, pw);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700286 pw.print(" startTime=");
287 if (startTime == 0) pw.print("0");
288 else TimeUtils.formatDuration(startTime, now, pw);
289 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700290 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800291 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700292 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800293 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700294 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700295 if (lastVisibleTime == 0) pw.print("0");
296 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
297 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700298 }
299 if (configDestroy || configChangeFlags != 0) {
300 pw.print(prefix); pw.print("configDestroy="); pw.print(configDestroy);
301 pw.print(" configChangeFlags=");
302 pw.println(Integer.toHexString(configChangeFlags));
303 }
304 if (connections != null) {
305 pw.print(prefix); pw.print("connections="); pw.println(connections);
306 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 }
308
Dianne Hackbornbe707852011-11-11 14:32:10 -0800309 static class Token extends IApplicationToken.Stub {
310 final WeakReference<ActivityRecord> weakActivity;
311
312 Token(ActivityRecord activity) {
313 weakActivity = new WeakReference<ActivityRecord>(activity);
314 }
315
Craig Mautnerde4ef022013-04-07 19:01:33 -0700316 @Override public void windowsDrawn() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800317 ActivityRecord activity = weakActivity.get();
318 if (activity != null) {
319 activity.windowsDrawn();
320 }
321 }
322
Craig Mautnerde4ef022013-04-07 19:01:33 -0700323 @Override public void windowsVisible() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800324 ActivityRecord activity = weakActivity.get();
325 if (activity != null) {
326 activity.windowsVisible();
327 }
328 }
329
Craig Mautnerde4ef022013-04-07 19:01:33 -0700330 @Override public void windowsGone() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800331 ActivityRecord activity = weakActivity.get();
332 if (activity != null) {
333 activity.windowsGone();
334 }
335 }
336
Jeff Brownbd181bb2013-09-10 16:44:24 -0700337 @Override public boolean keyDispatchingTimedOut(String reason) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800338 ActivityRecord activity = weakActivity.get();
Jeff Brownbd181bb2013-09-10 16:44:24 -0700339 return activity != null && activity.keyDispatchingTimedOut(reason);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800340 }
341
Craig Mautnerde4ef022013-04-07 19:01:33 -0700342 @Override public long getKeyDispatchingTimeout() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800343 ActivityRecord activity = weakActivity.get();
344 if (activity != null) {
345 return activity.getKeyDispatchingTimeout();
346 }
347 return 0;
348 }
349
Craig Mautnerde4ef022013-04-07 19:01:33 -0700350 @Override
Dianne Hackbornbe707852011-11-11 14:32:10 -0800351 public String toString() {
352 StringBuilder sb = new StringBuilder(128);
353 sb.append("Token{");
354 sb.append(Integer.toHexString(System.identityHashCode(this)));
355 sb.append(' ');
356 sb.append(weakActivity.get());
357 sb.append('}');
358 return sb.toString();
359 }
360 }
361
362 static ActivityRecord forToken(IBinder token) {
363 try {
364 return token != null ? ((Token)token).weakActivity.get() : null;
365 } catch (ClassCastException e) {
366 Slog.w(ActivityManagerService.TAG, "Bad activity token: " + token, e);
367 return null;
368 }
369 }
370
Craig Mautnerac6f8432013-07-17 13:24:59 -0700371 boolean isNotResolverActivity() {
372 return !ResolverActivity.class.getName().equals(realActivity.getClassName());
373 }
374
Craig Mautnerd2328952013-03-05 12:46:26 -0800375 ActivityRecord(ActivityManagerService _service, ProcessRecord _caller,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800376 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700378 ActivityRecord _resultTo, String _resultWho, int _reqCode,
Craig Mautnere0a38842013-12-16 16:14:02 -0800379 boolean _componentSpecified, ActivityStackSupervisor supervisor,
Craig Mautner233ceee2014-05-09 17:05:11 -0700380 ActivityContainer container, Bundle options) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 service = _service;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800382 appToken = new Token(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 info = aInfo;
384 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800385 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700386 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 intent = _intent;
388 shortComponentName = _intent.getComponent().flattenToShortString();
389 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800390 componentSpecified = _componentSpecified;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 configuration = _configuration;
392 resultTo = _resultTo;
393 resultWho = _resultWho;
394 requestCode = _reqCode;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700395 state = ActivityState.INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 frontOfTask = false;
397 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700399 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 finishing = false;
401 configDestroy = false;
402 keysPaused = false;
403 inHistory = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 visible = true;
405 waitingVisible = false;
406 nowVisible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 idle = false;
408 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700409 mStackSupervisor = supervisor;
Craig Mautnere0a38842013-12-16 16:14:02 -0800410 mInitialActivityContainer = container;
Craig Mautner233ceee2014-05-09 17:05:11 -0700411 if (options != null) {
412 pendingOptions = new ActivityOptions(options);
Craig Mautnerbb742462014-07-07 15:28:55 -0700413 mLaunchTaskBehind = pendingOptions.getLaunchTaskBehind();
Craig Mautner233ceee2014-05-09 17:05:11 -0700414 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700416 // This starts out true, since the initial state of an activity
417 // is that we have everything, and we shouldn't never consider it
418 // lacking in state to be removed if it dies.
419 haveState = true;
420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 if (aInfo != null) {
422 if (aInfo.targetActivity == null
423 || aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE
424 || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
425 realActivity = _intent.getComponent();
426 } else {
427 realActivity = new ComponentName(aInfo.packageName,
428 aInfo.targetActivity);
429 }
430 taskAffinity = aInfo.taskAffinity;
431 stateNotNeeded = (aInfo.flags&
432 ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700433 appInfo = aInfo.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 nonLocalizedLabel = aInfo.nonLocalizedLabel;
435 labelRes = aInfo.labelRes;
436 if (nonLocalizedLabel == null && labelRes == 0) {
437 ApplicationInfo app = aInfo.applicationInfo;
438 nonLocalizedLabel = app.nonLocalizedLabel;
439 labelRes = app.labelRes;
440 }
441 icon = aInfo.getIconResource();
Adam Powell04fe6eb2013-05-31 14:39:48 -0700442 logo = aInfo.getLogoResource();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 theme = aInfo.getThemeResource();
Dianne Hackborn247fe742011-01-08 17:25:57 -0800444 realTheme = theme;
445 if (realTheme == 0) {
446 realTheme = aInfo.applicationInfo.targetSdkVersion
447 < Build.VERSION_CODES.HONEYCOMB
448 ? android.R.style.Theme
449 : android.R.style.Theme_Holo;
450 }
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800451 if ((aInfo.flags&ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
452 windowFlags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
453 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0
455 && _caller != null
456 && (aInfo.applicationInfo.uid == Process.SYSTEM_UID
457 || aInfo.applicationInfo.uid == _caller.info.uid)) {
458 processName = _caller.processName;
459 } else {
460 processName = aInfo.processName;
461 }
462
463 if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
464 intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
465 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 packageName = aInfo.applicationInfo.packageName;
468 launchMode = aInfo.launchMode;
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700471 realTheme, com.android.internal.R.styleable.Window, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 fullscreen = ent != null && !ent.array.getBoolean(
473 com.android.internal.R.styleable.Window_windowIsFloating, false)
474 && !ent.array.getBoolean(
475 com.android.internal.R.styleable.Window_windowIsTranslucent, false);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800476 noDisplay = ent != null && ent.array.getBoolean(
477 com.android.internal.R.styleable.Window_windowNoDisplay, false);
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700478
Craig Mautner80259352013-09-28 12:35:25 -0700479 if ((!_componentSpecified || _launchedFromUid == Process.myUid()
Craig Mautner86d67a42013-05-14 10:34:38 -0700480 || _launchedFromUid == 0) &&
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700481 Intent.ACTION_MAIN.equals(_intent.getAction()) &&
482 _intent.hasCategory(Intent.CATEGORY_HOME) &&
483 _intent.getCategories().size() == 1 &&
484 _intent.getData() == null &&
485 _intent.getType() == null &&
Craig Mautner80259352013-09-28 12:35:25 -0700486 (intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 &&
487 isNotResolverActivity()) {
Craig Mautner86d67a42013-05-14 10:34:38 -0700488 // This sure looks like a home activity!
489 mActivityType = HOME_ACTIVITY_TYPE;
Craig Mautner80259352013-09-28 12:35:25 -0700490 } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) {
Craig Mautner86d67a42013-05-14 10:34:38 -0700491 mActivityType = RECENTS_ACTIVITY_TYPE;
492 } else {
493 mActivityType = APPLICATION_ACTIVITY_TYPE;
494 }
Daniel Sandler69a48172010-06-23 16:29:36 -0400495
496 immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 } else {
498 realActivity = null;
499 taskAffinity = null;
500 stateNotNeeded = false;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700501 appInfo = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 processName = null;
503 packageName = null;
504 fullscreen = true;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800505 noDisplay = false;
Craig Mautner86d67a42013-05-14 10:34:38 -0700506 mActivityType = APPLICATION_ACTIVITY_TYPE;
Daniel Sandler69a48172010-06-23 16:29:36 -0400507 immersive = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 }
509 }
510
Craig Mautnera228ae92014-07-09 05:44:55 -0700511 void setTask(TaskRecord newTask, TaskRecord taskToAffiliateWith) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700512 if (task != null && task.removeActivity(this)) {
Craig Mautner19d9bd52013-10-21 20:05:26 -0700513 if (task != newTask) {
Craig Mautner41db4a72014-05-07 17:20:56 -0700514 task.stack.removeTask(task);
Craig Mautner19d9bd52013-10-21 20:05:26 -0700515 } else {
516 Slog.d(TAG, "!!! REMOVE THIS LOG !!! setTask: nearly removed stack=" +
517 (newTask == null ? null : newTask.stack));
518 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700519 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700520 task = newTask;
Craig Mautnera228ae92014-07-09 05:44:55 -0700521 setTaskToAffiliateWith(taskToAffiliateWith);
522 }
523
524 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
525 if (taskToAffiliateWith != null &&
526 launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE &&
527 launchMode != ActivityInfo.LAUNCH_SINGLE_TASK) {
528 task.setTaskToAffiliateWith(taskToAffiliateWith);
529 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700530 }
531
Craig Mautner5eda9b32013-07-02 11:58:16 -0700532 boolean changeWindowTranslucency(boolean toOpaque) {
533 if (fullscreen == toOpaque) {
534 return false;
535 }
Craig Mautner4addfc52013-06-25 08:05:45 -0700536
Craig Mautner5eda9b32013-07-02 11:58:16 -0700537 // Keep track of the number of fullscreen activities in this task.
538 task.numFullscreen += toOpaque ? +1 : -1;
539
540 fullscreen = toOpaque;
541 return true;
Craig Mautner4addfc52013-06-25 08:05:45 -0700542 }
543
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700544 void putInHistory() {
545 if (!inHistory) {
546 inHistory = true;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700547 }
548 }
549
550 void takeFromHistory() {
551 if (inHistory) {
552 inHistory = false;
553 if (task != null && !finishing) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800554 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700555 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700556 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700557 }
558 }
559
560 boolean isInHistory() {
561 return inHistory;
562 }
563
Craig Mautner86d67a42013-05-14 10:34:38 -0700564 boolean isHomeActivity() {
565 return mActivityType == HOME_ACTIVITY_TYPE;
566 }
567
568 boolean isRecentsActivity() {
569 return mActivityType == RECENTS_ACTIVITY_TYPE;
570 }
571
572 boolean isApplicationActivity() {
573 return mActivityType == APPLICATION_ACTIVITY_TYPE;
574 }
575
Craig Mautner21d24a22014-04-23 11:45:37 -0700576 boolean isPersistable() {
Craig Mautner43e52ed2014-06-16 17:18:52 -0700577 return (info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY ||
578 info.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS) &&
579 (intent == null ||
580 (intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
Craig Mautner21d24a22014-04-23 11:45:37 -0700581 }
582
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800583 void makeFinishing() {
584 if (!finishing) {
Jose Lima34ff4922014-08-18 15:19:41 -0700585 if (this == task.stack.getVisibleBehindActivity()) {
586 // A finishing activity should not remain as visible in the background
587 mStackSupervisor.requestVisibleBehindLocked(this, false);
588 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800589 finishing = true;
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700590 if (stopped) {
591 clearOptionsLocked();
592 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800593 }
594 }
595
Dianne Hackborn7e269642010-08-25 19:50:20 -0700596 UriPermissionOwner getUriPermissionsLocked() {
597 if (uriPermissions == null) {
598 uriPermissions = new UriPermissionOwner(service, this);
599 }
600 return uriPermissions;
601 }
602
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700603 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 int requestCode, int resultCode,
605 Intent resultData) {
606 ActivityResult r = new ActivityResult(from, resultWho,
John Spurlock8a985d22014-02-25 09:40:05 -0500607 requestCode, resultCode, resultData);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800609 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 }
611 results.add(r);
612 }
613
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700614 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615 int requestCode) {
616 if (results != null) {
617 for (int i=results.size()-1; i>=0; i--) {
618 ActivityResult r = (ActivityResult)results.get(i);
619 if (r.mFrom != from) continue;
620 if (r.mResultWho == null) {
621 if (resultWho != null) continue;
622 } else {
623 if (!r.mResultWho.equals(resultWho)) continue;
624 }
625 if (r.mRequestCode != requestCode) continue;
626
627 results.remove(i);
628 }
629 }
630 }
631
632 void addNewIntentLocked(Intent intent) {
633 if (newIntents == null) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800634 newIntents = new ArrayList<Intent>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 }
636 newIntents.add(intent);
637 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700638
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700639 /**
640 * Deliver a new Intent to an existing activity, so that its onNewIntent()
641 * method will be called at the proper time.
642 */
Dianne Hackborn39792d22010-08-19 18:01:52 -0700643 final void deliverNewIntentLocked(int callingUid, Intent intent) {
Dianne Hackborn514074f2013-02-11 10:52:46 -0800644 // The activity now gets access to the data associated with this Intent.
645 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
Nicolas Prevotc6cf95c2014-05-29 11:30:36 +0100646 intent, getUriPermissionsLocked(), userId);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700647 // We want to immediately deliver the intent to the activity if
648 // it is currently the top resumed activity... however, if the
649 // device is sleeping, then all activities are stopped, so in that
650 // case we will deliver it if this is the current top activity on its
651 // stack.
Craig Mautner86d67a42013-05-14 10:34:38 -0700652 boolean unsent = true;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700653 if ((state == ActivityState.RESUMED || (service.isSleeping()
Craig Mautnerd2328952013-03-05 12:46:26 -0800654 && task.stack.topRunningActivityLocked(null) == this))
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700655 && app != null && app.thread != null) {
656 try {
657 ArrayList<Intent> ar = new ArrayList<Intent>();
Dianne Hackborn39792d22010-08-19 18:01:52 -0700658 intent = new Intent(intent);
659 ar.add(intent);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800660 app.thread.scheduleNewIntent(ar, appToken);
Craig Mautner86d67a42013-05-14 10:34:38 -0700661 unsent = false;
Dianne Hackborn39792d22010-08-19 18:01:52 -0700662 } catch (RemoteException e) {
663 Slog.w(ActivityManagerService.TAG,
664 "Exception thrown sending new intent to " + this, e);
665 } catch (NullPointerException e) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700666 Slog.w(ActivityManagerService.TAG,
667 "Exception thrown sending new intent to " + this, e);
668 }
669 }
Craig Mautner86d67a42013-05-14 10:34:38 -0700670 if (unsent) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700671 addNewIntentLocked(new Intent(intent));
672 }
673 }
674
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700675 void updateOptionsLocked(Bundle options) {
676 if (options != null) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700677 if (pendingOptions != null) {
678 pendingOptions.abort();
679 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700680 pendingOptions = new ActivityOptions(options);
681 }
682 }
683
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700684 void updateOptionsLocked(ActivityOptions options) {
685 if (options != null) {
686 if (pendingOptions != null) {
687 pendingOptions.abort();
688 }
689 pendingOptions = options;
690 }
691 }
692
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700693 void applyOptionsLocked() {
George Mount2c92c972014-03-20 09:38:23 -0700694 if (pendingOptions != null
695 && pendingOptions.getAnimationType() != ActivityOptions.ANIM_SCENE_TRANSITION) {
Michael Jurka21385cd2012-05-03 10:57:31 -0700696 final int animationType = pendingOptions.getAnimationType();
697 switch (animationType) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700698 case ActivityOptions.ANIM_CUSTOM:
699 service.mWindowManager.overridePendingAppTransition(
700 pendingOptions.getPackageName(),
701 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -0700702 pendingOptions.getCustomExitResId(),
703 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700704 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700705 case ActivityOptions.ANIM_SCALE_UP:
706 service.mWindowManager.overridePendingAppTransitionScaleUp(
707 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200708 pendingOptions.getWidth(), pendingOptions.getHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700709 if (intent.getSourceBounds() == null) {
710 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
711 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200712 pendingOptions.getStartX()+pendingOptions.getWidth(),
713 pendingOptions.getStartY()+pendingOptions.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700714 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700715 break;
Michael Jurka832cb222012-04-13 09:32:47 -0700716 case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
717 case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
718 boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700719 service.mWindowManager.overridePendingAppTransitionThumb(
720 pendingOptions.getThumbnail(),
721 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -0700722 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -0700723 scaleUp);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700724 if (intent.getSourceBounds() == null) {
725 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
726 pendingOptions.getStartY(),
727 pendingOptions.getStartX()
728 + pendingOptions.getThumbnail().getWidth(),
729 pendingOptions.getStartY()
730 + pendingOptions.getThumbnail().getHeight()));
731 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700732 break;
Winson Chunga4ccb862014-08-22 15:26:27 -0700733 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP:
734 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
735 service.mWindowManager.overridePendingAppTransitionAspectScaledThumb(
736 pendingOptions.getThumbnail(),
737 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200738 pendingOptions.getWidth(), pendingOptions.getHeight(),
Winson Chunga4ccb862014-08-22 15:26:27 -0700739 pendingOptions.getOnAnimationStartListener(),
740 (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP));
741 if (intent.getSourceBounds() == null) {
742 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
743 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200744 pendingOptions.getStartX() + pendingOptions.getWidth(),
745 pendingOptions.getStartY() + pendingOptions.getHeight()));
Winson Chunga4ccb862014-08-22 15:26:27 -0700746 }
747 break;
Craig Mautner233ceee2014-05-09 17:05:11 -0700748 default:
749 Slog.e(TAG, "applyOptionsLocked: Unknown animationType=" + animationType);
750 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700751 }
752 pendingOptions = null;
753 }
754 }
755
Adam Powellcfbe9be2013-11-06 14:58:58 -0800756 ActivityOptions getOptionsForTargetActivityLocked() {
757 return pendingOptions != null ? pendingOptions.forTargetActivity() : null;
758 }
759
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700760 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700761 if (pendingOptions != null) {
762 pendingOptions.abort();
763 pendingOptions = null;
764 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700765 }
766
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700767 ActivityOptions takeOptionsLocked() {
768 ActivityOptions opts = pendingOptions;
769 pendingOptions = null;
770 return opts;
771 }
772
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700773 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -0700774 if (uriPermissions != null) {
775 uriPermissions.removeUriPermissionsLocked();
776 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700777 }
778 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779
780 void pauseKeyDispatchingLocked() {
781 if (!keysPaused) {
782 keysPaused = true;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800783 service.mWindowManager.pauseKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 }
785 }
786
787 void resumeKeyDispatchingLocked() {
788 if (keysPaused) {
789 keysPaused = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800790 service.mWindowManager.resumeKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 }
792 }
793
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700794 void updateThumbnail(Bitmap newThumbnail, CharSequence description) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700795 if (newThumbnail != null) {
796 if (ActivityManagerService.DEBUG_THUMBNAILS) Slog.i(ActivityManagerService.TAG,
797 "Setting thumbnail of " + this + " to " + newThumbnail);
Winson Chung096f36b2014-08-20 15:39:01 -0700798 boolean thumbnailUpdated = task.setLastThumbnail(newThumbnail);
799 if (thumbnailUpdated && isPersistable()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700800 mStackSupervisor.mService.notifyTaskPersisterLocked(task, false);
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700801 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700802 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700803 task.lastDescription = description;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700804 }
805
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700806 void startLaunchTickingLocked() {
807 if (ActivityManagerService.IS_USER_BUILD) {
808 return;
809 }
810 if (launchTickTime == 0) {
811 launchTickTime = SystemClock.uptimeMillis();
812 continueLaunchTickingLocked();
813 }
814 }
815
816 boolean continueLaunchTickingLocked() {
817 if (launchTickTime != 0) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800818 final ActivityStack stack = task.stack;
Craig Mautnerf7bfefb2013-05-16 17:30:44 -0700819 Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG, this);
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700820 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
821 stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
822 return true;
823 }
824 return false;
825 }
826
827 void finishLaunchTickingLocked() {
828 launchTickTime = 0;
Craig Mautnerd2328952013-03-05 12:46:26 -0800829 task.stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700830 }
831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 // IApplicationToken
833
834 public boolean mayFreezeScreenLocked(ProcessRecord app) {
835 // Only freeze the screen if this activity is currently attached to
836 // an application, and that application is not blocked or unresponding.
837 // In any other case, we can't count on getting the screen unfrozen,
838 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -0800839 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
843 if (mayFreezeScreenLocked(app)) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800844 service.mWindowManager.startAppFreezingScreen(appToken, configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800845 }
846 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 public void stopFreezingScreenLocked(boolean force) {
849 if (force || frozenBeforeDestroy) {
850 frozenBeforeDestroy = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800851 service.mWindowManager.stopAppFreezingScreen(appToken, force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 }
853 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700854
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700855 public void reportFullyDrawnLocked() {
856 final long curTime = SystemClock.uptimeMillis();
857 if (displayStartTime != 0) {
858 reportLaunchTimeLocked(curTime);
859 }
860 if (fullyDrawnStartTime != 0) {
861 final ActivityStack stack = task.stack;
862 final long thisTime = curTime - fullyDrawnStartTime;
863 final long totalTime = stack.mFullyDrawnStartTime != 0
864 ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
865 if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -0700866 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700867 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME,
868 userId, System.identityHashCode(this), shortComponentName,
869 thisTime, totalTime);
870 StringBuilder sb = service.mStringBuilder;
871 sb.setLength(0);
872 sb.append("Fully drawn ");
873 sb.append(shortComponentName);
874 sb.append(": ");
875 TimeUtils.formatDuration(thisTime, sb);
876 if (thisTime != totalTime) {
877 sb.append(" (total ");
878 TimeUtils.formatDuration(totalTime, sb);
879 sb.append(")");
880 }
881 Log.i(ActivityManagerService.TAG, sb.toString());
882 }
883 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -0700884 //service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700885 }
886 fullyDrawnStartTime = 0;
887 stack.mFullyDrawnStartTime = 0;
888 }
889 }
890
891 private void reportLaunchTimeLocked(final long curTime) {
892 final ActivityStack stack = task.stack;
893 final long thisTime = curTime - displayStartTime;
894 final long totalTime = stack.mLaunchStartTime != 0
895 ? (curTime - stack.mLaunchStartTime) : thisTime;
896 if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -0700897 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700898 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
899 userId, System.identityHashCode(this), shortComponentName,
900 thisTime, totalTime);
901 StringBuilder sb = service.mStringBuilder;
902 sb.setLength(0);
903 sb.append("Displayed ");
904 sb.append(shortComponentName);
905 sb.append(": ");
906 TimeUtils.formatDuration(thisTime, sb);
907 if (thisTime != totalTime) {
908 sb.append(" (total ");
909 TimeUtils.formatDuration(totalTime, sb);
910 sb.append(")");
911 }
912 Log.i(ActivityManagerService.TAG, sb.toString());
913 }
914 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
915 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -0700916 //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700917 }
918 displayStartTime = 0;
919 stack.mLaunchStartTime = 0;
920 }
921
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700922 public void windowsDrawn() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 synchronized(service) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700924 if (displayStartTime != 0) {
925 reportLaunchTimeLocked(SystemClock.uptimeMillis());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 }
Dianne Hackborn6cfbb712014-09-17 12:47:35 -0700927 mStackSupervisor.sendWaitingVisibleReportLocked(this);
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700928 startTime = 0;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700929 finishLaunchTickingLocked();
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700930 if (task != null) {
931 task.hasBeenVisible = true;
932 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700933 }
934 }
935
936 public void windowsVisible() {
937 synchronized(service) {
Craig Mautnerce5f3cb2013-04-22 08:58:54 -0700938 mStackSupervisor.reportActivityVisibleLocked(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
940 ActivityManagerService.TAG, "windowsVisible(): " + this);
941 if (!nowVisible) {
942 nowVisible = true;
Dianne Hackborn50685602011-12-01 12:23:37 -0800943 lastVisibleTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 if (!idle) {
945 // Instead of doing the full stop routine here, let's just
946 // hide any activities we now can, and let them stop when
947 // the normal idle happens.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700948 mStackSupervisor.processStoppingActivitiesLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800949 } else {
950 // If this activity was already idle, then we now need to
951 // make sure we perform the full stop of any activities
952 // that are waiting to do so. This is because we won't
953 // do that while they are still waiting for this one to
954 // become visible.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700955 final int N = mStackSupervisor.mWaitingVisibleActivities.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 if (N > 0) {
957 for (int i=0; i<N; i++) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700958 ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 r.waitingVisible = false;
960 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
961 ActivityManagerService.TAG,
962 "Was waiting for visible: " + r);
963 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700964 mStackSupervisor.mWaitingVisibleActivities.clear();
Craig Mautnerf3333272013-04-22 10:55:53 -0700965 mStackSupervisor.scheduleIdleLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 }
967 }
968 service.scheduleAppGcsLocked();
969 }
970 }
971 }
972
973 public void windowsGone() {
974 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
975 ActivityManagerService.TAG, "windowsGone(): " + this);
976 nowVisible = false;
977 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700978
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700979 private ActivityRecord getWaitingHistoryRecordLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980 // First find the real culprit... if we are waiting
981 // for another app to start, then we have paused dispatching
982 // for this activity.
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700983 ActivityRecord r = this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 if (r.waitingVisible) {
Craig Mautner8f2adcb2014-04-07 22:21:33 +0000985 final ActivityStack stack = mStackSupervisor.getFocusedStack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 // Hmmm, who might we be waiting for?
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700987 r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -0800989 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 }
991 // Both of those null? Fall back to 'this' again
992 if (r == null) {
993 r = this;
994 }
995 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997 return r;
998 }
999
Jeff Brownbd181bb2013-09-10 16:44:24 -07001000 public boolean keyDispatchingTimedOut(String reason) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001001 ActivityRecord r;
Michael Wright7dd5bb12013-02-27 17:07:29 -08001002 ProcessRecord anrApp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 synchronized(service) {
Dianne Hackbornad5499d2010-03-29 18:08:45 -07001004 r = getWaitingHistoryRecordLocked();
Michael Wright7dd5bb12013-02-27 17:07:29 -08001005 anrApp = r != null ? r.app : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 }
Jeff Brownbd181bb2013-09-10 16:44:24 -07001007 return service.inputDispatchingTimedOut(anrApp, r, this, false, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001008 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 /** Returns the key dispatching timeout for this application token. */
1011 public long getKeyDispatchingTimeout() {
1012 synchronized(service) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001013 ActivityRecord r = getWaitingHistoryRecordLocked();
Michael Wright7dd5bb12013-02-27 17:07:29 -08001014 return ActivityManagerService.getInputDispatchingTimeoutLocked(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001015 }
1016 }
1017
1018 /**
1019 * This method will return true if the activity is either visible, is becoming visible, is
1020 * currently pausing, or is resumed.
1021 */
1022 public boolean isInterestingToUserLocked() {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001023 return visible || nowVisible || state == ActivityState.PAUSING ||
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001024 state == ActivityState.RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001025 }
1026
1027 public void setSleeping(boolean _sleeping) {
1028 if (sleeping == _sleeping) {
1029 return;
1030 }
1031 if (app != null && app.thread != null) {
1032 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -08001033 app.thread.scheduleSleeping(appToken, _sleeping);
Craig Mautner0eea92c2013-05-16 13:35:39 -07001034 if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
1035 mStackSupervisor.mGoingToSleepActivities.add(this);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001036 }
1037 sleeping = _sleeping;
1038 } catch (RemoteException e) {
Craig Mautner0eea92c2013-05-16 13:35:39 -07001039 Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001040 }
1041 }
1042 }
Craig Mautnerf81b90872013-02-26 13:02:43 -08001043
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001044 static void activityResumedLocked(IBinder token) {
1045 final ActivityRecord r = ActivityRecord.forToken(token);
1046 if (DEBUG_SAVED_STATE) Slog.i(TAG, "Resumed activity; dropping state of: " + r);
1047 r.icicle = null;
1048 r.haveState = false;
1049 }
1050
Craig Mautnerd2328952013-03-05 12:46:26 -08001051 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
1052 final ActivityRecord r = ActivityRecord.forToken(token);
1053 if (r == null) {
1054 return -1;
1055 }
1056 final TaskRecord task = r.task;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001057 final int activityNdx = task.mActivities.indexOf(r);
1058 if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) {
1059 return -1;
Craig Mautnerd2328952013-03-05 12:46:26 -08001060 }
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001061 return task.taskId;
Craig Mautnerd2328952013-03-05 12:46:26 -08001062 }
1063
1064 static ActivityRecord isInStackLocked(IBinder token) {
1065 final ActivityRecord r = ActivityRecord.forToken(token);
1066 if (r != null) {
1067 return r.task.stack.isInStackLocked(token);
1068 }
1069 return null;
1070 }
1071
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001072 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -08001073 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
1074 if (r != null) {
1075 return r.task.stack;
1076 }
1077 return null;
1078 }
1079
Dianne Hackborn89ad4562014-08-24 16:45:38 -07001080 final boolean isDestroyable() {
1081 if (finishing || app == null || state == ActivityState.DESTROYING
1082 || state == ActivityState.DESTROYED) {
1083 // This would be redundant.
1084 return false;
1085 }
1086 if (task == null || task.stack == null || this == task.stack.mResumedActivity
1087 || this == task.stack.mPausingActivity || !haveState || !stopped) {
1088 // We're not ready for this kind of thing.
1089 return false;
1090 }
1091 if (visible) {
1092 // The user would notice this!
1093 return false;
1094 }
1095 return true;
1096 }
1097
Winson Chung3bad5cc02014-08-19 17:44:32 -07001098 private static String createImageFilename(long createTime, int taskId) {
1099 return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime +
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001100 TaskPersister.IMAGE_EXTENSION;
1101 }
1102
Craig Mautner648f69b2014-09-18 14:16:26 -07001103 void setTaskDescription(TaskDescription _taskDescription) {
1104 Bitmap icon;
1105 if (_taskDescription.getIconFilename() == null &&
1106 (icon = _taskDescription.getIcon()) != null) {
1107 final String iconFilename = createImageFilename(createTime, task.taskId);
1108 mStackSupervisor.mService.mTaskPersister.saveImage(icon, iconFilename);
1109 _taskDescription.setIconFilename(iconFilename);
1110 }
1111 taskDescription = _taskDescription;
1112 }
1113
Craig Mautner21d24a22014-04-23 11:45:37 -07001114 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
1115 out.attribute(null, ATTR_ID, String.valueOf(createTime));
1116 out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
1117 if (launchedFromPackage != null) {
1118 out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage);
1119 }
1120 if (resolvedType != null) {
1121 out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType);
1122 }
1123 out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified));
1124 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Winson Chung2cb86c72014-06-25 12:03:30 -07001125
Craig Mautner21d24a22014-04-23 11:45:37 -07001126 if (taskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001127 taskDescription.saveToXml(out);
Craig Mautner21d24a22014-04-23 11:45:37 -07001128 }
1129
1130 out.startTag(null, TAG_INTENT);
1131 intent.saveToXml(out);
1132 out.endTag(null, TAG_INTENT);
1133
1134 if (isPersistable() && persistentState != null) {
1135 out.startTag(null, TAG_PERSISTABLEBUNDLE);
1136 persistentState.saveToXml(out);
1137 out.endTag(null, TAG_PERSISTABLEBUNDLE);
1138 }
1139 }
1140
1141 static ActivityRecord restoreFromXml(XmlPullParser in, int taskId,
1142 ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
1143 Intent intent = null;
1144 PersistableBundle persistentState = null;
1145 int launchedFromUid = 0;
1146 String launchedFromPackage = null;
1147 String resolvedType = null;
1148 boolean componentSpecified = false;
1149 int userId = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07001150 long createTime = -1;
1151 final int outerDepth = in.getDepth();
Winson Chung2cb86c72014-06-25 12:03:30 -07001152 TaskDescription taskDescription = new TaskDescription();
Craig Mautner21d24a22014-04-23 11:45:37 -07001153
1154 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1155 final String attrName = in.getAttributeName(attrNdx);
1156 final String attrValue = in.getAttributeValue(attrNdx);
1157 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "ActivityRecord: attribute name=" +
1158 attrName + " value=" + attrValue);
1159 if (ATTR_ID.equals(attrName)) {
1160 createTime = Long.valueOf(attrValue);
1161 } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
1162 launchedFromUid = Integer.valueOf(attrValue);
1163 } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
1164 launchedFromPackage = attrValue;
1165 } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
1166 resolvedType = attrValue;
1167 } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
1168 componentSpecified = Boolean.valueOf(attrValue);
1169 } else if (ATTR_USERID.equals(attrName)) {
1170 userId = Integer.valueOf(attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001171 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1172 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001173 } else {
1174 Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName);
1175 }
1176 }
1177
1178 int event;
1179 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
1180 (event != XmlPullParser.END_TAG || in.getDepth() < outerDepth)) {
1181 if (event == XmlPullParser.START_TAG) {
1182 final String name = in.getName();
1183 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
1184 "ActivityRecord: START_TAG name=" + name);
1185 if (TAG_INTENT.equals(name)) {
1186 intent = Intent.restoreFromXml(in);
1187 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
1188 "ActivityRecord: intent=" + intent);
1189 } else if (TAG_PERSISTABLEBUNDLE.equals(name)) {
1190 persistentState = PersistableBundle.restoreFromXml(in);
1191 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
1192 "ActivityRecord: persistentState=" + persistentState);
1193 } else {
1194 Slog.w(TAG, "restoreActivity: unexpected name=" + name);
1195 XmlUtils.skipCurrentTag(in);
1196 }
1197 }
1198 }
1199
1200 if (intent == null) {
Craig Mautnere0129b32014-05-25 16:41:09 -07001201 throw new XmlPullParserException("restoreActivity error intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07001202 }
1203
1204 final ActivityManagerService service = stackSupervisor.mService;
1205 final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null,
Jeff Hao1b012d32014-08-20 10:35:34 -07001206 userId);
Craig Mautnere0129b32014-05-25 16:41:09 -07001207 if (aInfo == null) {
Craig Mautner77b04262014-06-27 15:22:12 -07001208 throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent +
1209 " resolvedType=" + resolvedType);
Craig Mautnere0129b32014-05-25 16:41:09 -07001210 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001211 final ActivityRecord r = new ActivityRecord(service, /*caller*/null, launchedFromUid,
1212 launchedFromPackage, intent, resolvedType, aInfo, service.getConfiguration(),
1213 null, null, 0, componentSpecified, stackSupervisor, null, null);
1214
1215 r.persistentState = persistentState;
Winson Chung2cb86c72014-06-25 12:03:30 -07001216 r.taskDescription = taskDescription;
Craig Mautner21d24a22014-04-23 11:45:37 -07001217 r.createTime = createTime;
1218
1219 return r;
1220 }
1221
1222 private static String activityTypeToString(int type) {
Craig Mautnerae7ecab2013-09-18 11:48:14 -07001223 switch (type) {
1224 case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE";
1225 case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE";
1226 case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE";
1227 default: return Integer.toString(type);
1228 }
1229 }
1230
Craig Mautnerf81b90872013-02-26 13:02:43 -08001231 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001233 if (stringName != null) {
Craig Mautnerf3333272013-04-22 10:55:53 -07001234 return stringName + " t" + (task == null ? -1 : task.taskId) +
1235 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001236 }
1237 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -08001238 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001239 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -07001240 sb.append(" u");
1241 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001242 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001243 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -08001244 stringName = sb.toString();
1245 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001246 }
1247}