blob: 51b998453b58d7079c868fb134acf8a1b7cc440d [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
Dianne Hackborn2d69d492012-04-06 16:24:14 -070019import com.android.internal.app.ResolverActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import com.android.server.AttributeCache;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070021import com.android.server.am.ActivityStack.ActivityState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022
Dianne Hackborn7a2195c2012-03-19 17:38:00 -070023import android.app.ActivityOptions;
Craig Mautner05d6272ba2013-02-11 09:39:27 -080024import android.app.ResultInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.ComponentName;
26import android.content.Intent;
27import android.content.pm.ActivityInfo;
28import android.content.pm.ApplicationInfo;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -070029import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.content.res.Configuration;
31import android.graphics.Bitmap;
Dianne Hackbornd367ca82012-05-07 15:49:39 -070032import android.graphics.Rect;
Dianne Hackborn247fe742011-01-08 17:25:57 -080033import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.os.Bundle;
Dianne Hackbornbe707852011-11-11 14:32:10 -080035import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.os.Message;
37import android.os.Process;
Dianne Hackborn39792d22010-08-19 18:01:52 -070038import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.os.SystemClock;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070040import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.util.EventLog;
42import android.util.Log;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070043import android.util.Slog;
Dianne Hackborn0dad3642010-09-09 21:25:35 -070044import android.util.TimeUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import android.view.IApplicationToken;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -080046import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047
48import java.io.PrintWriter;
49import java.lang.ref.WeakReference;
50import java.util.ArrayList;
51import java.util.HashSet;
52
53/**
54 * An entry in the history stack, representing an activity.
55 */
Dianne Hackbornbe707852011-11-11 14:32:10 -080056final class ActivityRecord {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -070057 static final String TAG = ActivityManagerService.TAG;
58 static final boolean DEBUG_SAVED_STATE = ActivityStackSupervisor.DEBUG_SAVED_STATE;
59
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 final ActivityManagerService service; // owner
Dianne Hackbornbe707852011-11-11 14:32:10 -080061 final IApplicationToken.Stub appToken; // window manager token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 final ActivityInfo info; // all about me
63 final int launchedFromUid; // always the uid who started the activity.
Dianne Hackbornf265ea92013-01-31 15:00:51 -080064 final String launchedFromPackage; // always the package who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -070065 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 final Intent intent; // the original intent that generated us
67 final ComponentName realActivity; // the intent component, or target of an alias.
68 final String shortComponentName; // the short component name of the intent
69 final String resolvedType; // as per original caller;
70 final String packageName; // the package implementing intent's component
71 final String processName; // process where this component wants to run
72 final String taskAffinity; // as per ActivityInfo.taskAffinity
73 final boolean stateNotNeeded; // As per ActivityInfo.flags
Dianne Hackbornff801ec2011-01-22 18:05:38 -080074 final boolean fullscreen; // covers the full screen?
75 final boolean noDisplay; // activity is not displayed?
The Android Open Source Project4df24232009-03-05 14:34:35 -080076 final boolean componentSpecified; // did caller specifiy an explicit component?
77 final boolean isHomeActivity; // do we consider this to be a home activity?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 final String baseDir; // where activity source (resources etc) located
79 final String resDir; // where public activity source (public resources etc) located
80 final String dataDir; // where activity data should go
81 CharSequence nonLocalizedLabel; // the label information from the package mgr.
82 int labelRes; // the label information from the package mgr.
83 int icon; // resource identifier of activity's icon.
84 int theme; // resource identifier of activity's theme.
Dianne Hackborn247fe742011-01-08 17:25:57 -080085 int realTheme; // actual theme resource we will use, never 0.
Dianne Hackborn7eec10e2010-11-12 18:03:47 -080086 int windowFlags; // custom window flags for preview window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 TaskRecord task; // the task this is in.
Dianne Hackbornf26fd992011-04-08 18:14:09 -070088 ThumbnailHolder thumbHolder; // where our thumbnails should go.
Dianne Hackborn0dad3642010-09-09 21:25:35 -070089 long launchTime; // when we starting launching this activity
90 long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -080091 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -070092 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -070093 long pauseTime; // last time we started pausing the activity
94 long launchTickTime; // base time for launch tick messages
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 Configuration configuration; // configuration activity was last running in
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -070096 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -070097 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 final String resultWho; // additional identifier for use by resultTo.
99 final int requestCode; // code given by requester (resultTo)
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800100 ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800102 ArrayList<Intent> newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700103 ActivityOptions pendingOptions; // most recently given options
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700105 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700106 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700107 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 Bundle icicle; // last saved activity state
109 boolean frontOfTask; // is this the root activity of its task?
110 boolean launchFailed; // set if a launched failed, to abort on 2nd try
111 boolean haveState; // have we gotten the last activity state?
112 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700113 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 boolean finishing; // activity in pending finish list?
115 boolean configDestroy; // need to destroy due to config change?
116 int configChangeFlags; // which config values have changed
117 boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 int launchMode; // the launch mode activity attribute.
119 boolean visible; // does this activity's window need to be shown?
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800120 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 boolean waitingVisible; // true if waiting for a new act to become vis
122 boolean nowVisible; // is this activity's window visible?
123 boolean thumbnailNeeded;// has someone requested a thumbnail?
124 boolean idle; // has the activity gone idle?
125 boolean hasBeenLaunched;// has this activity ever been launched?
126 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400127 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400128 boolean forceNewConfig; // force re-create with new config next time
Dianne Hackborn07981492013-01-28 11:36:23 -0800129 int launchCount; // count of launches since last state
130 long lastLaunchTime; // time of last lauch of this activity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700132 String stringName; // for caching of toString().
Craig Mautnerde4ef022013-04-07 19:01:33 -0700133
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700134 private boolean inHistory; // are we in the history stack?
Craig Mautnerde4ef022013-04-07 19:01:33 -0700135 final ActivityStackSupervisor mStackSupervisor;
136
137 /** Launch the home activity rather than the activity at the top of stack */
138 boolean mLaunchHomeTaskNext;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700141 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700142 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
143 pw.print(" processName="); pw.println(processName);
144 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Craig Mautnere11f2b72013-04-01 12:37:17 -0700145 pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800146 pw.print(" userId="); pw.println(userId);
147 pw.print(prefix); pw.print("app="); pw.println(app);
148 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700149 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
150 pw.print(" task="); pw.println(task);
151 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700152 pw.print(prefix); pw.print("realActivity=");
153 pw.println(realActivity.flattenToShortString());
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800154 pw.print(prefix); pw.print("baseDir="); pw.println(baseDir);
155 if (!resDir.equals(baseDir)) {
156 pw.print(prefix); pw.print("resDir="); pw.println(resDir);
157 }
158 pw.print(prefix); pw.print("dataDir="); pw.println(dataDir);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700159 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
160 pw.print(" componentSpecified="); pw.print(componentSpecified);
161 pw.print(" isHomeActivity="); pw.println(isHomeActivity);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800162 pw.print(prefix); pw.print("compat="); pw.print(compat);
163 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
164 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
165 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Dianne Hackborne17aeb32011-04-07 15:11:57 -0700166 pw.print(prefix); pw.print("config="); pw.println(configuration);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700167 if (resultTo != null || resultWho != null) {
168 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
169 pw.print(" resultWho="); pw.print(resultWho);
170 pw.print(" resultCode="); pw.println(requestCode);
171 }
172 if (results != null) {
173 pw.print(prefix); pw.print("results="); pw.println(results);
174 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700175 if (pendingResults != null && pendingResults.size() > 0) {
176 pw.print(prefix); pw.println("Pending Results:");
177 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
178 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
179 pw.print(prefix); pw.print(" - ");
180 if (pir == null) {
181 pw.println("null");
182 } else {
183 pw.println(pir);
184 pir.dump(pw, prefix + " ");
185 }
186 }
187 }
188 if (newIntents != null && newIntents.size() > 0) {
189 pw.print(prefix); pw.println("Pending New Intents:");
190 for (int i=0; i<newIntents.size(); i++) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800191 Intent intent = newIntents.get(i);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700192 pw.print(prefix); pw.print(" - ");
193 if (intent == null) {
194 pw.println("null");
195 } else {
196 pw.println(intent.toShortString(false, true, false, true));
197 }
198 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700199 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700200 if (pendingOptions != null) {
201 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
202 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700203 if (uriPermissions != null) {
204 if (uriPermissions.readUriPermissions != null) {
205 pw.print(prefix); pw.print("readUriPermissions=");
206 pw.println(uriPermissions.readUriPermissions);
207 }
208 if (uriPermissions.writeUriPermissions != null) {
209 pw.print(prefix); pw.print("writeUriPermissions=");
210 pw.println(uriPermissions.writeUriPermissions);
211 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700212 }
213 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800214 pw.print(" launchCount="); pw.print(launchCount);
215 pw.print(" lastLaunchTime=");
216 if (lastLaunchTime == 0) pw.print("0");
217 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
218 pw.println();
219 pw.print(prefix); pw.print(" haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700220 pw.print(" icicle="); pw.println(icicle);
221 pw.print(prefix); pw.print("state="); pw.print(state);
222 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700223 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700224 pw.print(" finishing="); pw.println(finishing);
225 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
226 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700227 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800228 pw.print(" sleeping="); pw.print(sleeping);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700229 pw.print(" idle="); pw.println(idle);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800230 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
231 pw.print(" noDisplay="); pw.print(noDisplay);
232 pw.print(" immersive="); pw.print(immersive);
233 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800234 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400235 pw.print(" thumbnailNeeded="); pw.print(thumbnailNeeded);
236 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Dianne Hackborn15491c62012-09-19 10:59:14 -0700237 pw.print(prefix); pw.print("thumbHolder: ");
238 pw.print(Integer.toHexString(System.identityHashCode(thumbHolder)));
239 if (thumbHolder != null) {
240 pw.print(" bm="); pw.print(thumbHolder.lastThumbnail);
241 pw.print(" desc="); pw.print(thumbHolder.lastDescription);
242 }
243 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700244 if (launchTime != 0 || startTime != 0) {
245 pw.print(prefix); pw.print("launchTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700246 if (launchTime == 0) pw.print("0");
247 else TimeUtils.formatDuration(launchTime, now, pw);
248 pw.print(" startTime=");
249 if (startTime == 0) pw.print("0");
250 else TimeUtils.formatDuration(startTime, now, pw);
251 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700252 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800253 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700254 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800255 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700256 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700257 if (lastVisibleTime == 0) pw.print("0");
258 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
259 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700260 }
261 if (configDestroy || configChangeFlags != 0) {
262 pw.print(prefix); pw.print("configDestroy="); pw.print(configDestroy);
263 pw.print(" configChangeFlags=");
264 pw.println(Integer.toHexString(configChangeFlags));
265 }
266 if (connections != null) {
267 pw.print(prefix); pw.print("connections="); pw.println(connections);
268 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 }
270
Dianne Hackbornbe707852011-11-11 14:32:10 -0800271 static class Token extends IApplicationToken.Stub {
272 final WeakReference<ActivityRecord> weakActivity;
273
274 Token(ActivityRecord activity) {
275 weakActivity = new WeakReference<ActivityRecord>(activity);
276 }
277
Craig Mautnerde4ef022013-04-07 19:01:33 -0700278 @Override public void windowsDrawn() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800279 ActivityRecord activity = weakActivity.get();
280 if (activity != null) {
281 activity.windowsDrawn();
282 }
283 }
284
Craig Mautnerde4ef022013-04-07 19:01:33 -0700285 @Override public void windowsVisible() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800286 ActivityRecord activity = weakActivity.get();
287 if (activity != null) {
288 activity.windowsVisible();
289 }
290 }
291
Craig Mautnerde4ef022013-04-07 19:01:33 -0700292 @Override public void windowsGone() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800293 ActivityRecord activity = weakActivity.get();
294 if (activity != null) {
295 activity.windowsGone();
296 }
297 }
298
Craig Mautnerde4ef022013-04-07 19:01:33 -0700299 @Override public boolean keyDispatchingTimedOut() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800300 ActivityRecord activity = weakActivity.get();
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700301 return activity != null && activity.keyDispatchingTimedOut();
Dianne Hackbornbe707852011-11-11 14:32:10 -0800302 }
303
Craig Mautnerde4ef022013-04-07 19:01:33 -0700304 @Override public long getKeyDispatchingTimeout() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800305 ActivityRecord activity = weakActivity.get();
306 if (activity != null) {
307 return activity.getKeyDispatchingTimeout();
308 }
309 return 0;
310 }
311
Craig Mautnerde4ef022013-04-07 19:01:33 -0700312 @Override
Dianne Hackbornbe707852011-11-11 14:32:10 -0800313 public String toString() {
314 StringBuilder sb = new StringBuilder(128);
315 sb.append("Token{");
316 sb.append(Integer.toHexString(System.identityHashCode(this)));
317 sb.append(' ');
318 sb.append(weakActivity.get());
319 sb.append('}');
320 return sb.toString();
321 }
322 }
323
324 static ActivityRecord forToken(IBinder token) {
325 try {
326 return token != null ? ((Token)token).weakActivity.get() : null;
327 } catch (ClassCastException e) {
328 Slog.w(ActivityManagerService.TAG, "Bad activity token: " + token, e);
329 return null;
330 }
331 }
332
Craig Mautnerd2328952013-03-05 12:46:26 -0800333 ActivityRecord(ActivityManagerService _service, ProcessRecord _caller,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800334 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700336 ActivityRecord _resultTo, String _resultWho, int _reqCode,
Craig Mautnerde4ef022013-04-07 19:01:33 -0700337 boolean _componentSpecified, ActivityStackSupervisor supervisor) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 service = _service;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800339 appToken = new Token(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 info = aInfo;
341 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800342 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700343 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 intent = _intent;
345 shortComponentName = _intent.getComponent().flattenToShortString();
346 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800347 componentSpecified = _componentSpecified;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348 configuration = _configuration;
349 resultTo = _resultTo;
350 resultWho = _resultWho;
351 requestCode = _reqCode;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700352 state = ActivityState.INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 frontOfTask = false;
354 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700356 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 finishing = false;
358 configDestroy = false;
359 keysPaused = false;
360 inHistory = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 visible = true;
362 waitingVisible = false;
363 nowVisible = false;
364 thumbnailNeeded = false;
365 idle = false;
366 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700367 mStackSupervisor = supervisor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700369 // This starts out true, since the initial state of an activity
370 // is that we have everything, and we shouldn't never consider it
371 // lacking in state to be removed if it dies.
372 haveState = true;
373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 if (aInfo != null) {
375 if (aInfo.targetActivity == null
376 || aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE
377 || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
378 realActivity = _intent.getComponent();
379 } else {
380 realActivity = new ComponentName(aInfo.packageName,
381 aInfo.targetActivity);
382 }
383 taskAffinity = aInfo.taskAffinity;
384 stateNotNeeded = (aInfo.flags&
385 ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0;
386 baseDir = aInfo.applicationInfo.sourceDir;
387 resDir = aInfo.applicationInfo.publicSourceDir;
388 dataDir = aInfo.applicationInfo.dataDir;
389 nonLocalizedLabel = aInfo.nonLocalizedLabel;
390 labelRes = aInfo.labelRes;
391 if (nonLocalizedLabel == null && labelRes == 0) {
392 ApplicationInfo app = aInfo.applicationInfo;
393 nonLocalizedLabel = app.nonLocalizedLabel;
394 labelRes = app.labelRes;
395 }
396 icon = aInfo.getIconResource();
397 theme = aInfo.getThemeResource();
Dianne Hackborn247fe742011-01-08 17:25:57 -0800398 realTheme = theme;
399 if (realTheme == 0) {
400 realTheme = aInfo.applicationInfo.targetSdkVersion
401 < Build.VERSION_CODES.HONEYCOMB
402 ? android.R.style.Theme
403 : android.R.style.Theme_Holo;
404 }
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800405 if ((aInfo.flags&ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
406 windowFlags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
407 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0
409 && _caller != null
410 && (aInfo.applicationInfo.uid == Process.SYSTEM_UID
411 || aInfo.applicationInfo.uid == _caller.info.uid)) {
412 processName = _caller.processName;
413 } else {
414 processName = aInfo.processName;
415 }
416
417 if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
418 intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
419 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 packageName = aInfo.applicationInfo.packageName;
422 launchMode = aInfo.launchMode;
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800424 AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
Dianne Hackborn247fe742011-01-08 17:25:57 -0800425 realTheme, com.android.internal.R.styleable.Window);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 fullscreen = ent != null && !ent.array.getBoolean(
427 com.android.internal.R.styleable.Window_windowIsFloating, false)
428 && !ent.array.getBoolean(
429 com.android.internal.R.styleable.Window_windowIsTranslucent, false);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800430 noDisplay = ent != null && ent.array.getBoolean(
431 com.android.internal.R.styleable.Window_windowNoDisplay, false);
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700432
433 // If we know the system has determined the component, then
434 // we can consider this to be a home activity...
435 // Note the last check is so we don't count the resolver
436 // activity as being home... really, we don't care about
437 // doing anything special with something that comes from
438 // the core framework package.
439 isHomeActivity =
440 (!_componentSpecified || _launchedFromUid == Process.myUid()
441 || _launchedFromUid == 0) &&
442 Intent.ACTION_MAIN.equals(_intent.getAction()) &&
443 _intent.hasCategory(Intent.CATEGORY_HOME) &&
444 _intent.getCategories().size() == 1 &&
445 _intent.getData() == null &&
446 _intent.getType() == null &&
447 (intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 &&
448 !ResolverActivity.class.getName().equals(realActivity.getClassName());
The Android Open Source Project4df24232009-03-05 14:34:35 -0800449 // This sure looks like a home activity!
Daniel Sandler69a48172010-06-23 16:29:36 -0400450
451 immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 } else {
453 realActivity = null;
454 taskAffinity = null;
455 stateNotNeeded = false;
456 baseDir = null;
457 resDir = null;
458 dataDir = null;
459 processName = null;
460 packageName = null;
461 fullscreen = true;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800462 noDisplay = false;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800463 isHomeActivity = false;
Daniel Sandler69a48172010-06-23 16:29:36 -0400464 immersive = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465 }
466 }
467
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700468 void setTask(TaskRecord newTask, ThumbnailHolder newThumbHolder, boolean isRoot) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700469 if (task != null && task.removeActivity(this)) {
470 mStackSupervisor.removeTask(task);
471 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700472 if (inHistory && !finishing) {
473 if (task != null) {
474 task.numActivities--;
475 }
476 if (newTask != null) {
477 newTask.numActivities++;
478 }
479 }
480 if (newThumbHolder == null) {
481 newThumbHolder = newTask;
482 }
483 task = newTask;
484 if (!isRoot && (intent.getFlags()&Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
485 // This is the start of a new sub-task.
486 if (thumbHolder == null) {
487 thumbHolder = new ThumbnailHolder();
488 }
489 } else {
490 thumbHolder = newThumbHolder;
491 }
492 }
493
494 void putInHistory() {
495 if (!inHistory) {
496 inHistory = true;
497 if (task != null && !finishing) {
498 task.numActivities++;
499 }
500 }
501 }
502
503 void takeFromHistory() {
504 if (inHistory) {
505 inHistory = false;
506 if (task != null && !finishing) {
507 task.numActivities--;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800508 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700509 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700510 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700511 }
512 }
513
514 boolean isInHistory() {
515 return inHistory;
516 }
517
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800518 void makeFinishing() {
519 if (!finishing) {
520 finishing = true;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700521 if (task != null && inHistory) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800522 task.numActivities--;
523 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700524 if (stopped) {
525 clearOptionsLocked();
526 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800527 }
528 }
529
Craig Mautnerde4ef022013-04-07 19:01:33 -0700530 boolean isRootActivity() {
531 ArrayList<ActivityRecord> activities = task.mActivities;
532 return activities.size() == 0 || this == task.mActivities.get(0);
533 }
534
Dianne Hackborn7e269642010-08-25 19:50:20 -0700535 UriPermissionOwner getUriPermissionsLocked() {
536 if (uriPermissions == null) {
537 uriPermissions = new UriPermissionOwner(service, this);
538 }
539 return uriPermissions;
540 }
541
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700542 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 int requestCode, int resultCode,
544 Intent resultData) {
545 ActivityResult r = new ActivityResult(from, resultWho,
546 requestCode, resultCode, resultData);
547 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800548 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 }
550 results.add(r);
551 }
552
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700553 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 int requestCode) {
555 if (results != null) {
556 for (int i=results.size()-1; i>=0; i--) {
557 ActivityResult r = (ActivityResult)results.get(i);
558 if (r.mFrom != from) continue;
559 if (r.mResultWho == null) {
560 if (resultWho != null) continue;
561 } else {
562 if (!r.mResultWho.equals(resultWho)) continue;
563 }
564 if (r.mRequestCode != requestCode) continue;
565
566 results.remove(i);
567 }
568 }
569 }
570
571 void addNewIntentLocked(Intent intent) {
572 if (newIntents == null) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800573 newIntents = new ArrayList<Intent>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 }
575 newIntents.add(intent);
576 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700577
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700578 /**
579 * Deliver a new Intent to an existing activity, so that its onNewIntent()
580 * method will be called at the proper time.
581 */
Dianne Hackborn39792d22010-08-19 18:01:52 -0700582 final void deliverNewIntentLocked(int callingUid, Intent intent) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700583 boolean sent = false;
Dianne Hackborn514074f2013-02-11 10:52:46 -0800584 // The activity now gets access to the data associated with this Intent.
585 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
586 intent, getUriPermissionsLocked());
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700587 // We want to immediately deliver the intent to the activity if
588 // it is currently the top resumed activity... however, if the
589 // device is sleeping, then all activities are stopped, so in that
590 // case we will deliver it if this is the current top activity on its
591 // stack.
592 if ((state == ActivityState.RESUMED || (service.mSleeping
Craig Mautnerd2328952013-03-05 12:46:26 -0800593 && task.stack.topRunningActivityLocked(null) == this))
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700594 && app != null && app.thread != null) {
595 try {
596 ArrayList<Intent> ar = new ArrayList<Intent>();
Dianne Hackborn39792d22010-08-19 18:01:52 -0700597 intent = new Intent(intent);
598 ar.add(intent);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800599 app.thread.scheduleNewIntent(ar, appToken);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700600 sent = true;
Dianne Hackborn39792d22010-08-19 18:01:52 -0700601 } catch (RemoteException e) {
602 Slog.w(ActivityManagerService.TAG,
603 "Exception thrown sending new intent to " + this, e);
604 } catch (NullPointerException e) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700605 Slog.w(ActivityManagerService.TAG,
606 "Exception thrown sending new intent to " + this, e);
607 }
608 }
609 if (!sent) {
610 addNewIntentLocked(new Intent(intent));
611 }
612 }
613
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700614 void updateOptionsLocked(Bundle options) {
615 if (options != null) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700616 if (pendingOptions != null) {
617 pendingOptions.abort();
618 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700619 pendingOptions = new ActivityOptions(options);
620 }
621 }
622
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700623 void updateOptionsLocked(ActivityOptions options) {
624 if (options != null) {
625 if (pendingOptions != null) {
626 pendingOptions.abort();
627 }
628 pendingOptions = options;
629 }
630 }
631
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700632 void applyOptionsLocked() {
633 if (pendingOptions != null) {
Michael Jurka21385cd2012-05-03 10:57:31 -0700634 final int animationType = pendingOptions.getAnimationType();
635 switch (animationType) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700636 case ActivityOptions.ANIM_CUSTOM:
637 service.mWindowManager.overridePendingAppTransition(
638 pendingOptions.getPackageName(),
639 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -0700640 pendingOptions.getCustomExitResId(),
641 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700642 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700643 case ActivityOptions.ANIM_SCALE_UP:
644 service.mWindowManager.overridePendingAppTransitionScaleUp(
645 pendingOptions.getStartX(), pendingOptions.getStartY(),
646 pendingOptions.getStartWidth(), pendingOptions.getStartHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700647 if (intent.getSourceBounds() == null) {
648 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
649 pendingOptions.getStartY(),
650 pendingOptions.getStartX()+pendingOptions.getStartWidth(),
651 pendingOptions.getStartY()+pendingOptions.getStartHeight()));
652 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700653 break;
Michael Jurka832cb222012-04-13 09:32:47 -0700654 case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
655 case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
656 boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700657 service.mWindowManager.overridePendingAppTransitionThumb(
658 pendingOptions.getThumbnail(),
659 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -0700660 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -0700661 scaleUp);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700662 if (intent.getSourceBounds() == null) {
663 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
664 pendingOptions.getStartY(),
665 pendingOptions.getStartX()
666 + pendingOptions.getThumbnail().getWidth(),
667 pendingOptions.getStartY()
668 + pendingOptions.getThumbnail().getHeight()));
669 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700670 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700671 }
672 pendingOptions = null;
673 }
674 }
675
676 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700677 if (pendingOptions != null) {
678 pendingOptions.abort();
679 pendingOptions = null;
680 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700681 }
682
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700683 ActivityOptions takeOptionsLocked() {
684 ActivityOptions opts = pendingOptions;
685 pendingOptions = null;
686 return opts;
687 }
688
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700689 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -0700690 if (uriPermissions != null) {
691 uriPermissions.removeUriPermissionsLocked();
692 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700693 }
694 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800695
696 void pauseKeyDispatchingLocked() {
697 if (!keysPaused) {
698 keysPaused = true;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800699 service.mWindowManager.pauseKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700 }
701 }
702
703 void resumeKeyDispatchingLocked() {
704 if (keysPaused) {
705 keysPaused = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800706 service.mWindowManager.resumeKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 }
708 }
709
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700710 void updateThumbnail(Bitmap newThumbnail, CharSequence description) {
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700711 if (thumbHolder != null) {
712 if (newThumbnail != null) {
Dianne Hackborn15491c62012-09-19 10:59:14 -0700713 if (ActivityManagerService.DEBUG_THUMBNAILS) Slog.i(ActivityManagerService.TAG,
714 "Setting thumbnail of " + this + " holder " + thumbHolder
715 + " to " + newThumbnail);
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700716 thumbHolder.lastThumbnail = newThumbnail;
717 }
718 thumbHolder.lastDescription = description;
719 }
720 }
721
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700722 void startLaunchTickingLocked() {
723 if (ActivityManagerService.IS_USER_BUILD) {
724 return;
725 }
726 if (launchTickTime == 0) {
727 launchTickTime = SystemClock.uptimeMillis();
728 continueLaunchTickingLocked();
729 }
730 }
731
732 boolean continueLaunchTickingLocked() {
733 if (launchTickTime != 0) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800734 final ActivityStack stack = task.stack;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700735 Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG);
736 msg.obj = this;
737 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
738 stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
739 return true;
740 }
741 return false;
742 }
743
744 void finishLaunchTickingLocked() {
745 launchTickTime = 0;
Craig Mautnerd2328952013-03-05 12:46:26 -0800746 task.stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700747 }
748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749 // IApplicationToken
750
751 public boolean mayFreezeScreenLocked(ProcessRecord app) {
752 // Only freeze the screen if this activity is currently attached to
753 // an application, and that application is not blocked or unresponding.
754 // In any other case, we can't count on getting the screen unfrozen,
755 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -0800756 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
760 if (mayFreezeScreenLocked(app)) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800761 service.mWindowManager.startAppFreezingScreen(appToken, configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 }
763 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 public void stopFreezingScreenLocked(boolean force) {
766 if (force || frozenBeforeDestroy) {
767 frozenBeforeDestroy = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800768 service.mWindowManager.stopAppFreezingScreen(appToken, force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 }
770 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700771
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700772 public void windowsDrawn() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 synchronized(service) {
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700774 if (launchTime != 0) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800775 final ActivityStack stack = task.stack;
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700776 final long curTime = SystemClock.uptimeMillis();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700777 final long thisTime = curTime - launchTime;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700778 final long totalTime = stack.mInitialStartTime != 0
779 ? (curTime - stack.mInitialStartTime) : thisTime;
Dianne Hackborn6447ca32009-04-07 19:50:08 -0700780 if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700781 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
782 userId, System.identityHashCode(this), shortComponentName,
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700783 thisTime, totalTime);
784 StringBuilder sb = service.mStringBuilder;
785 sb.setLength(0);
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700786 sb.append("Displayed ");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700787 sb.append(shortComponentName);
788 sb.append(": ");
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700789 TimeUtils.formatDuration(thisTime, sb);
Dianne Hackborncef65ee2010-09-30 18:27:22 -0700790 if (thisTime != totalTime) {
791 sb.append(" (total ");
792 TimeUtils.formatDuration(totalTime, sb);
793 sb.append(")");
794 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700795 Log.i(ActivityManagerService.TAG, sb.toString());
Dianne Hackborn6447ca32009-04-07 19:50:08 -0700796 }
Craig Mautnerce5f3cb2013-04-22 08:58:54 -0700797 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700798 if (totalTime > 0) {
799 service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn6447ca32009-04-07 19:50:08 -0700800 }
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700801 launchTime = 0;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700802 stack.mInitialStartTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800803 }
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700804 startTime = 0;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700805 finishLaunchTickingLocked();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700806 }
807 }
808
809 public void windowsVisible() {
810 synchronized(service) {
Craig Mautnerce5f3cb2013-04-22 08:58:54 -0700811 mStackSupervisor.reportActivityVisibleLocked(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
813 ActivityManagerService.TAG, "windowsVisible(): " + this);
814 if (!nowVisible) {
815 nowVisible = true;
Dianne Hackborn50685602011-12-01 12:23:37 -0800816 lastVisibleTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800817 if (!idle) {
818 // Instead of doing the full stop routine here, let's just
819 // hide any activities we now can, and let them stop when
820 // the normal idle happens.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700821 mStackSupervisor.processStoppingActivitiesLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 } else {
823 // If this activity was already idle, then we now need to
824 // make sure we perform the full stop of any activities
825 // that are waiting to do so. This is because we won't
826 // do that while they are still waiting for this one to
827 // become visible.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700828 final int N = mStackSupervisor.mWaitingVisibleActivities.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 if (N > 0) {
830 for (int i=0; i<N; i++) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700831 ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 r.waitingVisible = false;
833 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
834 ActivityManagerService.TAG,
835 "Was waiting for visible: " + r);
836 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700837 mStackSupervisor.mWaitingVisibleActivities.clear();
Craig Mautnerf3333272013-04-22 10:55:53 -0700838 mStackSupervisor.scheduleIdleLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 }
840 }
841 service.scheduleAppGcsLocked();
842 }
843 }
844 }
845
846 public void windowsGone() {
847 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
848 ActivityManagerService.TAG, "windowsGone(): " + this);
849 nowVisible = false;
850 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700851
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700852 private ActivityRecord getWaitingHistoryRecordLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853 // First find the real culprit... if we are waiting
854 // for another app to start, then we have paused dispatching
855 // for this activity.
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700856 ActivityRecord r = this;
Craig Mautnerd2328952013-03-05 12:46:26 -0800857 final ActivityStack stack = task.stack;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800858 if (r.waitingVisible) {
859 // Hmmm, who might we be waiting for?
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700860 r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -0800862 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800863 }
864 // Both of those null? Fall back to 'this' again
865 if (r == null) {
866 r = this;
867 }
868 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870 return r;
871 }
872
873 public boolean keyDispatchingTimedOut() {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700874 ActivityRecord r;
Michael Wright7dd5bb12013-02-27 17:07:29 -0800875 ProcessRecord anrApp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800876 synchronized(service) {
Dianne Hackbornad5499d2010-03-29 18:08:45 -0700877 r = getWaitingHistoryRecordLocked();
Michael Wright7dd5bb12013-02-27 17:07:29 -0800878 anrApp = r != null ? r.app : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879 }
Michael Wright7dd5bb12013-02-27 17:07:29 -0800880 return service.inputDispatchingTimedOut(anrApp, r, this, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 /** Returns the key dispatching timeout for this application token. */
884 public long getKeyDispatchingTimeout() {
885 synchronized(service) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700886 ActivityRecord r = getWaitingHistoryRecordLocked();
Michael Wright7dd5bb12013-02-27 17:07:29 -0800887 return ActivityManagerService.getInputDispatchingTimeoutLocked(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800888 }
889 }
890
891 /**
892 * This method will return true if the activity is either visible, is becoming visible, is
893 * currently pausing, or is resumed.
894 */
895 public boolean isInterestingToUserLocked() {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700896 return visible || nowVisible || state == ActivityState.PAUSING ||
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 state == ActivityState.RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800898 }
899
900 public void setSleeping(boolean _sleeping) {
901 if (sleeping == _sleeping) {
902 return;
903 }
904 if (app != null && app.thread != null) {
905 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800906 app.thread.scheduleSleeping(appToken, _sleeping);
Craig Mautnerd2328952013-03-05 12:46:26 -0800907 final ActivityStack stack = task.stack;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800908 if (sleeping && !stack.mGoingToSleepActivities.contains(this)) {
909 stack.mGoingToSleepActivities.add(this);
910 }
911 sleeping = _sleeping;
912 } catch (RemoteException e) {
913 Slog.w(ActivityStack.TAG, "Exception thrown when sleeping: "
914 + intent.getComponent(), e);
915 }
916 }
917 }
Craig Mautnerf81b90872013-02-26 13:02:43 -0800918
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700919 static void activityResumedLocked(IBinder token) {
920 final ActivityRecord r = ActivityRecord.forToken(token);
921 if (DEBUG_SAVED_STATE) Slog.i(TAG, "Resumed activity; dropping state of: " + r);
922 r.icicle = null;
923 r.haveState = false;
924 }
925
Craig Mautnerd2328952013-03-05 12:46:26 -0800926 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
927 final ActivityRecord r = ActivityRecord.forToken(token);
928 if (r == null) {
929 return -1;
930 }
931 final TaskRecord task = r.task;
932 switch (task.mActivities.indexOf(r)) {
933 case -1: return -1;
934 case 0: return task.taskId;
935 default: return onlyRoot ? -1 : task.taskId;
936 }
937 }
938
939 static ActivityRecord isInStackLocked(IBinder token) {
940 final ActivityRecord r = ActivityRecord.forToken(token);
941 if (r != null) {
942 return r.task.stack.isInStackLocked(token);
943 }
944 return null;
945 }
946
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700947 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800948 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
949 if (r != null) {
950 return r.task.stack;
951 }
952 return null;
953 }
954
Craig Mautnerf81b90872013-02-26 13:02:43 -0800955 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700957 if (stringName != null) {
Craig Mautnerf3333272013-04-22 10:55:53 -0700958 return stringName + " t" + (task == null ? -1 : task.taskId) +
959 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700960 }
961 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -0800962 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700963 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700964 sb.append(" u");
965 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700966 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700967 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -0800968 stringName = sb.toString();
969 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 }
971}