blob: 749dc6651d389f053f661da35f2b07e692a1fbe5 [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
23import android.app.Activity;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -070024import android.app.ActivityOptions;
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 {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 final ActivityManagerService service; // owner
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070058 final ActivityStack stack; // owner
Dianne Hackbornbe707852011-11-11 14:32:10 -080059 final IApplicationToken.Stub appToken; // window manager token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 final ActivityInfo info; // all about me
61 final int launchedFromUid; // always the uid who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -070062 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 final Intent intent; // the original intent that generated us
64 final ComponentName realActivity; // the intent component, or target of an alias.
65 final String shortComponentName; // the short component name of the intent
66 final String resolvedType; // as per original caller;
67 final String packageName; // the package implementing intent's component
68 final String processName; // process where this component wants to run
69 final String taskAffinity; // as per ActivityInfo.taskAffinity
70 final boolean stateNotNeeded; // As per ActivityInfo.flags
Dianne Hackbornff801ec2011-01-22 18:05:38 -080071 final boolean fullscreen; // covers the full screen?
72 final boolean noDisplay; // activity is not displayed?
The Android Open Source Project4df24232009-03-05 14:34:35 -080073 final boolean componentSpecified; // did caller specifiy an explicit component?
74 final boolean isHomeActivity; // do we consider this to be a home activity?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 final String baseDir; // where activity source (resources etc) located
76 final String resDir; // where public activity source (public resources etc) located
77 final String dataDir; // where activity data should go
78 CharSequence nonLocalizedLabel; // the label information from the package mgr.
79 int labelRes; // the label information from the package mgr.
80 int icon; // resource identifier of activity's icon.
81 int theme; // resource identifier of activity's theme.
Dianne Hackborn247fe742011-01-08 17:25:57 -080082 int realTheme; // actual theme resource we will use, never 0.
Dianne Hackborn7eec10e2010-11-12 18:03:47 -080083 int windowFlags; // custom window flags for preview window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 TaskRecord task; // the task this is in.
Dianne Hackbornf26fd992011-04-08 18:14:09 -070085 ThumbnailHolder thumbHolder; // where our thumbnails should go.
Dianne Hackborn0dad3642010-09-09 21:25:35 -070086 long launchTime; // when we starting launching this activity
87 long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -080088 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -070089 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -070090 long pauseTime; // last time we started pausing the activity
91 long launchTickTime; // base time for launch tick messages
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 Configuration configuration; // configuration activity was last running in
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -070093 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -070094 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 final String resultWho; // additional identifier for use by resultTo.
96 final int requestCode; // code given by requester (resultTo)
97 ArrayList results; // pending ActivityResult objs we have received
98 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
99 ArrayList newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700100 ActivityOptions pendingOptions; // most recently given options
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700102 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700103 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700104 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 Bundle icicle; // last saved activity state
106 boolean frontOfTask; // is this the root activity of its task?
107 boolean launchFailed; // set if a launched failed, to abort on 2nd try
108 boolean haveState; // have we gotten the last activity state?
109 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700110 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 boolean finishing; // activity in pending finish list?
112 boolean configDestroy; // need to destroy due to config change?
113 int configChangeFlags; // which config values have changed
114 boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 int launchMode; // the launch mode activity attribute.
116 boolean visible; // does this activity's window need to be shown?
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800117 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 boolean waitingVisible; // true if waiting for a new act to become vis
119 boolean nowVisible; // is this activity's window visible?
120 boolean thumbnailNeeded;// has someone requested a thumbnail?
121 boolean idle; // has the activity gone idle?
122 boolean hasBeenLaunched;// has this activity ever been launched?
123 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400124 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400125 boolean forceNewConfig; // force re-create with new config next time
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700127 String stringName; // for caching of toString().
128
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700129 private boolean inHistory; // are we in the history stack?
130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700132 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700133 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
134 pw.print(" processName="); pw.println(processName);
135 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800136 pw.print(" userId="); pw.println(userId);
137 pw.print(prefix); pw.print("app="); pw.println(app);
138 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700139 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
140 pw.print(" task="); pw.println(task);
141 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700142 pw.print(prefix); pw.print("realActivity=");
143 pw.println(realActivity.flattenToShortString());
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800144 pw.print(prefix); pw.print("baseDir="); pw.println(baseDir);
145 if (!resDir.equals(baseDir)) {
146 pw.print(prefix); pw.print("resDir="); pw.println(resDir);
147 }
148 pw.print(prefix); pw.print("dataDir="); pw.println(dataDir);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700149 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
150 pw.print(" componentSpecified="); pw.print(componentSpecified);
151 pw.print(" isHomeActivity="); pw.println(isHomeActivity);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800152 pw.print(prefix); pw.print("compat="); pw.print(compat);
153 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
154 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
155 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Dianne Hackborne17aeb32011-04-07 15:11:57 -0700156 pw.print(prefix); pw.print("config="); pw.println(configuration);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700157 if (resultTo != null || resultWho != null) {
158 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
159 pw.print(" resultWho="); pw.print(resultWho);
160 pw.print(" resultCode="); pw.println(requestCode);
161 }
162 if (results != null) {
163 pw.print(prefix); pw.print("results="); pw.println(results);
164 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700165 if (pendingResults != null && pendingResults.size() > 0) {
166 pw.print(prefix); pw.println("Pending Results:");
167 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
168 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
169 pw.print(prefix); pw.print(" - ");
170 if (pir == null) {
171 pw.println("null");
172 } else {
173 pw.println(pir);
174 pir.dump(pw, prefix + " ");
175 }
176 }
177 }
178 if (newIntents != null && newIntents.size() > 0) {
179 pw.print(prefix); pw.println("Pending New Intents:");
180 for (int i=0; i<newIntents.size(); i++) {
181 Intent intent = (Intent)newIntents.get(i);
182 pw.print(prefix); pw.print(" - ");
183 if (intent == null) {
184 pw.println("null");
185 } else {
186 pw.println(intent.toShortString(false, true, false, true));
187 }
188 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700189 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700190 if (pendingOptions != null) {
191 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
192 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700193 if (uriPermissions != null) {
194 if (uriPermissions.readUriPermissions != null) {
195 pw.print(prefix); pw.print("readUriPermissions=");
196 pw.println(uriPermissions.readUriPermissions);
197 }
198 if (uriPermissions.writeUriPermissions != null) {
199 pw.print(prefix); pw.print("writeUriPermissions=");
200 pw.println(uriPermissions.writeUriPermissions);
201 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700202 }
203 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
204 pw.print(" haveState="); pw.print(haveState);
205 pw.print(" icicle="); pw.println(icicle);
206 pw.print(prefix); pw.print("state="); pw.print(state);
207 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700208 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700209 pw.print(" finishing="); pw.println(finishing);
210 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
211 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700212 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800213 pw.print(" sleeping="); pw.print(sleeping);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700214 pw.print(" idle="); pw.println(idle);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800215 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
216 pw.print(" noDisplay="); pw.print(noDisplay);
217 pw.print(" immersive="); pw.print(immersive);
218 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800219 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400220 pw.print(" thumbnailNeeded="); pw.print(thumbnailNeeded);
221 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Dianne Hackborn15491c62012-09-19 10:59:14 -0700222 pw.print(prefix); pw.print("thumbHolder: ");
223 pw.print(Integer.toHexString(System.identityHashCode(thumbHolder)));
224 if (thumbHolder != null) {
225 pw.print(" bm="); pw.print(thumbHolder.lastThumbnail);
226 pw.print(" desc="); pw.print(thumbHolder.lastDescription);
227 }
228 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700229 if (launchTime != 0 || startTime != 0) {
230 pw.print(prefix); pw.print("launchTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700231 if (launchTime == 0) pw.print("0");
232 else TimeUtils.formatDuration(launchTime, now, pw);
233 pw.print(" startTime=");
234 if (startTime == 0) pw.print("0");
235 else TimeUtils.formatDuration(startTime, now, pw);
236 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700237 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800238 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700239 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800240 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700241 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700242 if (lastVisibleTime == 0) pw.print("0");
243 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
244 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700245 }
246 if (configDestroy || configChangeFlags != 0) {
247 pw.print(prefix); pw.print("configDestroy="); pw.print(configDestroy);
248 pw.print(" configChangeFlags=");
249 pw.println(Integer.toHexString(configChangeFlags));
250 }
251 if (connections != null) {
252 pw.print(prefix); pw.print("connections="); pw.println(connections);
253 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 }
255
Dianne Hackbornbe707852011-11-11 14:32:10 -0800256 static class Token extends IApplicationToken.Stub {
257 final WeakReference<ActivityRecord> weakActivity;
258
259 Token(ActivityRecord activity) {
260 weakActivity = new WeakReference<ActivityRecord>(activity);
261 }
262
263 @Override public void windowsDrawn() throws RemoteException {
264 ActivityRecord activity = weakActivity.get();
265 if (activity != null) {
266 activity.windowsDrawn();
267 }
268 }
269
270 @Override public void windowsVisible() throws RemoteException {
271 ActivityRecord activity = weakActivity.get();
272 if (activity != null) {
273 activity.windowsVisible();
274 }
275 }
276
277 @Override public void windowsGone() throws RemoteException {
278 ActivityRecord activity = weakActivity.get();
279 if (activity != null) {
280 activity.windowsGone();
281 }
282 }
283
284 @Override public boolean keyDispatchingTimedOut() throws RemoteException {
285 ActivityRecord activity = weakActivity.get();
286 if (activity != null) {
287 return activity.keyDispatchingTimedOut();
288 }
289 return false;
290 }
291
292 @Override public long getKeyDispatchingTimeout() throws RemoteException {
293 ActivityRecord activity = weakActivity.get();
294 if (activity != null) {
295 return activity.getKeyDispatchingTimeout();
296 }
297 return 0;
298 }
299
300 public String toString() {
301 StringBuilder sb = new StringBuilder(128);
302 sb.append("Token{");
303 sb.append(Integer.toHexString(System.identityHashCode(this)));
304 sb.append(' ');
305 sb.append(weakActivity.get());
306 sb.append('}');
307 return sb.toString();
308 }
309 }
310
311 static ActivityRecord forToken(IBinder token) {
312 try {
313 return token != null ? ((Token)token).weakActivity.get() : null;
314 } catch (ClassCastException e) {
315 Slog.w(ActivityManagerService.TAG, "Bad activity token: " + token, e);
316 return null;
317 }
318 }
319
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700320 ActivityRecord(ActivityManagerService _service, ActivityStack _stack, ProcessRecord _caller,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 int _launchedFromUid, Intent _intent, String _resolvedType,
322 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700323 ActivityRecord _resultTo, String _resultWho, int _reqCode,
The Android Open Source Project4df24232009-03-05 14:34:35 -0800324 boolean _componentSpecified) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 service = _service;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700326 stack = _stack;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800327 appToken = new Token(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800328 info = aInfo;
329 launchedFromUid = _launchedFromUid;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700330 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 intent = _intent;
332 shortComponentName = _intent.getComponent().flattenToShortString();
333 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800334 componentSpecified = _componentSpecified;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 configuration = _configuration;
336 resultTo = _resultTo;
337 resultWho = _resultWho;
338 requestCode = _reqCode;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700339 state = ActivityState.INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 frontOfTask = false;
341 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700343 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 finishing = false;
345 configDestroy = false;
346 keysPaused = false;
347 inHistory = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348 visible = true;
349 waitingVisible = false;
350 nowVisible = false;
351 thumbnailNeeded = false;
352 idle = false;
353 hasBeenLaunched = false;
354
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700355 // This starts out true, since the initial state of an activity
356 // is that we have everything, and we shouldn't never consider it
357 // lacking in state to be removed if it dies.
358 haveState = true;
359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 if (aInfo != null) {
361 if (aInfo.targetActivity == null
362 || aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE
363 || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
364 realActivity = _intent.getComponent();
365 } else {
366 realActivity = new ComponentName(aInfo.packageName,
367 aInfo.targetActivity);
368 }
369 taskAffinity = aInfo.taskAffinity;
370 stateNotNeeded = (aInfo.flags&
371 ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0;
372 baseDir = aInfo.applicationInfo.sourceDir;
373 resDir = aInfo.applicationInfo.publicSourceDir;
374 dataDir = aInfo.applicationInfo.dataDir;
375 nonLocalizedLabel = aInfo.nonLocalizedLabel;
376 labelRes = aInfo.labelRes;
377 if (nonLocalizedLabel == null && labelRes == 0) {
378 ApplicationInfo app = aInfo.applicationInfo;
379 nonLocalizedLabel = app.nonLocalizedLabel;
380 labelRes = app.labelRes;
381 }
382 icon = aInfo.getIconResource();
383 theme = aInfo.getThemeResource();
Dianne Hackborn247fe742011-01-08 17:25:57 -0800384 realTheme = theme;
385 if (realTheme == 0) {
386 realTheme = aInfo.applicationInfo.targetSdkVersion
387 < Build.VERSION_CODES.HONEYCOMB
388 ? android.R.style.Theme
389 : android.R.style.Theme_Holo;
390 }
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800391 if ((aInfo.flags&ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
392 windowFlags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
393 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0
395 && _caller != null
396 && (aInfo.applicationInfo.uid == Process.SYSTEM_UID
397 || aInfo.applicationInfo.uid == _caller.info.uid)) {
398 processName = _caller.processName;
399 } else {
400 processName = aInfo.processName;
401 }
402
403 if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
404 intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
405 }
406
407 packageName = aInfo.applicationInfo.packageName;
408 launchMode = aInfo.launchMode;
409
410 AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
Dianne Hackborn247fe742011-01-08 17:25:57 -0800411 realTheme, com.android.internal.R.styleable.Window);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 fullscreen = ent != null && !ent.array.getBoolean(
413 com.android.internal.R.styleable.Window_windowIsFloating, false)
414 && !ent.array.getBoolean(
415 com.android.internal.R.styleable.Window_windowIsTranslucent, false);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800416 noDisplay = ent != null && ent.array.getBoolean(
417 com.android.internal.R.styleable.Window_windowNoDisplay, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418
The Android Open Source Project4df24232009-03-05 14:34:35 -0800419 if (!_componentSpecified || _launchedFromUid == Process.myUid()
420 || _launchedFromUid == 0) {
421 // If we know the system has determined the component, then
422 // we can consider this to be a home activity...
423 if (Intent.ACTION_MAIN.equals(_intent.getAction()) &&
424 _intent.hasCategory(Intent.CATEGORY_HOME) &&
425 _intent.getCategories().size() == 1 &&
426 _intent.getData() == null &&
427 _intent.getType() == null &&
428 (intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 &&
Dianne Hackborn2d69d492012-04-06 16:24:14 -0700429 !ResolverActivity.class.getName().equals(realActivity.getClassName())) {
The Android Open Source Project4df24232009-03-05 14:34:35 -0800430 // This sure looks like a home activity!
431 // Note the last check is so we don't count the resolver
432 // activity as being home... really, we don't care about
433 // doing anything special with something that comes from
434 // the core framework package.
435 isHomeActivity = true;
436 } else {
437 isHomeActivity = false;
438 }
439 } else {
440 isHomeActivity = false;
441 }
Daniel Sandler69a48172010-06-23 16:29:36 -0400442
443 immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 } else {
445 realActivity = null;
446 taskAffinity = null;
447 stateNotNeeded = false;
448 baseDir = null;
449 resDir = null;
450 dataDir = null;
451 processName = null;
452 packageName = null;
453 fullscreen = true;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800454 noDisplay = false;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800455 isHomeActivity = false;
Daniel Sandler69a48172010-06-23 16:29:36 -0400456 immersive = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 }
458 }
459
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700460 void setTask(TaskRecord newTask, ThumbnailHolder newThumbHolder, boolean isRoot) {
461 if (inHistory && !finishing) {
462 if (task != null) {
463 task.numActivities--;
464 }
465 if (newTask != null) {
466 newTask.numActivities++;
467 }
468 }
469 if (newThumbHolder == null) {
470 newThumbHolder = newTask;
471 }
472 task = newTask;
473 if (!isRoot && (intent.getFlags()&Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
474 // This is the start of a new sub-task.
475 if (thumbHolder == null) {
476 thumbHolder = new ThumbnailHolder();
477 }
478 } else {
479 thumbHolder = newThumbHolder;
480 }
481 }
482
483 void putInHistory() {
484 if (!inHistory) {
485 inHistory = true;
486 if (task != null && !finishing) {
487 task.numActivities++;
488 }
489 }
490 }
491
492 void takeFromHistory() {
493 if (inHistory) {
494 inHistory = false;
495 if (task != null && !finishing) {
496 task.numActivities--;
497 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700498 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700499 }
500 }
501
502 boolean isInHistory() {
503 return inHistory;
504 }
505
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800506 void makeFinishing() {
507 if (!finishing) {
508 finishing = true;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700509 if (task != null && inHistory) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800510 task.numActivities--;
511 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700512 if (stopped) {
513 clearOptionsLocked();
514 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800515 }
516 }
517
Dianne Hackborn7e269642010-08-25 19:50:20 -0700518 UriPermissionOwner getUriPermissionsLocked() {
519 if (uriPermissions == null) {
520 uriPermissions = new UriPermissionOwner(service, this);
521 }
522 return uriPermissions;
523 }
524
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700525 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 int requestCode, int resultCode,
527 Intent resultData) {
528 ActivityResult r = new ActivityResult(from, resultWho,
529 requestCode, resultCode, resultData);
530 if (results == null) {
531 results = new ArrayList();
532 }
533 results.add(r);
534 }
535
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700536 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 int requestCode) {
538 if (results != null) {
539 for (int i=results.size()-1; i>=0; i--) {
540 ActivityResult r = (ActivityResult)results.get(i);
541 if (r.mFrom != from) continue;
542 if (r.mResultWho == null) {
543 if (resultWho != null) continue;
544 } else {
545 if (!r.mResultWho.equals(resultWho)) continue;
546 }
547 if (r.mRequestCode != requestCode) continue;
548
549 results.remove(i);
550 }
551 }
552 }
553
554 void addNewIntentLocked(Intent intent) {
555 if (newIntents == null) {
556 newIntents = new ArrayList();
557 }
558 newIntents.add(intent);
559 }
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700560
561 /**
562 * Deliver a new Intent to an existing activity, so that its onNewIntent()
563 * method will be called at the proper time.
564 */
Dianne Hackborn39792d22010-08-19 18:01:52 -0700565 final void deliverNewIntentLocked(int callingUid, Intent intent) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700566 boolean sent = false;
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700567 // We want to immediately deliver the intent to the activity if
568 // it is currently the top resumed activity... however, if the
569 // device is sleeping, then all activities are stopped, so in that
570 // case we will deliver it if this is the current top activity on its
571 // stack.
572 if ((state == ActivityState.RESUMED || (service.mSleeping
573 && stack.topRunningActivityLocked(null) == this))
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700574 && app != null && app.thread != null) {
575 try {
576 ArrayList<Intent> ar = new ArrayList<Intent>();
Dianne Hackborn39792d22010-08-19 18:01:52 -0700577 intent = new Intent(intent);
578 ar.add(intent);
579 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
Dianne Hackborn7e269642010-08-25 19:50:20 -0700580 intent, getUriPermissionsLocked());
Dianne Hackbornbe707852011-11-11 14:32:10 -0800581 app.thread.scheduleNewIntent(ar, appToken);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700582 sent = true;
Dianne Hackborn39792d22010-08-19 18:01:52 -0700583 } catch (RemoteException e) {
584 Slog.w(ActivityManagerService.TAG,
585 "Exception thrown sending new intent to " + this, e);
586 } catch (NullPointerException e) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700587 Slog.w(ActivityManagerService.TAG,
588 "Exception thrown sending new intent to " + this, e);
589 }
590 }
591 if (!sent) {
592 addNewIntentLocked(new Intent(intent));
593 }
594 }
595
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700596 void updateOptionsLocked(Bundle options) {
597 if (options != null) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700598 if (pendingOptions != null) {
599 pendingOptions.abort();
600 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700601 pendingOptions = new ActivityOptions(options);
602 }
603 }
604
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700605 void updateOptionsLocked(ActivityOptions options) {
606 if (options != null) {
607 if (pendingOptions != null) {
608 pendingOptions.abort();
609 }
610 pendingOptions = options;
611 }
612 }
613
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700614 void applyOptionsLocked() {
615 if (pendingOptions != null) {
Michael Jurka21385cd2012-05-03 10:57:31 -0700616 final int animationType = pendingOptions.getAnimationType();
617 switch (animationType) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700618 case ActivityOptions.ANIM_CUSTOM:
619 service.mWindowManager.overridePendingAppTransition(
620 pendingOptions.getPackageName(),
621 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -0700622 pendingOptions.getCustomExitResId(),
623 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700624 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700625 case ActivityOptions.ANIM_SCALE_UP:
626 service.mWindowManager.overridePendingAppTransitionScaleUp(
627 pendingOptions.getStartX(), pendingOptions.getStartY(),
628 pendingOptions.getStartWidth(), pendingOptions.getStartHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700629 if (intent.getSourceBounds() == null) {
630 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
631 pendingOptions.getStartY(),
632 pendingOptions.getStartX()+pendingOptions.getStartWidth(),
633 pendingOptions.getStartY()+pendingOptions.getStartHeight()));
634 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700635 break;
Michael Jurka832cb222012-04-13 09:32:47 -0700636 case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
637 case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
638 boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700639 service.mWindowManager.overridePendingAppTransitionThumb(
640 pendingOptions.getThumbnail(),
641 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -0700642 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -0700643 scaleUp);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700644 if (intent.getSourceBounds() == null) {
645 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
646 pendingOptions.getStartY(),
647 pendingOptions.getStartX()
648 + pendingOptions.getThumbnail().getWidth(),
649 pendingOptions.getStartY()
650 + pendingOptions.getThumbnail().getHeight()));
651 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700652 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700653 }
654 pendingOptions = null;
655 }
656 }
657
658 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700659 if (pendingOptions != null) {
660 pendingOptions.abort();
661 pendingOptions = null;
662 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700663 }
664
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700665 ActivityOptions takeOptionsLocked() {
666 ActivityOptions opts = pendingOptions;
667 pendingOptions = null;
668 return opts;
669 }
670
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700671 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -0700672 if (uriPermissions != null) {
673 uriPermissions.removeUriPermissionsLocked();
674 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700675 }
676 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677
678 void pauseKeyDispatchingLocked() {
679 if (!keysPaused) {
680 keysPaused = true;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800681 service.mWindowManager.pauseKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 }
683 }
684
685 void resumeKeyDispatchingLocked() {
686 if (keysPaused) {
687 keysPaused = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800688 service.mWindowManager.resumeKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689 }
690 }
691
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700692 void updateThumbnail(Bitmap newThumbnail, CharSequence description) {
693 if ((intent.getFlags()&Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
694 // This is a logical break in the task; it repre
695 }
696 if (thumbHolder != null) {
697 if (newThumbnail != null) {
Dianne Hackborn15491c62012-09-19 10:59:14 -0700698 if (ActivityManagerService.DEBUG_THUMBNAILS) Slog.i(ActivityManagerService.TAG,
699 "Setting thumbnail of " + this + " holder " + thumbHolder
700 + " to " + newThumbnail);
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700701 thumbHolder.lastThumbnail = newThumbnail;
702 }
703 thumbHolder.lastDescription = description;
704 }
705 }
706
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700707 void startLaunchTickingLocked() {
708 if (ActivityManagerService.IS_USER_BUILD) {
709 return;
710 }
711 if (launchTickTime == 0) {
712 launchTickTime = SystemClock.uptimeMillis();
713 continueLaunchTickingLocked();
714 }
715 }
716
717 boolean continueLaunchTickingLocked() {
718 if (launchTickTime != 0) {
719 Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG);
720 msg.obj = this;
721 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
722 stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
723 return true;
724 }
725 return false;
726 }
727
728 void finishLaunchTickingLocked() {
729 launchTickTime = 0;
730 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
731 }
732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 // IApplicationToken
734
735 public boolean mayFreezeScreenLocked(ProcessRecord app) {
736 // Only freeze the screen if this activity is currently attached to
737 // an application, and that application is not blocked or unresponding.
738 // In any other case, we can't count on getting the screen unfrozen,
739 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -0800740 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 }
742
743 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
744 if (mayFreezeScreenLocked(app)) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800745 service.mWindowManager.startAppFreezingScreen(appToken, configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746 }
747 }
748
749 public void stopFreezingScreenLocked(boolean force) {
750 if (force || frozenBeforeDestroy) {
751 frozenBeforeDestroy = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800752 service.mWindowManager.stopAppFreezingScreen(appToken, force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 }
754 }
755
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700756 public void windowsDrawn() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 synchronized(service) {
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700758 if (launchTime != 0) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700759 final long curTime = SystemClock.uptimeMillis();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700760 final long thisTime = curTime - launchTime;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700761 final long totalTime = stack.mInitialStartTime != 0
762 ? (curTime - stack.mInitialStartTime) : thisTime;
Dianne Hackborn6447ca32009-04-07 19:50:08 -0700763 if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700764 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
765 userId, System.identityHashCode(this), shortComponentName,
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700766 thisTime, totalTime);
767 StringBuilder sb = service.mStringBuilder;
768 sb.setLength(0);
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700769 sb.append("Displayed ");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700770 sb.append(shortComponentName);
771 sb.append(": ");
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700772 TimeUtils.formatDuration(thisTime, sb);
Dianne Hackborncef65ee2010-09-30 18:27:22 -0700773 if (thisTime != totalTime) {
774 sb.append(" (total ");
775 TimeUtils.formatDuration(totalTime, sb);
776 sb.append(")");
777 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700778 Log.i(ActivityManagerService.TAG, sb.toString());
Dianne Hackborn6447ca32009-04-07 19:50:08 -0700779 }
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700780 stack.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700781 if (totalTime > 0) {
782 service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn6447ca32009-04-07 19:50:08 -0700783 }
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700784 launchTime = 0;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700785 stack.mInitialStartTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 }
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700787 startTime = 0;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700788 finishLaunchTickingLocked();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700789 }
790 }
791
792 public void windowsVisible() {
793 synchronized(service) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700794 stack.reportActivityVisibleLocked(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800795 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
796 ActivityManagerService.TAG, "windowsVisible(): " + this);
797 if (!nowVisible) {
798 nowVisible = true;
Dianne Hackborn50685602011-12-01 12:23:37 -0800799 lastVisibleTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 if (!idle) {
801 // Instead of doing the full stop routine here, let's just
802 // hide any activities we now can, and let them stop when
803 // the normal idle happens.
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700804 stack.processStoppingActivitiesLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 } else {
806 // If this activity was already idle, then we now need to
807 // make sure we perform the full stop of any activities
808 // that are waiting to do so. This is because we won't
809 // do that while they are still waiting for this one to
810 // become visible.
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700811 final int N = stack.mWaitingVisibleActivities.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 if (N > 0) {
813 for (int i=0; i<N; i++) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700814 ActivityRecord r = (ActivityRecord)
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700815 stack.mWaitingVisibleActivities.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800816 r.waitingVisible = false;
817 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
818 ActivityManagerService.TAG,
819 "Was waiting for visible: " + r);
820 }
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700821 stack.mWaitingVisibleActivities.clear();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 Message msg = Message.obtain();
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700823 msg.what = ActivityStack.IDLE_NOW_MSG;
824 stack.mHandler.sendMessage(msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 }
826 }
827 service.scheduleAppGcsLocked();
828 }
829 }
830 }
831
832 public void windowsGone() {
833 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
834 ActivityManagerService.TAG, "windowsGone(): " + this);
835 nowVisible = false;
836 }
837
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700838 private ActivityRecord getWaitingHistoryRecordLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 // First find the real culprit... if we are waiting
840 // for another app to start, then we have paused dispatching
841 // for this activity.
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700842 ActivityRecord r = this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843 if (r.waitingVisible) {
844 // Hmmm, who might we be waiting for?
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700845 r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -0800847 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 }
849 // Both of those null? Fall back to 'this' again
850 if (r == null) {
851 r = this;
852 }
853 }
854
855 return r;
856 }
857
858 public boolean keyDispatchingTimedOut() {
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700859 // TODO: Unify this code with ActivityManagerService.inputDispatchingTimedOut().
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700860 ActivityRecord r;
Dianne Hackbornad5499d2010-03-29 18:08:45 -0700861 ProcessRecord anrApp = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800862 synchronized(service) {
Dianne Hackbornad5499d2010-03-29 18:08:45 -0700863 r = getWaitingHistoryRecordLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800864 if (r != null && r.app != null) {
865 if (r.app.debugging) {
866 return false;
867 }
868
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700869 if (service.mDidDexOpt) {
870 // Give more time since we were dexopting.
871 service.mDidDexOpt = false;
872 return false;
873 }
874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800875 if (r.app.instrumentationClass == null) {
Dianne Hackbornad5499d2010-03-29 18:08:45 -0700876 anrApp = r.app;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 } else {
878 Bundle info = new Bundle();
879 info.putString("shortMsg", "keyDispatchingTimedOut");
880 info.putString("longMsg", "Timed out while dispatching key event");
881 service.finishInstrumentationLocked(
882 r.app, Activity.RESULT_CANCELED, info);
883 }
884 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800885 }
Dianne Hackbornad5499d2010-03-29 18:08:45 -0700886
887 if (anrApp != null) {
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700888 service.appNotResponding(anrApp, r, this, false, "keyDispatchingTimedOut");
Dianne Hackbornad5499d2010-03-29 18:08:45 -0700889 }
890
891 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 }
893
894 /** Returns the key dispatching timeout for this application token. */
895 public long getKeyDispatchingTimeout() {
896 synchronized(service) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700897 ActivityRecord r = getWaitingHistoryRecordLocked();
Jeff Brown3f9dd282011-07-08 20:02:19 -0700898 if (r != null && r.app != null
899 && (r.app.instrumentationClass != null || r.app.usingWrapper)) {
900 return ActivityManagerService.INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 }
Jeff Brown3f9dd282011-07-08 20:02:19 -0700902
903 return ActivityManagerService.KEY_DISPATCHING_TIMEOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904 }
905 }
906
907 /**
908 * This method will return true if the activity is either visible, is becoming visible, is
909 * currently pausing, or is resumed.
910 */
911 public boolean isInterestingToUserLocked() {
912 return visible || nowVisible || state == ActivityState.PAUSING ||
913 state == ActivityState.RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800914 }
915
916 public void setSleeping(boolean _sleeping) {
917 if (sleeping == _sleeping) {
918 return;
919 }
920 if (app != null && app.thread != null) {
921 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800922 app.thread.scheduleSleeping(appToken, _sleeping);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800923 if (sleeping && !stack.mGoingToSleepActivities.contains(this)) {
924 stack.mGoingToSleepActivities.add(this);
925 }
926 sleeping = _sleeping;
927 } catch (RemoteException e) {
928 Slog.w(ActivityStack.TAG, "Exception thrown when sleeping: "
929 + intent.getComponent(), e);
930 }
931 }
932 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700935 if (stringName != null) {
936 return stringName;
937 }
938 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -0800939 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700940 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700941 sb.append(" u");
942 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700943 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700944 sb.append(intent.getComponent().flattenToShortString());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700945 sb.append('}');
946 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 }
948}