blob: 3bd44f5cd3c9ee3f075b29fd58976c0b940d29d0 [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
Jorim Jaggi02886a82016-12-06 09:10:06 -080019import static android.app.ActivityManager.ENABLE_TASK_SNAPSHOTS;
Wale Ogunwale4cea0f52015-12-25 06:30:31 -080020import static android.app.ActivityManager.StackId;
Wale Ogunwaleeb915f22016-10-14 07:18:22 -070021import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080022import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Matthew Ngae1ff4f2016-11-10 15:49:14 -080023import static android.app.ActivityManager.StackId.HOME_STACK_ID;
Wale Ogunwale22e25262016-02-01 10:32:02 -080024import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Winson Chung59fda9e2017-01-20 16:14:51 -080025import static android.app.AppOpsManager.MODE_ALLOWED;
26import static android.app.AppOpsManager.OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080027import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
Andrii Kulian21713ac2016-10-12 22:05:05 -070028import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
29import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT;
30import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
31import static android.content.pm.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080032import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080033import static android.content.pm.ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
34import static android.content.pm.ActivityInfo.FLAG_IMMERSIVE;
35import static android.content.pm.ActivityInfo.FLAG_MULTIPROCESS;
Chong Zhang87761972016-08-22 13:53:24 -070036import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080037import static android.content.pm.ActivityInfo.FLAG_STATE_NOT_NEEDED;
38import static android.content.pm.ActivityInfo.LAUNCH_MULTIPLE;
39import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP;
Wale Ogunwaledf241e92016-10-13 15:14:21 -070040import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
Jorim Jaggicd13d332016-04-27 15:40:20 -070041import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
Wale Ogunwaled26176f2016-01-25 20:04:04 -080042import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE;
Wale Ogunwale72a73e32016-10-13 12:16:39 -070043import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Wale Ogunwaledf241e92016-10-13 15:14:21 -070044import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080045import static android.os.Build.VERSION_CODES.HONEYCOMB;
46import static android.os.Process.SYSTEM_UID;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080047import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION;
Andrii Kulian21713ac2016-10-12 22:05:05 -070048import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE;
49import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SCREENSHOTS;
50import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080051import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH;
52import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_THUMBNAILS;
Andrii Kulian21713ac2016-10-12 22:05:05 -070053import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBILITY;
54import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONFIGURATION;
55import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SAVED_STATE;
56import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SCREENSHOTS;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080057import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES;
58import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH;
59import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_THUMBNAILS;
Andrii Kulian21713ac2016-10-12 22:05:05 -070060import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBILITY;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080061import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
62import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Andrii Kulian21713ac2016-10-12 22:05:05 -070063import static com.android.server.am.ActivityManagerService.TAKE_FULLSCREEN_SCREENSHOTS;
Wale Ogunwale18795a22014-12-03 11:38:33 -080064import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
65
Andrii Kulian21713ac2016-10-12 22:05:05 -070066import android.annotation.NonNull;
Craig Mautner21d24a22014-04-23 11:45:37 -070067import android.app.ActivityManager.TaskDescription;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -070068import android.app.ActivityOptions;
Winson Chung59fda9e2017-01-20 16:14:51 -080069import android.app.AppOpsManager;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080070import android.app.PendingIntent;
Winson Chungc2baac02017-01-11 13:34:47 -080071import android.app.PictureInPictureArgs;
Craig Mautner05d6272ba2013-02-11 09:39:27 -080072import android.app.ResultInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073import android.content.ComponentName;
74import android.content.Intent;
75import android.content.pm.ActivityInfo;
76import android.content.pm.ApplicationInfo;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -070077import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078import android.content.res.Configuration;
79import android.graphics.Bitmap;
Dianne Hackbornd367ca82012-05-07 15:49:39 -070080import android.graphics.Rect;
Winson Chung59fda9e2017-01-20 16:14:51 -080081import android.os.Binder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082import android.os.Bundle;
Andrii Kulian21713ac2016-10-12 22:05:05 -070083import android.os.Debug;
Dianne Hackbornbe707852011-11-11 14:32:10 -080084import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085import android.os.Message;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080086import android.os.PersistableBundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087import android.os.Process;
Dianne Hackborn39792d22010-08-19 18:01:52 -070088import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089import android.os.SystemClock;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080090import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070091import android.os.UserHandle;
Amith Yamasani0af6fa72016-01-17 15:36:19 -080092import android.service.voice.IVoiceInteractionSession;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093import android.util.EventLog;
94import android.util.Log;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070095import android.util.Slog;
Dianne Hackborn0dad3642010-09-09 21:25:35 -070096import android.util.TimeUtils;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -070097import android.view.AppTransitionAnimationSpec;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.IApplicationToken;
Jorim Jaggife762342016-10-13 14:33:27 +020099import android.view.WindowManager.LayoutParams;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700100
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800101import com.android.internal.app.ResolverActivity;
102import com.android.internal.content.ReferrerIntent;
103import com.android.internal.util.XmlUtils;
104import com.android.server.AttributeCache;
105import com.android.server.am.ActivityStack.ActivityState;
106import com.android.server.am.ActivityStackSupervisor.ActivityContainer;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800107import com.android.server.wm.AppWindowContainerController;
108import com.android.server.wm.AppWindowContainerListener;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800109import com.android.server.wm.TaskWindowContainerController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110
Jorim Jaggi02886a82016-12-06 09:10:06 -0800111import org.xmlpull.v1.XmlPullParser;
112import org.xmlpull.v1.XmlPullParserException;
113import org.xmlpull.v1.XmlSerializer;
114
Suprabh Shukla23593142015-11-03 17:31:15 -0800115import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -0700116import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117import java.io.PrintWriter;
118import java.lang.ref.WeakReference;
119import java.util.ArrayList;
Todd Kennedy39bfee52016-02-24 10:28:21 -0800120import java.util.Arrays;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121import java.util.HashSet;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700122import java.util.List;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700123import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124
125/**
126 * An entry in the history stack, representing an activity.
127 */
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800128final class ActivityRecord implements AppWindowContainerListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800129 private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityRecord" : TAG_AM;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700130 private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION;
131 private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE;
132 private static final String TAG_SCREENSHOTS = TAG + POSTFIX_SCREENSHOTS;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700133 private static final String TAG_STATES = TAG + POSTFIX_STATES;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700134 private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH;
135 private static final String TAG_THUMBNAILS = TAG + POSTFIX_THUMBNAILS;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700136 private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY;
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800137
Wale Ogunwale3ab9a272015-03-16 09:55:45 -0700138 private static final boolean SHOW_ACTIVITY_START_TIME = true;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700139 private static final String RECENTS_PACKAGE_NAME = "com.android.systemui.recents";
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700140
Craig Mautner21d24a22014-04-23 11:45:37 -0700141 private static final String ATTR_ID = "id";
142 private static final String TAG_INTENT = "intent";
143 private static final String ATTR_USERID = "user_id";
144 private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle";
145 private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700146 private static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package";
Craig Mautner21d24a22014-04-23 11:45:37 -0700147 private static final String ATTR_RESOLVEDTYPE = "resolved_type";
148 private static final String ATTR_COMPONENTSPECIFIED = "component_specified";
Dianne Hackborn337abb32014-09-24 12:44:29 -0700149 static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_";
Craig Mautner21d24a22014-04-23 11:45:37 -0700150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 final ActivityManagerService service; // owner
Dianne Hackbornbe707852011-11-11 14:32:10 -0800152 final IApplicationToken.Stub appToken; // window manager token
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800153 AppWindowContainerController mWindowContainerController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 final ActivityInfo info; // all about me
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700155 final ApplicationInfo appInfo; // information about activity's app
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800156 final int launchedFromPid; // always the pid who started the activity.
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700157 final int launchedFromUid; // always the uid who started the activity.
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800158 final String launchedFromPackage; // always the package who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -0700159 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 final Intent intent; // the original intent that generated us
161 final ComponentName realActivity; // the intent component, or target of an alias.
162 final String shortComponentName; // the short component name of the intent
163 final String resolvedType; // as per original caller;
164 final String packageName; // the package implementing intent's component
165 final String processName; // process where this component wants to run
166 final String taskAffinity; // as per ActivityInfo.taskAffinity
167 final boolean stateNotNeeded; // As per ActivityInfo.flags
Craig Mautner4addfc52013-06-25 08:05:45 -0700168 boolean fullscreen; // covers the full screen?
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800169 final boolean noDisplay; // activity is not displayed?
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800170 private final boolean componentSpecified; // did caller specify an explicit component?
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700171 final boolean rootVoiceInteraction; // was this the root activity of a voice interaction?
Craig Mautner86d67a42013-05-14 10:34:38 -0700172
173 static final int APPLICATION_ACTIVITY_TYPE = 0;
174 static final int HOME_ACTIVITY_TYPE = 1;
175 static final int RECENTS_ACTIVITY_TYPE = 2;
Craig Mautner2c1faed2013-07-23 12:56:02 -0700176 int mActivityType;
Craig Mautner86d67a42013-05-14 10:34:38 -0700177
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800178 private CharSequence nonLocalizedLabel; // the label information from the package mgr.
179 private int labelRes; // the label information from the package mgr.
180 private int icon; // resource identifier of activity's icon.
181 private int logo; // resource identifier of activity's logo.
182 private int theme; // resource identifier of activity's theme.
183 private int realTheme; // actual theme resource we will use, never 0.
184 private int windowFlags; // custom window flags for preview window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 TaskRecord task; // the task this is in.
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800186 private long createTime = System.currentTimeMillis();
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700187 long displayStartTime; // when we started launching this activity
188 long fullyDrawnStartTime; // when we started launching this activity
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800189 private long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -0800190 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700191 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700192 long pauseTime; // last time we started pausing the activity
193 long launchTickTime; // base time for launch tick messages
Andrii Kulian21713ac2016-10-12 22:05:05 -0700194 private Configuration mLastReportedConfiguration; // configuration activity was last running in
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700195 // Overridden configuration by the activity task
Andrii Kulian1779e612016-10-12 21:58:25 -0700196 // WARNING: Reference points to {@link TaskRecord#getMergedOverrideConfig}, so its internal
197 // state should never be altered directly.
Andrii Kulian21713ac2016-10-12 22:05:05 -0700198 private Configuration mLastReportedOverrideConfiguration;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700199 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700200 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 final String resultWho; // additional identifier for use by resultTo.
202 final int requestCode; // code given by requester (resultTo)
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800203 ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800205 ArrayList<ReferrerIntent> newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700206 ActivityOptions pendingOptions; // most recently given options
George Mount6ba042b2014-07-28 11:12:28 -0700207 ActivityOptions returningOptions; // options that are coming back via convertToTranslucent
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700208 AppTimeTracker appTimeTracker; // set if we are tracking the time in this app/task/activity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700210 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700211 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700212 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 Bundle icicle; // last saved activity state
Craig Mautnera0026042014-04-23 11:45:37 -0700214 PersistableBundle persistentState; // last persistently saved activity state
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 boolean frontOfTask; // is this the root activity of its task?
216 boolean launchFailed; // set if a launched failed, to abort on 2nd try
217 boolean haveState; // have we gotten the last activity state?
218 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700219 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 boolean finishing; // activity in pending finish list?
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800221 boolean deferRelaunchUntilPaused; // relaunch of activity is being deferred until pause is
222 // completed
223 boolean preserveWindowOnDeferredRelaunch; // activity windows are preserved on deferred relaunch
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 int configChangeFlags; // which config values have changed
225 boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 int launchMode; // the launch mode activity attribute.
227 boolean visible; // does this activity's window need to be shown?
Jorim Jaggi241ae102016-11-02 21:57:33 -0700228 boolean visibleIgnoringKeyguard; // is this activity visible, ignoring the fact that Keyguard
229 // might hide this activity?
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800230 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 boolean nowVisible; // is this activity's window visible?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 boolean idle; // has the activity gone idle?
233 boolean hasBeenLaunched;// has this activity ever been launched?
234 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400235 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400236 boolean forceNewConfig; // force re-create with new config next time
Winson Chungc2baac02017-01-11 13:34:47 -0800237 boolean supportsPictureInPictureWhilePausing; // This flag is set by the system to indicate
238 // that the activity can enter picture in picture while pausing (ie. only when another
239 // task is brought to front or started)
240 PictureInPictureArgs pictureInPictureArgs = new PictureInPictureArgs(); // The PiP
Winson Chunga29eb982016-12-14 12:01:27 -0800241 // arguments used when deferring the entering of picture-in-picture.
Dianne Hackborn07981492013-01-28 11:36:23 -0800242 int launchCount; // count of launches since last state
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800243 long lastLaunchTime; // time of last launch of this activity
Ruben Brunke24b9a62016-02-16 21:38:24 -0800244 ComponentName requestedVrComponent; // the requested component for handling VR mode.
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800245 ArrayList<ActivityContainer> mChildContainers = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700247 String stringName; // for caching of toString().
Craig Mautnerde4ef022013-04-07 19:01:33 -0700248
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700249 private boolean inHistory; // are we in the history stack?
Craig Mautnerde4ef022013-04-07 19:01:33 -0700250 final ActivityStackSupervisor mStackSupervisor;
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800251
252 static final int STARTING_WINDOW_NOT_SHOWN = 0;
253 static final int STARTING_WINDOW_SHOWN = 1;
254 static final int STARTING_WINDOW_REMOVED = 2;
255 int mStartingWindowState = STARTING_WINDOW_NOT_SHOWN;
Wale Ogunwale3b232392016-05-13 15:37:13 -0700256 boolean mTaskOverlay = false; // Task is always on-top of other activities in the task.
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800257
Jorim Jaggic2f262b2015-12-07 16:59:10 -0800258 boolean mUpdateTaskThumbnailWhenHidden;
Craig Mautnere0a38842013-12-16 16:14:02 -0800259 ActivityContainer mInitialActivityContainer;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700260
Craig Mautner21d24a22014-04-23 11:45:37 -0700261 TaskDescription taskDescription; // the recents information for this activity
Craig Mautnerbb742462014-07-07 15:28:55 -0700262 boolean mLaunchTaskBehind; // this activity is actively being launched with
263 // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed.
Craig Mautner2fbd7542014-03-21 09:34:07 -0700264
Filip Gruszczynski23493322015-07-29 17:02:59 -0700265 // These configurations are collected from application's resources based on size-sensitive
266 // qualifiers. For example, layout-w800dp will be added to mHorizontalSizeConfigurations as 800
267 // and drawable-sw400dp will be added to both as 400.
268 private int[] mVerticalSizeConfigurations;
269 private int[] mHorizontalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700270 private int[] mSmallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700271
Amith Yamasani0af6fa72016-01-17 15:36:19 -0800272 boolean pendingVoiceInteractionStart; // Waiting for activity-invoked voice session
273 IVoiceInteractionSession voiceSession; // Voice interaction session for this activity
274
Robert Carrd2265122016-08-05 10:25:21 -0700275 // A hint to override the window specified rotation animation, or -1
276 // to use the window specified value. We use this so that
277 // we can select the right animation in the cases of starting
278 // windows, where the app hasn't had time to set a value
279 // on the window.
280 int mRotationAnimationHint = -1;
Robert Carrfd10cd12016-06-29 16:41:50 -0700281
Andrii Kulian21713ac2016-10-12 22:05:05 -0700282 /**
283 * Temp configs used in {@link #ensureActivityConfigurationLocked(int, boolean)}
284 */
285 private final Configuration mTmpGlobalConfig = new Configuration();
286 private final Configuration mTmpTaskConfig = new Configuration();
287
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800288 private static String startingWindowStateToString(int state) {
289 switch (state) {
290 case STARTING_WINDOW_NOT_SHOWN:
291 return "STARTING_WINDOW_NOT_SHOWN";
292 case STARTING_WINDOW_SHOWN:
293 return "STARTING_WINDOW_SHOWN";
294 case STARTING_WINDOW_REMOVED:
295 return "STARTING_WINDOW_REMOVED";
296 default:
297 return "unknown state=" + state;
298 }
299 }
300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700302 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700303 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
304 pw.print(" processName="); pw.println(processName);
305 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Craig Mautnere11f2b72013-04-01 12:37:17 -0700306 pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800307 pw.print(" userId="); pw.println(userId);
308 pw.print(prefix); pw.print("app="); pw.println(app);
309 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700310 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
311 pw.print(" task="); pw.println(task);
312 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700313 pw.print(prefix); pw.print("realActivity=");
314 pw.println(realActivity.flattenToShortString());
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700315 if (appInfo != null) {
316 pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir);
317 if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) {
318 pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir);
319 }
320 pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir);
Todd Kennedy39bfee52016-02-24 10:28:21 -0800321 if (appInfo.splitSourceDirs != null) {
322 pw.print(prefix); pw.print("splitDir=");
323 pw.println(Arrays.toString(appInfo.splitSourceDirs));
324 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800325 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700326 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
327 pw.print(" componentSpecified="); pw.print(componentSpecified);
Craig Mautner86d67a42013-05-14 10:34:38 -0700328 pw.print(" mActivityType="); pw.println(mActivityType);
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700329 if (rootVoiceInteraction) {
330 pw.print(prefix); pw.print("rootVoiceInteraction="); pw.println(rootVoiceInteraction);
331 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800332 pw.print(prefix); pw.print("compat="); pw.print(compat);
333 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
334 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
335 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Andrii Kulian1779e612016-10-12 21:58:25 -0700336 pw.print(prefix); pw.print("mLastReportedConfiguration=");
337 pw.println(mLastReportedConfiguration);
338 pw.print(prefix); pw.print("mLastReportedOverrideConfiguration=");
339 pw.println(mLastReportedOverrideConfiguration);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700340 if (resultTo != null || resultWho != null) {
341 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
342 pw.print(" resultWho="); pw.print(resultWho);
343 pw.print(" resultCode="); pw.println(requestCode);
344 }
Craig Mautner29c58ca2014-10-14 16:17:06 -0700345 if (taskDescription != null) {
346 final String iconFilename = taskDescription.getIconFilename();
347 if (iconFilename != null || taskDescription.getLabel() != null ||
348 taskDescription.getPrimaryColor() != 0) {
349 pw.print(prefix); pw.print("taskDescription:");
350 pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename());
351 pw.print(" label=\""); pw.print(taskDescription.getLabel());
352 pw.print("\"");
353 pw.print(" color=");
354 pw.println(Integer.toHexString(taskDescription.getPrimaryColor()));
355 }
356 if (iconFilename == null && taskDescription.getIcon() != null) {
357 pw.print(prefix); pw.println("taskDescription contains Bitmap");
358 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700359 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700360 if (results != null) {
361 pw.print(prefix); pw.print("results="); pw.println(results);
362 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700363 if (pendingResults != null && pendingResults.size() > 0) {
364 pw.print(prefix); pw.println("Pending Results:");
365 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
366 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
367 pw.print(prefix); pw.print(" - ");
368 if (pir == null) {
369 pw.println("null");
370 } else {
371 pw.println(pir);
372 pir.dump(pw, prefix + " ");
373 }
374 }
375 }
376 if (newIntents != null && newIntents.size() > 0) {
377 pw.print(prefix); pw.println("Pending New Intents:");
378 for (int i=0; i<newIntents.size(); i++) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800379 Intent intent = newIntents.get(i);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700380 pw.print(prefix); pw.print(" - ");
381 if (intent == null) {
382 pw.println("null");
383 } else {
384 pw.println(intent.toShortString(false, true, false, true));
385 }
386 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700387 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700388 if (pendingOptions != null) {
389 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
390 }
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700391 if (appTimeTracker != null) {
392 appTimeTracker.dumpWithHeader(pw, prefix, false);
393 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700394 if (uriPermissions != null) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700395 uriPermissions.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700396 }
397 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800398 pw.print(" launchCount="); pw.print(launchCount);
399 pw.print(" lastLaunchTime=");
400 if (lastLaunchTime == 0) pw.print("0");
401 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
402 pw.println();
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700403 pw.print(prefix); pw.print("haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700404 pw.print(" icicle="); pw.println(icicle);
405 pw.print(prefix); pw.print("state="); pw.print(state);
406 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700407 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700408 pw.print(" finishing="); pw.println(finishing);
409 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
410 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700411 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800412 pw.print(" sleeping="); pw.print(sleeping);
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800413 pw.print(" idle="); pw.print(idle);
414 pw.print(" mStartingWindowState=");
415 pw.println(startingWindowStateToString(mStartingWindowState));
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800416 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
417 pw.print(" noDisplay="); pw.print(noDisplay);
418 pw.print(" immersive="); pw.print(immersive);
419 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800420 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400421 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700422 pw.print(prefix); pw.print("mActivityType=");
423 pw.println(activityTypeToString(mActivityType));
Ruben Brunke24b9a62016-02-16 21:38:24 -0800424 if (requestedVrComponent != null) {
425 pw.print(prefix);
426 pw.print("requestedVrComponent=");
427 pw.println(requestedVrComponent);
428 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700429 if (displayStartTime != 0 || startTime != 0) {
430 pw.print(prefix); pw.print("displayStartTime=");
431 if (displayStartTime == 0) pw.print("0");
432 else TimeUtils.formatDuration(displayStartTime, now, pw);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700433 pw.print(" startTime=");
434 if (startTime == 0) pw.print("0");
435 else TimeUtils.formatDuration(startTime, now, pw);
436 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700437 }
Craig Mautner8c14c152015-01-15 17:32:07 -0800438 final boolean waitingVisible = mStackSupervisor.mWaitingVisibleActivities.contains(this);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800439 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700440 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800441 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700442 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700443 if (lastVisibleTime == 0) pw.print("0");
444 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
445 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700446 }
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800447 if (deferRelaunchUntilPaused || configChangeFlags != 0) {
448 pw.print(prefix); pw.print("deferRelaunchUntilPaused="); pw.print(deferRelaunchUntilPaused);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700449 pw.print(" configChangeFlags=");
450 pw.println(Integer.toHexString(configChangeFlags));
451 }
452 if (connections != null) {
453 pw.print(prefix); pw.print("connections="); pw.println(connections);
454 }
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800455 if (info != null) {
456 pw.println(prefix + "resizeMode=" + ActivityInfo.resizeModeToString(info.resizeMode));
457 }
Winson Chungc2baac02017-01-11 13:34:47 -0800458 pw.println(prefix + "supportsPictureInPictureWhilePausing: "
459 + supportsPictureInPictureWhilePausing);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460 }
461
Andrii Kulian21713ac2016-10-12 22:05:05 -0700462 private boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700463 return crossesSizeThreshold(mHorizontalSizeConfigurations, firstDp, secondDp);
464 }
465
Andrii Kulian21713ac2016-10-12 22:05:05 -0700466 private boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700467 return crossesSizeThreshold(mVerticalSizeConfigurations, firstDp, secondDp);
468 }
469
Andrii Kulian21713ac2016-10-12 22:05:05 -0700470 private boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700471 return crossesSizeThreshold(mSmallestSizeConfigurations, firstDp, secondDp);
472 }
473
Filip Gruszczynski23493322015-07-29 17:02:59 -0700474 /**
475 * The purpose of this method is to decide whether the activity needs to be relaunched upon
476 * changing its size. In most cases the activities don't need to be relaunched, if the resize
477 * is small, all the activity content has to do is relayout itself within new bounds. There are
478 * cases however, where the activity's content would be completely changed in the new size and
479 * the full relaunch is required.
480 *
481 * The activity will report to us vertical and horizontal thresholds after which a relaunch is
482 * required. These thresholds are collected from the application resource qualifiers. For
483 * example, if application has layout-w600dp resource directory, then it needs a relaunch when
484 * we resize from width of 650dp to 550dp, as it crosses the 600dp threshold. However, if
485 * it resizes width from 620dp to 700dp, it won't be relaunched as it stays on the same side
486 * of the threshold.
487 */
488 private static boolean crossesSizeThreshold(int[] thresholds, int firstDp,
489 int secondDp) {
490 if (thresholds == null) {
491 return false;
492 }
493 for (int i = thresholds.length - 1; i >= 0; i--) {
494 final int threshold = thresholds[i];
495 if ((firstDp < threshold && secondDp >= threshold)
496 || (firstDp >= threshold && secondDp < threshold)) {
497 return true;
498 }
499 }
500 return false;
501 }
502
Andrii Kulian21713ac2016-10-12 22:05:05 -0700503 void setSizeConfigurations(int[] horizontalSizeConfiguration,
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700504 int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700505 mHorizontalSizeConfigurations = horizontalSizeConfiguration;
506 mVerticalSizeConfigurations = verticalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700507 mSmallestSizeConfigurations = smallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700508 }
509
Andrii Kulian21713ac2016-10-12 22:05:05 -0700510 private void scheduleConfigurationChanged(Configuration config, boolean reportToActivity) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800511 if (app == null || app.thread == null) {
512 return;
513 }
514 try {
515 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + this + " " +
Adam Lesinskibad43fc2016-07-19 13:35:01 -0700516 "reportToActivity=" + reportToActivity + " and config: " + config);
Chong Zhang6be533e2016-06-17 16:24:21 -0700517
Andrii Kulian1779e612016-10-12 21:58:25 -0700518 app.thread.scheduleActivityConfigurationChanged(appToken, new Configuration(config),
519 reportToActivity);
Wale Ogunwale22e25262016-02-01 10:32:02 -0800520 } catch (RemoteException e) {
521 // If process died, whatever.
522 }
523 }
524
Andrii Kulian933076d2016-03-29 17:04:42 -0700525 void scheduleMultiWindowModeChanged() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700526 if (task == null || task.getStack() == null || app == null || app.thread == null) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800527 return;
528 }
529 try {
530 // An activity is considered to be in multi-window mode if its task isn't fullscreen.
Andrii Kulian933076d2016-03-29 17:04:42 -0700531 app.thread.scheduleMultiWindowModeChanged(appToken, !task.mFullscreen);
Wale Ogunwale22e25262016-02-01 10:32:02 -0800532 } catch (Exception e) {
533 // If process died, I don't care.
534 }
535 }
536
Andrii Kulian933076d2016-03-29 17:04:42 -0700537 void schedulePictureInPictureModeChanged() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700538 if (task == null || task.getStack() == null || app == null || app.thread == null) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800539 return;
540 }
541 try {
Andrii Kulian933076d2016-03-29 17:04:42 -0700542 app.thread.schedulePictureInPictureModeChanged(
Andrii Kulian02b7a832016-10-06 23:11:56 -0700543 appToken, task.getStackId() == PINNED_STACK_ID);
Wale Ogunwale22e25262016-02-01 10:32:02 -0800544 } catch (Exception e) {
545 // If process died, no one cares.
Filip Gruszczynskica664812015-12-04 12:43:36 -0800546 }
547 }
548
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800549 boolean isFreeform() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700550 return task != null && task.getStackId() == FREEFORM_WORKSPACE_STACK_ID;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800551 }
552
Dianne Hackbornbe707852011-11-11 14:32:10 -0800553 static class Token extends IApplicationToken.Stub {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700554 private final WeakReference<ActivityRecord> weakActivity;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800555
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800556 Token(ActivityRecord activity) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800557 weakActivity = new WeakReference<>(activity);
Wale Ogunwale7d701172015-03-11 15:36:30 -0700558 }
559
Andrii Kulian21713ac2016-10-12 22:05:05 -0700560 private static ActivityRecord tokenToActivityRecordLocked(Token token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700561 if (token == null) {
562 return null;
563 }
564 ActivityRecord r = token.weakActivity.get();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700565 if (r == null || r.getStack() == null) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700566 return null;
567 }
568 return r;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800569 }
570
Craig Mautnerde4ef022013-04-07 19:01:33 -0700571 @Override
Dianne Hackbornbe707852011-11-11 14:32:10 -0800572 public String toString() {
573 StringBuilder sb = new StringBuilder(128);
574 sb.append("Token{");
575 sb.append(Integer.toHexString(System.identityHashCode(this)));
576 sb.append(' ');
577 sb.append(weakActivity.get());
578 sb.append('}');
579 return sb.toString();
580 }
581 }
582
Wale Ogunwale7d701172015-03-11 15:36:30 -0700583 static ActivityRecord forTokenLocked(IBinder token) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800584 try {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700585 return Token.tokenToActivityRecordLocked((Token)token);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800586 } catch (ClassCastException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800587 Slog.w(TAG, "Bad activity token: " + token, e);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800588 return null;
589 }
590 }
591
Chong Zhang85ee6542015-10-02 13:36:38 -0700592 boolean isResolverActivity() {
593 return ResolverActivity.class.getName().equals(realActivity.getClassName());
Craig Mautnerac6f8432013-07-17 13:24:59 -0700594 }
595
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800596 ActivityRecord(ActivityManagerService _service, ProcessRecord _caller, int _launchedFromPid,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800597 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700599 ActivityRecord _resultTo, String _resultWho, int _reqCode,
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700600 boolean _componentSpecified, boolean _rootVoiceInteraction,
601 ActivityStackSupervisor supervisor,
Wale Ogunwale1affbbc2016-05-01 09:03:52 -0700602 ActivityContainer container, ActivityOptions options, ActivityRecord sourceRecord) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 service = _service;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800604 appToken = new Token(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 info = aInfo;
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800606 launchedFromPid = _launchedFromPid;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800608 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700609 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 intent = _intent;
611 shortComponentName = _intent.getComponent().flattenToShortString();
612 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800613 componentSpecified = _componentSpecified;
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700614 rootVoiceInteraction = _rootVoiceInteraction;
Andrii Kulian1779e612016-10-12 21:58:25 -0700615 mLastReportedConfiguration = new Configuration(_configuration);
616 mLastReportedOverrideConfiguration = new Configuration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617 resultTo = _resultTo;
618 resultWho = _resultWho;
619 requestCode = _reqCode;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700620 state = ActivityState.INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 frontOfTask = false;
622 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700624 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 finishing = false;
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800626 deferRelaunchUntilPaused = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 keysPaused = false;
628 inHistory = false;
Chong Zhanga48ef662015-08-18 19:21:47 -0700629 visible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 nowVisible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 idle = false;
632 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700633 mStackSupervisor = supervisor;
Craig Mautnere0a38842013-12-16 16:14:02 -0800634 mInitialActivityContainer = container;
Robert Carr0f5d7532016-10-17 16:39:17 -0700635
636 mRotationAnimationHint = aInfo.rotationAnimation;
637
Craig Mautner233ceee2014-05-09 17:05:11 -0700638 if (options != null) {
Chong Zhang280d3322015-11-03 17:27:26 -0800639 pendingOptions = options;
Craig Mautnerbb742462014-07-07 15:28:55 -0700640 mLaunchTaskBehind = pendingOptions.getLaunchTaskBehind();
Robert Carr0f5d7532016-10-17 16:39:17 -0700641
642 final int rotationAnimation = pendingOptions.getRotationAnimationHint();
643 // Only override manifest supplied option if set.
644 if (rotationAnimation >= 0) {
645 mRotationAnimationHint = rotationAnimation;
646 }
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700647 PendingIntent usageReport = pendingOptions.getUsageTimeReport();
648 if (usageReport != null) {
649 appTimeTracker = new AppTimeTracker(usageReport);
650 }
Craig Mautner233ceee2014-05-09 17:05:11 -0700651 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800653 // This starts out true, since the initial state of an activity is that we have everything,
654 // and we shouldn't never consider it lacking in state to be removed if it dies.
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700655 haveState = true;
656
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800657 // If the class name in the intent doesn't match that of the target, this is
658 // probably an alias. We have to create a new ComponentName object to keep track
659 // of the real activity name, so that FLAG_ACTIVITY_CLEAR_TOP is handled properly.
660 if (aInfo.targetActivity == null
661 || (aInfo.targetActivity.equals(_intent.getComponent().getClassName())
662 && (aInfo.launchMode == LAUNCH_MULTIPLE
663 || aInfo.launchMode == LAUNCH_SINGLE_TOP))) {
664 realActivity = _intent.getComponent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 } else {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800666 realActivity = new ComponentName(aInfo.packageName, aInfo.targetActivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800668 taskAffinity = aInfo.taskAffinity;
669 stateNotNeeded = (aInfo.flags & FLAG_STATE_NOT_NEEDED) != 0;
670 appInfo = aInfo.applicationInfo;
671 nonLocalizedLabel = aInfo.nonLocalizedLabel;
672 labelRes = aInfo.labelRes;
673 if (nonLocalizedLabel == null && labelRes == 0) {
674 ApplicationInfo app = aInfo.applicationInfo;
675 nonLocalizedLabel = app.nonLocalizedLabel;
676 labelRes = app.labelRes;
677 }
678 icon = aInfo.getIconResource();
679 logo = aInfo.getLogoResource();
680 theme = aInfo.getThemeResource();
681 realTheme = theme;
682 if (realTheme == 0) {
683 realTheme = aInfo.applicationInfo.targetSdkVersion < HONEYCOMB
684 ? android.R.style.Theme : android.R.style.Theme_Holo;
685 }
686 if ((aInfo.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
687 windowFlags |= LayoutParams.FLAG_HARDWARE_ACCELERATED;
688 }
689 if ((aInfo.flags & FLAG_MULTIPROCESS) != 0 && _caller != null
690 && (aInfo.applicationInfo.uid == SYSTEM_UID
691 || aInfo.applicationInfo.uid == _caller.info.uid)) {
692 processName = _caller.processName;
693 } else {
694 processName = aInfo.processName;
695 }
696
697 if ((aInfo.flags & FLAG_EXCLUDE_FROM_RECENTS) != 0) {
698 intent.addFlags(FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
699 }
700
701 packageName = aInfo.applicationInfo.packageName;
702 launchMode = aInfo.launchMode;
703
704 AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
705 realTheme, com.android.internal.R.styleable.Window, userId);
706 final boolean translucent = ent != null && (ent.array.getBoolean(
707 com.android.internal.R.styleable.Window_windowIsTranslucent, false)
708 || (!ent.array.hasValue(
709 com.android.internal.R.styleable.Window_windowIsTranslucent)
710 && ent.array.getBoolean(
711 com.android.internal.R.styleable.Window_windowSwipeToDismiss,
712 false)));
713 fullscreen = ent != null && !ent.array.getBoolean(
714 com.android.internal.R.styleable.Window_windowIsFloating, false) && !translucent;
715 noDisplay = ent != null && ent.array.getBoolean(
716 com.android.internal.R.styleable.Window_windowNoDisplay, false);
717
718 setActivityType(_componentSpecified, _launchedFromUid, _intent, sourceRecord);
719
720 immersive = (aInfo.flags & FLAG_IMMERSIVE) != 0;
721
722 requestedVrComponent = (aInfo.requestedVrComponent == null) ?
723 null : ComponentName.unflattenFromString(aInfo.requestedVrComponent);
724 }
725
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800726 AppWindowContainerController getWindowContainerController() {
727 return mWindowContainerController;
728 }
729
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800730 void createWindowContainer() {
731 if (mWindowContainerController != null) {
732 throw new IllegalArgumentException("Window container=" + mWindowContainerController
733 + " already created for r=" + this);
734
735 }
736
737 inHistory = true;
738
739 task.updateOverrideConfigurationFromLaunchBounds();
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800740 final TaskWindowContainerController taskController = task.getWindowContainerController();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800741
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800742 mWindowContainerController = new AppWindowContainerController(taskController, appToken,
743 this, Integer.MAX_VALUE /* add on top */, info.screenOrientation, fullscreen,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800744 (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, info.configChanges,
745 task.voiceSession != null, mLaunchTaskBehind, isAlwaysFocusable(),
746 appInfo.targetSdkVersion, mRotationAnimationHint,
747 ActivityManagerService.getInputDispatchingTimeoutLocked(this) * 1000000L);
748
749 task.addActivityToTop(this);
750
751 onOverrideConfigurationSent();
752 }
753
754 void removeWindowContainer() {
755 mWindowContainerController.removeContainer(getDisplayId());
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800756 mWindowContainerController = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 }
758
Wale Ogunwale1affbbc2016-05-01 09:03:52 -0700759 private boolean isHomeIntent(Intent intent) {
760 return Intent.ACTION_MAIN.equals(intent.getAction())
761 && intent.hasCategory(Intent.CATEGORY_HOME)
762 && intent.getCategories().size() == 1
763 && intent.getData() == null
764 && intent.getType() == null;
765 }
766
Chong Zhangad24f962016-08-25 12:12:33 -0700767 static boolean isMainIntent(Intent intent) {
768 return Intent.ACTION_MAIN.equals(intent.getAction())
769 && intent.hasCategory(Intent.CATEGORY_LAUNCHER)
770 && intent.getCategories().size() == 1
771 && intent.getData() == null
772 && intent.getType() == null;
773 }
774
Wale Ogunwale1affbbc2016-05-01 09:03:52 -0700775 private boolean canLaunchHomeActivity(int uid, ActivityRecord sourceRecord) {
776 if (uid == Process.myUid() || uid == 0) {
777 // System process can launch home activity.
778 return true;
779 }
780 // Resolver activity can launch home activity.
781 return sourceRecord != null && sourceRecord.isResolverActivity();
782 }
783
784 private void setActivityType(boolean componentSpecified,
785 int launchedFromUid, Intent intent, ActivityRecord sourceRecord) {
786 if ((!componentSpecified || canLaunchHomeActivity(launchedFromUid, sourceRecord))
787 && isHomeIntent(intent) && !isResolverActivity()) {
788 // This sure looks like a home activity!
789 mActivityType = HOME_ACTIVITY_TYPE;
Wale Ogunwaledf241e92016-10-13 15:14:21 -0700790
791 if (info.resizeMode == RESIZE_MODE_FORCE_RESIZEABLE
792 || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) {
793 // We only allow home activities to be resizeable if they explicitly requested it.
794 info.resizeMode = RESIZE_MODE_UNRESIZEABLE;
795 }
Wale Ogunwale1affbbc2016-05-01 09:03:52 -0700796 } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) {
797 mActivityType = RECENTS_ACTIVITY_TYPE;
798 } else {
799 mActivityType = APPLICATION_ACTIVITY_TYPE;
800 }
801 }
802
Craig Mautnera228ae92014-07-09 05:44:55 -0700803 void setTask(TaskRecord newTask, TaskRecord taskToAffiliateWith) {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700804 if (task != null && task.removeActivity(this) && task != newTask
805 && task.getStack() != null) {
806 task.getStack().removeTask(task, "setTask");
Craig Mautnerde4ef022013-04-07 19:01:33 -0700807 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700808 task = newTask;
Craig Mautnera228ae92014-07-09 05:44:55 -0700809 setTaskToAffiliateWith(taskToAffiliateWith);
810 }
811
812 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
813 if (taskToAffiliateWith != null &&
814 launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE &&
815 launchMode != ActivityInfo.LAUNCH_SINGLE_TASK) {
816 task.setTaskToAffiliateWith(taskToAffiliateWith);
817 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700818 }
819
Andrii Kulian02b7a832016-10-06 23:11:56 -0700820 /**
821 * @return Stack value from current task, null if there is no task.
822 */
823 ActivityStack getStack() {
824 return task != null ? task.getStack() : null;
825 }
826
Craig Mautner5eda9b32013-07-02 11:58:16 -0700827 boolean changeWindowTranslucency(boolean toOpaque) {
828 if (fullscreen == toOpaque) {
829 return false;
830 }
Craig Mautner4addfc52013-06-25 08:05:45 -0700831
Craig Mautner5eda9b32013-07-02 11:58:16 -0700832 // Keep track of the number of fullscreen activities in this task.
833 task.numFullscreen += toOpaque ? +1 : -1;
834
835 fullscreen = toOpaque;
836 return true;
Craig Mautner4addfc52013-06-25 08:05:45 -0700837 }
838
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700839 void takeFromHistory() {
840 if (inHistory) {
841 inHistory = false;
842 if (task != null && !finishing) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800843 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700844 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700845 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700846 }
847 }
848
849 boolean isInHistory() {
850 return inHistory;
851 }
852
Wale Ogunwale7d701172015-03-11 15:36:30 -0700853 boolean isInStackLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700854 final ActivityStack stack = getStack();
855 return stack != null && stack.isInStackLocked(this) != null;
Wale Ogunwale7d701172015-03-11 15:36:30 -0700856 }
857
Craig Mautner86d67a42013-05-14 10:34:38 -0700858 boolean isHomeActivity() {
859 return mActivityType == HOME_ACTIVITY_TYPE;
860 }
861
862 boolean isRecentsActivity() {
863 return mActivityType == RECENTS_ACTIVITY_TYPE;
864 }
865
866 boolean isApplicationActivity() {
867 return mActivityType == APPLICATION_ACTIVITY_TYPE;
868 }
869
Craig Mautner21d24a22014-04-23 11:45:37 -0700870 boolean isPersistable() {
Craig Mautner43e52ed2014-06-16 17:18:52 -0700871 return (info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY ||
872 info.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS) &&
873 (intent == null ||
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800874 (intent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
Craig Mautner21d24a22014-04-23 11:45:37 -0700875 }
876
Wale Ogunwale4cea0f52015-12-25 06:30:31 -0800877 boolean isFocusable() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700878 return StackId.canReceiveKeys(task.getStackId()) || isAlwaysFocusable();
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800879 }
880
881 boolean isResizeable() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -0700882 return ActivityInfo.isResizeableMode(info.resizeMode);
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800883 }
884
Wale Ogunwale513346d2016-01-27 10:55:01 -0800885 boolean isResizeableOrForced() {
886 return !isHomeActivity() && (isResizeable() || service.mForceResizableActivities);
887 }
888
Jorim Jaggicd13d332016-04-27 15:40:20 -0700889 boolean isNonResizableOrForced() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -0700890 return info.resizeMode != RESIZE_MODE_RESIZEABLE
Wale Ogunwale72a73e32016-10-13 12:16:39 -0700891 && info.resizeMode != RESIZE_MODE_RESIZEABLE_AND_PIPABLE
892 && info.resizeMode != RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Jorim Jaggicd13d332016-04-27 15:40:20 -0700893 }
894
Winson Chunge6308042016-10-31 09:24:01 -0700895 /**
896 * @return whether this activity's resize mode supports PIP.
897 */
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800898 boolean supportsPictureInPicture() {
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800899 return !isHomeActivity() && info.resizeMode == RESIZE_MODE_RESIZEABLE_AND_PIPABLE;
900 }
901
Winson Chunge6308042016-10-31 09:24:01 -0700902 /**
Winson Chungc2baac02017-01-11 13:34:47 -0800903 * @return whether this activity is currently allowed to enter PIP, throwing an exception if
904 * the activity is not currently visible.
Winson Chunge6308042016-10-31 09:24:01 -0700905 */
Winson Chungc2baac02017-01-11 13:34:47 -0800906 boolean checkEnterPictureInPictureState(String caller) {
907 boolean isKeyguardLocked = service.isKeyguardLocked();
908 boolean hasPinnedStack = mStackSupervisor.getStack(PINNED_STACK_ID) != null;
909 switch (state) {
910 case RESUMED:
911 // When visible, allow entering PiP if not on the lockscreen. If there is another
912 // PiP activity, the logic to handle that comes later in enterPictureInPictureMode()
913 return !isKeyguardLocked;
914 case PAUSING:
915 case PAUSED:
916 // When pausing, only allow enter PiP if not on the lockscreen and there is not
917 // already an existing PiP activity
Winson Chung59fda9e2017-01-20 16:14:51 -0800918 return !isKeyguardLocked && !hasPinnedStack && supportsPictureInPictureWhilePausing
919 && checkEnterPictureInPictureOnHideAppOpsState();
Winson Chungc2baac02017-01-11 13:34:47 -0800920 case STOPPING:
921 // When stopping in a valid state, then only allow enter PiP as in the pause state.
922 // Otherwise, fall through to throw an exception if the caller is trying to enter
923 // PiP in an invalid stopping state.
924 if (supportsPictureInPictureWhilePausing) {
Winson Chung59fda9e2017-01-20 16:14:51 -0800925 return !isKeyguardLocked && !hasPinnedStack
926 && checkEnterPictureInPictureOnHideAppOpsState();
Winson Chungc2baac02017-01-11 13:34:47 -0800927 }
928 default:
929 throw new IllegalStateException(caller
930 + ": Current activity is not visible (state=" + state.name() + ") "
931 + "r=" + this);
Winson Chungb5c41b72016-12-07 15:00:47 -0800932 }
Winson Chunge6308042016-10-31 09:24:01 -0700933 }
934
Winson Chung59fda9e2017-01-20 16:14:51 -0800935 /**
936 * @return Whether AppOps allows this package to enter picture-in-picture when it is hidden.
937 */
938 private boolean checkEnterPictureInPictureOnHideAppOpsState() {
939 try {
940 return service.getAppOpsService().checkOperation(OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE,
941 appInfo.uid, packageName) == MODE_ALLOWED;
942 } catch (RemoteException e) {
943 // Local call
944 }
945 return false;
946 }
947
Wale Ogunwale513346d2016-01-27 10:55:01 -0800948 boolean canGoInDockedStack() {
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700949 return !isHomeActivity() && isResizeableOrForced();
Wale Ogunwale513346d2016-01-27 10:55:01 -0800950 }
951
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800952 boolean isAlwaysFocusable() {
953 return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0;
Wale Ogunwale4cea0f52015-12-25 06:30:31 -0800954 }
955
Jorim Jaggife762342016-10-13 14:33:27 +0200956 /**
957 * @return true if the activity contains windows that have
958 * {@link LayoutParams#FLAG_SHOW_WHEN_LOCKED} set
959 */
960 boolean hasShowWhenLockedWindows() {
961 return service.mWindowManager.containsShowWhenLockedWindow(appToken);
962 }
963
964 /**
965 * @return true if the activity contains windows that have
966 * {@link LayoutParams#FLAG_DISMISS_KEYGUARD} set
967 */
968 boolean hasDismissKeyguardWindows() {
969 return service.mWindowManager.containsDismissKeyguardWindow(appToken);
970 }
971
Wale Ogunwale7d701172015-03-11 15:36:30 -0700972 void makeFinishingLocked() {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800973 if (!finishing) {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700974 final ActivityStack stack = getStack();
975 if (stack != null && this == stack.getVisibleBehindActivity()) {
Jose Lima34ff4922014-08-18 15:19:41 -0700976 // A finishing activity should not remain as visible in the background
977 mStackSupervisor.requestVisibleBehindLocked(this, false);
978 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800979 finishing = true;
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700980 if (stopped) {
981 clearOptionsLocked();
982 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700983
984 if (service != null) {
985 service.mTaskChangeNotificationController.notifyTaskStackChanged();
986 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800987 }
988 }
989
Dianne Hackborn7e269642010-08-25 19:50:20 -0700990 UriPermissionOwner getUriPermissionsLocked() {
991 if (uriPermissions == null) {
992 uriPermissions = new UriPermissionOwner(service, this);
993 }
994 return uriPermissions;
995 }
996
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700997 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 int requestCode, int resultCode,
999 Intent resultData) {
1000 ActivityResult r = new ActivityResult(from, resultWho,
John Spurlock8a985d22014-02-25 09:40:05 -05001001 requestCode, resultCode, resultData);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001002 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001003 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 }
1005 results.add(r);
1006 }
1007
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001008 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 int requestCode) {
1010 if (results != null) {
1011 for (int i=results.size()-1; i>=0; i--) {
1012 ActivityResult r = (ActivityResult)results.get(i);
1013 if (r.mFrom != from) continue;
1014 if (r.mResultWho == null) {
1015 if (resultWho != null) continue;
1016 } else {
1017 if (!r.mResultWho.equals(resultWho)) continue;
1018 }
1019 if (r.mRequestCode != requestCode) continue;
1020
1021 results.remove(i);
1022 }
1023 }
1024 }
1025
Andrii Kulian21713ac2016-10-12 22:05:05 -07001026 private void addNewIntentLocked(ReferrerIntent intent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001027 if (newIntents == null) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001028 newIntents = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001029 }
1030 newIntents.add(intent);
1031 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001032
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001033 /**
1034 * Deliver a new Intent to an existing activity, so that its onNewIntent()
1035 * method will be called at the proper time.
1036 */
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001037 final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) {
Dianne Hackborn514074f2013-02-11 10:52:46 -08001038 // The activity now gets access to the data associated with this Intent.
1039 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
Nicolas Prevotc6cf95c2014-05-29 11:30:36 +01001040 intent, getUriPermissionsLocked(), userId);
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001041 final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
Craig Mautner86d67a42013-05-14 10:34:38 -07001042 boolean unsent = true;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001043 final ActivityStack stack = getStack();
Wale Ogunwale826c7062016-09-13 08:25:54 -07001044 final boolean isTopActivityInStack =
1045 stack != null && stack.topRunningActivityLocked() == this;
1046 final boolean isTopActivityWhileSleeping =
1047 service.isSleepingLocked() && isTopActivityInStack;
Wale Ogunwale826c7062016-09-13 08:25:54 -07001048
1049 // We want to immediately deliver the intent to the activity if:
Wale Ogunwale03f7e9e2016-09-22 09:04:09 -07001050 // - It is currently resumed or paused. i.e. it is currently visible to the user and we want
1051 // the user to see the visual effects caused by the intent delivery now.
Wale Ogunwale826c7062016-09-13 08:25:54 -07001052 // - The device is sleeping and it is the top activity behind the lock screen (b/6700897).
Wale Ogunwale03f7e9e2016-09-22 09:04:09 -07001053 if ((state == ActivityState.RESUMED || state == ActivityState.PAUSED
1054 || isTopActivityWhileSleeping) && app != null && app.thread != null) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001055 try {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001056 ArrayList<ReferrerIntent> ar = new ArrayList<>(1);
1057 ar.add(rintent);
Wale Ogunwale826c7062016-09-13 08:25:54 -07001058 app.thread.scheduleNewIntent(
Wale Ogunwale03f7e9e2016-09-22 09:04:09 -07001059 ar, appToken, state == ActivityState.PAUSED /* andPause */);
Craig Mautner86d67a42013-05-14 10:34:38 -07001060 unsent = false;
Dianne Hackborn39792d22010-08-19 18:01:52 -07001061 } catch (RemoteException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001062 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn39792d22010-08-19 18:01:52 -07001063 } catch (NullPointerException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001064 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001065 }
1066 }
Craig Mautner86d67a42013-05-14 10:34:38 -07001067 if (unsent) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001068 addNewIntentLocked(rintent);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001069 }
1070 }
1071
Dianne Hackborn9622ca42012-10-23 18:56:33 -07001072 void updateOptionsLocked(ActivityOptions options) {
1073 if (options != null) {
1074 if (pendingOptions != null) {
1075 pendingOptions.abort();
1076 }
1077 pendingOptions = options;
1078 }
1079 }
1080
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001081 void applyOptionsLocked() {
George Mount2c92c972014-03-20 09:38:23 -07001082 if (pendingOptions != null
1083 && pendingOptions.getAnimationType() != ActivityOptions.ANIM_SCENE_TRANSITION) {
Michael Jurka21385cd2012-05-03 10:57:31 -07001084 final int animationType = pendingOptions.getAnimationType();
1085 switch (animationType) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001086 case ActivityOptions.ANIM_CUSTOM:
1087 service.mWindowManager.overridePendingAppTransition(
1088 pendingOptions.getPackageName(),
1089 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -07001090 pendingOptions.getCustomExitResId(),
1091 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001092 break;
Chet Haase10e23ab2015-02-11 15:08:38 -08001093 case ActivityOptions.ANIM_CLIP_REVEAL:
1094 service.mWindowManager.overridePendingAppTransitionClipReveal(
1095 pendingOptions.getStartX(), pendingOptions.getStartY(),
1096 pendingOptions.getWidth(), pendingOptions.getHeight());
1097 if (intent.getSourceBounds() == null) {
1098 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1099 pendingOptions.getStartY(),
1100 pendingOptions.getStartX()+pendingOptions.getWidth(),
1101 pendingOptions.getStartY()+pendingOptions.getHeight()));
1102 }
1103 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001104 case ActivityOptions.ANIM_SCALE_UP:
1105 service.mWindowManager.overridePendingAppTransitionScaleUp(
1106 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001107 pendingOptions.getWidth(), pendingOptions.getHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001108 if (intent.getSourceBounds() == null) {
1109 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1110 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001111 pendingOptions.getStartX()+pendingOptions.getWidth(),
1112 pendingOptions.getStartY()+pendingOptions.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001113 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001114 break;
Michael Jurka832cb222012-04-13 09:32:47 -07001115 case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
1116 case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
1117 boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001118 service.mWindowManager.overridePendingAppTransitionThumb(
1119 pendingOptions.getThumbnail(),
1120 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -07001121 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -07001122 scaleUp);
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001123 if (intent.getSourceBounds() == null) {
1124 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1125 pendingOptions.getStartY(),
1126 pendingOptions.getStartX()
1127 + pendingOptions.getThumbnail().getWidth(),
1128 pendingOptions.getStartY()
1129 + pendingOptions.getThumbnail().getHeight()));
1130 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001131 break;
Winson Chunga4ccb862014-08-22 15:26:27 -07001132 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP:
1133 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001134 final AppTransitionAnimationSpec[] specs = pendingOptions.getAnimSpecs();
1135 if (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN
1136 && specs != null) {
1137 service.mWindowManager.overridePendingAppTransitionMultiThumb(
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001138 specs, pendingOptions.getOnAnimationStartListener(),
1139 pendingOptions.getAnimationFinishedListener(), false);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001140 } else {
1141 service.mWindowManager.overridePendingAppTransitionAspectScaledThumb(
1142 pendingOptions.getThumbnail(),
1143 pendingOptions.getStartX(), pendingOptions.getStartY(),
1144 pendingOptions.getWidth(), pendingOptions.getHeight(),
1145 pendingOptions.getOnAnimationStartListener(),
1146 (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP));
1147 if (intent.getSourceBounds() == null) {
1148 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1149 pendingOptions.getStartY(),
1150 pendingOptions.getStartX() + pendingOptions.getWidth(),
1151 pendingOptions.getStartY() + pendingOptions.getHeight()));
1152 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001153 }
1154 break;
Craig Mautner233ceee2014-05-09 17:05:11 -07001155 default:
1156 Slog.e(TAG, "applyOptionsLocked: Unknown animationType=" + animationType);
1157 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001158 }
1159 pendingOptions = null;
1160 }
1161 }
1162
Adam Powellcfbe9be2013-11-06 14:58:58 -08001163 ActivityOptions getOptionsForTargetActivityLocked() {
1164 return pendingOptions != null ? pendingOptions.forTargetActivity() : null;
1165 }
1166
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001167 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001168 if (pendingOptions != null) {
1169 pendingOptions.abort();
1170 pendingOptions = null;
1171 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001172 }
1173
Dianne Hackborn9622ca42012-10-23 18:56:33 -07001174 ActivityOptions takeOptionsLocked() {
1175 ActivityOptions opts = pendingOptions;
1176 pendingOptions = null;
1177 return opts;
1178 }
1179
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001180 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -07001181 if (uriPermissions != null) {
1182 uriPermissions.removeUriPermissionsLocked();
1183 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001184 }
1185 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186
1187 void pauseKeyDispatchingLocked() {
1188 if (!keysPaused) {
1189 keysPaused = true;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001190 mWindowContainerController.pauseKeyDispatching();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001191 }
1192 }
1193
1194 void resumeKeyDispatchingLocked() {
1195 if (keysPaused) {
1196 keysPaused = false;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001197 mWindowContainerController.resumeKeyDispatching();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 }
1199 }
1200
Winson Chung740c3ac2014-11-12 16:14:38 -08001201 void updateThumbnailLocked(Bitmap newThumbnail, CharSequence description) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001202 if (newThumbnail != null) {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001203 if (DEBUG_THUMBNAILS) Slog.i(TAG_THUMBNAILS,
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001204 "Setting thumbnail of " + this + " to " + newThumbnail);
Winsonc809cbb2015-11-02 12:06:15 -08001205 boolean thumbnailUpdated = task.setLastThumbnailLocked(newThumbnail);
Winson Chung096f36b2014-08-20 15:39:01 -07001206 if (thumbnailUpdated && isPersistable()) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001207 service.notifyTaskPersisterLocked(task, false);
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001208 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001209 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001210 task.lastDescription = description;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001211 }
1212
Andrii Kulian21713ac2016-10-12 22:05:05 -07001213 final Bitmap screenshotActivityLocked() {
1214 if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "screenshotActivityLocked: " + this);
Jorim Jaggi02886a82016-12-06 09:10:06 -08001215
1216 if (ENABLE_TASK_SNAPSHOTS) {
1217 // No need to screenshot if snapshots are enabled.
1218 if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS,
1219 "\tSnapshots are enabled, abort taking screenshot");
1220 return null;
1221 }
1222
Andrii Kulian21713ac2016-10-12 22:05:05 -07001223 if (noDisplay) {
1224 if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tNo display");
1225 return null;
1226 }
1227
1228 final ActivityStack stack = getStack();
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001229 if (stack.isHomeOrRecentsStack()) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001230 // This is an optimization -- since we never show Home or Recents within Recents itself,
1231 // we can just go ahead and skip taking the screenshot if this is the home stack.
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001232 if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, stack.getStackId() == HOME_STACK_ID ?
1233 "\tHome stack" : "\tRecents stack");
Andrii Kulian21713ac2016-10-12 22:05:05 -07001234 return null;
1235 }
1236
1237 int w = service.mThumbnailWidth;
1238 int h = service.mThumbnailHeight;
1239
1240 if (w <= 0) {
1241 Slog.e(TAG, "\tInvalid thumbnail dimensions: " + w + "x" + h);
1242 return null;
1243 }
1244
1245 if (stack.mStackId == DOCKED_STACK_ID && mStackSupervisor.mIsDockMinimized) {
1246 // When the docked stack is minimized its app windows are cropped significantly so any
1247 // screenshot taken will not display the apps contain. So, we avoid taking a screenshot
1248 // in that case.
1249 if (DEBUG_SCREENSHOTS) Slog.e(TAG, "\tIn minimized docked stack");
1250 return null;
1251 }
1252
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001253 float scale = 0;
Andrii Kulian21713ac2016-10-12 22:05:05 -07001254 if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tTaking screenshot");
1255
1256 // When this flag is set, we currently take the fullscreen screenshot of the activity but
1257 // scaled to half the size. This gives us a "good-enough" fullscreen thumbnail to use within
1258 // SystemUI while keeping memory usage low.
1259 if (TAKE_FULLSCREEN_SCREENSHOTS) {
1260 w = h = -1;
1261 scale = service.mFullscreenThumbnailScale;
1262 }
1263
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001264 return mWindowContainerController.screenshotApplications(getDisplayId(), w, h, scale);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001265 }
1266
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001267 void setVisibility(boolean visible) {
1268 mWindowContainerController.setVisibility(visible);
1269 }
1270
1271 // TODO: Look into merging with #setVisibility()
Andrii Kulian21713ac2016-10-12 22:05:05 -07001272 void setVisible(boolean newVisible) {
1273 visible = newVisible;
1274 if (!visible && mUpdateTaskThumbnailWhenHidden) {
1275 updateThumbnailLocked(screenshotActivityLocked(), null /* description */);
1276 mUpdateTaskThumbnailWhenHidden = false;
1277 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001278 mWindowContainerController.setVisibility(visible);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001279 final ArrayList<ActivityContainer> containers = mChildContainers;
1280 for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) {
1281 final ActivityContainer container = containers.get(containerNdx);
1282 container.setVisible(visible);
1283 }
1284 mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
1285 }
1286
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001287 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
1288 mWindowContainerController.notifyAppResumed(wasStopped, allowSavedSurface);
1289 }
1290
1291 void notifyUnknownVisibilityLaunched() {
1292 mWindowContainerController.notifyUnknownVisibilityLaunched();
1293 }
1294
Jorim Jaggi241ae102016-11-02 21:57:33 -07001295 /**
1296 * @return true if the input activity should be made visible, ignoring any effect Keyguard
1297 * might have on the visibility
1298 *
1299 * @see {@link ActivityStack#checkKeyguardVisibility}
1300 */
1301 boolean shouldBeVisibleIgnoringKeyguard(boolean behindTranslucentActivity,
1302 boolean stackVisibleBehind, ActivityRecord visibleBehind,
1303 boolean behindFullscreenActivity) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001304 if (!okToShowLocked()) {
1305 return false;
1306 }
1307
1308 // mLaunchingBehind: Activities launching behind are at the back of the task stack
1309 // but must be drawn initially for the animation as though they were visible.
1310 final boolean activityVisibleBehind =
1311 (behindTranslucentActivity || stackVisibleBehind) && visibleBehind == this;
1312
1313 boolean isVisible =
1314 !behindFullscreenActivity || mLaunchTaskBehind || activityVisibleBehind;
1315
1316 if (service.mSupportsLeanbackOnly && isVisible && isRecentsActivity()) {
1317 // On devices that support leanback only (Android TV), Recents activity can only be
1318 // visible if the home stack is the focused stack or we are in split-screen mode.
1319 isVisible = mStackSupervisor.getStack(DOCKED_STACK_ID) != null
1320 || mStackSupervisor.isFocusedStack(getStack());
1321 }
1322
1323 return isVisible;
1324 }
1325
1326 void makeVisibleIfNeeded(ActivityRecord starting) {
1327 // This activity is not currently visible, but is running. Tell it to become visible.
1328 if (state == ActivityState.RESUMED || this == starting) {
1329 if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY,
1330 "Not making visible, r=" + this + " state=" + state + " starting=" + starting);
1331 return;
1332 }
1333
1334 // If this activity is paused, tell it to now show its window.
1335 if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY,
1336 "Making visible and scheduling visibility: " + this);
1337 final ActivityStack stack = getStack();
1338 try {
1339 if (stack.mTranslucentActivityWaiting != null) {
1340 updateOptionsLocked(returningOptions);
1341 stack.mUndrawnActivitiesBelowTopTranslucent.add(this);
1342 }
1343 setVisible(true);
1344 sleeping = false;
1345 app.pendingUiClean = true;
1346 app.thread.scheduleWindowVisibility(appToken, true /* showWindow */);
1347 // The activity may be waiting for stop, but that is no longer appropriate for it.
1348 mStackSupervisor.mStoppingActivities.remove(this);
1349 mStackSupervisor.mGoingToSleepActivities.remove(this);
1350 } catch (Exception e) {
1351 // Just skip on any failure; we'll make it visible when it next restarts.
1352 Slog.w(TAG, "Exception thrown making visibile: " + intent.getComponent(), e);
1353 }
1354 handleAlreadyVisible();
1355 }
1356
1357 boolean handleAlreadyVisible() {
1358 stopFreezingScreenLocked(false);
1359 try {
1360 if (returningOptions != null) {
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001361 app.thread.scheduleOnNewActivityOptions(appToken, returningOptions.toBundle());
Andrii Kulian21713ac2016-10-12 22:05:05 -07001362 }
1363 } catch(RemoteException e) {
1364 }
1365 return state == ActivityState.RESUMED;
1366 }
1367
1368 static void activityResumedLocked(IBinder token) {
1369 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
1370 if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r);
1371 if (r != null) {
1372 r.icicle = null;
1373 r.haveState = false;
1374 }
1375 }
1376
1377 /**
1378 * Once we know that we have asked an application to put an activity in the resumed state
1379 * (either by launching it or explicitly telling it), this function updates the rest of our
1380 * state to match that fact.
1381 */
1382 void completeResumeLocked() {
1383 final boolean wasVisible = visible;
1384 visible = true;
1385 if (!wasVisible) {
1386 // Visibility has changed, so take a note of it so we call the TaskStackChangedListener
1387 mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
1388 }
1389 idle = false;
1390 results = null;
1391 newIntents = null;
1392 stopped = false;
1393
1394 if (isHomeActivity()) {
1395 ProcessRecord app = task.mActivities.get(0).app;
1396 if (app != null && app != service.mHomeProcess) {
1397 service.mHomeProcess = app;
1398 }
1399 }
1400
1401 if (nowVisible) {
1402 // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now.
1403 mStackSupervisor.reportActivityVisibleLocked(this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001404 }
1405
1406 // Schedule an idle timeout in case the app doesn't do it for us.
1407 mStackSupervisor.scheduleIdleTimeoutLocked(this);
1408
1409 mStackSupervisor.reportResumedActivityLocked(this);
1410
1411 resumeKeyDispatchingLocked();
1412 final ActivityStack stack = getStack();
1413 stack.mNoAnimActivities.clear();
1414
1415 // Mark the point when the activity is resuming
1416 // TODO: To be more accurate, the mark should be before the onCreate,
1417 // not after the onResume. But for subsequent starts, onResume is fine.
1418 if (app != null) {
1419 cpuTimeAtResume = service.mProcessCpuTracker.getCpuTimeForPid(app.pid);
1420 } else {
1421 cpuTimeAtResume = 0; // Couldn't get the cpu time of process
1422 }
1423
1424 returningOptions = null;
1425
1426 if (stack.getVisibleBehindActivity() == this) {
1427 // When resuming an activity, require it to call requestVisibleBehind() again.
1428 stack.setVisibleBehindActivity(null /* ActivityRecord */);
1429 }
1430 mStackSupervisor.checkReadyForSleepLocked();
1431 }
1432
1433 final void activityStoppedLocked(Bundle newIcicle, PersistableBundle newPersistentState,
1434 CharSequence description) {
1435 final ActivityStack stack = getStack();
1436 if (state != ActivityState.STOPPING) {
1437 Slog.i(TAG, "Activity reported stop, but no longer stopping: " + this);
1438 stack.mHandler.removeMessages(ActivityStack.STOP_TIMEOUT_MSG, this);
1439 return;
1440 }
1441 if (newPersistentState != null) {
1442 persistentState = newPersistentState;
1443 service.notifyTaskPersisterLocked(task, false);
1444 }
1445 if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, "Saving icicle of " + this + ": " + icicle);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001446
Andrii Kulian21713ac2016-10-12 22:05:05 -07001447 if (newIcicle != null) {
1448 // If icicle is null, this is happening due to a timeout, so we haven't really saved
1449 // the state.
1450 icicle = newIcicle;
1451 haveState = true;
1452 launchCount = 0;
1453 updateThumbnailLocked(null /* newThumbnail */, description);
1454 }
1455 if (!stopped) {
1456 if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to STOPPED: " + this + " (stop complete)");
1457 stack.mHandler.removeMessages(ActivityStack.STOP_TIMEOUT_MSG, this);
1458 stopped = true;
1459 state = ActivityState.STOPPED;
1460
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001461 mWindowContainerController.notifyAppStopped();
Andrii Kulian21713ac2016-10-12 22:05:05 -07001462
1463 if (stack.getVisibleBehindActivity() == this) {
1464 mStackSupervisor.requestVisibleBehindLocked(this, false /* visible */);
1465 }
1466 if (finishing) {
1467 clearOptionsLocked();
1468 } else {
1469 if (deferRelaunchUntilPaused) {
1470 stack.destroyActivityLocked(this, true /* removeFromApp */, "stop-config");
1471 mStackSupervisor.resumeFocusedStackTopActivityLocked();
1472 } else {
1473 mStackSupervisor.updatePreviousProcessLocked(this);
1474 }
1475 }
1476 }
1477 }
1478
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001479 void startLaunchTickingLocked() {
1480 if (ActivityManagerService.IS_USER_BUILD) {
1481 return;
1482 }
1483 if (launchTickTime == 0) {
1484 launchTickTime = SystemClock.uptimeMillis();
1485 continueLaunchTickingLocked();
1486 }
1487 }
1488
1489 boolean continueLaunchTickingLocked() {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001490 if (launchTickTime == 0) {
1491 return false;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001492 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001493
Andrii Kulian02b7a832016-10-06 23:11:56 -07001494 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001495 if (stack == null) {
1496 return false;
1497 }
1498
1499 Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG, this);
1500 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
1501 stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
1502 return true;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001503 }
1504
1505 void finishLaunchTickingLocked() {
1506 launchTickTime = 0;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001507 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001508 if (stack != null) {
1509 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
1510 }
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001511 }
1512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001513 // IApplicationToken
1514
1515 public boolean mayFreezeScreenLocked(ProcessRecord app) {
1516 // Only freeze the screen if this activity is currently attached to
1517 // an application, and that application is not blocked or unresponding.
1518 // In any other case, we can't count on getting the screen unfrozen,
1519 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -08001520 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
1524 if (mayFreezeScreenLocked(app)) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001525 mWindowContainerController.startFreezingScreen(configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 }
1527 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 public void stopFreezingScreenLocked(boolean force) {
1530 if (force || frozenBeforeDestroy) {
1531 frozenBeforeDestroy = false;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001532 mWindowContainerController.stopFreezingScreen(force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 }
1534 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001535
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001536 public void reportFullyDrawnLocked() {
1537 final long curTime = SystemClock.uptimeMillis();
1538 if (displayStartTime != 0) {
1539 reportLaunchTimeLocked(curTime);
1540 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001541 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001542 if (fullyDrawnStartTime != 0 && stack != null) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001543 final long thisTime = curTime - fullyDrawnStartTime;
1544 final long totalTime = stack.mFullyDrawnStartTime != 0
1545 ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07001546 if (SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -07001547 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001548 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME,
1549 userId, System.identityHashCode(this), shortComponentName,
1550 thisTime, totalTime);
1551 StringBuilder sb = service.mStringBuilder;
1552 sb.setLength(0);
1553 sb.append("Fully drawn ");
1554 sb.append(shortComponentName);
1555 sb.append(": ");
1556 TimeUtils.formatDuration(thisTime, sb);
1557 if (thisTime != totalTime) {
1558 sb.append(" (total ");
1559 TimeUtils.formatDuration(totalTime, sb);
1560 sb.append(")");
1561 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001562 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001563 }
1564 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001565 //service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001566 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001567 stack.mFullyDrawnStartTime = 0;
1568 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001569 fullyDrawnStartTime = 0;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001570 }
1571
1572 private void reportLaunchTimeLocked(final long curTime) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001573 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001574 if (stack == null) {
1575 return;
1576 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001577 final long thisTime = curTime - displayStartTime;
1578 final long totalTime = stack.mLaunchStartTime != 0
1579 ? (curTime - stack.mLaunchStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07001580 if (SHOW_ACTIVITY_START_TIME) {
Narayan Kamath7829c812015-06-08 17:39:43 +01001581 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001582 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
1583 userId, System.identityHashCode(this), shortComponentName,
1584 thisTime, totalTime);
1585 StringBuilder sb = service.mStringBuilder;
1586 sb.setLength(0);
1587 sb.append("Displayed ");
1588 sb.append(shortComponentName);
1589 sb.append(": ");
1590 TimeUtils.formatDuration(thisTime, sb);
1591 if (thisTime != totalTime) {
1592 sb.append(" (total ");
1593 TimeUtils.formatDuration(totalTime, sb);
1594 sb.append(")");
1595 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001596 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001597 }
1598 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
1599 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001600 //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001601 }
1602 displayStartTime = 0;
1603 stack.mLaunchStartTime = 0;
1604 }
1605
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001606 @Override
1607 public void onWindowsDrawn() {
1608 synchronized (service) {
1609 mStackSupervisor.mActivityMetricsLogger.notifyWindowsDrawn();
1610 if (displayStartTime != 0) {
1611 reportLaunchTimeLocked(SystemClock.uptimeMillis());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001612 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001613 mStackSupervisor.sendWaitingVisibleReportLocked(this);
1614 startTime = 0;
1615 finishLaunchTickingLocked();
1616 if (task != null) {
1617 task.hasBeenVisible = true;
1618 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001619 }
1620 }
1621
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001622 @Override
1623 public void onWindowsVisible() {
1624 synchronized (service) {
1625 mStackSupervisor.reportActivityVisibleLocked(this);
1626 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this);
1627 if (!nowVisible) {
1628 nowVisible = true;
1629 lastVisibleTime = SystemClock.uptimeMillis();
1630 if (!idle) {
1631 // Instead of doing the full stop routine here, let's just hide any activities
1632 // we now can, and let them stop when the normal idle happens.
1633 mStackSupervisor.processStoppingActivitiesLocked(false);
1634 } else {
1635 // If this activity was already idle, then we now need to make sure we perform
1636 // the full stop of any activities that are waiting to do so. This is because
1637 // we won't do that while they are still waiting for this one to become visible.
1638 final int size = mStackSupervisor.mWaitingVisibleActivities.size();
1639 if (size > 0) {
1640 for (int i = 0; i < size; i++) {
1641 ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i);
1642 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "Was waiting for visible: " + r);
1643 }
1644 mStackSupervisor.mWaitingVisibleActivities.clear();
1645 mStackSupervisor.scheduleIdleLocked();
1646 }
1647 }
1648 service.scheduleAppGcsLocked();
1649 }
1650 }
1651 }
1652
1653 @Override
1654 public void onWindowsGone() {
1655 synchronized (service) {
1656 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + this);
1657 nowVisible = false;
1658 }
1659 }
1660
1661 @Override
1662 public boolean keyDispatchingTimedOut(String reason) {
1663 ActivityRecord anrActivity;
1664 ProcessRecord anrApp;
1665 synchronized (service) {
1666 anrActivity = getWaitingHistoryRecordLocked();
1667 anrApp = app;
1668 }
1669 return service.inputDispatchingTimedOut(anrApp, anrActivity, this, false, reason);
1670 }
1671
1672 private ActivityRecord getWaitingHistoryRecordLocked() {
riddle_hsudb46d6b2015-04-01 18:58:07 +08001673 // First find the real culprit... if this activity is waiting for
1674 // another activity to start or has stopped, then the key dispatching
1675 // timeout should not be caused by this.
Wale Ogunwale16a62792015-04-01 11:50:31 -07001676 if (mStackSupervisor.mWaitingVisibleActivities.contains(this) || stopped) {
Craig Mautner8f2adcb2014-04-07 22:21:33 +00001677 final ActivityStack stack = mStackSupervisor.getFocusedStack();
riddle_hsudb46d6b2015-04-01 18:58:07 +08001678 // Try to use the one which is closest to top.
1679 ActivityRecord r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001680 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -08001681 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001682 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001683 if (r != null) {
1684 return r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001685 }
1686 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001687 return this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001688 }
1689
Chong Zhang87761972016-08-22 13:53:24 -07001690 /** Checks whether the activity should be shown for current user. */
1691 public boolean okToShowLocked() {
1692 return (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0
1693 || (mStackSupervisor.isCurrentProfileLocked(userId)
1694 && !service.mUserController.isUserStoppingOrShuttingDownLocked(userId));
1695 }
1696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 /**
1698 * This method will return true if the activity is either visible, is becoming visible, is
1699 * currently pausing, or is resumed.
1700 */
1701 public boolean isInterestingToUserLocked() {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001702 return visible || nowVisible || state == ActivityState.PAUSING ||
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001703 state == ActivityState.RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001704 }
1705
Wale Ogunwale3e997362016-09-06 10:37:56 -07001706 void setSleeping(boolean _sleeping) {
1707 setSleeping(_sleeping, false);
1708 }
1709
1710 void setSleeping(boolean _sleeping, boolean force) {
1711 if (!force && sleeping == _sleeping) {
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001712 return;
1713 }
1714 if (app != null && app.thread != null) {
1715 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -08001716 app.thread.scheduleSleeping(appToken, _sleeping);
Craig Mautner0eea92c2013-05-16 13:35:39 -07001717 if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
1718 mStackSupervisor.mGoingToSleepActivities.add(this);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001719 }
1720 sleeping = _sleeping;
1721 } catch (RemoteException e) {
Craig Mautner0eea92c2013-05-16 13:35:39 -07001722 Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001723 }
1724 }
1725 }
Craig Mautnerf81b90872013-02-26 13:02:43 -08001726
Craig Mautnerd2328952013-03-05 12:46:26 -08001727 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001728 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Craig Mautnerd2328952013-03-05 12:46:26 -08001729 if (r == null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001730 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08001731 }
1732 final TaskRecord task = r.task;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001733 final int activityNdx = task.mActivities.indexOf(r);
1734 if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001735 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08001736 }
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001737 return task.taskId;
Craig Mautnerd2328952013-03-05 12:46:26 -08001738 }
1739
1740 static ActivityRecord isInStackLocked(IBinder token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001741 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Andrii Kulian02b7a832016-10-06 23:11:56 -07001742 return (r != null) ? r.getStack().isInStackLocked(r) : null;
Craig Mautnerd2328952013-03-05 12:46:26 -08001743 }
1744
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001745 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -08001746 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
1747 if (r != null) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001748 return r.getStack();
Craig Mautnerd2328952013-03-05 12:46:26 -08001749 }
1750 return null;
1751 }
1752
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001753 /**
1754 * @return display id to which this record is attached, -1 if not attached.
1755 */
1756 int getDisplayId() {
1757 final ActivityStack stack = getStack();
1758 if (stack == null) {
1759 return -1;
1760 }
1761 return stack.mDisplayId;
1762 }
1763
Dianne Hackborn89ad4562014-08-24 16:45:38 -07001764 final boolean isDestroyable() {
1765 if (finishing || app == null || state == ActivityState.DESTROYING
1766 || state == ActivityState.DESTROYED) {
1767 // This would be redundant.
1768 return false;
1769 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001770 final ActivityStack stack = getStack();
1771 if (stack == null || this == stack.mResumedActivity || this == stack.mPausingActivity
1772 || !haveState || !stopped) {
Dianne Hackborn89ad4562014-08-24 16:45:38 -07001773 // We're not ready for this kind of thing.
1774 return false;
1775 }
1776 if (visible) {
1777 // The user would notice this!
1778 return false;
1779 }
1780 return true;
1781 }
1782
Winson Chung3bad5cc02014-08-19 17:44:32 -07001783 private static String createImageFilename(long createTime, int taskId) {
1784 return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime +
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001785 TaskPersister.IMAGE_EXTENSION;
1786 }
1787
Craig Mautner648f69b2014-09-18 14:16:26 -07001788 void setTaskDescription(TaskDescription _taskDescription) {
1789 Bitmap icon;
1790 if (_taskDescription.getIconFilename() == null &&
1791 (icon = _taskDescription.getIcon()) != null) {
1792 final String iconFilename = createImageFilename(createTime, task.taskId);
Suprabh Shukla23593142015-11-03 17:31:15 -08001793 final File iconFile = new File(TaskPersister.getUserImagesDir(userId), iconFilename);
1794 final String iconFilePath = iconFile.getAbsolutePath();
Suprabh Shukla09a88f52015-12-02 14:36:31 -08001795 service.mRecentTasks.saveImage(icon, iconFilePath);
Suprabh Shukla23593142015-11-03 17:31:15 -08001796 _taskDescription.setIconFilename(iconFilePath);
Craig Mautner648f69b2014-09-18 14:16:26 -07001797 }
1798 taskDescription = _taskDescription;
1799 }
1800
Amith Yamasani0af6fa72016-01-17 15:36:19 -08001801 void setVoiceSessionLocked(IVoiceInteractionSession session) {
1802 voiceSession = session;
1803 pendingVoiceInteractionStart = false;
1804 }
1805
1806 void clearVoiceSessionLocked() {
1807 voiceSession = null;
1808 pendingVoiceInteractionStart = false;
1809 }
1810
Jorim Jaggi02886a82016-12-06 09:10:06 -08001811 void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch) {
Jorim Jaggi70176432017-01-18 12:52:13 +01001812 if (mWindowContainerController == null) {
1813 return;
1814 }
Wale Ogunwale3b232392016-05-13 15:37:13 -07001815 final CompatibilityInfo compatInfo =
1816 service.compatibilityInfoForPackageLocked(info.applicationInfo);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001817 final boolean shown = mWindowContainerController.addStartingWindow(packageName, theme,
1818 compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags,
Jorim Jaggi02886a82016-12-06 09:10:06 -08001819 prev != null ? prev.appToken : null, newTask, taskSwitch, isProcessRunning());
Wale Ogunwale3b232392016-05-13 15:37:13 -07001820 if (shown) {
1821 mStartingWindowState = STARTING_WINDOW_SHOWN;
1822 }
1823 }
1824
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001825 void removeOrphanedStartingWindow(boolean behindFullscreenActivity) {
1826 if (state == ActivityState.INITIALIZING
1827 && mStartingWindowState == STARTING_WINDOW_SHOWN
1828 && behindFullscreenActivity) {
1829 if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, "Found orphaned starting window " + this);
1830 mStartingWindowState = STARTING_WINDOW_REMOVED;
1831 mWindowContainerController.removeStartingWindow();
1832 }
1833 }
1834
1835 int getRequestedOrientation() {
1836 return mWindowContainerController.getOrientation();
1837 }
1838
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001839 void setRequestedOrientation(int requestedOrientation) {
1840 if (task != null && (!task.mFullscreen || !task.getStack().mFullscreen)) {
1841 // Fixed screen orientation isn't supported when activities aren't in full screen mode.
1842 return;
1843 }
1844
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001845 final int displayId = getDisplayId();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001846 final Configuration displayConfig =
1847 mStackSupervisor.getDisplayOverrideConfiguration(displayId);
1848
1849 final Configuration config = mWindowContainerController.setOrientation(requestedOrientation,
1850 displayId, displayConfig, mayFreezeScreenLocked(app));
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001851 if (config != null) {
1852 frozenBeforeDestroy = true;
1853 if (!service.updateDisplayOverrideConfigurationLocked(config, this,
1854 false /* deferResume */, displayId)) {
1855 mStackSupervisor.resumeFocusedStackTopActivityLocked();
1856 }
1857 }
Yorke Leebd54c2a2016-10-25 13:49:23 -07001858 service.mTaskChangeNotificationController.notifyActivityRequestedOrientationChanged(
1859 task.taskId, requestedOrientation);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001860 }
1861
Andrii Kulian21713ac2016-10-12 22:05:05 -07001862 // TODO: now used only in one place to address race-condition. Remove when that will be fixed.
1863 void setLastReportedConfiguration(@NonNull Configuration config) {
1864 mLastReportedConfiguration.setTo(config);
1865 }
1866
1867 /** Call when override config was sent to the Window Manager to update internal records. */
1868 void onOverrideConfigurationSent() {
1869 mLastReportedOverrideConfiguration.setTo(task.getMergedOverrideConfiguration());
1870 }
1871
1872 /**
1873 * Make sure the given activity matches the current configuration. Returns false if the activity
1874 * had to be destroyed. Returns true if the configuration is the same, or the activity will
1875 * remain running as-is for whatever reason. Ensures the HistoryRecord is updated with the
1876 * correct configuration and all other bookkeeping is handled.
1877 */
1878 boolean ensureActivityConfigurationLocked(int globalChanges, boolean preserveWindow) {
1879 final ActivityStack stack = getStack();
1880 if (stack.mConfigWillChange) {
1881 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1882 "Skipping config check (will change): " + this);
1883 return true;
1884 }
1885
1886 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1887 "Ensuring correct configuration: " + this);
1888
1889 // Short circuit: if the two configurations are equal (the common case), then there is
1890 // nothing to do.
1891 final Configuration newGlobalConfig = service.getGlobalConfiguration();
1892 final Configuration newTaskMergedOverrideConfig = task.getMergedOverrideConfiguration();
1893 if (mLastReportedConfiguration.equals(newGlobalConfig)
1894 && mLastReportedOverrideConfiguration.equals(newTaskMergedOverrideConfig)
1895 && !forceNewConfig) {
1896 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1897 "Configuration unchanged in " + this);
1898 return true;
1899 }
1900
1901 // We don't worry about activities that are finishing.
1902 if (finishing) {
1903 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1904 "Configuration doesn't matter in finishing " + this);
1905 stopFreezingScreenLocked(false);
1906 return true;
1907 }
1908
1909 // Okay we now are going to make this activity have the new config.
1910 // But then we need to figure out how it needs to deal with that.
1911 mTmpGlobalConfig.setTo(mLastReportedConfiguration);
1912 mTmpTaskConfig.setTo(mLastReportedOverrideConfiguration);
1913 mLastReportedConfiguration.setTo(newGlobalConfig);
1914 mLastReportedOverrideConfiguration.setTo(newTaskMergedOverrideConfig);
1915
1916 int taskChanges = getTaskConfigurationChanges(this, newTaskMergedOverrideConfig,
1917 mTmpTaskConfig);
1918 final int changes = mTmpGlobalConfig.diff(newGlobalConfig) | taskChanges;
1919 if (changes == 0 && !forceNewConfig) {
1920 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1921 "Configuration no differences in " + this);
1922 // There are no significant differences, so we won't relaunch but should still deliver
1923 // the new configuration to the client process.
1924 scheduleConfigurationChanged(newTaskMergedOverrideConfig, true);
1925 return true;
1926 }
1927
1928 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1929 "Configuration changes for " + this + " ; taskChanges="
1930 + Configuration.configurationDiffToString(taskChanges) + ", allChanges="
1931 + Configuration.configurationDiffToString(changes));
1932
1933 // If the activity isn't currently running, just leave the new configuration and it will
1934 // pick that up next time it starts.
1935 if (app == null || app.thread == null) {
1936 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1937 "Configuration doesn't matter not running " + this);
1938 stopFreezingScreenLocked(false);
1939 forceNewConfig = false;
1940 return true;
1941 }
1942
1943 // Figure out how to handle the changes between the configurations.
1944 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1945 "Checking to restart " + info.name + ": changed=0x"
1946 + Integer.toHexString(changes) + ", handles=0x"
1947 + Integer.toHexString(info.getRealConfigChanged())
1948 + ", newGlobalConfig=" + newGlobalConfig
1949 + ", newTaskMergedOverrideConfig=" + newTaskMergedOverrideConfig);
1950
1951 if ((changes&(~info.getRealConfigChanged())) != 0 || forceNewConfig) {
1952 // Aha, the activity isn't handling the change, so DIE DIE DIE.
1953 configChangeFlags |= changes;
1954 startFreezingScreenLocked(app, globalChanges);
1955 forceNewConfig = false;
1956 preserveWindow &= isResizeOnlyChange(changes);
1957 if (app == null || app.thread == null) {
1958 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1959 "Config is destroying non-running " + this);
1960 stack.destroyActivityLocked(this, true, "config");
1961 } else if (state == ActivityState.PAUSING) {
1962 // A little annoying: we are waiting for this activity to finish pausing. Let's not
1963 // do anything now, but just flag that it needs to be restarted when done pausing.
1964 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1965 "Config is skipping already pausing " + this);
1966 deferRelaunchUntilPaused = true;
1967 preserveWindowOnDeferredRelaunch = preserveWindow;
1968 return true;
1969 } else if (state == ActivityState.RESUMED) {
1970 // Try to optimize this case: the configuration is changing and we need to restart
1971 // the top, resumed activity. Instead of doing the normal handshaking, just say
1972 // "restart!".
1973 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1974 "Config is relaunching resumed " + this);
1975
1976 if (DEBUG_STATES && !visible) {
1977 Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + this
1978 + " called by " + Debug.getCallers(4));
1979 }
1980
1981 relaunchActivityLocked(true /* andResume */, preserveWindow);
1982 } else {
1983 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1984 "Config is relaunching non-resumed " + this);
1985 relaunchActivityLocked(false /* andResume */, preserveWindow);
1986 }
1987
1988 // All done... tell the caller we weren't able to keep this activity around.
1989 return false;
1990 }
1991
1992 // Default case: the activity can handle this new configuration, so hand it over.
1993 // NOTE: We only forward the task override configuration as the system level configuration
1994 // changes is always sent to all processes when they happen so it can just use whatever
1995 // system level configuration it last got.
1996 scheduleConfigurationChanged(newTaskMergedOverrideConfig, true);
1997 stopFreezingScreenLocked(false);
1998
1999 return true;
2000 }
2001
2002 private static int getTaskConfigurationChanges(ActivityRecord record, Configuration taskConfig,
2003 Configuration oldTaskOverride) {
2004 // If we went from full-screen to non-full-screen, make sure to use the correct
2005 // configuration task diff, so the diff stays as small as possible.
2006 if (Configuration.EMPTY.equals(oldTaskOverride)
2007 && !Configuration.EMPTY.equals(taskConfig)) {
2008 oldTaskOverride = record.task.extractOverrideConfig(record.mLastReportedConfiguration);
2009 }
2010
2011 // Conversely, do the same when going the other direction.
2012 if (Configuration.EMPTY.equals(taskConfig)
2013 && !Configuration.EMPTY.equals(oldTaskOverride)) {
2014 taskConfig = record.task.extractOverrideConfig(record.mLastReportedConfiguration);
2015 }
2016
2017 // Determine what has changed. May be nothing, if this is a config that has come back from
2018 // the app after going idle. In that case we just want to leave the official config object
2019 // now in the activity and do nothing else.
2020 int taskChanges = oldTaskOverride.diff(taskConfig, true /* skipUndefined */);
2021 // We don't want to use size changes if they don't cross boundaries that are important to
2022 // the app.
2023 if ((taskChanges & CONFIG_SCREEN_SIZE) != 0) {
2024 final boolean crosses = record.crossesHorizontalSizeThreshold(
2025 oldTaskOverride.screenWidthDp, taskConfig.screenWidthDp)
2026 || record.crossesVerticalSizeThreshold(
2027 oldTaskOverride.screenHeightDp, taskConfig.screenHeightDp);
2028 if (!crosses) {
2029 taskChanges &= ~CONFIG_SCREEN_SIZE;
2030 }
2031 }
2032 if ((taskChanges & CONFIG_SMALLEST_SCREEN_SIZE) != 0) {
2033 final int oldSmallest = oldTaskOverride.smallestScreenWidthDp;
2034 final int newSmallest = taskConfig.smallestScreenWidthDp;
2035 if (!record.crossesSmallestSizeThreshold(oldSmallest, newSmallest)) {
2036 taskChanges &= ~CONFIG_SMALLEST_SCREEN_SIZE;
2037 }
2038 }
2039 return taskChanges;
2040 }
2041
2042 private static boolean isResizeOnlyChange(int change) {
2043 return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION
2044 | CONFIG_SCREEN_LAYOUT)) == 0;
2045 }
2046
2047 void relaunchActivityLocked(boolean andResume, boolean preserveWindow) {
2048 if (service.mSuppressResizeConfigChanges && preserveWindow) {
2049 configChangeFlags = 0;
2050 return;
2051 }
2052
2053 List<ResultInfo> pendingResults = null;
2054 List<ReferrerIntent> pendingNewIntents = null;
2055 if (andResume) {
2056 pendingResults = results;
2057 pendingNewIntents = newIntents;
2058 }
2059 if (DEBUG_SWITCH) Slog.v(TAG_SWITCH,
2060 "Relaunching: " + this + " with results=" + pendingResults
2061 + " newIntents=" + pendingNewIntents + " andResume=" + andResume
2062 + " preserveWindow=" + preserveWindow);
2063 EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY
2064 : EventLogTags.AM_RELAUNCH_ACTIVITY, userId, System.identityHashCode(this),
2065 task.taskId, shortComponentName);
2066
2067 startFreezingScreenLocked(app, 0);
2068
2069 mStackSupervisor.removeChildActivityContainers(this);
2070
2071 try {
2072 if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH,
2073 "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + this
2074 + " callers=" + Debug.getCallers(6));
2075 forceNewConfig = false;
2076 mStackSupervisor.activityRelaunchingLocked(this);
2077 app.thread.scheduleRelaunchActivity(appToken, pendingResults, pendingNewIntents,
2078 configChangeFlags, !andResume,
2079 new Configuration(service.getGlobalConfiguration()),
2080 new Configuration(task.getMergedOverrideConfiguration()), preserveWindow);
2081 // Note: don't need to call pauseIfSleepingLocked() here, because the caller will only
2082 // pass in 'andResume' if this activity is currently resumed, which implies we aren't
2083 // sleeping.
2084 } catch (RemoteException e) {
2085 if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e);
2086 }
2087
2088 if (andResume) {
2089 if (DEBUG_STATES) {
2090 Slog.d(TAG_STATES, "Resumed after relaunch " + this);
2091 }
2092 results = null;
2093 newIntents = null;
2094 service.showUnsupportedZoomDialogIfNeededLocked(this);
2095 service.showAskCompatModeDialogLocked(this);
2096 } else {
2097 service.mHandler.removeMessages(ActivityStack.PAUSE_TIMEOUT_MSG, this);
2098 state = ActivityState.PAUSED;
2099 // if the app is relaunched when it's stopped, and we're not resuming,
2100 // put it back into stopped state.
2101 if (stopped) {
2102 getStack().addToStopping(this, true /* immediate */);
2103 }
2104 }
2105
2106 configChangeFlags = 0;
2107 deferRelaunchUntilPaused = false;
2108 preserveWindowOnDeferredRelaunch = false;
2109 }
2110
Jorim Jaggi02886a82016-12-06 09:10:06 -08002111 boolean isProcessRunning() {
2112 ProcessRecord proc = app;
2113 if (proc == null) {
2114 proc = service.mProcessNames.get(processName, info.applicationInfo.uid);
2115 }
2116 return proc != null && proc.thread != null;
2117 }
2118
Craig Mautner21d24a22014-04-23 11:45:37 -07002119 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
2120 out.attribute(null, ATTR_ID, String.valueOf(createTime));
2121 out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
2122 if (launchedFromPackage != null) {
2123 out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage);
2124 }
2125 if (resolvedType != null) {
2126 out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType);
2127 }
2128 out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified));
2129 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Winson Chung2cb86c72014-06-25 12:03:30 -07002130
Craig Mautner21d24a22014-04-23 11:45:37 -07002131 if (taskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07002132 taskDescription.saveToXml(out);
Craig Mautner21d24a22014-04-23 11:45:37 -07002133 }
2134
2135 out.startTag(null, TAG_INTENT);
2136 intent.saveToXml(out);
2137 out.endTag(null, TAG_INTENT);
2138
2139 if (isPersistable() && persistentState != null) {
2140 out.startTag(null, TAG_PERSISTABLEBUNDLE);
2141 persistentState.saveToXml(out);
2142 out.endTag(null, TAG_PERSISTABLEBUNDLE);
2143 }
2144 }
2145
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07002146 static ActivityRecord restoreFromXml(XmlPullParser in,
2147 ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07002148 Intent intent = null;
2149 PersistableBundle persistentState = null;
2150 int launchedFromUid = 0;
2151 String launchedFromPackage = null;
2152 String resolvedType = null;
2153 boolean componentSpecified = false;
2154 int userId = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07002155 long createTime = -1;
2156 final int outerDepth = in.getDepth();
Winson Chung2cb86c72014-06-25 12:03:30 -07002157 TaskDescription taskDescription = new TaskDescription();
Craig Mautner21d24a22014-04-23 11:45:37 -07002158
2159 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
2160 final String attrName = in.getAttributeName(attrNdx);
2161 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07002162 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
Wale Ogunwale18795a22014-12-03 11:38:33 -08002163 "ActivityRecord: attribute name=" + attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002164 if (ATTR_ID.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01002165 createTime = Long.parseLong(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002166 } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01002167 launchedFromUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002168 } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
2169 launchedFromPackage = attrValue;
2170 } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
2171 resolvedType = attrValue;
2172 } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
Tobias Thiererb0800dc2016-04-21 17:51:41 +01002173 componentSpecified = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002174 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01002175 userId = Integer.parseInt(attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07002176 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
2177 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002178 } else {
2179 Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName);
2180 }
2181 }
2182
2183 int event;
2184 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07002185 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07002186 if (event == XmlPullParser.START_TAG) {
2187 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07002188 if (TaskPersister.DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08002189 Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name);
Craig Mautner21d24a22014-04-23 11:45:37 -07002190 if (TAG_INTENT.equals(name)) {
2191 intent = Intent.restoreFromXml(in);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07002192 if (TaskPersister.DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08002193 Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07002194 } else if (TAG_PERSISTABLEBUNDLE.equals(name)) {
2195 persistentState = PersistableBundle.restoreFromXml(in);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07002196 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
Craig Mautner21d24a22014-04-23 11:45:37 -07002197 "ActivityRecord: persistentState=" + persistentState);
2198 } else {
2199 Slog.w(TAG, "restoreActivity: unexpected name=" + name);
2200 XmlUtils.skipCurrentTag(in);
2201 }
2202 }
2203 }
2204
2205 if (intent == null) {
Craig Mautnere0129b32014-05-25 16:41:09 -07002206 throw new XmlPullParserException("restoreActivity error intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07002207 }
2208
2209 final ActivityManagerService service = stackSupervisor.mService;
2210 final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null,
Jeff Hao1b012d32014-08-20 10:35:34 -07002211 userId);
Craig Mautnere0129b32014-05-25 16:41:09 -07002212 if (aInfo == null) {
Craig Mautner77b04262014-06-27 15:22:12 -07002213 throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent +
2214 " resolvedType=" + resolvedType);
Craig Mautnere0129b32014-05-25 16:41:09 -07002215 }
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002216 final ActivityRecord r = new ActivityRecord(service, null /* caller */,
2217 0 /* launchedFromPid */, launchedFromUid, launchedFromPackage, intent, resolvedType,
2218 aInfo, service.getConfiguration(), null /* resultTo */, null /* resultWho */,
2219 0 /* reqCode */, componentSpecified, false /* rootVoiceInteraction */,
2220 stackSupervisor, null /* container */, null /* options */, null /* sourceRecord */);
Craig Mautner21d24a22014-04-23 11:45:37 -07002221
2222 r.persistentState = persistentState;
Winson Chung2cb86c72014-06-25 12:03:30 -07002223 r.taskDescription = taskDescription;
Craig Mautner21d24a22014-04-23 11:45:37 -07002224 r.createTime = createTime;
2225
2226 return r;
2227 }
2228
2229 private static String activityTypeToString(int type) {
Craig Mautnerae7ecab2013-09-18 11:48:14 -07002230 switch (type) {
2231 case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE";
2232 case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE";
2233 case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE";
2234 default: return Integer.toString(type);
2235 }
2236 }
2237
Craig Mautnerf81b90872013-02-26 13:02:43 -08002238 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002239 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002240 if (stringName != null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08002241 return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) +
Craig Mautnerf3333272013-04-22 10:55:53 -07002242 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002243 }
2244 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -08002245 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002246 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -07002247 sb.append(" u");
2248 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002249 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002250 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -08002251 stringName = sb.toString();
2252 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002253 }
2254}