blob: aaf5f4d862a13b072c9d11f3ccf5850086a8487f [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.am;
18
Dianne Hackborn2286cdc2013-07-01 19:10:06 -070019import android.os.Trace;
Craig Mautner5eda9b32013-07-02 11:58:16 -070020import com.android.internal.R.styleable;
Dianne Hackborn2d69d492012-04-06 16:24:14 -070021import com.android.internal.app.ResolverActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import com.android.server.AttributeCache;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070023import com.android.server.am.ActivityStack.ActivityState;
Craig Mautner4a1cb222013-12-04 16:14:06 -080024import com.android.server.am.ActivityStackSupervisor.ActivityContainer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025
Dianne Hackborn7a2195c2012-03-19 17:38:00 -070026import android.app.ActivityOptions;
Craig Mautner05d6272ba2013-02-11 09:39:27 -080027import android.app.ResultInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.content.ComponentName;
29import android.content.Intent;
30import android.content.pm.ActivityInfo;
31import android.content.pm.ApplicationInfo;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -070032import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.content.res.Configuration;
34import android.graphics.Bitmap;
Dianne Hackbornd367ca82012-05-07 15:49:39 -070035import android.graphics.Rect;
Dianne Hackborn247fe742011-01-08 17:25:57 -080036import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.os.Bundle;
Dianne Hackbornbe707852011-11-11 14:32:10 -080038import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.os.Message;
40import android.os.Process;
Dianne Hackborn39792d22010-08-19 18:01:52 -070041import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.os.SystemClock;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070043import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.util.EventLog;
45import android.util.Log;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070046import android.util.Slog;
Dianne Hackborn0dad3642010-09-09 21:25:35 -070047import android.util.TimeUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.view.IApplicationToken;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -080049import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050
51import java.io.PrintWriter;
52import java.lang.ref.WeakReference;
53import java.util.ArrayList;
54import java.util.HashSet;
55
56/**
57 * An entry in the history stack, representing an activity.
58 */
Dianne Hackbornbe707852011-11-11 14:32:10 -080059final class ActivityRecord {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -070060 static final String TAG = ActivityManagerService.TAG;
61 static final boolean DEBUG_SAVED_STATE = ActivityStackSupervisor.DEBUG_SAVED_STATE;
Craig Mautner80259352013-09-28 12:35:25 -070062 final public static String RECENTS_PACKAGE_NAME = "com.android.systemui.recent";
Craig Mautnerb59dcfd2013-05-06 13:12:58 -070063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 final ActivityManagerService service; // owner
Dianne Hackbornbe707852011-11-11 14:32:10 -080065 final IApplicationToken.Stub appToken; // window manager token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 final ActivityInfo info; // all about me
67 final int launchedFromUid; // always the uid who started the activity.
Dianne Hackbornf265ea92013-01-31 15:00:51 -080068 final String launchedFromPackage; // always the package who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -070069 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 final Intent intent; // the original intent that generated us
71 final ComponentName realActivity; // the intent component, or target of an alias.
72 final String shortComponentName; // the short component name of the intent
73 final String resolvedType; // as per original caller;
74 final String packageName; // the package implementing intent's component
75 final String processName; // process where this component wants to run
76 final String taskAffinity; // as per ActivityInfo.taskAffinity
77 final boolean stateNotNeeded; // As per ActivityInfo.flags
Craig Mautner4addfc52013-06-25 08:05:45 -070078 boolean fullscreen; // covers the full screen?
Dianne Hackbornff801ec2011-01-22 18:05:38 -080079 final boolean noDisplay; // activity is not displayed?
The Android Open Source Project4df24232009-03-05 14:34:35 -080080 final boolean componentSpecified; // did caller specifiy an explicit component?
Craig Mautner86d67a42013-05-14 10:34:38 -070081
82 static final int APPLICATION_ACTIVITY_TYPE = 0;
83 static final int HOME_ACTIVITY_TYPE = 1;
84 static final int RECENTS_ACTIVITY_TYPE = 2;
Craig Mautner2c1faed2013-07-23 12:56:02 -070085 int mActivityType;
Craig Mautner86d67a42013-05-14 10:34:38 -070086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 final String baseDir; // where activity source (resources etc) located
88 final String resDir; // where public activity source (public resources etc) located
89 final String dataDir; // where activity data should go
90 CharSequence nonLocalizedLabel; // the label information from the package mgr.
91 int labelRes; // the label information from the package mgr.
92 int icon; // resource identifier of activity's icon.
Adam Powell04fe6eb2013-05-31 14:39:48 -070093 int logo; // resource identifier of activity's logo.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 int theme; // resource identifier of activity's theme.
Dianne Hackborn247fe742011-01-08 17:25:57 -080095 int realTheme; // actual theme resource we will use, never 0.
Dianne Hackborn7eec10e2010-11-12 18:03:47 -080096 int windowFlags; // custom window flags for preview window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 TaskRecord task; // the task this is in.
Dianne Hackbornf26fd992011-04-08 18:14:09 -070098 ThumbnailHolder thumbHolder; // where our thumbnails should go.
Dianne Hackborn2286cdc2013-07-01 19:10:06 -070099 long displayStartTime; // when we started launching this activity
100 long fullyDrawnStartTime; // when we started launching this activity
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700101 long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -0800102 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700103 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700104 long pauseTime; // last time we started pausing the activity
105 long launchTickTime; // base time for launch tick messages
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 Configuration configuration; // configuration activity was last running in
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700107 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700108 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 final String resultWho; // additional identifier for use by resultTo.
110 final int requestCode; // code given by requester (resultTo)
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800111 ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800113 ArrayList<Intent> newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700114 ActivityOptions pendingOptions; // most recently given options
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700116 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700117 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700118 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 Bundle icicle; // last saved activity state
120 boolean frontOfTask; // is this the root activity of its task?
121 boolean launchFailed; // set if a launched failed, to abort on 2nd try
122 boolean haveState; // have we gotten the last activity state?
123 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700124 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 boolean finishing; // activity in pending finish list?
126 boolean configDestroy; // need to destroy due to config change?
127 int configChangeFlags; // which config values have changed
128 boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 int launchMode; // the launch mode activity attribute.
130 boolean visible; // does this activity's window need to be shown?
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800131 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 boolean waitingVisible; // true if waiting for a new act to become vis
133 boolean nowVisible; // is this activity's window visible?
134 boolean thumbnailNeeded;// has someone requested a thumbnail?
135 boolean idle; // has the activity gone idle?
136 boolean hasBeenLaunched;// has this activity ever been launched?
137 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400138 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400139 boolean forceNewConfig; // force re-create with new config next time
Dianne Hackborn07981492013-01-28 11:36:23 -0800140 int launchCount; // count of launches since last state
141 long lastLaunchTime; // time of last lauch of this activity
Craig Mautner4a1cb222013-12-04 16:14:06 -0800142 ArrayList<ActivityStack> mChildContainers = new ArrayList<ActivityStack>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700144 String stringName; // for caching of toString().
Craig Mautnerde4ef022013-04-07 19:01:33 -0700145
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700146 private boolean inHistory; // are we in the history stack?
Craig Mautnerde4ef022013-04-07 19:01:33 -0700147 final ActivityStackSupervisor mStackSupervisor;
Craig Mautnere0a38842013-12-16 16:14:02 -0800148 ActivityContainer mInitialActivityContainer;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700151 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700152 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
153 pw.print(" processName="); pw.println(processName);
154 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Craig Mautnere11f2b72013-04-01 12:37:17 -0700155 pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800156 pw.print(" userId="); pw.println(userId);
157 pw.print(prefix); pw.print("app="); pw.println(app);
158 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700159 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
160 pw.print(" task="); pw.println(task);
161 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700162 pw.print(prefix); pw.print("realActivity=");
163 pw.println(realActivity.flattenToShortString());
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800164 pw.print(prefix); pw.print("baseDir="); pw.println(baseDir);
165 if (!resDir.equals(baseDir)) {
166 pw.print(prefix); pw.print("resDir="); pw.println(resDir);
167 }
168 pw.print(prefix); pw.print("dataDir="); pw.println(dataDir);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700169 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
170 pw.print(" componentSpecified="); pw.print(componentSpecified);
Craig Mautner86d67a42013-05-14 10:34:38 -0700171 pw.print(" mActivityType="); pw.println(mActivityType);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800172 pw.print(prefix); pw.print("compat="); pw.print(compat);
173 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
174 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
175 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Dianne Hackborne17aeb32011-04-07 15:11:57 -0700176 pw.print(prefix); pw.print("config="); pw.println(configuration);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700177 if (resultTo != null || resultWho != null) {
178 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
179 pw.print(" resultWho="); pw.print(resultWho);
180 pw.print(" resultCode="); pw.println(requestCode);
181 }
182 if (results != null) {
183 pw.print(prefix); pw.print("results="); pw.println(results);
184 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700185 if (pendingResults != null && pendingResults.size() > 0) {
186 pw.print(prefix); pw.println("Pending Results:");
187 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
188 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
189 pw.print(prefix); pw.print(" - ");
190 if (pir == null) {
191 pw.println("null");
192 } else {
193 pw.println(pir);
194 pir.dump(pw, prefix + " ");
195 }
196 }
197 }
198 if (newIntents != null && newIntents.size() > 0) {
199 pw.print(prefix); pw.println("Pending New Intents:");
200 for (int i=0; i<newIntents.size(); i++) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800201 Intent intent = newIntents.get(i);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700202 pw.print(prefix); pw.print(" - ");
203 if (intent == null) {
204 pw.println("null");
205 } else {
206 pw.println(intent.toShortString(false, true, false, true));
207 }
208 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700209 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700210 if (pendingOptions != null) {
211 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
212 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700213 if (uriPermissions != null) {
214 if (uriPermissions.readUriPermissions != null) {
215 pw.print(prefix); pw.print("readUriPermissions=");
216 pw.println(uriPermissions.readUriPermissions);
217 }
218 if (uriPermissions.writeUriPermissions != null) {
219 pw.print(prefix); pw.print("writeUriPermissions=");
220 pw.println(uriPermissions.writeUriPermissions);
221 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700222 }
223 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800224 pw.print(" launchCount="); pw.print(launchCount);
225 pw.print(" lastLaunchTime=");
226 if (lastLaunchTime == 0) pw.print("0");
227 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
228 pw.println();
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700229 pw.print(prefix); pw.print("haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700230 pw.print(" icicle="); pw.println(icicle);
231 pw.print(prefix); pw.print("state="); pw.print(state);
232 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700233 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700234 pw.print(" finishing="); pw.println(finishing);
235 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
236 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700237 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800238 pw.print(" sleeping="); pw.print(sleeping);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700239 pw.print(" idle="); pw.println(idle);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800240 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
241 pw.print(" noDisplay="); pw.print(noDisplay);
242 pw.print(" immersive="); pw.print(immersive);
243 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800244 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400245 pw.print(" thumbnailNeeded="); pw.print(thumbnailNeeded);
246 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700247 pw.print(prefix); pw.print("mActivityType=");
248 pw.println(activityTypeToString(mActivityType));
Dianne Hackborn15491c62012-09-19 10:59:14 -0700249 pw.print(prefix); pw.print("thumbHolder: ");
250 pw.print(Integer.toHexString(System.identityHashCode(thumbHolder)));
251 if (thumbHolder != null) {
252 pw.print(" bm="); pw.print(thumbHolder.lastThumbnail);
253 pw.print(" desc="); pw.print(thumbHolder.lastDescription);
254 }
255 pw.println();
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700256 if (displayStartTime != 0 || startTime != 0) {
257 pw.print(prefix); pw.print("displayStartTime=");
258 if (displayStartTime == 0) pw.print("0");
259 else TimeUtils.formatDuration(displayStartTime, now, pw);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700260 pw.print(" startTime=");
261 if (startTime == 0) pw.print("0");
262 else TimeUtils.formatDuration(startTime, now, pw);
263 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700264 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800265 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700266 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800267 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700268 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700269 if (lastVisibleTime == 0) pw.print("0");
270 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
271 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700272 }
273 if (configDestroy || configChangeFlags != 0) {
274 pw.print(prefix); pw.print("configDestroy="); pw.print(configDestroy);
275 pw.print(" configChangeFlags=");
276 pw.println(Integer.toHexString(configChangeFlags));
277 }
278 if (connections != null) {
279 pw.print(prefix); pw.print("connections="); pw.println(connections);
280 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 }
282
Dianne Hackbornbe707852011-11-11 14:32:10 -0800283 static class Token extends IApplicationToken.Stub {
284 final WeakReference<ActivityRecord> weakActivity;
285
286 Token(ActivityRecord activity) {
287 weakActivity = new WeakReference<ActivityRecord>(activity);
288 }
289
Craig Mautnerde4ef022013-04-07 19:01:33 -0700290 @Override public void windowsDrawn() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800291 ActivityRecord activity = weakActivity.get();
292 if (activity != null) {
293 activity.windowsDrawn();
294 }
295 }
296
Craig Mautnerde4ef022013-04-07 19:01:33 -0700297 @Override public void windowsVisible() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800298 ActivityRecord activity = weakActivity.get();
299 if (activity != null) {
300 activity.windowsVisible();
301 }
302 }
303
Craig Mautnerde4ef022013-04-07 19:01:33 -0700304 @Override public void windowsGone() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800305 ActivityRecord activity = weakActivity.get();
306 if (activity != null) {
307 activity.windowsGone();
308 }
309 }
310
Jeff Brownbd181bb2013-09-10 16:44:24 -0700311 @Override public boolean keyDispatchingTimedOut(String reason) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800312 ActivityRecord activity = weakActivity.get();
Jeff Brownbd181bb2013-09-10 16:44:24 -0700313 return activity != null && activity.keyDispatchingTimedOut(reason);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800314 }
315
Craig Mautnerde4ef022013-04-07 19:01:33 -0700316 @Override public long getKeyDispatchingTimeout() {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800317 ActivityRecord activity = weakActivity.get();
318 if (activity != null) {
319 return activity.getKeyDispatchingTimeout();
320 }
321 return 0;
322 }
323
Craig Mautnerde4ef022013-04-07 19:01:33 -0700324 @Override
Dianne Hackbornbe707852011-11-11 14:32:10 -0800325 public String toString() {
326 StringBuilder sb = new StringBuilder(128);
327 sb.append("Token{");
328 sb.append(Integer.toHexString(System.identityHashCode(this)));
329 sb.append(' ');
330 sb.append(weakActivity.get());
331 sb.append('}');
332 return sb.toString();
333 }
334 }
335
336 static ActivityRecord forToken(IBinder token) {
337 try {
338 return token != null ? ((Token)token).weakActivity.get() : null;
339 } catch (ClassCastException e) {
340 Slog.w(ActivityManagerService.TAG, "Bad activity token: " + token, e);
341 return null;
342 }
343 }
344
Craig Mautnerac6f8432013-07-17 13:24:59 -0700345 boolean isNotResolverActivity() {
346 return !ResolverActivity.class.getName().equals(realActivity.getClassName());
347 }
348
Craig Mautnerd2328952013-03-05 12:46:26 -0800349 ActivityRecord(ActivityManagerService _service, ProcessRecord _caller,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800350 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700352 ActivityRecord _resultTo, String _resultWho, int _reqCode,
Craig Mautnere0a38842013-12-16 16:14:02 -0800353 boolean _componentSpecified, ActivityStackSupervisor supervisor,
354 ActivityContainer container) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 service = _service;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800356 appToken = new Token(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 info = aInfo;
358 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800359 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700360 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 intent = _intent;
362 shortComponentName = _intent.getComponent().flattenToShortString();
363 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800364 componentSpecified = _componentSpecified;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 configuration = _configuration;
366 resultTo = _resultTo;
367 resultWho = _resultWho;
368 requestCode = _reqCode;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700369 state = ActivityState.INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 frontOfTask = false;
371 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700373 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 finishing = false;
375 configDestroy = false;
376 keysPaused = false;
377 inHistory = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 visible = true;
379 waitingVisible = false;
380 nowVisible = false;
381 thumbnailNeeded = false;
382 idle = false;
383 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700384 mStackSupervisor = supervisor;
Craig Mautnere0a38842013-12-16 16:14:02 -0800385 mInitialActivityContainer = container;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700387 // This starts out true, since the initial state of an activity
388 // is that we have everything, and we shouldn't never consider it
389 // lacking in state to be removed if it dies.
390 haveState = true;
391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 if (aInfo != null) {
393 if (aInfo.targetActivity == null
394 || aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE
395 || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
396 realActivity = _intent.getComponent();
397 } else {
398 realActivity = new ComponentName(aInfo.packageName,
399 aInfo.targetActivity);
400 }
401 taskAffinity = aInfo.taskAffinity;
402 stateNotNeeded = (aInfo.flags&
403 ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0;
404 baseDir = aInfo.applicationInfo.sourceDir;
405 resDir = aInfo.applicationInfo.publicSourceDir;
406 dataDir = aInfo.applicationInfo.dataDir;
407 nonLocalizedLabel = aInfo.nonLocalizedLabel;
408 labelRes = aInfo.labelRes;
409 if (nonLocalizedLabel == null && labelRes == 0) {
410 ApplicationInfo app = aInfo.applicationInfo;
411 nonLocalizedLabel = app.nonLocalizedLabel;
412 labelRes = app.labelRes;
413 }
414 icon = aInfo.getIconResource();
Adam Powell04fe6eb2013-05-31 14:39:48 -0700415 logo = aInfo.getLogoResource();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 theme = aInfo.getThemeResource();
Dianne Hackborn247fe742011-01-08 17:25:57 -0800417 realTheme = theme;
418 if (realTheme == 0) {
419 realTheme = aInfo.applicationInfo.targetSdkVersion
420 < Build.VERSION_CODES.HONEYCOMB
421 ? android.R.style.Theme
422 : android.R.style.Theme_Holo;
423 }
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800424 if ((aInfo.flags&ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
425 windowFlags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
426 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0
428 && _caller != null
429 && (aInfo.applicationInfo.uid == Process.SYSTEM_UID
430 || aInfo.applicationInfo.uid == _caller.info.uid)) {
431 processName = _caller.processName;
432 } else {
433 processName = aInfo.processName;
434 }
435
436 if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
437 intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
438 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 packageName = aInfo.applicationInfo.packageName;
441 launchMode = aInfo.launchMode;
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700444 realTheme, com.android.internal.R.styleable.Window, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 fullscreen = ent != null && !ent.array.getBoolean(
446 com.android.internal.R.styleable.Window_windowIsFloating, false)
447 && !ent.array.getBoolean(
448 com.android.internal.R.styleable.Window_windowIsTranslucent, false);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800449 noDisplay = ent != null && ent.array.getBoolean(
450 com.android.internal.R.styleable.Window_windowNoDisplay, false);
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700451
Craig Mautner80259352013-09-28 12:35:25 -0700452 if ((!_componentSpecified || _launchedFromUid == Process.myUid()
Craig Mautner86d67a42013-05-14 10:34:38 -0700453 || _launchedFromUid == 0) &&
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700454 Intent.ACTION_MAIN.equals(_intent.getAction()) &&
455 _intent.hasCategory(Intent.CATEGORY_HOME) &&
456 _intent.getCategories().size() == 1 &&
457 _intent.getData() == null &&
458 _intent.getType() == null &&
Craig Mautner80259352013-09-28 12:35:25 -0700459 (intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 &&
460 isNotResolverActivity()) {
Craig Mautner86d67a42013-05-14 10:34:38 -0700461 // This sure looks like a home activity!
462 mActivityType = HOME_ACTIVITY_TYPE;
Craig Mautner80259352013-09-28 12:35:25 -0700463 } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) {
Craig Mautner86d67a42013-05-14 10:34:38 -0700464 mActivityType = RECENTS_ACTIVITY_TYPE;
465 } else {
466 mActivityType = APPLICATION_ACTIVITY_TYPE;
467 }
Daniel Sandler69a48172010-06-23 16:29:36 -0400468
469 immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 } else {
471 realActivity = null;
472 taskAffinity = null;
473 stateNotNeeded = false;
474 baseDir = null;
475 resDir = null;
476 dataDir = null;
477 processName = null;
478 packageName = null;
479 fullscreen = true;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800480 noDisplay = false;
Craig Mautner86d67a42013-05-14 10:34:38 -0700481 mActivityType = APPLICATION_ACTIVITY_TYPE;
Daniel Sandler69a48172010-06-23 16:29:36 -0400482 immersive = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483 }
484 }
485
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700486 void setTask(TaskRecord newTask, ThumbnailHolder newThumbHolder, boolean isRoot) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700487 if (task != null && task.removeActivity(this)) {
Craig Mautner19d9bd52013-10-21 20:05:26 -0700488 if (task != newTask) {
Craig Mautner04a0ea62014-01-13 12:51:26 -0800489 task.stack.removeTask(task);
Craig Mautner19d9bd52013-10-21 20:05:26 -0700490 } else {
491 Slog.d(TAG, "!!! REMOVE THIS LOG !!! setTask: nearly removed stack=" +
492 (newTask == null ? null : newTask.stack));
493 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700494 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700495 if (inHistory && !finishing) {
496 if (task != null) {
497 task.numActivities--;
498 }
499 if (newTask != null) {
500 newTask.numActivities++;
501 }
502 }
503 if (newThumbHolder == null) {
504 newThumbHolder = newTask;
505 }
506 task = newTask;
507 if (!isRoot && (intent.getFlags()&Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
508 // This is the start of a new sub-task.
509 if (thumbHolder == null) {
510 thumbHolder = new ThumbnailHolder();
511 }
512 } else {
513 thumbHolder = newThumbHolder;
514 }
515 }
516
Craig Mautner5eda9b32013-07-02 11:58:16 -0700517 boolean changeWindowTranslucency(boolean toOpaque) {
518 if (fullscreen == toOpaque) {
519 return false;
520 }
521 AttributeCache.Entry ent =
Amith Yamasanied411592013-07-12 12:23:16 -0700522 AttributeCache.instance().get(packageName, realTheme, styleable.Window, userId);
Craig Mautner5eda9b32013-07-02 11:58:16 -0700523 if (ent == null
524 || !ent.array.getBoolean(styleable.Window_windowIsTranslucent, false)
525 || ent.array.getBoolean(styleable.Window_windowIsFloating, false)) {
Craig Mautner4addfc52013-06-25 08:05:45 -0700526 return false;
527 }
528
Craig Mautner5eda9b32013-07-02 11:58:16 -0700529 // Keep track of the number of fullscreen activities in this task.
530 task.numFullscreen += toOpaque ? +1 : -1;
531
532 fullscreen = toOpaque;
533 return true;
Craig Mautner4addfc52013-06-25 08:05:45 -0700534 }
535
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700536 void putInHistory() {
537 if (!inHistory) {
538 inHistory = true;
539 if (task != null && !finishing) {
540 task.numActivities++;
541 }
542 }
543 }
544
545 void takeFromHistory() {
546 if (inHistory) {
547 inHistory = false;
548 if (task != null && !finishing) {
549 task.numActivities--;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800550 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700551 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700552 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700553 }
554 }
555
556 boolean isInHistory() {
557 return inHistory;
558 }
559
Craig Mautner86d67a42013-05-14 10:34:38 -0700560 boolean isHomeActivity() {
561 return mActivityType == HOME_ACTIVITY_TYPE;
562 }
563
564 boolean isRecentsActivity() {
565 return mActivityType == RECENTS_ACTIVITY_TYPE;
566 }
567
568 boolean isApplicationActivity() {
569 return mActivityType == APPLICATION_ACTIVITY_TYPE;
570 }
571
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800572 void makeFinishing() {
573 if (!finishing) {
574 finishing = true;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700575 if (task != null && inHistory) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800576 task.numActivities--;
577 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700578 if (stopped) {
579 clearOptionsLocked();
580 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800581 }
582 }
583
Craig Mautnerde4ef022013-04-07 19:01:33 -0700584 boolean isRootActivity() {
Craig Mautner9c85c202013-10-04 20:11:26 -0700585 final ArrayList<ActivityRecord> activities = task.mActivities;
586 return activities.size() == 0 || this == activities.get(0);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700587 }
588
Dianne Hackborn7e269642010-08-25 19:50:20 -0700589 UriPermissionOwner getUriPermissionsLocked() {
590 if (uriPermissions == null) {
591 uriPermissions = new UriPermissionOwner(service, this);
592 }
593 return uriPermissions;
594 }
595
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700596 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597 int requestCode, int resultCode,
598 Intent resultData) {
599 ActivityResult r = new ActivityResult(from, resultWho,
600 requestCode, resultCode, resultData);
601 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800602 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 }
604 results.add(r);
605 }
606
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700607 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 int requestCode) {
609 if (results != null) {
610 for (int i=results.size()-1; i>=0; i--) {
611 ActivityResult r = (ActivityResult)results.get(i);
612 if (r.mFrom != from) continue;
613 if (r.mResultWho == null) {
614 if (resultWho != null) continue;
615 } else {
616 if (!r.mResultWho.equals(resultWho)) continue;
617 }
618 if (r.mRequestCode != requestCode) continue;
619
620 results.remove(i);
621 }
622 }
623 }
624
625 void addNewIntentLocked(Intent intent) {
626 if (newIntents == null) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800627 newIntents = new ArrayList<Intent>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 }
629 newIntents.add(intent);
630 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700631
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700632 /**
633 * Deliver a new Intent to an existing activity, so that its onNewIntent()
634 * method will be called at the proper time.
635 */
Dianne Hackborn39792d22010-08-19 18:01:52 -0700636 final void deliverNewIntentLocked(int callingUid, Intent intent) {
Dianne Hackborn514074f2013-02-11 10:52:46 -0800637 // The activity now gets access to the data associated with this Intent.
638 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
639 intent, getUriPermissionsLocked());
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700640 // We want to immediately deliver the intent to the activity if
641 // it is currently the top resumed activity... however, if the
642 // device is sleeping, then all activities are stopped, so in that
643 // case we will deliver it if this is the current top activity on its
644 // stack.
Craig Mautner86d67a42013-05-14 10:34:38 -0700645 boolean unsent = true;
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700646 if ((state == ActivityState.RESUMED || (service.mSleeping
Craig Mautnerd2328952013-03-05 12:46:26 -0800647 && task.stack.topRunningActivityLocked(null) == this))
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700648 && app != null && app.thread != null) {
649 try {
650 ArrayList<Intent> ar = new ArrayList<Intent>();
Dianne Hackborn39792d22010-08-19 18:01:52 -0700651 intent = new Intent(intent);
652 ar.add(intent);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800653 app.thread.scheduleNewIntent(ar, appToken);
Craig Mautner86d67a42013-05-14 10:34:38 -0700654 unsent = false;
Dianne Hackborn39792d22010-08-19 18:01:52 -0700655 } catch (RemoteException e) {
656 Slog.w(ActivityManagerService.TAG,
657 "Exception thrown sending new intent to " + this, e);
658 } catch (NullPointerException e) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700659 Slog.w(ActivityManagerService.TAG,
660 "Exception thrown sending new intent to " + this, e);
661 }
662 }
Craig Mautner86d67a42013-05-14 10:34:38 -0700663 if (unsent) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700664 addNewIntentLocked(new Intent(intent));
665 }
666 }
667
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700668 void updateOptionsLocked(Bundle options) {
669 if (options != null) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700670 if (pendingOptions != null) {
671 pendingOptions.abort();
672 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700673 pendingOptions = new ActivityOptions(options);
674 }
675 }
676
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700677 void updateOptionsLocked(ActivityOptions options) {
678 if (options != null) {
679 if (pendingOptions != null) {
680 pendingOptions.abort();
681 }
682 pendingOptions = options;
683 }
684 }
685
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700686 void applyOptionsLocked() {
687 if (pendingOptions != null) {
Michael Jurka21385cd2012-05-03 10:57:31 -0700688 final int animationType = pendingOptions.getAnimationType();
689 switch (animationType) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700690 case ActivityOptions.ANIM_CUSTOM:
691 service.mWindowManager.overridePendingAppTransition(
692 pendingOptions.getPackageName(),
693 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -0700694 pendingOptions.getCustomExitResId(),
695 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700696 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700697 case ActivityOptions.ANIM_SCALE_UP:
698 service.mWindowManager.overridePendingAppTransitionScaleUp(
699 pendingOptions.getStartX(), pendingOptions.getStartY(),
700 pendingOptions.getStartWidth(), pendingOptions.getStartHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700701 if (intent.getSourceBounds() == null) {
702 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
703 pendingOptions.getStartY(),
704 pendingOptions.getStartX()+pendingOptions.getStartWidth(),
705 pendingOptions.getStartY()+pendingOptions.getStartHeight()));
706 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700707 break;
Michael Jurka832cb222012-04-13 09:32:47 -0700708 case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
709 case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
710 boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700711 service.mWindowManager.overridePendingAppTransitionThumb(
712 pendingOptions.getThumbnail(),
713 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -0700714 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -0700715 scaleUp);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700716 if (intent.getSourceBounds() == null) {
717 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
718 pendingOptions.getStartY(),
719 pendingOptions.getStartX()
720 + pendingOptions.getThumbnail().getWidth(),
721 pendingOptions.getStartY()
722 + pendingOptions.getThumbnail().getHeight()));
723 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700724 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700725 }
726 pendingOptions = null;
727 }
728 }
729
730 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700731 if (pendingOptions != null) {
732 pendingOptions.abort();
733 pendingOptions = null;
734 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700735 }
736
Dianne Hackborn9622ca42012-10-23 18:56:33 -0700737 ActivityOptions takeOptionsLocked() {
738 ActivityOptions opts = pendingOptions;
739 pendingOptions = null;
740 return opts;
741 }
742
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700743 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -0700744 if (uriPermissions != null) {
745 uriPermissions.removeUriPermissionsLocked();
746 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700747 }
748 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749
750 void pauseKeyDispatchingLocked() {
751 if (!keysPaused) {
752 keysPaused = true;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800753 service.mWindowManager.pauseKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 }
755 }
756
757 void resumeKeyDispatchingLocked() {
758 if (keysPaused) {
759 keysPaused = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800760 service.mWindowManager.resumeKeyDispatching(appToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 }
762 }
763
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700764 void updateThumbnail(Bitmap newThumbnail, CharSequence description) {
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700765 if (thumbHolder != null) {
766 if (newThumbnail != null) {
Dianne Hackborn15491c62012-09-19 10:59:14 -0700767 if (ActivityManagerService.DEBUG_THUMBNAILS) Slog.i(ActivityManagerService.TAG,
768 "Setting thumbnail of " + this + " holder " + thumbHolder
769 + " to " + newThumbnail);
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700770 thumbHolder.lastThumbnail = newThumbnail;
771 }
772 thumbHolder.lastDescription = description;
773 }
774 }
775
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700776 void startLaunchTickingLocked() {
777 if (ActivityManagerService.IS_USER_BUILD) {
778 return;
779 }
780 if (launchTickTime == 0) {
781 launchTickTime = SystemClock.uptimeMillis();
782 continueLaunchTickingLocked();
783 }
784 }
785
786 boolean continueLaunchTickingLocked() {
787 if (launchTickTime != 0) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800788 final ActivityStack stack = task.stack;
Craig Mautnerf7bfefb2013-05-16 17:30:44 -0700789 Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG, this);
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700790 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
791 stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
792 return true;
793 }
794 return false;
795 }
796
797 void finishLaunchTickingLocked() {
798 launchTickTime = 0;
Craig Mautnerd2328952013-03-05 12:46:26 -0800799 task.stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700800 }
801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800802 // IApplicationToken
803
804 public boolean mayFreezeScreenLocked(ProcessRecord app) {
805 // Only freeze the screen if this activity is currently attached to
806 // an application, and that application is not blocked or unresponding.
807 // In any other case, we can't count on getting the screen unfrozen,
808 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -0800809 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800810 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
813 if (mayFreezeScreenLocked(app)) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800814 service.mWindowManager.startAppFreezingScreen(appToken, configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800815 }
816 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800818 public void stopFreezingScreenLocked(boolean force) {
819 if (force || frozenBeforeDestroy) {
820 frozenBeforeDestroy = false;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800821 service.mWindowManager.stopAppFreezingScreen(appToken, force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 }
823 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700824
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700825 public void reportFullyDrawnLocked() {
826 final long curTime = SystemClock.uptimeMillis();
827 if (displayStartTime != 0) {
828 reportLaunchTimeLocked(curTime);
829 }
830 if (fullyDrawnStartTime != 0) {
831 final ActivityStack stack = task.stack;
832 final long thisTime = curTime - fullyDrawnStartTime;
833 final long totalTime = stack.mFullyDrawnStartTime != 0
834 ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
835 if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -0700836 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700837 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME,
838 userId, System.identityHashCode(this), shortComponentName,
839 thisTime, totalTime);
840 StringBuilder sb = service.mStringBuilder;
841 sb.setLength(0);
842 sb.append("Fully drawn ");
843 sb.append(shortComponentName);
844 sb.append(": ");
845 TimeUtils.formatDuration(thisTime, sb);
846 if (thisTime != totalTime) {
847 sb.append(" (total ");
848 TimeUtils.formatDuration(totalTime, sb);
849 sb.append(")");
850 }
851 Log.i(ActivityManagerService.TAG, sb.toString());
852 }
853 if (totalTime > 0) {
854 service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
855 }
856 fullyDrawnStartTime = 0;
857 stack.mFullyDrawnStartTime = 0;
858 }
859 }
860
861 private void reportLaunchTimeLocked(final long curTime) {
862 final ActivityStack stack = task.stack;
863 final long thisTime = curTime - displayStartTime;
864 final long totalTime = stack.mLaunchStartTime != 0
865 ? (curTime - stack.mLaunchStartTime) : thisTime;
866 if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -0700867 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700868 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
869 userId, System.identityHashCode(this), shortComponentName,
870 thisTime, totalTime);
871 StringBuilder sb = service.mStringBuilder;
872 sb.setLength(0);
873 sb.append("Displayed ");
874 sb.append(shortComponentName);
875 sb.append(": ");
876 TimeUtils.formatDuration(thisTime, sb);
877 if (thisTime != totalTime) {
878 sb.append(" (total ");
879 TimeUtils.formatDuration(totalTime, sb);
880 sb.append(")");
881 }
882 Log.i(ActivityManagerService.TAG, sb.toString());
883 }
884 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
885 if (totalTime > 0) {
886 service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
887 }
888 displayStartTime = 0;
889 stack.mLaunchStartTime = 0;
890 }
891
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700892 public void windowsDrawn() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893 synchronized(service) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700894 if (displayStartTime != 0) {
895 reportLaunchTimeLocked(SystemClock.uptimeMillis());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896 }
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700897 startTime = 0;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700898 finishLaunchTickingLocked();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700899 }
900 }
901
902 public void windowsVisible() {
903 synchronized(service) {
Craig Mautnerce5f3cb2013-04-22 08:58:54 -0700904 mStackSupervisor.reportActivityVisibleLocked(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
906 ActivityManagerService.TAG, "windowsVisible(): " + this);
907 if (!nowVisible) {
908 nowVisible = true;
Dianne Hackborn50685602011-12-01 12:23:37 -0800909 lastVisibleTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 if (!idle) {
911 // Instead of doing the full stop routine here, let's just
912 // hide any activities we now can, and let them stop when
913 // the normal idle happens.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700914 mStackSupervisor.processStoppingActivitiesLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 } else {
916 // If this activity was already idle, then we now need to
917 // make sure we perform the full stop of any activities
918 // that are waiting to do so. This is because we won't
919 // do that while they are still waiting for this one to
920 // become visible.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700921 final int N = mStackSupervisor.mWaitingVisibleActivities.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 if (N > 0) {
923 for (int i=0; i<N; i++) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700924 ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 r.waitingVisible = false;
926 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
927 ActivityManagerService.TAG,
928 "Was waiting for visible: " + r);
929 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700930 mStackSupervisor.mWaitingVisibleActivities.clear();
Craig Mautnerf3333272013-04-22 10:55:53 -0700931 mStackSupervisor.scheduleIdleLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 }
933 }
934 service.scheduleAppGcsLocked();
935 }
936 }
937 }
938
939 public void windowsGone() {
940 if (ActivityManagerService.DEBUG_SWITCH) Log.v(
941 ActivityManagerService.TAG, "windowsGone(): " + this);
942 nowVisible = false;
943 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700944
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700945 private ActivityRecord getWaitingHistoryRecordLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 // First find the real culprit... if we are waiting
947 // for another app to start, then we have paused dispatching
948 // for this activity.
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700949 ActivityRecord r = this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 if (r.waitingVisible) {
Craig Mautner8f2adcb2014-04-07 22:21:33 +0000951 final ActivityStack stack = mStackSupervisor.getFocusedStack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 // Hmmm, who might we be waiting for?
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700953 r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -0800955 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 }
957 // Both of those null? Fall back to 'this' again
958 if (r == null) {
959 r = this;
960 }
961 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 return r;
964 }
965
Jeff Brownbd181bb2013-09-10 16:44:24 -0700966 public boolean keyDispatchingTimedOut(String reason) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700967 ActivityRecord r;
Michael Wright7dd5bb12013-02-27 17:07:29 -0800968 ProcessRecord anrApp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 synchronized(service) {
Dianne Hackbornad5499d2010-03-29 18:08:45 -0700970 r = getWaitingHistoryRecordLocked();
Michael Wright7dd5bb12013-02-27 17:07:29 -0800971 anrApp = r != null ? r.app : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 }
Jeff Brownbd181bb2013-09-10 16:44:24 -0700973 return service.inputDispatchingTimedOut(anrApp, r, this, false, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800976 /** Returns the key dispatching timeout for this application token. */
977 public long getKeyDispatchingTimeout() {
978 synchronized(service) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700979 ActivityRecord r = getWaitingHistoryRecordLocked();
Michael Wright7dd5bb12013-02-27 17:07:29 -0800980 return ActivityManagerService.getInputDispatchingTimeoutLocked(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 }
982 }
983
984 /**
985 * This method will return true if the activity is either visible, is becoming visible, is
986 * currently pausing, or is resumed.
987 */
988 public boolean isInterestingToUserLocked() {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700989 return visible || nowVisible || state == ActivityState.PAUSING ||
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 state == ActivityState.RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800991 }
992
993 public void setSleeping(boolean _sleeping) {
994 if (sleeping == _sleeping) {
995 return;
996 }
997 if (app != null && app.thread != null) {
998 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800999 app.thread.scheduleSleeping(appToken, _sleeping);
Craig Mautner0eea92c2013-05-16 13:35:39 -07001000 if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
1001 mStackSupervisor.mGoingToSleepActivities.add(this);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001002 }
1003 sleeping = _sleeping;
1004 } catch (RemoteException e) {
Craig Mautner0eea92c2013-05-16 13:35:39 -07001005 Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001006 }
1007 }
1008 }
Craig Mautnerf81b90872013-02-26 13:02:43 -08001009
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001010 static void activityResumedLocked(IBinder token) {
1011 final ActivityRecord r = ActivityRecord.forToken(token);
1012 if (DEBUG_SAVED_STATE) Slog.i(TAG, "Resumed activity; dropping state of: " + r);
1013 r.icicle = null;
1014 r.haveState = false;
1015 }
1016
Craig Mautnerd2328952013-03-05 12:46:26 -08001017 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
1018 final ActivityRecord r = ActivityRecord.forToken(token);
1019 if (r == null) {
1020 return -1;
1021 }
1022 final TaskRecord task = r.task;
1023 switch (task.mActivities.indexOf(r)) {
1024 case -1: return -1;
1025 case 0: return task.taskId;
1026 default: return onlyRoot ? -1 : task.taskId;
1027 }
1028 }
1029
1030 static ActivityRecord isInStackLocked(IBinder token) {
1031 final ActivityRecord r = ActivityRecord.forToken(token);
1032 if (r != null) {
1033 return r.task.stack.isInStackLocked(token);
1034 }
1035 return null;
1036 }
1037
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001038 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -08001039 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
1040 if (r != null) {
1041 return r.task.stack;
1042 }
1043 return null;
1044 }
1045
Craig Mautnerae7ecab2013-09-18 11:48:14 -07001046 private String activityTypeToString(int type) {
1047 switch (type) {
1048 case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE";
1049 case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE";
1050 case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE";
1051 default: return Integer.toString(type);
1052 }
1053 }
1054
Craig Mautnerf81b90872013-02-26 13:02:43 -08001055 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001057 if (stringName != null) {
Craig Mautnerf3333272013-04-22 10:55:53 -07001058 return stringName + " t" + (task == null ? -1 : task.taskId) +
1059 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001060 }
1061 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -08001062 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001063 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -07001064 sb.append(" u");
1065 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07001066 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001067 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -08001068 stringName = sb.toString();
1069 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 }
1071}