blob: aa82be3cc74fa1d805588fdd0b6311b75af4c810 [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.
Dianne Hackbornf265ea92013-01-31 15:00:51 -080062 final String launchedFromPackage; // always the package who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -070063 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 final Intent intent; // the original intent that generated us
65 final ComponentName realActivity; // the intent component, or target of an alias.
66 final String shortComponentName; // the short component name of the intent
67 final String resolvedType; // as per original caller;
68 final String packageName; // the package implementing intent's component
69 final String processName; // process where this component wants to run
70 final String taskAffinity; // as per ActivityInfo.taskAffinity
71 final boolean stateNotNeeded; // As per ActivityInfo.flags
Dianne Hackbornff801ec2011-01-22 18:05:38 -080072 final boolean fullscreen; // covers the full screen?
73 final boolean noDisplay; // activity is not displayed?
The Android Open Source Project4df24232009-03-05 14:34:35 -080074 final boolean componentSpecified; // did caller specifiy an explicit component?
75 final boolean isHomeActivity; // do we consider this to be a home activity?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 final String baseDir; // where activity source (resources etc) located
77 final String resDir; // where public activity source (public resources etc) located
78 final String dataDir; // where activity data should go
79 CharSequence nonLocalizedLabel; // the label information from the package mgr.
80 int labelRes; // the label information from the package mgr.
81 int icon; // resource identifier of activity's icon.
82 int theme; // resource identifier of activity's theme.
Dianne Hackborn247fe742011-01-08 17:25:57 -080083 int realTheme; // actual theme resource we will use, never 0.
Dianne Hackborn7eec10e2010-11-12 18:03:47 -080084 int windowFlags; // custom window flags for preview window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 TaskRecord task; // the task this is in.
Dianne Hackbornf26fd992011-04-08 18:14:09 -070086 ThumbnailHolder thumbHolder; // where our thumbnails should go.
Dianne Hackborn0dad3642010-09-09 21:25:35 -070087 long launchTime; // when we starting launching this activity
88 long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -080089 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -070090 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -070091 long pauseTime; // last time we started pausing the activity
92 long launchTickTime; // base time for launch tick messages
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 Configuration configuration; // configuration activity was last running in
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -070094 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -070095 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 final String resultWho; // additional identifier for use by resultTo.
97 final int requestCode; // code given by requester (resultTo)
Craig Mautner2ad92072013-02-25 16:19:24 -080098 ArrayList results; // pending ActivityResult objs we have received
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
Craig Mautner2ad92072013-02-25 16:19:24 -0800100 ArrayList newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700101 ActivityOptions pendingOptions; // most recently given options
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700103 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700104 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700105 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 Bundle icicle; // last saved activity state
107 boolean frontOfTask; // is this the root activity of its task?
108 boolean launchFailed; // set if a launched failed, to abort on 2nd try
109 boolean haveState; // have we gotten the last activity state?
110 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700111 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 boolean finishing; // activity in pending finish list?
113 boolean configDestroy; // need to destroy due to config change?
114 int configChangeFlags; // which config values have changed
115 boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 int launchMode; // the launch mode activity attribute.
117 boolean visible; // does this activity's window need to be shown?
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800118 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 boolean waitingVisible; // true if waiting for a new act to become vis
120 boolean nowVisible; // is this activity's window visible?
121 boolean thumbnailNeeded;// has someone requested a thumbnail?
122 boolean idle; // has the activity gone idle?
123 boolean hasBeenLaunched;// has this activity ever been launched?
124 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400125 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400126 boolean forceNewConfig; // force re-create with new config next time
Dianne Hackborn07981492013-01-28 11:36:23 -0800127 int launchCount; // count of launches since last state
128 long lastLaunchTime; // time of last lauch of this activity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700130 String stringName; // for caching of toString().
131
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700132 private boolean inHistory; // are we in the history stack?
133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700135 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700136 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
137 pw.print(" processName="); pw.println(processName);
138 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800139 pw.print(" launchedFromPackage="); pw.println(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800140 pw.print(" userId="); pw.println(userId);
141 pw.print(prefix); pw.print("app="); pw.println(app);
142 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700143 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
144 pw.print(" task="); pw.println(task);
145 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700146 pw.print(prefix); pw.print("realActivity=");
147 pw.println(realActivity.flattenToShortString());
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800148 pw.print(prefix); pw.print("baseDir="); pw.println(baseDir);
149 if (!resDir.equals(baseDir)) {
150 pw.print(prefix); pw.print("resDir="); pw.println(resDir);
151 }
152 pw.print(prefix); pw.print("dataDir="); pw.println(dataDir);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700153 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
154 pw.print(" componentSpecified="); pw.print(componentSpecified);
155 pw.print(" isHomeActivity="); pw.println(isHomeActivity);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800156 pw.print(prefix); pw.print("compat="); pw.print(compat);
157 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
158 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
159 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Dianne Hackborne17aeb32011-04-07 15:11:57 -0700160 pw.print(prefix); pw.print("config="); pw.println(configuration);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700161 if (resultTo != null || resultWho != null) {
162 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
163 pw.print(" resultWho="); pw.print(resultWho);
164 pw.print(" resultCode="); pw.println(requestCode);
165 }
166 if (results != null) {
167 pw.print(prefix); pw.print("results="); pw.println(results);
168 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700169 if (pendingResults != null && pendingResults.size() > 0) {
170 pw.print(prefix); pw.println("Pending Results:");
171 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
172 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
173 pw.print(prefix); pw.print(" - ");
174 if (pir == null) {
175 pw.println("null");
176 } else {
177 pw.println(pir);
178 pir.dump(pw, prefix + " ");
179 }
180 }
181 }
182 if (newIntents != null && newIntents.size() > 0) {
183 pw.print(prefix); pw.println("Pending New Intents:");
184 for (int i=0; i<newIntents.size(); i++) {
185 Intent intent = (Intent)newIntents.get(i);
186 pw.print(prefix); pw.print(" - ");
187 if (intent == null) {
188 pw.println("null");
189 } else {
190 pw.println(intent.toShortString(false, true, false, true));
191 }
192 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700193 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700194 if (pendingOptions != null) {
195 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
196 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700197 if (uriPermissions != null) {
198 if (uriPermissions.readUriPermissions != null) {
199 pw.print(prefix); pw.print("readUriPermissions=");
200 pw.println(uriPermissions.readUriPermissions);
201 }
202 if (uriPermissions.writeUriPermissions != null) {
203 pw.print(prefix); pw.print("writeUriPermissions=");
204 pw.println(uriPermissions.writeUriPermissions);
205 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700206 }
207 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800208 pw.print(" launchCount="); pw.print(launchCount);
209 pw.print(" lastLaunchTime=");
210 if (lastLaunchTime == 0) pw.print("0");
211 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
212 pw.println();
213 pw.print(prefix); pw.print(" haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700214 pw.print(" icicle="); pw.println(icicle);
215 pw.print(prefix); pw.print("state="); pw.print(state);
216 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700217 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700218 pw.print(" finishing="); pw.println(finishing);
219 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
220 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700221 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800222 pw.print(" sleeping="); pw.print(sleeping);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700223 pw.print(" idle="); pw.println(idle);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800224 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
225 pw.print(" noDisplay="); pw.print(noDisplay);
226 pw.print(" immersive="); pw.print(immersive);
227 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800228 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400229 pw.print(" thumbnailNeeded="); pw.print(thumbnailNeeded);
230 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Dianne Hackborn15491c62012-09-19 10:59:14 -0700231 pw.print(prefix); pw.print("thumbHolder: ");
232 pw.print(Integer.toHexString(System.identityHashCode(thumbHolder)));
233 if (thumbHolder != null) {
234 pw.print(" bm="); pw.print(thumbHolder.lastThumbnail);
235 pw.print(" desc="); pw.print(thumbHolder.lastDescription);
236 }
237 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700238 if (launchTime != 0 || startTime != 0) {
239 pw.print(prefix); pw.print("launchTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700240 if (launchTime == 0) pw.print("0");
241 else TimeUtils.formatDuration(launchTime, now, pw);
242 pw.print(" startTime=");
243 if (startTime == 0) pw.print("0");
244 else TimeUtils.formatDuration(startTime, now, pw);
245 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700246 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800247 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700248 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800249 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700250 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700251 if (lastVisibleTime == 0) pw.print("0");
252 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
253 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700254 }
255 if (configDestroy || configChangeFlags != 0) {
256 pw.print(prefix); pw.print("configDestroy="); pw.print(configDestroy);
257 pw.print(" configChangeFlags=");
258 pw.println(Integer.toHexString(configChangeFlags));
259 }
260 if (connections != null) {
261 pw.print(prefix); pw.print("connections="); pw.println(connections);
262 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 }
264
Dianne Hackbornbe707852011-11-11 14:32:10 -0800265 static class Token extends IApplicationToken.Stub {
266 final WeakReference<ActivityRecord> weakActivity;
267
268 Token(ActivityRecord activity) {
269 weakActivity = new WeakReference<ActivityRecord>(activity);
270 }
271
272 @Override public void windowsDrawn() throws RemoteException {
273 ActivityRecord activity = weakActivity.get();
274 if (activity != null) {
275 activity.windowsDrawn();
276 }
277 }
278
279 @Override public void windowsVisible() throws RemoteException {
280 ActivityRecord activity = weakActivity.get();
281 if (activity != null) {
282 activity.windowsVisible();
283 }
284 }
285
286 @Override public void windowsGone() throws RemoteException {
287 ActivityRecord activity = weakActivity.get();
288 if (activity != null) {
289 activity.windowsGone();
290 }
291 }
292
293 @Override public boolean keyDispatchingTimedOut() throws RemoteException {
294 ActivityRecord activity = weakActivity.get();
295 if (activity != null) {
296 return activity.keyDispatchingTimedOut();
297 }
298 return false;
299 }
300
301 @Override public long getKeyDispatchingTimeout() throws RemoteException {
302 ActivityRecord activity = weakActivity.get();
303 if (activity != null) {
304 return activity.getKeyDispatchingTimeout();
305 }
306 return 0;
307 }
308
309 public String toString() {
310 StringBuilder sb = new StringBuilder(128);
311 sb.append("Token{");
312 sb.append(Integer.toHexString(System.identityHashCode(this)));
313 sb.append(' ');
314 sb.append(weakActivity.get());
315 sb.append('}');
316 return sb.toString();
317 }
318 }
319
320 static ActivityRecord forToken(IBinder token) {
321 try {
322 return token != null ? ((Token)token).weakActivity.get() : null;
323 } catch (ClassCastException e) {
324 Slog.w(ActivityManagerService.TAG, "Bad activity token: " + token, e);
325 return null;
326 }
327 }
328
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700329 ActivityRecord(ActivityManagerService _service, ActivityStack _stack, ProcessRecord _caller,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800330 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700332 ActivityRecord _resultTo, String _resultWho, int _reqCode,
The Android Open Source Project4df24232009-03-05 14:34:35 -0800333 boolean _componentSpecified) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 service = _service;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700335 stack = _stack;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800336 appToken = new Token(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 info = aInfo;
338 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800339 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700340 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 intent = _intent;
342 shortComponentName = _intent.getComponent().flattenToShortString();
343 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800344 componentSpecified = _componentSpecified;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 configuration = _configuration;
346 resultTo = _resultTo;
347 resultWho = _resultWho;
348 requestCode = _reqCode;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700349 state = ActivityState.INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 frontOfTask = false;
351 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700353 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 finishing = false;
355 configDestroy = false;
356 keysPaused = false;
357 inHistory = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 visible = true;
359 waitingVisible = false;
360 nowVisible = false;
361 thumbnailNeeded = false;
362 idle = false;
363 hasBeenLaunched = false;
364
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700365 // This starts out true, since the initial state of an activity
366 // is that we have everything, and we shouldn't never consider it
367 // lacking in state to be removed if it dies.
368 haveState = true;
369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 if (aInfo != null) {
371 if (aInfo.targetActivity == null
372 || aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE
373 || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
374 realActivity = _intent.getComponent();
375 } else {
376 realActivity = new ComponentName(aInfo.packageName,
377 aInfo.targetActivity);
378 }
379 taskAffinity = aInfo.taskAffinity;
380 stateNotNeeded = (aInfo.flags&
381 ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0;
382 baseDir = aInfo.applicationInfo.sourceDir;
383 resDir = aInfo.applicationInfo.publicSourceDir;
384 dataDir = aInfo.applicationInfo.dataDir;
385 nonLocalizedLabel = aInfo.nonLocalizedLabel;
386 labelRes = aInfo.labelRes;
387 if (nonLocalizedLabel == null && labelRes == 0) {
388 ApplicationInfo app = aInfo.applicationInfo;
389 nonLocalizedLabel = app.nonLocalizedLabel;
390 labelRes = app.labelRes;
391 }
392 icon = aInfo.getIconResource();
393 theme = aInfo.getThemeResource();
Dianne Hackborn247fe742011-01-08 17:25:57 -0800394 realTheme = theme;
395 if (realTheme == 0) {
396 realTheme = aInfo.applicationInfo.targetSdkVersion
397 < Build.VERSION_CODES.HONEYCOMB
398 ? android.R.style.Theme
399 : android.R.style.Theme_Holo;
400 }
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800401 if ((aInfo.flags&ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
402 windowFlags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
403 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0
405 && _caller != null
406 && (aInfo.applicationInfo.uid == Process.SYSTEM_UID
407 || aInfo.applicationInfo.uid == _caller.info.uid)) {
408 processName = _caller.processName;
409 } else {
410 processName = aInfo.processName;
411 }
412
413 if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
414 intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
415 }
416
417 packageName = aInfo.applicationInfo.packageName;
418 launchMode = aInfo.launchMode;
419
420 AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700421 realTheme, com.android.internal.R.styleable.Window, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 fullscreen = ent != null && !ent.array.getBoolean(
423 com.android.internal.R.styleable.Window_windowIsFloating, false)
424 && !ent.array.getBoolean(
425 com.android.internal.R.styleable.Window_windowIsTranslucent, false);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800426 noDisplay = ent != null && ent.array.getBoolean(
427 com.android.internal.R.styleable.Window_windowNoDisplay, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428
The Android Open Source Project4df24232009-03-05 14:34:35 -0800429 if (!_componentSpecified || _launchedFromUid == Process.myUid()
430 || _launchedFromUid == 0) {
431 // If we know the system has determined the component, then
432 // we can consider this to be a home activity...
433 if (Intent.ACTION_MAIN.equals(_intent.getAction()) &&
434 _intent.hasCategory(Intent.CATEGORY_HOME) &&
435 _intent.getCategories().size() == 1 &&
436 _intent.getData() == null &&
437 _intent.getType() == null &&
438 (intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 &&
Dianne Hackborn2d69d492012-04-06 16:24:14 -0700439 !ResolverActivity.class.getName().equals(realActivity.getClassName())) {
The Android Open Source Project4df24232009-03-05 14:34:35 -0800440 // This sure looks like a home activity!
441 // Note the last check is so we don't count the resolver
442 // activity as being home... really, we don't care about
443 // doing anything special with something that comes from
444 // the core framework package.
445 isHomeActivity = true;
446 } else {
447 isHomeActivity = false;
448 }
449 } else {
450 isHomeActivity = false;
451 }
Daniel Sandler69a48172010-06-23 16:29:36 -0400452
453 immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 } else {
455 realActivity = null;
456 taskAffinity = null;
457 stateNotNeeded = false;
458 baseDir = null;
459 resDir = null;
460 dataDir = null;
461 processName = null;
462 packageName = null;
463 fullscreen = true;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800464 noDisplay = false;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800465 isHomeActivity = false;
Daniel Sandler69a48172010-06-23 16:29:36 -0400466 immersive = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 }
468 }
469
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700470 void setTask(TaskRecord newTask, ThumbnailHolder newThumbHolder, boolean isRoot) {
471 if (inHistory && !finishing) {
472 if (task != null) {
473 task.numActivities--;
474 }
475 if (newTask != null) {
476 newTask.numActivities++;
477 }
478 }
479 if (newThumbHolder == null) {
480 newThumbHolder = newTask;
481 }
482 task = newTask;
483 if (!isRoot && (intent.getFlags()&Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
484 // This is the start of a new sub-task.
485 if (thumbHolder == null) {
486 thumbHolder = new ThumbnailHolder();
487 }
488 } else {
489 thumbHolder = newThumbHolder;
490 }
491 }
492
493 void putInHistory() {
494 if (!inHistory) {
495 inHistory = true;
496 if (task != null && !finishing) {
497 task.numActivities++;
498 }
499 }
500 }
501
502 void takeFromHistory() {
503 if (inHistory) {
504 inHistory = false;
505 if (task != null && !finishing) {
506 task.numActivities--;
507 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700508 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700509 }
510 }
511
512 boolean isInHistory() {
513 return inHistory;
514 }
515
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800516 void makeFinishing() {
517 if (!finishing) {
518 finishing = true;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700519 if (task != null && inHistory) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800520 task.numActivities--;
521 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700522 if (stopped) {
523 clearOptionsLocked();
524 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800525 }
526 }
527
Dianne Hackborn7e269642010-08-25 19:50:20 -0700528 UriPermissionOwner getUriPermissionsLocked() {
529 if (uriPermissions == null) {
530 uriPermissions = new UriPermissionOwner(service, this);
531 }
532 return uriPermissions;
533 }
534
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700535 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 int requestCode, int resultCode,
537 Intent resultData) {
538 ActivityResult r = new ActivityResult(from, resultWho,
539 requestCode, resultCode, resultData);
540 if (results == null) {
Craig Mautner2ad92072013-02-25 16:19:24 -0800541 results = new ArrayList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 }
543 results.add(r);
544 }
545
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700546 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 int requestCode) {
548 if (results != null) {
549 for (int i=results.size()-1; i>=0; i--) {
550 ActivityResult r = (ActivityResult)results.get(i);
551 if (r.mFrom != from) continue;
552 if (r.mResultWho == null) {
553 if (resultWho != null) continue;
554 } else {
555 if (!r.mResultWho.equals(resultWho)) continue;
556 }
557 if (r.mRequestCode != requestCode) continue;
558
559 results.remove(i);
560 }
561 }
562 }
563
564 void addNewIntentLocked(Intent intent) {
565 if (newIntents == null) {
566 newIntents = new ArrayList();
567 }
568 newIntents.add(intent);
569 }
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700570
571 /**
572 * Deliver a new Intent to an existing activity, so that its onNewIntent()
573 * method will be called at the proper time.
574 */
Dianne Hackborn39792d22010-08-19 18:01:52 -0700575 final void deliverNewIntentLocked(int callingUid, Intent intent) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700576 boolean sent = false;
Dianne Hackborn514074f2013-02-11 10:52:46 -0800577 // The activity now gets access to the data associated with this Intent.
578 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
579 intent, getUriPermissionsLocked());
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700580 // We want to immediately deliver the intent to the activity if
581 // it is currently the top resumed activity... however, if the
582 // device is sleeping, then all activities are stopped, so in that
583 // case we will deliver it if this is the current top activity on its
584 // stack.
585 if ((state == ActivityState.RESUMED || (service.mSleeping
586 && stack.topRunningActivityLocked(null) == this))
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700587 && app != null && app.thread != null) {
588 try {
589 ArrayList<Intent> ar = new ArrayList<Intent>();
Dianne Hackborn39792d22010-08-19 18:01:52 -0700590 intent = new Intent(intent);
591 ar.add(intent);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800592 app.thread.scheduleNewIntent(ar, appToken);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700593 sent = true;
Dianne Hackborn39792d22010-08-19 18:01:52 -0700594 } catch (RemoteException e) {
595 Slog.w(ActivityManagerService.TAG,
596 "Exception thrown sending new intent to " + this, e);
597 } catch (NullPointerException e) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700598 Slog.w(ActivityManagerService.TAG,
599 "Exception thrown sending new intent to " + this, e);
600 }
601 }
602 if (!sent) {
603 addNewIntentLocked(new Intent(intent));
604 }
605 }
606
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700607 void updateOptionsLocked(Bundle options) {
608 if (options != null) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700609 if (pendingOptions != null) {
610 pendingOptions.abort();
611 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700612 pendingOptions = new ActivityOptions(options);
613 }
614 }
615
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700616 void updateOptionsLocked(ActivityOptions options) {
617 if (options != null) {
618 if (pendingOptions != null) {
619 pendingOptions.abort();
620 }
621 pendingOptions = options;
622 }
623 }
624
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700625 void applyOptionsLocked() {
626 if (pendingOptions != null) {
Michael Jurka21385cd2012-05-03 10:57:31 -0700627 final int animationType = pendingOptions.getAnimationType();
628 switch (animationType) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700629 case ActivityOptions.ANIM_CUSTOM:
630 service.mWindowManager.overridePendingAppTransition(
631 pendingOptions.getPackageName(),
632 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -0700633 pendingOptions.getCustomExitResId(),
634 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700635 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700636 case ActivityOptions.ANIM_SCALE_UP:
637 service.mWindowManager.overridePendingAppTransitionScaleUp(
638 pendingOptions.getStartX(), pendingOptions.getStartY(),
639 pendingOptions.getStartWidth(), pendingOptions.getStartHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700640 if (intent.getSourceBounds() == null) {
641 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
642 pendingOptions.getStartY(),
643 pendingOptions.getStartX()+pendingOptions.getStartWidth(),
644 pendingOptions.getStartY()+pendingOptions.getStartHeight()));
645 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700646 break;
Michael Jurka832cb222012-04-13 09:32:47 -0700647 case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
648 case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
649 boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700650 service.mWindowManager.overridePendingAppTransitionThumb(
651 pendingOptions.getThumbnail(),
652 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -0700653 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -0700654 scaleUp);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700655 if (intent.getSourceBounds() == null) {
656 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
657 pendingOptions.getStartY(),
658 pendingOptions.getStartX()
659 + pendingOptions.getThumbnail().getWidth(),
660 pendingOptions.getStartY()
661 + pendingOptions.getThumbnail().getHeight()));
662 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700663 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700664 }
665 pendingOptions = null;
666 }
667 }
668
669 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700670 if (pendingOptions != null) {
671 pendingOptions.abort();
672 pendingOptions = null;
673 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700674 }
675
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700676 ActivityOptions takeOptionsLocked() {
677 ActivityOptions opts = pendingOptions;
678 pendingOptions = null;
679 return opts;
680 }
681
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700682 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -0700683 if (uriPermissions != null) {
684 uriPermissions.removeUriPermissionsLocked();
685 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700686 }
687 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688
689 void pauseKeyDispatchingLocked() {
690 if (!keysPaused) {
691 keysPaused = true;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800692 service.mWindowManager.pauseKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 }
694 }
695
696 void resumeKeyDispatchingLocked() {
697 if (keysPaused) {
698 keysPaused = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800699 service.mWindowManager.resumeKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700 }
701 }
702
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700703 void updateThumbnail(Bitmap newThumbnail, CharSequence description) {
704 if ((intent.getFlags()&Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
705 // This is a logical break in the task; it repre
706 }
707 if (thumbHolder != null) {
708 if (newThumbnail != null) {
Dianne Hackborn15491c62012-09-19 10:59:14 -0700709 if (ActivityManagerService.DEBUG_THUMBNAILS) Slog.i(ActivityManagerService.TAG,
710 "Setting thumbnail of " + this + " holder " + thumbHolder
711 + " to " + newThumbnail);
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700712 thumbHolder.lastThumbnail = newThumbnail;
713 }
714 thumbHolder.lastDescription = description;
715 }
716 }
717
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700718 void startLaunchTickingLocked() {
719 if (ActivityManagerService.IS_USER_BUILD) {
720 return;
721 }
722 if (launchTickTime == 0) {
723 launchTickTime = SystemClock.uptimeMillis();
724 continueLaunchTickingLocked();
725 }
726 }
727
728 boolean continueLaunchTickingLocked() {
729 if (launchTickTime != 0) {
730 Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG);
731 msg.obj = this;
732 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
733 stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
734 return true;
735 }
736 return false;
737 }
738
739 void finishLaunchTickingLocked() {
740 launchTickTime = 0;
741 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
742 }
743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 // IApplicationToken
745
746 public boolean mayFreezeScreenLocked(ProcessRecord app) {
747 // Only freeze the screen if this activity is currently attached to
748 // an application, and that application is not blocked or unresponding.
749 // In any other case, we can't count on getting the screen unfrozen,
750 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -0800751 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 }
753
754 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
755 if (mayFreezeScreenLocked(app)) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800756 service.mWindowManager.startAppFreezingScreen(appToken, configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 }
758 }
759
760 public void stopFreezingScreenLocked(boolean force) {
761 if (force || frozenBeforeDestroy) {
762 frozenBeforeDestroy = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800763 service.mWindowManager.stopAppFreezingScreen(appToken, force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 }
765 }
766
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700767 public void windowsDrawn() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 synchronized(service) {
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700769 if (launchTime != 0) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700770 final long curTime = SystemClock.uptimeMillis();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700771 final long thisTime = curTime - launchTime;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700772 final long totalTime = stack.mInitialStartTime != 0
773 ? (curTime - stack.mInitialStartTime) : thisTime;
Dianne Hackborn6447ca32009-04-07 19:50:08 -0700774 if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700775 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
776 userId, System.identityHashCode(this), shortComponentName,
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700777 thisTime, totalTime);
778 StringBuilder sb = service.mStringBuilder;
779 sb.setLength(0);
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700780 sb.append("Displayed ");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700781 sb.append(shortComponentName);
782 sb.append(": ");
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700783 TimeUtils.formatDuration(thisTime, sb);
Dianne Hackborncef65ee2010-09-30 18:27:22 -0700784 if (thisTime != totalTime) {
785 sb.append(" (total ");
786 TimeUtils.formatDuration(totalTime, sb);
787 sb.append(")");
788 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700789 Log.i(ActivityManagerService.TAG, sb.toString());
Dianne Hackborn6447ca32009-04-07 19:50:08 -0700790 }
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700791 stack.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700792 if (totalTime > 0) {
793 service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn6447ca32009-04-07 19:50:08 -0700794 }
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700795 launchTime = 0;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700796 stack.mInitialStartTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 }
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700798 startTime = 0;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700799 finishLaunchTickingLocked();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700800 }
801 }
802
803 public void windowsVisible() {
804 synchronized(service) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700805 stack.reportActivityVisibleLocked(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
807 ActivityManagerService.TAG, "windowsVisible(): " + this);
808 if (!nowVisible) {
809 nowVisible = true;
Dianne Hackborn50685602011-12-01 12:23:37 -0800810 lastVisibleTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 if (!idle) {
812 // Instead of doing the full stop routine here, let's just
813 // hide any activities we now can, and let them stop when
814 // the normal idle happens.
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700815 stack.processStoppingActivitiesLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800816 } else {
817 // If this activity was already idle, then we now need to
818 // make sure we perform the full stop of any activities
819 // that are waiting to do so. This is because we won't
820 // do that while they are still waiting for this one to
821 // become visible.
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700822 final int N = stack.mWaitingVisibleActivities.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 if (N > 0) {
824 for (int i=0; i<N; i++) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700825 ActivityRecord r = (ActivityRecord)
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700826 stack.mWaitingVisibleActivities.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 r.waitingVisible = false;
828 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
829 ActivityManagerService.TAG,
830 "Was waiting for visible: " + r);
831 }
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700832 stack.mWaitingVisibleActivities.clear();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 Message msg = Message.obtain();
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700834 msg.what = ActivityStack.IDLE_NOW_MSG;
835 stack.mHandler.sendMessage(msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800836 }
837 }
838 service.scheduleAppGcsLocked();
839 }
840 }
841 }
842
843 public void windowsGone() {
844 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
845 ActivityManagerService.TAG, "windowsGone(): " + this);
846 nowVisible = false;
847 }
848
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700849 private ActivityRecord getWaitingHistoryRecordLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 // First find the real culprit... if we are waiting
851 // for another app to start, then we have paused dispatching
852 // for this activity.
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700853 ActivityRecord r = this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 if (r.waitingVisible) {
855 // Hmmm, who might we be waiting for?
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700856 r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800857 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -0800858 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800859 }
860 // Both of those null? Fall back to 'this' again
861 if (r == null) {
862 r = this;
863 }
864 }
865
866 return r;
867 }
868
869 public boolean keyDispatchingTimedOut() {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700870 ActivityRecord r;
Michael Wright7dd5bb12013-02-27 17:07:29 -0800871 ProcessRecord anrApp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872 synchronized(service) {
Dianne Hackbornad5499d2010-03-29 18:08:45 -0700873 r = getWaitingHistoryRecordLocked();
Michael Wright7dd5bb12013-02-27 17:07:29 -0800874 anrApp = r != null ? r.app : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800875 }
Michael Wright7dd5bb12013-02-27 17:07:29 -0800876 return service.inputDispatchingTimedOut(anrApp, r, this, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 }
878
879 /** Returns the key dispatching timeout for this application token. */
880 public long getKeyDispatchingTimeout() {
881 synchronized(service) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700882 ActivityRecord r = getWaitingHistoryRecordLocked();
Michael Wright7dd5bb12013-02-27 17:07:29 -0800883 return ActivityManagerService.getInputDispatchingTimeoutLocked(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884 }
885 }
886
887 /**
888 * This method will return true if the activity is either visible, is becoming visible, is
889 * currently pausing, or is resumed.
890 */
891 public boolean isInterestingToUserLocked() {
892 return visible || nowVisible || state == ActivityState.PAUSING ||
893 state == ActivityState.RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800894 }
895
896 public void setSleeping(boolean _sleeping) {
897 if (sleeping == _sleeping) {
898 return;
899 }
900 if (app != null && app.thread != null) {
901 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800902 app.thread.scheduleSleeping(appToken, _sleeping);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800903 if (sleeping && !stack.mGoingToSleepActivities.contains(this)) {
904 stack.mGoingToSleepActivities.add(this);
905 }
906 sleeping = _sleeping;
907 } catch (RemoteException e) {
908 Slog.w(ActivityStack.TAG, "Exception thrown when sleeping: "
909 + intent.getComponent(), e);
910 }
911 }
912 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700915 if (stringName != null) {
916 return stringName;
917 }
918 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -0800919 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700920 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700921 sb.append(" u");
922 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700923 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700924 sb.append(intent.getComponent().flattenToShortString());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700925 sb.append('}');
926 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 }
928}