blob: e6849ede255d3220061afe268855f9e76d21ee63 [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 Hackborn2286cdc2013-07-01 19:10:06 -070019import android.os.Trace;
Craig Mautner5eda9b32013-07-02 11:58:16 -070020import com.android.internal.R.styleable;
Dianne Hackborn2d69d492012-04-06 16:24:14 -070021import com.android.internal.app.ResolverActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import com.android.server.AttributeCache;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070023import com.android.server.am.ActivityStack.ActivityState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
Dianne Hackborn7a2195c2012-03-19 17:38:00 -070025import android.app.ActivityOptions;
Craig Mautner05d6272ba2013-02-11 09:39:27 -080026import android.app.ResultInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.content.ComponentName;
28import android.content.Intent;
29import android.content.pm.ActivityInfo;
30import android.content.pm.ApplicationInfo;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -070031import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.content.res.Configuration;
33import android.graphics.Bitmap;
Dianne Hackbornd367ca82012-05-07 15:49:39 -070034import android.graphics.Rect;
Dianne Hackborn247fe742011-01-08 17:25:57 -080035import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.os.Bundle;
Dianne Hackbornbe707852011-11-11 14:32:10 -080037import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.os.Message;
39import android.os.Process;
Dianne Hackborn39792d22010-08-19 18:01:52 -070040import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.os.SystemClock;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070042import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import android.util.EventLog;
44import android.util.Log;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070045import android.util.Slog;
Dianne Hackborn0dad3642010-09-09 21:25:35 -070046import android.util.TimeUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import android.view.IApplicationToken;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -080048import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049
50import java.io.PrintWriter;
51import java.lang.ref.WeakReference;
52import java.util.ArrayList;
53import java.util.HashSet;
54
55/**
56 * An entry in the history stack, representing an activity.
57 */
Dianne Hackbornbe707852011-11-11 14:32:10 -080058final class ActivityRecord {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -070059 static final String TAG = ActivityManagerService.TAG;
60 static final boolean DEBUG_SAVED_STATE = ActivityStackSupervisor.DEBUG_SAVED_STATE;
61
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 final ActivityManagerService service; // owner
Dianne Hackbornbe707852011-11-11 14:32:10 -080063 final IApplicationToken.Stub appToken; // window manager token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 final ActivityInfo info; // all about me
65 final int launchedFromUid; // always the uid who started the activity.
Dianne Hackbornf265ea92013-01-31 15:00:51 -080066 final String launchedFromPackage; // always the package who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -070067 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 final Intent intent; // the original intent that generated us
69 final ComponentName realActivity; // the intent component, or target of an alias.
70 final String shortComponentName; // the short component name of the intent
71 final String resolvedType; // as per original caller;
72 final String packageName; // the package implementing intent's component
73 final String processName; // process where this component wants to run
74 final String taskAffinity; // as per ActivityInfo.taskAffinity
75 final boolean stateNotNeeded; // As per ActivityInfo.flags
Craig Mautner4addfc52013-06-25 08:05:45 -070076 boolean fullscreen; // covers the full screen?
Dianne Hackbornff801ec2011-01-22 18:05:38 -080077 final boolean noDisplay; // activity is not displayed?
The Android Open Source Project4df24232009-03-05 14:34:35 -080078 final boolean componentSpecified; // did caller specifiy an explicit component?
Craig Mautner86d67a42013-05-14 10:34:38 -070079
80 static final int APPLICATION_ACTIVITY_TYPE = 0;
81 static final int HOME_ACTIVITY_TYPE = 1;
82 static final int RECENTS_ACTIVITY_TYPE = 2;
83 final int mActivityType;
84
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 final String baseDir; // where activity source (resources etc) located
86 final String resDir; // where public activity source (public resources etc) located
87 final String dataDir; // where activity data should go
88 CharSequence nonLocalizedLabel; // the label information from the package mgr.
89 int labelRes; // the label information from the package mgr.
90 int icon; // resource identifier of activity's icon.
Adam Powell04fe6eb2013-05-31 14:39:48 -070091 int logo; // resource identifier of activity's logo.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 int theme; // resource identifier of activity's theme.
Dianne Hackborn247fe742011-01-08 17:25:57 -080093 int realTheme; // actual theme resource we will use, never 0.
Dianne Hackborn7eec10e2010-11-12 18:03:47 -080094 int windowFlags; // custom window flags for preview window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 TaskRecord task; // the task this is in.
Dianne Hackbornf26fd992011-04-08 18:14:09 -070096 ThumbnailHolder thumbHolder; // where our thumbnails should go.
Dianne Hackborn2286cdc2013-07-01 19:10:06 -070097 long displayStartTime; // when we started launching this activity
98 long fullyDrawnStartTime; // when we started launching this activity
Dianne Hackborn0dad3642010-09-09 21:25:35 -070099 long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -0800100 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700101 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700102 long pauseTime; // last time we started pausing the activity
103 long launchTickTime; // base time for launch tick messages
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 Configuration configuration; // configuration activity was last running in
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700105 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700106 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 final String resultWho; // additional identifier for use by resultTo.
108 final int requestCode; // code given by requester (resultTo)
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800109 ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800111 ArrayList<Intent> newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700112 ActivityOptions pendingOptions; // most recently given options
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700114 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700115 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700116 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 Bundle icicle; // last saved activity state
118 boolean frontOfTask; // is this the root activity of its task?
119 boolean launchFailed; // set if a launched failed, to abort on 2nd try
120 boolean haveState; // have we gotten the last activity state?
121 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700122 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 boolean finishing; // activity in pending finish list?
124 boolean configDestroy; // need to destroy due to config change?
125 int configChangeFlags; // which config values have changed
126 boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 int launchMode; // the launch mode activity attribute.
128 boolean visible; // does this activity's window need to be shown?
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800129 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 boolean waitingVisible; // true if waiting for a new act to become vis
131 boolean nowVisible; // is this activity's window visible?
132 boolean thumbnailNeeded;// has someone requested a thumbnail?
133 boolean idle; // has the activity gone idle?
134 boolean hasBeenLaunched;// has this activity ever been launched?
135 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400136 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400137 boolean forceNewConfig; // force re-create with new config next time
Dianne Hackborn07981492013-01-28 11:36:23 -0800138 int launchCount; // count of launches since last state
139 long lastLaunchTime; // time of last lauch of this activity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700141 String stringName; // for caching of toString().
Craig Mautnerde4ef022013-04-07 19:01:33 -0700142
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700143 private boolean inHistory; // are we in the history stack?
Craig Mautnerde4ef022013-04-07 19:01:33 -0700144 final ActivityStackSupervisor mStackSupervisor;
145
146 /** Launch the home activity rather than the activity at the top of stack */
147 boolean mLaunchHomeTaskNext;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700150 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700151 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
152 pw.print(" processName="); pw.println(processName);
153 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Craig Mautnere11f2b72013-04-01 12:37:17 -0700154 pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800155 pw.print(" userId="); pw.println(userId);
156 pw.print(prefix); pw.print("app="); pw.println(app);
157 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700158 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
159 pw.print(" task="); pw.println(task);
160 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700161 pw.print(prefix); pw.print("realActivity=");
162 pw.println(realActivity.flattenToShortString());
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800163 pw.print(prefix); pw.print("baseDir="); pw.println(baseDir);
164 if (!resDir.equals(baseDir)) {
165 pw.print(prefix); pw.print("resDir="); pw.println(resDir);
166 }
167 pw.print(prefix); pw.print("dataDir="); pw.println(dataDir);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700168 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
169 pw.print(" componentSpecified="); pw.print(componentSpecified);
Craig Mautner86d67a42013-05-14 10:34:38 -0700170 pw.print(" mActivityType="); pw.println(mActivityType);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800171 pw.print(prefix); pw.print("compat="); pw.print(compat);
172 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
173 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
174 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Dianne Hackborne17aeb32011-04-07 15:11:57 -0700175 pw.print(prefix); pw.print("config="); pw.println(configuration);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700176 if (resultTo != null || resultWho != null) {
177 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
178 pw.print(" resultWho="); pw.print(resultWho);
179 pw.print(" resultCode="); pw.println(requestCode);
180 }
181 if (results != null) {
182 pw.print(prefix); pw.print("results="); pw.println(results);
183 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700184 if (pendingResults != null && pendingResults.size() > 0) {
185 pw.print(prefix); pw.println("Pending Results:");
186 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
187 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
188 pw.print(prefix); pw.print(" - ");
189 if (pir == null) {
190 pw.println("null");
191 } else {
192 pw.println(pir);
193 pir.dump(pw, prefix + " ");
194 }
195 }
196 }
197 if (newIntents != null && newIntents.size() > 0) {
198 pw.print(prefix); pw.println("Pending New Intents:");
199 for (int i=0; i<newIntents.size(); i++) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800200 Intent intent = newIntents.get(i);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700201 pw.print(prefix); pw.print(" - ");
202 if (intent == null) {
203 pw.println("null");
204 } else {
205 pw.println(intent.toShortString(false, true, false, true));
206 }
207 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700208 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700209 if (pendingOptions != null) {
210 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
211 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700212 if (uriPermissions != null) {
213 if (uriPermissions.readUriPermissions != null) {
214 pw.print(prefix); pw.print("readUriPermissions=");
215 pw.println(uriPermissions.readUriPermissions);
216 }
217 if (uriPermissions.writeUriPermissions != null) {
218 pw.print(prefix); pw.print("writeUriPermissions=");
219 pw.println(uriPermissions.writeUriPermissions);
220 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700221 }
222 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800223 pw.print(" launchCount="); pw.print(launchCount);
224 pw.print(" lastLaunchTime=");
225 if (lastLaunchTime == 0) pw.print("0");
226 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
227 pw.println();
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700228 pw.print(prefix); pw.print("haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700229 pw.print(" icicle="); pw.println(icicle);
230 pw.print(prefix); pw.print("state="); pw.print(state);
231 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700232 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700233 pw.print(" finishing="); pw.println(finishing);
234 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
235 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700236 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800237 pw.print(" sleeping="); pw.print(sleeping);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700238 pw.print(" idle="); pw.println(idle);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800239 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
240 pw.print(" noDisplay="); pw.print(noDisplay);
241 pw.print(" immersive="); pw.print(immersive);
242 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800243 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400244 pw.print(" thumbnailNeeded="); pw.print(thumbnailNeeded);
245 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Dianne Hackborn15491c62012-09-19 10:59:14 -0700246 pw.print(prefix); pw.print("thumbHolder: ");
247 pw.print(Integer.toHexString(System.identityHashCode(thumbHolder)));
248 if (thumbHolder != null) {
249 pw.print(" bm="); pw.print(thumbHolder.lastThumbnail);
250 pw.print(" desc="); pw.print(thumbHolder.lastDescription);
251 }
252 pw.println();
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700253 if (displayStartTime != 0 || startTime != 0) {
254 pw.print(prefix); pw.print("displayStartTime=");
255 if (displayStartTime == 0) pw.print("0");
256 else TimeUtils.formatDuration(displayStartTime, now, pw);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700257 pw.print(" startTime=");
258 if (startTime == 0) pw.print("0");
259 else TimeUtils.formatDuration(startTime, now, pw);
260 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700261 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800262 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700263 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800264 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700265 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700266 if (lastVisibleTime == 0) pw.print("0");
267 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
268 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700269 }
270 if (configDestroy || configChangeFlags != 0) {
271 pw.print(prefix); pw.print("configDestroy="); pw.print(configDestroy);
272 pw.print(" configChangeFlags=");
273 pw.println(Integer.toHexString(configChangeFlags));
274 }
275 if (connections != null) {
276 pw.print(prefix); pw.print("connections="); pw.println(connections);
277 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 }
279
Dianne Hackbornbe707852011-11-11 14:32:10 -0800280 static class Token extends IApplicationToken.Stub {
281 final WeakReference<ActivityRecord> weakActivity;
282
283 Token(ActivityRecord activity) {
284 weakActivity = new WeakReference<ActivityRecord>(activity);
285 }
286
Craig Mautnerde4ef022013-04-07 19:01:33 -0700287 @Override public void windowsDrawn() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800288 ActivityRecord activity = weakActivity.get();
289 if (activity != null) {
290 activity.windowsDrawn();
291 }
292 }
293
Craig Mautnerde4ef022013-04-07 19:01:33 -0700294 @Override public void windowsVisible() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800295 ActivityRecord activity = weakActivity.get();
296 if (activity != null) {
297 activity.windowsVisible();
298 }
299 }
300
Craig Mautnerde4ef022013-04-07 19:01:33 -0700301 @Override public void windowsGone() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800302 ActivityRecord activity = weakActivity.get();
303 if (activity != null) {
304 activity.windowsGone();
305 }
306 }
307
Craig Mautnerde4ef022013-04-07 19:01:33 -0700308 @Override public boolean keyDispatchingTimedOut() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800309 ActivityRecord activity = weakActivity.get();
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700310 return activity != null && activity.keyDispatchingTimedOut();
Dianne Hackbornbe707852011-11-11 14:32:10 -0800311 }
312
Craig Mautnerde4ef022013-04-07 19:01:33 -0700313 @Override public long getKeyDispatchingTimeout() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800314 ActivityRecord activity = weakActivity.get();
315 if (activity != null) {
316 return activity.getKeyDispatchingTimeout();
317 }
318 return 0;
319 }
320
Craig Mautnerde4ef022013-04-07 19:01:33 -0700321 @Override
Dianne Hackbornbe707852011-11-11 14:32:10 -0800322 public String toString() {
323 StringBuilder sb = new StringBuilder(128);
324 sb.append("Token{");
325 sb.append(Integer.toHexString(System.identityHashCode(this)));
326 sb.append(' ');
327 sb.append(weakActivity.get());
328 sb.append('}');
329 return sb.toString();
330 }
331 }
332
333 static ActivityRecord forToken(IBinder token) {
334 try {
335 return token != null ? ((Token)token).weakActivity.get() : null;
336 } catch (ClassCastException e) {
337 Slog.w(ActivityManagerService.TAG, "Bad activity token: " + token, e);
338 return null;
339 }
340 }
341
Craig Mautnerd2328952013-03-05 12:46:26 -0800342 ActivityRecord(ActivityManagerService _service, ProcessRecord _caller,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800343 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700345 ActivityRecord _resultTo, String _resultWho, int _reqCode,
Craig Mautnerde4ef022013-04-07 19:01:33 -0700346 boolean _componentSpecified, ActivityStackSupervisor supervisor) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 service = _service;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800348 appToken = new Token(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 info = aInfo;
350 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800351 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700352 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 intent = _intent;
354 shortComponentName = _intent.getComponent().flattenToShortString();
355 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800356 componentSpecified = _componentSpecified;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 configuration = _configuration;
358 resultTo = _resultTo;
359 resultWho = _resultWho;
360 requestCode = _reqCode;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700361 state = ActivityState.INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362 frontOfTask = false;
363 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800364 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700365 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 finishing = false;
367 configDestroy = false;
368 keysPaused = false;
369 inHistory = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 visible = true;
371 waitingVisible = false;
372 nowVisible = false;
373 thumbnailNeeded = false;
374 idle = false;
375 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700376 mStackSupervisor = supervisor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700378 // This starts out true, since the initial state of an activity
379 // is that we have everything, and we shouldn't never consider it
380 // lacking in state to be removed if it dies.
381 haveState = true;
382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 if (aInfo != null) {
384 if (aInfo.targetActivity == null
385 || aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE
386 || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
387 realActivity = _intent.getComponent();
388 } else {
389 realActivity = new ComponentName(aInfo.packageName,
390 aInfo.targetActivity);
391 }
392 taskAffinity = aInfo.taskAffinity;
393 stateNotNeeded = (aInfo.flags&
394 ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0;
395 baseDir = aInfo.applicationInfo.sourceDir;
396 resDir = aInfo.applicationInfo.publicSourceDir;
397 dataDir = aInfo.applicationInfo.dataDir;
398 nonLocalizedLabel = aInfo.nonLocalizedLabel;
399 labelRes = aInfo.labelRes;
400 if (nonLocalizedLabel == null && labelRes == 0) {
401 ApplicationInfo app = aInfo.applicationInfo;
402 nonLocalizedLabel = app.nonLocalizedLabel;
403 labelRes = app.labelRes;
404 }
405 icon = aInfo.getIconResource();
Adam Powell04fe6eb2013-05-31 14:39:48 -0700406 logo = aInfo.getLogoResource();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 theme = aInfo.getThemeResource();
Dianne Hackborn247fe742011-01-08 17:25:57 -0800408 realTheme = theme;
409 if (realTheme == 0) {
410 realTheme = aInfo.applicationInfo.targetSdkVersion
411 < Build.VERSION_CODES.HONEYCOMB
412 ? android.R.style.Theme
413 : android.R.style.Theme_Holo;
414 }
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800415 if ((aInfo.flags&ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
416 windowFlags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
417 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0
419 && _caller != null
420 && (aInfo.applicationInfo.uid == Process.SYSTEM_UID
421 || aInfo.applicationInfo.uid == _caller.info.uid)) {
422 processName = _caller.processName;
423 } else {
424 processName = aInfo.processName;
425 }
426
427 if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
428 intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
429 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 packageName = aInfo.applicationInfo.packageName;
432 launchMode = aInfo.launchMode;
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700435 realTheme, com.android.internal.R.styleable.Window, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 fullscreen = ent != null && !ent.array.getBoolean(
437 com.android.internal.R.styleable.Window_windowIsFloating, false)
438 && !ent.array.getBoolean(
439 com.android.internal.R.styleable.Window_windowIsTranslucent, false);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800440 noDisplay = ent != null && ent.array.getBoolean(
441 com.android.internal.R.styleable.Window_windowNoDisplay, false);
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700442
443 // If we know the system has determined the component, then
444 // we can consider this to be a home activity...
445 // Note the last check is so we don't count the resolver
446 // activity as being home... really, we don't care about
447 // doing anything special with something that comes from
448 // the core framework package.
Craig Mautner86d67a42013-05-14 10:34:38 -0700449 if ((!_componentSpecified || _launchedFromUid == Process.myUid()
450 || _launchedFromUid == 0) &&
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700451 Intent.ACTION_MAIN.equals(_intent.getAction()) &&
452 _intent.hasCategory(Intent.CATEGORY_HOME) &&
453 _intent.getCategories().size() == 1 &&
454 _intent.getData() == null &&
455 _intent.getType() == null &&
456 (intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 &&
Craig Mautner86d67a42013-05-14 10:34:38 -0700457 !ResolverActivity.class.getName().equals(realActivity.getClassName())) {
458 // This sure looks like a home activity!
459 mActivityType = HOME_ACTIVITY_TYPE;
460 } else if (realActivity.getClassName().contains("com.android.systemui.recent")) {
461 mActivityType = RECENTS_ACTIVITY_TYPE;
462 } else {
463 mActivityType = APPLICATION_ACTIVITY_TYPE;
464 }
Daniel Sandler69a48172010-06-23 16:29:36 -0400465
466 immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 } else {
468 realActivity = null;
469 taskAffinity = null;
470 stateNotNeeded = false;
471 baseDir = null;
472 resDir = null;
473 dataDir = null;
474 processName = null;
475 packageName = null;
476 fullscreen = true;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800477 noDisplay = false;
Craig Mautner86d67a42013-05-14 10:34:38 -0700478 mActivityType = APPLICATION_ACTIVITY_TYPE;
Daniel Sandler69a48172010-06-23 16:29:36 -0400479 immersive = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 }
481 }
482
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700483 void setTask(TaskRecord newTask, ThumbnailHolder newThumbHolder, boolean isRoot) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700484 if (task != null && task.removeActivity(this)) {
485 mStackSupervisor.removeTask(task);
486 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700487 if (inHistory && !finishing) {
488 if (task != null) {
489 task.numActivities--;
490 }
491 if (newTask != null) {
492 newTask.numActivities++;
493 }
494 }
495 if (newThumbHolder == null) {
496 newThumbHolder = newTask;
497 }
498 task = newTask;
499 if (!isRoot && (intent.getFlags()&Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
500 // This is the start of a new sub-task.
501 if (thumbHolder == null) {
502 thumbHolder = new ThumbnailHolder();
503 }
504 } else {
505 thumbHolder = newThumbHolder;
506 }
507 }
508
Craig Mautner5eda9b32013-07-02 11:58:16 -0700509 boolean changeWindowTranslucency(boolean toOpaque) {
510 if (fullscreen == toOpaque) {
511 return false;
512 }
513 AttributeCache.Entry ent =
Amith Yamasanied411592013-07-12 12:23:16 -0700514 AttributeCache.instance().get(packageName, realTheme, styleable.Window, userId);
Craig Mautner5eda9b32013-07-02 11:58:16 -0700515 if (ent == null
516 || !ent.array.getBoolean(styleable.Window_windowIsTranslucent, false)
517 || ent.array.getBoolean(styleable.Window_windowIsFloating, false)) {
Craig Mautner4addfc52013-06-25 08:05:45 -0700518 return false;
519 }
520
Craig Mautner5eda9b32013-07-02 11:58:16 -0700521 // Keep track of the number of fullscreen activities in this task.
522 task.numFullscreen += toOpaque ? +1 : -1;
523
524 fullscreen = toOpaque;
525 return true;
Craig Mautner4addfc52013-06-25 08:05:45 -0700526 }
527
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700528 void putInHistory() {
529 if (!inHistory) {
530 inHistory = true;
531 if (task != null && !finishing) {
532 task.numActivities++;
533 }
534 }
535 }
536
537 void takeFromHistory() {
538 if (inHistory) {
539 inHistory = false;
540 if (task != null && !finishing) {
541 task.numActivities--;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800542 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700543 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700544 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700545 }
546 }
547
548 boolean isInHistory() {
549 return inHistory;
550 }
551
Craig Mautner86d67a42013-05-14 10:34:38 -0700552 boolean isHomeActivity() {
553 return mActivityType == HOME_ACTIVITY_TYPE;
554 }
555
556 boolean isRecentsActivity() {
557 return mActivityType == RECENTS_ACTIVITY_TYPE;
558 }
559
560 boolean isApplicationActivity() {
561 return mActivityType == APPLICATION_ACTIVITY_TYPE;
562 }
563
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800564 void makeFinishing() {
565 if (!finishing) {
566 finishing = true;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700567 if (task != null && inHistory) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800568 task.numActivities--;
569 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700570 if (stopped) {
571 clearOptionsLocked();
572 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800573 }
574 }
575
Craig Mautnerde4ef022013-04-07 19:01:33 -0700576 boolean isRootActivity() {
577 ArrayList<ActivityRecord> activities = task.mActivities;
578 return activities.size() == 0 || this == task.mActivities.get(0);
579 }
580
Dianne Hackborn7e269642010-08-25 19:50:20 -0700581 UriPermissionOwner getUriPermissionsLocked() {
582 if (uriPermissions == null) {
583 uriPermissions = new UriPermissionOwner(service, this);
584 }
585 return uriPermissions;
586 }
587
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700588 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 int requestCode, int resultCode,
590 Intent resultData) {
591 ActivityResult r = new ActivityResult(from, resultWho,
592 requestCode, resultCode, resultData);
593 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800594 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 }
596 results.add(r);
597 }
598
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700599 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 int requestCode) {
601 if (results != null) {
602 for (int i=results.size()-1; i>=0; i--) {
603 ActivityResult r = (ActivityResult)results.get(i);
604 if (r.mFrom != from) continue;
605 if (r.mResultWho == null) {
606 if (resultWho != null) continue;
607 } else {
608 if (!r.mResultWho.equals(resultWho)) continue;
609 }
610 if (r.mRequestCode != requestCode) continue;
611
612 results.remove(i);
613 }
614 }
615 }
616
617 void addNewIntentLocked(Intent intent) {
618 if (newIntents == null) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800619 newIntents = new ArrayList<Intent>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 }
621 newIntents.add(intent);
622 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700623
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700624 /**
625 * Deliver a new Intent to an existing activity, so that its onNewIntent()
626 * method will be called at the proper time.
627 */
Dianne Hackborn39792d22010-08-19 18:01:52 -0700628 final void deliverNewIntentLocked(int callingUid, Intent intent) {
Dianne Hackborn514074f2013-02-11 10:52:46 -0800629 // The activity now gets access to the data associated with this Intent.
630 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
631 intent, getUriPermissionsLocked());
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700632 // We want to immediately deliver the intent to the activity if
633 // it is currently the top resumed activity... however, if the
634 // device is sleeping, then all activities are stopped, so in that
635 // case we will deliver it if this is the current top activity on its
636 // stack.
Craig Mautner86d67a42013-05-14 10:34:38 -0700637 boolean unsent = true;
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700638 if ((state == ActivityState.RESUMED || (service.mSleeping
Craig Mautnerd2328952013-03-05 12:46:26 -0800639 && task.stack.topRunningActivityLocked(null) == this))
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700640 && app != null && app.thread != null) {
641 try {
642 ArrayList<Intent> ar = new ArrayList<Intent>();
Dianne Hackborn39792d22010-08-19 18:01:52 -0700643 intent = new Intent(intent);
644 ar.add(intent);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800645 app.thread.scheduleNewIntent(ar, appToken);
Craig Mautner86d67a42013-05-14 10:34:38 -0700646 unsent = false;
Dianne Hackborn39792d22010-08-19 18:01:52 -0700647 } catch (RemoteException e) {
648 Slog.w(ActivityManagerService.TAG,
649 "Exception thrown sending new intent to " + this, e);
650 } catch (NullPointerException e) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700651 Slog.w(ActivityManagerService.TAG,
652 "Exception thrown sending new intent to " + this, e);
653 }
654 }
Craig Mautner86d67a42013-05-14 10:34:38 -0700655 if (unsent) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700656 addNewIntentLocked(new Intent(intent));
657 }
658 }
659
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700660 void updateOptionsLocked(Bundle options) {
661 if (options != null) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700662 if (pendingOptions != null) {
663 pendingOptions.abort();
664 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700665 pendingOptions = new ActivityOptions(options);
666 }
667 }
668
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700669 void updateOptionsLocked(ActivityOptions options) {
670 if (options != null) {
671 if (pendingOptions != null) {
672 pendingOptions.abort();
673 }
674 pendingOptions = options;
675 }
676 }
677
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700678 void applyOptionsLocked() {
679 if (pendingOptions != null) {
Michael Jurka21385cd2012-05-03 10:57:31 -0700680 final int animationType = pendingOptions.getAnimationType();
681 switch (animationType) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700682 case ActivityOptions.ANIM_CUSTOM:
683 service.mWindowManager.overridePendingAppTransition(
684 pendingOptions.getPackageName(),
685 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -0700686 pendingOptions.getCustomExitResId(),
687 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700688 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700689 case ActivityOptions.ANIM_SCALE_UP:
690 service.mWindowManager.overridePendingAppTransitionScaleUp(
691 pendingOptions.getStartX(), pendingOptions.getStartY(),
692 pendingOptions.getStartWidth(), pendingOptions.getStartHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700693 if (intent.getSourceBounds() == null) {
694 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
695 pendingOptions.getStartY(),
696 pendingOptions.getStartX()+pendingOptions.getStartWidth(),
697 pendingOptions.getStartY()+pendingOptions.getStartHeight()));
698 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700699 break;
Michael Jurka832cb222012-04-13 09:32:47 -0700700 case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
701 case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
702 boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700703 service.mWindowManager.overridePendingAppTransitionThumb(
704 pendingOptions.getThumbnail(),
705 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -0700706 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -0700707 scaleUp);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700708 if (intent.getSourceBounds() == null) {
709 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
710 pendingOptions.getStartY(),
711 pendingOptions.getStartX()
712 + pendingOptions.getThumbnail().getWidth(),
713 pendingOptions.getStartY()
714 + pendingOptions.getThumbnail().getHeight()));
715 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700716 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700717 }
718 pendingOptions = null;
719 }
720 }
721
722 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700723 if (pendingOptions != null) {
724 pendingOptions.abort();
725 pendingOptions = null;
726 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700727 }
728
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700729 ActivityOptions takeOptionsLocked() {
730 ActivityOptions opts = pendingOptions;
731 pendingOptions = null;
732 return opts;
733 }
734
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700735 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -0700736 if (uriPermissions != null) {
737 uriPermissions.removeUriPermissionsLocked();
738 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700739 }
740 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741
742 void pauseKeyDispatchingLocked() {
743 if (!keysPaused) {
744 keysPaused = true;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800745 service.mWindowManager.pauseKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746 }
747 }
748
749 void resumeKeyDispatchingLocked() {
750 if (keysPaused) {
751 keysPaused = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800752 service.mWindowManager.resumeKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 }
754 }
755
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700756 void updateThumbnail(Bitmap newThumbnail, CharSequence description) {
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700757 if (thumbHolder != null) {
758 if (newThumbnail != null) {
Dianne Hackborn15491c62012-09-19 10:59:14 -0700759 if (ActivityManagerService.DEBUG_THUMBNAILS) Slog.i(ActivityManagerService.TAG,
760 "Setting thumbnail of " + this + " holder " + thumbHolder
761 + " to " + newThumbnail);
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700762 thumbHolder.lastThumbnail = newThumbnail;
763 }
764 thumbHolder.lastDescription = description;
765 }
766 }
767
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700768 void startLaunchTickingLocked() {
769 if (ActivityManagerService.IS_USER_BUILD) {
770 return;
771 }
772 if (launchTickTime == 0) {
773 launchTickTime = SystemClock.uptimeMillis();
774 continueLaunchTickingLocked();
775 }
776 }
777
778 boolean continueLaunchTickingLocked() {
779 if (launchTickTime != 0) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800780 final ActivityStack stack = task.stack;
Craig Mautnerf7bfefb2013-05-16 17:30:44 -0700781 Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG, this);
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700782 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
783 stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
784 return true;
785 }
786 return false;
787 }
788
789 void finishLaunchTickingLocked() {
790 launchTickTime = 0;
Craig Mautnerd2328952013-03-05 12:46:26 -0800791 task.stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700792 }
793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 // IApplicationToken
795
796 public boolean mayFreezeScreenLocked(ProcessRecord app) {
797 // Only freeze the screen if this activity is currently attached to
798 // an application, and that application is not blocked or unresponding.
799 // In any other case, we can't count on getting the screen unfrozen,
800 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -0800801 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800802 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
805 if (mayFreezeScreenLocked(app)) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800806 service.mWindowManager.startAppFreezingScreen(appToken, configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800807 }
808 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800810 public void stopFreezingScreenLocked(boolean force) {
811 if (force || frozenBeforeDestroy) {
812 frozenBeforeDestroy = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800813 service.mWindowManager.stopAppFreezingScreen(appToken, force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 }
815 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700816
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700817 public void reportFullyDrawnLocked() {
818 final long curTime = SystemClock.uptimeMillis();
819 if (displayStartTime != 0) {
820 reportLaunchTimeLocked(curTime);
821 }
822 if (fullyDrawnStartTime != 0) {
823 final ActivityStack stack = task.stack;
824 final long thisTime = curTime - fullyDrawnStartTime;
825 final long totalTime = stack.mFullyDrawnStartTime != 0
826 ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
827 if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -0700828 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700829 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME,
830 userId, System.identityHashCode(this), shortComponentName,
831 thisTime, totalTime);
832 StringBuilder sb = service.mStringBuilder;
833 sb.setLength(0);
834 sb.append("Fully drawn ");
835 sb.append(shortComponentName);
836 sb.append(": ");
837 TimeUtils.formatDuration(thisTime, sb);
838 if (thisTime != totalTime) {
839 sb.append(" (total ");
840 TimeUtils.formatDuration(totalTime, sb);
841 sb.append(")");
842 }
843 Log.i(ActivityManagerService.TAG, sb.toString());
844 }
845 if (totalTime > 0) {
846 service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
847 }
848 fullyDrawnStartTime = 0;
849 stack.mFullyDrawnStartTime = 0;
850 }
851 }
852
853 private void reportLaunchTimeLocked(final long curTime) {
854 final ActivityStack stack = task.stack;
855 final long thisTime = curTime - displayStartTime;
856 final long totalTime = stack.mLaunchStartTime != 0
857 ? (curTime - stack.mLaunchStartTime) : thisTime;
858 if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -0700859 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700860 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
861 userId, System.identityHashCode(this), shortComponentName,
862 thisTime, totalTime);
863 StringBuilder sb = service.mStringBuilder;
864 sb.setLength(0);
865 sb.append("Displayed ");
866 sb.append(shortComponentName);
867 sb.append(": ");
868 TimeUtils.formatDuration(thisTime, sb);
869 if (thisTime != totalTime) {
870 sb.append(" (total ");
871 TimeUtils.formatDuration(totalTime, sb);
872 sb.append(")");
873 }
874 Log.i(ActivityManagerService.TAG, sb.toString());
875 }
876 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
877 if (totalTime > 0) {
878 service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
879 }
880 displayStartTime = 0;
881 stack.mLaunchStartTime = 0;
882 }
883
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700884 public void windowsDrawn() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800885 synchronized(service) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700886 if (displayStartTime != 0) {
887 reportLaunchTimeLocked(SystemClock.uptimeMillis());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800888 }
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700889 startTime = 0;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700890 finishLaunchTickingLocked();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700891 }
892 }
893
894 public void windowsVisible() {
895 synchronized(service) {
Craig Mautnerce5f3cb2013-04-22 08:58:54 -0700896 mStackSupervisor.reportActivityVisibleLocked(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
898 ActivityManagerService.TAG, "windowsVisible(): " + this);
899 if (!nowVisible) {
900 nowVisible = true;
Dianne Hackborn50685602011-12-01 12:23:37 -0800901 lastVisibleTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902 if (!idle) {
903 // Instead of doing the full stop routine here, let's just
904 // hide any activities we now can, and let them stop when
905 // the normal idle happens.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700906 mStackSupervisor.processStoppingActivitiesLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800907 } else {
908 // If this activity was already idle, then we now need to
909 // make sure we perform the full stop of any activities
910 // that are waiting to do so. This is because we won't
911 // do that while they are still waiting for this one to
912 // become visible.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700913 final int N = mStackSupervisor.mWaitingVisibleActivities.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 if (N > 0) {
915 for (int i=0; i<N; i++) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700916 ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 r.waitingVisible = false;
918 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
919 ActivityManagerService.TAG,
920 "Was waiting for visible: " + r);
921 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700922 mStackSupervisor.mWaitingVisibleActivities.clear();
Craig Mautnerf3333272013-04-22 10:55:53 -0700923 mStackSupervisor.scheduleIdleLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 }
925 }
926 service.scheduleAppGcsLocked();
927 }
928 }
929 }
930
931 public void windowsGone() {
932 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
933 ActivityManagerService.TAG, "windowsGone(): " + this);
934 nowVisible = false;
935 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700936
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700937 private ActivityRecord getWaitingHistoryRecordLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 // First find the real culprit... if we are waiting
939 // for another app to start, then we have paused dispatching
940 // for this activity.
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700941 ActivityRecord r = this;
Craig Mautnerd2328952013-03-05 12:46:26 -0800942 final ActivityStack stack = task.stack;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 if (r.waitingVisible) {
944 // Hmmm, who might we be waiting for?
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700945 r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -0800947 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 }
949 // Both of those null? Fall back to 'this' again
950 if (r == null) {
951 r = this;
952 }
953 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 return r;
956 }
957
958 public boolean keyDispatchingTimedOut() {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700959 ActivityRecord r;
Michael Wright7dd5bb12013-02-27 17:07:29 -0800960 ProcessRecord anrApp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 synchronized(service) {
Dianne Hackbornad5499d2010-03-29 18:08:45 -0700962 r = getWaitingHistoryRecordLocked();
Michael Wright7dd5bb12013-02-27 17:07:29 -0800963 anrApp = r != null ? r.app : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 }
Michael Wright7dd5bb12013-02-27 17:07:29 -0800965 return service.inputDispatchingTimedOut(anrApp, r, this, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 /** Returns the key dispatching timeout for this application token. */
969 public long getKeyDispatchingTimeout() {
970 synchronized(service) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700971 ActivityRecord r = getWaitingHistoryRecordLocked();
Michael Wright7dd5bb12013-02-27 17:07:29 -0800972 return ActivityManagerService.getInputDispatchingTimeoutLocked(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800973 }
974 }
975
976 /**
977 * This method will return true if the activity is either visible, is becoming visible, is
978 * currently pausing, or is resumed.
979 */
980 public boolean isInterestingToUserLocked() {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700981 return visible || nowVisible || state == ActivityState.PAUSING ||
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 state == ActivityState.RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800983 }
984
985 public void setSleeping(boolean _sleeping) {
986 if (sleeping == _sleeping) {
987 return;
988 }
989 if (app != null && app.thread != null) {
990 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800991 app.thread.scheduleSleeping(appToken, _sleeping);
Craig Mautner0eea92c2013-05-16 13:35:39 -0700992 if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
993 mStackSupervisor.mGoingToSleepActivities.add(this);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800994 }
995 sleeping = _sleeping;
996 } catch (RemoteException e) {
Craig Mautner0eea92c2013-05-16 13:35:39 -0700997 Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800998 }
999 }
1000 }
Craig Mautnerf81b90872013-02-26 13:02:43 -08001001
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001002 static void activityResumedLocked(IBinder token) {
1003 final ActivityRecord r = ActivityRecord.forToken(token);
1004 if (DEBUG_SAVED_STATE) Slog.i(TAG, "Resumed activity; dropping state of: " + r);
1005 r.icicle = null;
1006 r.haveState = false;
1007 }
1008
Craig Mautnerd2328952013-03-05 12:46:26 -08001009 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
1010 final ActivityRecord r = ActivityRecord.forToken(token);
1011 if (r == null) {
1012 return -1;
1013 }
1014 final TaskRecord task = r.task;
1015 switch (task.mActivities.indexOf(r)) {
1016 case -1: return -1;
1017 case 0: return task.taskId;
1018 default: return onlyRoot ? -1 : task.taskId;
1019 }
1020 }
1021
1022 static ActivityRecord isInStackLocked(IBinder token) {
1023 final ActivityRecord r = ActivityRecord.forToken(token);
1024 if (r != null) {
1025 return r.task.stack.isInStackLocked(token);
1026 }
1027 return null;
1028 }
1029
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001030 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -08001031 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
1032 if (r != null) {
1033 return r.task.stack;
1034 }
1035 return null;
1036 }
1037
Craig Mautnerf81b90872013-02-26 13:02:43 -08001038 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001040 if (stringName != null) {
Craig Mautnerf3333272013-04-22 10:55:53 -07001041 return stringName + " t" + (task == null ? -1 : task.taskId) +
1042 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001043 }
1044 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -08001045 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001046 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -07001047 sb.append(" u");
1048 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001049 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001050 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -08001051 stringName = sb.toString();
1052 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 }
1054}