blob: fe006fc061649d17b542432b500eee62902b50a3 [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;
Winson Chungbb348802017-01-30 12:01:45 -080020import static android.app.ActivityManager.LOCK_TASK_MODE_NONE;
Wale Ogunwale4cea0f52015-12-25 06:30:31 -080021import static android.app.ActivityManager.StackId;
Winson Chung83471632016-12-13 11:02:12 -080022import static android.app.ActivityManager.StackId.ASSISTANT_STACK_ID;
Wale Ogunwaleeb915f22016-10-14 07:18:22 -070023import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080024import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Matthew Ngae1ff4f2016-11-10 15:49:14 -080025import static android.app.ActivityManager.StackId.HOME_STACK_ID;
Jorim Jaggi3878ca32017-02-02 17:13:05 -080026import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Wale Ogunwale22e25262016-02-01 10:32:02 -080027import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Ruben Brunkf53497c2017-03-27 20:26:17 -070028import static android.app.ActivityManager.TaskDescription.ATTR_TASKDESCRIPTION_PREFIX;
29import static android.app.ActivityOptions.ANIM_CLIP_REVEAL;
30import static android.app.ActivityOptions.ANIM_CUSTOM;
31import static android.app.ActivityOptions.ANIM_SCALE_UP;
32import static android.app.ActivityOptions.ANIM_SCENE_TRANSITION;
33import static android.app.ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN;
34import static android.app.ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP;
35import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN;
36import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_UP;
Winson Chung59fda9e2017-01-20 16:14:51 -080037import static android.app.AppOpsManager.MODE_ALLOWED;
Winson Chungf4ac0632017-03-17 12:34:12 -070038import static android.app.AppOpsManager.OP_PICTURE_IN_PICTURE;
Ruben Brunkf53497c2017-03-27 20:26:17 -070039import static android.content.Intent.ACTION_MAIN;
40import static android.content.Intent.CATEGORY_HOME;
41import static android.content.Intent.CATEGORY_LAUNCHER;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080042import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
Bryce Leeb7c9b802017-05-02 14:20:24 -070043import static android.content.Intent.FLAG_ACTIVITY_NO_HISTORY;
Andrii Kulian21713ac2016-10-12 22:05:05 -070044import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
45import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT;
46import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
47import static android.content.pm.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
Zak Cohen90e7116742017-01-29 12:59:23 -080048import static android.content.pm.ActivityInfo.CONFIG_UI_MODE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080049import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080050import static android.content.pm.ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
51import static android.content.pm.ActivityInfo.FLAG_IMMERSIVE;
52import static android.content.pm.ActivityInfo.FLAG_MULTIPROCESS;
Chong Zhang87761972016-08-22 13:53:24 -070053import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080054import static android.content.pm.ActivityInfo.FLAG_STATE_NOT_NEEDED;
55import static android.content.pm.ActivityInfo.LAUNCH_MULTIPLE;
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -080056import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE;
57import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080058import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP;
Ruben Brunkf53497c2017-03-27 20:26:17 -070059import static android.content.pm.ActivityInfo.PERSIST_ACROSS_REBOOTS;
60import static android.content.pm.ActivityInfo.PERSIST_ROOT_ONLY;
Wale Ogunwaledf241e92016-10-13 15:14:21 -070061import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
Jorim Jaggicd13d332016-04-27 15:40:20 -070062import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
Wale Ogunwale72a73e32016-10-13 12:16:39 -070063import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Wale Ogunwaledf241e92016-10-13 15:14:21 -070064import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
Bryce Leeb7c9b802017-05-02 14:20:24 -070065import static android.content.pm.ActivityInfo.FLAG_NO_HISTORY;
Wale Ogunwaled4b1d1e2017-04-10 06:35:59 -070066import static android.content.pm.ActivityInfo.isFixedOrientationLandscape;
67import static android.content.pm.ActivityInfo.isFixedOrientationPortrait;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -070068import static android.content.res.Configuration.EMPTY;
Wale Ogunwalee610d3d2017-04-25 10:23:48 -070069import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
70import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
Ruben Brunkf53497c2017-03-27 20:26:17 -070071import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
Zak Cohen90e7116742017-01-29 12:59:23 -080072import static android.content.res.Configuration.UI_MODE_TYPE_VR_HEADSET;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080073import static android.os.Build.VERSION_CODES.HONEYCOMB;
Zak Cohen90e7116742017-01-29 12:59:23 -080074import static android.os.Build.VERSION_CODES.O;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080075import static android.os.Process.SYSTEM_UID;
Ruben Brunkf53497c2017-03-27 20:26:17 -070076import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
Andrii Kulian3a1619d2017-07-07 14:38:09 -070077import static android.view.WindowManagerPolicy.NAV_BAR_LEFT;
Andrii Kulian036e3ad2017-04-19 10:55:10 -070078
Filip Gruszczynski3d026712015-12-16 13:46:38 -080079import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION;
Andrii Kulian21713ac2016-10-12 22:05:05 -070080import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE;
81import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SCREENSHOTS;
82import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080083import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH;
84import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_THUMBNAILS;
Andrii Kulian21713ac2016-10-12 22:05:05 -070085import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBILITY;
86import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONFIGURATION;
87import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SAVED_STATE;
88import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SCREENSHOTS;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080089import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES;
90import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH;
91import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_THUMBNAILS;
Andrii Kulian21713ac2016-10-12 22:05:05 -070092import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBILITY;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080093import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
94import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Ruben Brunkf53497c2017-03-27 20:26:17 -070095import static com.android.server.am.ActivityManagerService.IS_USER_BUILD;
Andrii Kulian21713ac2016-10-12 22:05:05 -070096import static com.android.server.am.ActivityManagerService.TAKE_FULLSCREEN_SCREENSHOTS;
Ruben Brunkf53497c2017-03-27 20:26:17 -070097import static com.android.server.am.ActivityStack.ActivityState.DESTROYED;
98import static com.android.server.am.ActivityStack.ActivityState.DESTROYING;
99import static com.android.server.am.ActivityStack.ActivityState.INITIALIZING;
100import static com.android.server.am.ActivityStack.ActivityState.PAUSED;
101import static com.android.server.am.ActivityStack.ActivityState.PAUSING;
102import static com.android.server.am.ActivityStack.ActivityState.RESUMED;
103import static com.android.server.am.ActivityStack.ActivityState.STOPPED;
104import static com.android.server.am.ActivityStack.ActivityState.STOPPING;
105import static com.android.server.am.ActivityStack.LAUNCH_TICK;
106import static com.android.server.am.ActivityStack.LAUNCH_TICK_MSG;
107import static com.android.server.am.ActivityStack.PAUSE_TIMEOUT_MSG;
Wale Ogunwale9b7a8272017-04-10 08:05:41 -0700108import static com.android.server.am.ActivityStack.STACK_INVISIBLE;
Ruben Brunkf53497c2017-03-27 20:26:17 -0700109import static com.android.server.am.ActivityStack.STOP_TIMEOUT_MSG;
110import static com.android.server.am.EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME;
111import static com.android.server.am.EventLogTags.AM_ACTIVITY_LAUNCH_TIME;
112import static com.android.server.am.EventLogTags.AM_RELAUNCH_ACTIVITY;
113import static com.android.server.am.EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY;
114import static com.android.server.am.TaskPersister.DEBUG;
115import static com.android.server.am.TaskPersister.IMAGE_EXTENSION;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800116import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
Ruben Brunkf53497c2017-03-27 20:26:17 -0700117import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
118import static org.xmlpull.v1.XmlPullParser.END_TAG;
119import static org.xmlpull.v1.XmlPullParser.START_TAG;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800120
Andrii Kulian21713ac2016-10-12 22:05:05 -0700121import android.annotation.NonNull;
Craig Mautner21d24a22014-04-23 11:45:37 -0700122import android.app.ActivityManager.TaskDescription;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700123import android.app.ActivityOptions;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800124import android.app.PendingIntent;
Winson Chung709904f2017-04-25 11:00:48 -0700125import android.app.PictureInPictureParams;
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800126import android.app.ResultInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127import android.content.ComponentName;
128import android.content.Intent;
129import android.content.pm.ActivityInfo;
130import android.content.pm.ApplicationInfo;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700131import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132import android.content.res.Configuration;
133import android.graphics.Bitmap;
Winson Chungaa7fa012017-05-24 15:50:06 -0700134import android.graphics.GraphicBuffer;
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700135import android.graphics.Rect;
Bryce Lee39791592017-04-26 09:29:12 -0700136import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137import android.os.Bundle;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700138import android.os.Debug;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800139import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140import android.os.Message;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800141import android.os.PersistableBundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142import android.os.Process;
Dianne Hackborn39792d22010-08-19 18:01:52 -0700143import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144import android.os.SystemClock;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800145import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700146import android.os.UserHandle;
Amith Yamasani0af6fa72016-01-17 15:36:19 -0800147import android.service.voice.IVoiceInteractionSession;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148import android.util.EventLog;
149import android.util.Log;
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700150import android.util.MergedConfiguration;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700151import android.util.Slog;
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700152import android.util.TimeUtils;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700153import android.view.AppTransitionAnimationSpec;
Jorim Jaggi34795e32017-05-12 17:27:46 +0200154import android.view.IAppTransitionAnimationSpecsFuture;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155import android.view.IApplicationToken;
Jorim Jaggife762342016-10-13 14:33:27 +0200156import android.view.WindowManager.LayoutParams;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700157
Andrii Kulian3a1619d2017-07-07 14:38:09 -0700158import com.android.internal.annotations.VisibleForTesting;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800159import com.android.internal.app.ResolverActivity;
160import com.android.internal.content.ReferrerIntent;
161import com.android.internal.util.XmlUtils;
162import com.android.server.AttributeCache;
Ruben Brunkf53497c2017-03-27 20:26:17 -0700163import com.android.server.AttributeCache.Entry;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800164import com.android.server.am.ActivityStack.ActivityState;
165import com.android.server.am.ActivityStackSupervisor.ActivityContainer;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800166import com.android.server.wm.AppWindowContainerController;
167import com.android.server.wm.AppWindowContainerListener;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800168import com.android.server.wm.TaskWindowContainerController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169
Jorim Jaggi02886a82016-12-06 09:10:06 -0800170import org.xmlpull.v1.XmlPullParser;
171import org.xmlpull.v1.XmlPullParserException;
172import org.xmlpull.v1.XmlSerializer;
173
Suprabh Shukla23593142015-11-03 17:31:15 -0800174import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -0700175import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176import java.io.PrintWriter;
177import java.lang.ref.WeakReference;
178import java.util.ArrayList;
Todd Kennedy39bfee52016-02-24 10:28:21 -0800179import java.util.Arrays;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180import java.util.HashSet;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700181import java.util.List;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700182import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183
184/**
185 * An entry in the history stack, representing an activity.
186 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700187final class ActivityRecord extends ConfigurationContainer implements AppWindowContainerListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800188 private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityRecord" : TAG_AM;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700189 private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION;
190 private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE;
191 private static final String TAG_SCREENSHOTS = TAG + POSTFIX_SCREENSHOTS;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700192 private static final String TAG_STATES = TAG + POSTFIX_STATES;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700193 private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH;
194 private static final String TAG_THUMBNAILS = TAG + POSTFIX_THUMBNAILS;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700195 private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY;
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800196
Wale Ogunwale3ab9a272015-03-16 09:55:45 -0700197 private static final boolean SHOW_ACTIVITY_START_TIME = true;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700198 private static final String RECENTS_PACKAGE_NAME = "com.android.systemui.recents";
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700199
Craig Mautner21d24a22014-04-23 11:45:37 -0700200 private static final String ATTR_ID = "id";
201 private static final String TAG_INTENT = "intent";
202 private static final String ATTR_USERID = "user_id";
203 private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle";
204 private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700205 private static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package";
Craig Mautner21d24a22014-04-23 11:45:37 -0700206 private static final String ATTR_RESOLVEDTYPE = "resolved_type";
207 private static final String ATTR_COMPONENTSPECIFIED = "component_specified";
Dianne Hackborn337abb32014-09-24 12:44:29 -0700208 static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_";
Craig Mautner21d24a22014-04-23 11:45:37 -0700209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 final ActivityManagerService service; // owner
Dianne Hackbornbe707852011-11-11 14:32:10 -0800211 final IApplicationToken.Stub appToken; // window manager token
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800212 AppWindowContainerController mWindowContainerController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 final ActivityInfo info; // all about me
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700214 final ApplicationInfo appInfo; // information about activity's app
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800215 final int launchedFromPid; // always the pid who started the activity.
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700216 final int launchedFromUid; // always the uid who started the activity.
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800217 final String launchedFromPackage; // always the package who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -0700218 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 final Intent intent; // the original intent that generated us
220 final ComponentName realActivity; // the intent component, or target of an alias.
221 final String shortComponentName; // the short component name of the intent
222 final String resolvedType; // as per original caller;
223 final String packageName; // the package implementing intent's component
224 final String processName; // process where this component wants to run
225 final String taskAffinity; // as per ActivityInfo.taskAffinity
226 final boolean stateNotNeeded; // As per ActivityInfo.flags
Craig Mautner4addfc52013-06-25 08:05:45 -0700227 boolean fullscreen; // covers the full screen?
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800228 final boolean noDisplay; // activity is not displayed?
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800229 private final boolean componentSpecified; // did caller specify an explicit component?
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700230 final boolean rootVoiceInteraction; // was this the root activity of a voice interaction?
Craig Mautner86d67a42013-05-14 10:34:38 -0700231
232 static final int APPLICATION_ACTIVITY_TYPE = 0;
233 static final int HOME_ACTIVITY_TYPE = 1;
234 static final int RECENTS_ACTIVITY_TYPE = 2;
Winson Chung83471632016-12-13 11:02:12 -0800235 static final int ASSISTANT_ACTIVITY_TYPE = 3;
Craig Mautner2c1faed2013-07-23 12:56:02 -0700236 int mActivityType;
Craig Mautner86d67a42013-05-14 10:34:38 -0700237
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800238 private CharSequence nonLocalizedLabel; // the label information from the package mgr.
239 private int labelRes; // the label information from the package mgr.
240 private int icon; // resource identifier of activity's icon.
241 private int logo; // resource identifier of activity's logo.
242 private int theme; // resource identifier of activity's theme.
243 private int realTheme; // actual theme resource we will use, never 0.
244 private int windowFlags; // custom window flags for preview window.
Bryce Leeaf691c02017-03-20 14:20:22 -0700245 private TaskRecord task; // the task this is in.
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800246 private long createTime = System.currentTimeMillis();
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700247 long displayStartTime; // when we started launching this activity
248 long fullyDrawnStartTime; // when we started launching this activity
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800249 private long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -0800250 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700251 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700252 long pauseTime; // last time we started pausing the activity
253 long launchTickTime; // base time for launch tick messages
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700254 // Last configuration reported to the activity in the client process.
255 private MergedConfiguration mLastReportedConfiguration;
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800256 private int mLastReportedDisplayId;
Winson Chung609e1e92017-05-08 10:52:12 -0700257 private boolean mLastReportedMultiWindowMode;
258 private boolean mLastReportedPictureInPictureMode;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700259 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700260 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 final String resultWho; // additional identifier for use by resultTo.
262 final int requestCode; // code given by requester (resultTo)
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800263 ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800265 ArrayList<ReferrerIntent> newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700266 ActivityOptions pendingOptions; // most recently given options
George Mount6ba042b2014-07-28 11:12:28 -0700267 ActivityOptions returningOptions; // options that are coming back via convertToTranslucent
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700268 AppTimeTracker appTimeTracker; // set if we are tracking the time in this app/task/activity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700270 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700271 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700272 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 Bundle icicle; // last saved activity state
Craig Mautnera0026042014-04-23 11:45:37 -0700274 PersistableBundle persistentState; // last persistently saved activity state
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 boolean frontOfTask; // is this the root activity of its task?
276 boolean launchFailed; // set if a launched failed, to abort on 2nd try
277 boolean haveState; // have we gotten the last activity state?
278 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700279 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 boolean finishing; // activity in pending finish list?
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800281 boolean deferRelaunchUntilPaused; // relaunch of activity is being deferred until pause is
282 // completed
283 boolean preserveWindowOnDeferredRelaunch; // activity windows are preserved on deferred relaunch
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 int configChangeFlags; // which config values have changed
Wale Ogunwaleec950642017-04-25 07:44:21 -0700285 private boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 int launchMode; // the launch mode activity attribute.
287 boolean visible; // does this activity's window need to be shown?
Jorim Jaggi241ae102016-11-02 21:57:33 -0700288 boolean visibleIgnoringKeyguard; // is this activity visible, ignoring the fact that Keyguard
289 // might hide this activity?
Wale Ogunwaleec950642017-04-25 07:44:21 -0700290 private boolean mDeferHidingClient; // If true we told WM to defer reporting to the client
291 // process that it is hidden.
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800292 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 boolean nowVisible; // is this activity's window visible?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 boolean idle; // has the activity gone idle?
295 boolean hasBeenLaunched;// has this activity ever been launched?
296 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400297 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400298 boolean forceNewConfig; // force re-create with new config next time
Winson Chungc2baac02017-01-11 13:34:47 -0800299 boolean supportsPictureInPictureWhilePausing; // This flag is set by the system to indicate
300 // that the activity can enter picture in picture while pausing (ie. only when another
301 // task is brought to front or started)
Winson Chung709904f2017-04-25 11:00:48 -0700302 PictureInPictureParams pictureInPictureArgs = new PictureInPictureParams.Builder().build();
303 // The PiP params used when deferring the entering of picture-in-picture.
Dianne Hackborn07981492013-01-28 11:36:23 -0800304 int launchCount; // count of launches since last state
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800305 long lastLaunchTime; // time of last launch of this activity
Ruben Brunke24b9a62016-02-16 21:38:24 -0800306 ComponentName requestedVrComponent; // the requested component for handling VR mode.
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800307 ArrayList<ActivityContainer> mChildContainers = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700309 String stringName; // for caching of toString().
Craig Mautnerde4ef022013-04-07 19:01:33 -0700310
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700311 private boolean inHistory; // are we in the history stack?
Craig Mautnerde4ef022013-04-07 19:01:33 -0700312 final ActivityStackSupervisor mStackSupervisor;
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800313
314 static final int STARTING_WINDOW_NOT_SHOWN = 0;
315 static final int STARTING_WINDOW_SHOWN = 1;
316 static final int STARTING_WINDOW_REMOVED = 2;
317 int mStartingWindowState = STARTING_WINDOW_NOT_SHOWN;
Wale Ogunwale3b232392016-05-13 15:37:13 -0700318 boolean mTaskOverlay = false; // Task is always on-top of other activities in the task.
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800319
Jorim Jaggic2f262b2015-12-07 16:59:10 -0800320 boolean mUpdateTaskThumbnailWhenHidden;
Craig Mautnere0a38842013-12-16 16:14:02 -0800321 ActivityContainer mInitialActivityContainer;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700322
Craig Mautner21d24a22014-04-23 11:45:37 -0700323 TaskDescription taskDescription; // the recents information for this activity
Craig Mautnerbb742462014-07-07 15:28:55 -0700324 boolean mLaunchTaskBehind; // this activity is actively being launched with
325 // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed.
Craig Mautner2fbd7542014-03-21 09:34:07 -0700326
Filip Gruszczynski23493322015-07-29 17:02:59 -0700327 // These configurations are collected from application's resources based on size-sensitive
328 // qualifiers. For example, layout-w800dp will be added to mHorizontalSizeConfigurations as 800
329 // and drawable-sw400dp will be added to both as 400.
330 private int[] mVerticalSizeConfigurations;
331 private int[] mHorizontalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700332 private int[] mSmallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700333
Amith Yamasani0af6fa72016-01-17 15:36:19 -0800334 boolean pendingVoiceInteractionStart; // Waiting for activity-invoked voice session
335 IVoiceInteractionSession voiceSession; // Voice interaction session for this activity
336
Robert Carrd2265122016-08-05 10:25:21 -0700337 // A hint to override the window specified rotation animation, or -1
338 // to use the window specified value. We use this so that
339 // we can select the right animation in the cases of starting
340 // windows, where the app hasn't had time to set a value
341 // on the window.
342 int mRotationAnimationHint = -1;
Robert Carrfd10cd12016-06-29 16:41:50 -0700343
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700344 // The bounds of this activity. Mainly used for aspect-ratio compatibility.
345 // TODO(b/36505427): Every level on ConfigurationContainer now has bounds information, which
346 // directly affects the configuration. We should probably move this into that class and have it
347 // handle calculating override configuration from the bounds.
348 private final Rect mBounds = new Rect();
349
Andrii Kulian21713ac2016-10-12 22:05:05 -0700350 /**
351 * Temp configs used in {@link #ensureActivityConfigurationLocked(int, boolean)}
352 */
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700353 private final Configuration mTmpConfig = new Configuration();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700354 private final Rect mTmpBounds = new Rect();
Andrii Kulian21713ac2016-10-12 22:05:05 -0700355
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800356 private static String startingWindowStateToString(int state) {
357 switch (state) {
358 case STARTING_WINDOW_NOT_SHOWN:
359 return "STARTING_WINDOW_NOT_SHOWN";
360 case STARTING_WINDOW_SHOWN:
361 return "STARTING_WINDOW_SHOWN";
362 case STARTING_WINDOW_REMOVED:
363 return "STARTING_WINDOW_REMOVED";
364 default:
365 return "unknown state=" + state;
366 }
367 }
368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700370 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700371 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
372 pw.print(" processName="); pw.println(processName);
373 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Craig Mautnere11f2b72013-04-01 12:37:17 -0700374 pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800375 pw.print(" userId="); pw.println(userId);
376 pw.print(prefix); pw.print("app="); pw.println(app);
377 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700378 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
379 pw.print(" task="); pw.println(task);
380 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700381 pw.print(prefix); pw.print("realActivity=");
382 pw.println(realActivity.flattenToShortString());
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700383 if (appInfo != null) {
384 pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir);
385 if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) {
386 pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir);
387 }
388 pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir);
Todd Kennedy39bfee52016-02-24 10:28:21 -0800389 if (appInfo.splitSourceDirs != null) {
390 pw.print(prefix); pw.print("splitDir=");
391 pw.println(Arrays.toString(appInfo.splitSourceDirs));
392 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800393 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700394 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
395 pw.print(" componentSpecified="); pw.print(componentSpecified);
Craig Mautner86d67a42013-05-14 10:34:38 -0700396 pw.print(" mActivityType="); pw.println(mActivityType);
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700397 if (rootVoiceInteraction) {
398 pw.print(prefix); pw.print("rootVoiceInteraction="); pw.println(rootVoiceInteraction);
399 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800400 pw.print(prefix); pw.print("compat="); pw.print(compat);
401 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
402 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
403 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700404 pw.println(prefix + "mLastReportedConfigurations:");
405 mLastReportedConfiguration.dump(pw, prefix + " ");
406
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700407 pw.print(prefix); pw.print("CurrentConfiguration="); pw.println(getConfiguration());
408 if (!getOverrideConfiguration().equals(EMPTY)) {
409 pw.println(prefix + "OverrideConfiguration=" + getOverrideConfiguration());
410 }
411 if (!mBounds.isEmpty()) {
412 pw.println(prefix + "mBounds=" + mBounds);
413 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700414 if (resultTo != null || resultWho != null) {
415 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
416 pw.print(" resultWho="); pw.print(resultWho);
417 pw.print(" resultCode="); pw.println(requestCode);
418 }
Craig Mautner29c58ca2014-10-14 16:17:06 -0700419 if (taskDescription != null) {
420 final String iconFilename = taskDescription.getIconFilename();
421 if (iconFilename != null || taskDescription.getLabel() != null ||
422 taskDescription.getPrimaryColor() != 0) {
423 pw.print(prefix); pw.print("taskDescription:");
424 pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename());
425 pw.print(" label=\""); pw.print(taskDescription.getLabel());
426 pw.print("\"");
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200427 pw.print(" primaryColor=");
Craig Mautner29c58ca2014-10-14 16:17:06 -0700428 pw.println(Integer.toHexString(taskDescription.getPrimaryColor()));
Wale Ogunwale9c64cb62017-04-12 13:39:59 -0700429 pw.print(prefix + " backgroundColor=");
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200430 pw.println(Integer.toHexString(taskDescription.getBackgroundColor()));
Wale Ogunwale9c64cb62017-04-12 13:39:59 -0700431 pw.print(prefix + " statusBarColor=");
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200432 pw.println(Integer.toHexString(taskDescription.getStatusBarColor()));
Wale Ogunwale9c64cb62017-04-12 13:39:59 -0700433 pw.print(prefix + " navigationBarColor=");
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200434 pw.println(Integer.toHexString(taskDescription.getNavigationBarColor()));
Craig Mautner29c58ca2014-10-14 16:17:06 -0700435 }
436 if (iconFilename == null && taskDescription.getIcon() != null) {
437 pw.print(prefix); pw.println("taskDescription contains Bitmap");
438 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700439 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700440 if (results != null) {
441 pw.print(prefix); pw.print("results="); pw.println(results);
442 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700443 if (pendingResults != null && pendingResults.size() > 0) {
444 pw.print(prefix); pw.println("Pending Results:");
445 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
446 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
447 pw.print(prefix); pw.print(" - ");
448 if (pir == null) {
449 pw.println("null");
450 } else {
451 pw.println(pir);
452 pir.dump(pw, prefix + " ");
453 }
454 }
455 }
456 if (newIntents != null && newIntents.size() > 0) {
457 pw.print(prefix); pw.println("Pending New Intents:");
458 for (int i=0; i<newIntents.size(); i++) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800459 Intent intent = newIntents.get(i);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700460 pw.print(prefix); pw.print(" - ");
461 if (intent == null) {
462 pw.println("null");
463 } else {
464 pw.println(intent.toShortString(false, true, false, true));
465 }
466 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700467 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700468 if (pendingOptions != null) {
469 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
470 }
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700471 if (appTimeTracker != null) {
472 appTimeTracker.dumpWithHeader(pw, prefix, false);
473 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700474 if (uriPermissions != null) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700475 uriPermissions.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700476 }
477 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800478 pw.print(" launchCount="); pw.print(launchCount);
479 pw.print(" lastLaunchTime=");
480 if (lastLaunchTime == 0) pw.print("0");
481 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
482 pw.println();
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700483 pw.print(prefix); pw.print("haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700484 pw.print(" icicle="); pw.println(icicle);
485 pw.print(prefix); pw.print("state="); pw.print(state);
486 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700487 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700488 pw.print(" finishing="); pw.println(finishing);
489 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
490 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700491 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800492 pw.print(" sleeping="); pw.print(sleeping);
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800493 pw.print(" idle="); pw.print(idle);
494 pw.print(" mStartingWindowState=");
495 pw.println(startingWindowStateToString(mStartingWindowState));
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800496 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
497 pw.print(" noDisplay="); pw.print(noDisplay);
498 pw.print(" immersive="); pw.print(immersive);
499 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800500 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400501 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700502 pw.print(prefix); pw.print("mActivityType=");
503 pw.println(activityTypeToString(mActivityType));
Ruben Brunke24b9a62016-02-16 21:38:24 -0800504 if (requestedVrComponent != null) {
505 pw.print(prefix);
506 pw.print("requestedVrComponent=");
507 pw.println(requestedVrComponent);
508 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700509 if (displayStartTime != 0 || startTime != 0) {
510 pw.print(prefix); pw.print("displayStartTime=");
511 if (displayStartTime == 0) pw.print("0");
512 else TimeUtils.formatDuration(displayStartTime, now, pw);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700513 pw.print(" startTime=");
514 if (startTime == 0) pw.print("0");
515 else TimeUtils.formatDuration(startTime, now, pw);
516 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700517 }
Bryce Lee4a194382017-04-04 14:32:48 -0700518 final boolean waitingVisible =
519 mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(this);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800520 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700521 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800522 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700523 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700524 if (lastVisibleTime == 0) pw.print("0");
525 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
526 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700527 }
Wale Ogunwaleec950642017-04-25 07:44:21 -0700528 if (mDeferHidingClient) {
529 pw.println(prefix + "mDeferHidingClient=" + mDeferHidingClient);
530 }
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800531 if (deferRelaunchUntilPaused || configChangeFlags != 0) {
532 pw.print(prefix); pw.print("deferRelaunchUntilPaused="); pw.print(deferRelaunchUntilPaused);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700533 pw.print(" configChangeFlags=");
534 pw.println(Integer.toHexString(configChangeFlags));
535 }
536 if (connections != null) {
537 pw.print(prefix); pw.print("connections="); pw.println(connections);
538 }
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800539 if (info != null) {
540 pw.println(prefix + "resizeMode=" + ActivityInfo.resizeModeToString(info.resizeMode));
Winson Chung609e1e92017-05-08 10:52:12 -0700541 pw.println(prefix + "mLastReportedMultiWindowMode=" + mLastReportedMultiWindowMode
542 + " mLastReportedPictureInPictureMode=" + mLastReportedPictureInPictureMode);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700543 if (info.supportsPictureInPicture()) {
544 pw.println(prefix + "supportsPictureInPicture=" + info.supportsPictureInPicture());
545 pw.println(prefix + "supportsPictureInPictureWhilePausing: "
546 + supportsPictureInPictureWhilePausing);
547 }
548 if (info.maxAspectRatio != 0) {
549 pw.println(prefix + "maxAspectRatio=" + info.maxAspectRatio);
550 }
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800551 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 }
553
Andrii Kulian21713ac2016-10-12 22:05:05 -0700554 private boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700555 return crossesSizeThreshold(mHorizontalSizeConfigurations, firstDp, secondDp);
556 }
557
Andrii Kulian21713ac2016-10-12 22:05:05 -0700558 private boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700559 return crossesSizeThreshold(mVerticalSizeConfigurations, firstDp, secondDp);
560 }
561
Andrii Kulian21713ac2016-10-12 22:05:05 -0700562 private boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700563 return crossesSizeThreshold(mSmallestSizeConfigurations, firstDp, secondDp);
564 }
565
Filip Gruszczynski23493322015-07-29 17:02:59 -0700566 /**
567 * The purpose of this method is to decide whether the activity needs to be relaunched upon
568 * changing its size. In most cases the activities don't need to be relaunched, if the resize
569 * is small, all the activity content has to do is relayout itself within new bounds. There are
570 * cases however, where the activity's content would be completely changed in the new size and
571 * the full relaunch is required.
572 *
573 * The activity will report to us vertical and horizontal thresholds after which a relaunch is
574 * required. These thresholds are collected from the application resource qualifiers. For
575 * example, if application has layout-w600dp resource directory, then it needs a relaunch when
576 * we resize from width of 650dp to 550dp, as it crosses the 600dp threshold. However, if
577 * it resizes width from 620dp to 700dp, it won't be relaunched as it stays on the same side
578 * of the threshold.
579 */
580 private static boolean crossesSizeThreshold(int[] thresholds, int firstDp,
581 int secondDp) {
582 if (thresholds == null) {
583 return false;
584 }
585 for (int i = thresholds.length - 1; i >= 0; i--) {
586 final int threshold = thresholds[i];
587 if ((firstDp < threshold && secondDp >= threshold)
588 || (firstDp >= threshold && secondDp < threshold)) {
589 return true;
590 }
591 }
592 return false;
593 }
594
Andrii Kulian21713ac2016-10-12 22:05:05 -0700595 void setSizeConfigurations(int[] horizontalSizeConfiguration,
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700596 int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700597 mHorizontalSizeConfigurations = horizontalSizeConfiguration;
598 mVerticalSizeConfigurations = verticalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700599 mSmallestSizeConfigurations = smallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700600 }
601
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800602 private void scheduleActivityMovedToDisplay(int displayId, Configuration config) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800603 if (app == null || app.thread == null) {
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800604 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.w(TAG,
605 "Can't report activity moved to display - client not running, activityRecord="
606 + this + ", displayId=" + displayId);
Wale Ogunwale22e25262016-02-01 10:32:02 -0800607 return;
608 }
609 try {
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800610 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
611 "Reporting activity moved to display" + ", activityRecord=" + this
612 + ", displayId=" + displayId + ", config=" + config);
Chong Zhang6be533e2016-06-17 16:24:21 -0700613
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800614 app.thread.scheduleActivityMovedToDisplay(appToken, displayId,
615 new Configuration(config));
616 } catch (RemoteException e) {
617 // If process died, whatever.
618 }
619 }
620
621 private void scheduleConfigurationChanged(Configuration config) {
622 if (app == null || app.thread == null) {
623 if (DEBUG_CONFIGURATION) Slog.w(TAG,
624 "Can't report activity configuration update - client not running"
625 + ", activityRecord=" + this);
626 return;
627 }
628 try {
629 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + this + ", config: "
630 + config);
631
632 app.thread.scheduleActivityConfigurationChanged(appToken, new Configuration(config));
Wale Ogunwale22e25262016-02-01 10:32:02 -0800633 } catch (RemoteException e) {
634 // If process died, whatever.
635 }
636 }
637
Winson Chung5af42fc2017-03-24 17:11:33 -0700638 void updateMultiWindowMode() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700639 if (task == null || task.getStack() == null || app == null || app.thread == null) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800640 return;
641 }
Winson Chung5af42fc2017-03-24 17:11:33 -0700642
643 // An activity is considered to be in multi-window mode if its task isn't fullscreen.
644 final boolean inMultiWindowMode = !task.mFullscreen;
Winson Chung609e1e92017-05-08 10:52:12 -0700645 if (inMultiWindowMode != mLastReportedMultiWindowMode) {
646 mLastReportedMultiWindowMode = inMultiWindowMode;
Winson Chung5af42fc2017-03-24 17:11:33 -0700647 scheduleMultiWindowModeChanged(getConfiguration());
648 }
649 }
650
651 private void scheduleMultiWindowModeChanged(Configuration overrideConfig) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800652 try {
Winson Chung609e1e92017-05-08 10:52:12 -0700653 app.thread.scheduleMultiWindowModeChanged(appToken, mLastReportedMultiWindowMode,
Winson Chung5af42fc2017-03-24 17:11:33 -0700654 overrideConfig);
Wale Ogunwale22e25262016-02-01 10:32:02 -0800655 } catch (Exception e) {
656 // If process died, I don't care.
657 }
658 }
659
Winson Chung5af42fc2017-03-24 17:11:33 -0700660 void updatePictureInPictureMode(Rect targetStackBounds) {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700661 if (task == null || task.getStack() == null || app == null || app.thread == null) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800662 return;
663 }
Winson Chung5af42fc2017-03-24 17:11:33 -0700664
665 final boolean inPictureInPictureMode = (task.getStackId() == PINNED_STACK_ID) &&
666 (targetStackBounds != null);
Winson Chung609e1e92017-05-08 10:52:12 -0700667 if (inPictureInPictureMode != mLastReportedPictureInPictureMode) {
Winson Chung5af42fc2017-03-24 17:11:33 -0700668 // Picture-in-picture mode changes also trigger a multi-window mode change as well, so
669 // update that here in order
Winson Chung609e1e92017-05-08 10:52:12 -0700670 mLastReportedPictureInPictureMode = inPictureInPictureMode;
671 mLastReportedMultiWindowMode = inPictureInPictureMode;
Winson Chung5af42fc2017-03-24 17:11:33 -0700672 final Configuration newConfig = task.computeNewOverrideConfigurationForBounds(
673 targetStackBounds, null);
674 schedulePictureInPictureModeChanged(newConfig);
675 scheduleMultiWindowModeChanged(newConfig);
676 }
677 }
678
679 private void schedulePictureInPictureModeChanged(Configuration overrideConfig) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800680 try {
Winson Chung609e1e92017-05-08 10:52:12 -0700681 app.thread.schedulePictureInPictureModeChanged(appToken,
682 mLastReportedPictureInPictureMode,
Winson Chung5af42fc2017-03-24 17:11:33 -0700683 overrideConfig);
Wale Ogunwale22e25262016-02-01 10:32:02 -0800684 } catch (Exception e) {
685 // If process died, no one cares.
Filip Gruszczynskica664812015-12-04 12:43:36 -0800686 }
687 }
688
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800689 boolean isFreeform() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700690 return task != null && task.getStackId() == FREEFORM_WORKSPACE_STACK_ID;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800691 }
692
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700693 @Override
694 protected int getChildCount() {
695 // {@link ActivityRecord} is a leaf node and has no children.
696 return 0;
697 }
698
699 @Override
700 protected ConfigurationContainer getChildAt(int index) {
701 return null;
702 }
703
704 @Override
705 protected ConfigurationContainer getParent() {
Bryce Leeaf691c02017-03-20 14:20:22 -0700706 return getTask();
707 }
708
709 TaskRecord getTask() {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700710 return task;
711 }
712
Bryce Leeaf691c02017-03-20 14:20:22 -0700713 /**
714 * Sets reference to the {@link TaskRecord} the {@link ActivityRecord} will treat as its parent.
715 * Note that this does not actually add the {@link ActivityRecord} as a {@link TaskRecord}
716 * children. However, this method will clean up references to this {@link ActivityRecord} in
717 * {@link ActivityStack}.
718 * @param task The new parent {@link TaskRecord}.
719 */
720 void setTask(TaskRecord task) {
721 setTask(task, false /*reparenting*/);
722 }
723
724 /**
725 * This method should only be called by {@link TaskRecord#removeActivity(ActivityRecord)}.
726 */
727 void setTask(TaskRecord task, boolean reparenting) {
728 // Do nothing if the {@link TaskRecord} is the same as the current {@link getTask}.
729 if (task != null && task == getTask()) {
730 return;
731 }
732
733 final ActivityStack stack = getStack();
734
735 // If the new {@link TaskRecord} is from a different {@link ActivityStack}, remove this
736 // {@link ActivityRecord} from its current {@link ActivityStack}.
737 if (!reparenting && stack != null && (task == null || stack != task.getStack())) {
738 stack.onActivityRemovedFromStack(this);
739 }
740
741 this.task = task;
742
743 if (!reparenting) {
744 onParentChanged();
745 }
746 }
747
Dianne Hackbornbe707852011-11-11 14:32:10 -0800748 static class Token extends IApplicationToken.Stub {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700749 private final WeakReference<ActivityRecord> weakActivity;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800750
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800751 Token(ActivityRecord activity) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800752 weakActivity = new WeakReference<>(activity);
Wale Ogunwale7d701172015-03-11 15:36:30 -0700753 }
754
Andrii Kulian21713ac2016-10-12 22:05:05 -0700755 private static ActivityRecord tokenToActivityRecordLocked(Token token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700756 if (token == null) {
757 return null;
758 }
759 ActivityRecord r = token.weakActivity.get();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700760 if (r == null || r.getStack() == null) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700761 return null;
762 }
763 return r;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800764 }
765
Craig Mautnerde4ef022013-04-07 19:01:33 -0700766 @Override
Dianne Hackbornbe707852011-11-11 14:32:10 -0800767 public String toString() {
768 StringBuilder sb = new StringBuilder(128);
769 sb.append("Token{");
770 sb.append(Integer.toHexString(System.identityHashCode(this)));
771 sb.append(' ');
772 sb.append(weakActivity.get());
773 sb.append('}');
774 return sb.toString();
775 }
776 }
777
Wale Ogunwale7d701172015-03-11 15:36:30 -0700778 static ActivityRecord forTokenLocked(IBinder token) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800779 try {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700780 return Token.tokenToActivityRecordLocked((Token)token);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800781 } catch (ClassCastException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800782 Slog.w(TAG, "Bad activity token: " + token, e);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800783 return null;
784 }
785 }
786
Chong Zhang85ee6542015-10-02 13:36:38 -0700787 boolean isResolverActivity() {
788 return ResolverActivity.class.getName().equals(realActivity.getClassName());
Craig Mautnerac6f8432013-07-17 13:24:59 -0700789 }
790
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800791 ActivityRecord(ActivityManagerService _service, ProcessRecord _caller, int _launchedFromPid,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800792 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800793 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700794 ActivityRecord _resultTo, String _resultWho, int _reqCode,
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700795 boolean _componentSpecified, boolean _rootVoiceInteraction,
796 ActivityStackSupervisor supervisor,
Wale Ogunwale1affbbc2016-05-01 09:03:52 -0700797 ActivityContainer container, ActivityOptions options, ActivityRecord sourceRecord) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 service = _service;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800799 appToken = new Token(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 info = aInfo;
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800801 launchedFromPid = _launchedFromPid;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800802 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800803 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700804 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 intent = _intent;
806 shortComponentName = _intent.getComponent().flattenToShortString();
807 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800808 componentSpecified = _componentSpecified;
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700809 rootVoiceInteraction = _rootVoiceInteraction;
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700810 mLastReportedConfiguration = new MergedConfiguration(_configuration);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 resultTo = _resultTo;
812 resultWho = _resultWho;
813 requestCode = _reqCode;
Ruben Brunkf53497c2017-03-27 20:26:17 -0700814 state = INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800815 frontOfTask = false;
816 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800817 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700818 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 finishing = false;
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800820 deferRelaunchUntilPaused = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 keysPaused = false;
822 inHistory = false;
Chong Zhanga48ef662015-08-18 19:21:47 -0700823 visible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 nowVisible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 idle = false;
826 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700827 mStackSupervisor = supervisor;
Craig Mautnere0a38842013-12-16 16:14:02 -0800828 mInitialActivityContainer = container;
Robert Carr0f5d7532016-10-17 16:39:17 -0700829
830 mRotationAnimationHint = aInfo.rotationAnimation;
831
Craig Mautner233ceee2014-05-09 17:05:11 -0700832 if (options != null) {
Chong Zhang280d3322015-11-03 17:27:26 -0800833 pendingOptions = options;
Craig Mautnerbb742462014-07-07 15:28:55 -0700834 mLaunchTaskBehind = pendingOptions.getLaunchTaskBehind();
Robert Carr0f5d7532016-10-17 16:39:17 -0700835
836 final int rotationAnimation = pendingOptions.getRotationAnimationHint();
837 // Only override manifest supplied option if set.
838 if (rotationAnimation >= 0) {
839 mRotationAnimationHint = rotationAnimation;
840 }
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700841 PendingIntent usageReport = pendingOptions.getUsageTimeReport();
842 if (usageReport != null) {
843 appTimeTracker = new AppTimeTracker(usageReport);
844 }
Craig Mautner233ceee2014-05-09 17:05:11 -0700845 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800847 // This starts out true, since the initial state of an activity is that we have everything,
848 // and we shouldn't never consider it lacking in state to be removed if it dies.
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700849 haveState = true;
850
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800851 // If the class name in the intent doesn't match that of the target, this is
852 // probably an alias. We have to create a new ComponentName object to keep track
853 // of the real activity name, so that FLAG_ACTIVITY_CLEAR_TOP is handled properly.
854 if (aInfo.targetActivity == null
855 || (aInfo.targetActivity.equals(_intent.getComponent().getClassName())
856 && (aInfo.launchMode == LAUNCH_MULTIPLE
857 || aInfo.launchMode == LAUNCH_SINGLE_TOP))) {
858 realActivity = _intent.getComponent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800859 } else {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800860 realActivity = new ComponentName(aInfo.packageName, aInfo.targetActivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800862 taskAffinity = aInfo.taskAffinity;
863 stateNotNeeded = (aInfo.flags & FLAG_STATE_NOT_NEEDED) != 0;
864 appInfo = aInfo.applicationInfo;
865 nonLocalizedLabel = aInfo.nonLocalizedLabel;
866 labelRes = aInfo.labelRes;
867 if (nonLocalizedLabel == null && labelRes == 0) {
868 ApplicationInfo app = aInfo.applicationInfo;
869 nonLocalizedLabel = app.nonLocalizedLabel;
870 labelRes = app.labelRes;
871 }
872 icon = aInfo.getIconResource();
873 logo = aInfo.getLogoResource();
874 theme = aInfo.getThemeResource();
875 realTheme = theme;
876 if (realTheme == 0) {
877 realTheme = aInfo.applicationInfo.targetSdkVersion < HONEYCOMB
878 ? android.R.style.Theme : android.R.style.Theme_Holo;
879 }
880 if ((aInfo.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
881 windowFlags |= LayoutParams.FLAG_HARDWARE_ACCELERATED;
882 }
883 if ((aInfo.flags & FLAG_MULTIPROCESS) != 0 && _caller != null
884 && (aInfo.applicationInfo.uid == SYSTEM_UID
885 || aInfo.applicationInfo.uid == _caller.info.uid)) {
886 processName = _caller.processName;
887 } else {
888 processName = aInfo.processName;
889 }
890
891 if ((aInfo.flags & FLAG_EXCLUDE_FROM_RECENTS) != 0) {
892 intent.addFlags(FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
893 }
894
895 packageName = aInfo.applicationInfo.packageName;
896 launchMode = aInfo.launchMode;
897
Ruben Brunkf53497c2017-03-27 20:26:17 -0700898 Entry ent = AttributeCache.instance().get(packageName,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800899 realTheme, com.android.internal.R.styleable.Window, userId);
Bryce Lee39791592017-04-26 09:29:12 -0700900 fullscreen = ent != null && !ActivityInfo.isTranslucentOrFloating(ent.array);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800901 noDisplay = ent != null && ent.array.getBoolean(
902 com.android.internal.R.styleable.Window_windowNoDisplay, false);
903
Winson Chung83471632016-12-13 11:02:12 -0800904 setActivityType(_componentSpecified, _launchedFromUid, _intent, options, sourceRecord);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800905
906 immersive = (aInfo.flags & FLAG_IMMERSIVE) != 0;
907
908 requestedVrComponent = (aInfo.requestedVrComponent == null) ?
909 null : ComponentName.unflattenFromString(aInfo.requestedVrComponent);
910 }
911
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800912 AppWindowContainerController getWindowContainerController() {
913 return mWindowContainerController;
914 }
915
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800916 void createWindowContainer() {
917 if (mWindowContainerController != null) {
918 throw new IllegalArgumentException("Window container=" + mWindowContainerController
919 + " already created for r=" + this);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800920 }
921
922 inHistory = true;
923
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800924 final TaskWindowContainerController taskController = task.getWindowContainerController();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800925
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700926 // TODO(b/36505427): Maybe this call should be moved inside updateOverrideConfiguration()
927 task.updateOverrideConfigurationFromLaunchBounds();
928 // Make sure override configuration is up-to-date before using to create window controller.
929 updateOverrideConfiguration();
930
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800931 mWindowContainerController = new AppWindowContainerController(taskController, appToken,
932 this, Integer.MAX_VALUE /* add on top */, info.screenOrientation, fullscreen,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800933 (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, info.configChanges,
934 task.voiceSession != null, mLaunchTaskBehind, isAlwaysFocusable(),
935 appInfo.targetSdkVersion, mRotationAnimationHint,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700936 ActivityManagerService.getInputDispatchingTimeoutLocked(this) * 1000000L,
937 getOverrideConfiguration(), mBounds);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800938
939 task.addActivityToTop(this);
940
Winson Chung609e1e92017-05-08 10:52:12 -0700941 // When an activity is started directly into a split-screen fullscreen stack, we need to
942 // update the initial multi-window modes so that the callbacks are scheduled correctly when
943 // the user leaves that mode.
944 mLastReportedMultiWindowMode = !task.mFullscreen;
945 mLastReportedPictureInPictureMode = (task.getStackId() == PINNED_STACK_ID);
946
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800947 onOverrideConfigurationSent();
948 }
949
950 void removeWindowContainer() {
Wale Ogunwalecc367f42017-02-01 08:12:14 -0800951 // Resume key dispatching if it is currently paused before we remove the container.
952 resumeKeyDispatchingLocked();
953
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800954 mWindowContainerController.removeContainer(getDisplayId());
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800955 mWindowContainerController = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 }
957
Winson Chung30480042017-01-26 10:55:34 -0800958 /**
959 * Reparents this activity into {@param newTask} at the provided {@param position}. The caller
960 * should ensure that the {@param newTask} is not already the parent of this activity.
961 */
962 void reparent(TaskRecord newTask, int position, String reason) {
963 final TaskRecord prevTask = task;
964 if (prevTask == newTask) {
965 throw new IllegalArgumentException(reason + ": task=" + newTask
966 + " is already the parent of r=" + this);
967 }
968
Winson Chung74666102017-02-22 17:49:24 -0800969 // TODO: Ensure that we do not directly reparent activities across stacks, as that may leave
970 // the stacks in strange states. For now, we should use Task.reparent() to ensure that
971 // the stack is left in an OK state.
972 if (prevTask != null && newTask != null && prevTask.getStack() != newTask.getStack()) {
973 throw new IllegalArgumentException(reason + ": task=" + newTask
974 + " is in a different stack (" + newTask.getStackId() + ") than the parent of"
975 + " r=" + this + " (" + prevTask.getStackId() + ")");
976 }
977
Winson Chung30480042017-01-26 10:55:34 -0800978 // Must reparent first in window manager
979 mWindowContainerController.reparent(newTask.getWindowContainerController(), position);
980
Bryce Leeaf691c02017-03-20 14:20:22 -0700981 // Remove the activity from the old task and add it to the new task.
982 prevTask.removeActivity(this, true /*reparenting*/);
Bryce Lee0f9bde82017-02-22 16:39:06 -0800983
Winson Chung30480042017-01-26 10:55:34 -0800984 newTask.addActivityAtIndex(position, this);
985 }
986
Wale Ogunwale1affbbc2016-05-01 09:03:52 -0700987 private boolean isHomeIntent(Intent intent) {
Ruben Brunkf53497c2017-03-27 20:26:17 -0700988 return ACTION_MAIN.equals(intent.getAction())
989 && intent.hasCategory(CATEGORY_HOME)
Wale Ogunwale1affbbc2016-05-01 09:03:52 -0700990 && intent.getCategories().size() == 1
991 && intent.getData() == null
992 && intent.getType() == null;
993 }
994
Chong Zhangad24f962016-08-25 12:12:33 -0700995 static boolean isMainIntent(Intent intent) {
Ruben Brunkf53497c2017-03-27 20:26:17 -0700996 return ACTION_MAIN.equals(intent.getAction())
997 && intent.hasCategory(CATEGORY_LAUNCHER)
Chong Zhangad24f962016-08-25 12:12:33 -0700998 && intent.getCategories().size() == 1
999 && intent.getData() == null
1000 && intent.getType() == null;
1001 }
1002
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001003 private boolean canLaunchHomeActivity(int uid, ActivityRecord sourceRecord) {
1004 if (uid == Process.myUid() || uid == 0) {
1005 // System process can launch home activity.
1006 return true;
1007 }
1008 // Resolver activity can launch home activity.
1009 return sourceRecord != null && sourceRecord.isResolverActivity();
1010 }
1011
Winson Chung83471632016-12-13 11:02:12 -08001012 /**
1013 * @return whether the given package name can launch an assist activity.
1014 */
1015 private boolean canLaunchAssistActivity(String packageName) {
1016 if (service.mAssistUtils == null) {
1017 return false;
1018 }
1019
1020 final ComponentName assistComponent = service.mAssistUtils.getActiveServiceComponentName();
1021 if (assistComponent != null) {
1022 return assistComponent.getPackageName().equals(packageName);
1023 }
1024 return false;
1025 }
1026
1027 private void setActivityType(boolean componentSpecified, int launchedFromUid, Intent intent,
1028 ActivityOptions options, ActivityRecord sourceRecord) {
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001029 if ((!componentSpecified || canLaunchHomeActivity(launchedFromUid, sourceRecord))
1030 && isHomeIntent(intent) && !isResolverActivity()) {
1031 // This sure looks like a home activity!
1032 mActivityType = HOME_ACTIVITY_TYPE;
Wale Ogunwaledf241e92016-10-13 15:14:21 -07001033
1034 if (info.resizeMode == RESIZE_MODE_FORCE_RESIZEABLE
1035 || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) {
1036 // We only allow home activities to be resizeable if they explicitly requested it.
1037 info.resizeMode = RESIZE_MODE_UNRESIZEABLE;
1038 }
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001039 } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) {
1040 mActivityType = RECENTS_ACTIVITY_TYPE;
Winson Chung83471632016-12-13 11:02:12 -08001041 } else if (options != null && options.getLaunchStackId() == ASSISTANT_STACK_ID
1042 && canLaunchAssistActivity(launchedFromPackage)) {
1043 mActivityType = ASSISTANT_ACTIVITY_TYPE;
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001044 } else {
1045 mActivityType = APPLICATION_ACTIVITY_TYPE;
1046 }
1047 }
1048
Craig Mautnera228ae92014-07-09 05:44:55 -07001049 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001050 if (launchMode != LAUNCH_SINGLE_INSTANCE && launchMode != LAUNCH_SINGLE_TASK) {
Craig Mautnera228ae92014-07-09 05:44:55 -07001051 task.setTaskToAffiliateWith(taskToAffiliateWith);
1052 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001053 }
1054
Andrii Kulian02b7a832016-10-06 23:11:56 -07001055 /**
1056 * @return Stack value from current task, null if there is no task.
1057 */
Winson Chung55893332017-02-17 17:13:10 -08001058 <T extends ActivityStack> T getStack() {
1059 return task != null ? (T) task.getStack() : null;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001060 }
1061
Jorim Jaggicdfc04e2017-04-28 19:06:24 +02001062 int getStackId() {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001063 return getStack() != null ? getStack().mStackId : INVALID_STACK_ID;
1064 }
1065
Craig Mautner5eda9b32013-07-02 11:58:16 -07001066 boolean changeWindowTranslucency(boolean toOpaque) {
1067 if (fullscreen == toOpaque) {
1068 return false;
1069 }
Craig Mautner4addfc52013-06-25 08:05:45 -07001070
Craig Mautner5eda9b32013-07-02 11:58:16 -07001071 // Keep track of the number of fullscreen activities in this task.
1072 task.numFullscreen += toOpaque ? +1 : -1;
1073
1074 fullscreen = toOpaque;
1075 return true;
Craig Mautner4addfc52013-06-25 08:05:45 -07001076 }
1077
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001078 void takeFromHistory() {
1079 if (inHistory) {
1080 inHistory = false;
1081 if (task != null && !finishing) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001082 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001083 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -07001084 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001085 }
1086 }
1087
1088 boolean isInHistory() {
1089 return inHistory;
1090 }
1091
Wale Ogunwale7d701172015-03-11 15:36:30 -07001092 boolean isInStackLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001093 final ActivityStack stack = getStack();
1094 return stack != null && stack.isInStackLocked(this) != null;
Wale Ogunwale7d701172015-03-11 15:36:30 -07001095 }
1096
Craig Mautner86d67a42013-05-14 10:34:38 -07001097 boolean isHomeActivity() {
1098 return mActivityType == HOME_ACTIVITY_TYPE;
1099 }
1100
1101 boolean isRecentsActivity() {
1102 return mActivityType == RECENTS_ACTIVITY_TYPE;
1103 }
1104
Winson Chung83471632016-12-13 11:02:12 -08001105 boolean isAssistantActivity() {
1106 return mActivityType == ASSISTANT_ACTIVITY_TYPE;
1107 }
1108
Craig Mautner86d67a42013-05-14 10:34:38 -07001109 boolean isApplicationActivity() {
1110 return mActivityType == APPLICATION_ACTIVITY_TYPE;
1111 }
1112
Craig Mautner21d24a22014-04-23 11:45:37 -07001113 boolean isPersistable() {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001114 return (info.persistableMode == PERSIST_ROOT_ONLY ||
1115 info.persistableMode == PERSIST_ACROSS_REBOOTS) &&
Craig Mautner43e52ed2014-06-16 17:18:52 -07001116 (intent == null ||
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001117 (intent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
Craig Mautner21d24a22014-04-23 11:45:37 -07001118 }
1119
Wale Ogunwale4cea0f52015-12-25 06:30:31 -08001120 boolean isFocusable() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001121 return StackId.canReceiveKeys(task.getStackId()) || isAlwaysFocusable();
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001122 }
1123
1124 boolean isResizeable() {
Winson Chungd3395382016-12-13 11:49:09 -08001125 return ActivityInfo.isResizeableMode(info.resizeMode) || info.supportsPictureInPicture();
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001126 }
1127
Winson Chungd3395382016-12-13 11:49:09 -08001128 /**
1129 * @return whether this activity is non-resizeable or forced to be resizeable
1130 */
1131 boolean isNonResizableOrForcedResizable() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -07001132 return info.resizeMode != RESIZE_MODE_RESIZEABLE
Wale Ogunwale72a73e32016-10-13 12:16:39 -07001133 && info.resizeMode != RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Jorim Jaggicd13d332016-04-27 15:40:20 -07001134 }
1135
Winson Chunge6308042016-10-31 09:24:01 -07001136 /**
Winson Chungd3395382016-12-13 11:49:09 -08001137 * @return whether this activity supports PiP multi-window and can be put in the pinned stack.
Winson Chunge6308042016-10-31 09:24:01 -07001138 */
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001139 boolean supportsPictureInPicture() {
Winson Chungd3395382016-12-13 11:49:09 -08001140 return service.mSupportsPictureInPicture && !isHomeActivity()
1141 && info.supportsPictureInPicture();
1142 }
1143
1144 /**
1145 * @return whether this activity supports split-screen multi-window and can be put in the docked
1146 * stack.
1147 */
1148 boolean supportsSplitScreen() {
1149 // An activity can not be docked even if it is considered resizeable because it only
1150 // supports picture-in-picture mode but has a non-resizeable resizeMode
1151 return service.mSupportsSplitScreenMultiWindow && supportsResizeableMultiWindow();
1152 }
1153
1154 /**
1155 * @return whether this activity supports freeform multi-window and can be put in the freeform
1156 * stack.
1157 */
1158 boolean supportsFreeform() {
1159 return service.mSupportsFreeformWindowManagement && supportsResizeableMultiWindow();
1160 }
1161
1162 /**
1163 * @return whether this activity supports non-PiP multi-window.
1164 */
1165 private boolean supportsResizeableMultiWindow() {
1166 return service.mSupportsMultiWindow && !isHomeActivity()
1167 && (ActivityInfo.isResizeableMode(info.resizeMode)
1168 || service.mForceResizableActivities);
Wale Ogunwaled26176f2016-01-25 20:04:04 -08001169 }
1170
Winson Chunge6308042016-10-31 09:24:01 -07001171 /**
Andrii Kulian036e3ad2017-04-19 10:55:10 -07001172 * Check whether this activity can be launched on the specified display.
1173 * @param displayId Target display id.
1174 * @return {@code true} if either it is the default display or this activity is resizeable and
1175 * can be put a secondary screen.
1176 */
1177 boolean canBeLaunchedOnDisplay(int displayId) {
1178 return service.mStackSupervisor.canPlaceEntityOnDisplay(displayId,
1179 supportsResizeableMultiWindow());
1180 }
1181
1182 /**
Robert Carrc33658e2017-04-11 18:24:20 -07001183 * @param beforeStopping Whether this check is for an auto-enter-pip operation, that is to say
1184 * the activity has requested to enter PiP when it would otherwise be stopped.
1185 *
Winson Chungc2baac02017-01-11 13:34:47 -08001186 * @return whether this activity is currently allowed to enter PIP, throwing an exception if
Winson Chung4dabf232017-01-25 13:25:22 -08001187 * the activity is not currently visible and {@param noThrow} is not set.
Winson Chunge6308042016-10-31 09:24:01 -07001188 */
Robert Carrc33658e2017-04-11 18:24:20 -07001189 boolean checkEnterPictureInPictureState(String caller, boolean noThrow, boolean beforeStopping) {
Wale Ogunwaleb9a0c992017-04-18 07:25:20 -07001190 if (!supportsPictureInPicture()) {
1191 return false;
1192 }
1193
Winson Chungf4ac0632017-03-17 12:34:12 -07001194 // Check app-ops and see if PiP is supported for this package
1195 if (!checkEnterPictureInPictureAppOpsState()) {
1196 return false;
1197 }
1198
Winson Chungf1bfee12017-03-24 17:11:33 -07001199 // Check to see if we are in VR mode, and disallow PiP if so
1200 if (service.shouldDisableNonVrUiLocked()) {
1201 return false;
1202 }
1203
Winson Chungc2baac02017-01-11 13:34:47 -08001204 boolean isKeyguardLocked = service.isKeyguardLocked();
Robert Carrc33658e2017-04-11 18:24:20 -07001205 boolean isCurrentAppLocked = mStackSupervisor.getLockTaskModeState() != LOCK_TASK_MODE_NONE;
Winson Chungc2baac02017-01-11 13:34:47 -08001206 boolean hasPinnedStack = mStackSupervisor.getStack(PINNED_STACK_ID) != null;
Winson Chungbb348802017-01-30 12:01:45 -08001207 // Don't return early if !isNotLocked, since we want to throw an exception if the activity
1208 // is in an incorrect state
Winson Chunge581ebf2017-02-21 08:25:03 -08001209 boolean isNotLockedOrOnKeyguard = !isKeyguardLocked && !isCurrentAppLocked;
Robert Carrc33658e2017-04-11 18:24:20 -07001210
1211 // We don't allow auto-PiP when something else is already pipped.
1212 if (beforeStopping && hasPinnedStack) {
1213 return false;
1214 }
1215
Winson Chungc2baac02017-01-11 13:34:47 -08001216 switch (state) {
1217 case RESUMED:
Winson Chunge581ebf2017-02-21 08:25:03 -08001218 // When visible, allow entering PiP if the app is not locked. If it is over the
1219 // keyguard, then we will prompt to unlock in the caller before entering PiP.
Robert Carrc33658e2017-04-11 18:24:20 -07001220 return !isCurrentAppLocked &&
1221 (supportsPictureInPictureWhilePausing || !beforeStopping);
Winson Chungc2baac02017-01-11 13:34:47 -08001222 case PAUSING:
1223 case PAUSED:
Winson Chungbb348802017-01-30 12:01:45 -08001224 // When pausing, then only allow enter PiP as in the resume state, and in addition,
1225 // require that there is not an existing PiP activity and that the current system
1226 // state supports entering PiP
Winson Chunge581ebf2017-02-21 08:25:03 -08001227 return isNotLockedOrOnKeyguard && !hasPinnedStack
Winson Chungf4ac0632017-03-17 12:34:12 -07001228 && supportsPictureInPictureWhilePausing;
Winson Chungc2baac02017-01-11 13:34:47 -08001229 case STOPPING:
1230 // When stopping in a valid state, then only allow enter PiP as in the pause state.
1231 // Otherwise, fall through to throw an exception if the caller is trying to enter
1232 // PiP in an invalid stopping state.
1233 if (supportsPictureInPictureWhilePausing) {
Winson Chungf4ac0632017-03-17 12:34:12 -07001234 return isNotLockedOrOnKeyguard && !hasPinnedStack;
Winson Chungc2baac02017-01-11 13:34:47 -08001235 }
1236 default:
Winson Chung4dabf232017-01-25 13:25:22 -08001237 if (noThrow) {
1238 return false;
1239 } else {
1240 throw new IllegalStateException(caller
1241 + ": Current activity is not visible (state=" + state.name() + ") "
1242 + "r=" + this);
1243 }
Winson Chungb5c41b72016-12-07 15:00:47 -08001244 }
Winson Chunge6308042016-10-31 09:24:01 -07001245 }
1246
Winson Chung59fda9e2017-01-20 16:14:51 -08001247 /**
Winson Chungf4ac0632017-03-17 12:34:12 -07001248 * @return Whether AppOps allows this package to enter picture-in-picture.
Winson Chung59fda9e2017-01-20 16:14:51 -08001249 */
Winson Chungf4ac0632017-03-17 12:34:12 -07001250 private boolean checkEnterPictureInPictureAppOpsState() {
Winson Chung59fda9e2017-01-20 16:14:51 -08001251 try {
Winson Chungf4ac0632017-03-17 12:34:12 -07001252 return service.getAppOpsService().checkOperation(OP_PICTURE_IN_PICTURE,
Winson Chung59fda9e2017-01-20 16:14:51 -08001253 appInfo.uid, packageName) == MODE_ALLOWED;
1254 } catch (RemoteException e) {
1255 // Local call
1256 }
1257 return false;
1258 }
1259
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001260 boolean isAlwaysFocusable() {
1261 return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0;
Wale Ogunwale4cea0f52015-12-25 06:30:31 -08001262 }
1263
Jorim Jaggife762342016-10-13 14:33:27 +02001264 /**
1265 * @return true if the activity contains windows that have
1266 * {@link LayoutParams#FLAG_SHOW_WHEN_LOCKED} set
1267 */
1268 boolean hasShowWhenLockedWindows() {
1269 return service.mWindowManager.containsShowWhenLockedWindow(appToken);
1270 }
1271
1272 /**
1273 * @return true if the activity contains windows that have
1274 * {@link LayoutParams#FLAG_DISMISS_KEYGUARD} set
1275 */
1276 boolean hasDismissKeyguardWindows() {
1277 return service.mWindowManager.containsDismissKeyguardWindow(appToken);
1278 }
1279
Wale Ogunwale7d701172015-03-11 15:36:30 -07001280 void makeFinishingLocked() {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08001281 if (!finishing) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001282 final ActivityStack stack = getStack();
1283 if (stack != null && this == stack.getVisibleBehindActivity()) {
Jose Lima34ff4922014-08-18 15:19:41 -07001284 // A finishing activity should not remain as visible in the background
1285 mStackSupervisor.requestVisibleBehindLocked(this, false);
1286 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08001287 finishing = true;
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -07001288 if (stopped) {
1289 clearOptionsLocked();
1290 }
Yorke Leebd54c2a2016-10-25 13:49:23 -07001291
1292 if (service != null) {
1293 service.mTaskChangeNotificationController.notifyTaskStackChanged();
1294 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08001295 }
1296 }
1297
Dianne Hackborn7e269642010-08-25 19:50:20 -07001298 UriPermissionOwner getUriPermissionsLocked() {
1299 if (uriPermissions == null) {
1300 uriPermissions = new UriPermissionOwner(service, this);
1301 }
1302 return uriPermissions;
1303 }
1304
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001305 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 int requestCode, int resultCode,
1307 Intent resultData) {
1308 ActivityResult r = new ActivityResult(from, resultWho,
John Spurlock8a985d22014-02-25 09:40:05 -05001309 requestCode, resultCode, resultData);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001311 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312 }
1313 results.add(r);
1314 }
1315
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001316 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317 int requestCode) {
1318 if (results != null) {
1319 for (int i=results.size()-1; i>=0; i--) {
1320 ActivityResult r = (ActivityResult)results.get(i);
1321 if (r.mFrom != from) continue;
1322 if (r.mResultWho == null) {
1323 if (resultWho != null) continue;
1324 } else {
1325 if (!r.mResultWho.equals(resultWho)) continue;
1326 }
1327 if (r.mRequestCode != requestCode) continue;
1328
1329 results.remove(i);
1330 }
1331 }
1332 }
1333
Andrii Kulian21713ac2016-10-12 22:05:05 -07001334 private void addNewIntentLocked(ReferrerIntent intent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 if (newIntents == null) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001336 newIntents = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337 }
1338 newIntents.add(intent);
1339 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001340
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001341 /**
1342 * Deliver a new Intent to an existing activity, so that its onNewIntent()
1343 * method will be called at the proper time.
1344 */
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001345 final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) {
Dianne Hackborn514074f2013-02-11 10:52:46 -08001346 // The activity now gets access to the data associated with this Intent.
1347 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
Nicolas Prevotc6cf95c2014-05-29 11:30:36 +01001348 intent, getUriPermissionsLocked(), userId);
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001349 final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
Craig Mautner86d67a42013-05-14 10:34:38 -07001350 boolean unsent = true;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001351 final ActivityStack stack = getStack();
Wale Ogunwale826c7062016-09-13 08:25:54 -07001352 final boolean isTopActivityInStack =
1353 stack != null && stack.topRunningActivityLocked() == this;
1354 final boolean isTopActivityWhileSleeping =
1355 service.isSleepingLocked() && isTopActivityInStack;
Wale Ogunwale826c7062016-09-13 08:25:54 -07001356
1357 // We want to immediately deliver the intent to the activity if:
Wale Ogunwale03f7e9e2016-09-22 09:04:09 -07001358 // - It is currently resumed or paused. i.e. it is currently visible to the user and we want
1359 // the user to see the visual effects caused by the intent delivery now.
Wale Ogunwale826c7062016-09-13 08:25:54 -07001360 // - The device is sleeping and it is the top activity behind the lock screen (b/6700897).
Ruben Brunkf53497c2017-03-27 20:26:17 -07001361 if ((state == RESUMED || state == PAUSED
Wale Ogunwale03f7e9e2016-09-22 09:04:09 -07001362 || isTopActivityWhileSleeping) && app != null && app.thread != null) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001363 try {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001364 ArrayList<ReferrerIntent> ar = new ArrayList<>(1);
1365 ar.add(rintent);
Wale Ogunwale826c7062016-09-13 08:25:54 -07001366 app.thread.scheduleNewIntent(
Ruben Brunkf53497c2017-03-27 20:26:17 -07001367 ar, appToken, state == PAUSED /* andPause */);
Craig Mautner86d67a42013-05-14 10:34:38 -07001368 unsent = false;
Dianne Hackborn39792d22010-08-19 18:01:52 -07001369 } catch (RemoteException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001370 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn39792d22010-08-19 18:01:52 -07001371 } catch (NullPointerException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001372 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001373 }
1374 }
Craig Mautner86d67a42013-05-14 10:34:38 -07001375 if (unsent) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001376 addNewIntentLocked(rintent);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001377 }
1378 }
1379
Dianne Hackborn9622ca42012-10-23 18:56:33 -07001380 void updateOptionsLocked(ActivityOptions options) {
1381 if (options != null) {
1382 if (pendingOptions != null) {
1383 pendingOptions.abort();
1384 }
1385 pendingOptions = options;
1386 }
1387 }
1388
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001389 void applyOptionsLocked() {
George Mount2c92c972014-03-20 09:38:23 -07001390 if (pendingOptions != null
Ruben Brunkf53497c2017-03-27 20:26:17 -07001391 && pendingOptions.getAnimationType() != ANIM_SCENE_TRANSITION) {
Michael Jurka21385cd2012-05-03 10:57:31 -07001392 final int animationType = pendingOptions.getAnimationType();
1393 switch (animationType) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001394 case ANIM_CUSTOM:
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001395 service.mWindowManager.overridePendingAppTransition(
1396 pendingOptions.getPackageName(),
1397 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -07001398 pendingOptions.getCustomExitResId(),
1399 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001400 break;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001401 case ANIM_CLIP_REVEAL:
Chet Haase10e23ab2015-02-11 15:08:38 -08001402 service.mWindowManager.overridePendingAppTransitionClipReveal(
1403 pendingOptions.getStartX(), pendingOptions.getStartY(),
1404 pendingOptions.getWidth(), pendingOptions.getHeight());
1405 if (intent.getSourceBounds() == null) {
1406 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1407 pendingOptions.getStartY(),
1408 pendingOptions.getStartX()+pendingOptions.getWidth(),
1409 pendingOptions.getStartY()+pendingOptions.getHeight()));
1410 }
1411 break;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001412 case ANIM_SCALE_UP:
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001413 service.mWindowManager.overridePendingAppTransitionScaleUp(
1414 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001415 pendingOptions.getWidth(), pendingOptions.getHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001416 if (intent.getSourceBounds() == null) {
1417 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1418 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001419 pendingOptions.getStartX()+pendingOptions.getWidth(),
1420 pendingOptions.getStartY()+pendingOptions.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001421 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001422 break;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001423 case ANIM_THUMBNAIL_SCALE_UP:
1424 case ANIM_THUMBNAIL_SCALE_DOWN:
Winson Chungaa7fa012017-05-24 15:50:06 -07001425 final boolean scaleUp = (animationType == ANIM_THUMBNAIL_SCALE_UP);
1426 final GraphicBuffer buffer = pendingOptions.getThumbnail();
1427 service.mWindowManager.overridePendingAppTransitionThumb(buffer,
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001428 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -07001429 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -07001430 scaleUp);
Winson Chungf229ae52017-06-02 14:34:52 -07001431 if (intent.getSourceBounds() == null && buffer != null) {
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001432 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1433 pendingOptions.getStartY(),
Winson Chungaa7fa012017-05-24 15:50:06 -07001434 pendingOptions.getStartX() + buffer.getWidth(),
1435 pendingOptions.getStartY() + buffer.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001436 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001437 break;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001438 case ANIM_THUMBNAIL_ASPECT_SCALE_UP:
1439 case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001440 final AppTransitionAnimationSpec[] specs = pendingOptions.getAnimSpecs();
Jorim Jaggi34795e32017-05-12 17:27:46 +02001441 final IAppTransitionAnimationSpecsFuture specsFuture =
1442 pendingOptions.getSpecsFuture();
1443 if (specsFuture != null) {
1444 service.mWindowManager.overridePendingAppTransitionMultiThumbFuture(
1445 specsFuture, pendingOptions.getOnAnimationStartListener(),
1446 animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP);
1447 } else if (animationType == ANIM_THUMBNAIL_ASPECT_SCALE_DOWN
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001448 && specs != null) {
1449 service.mWindowManager.overridePendingAppTransitionMultiThumb(
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001450 specs, pendingOptions.getOnAnimationStartListener(),
1451 pendingOptions.getAnimationFinishedListener(), false);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001452 } else {
1453 service.mWindowManager.overridePendingAppTransitionAspectScaledThumb(
1454 pendingOptions.getThumbnail(),
1455 pendingOptions.getStartX(), pendingOptions.getStartY(),
1456 pendingOptions.getWidth(), pendingOptions.getHeight(),
1457 pendingOptions.getOnAnimationStartListener(),
Ruben Brunkf53497c2017-03-27 20:26:17 -07001458 (animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP));
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001459 if (intent.getSourceBounds() == null) {
1460 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1461 pendingOptions.getStartY(),
1462 pendingOptions.getStartX() + pendingOptions.getWidth(),
1463 pendingOptions.getStartY() + pendingOptions.getHeight()));
1464 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001465 }
1466 break;
Craig Mautner233ceee2014-05-09 17:05:11 -07001467 default:
1468 Slog.e(TAG, "applyOptionsLocked: Unknown animationType=" + animationType);
1469 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001470 }
1471 pendingOptions = null;
1472 }
1473 }
1474
Adam Powellcfbe9be2013-11-06 14:58:58 -08001475 ActivityOptions getOptionsForTargetActivityLocked() {
1476 return pendingOptions != null ? pendingOptions.forTargetActivity() : null;
1477 }
1478
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001479 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001480 if (pendingOptions != null) {
1481 pendingOptions.abort();
1482 pendingOptions = null;
1483 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001484 }
1485
Dianne Hackborn9622ca42012-10-23 18:56:33 -07001486 ActivityOptions takeOptionsLocked() {
1487 ActivityOptions opts = pendingOptions;
1488 pendingOptions = null;
1489 return opts;
1490 }
1491
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001492 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -07001493 if (uriPermissions != null) {
1494 uriPermissions.removeUriPermissionsLocked();
1495 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001496 }
1497 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498
1499 void pauseKeyDispatchingLocked() {
1500 if (!keysPaused) {
1501 keysPaused = true;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001502 mWindowContainerController.pauseKeyDispatching();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001503 }
1504 }
1505
1506 void resumeKeyDispatchingLocked() {
1507 if (keysPaused) {
1508 keysPaused = false;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001509 mWindowContainerController.resumeKeyDispatching();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 }
1511 }
1512
Winson Chung740c3ac2014-11-12 16:14:38 -08001513 void updateThumbnailLocked(Bitmap newThumbnail, CharSequence description) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001514 if (newThumbnail != null) {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001515 if (DEBUG_THUMBNAILS) Slog.i(TAG_THUMBNAILS,
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001516 "Setting thumbnail of " + this + " to " + newThumbnail);
Winsonc809cbb2015-11-02 12:06:15 -08001517 boolean thumbnailUpdated = task.setLastThumbnailLocked(newThumbnail);
Winson Chung096f36b2014-08-20 15:39:01 -07001518 if (thumbnailUpdated && isPersistable()) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001519 service.notifyTaskPersisterLocked(task, false);
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001520 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001521 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001522 task.lastDescription = description;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001523 }
1524
Andrii Kulian21713ac2016-10-12 22:05:05 -07001525 final Bitmap screenshotActivityLocked() {
1526 if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "screenshotActivityLocked: " + this);
Jorim Jaggi02886a82016-12-06 09:10:06 -08001527
1528 if (ENABLE_TASK_SNAPSHOTS) {
1529 // No need to screenshot if snapshots are enabled.
1530 if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS,
1531 "\tSnapshots are enabled, abort taking screenshot");
1532 return null;
1533 }
1534
Andrii Kulian21713ac2016-10-12 22:05:05 -07001535 if (noDisplay) {
1536 if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tNo display");
1537 return null;
1538 }
1539
1540 final ActivityStack stack = getStack();
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001541 if (stack.isHomeOrRecentsStack()) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001542 // This is an optimization -- since we never show Home or Recents within Recents itself,
1543 // we can just go ahead and skip taking the screenshot if this is the home stack.
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001544 if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, stack.getStackId() == HOME_STACK_ID ?
1545 "\tHome stack" : "\tRecents stack");
Andrii Kulian21713ac2016-10-12 22:05:05 -07001546 return null;
1547 }
1548
1549 int w = service.mThumbnailWidth;
1550 int h = service.mThumbnailHeight;
1551
1552 if (w <= 0) {
1553 Slog.e(TAG, "\tInvalid thumbnail dimensions: " + w + "x" + h);
1554 return null;
1555 }
1556
1557 if (stack.mStackId == DOCKED_STACK_ID && mStackSupervisor.mIsDockMinimized) {
1558 // When the docked stack is minimized its app windows are cropped significantly so any
1559 // screenshot taken will not display the apps contain. So, we avoid taking a screenshot
1560 // in that case.
1561 if (DEBUG_SCREENSHOTS) Slog.e(TAG, "\tIn minimized docked stack");
1562 return null;
1563 }
1564
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001565 float scale = 0;
Andrii Kulian21713ac2016-10-12 22:05:05 -07001566 if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tTaking screenshot");
1567
1568 // When this flag is set, we currently take the fullscreen screenshot of the activity but
1569 // scaled to half the size. This gives us a "good-enough" fullscreen thumbnail to use within
1570 // SystemUI while keeping memory usage low.
1571 if (TAKE_FULLSCREEN_SCREENSHOTS) {
1572 w = h = -1;
1573 scale = service.mFullscreenThumbnailScale;
1574 }
1575
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001576 return mWindowContainerController.screenshotApplications(getDisplayId(), w, h, scale);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001577 }
1578
Wale Ogunwaleec950642017-04-25 07:44:21 -07001579 void setDeferHidingClient(boolean deferHidingClient) {
1580 if (mDeferHidingClient == deferHidingClient) {
1581 return;
1582 }
1583 mDeferHidingClient = deferHidingClient;
1584 if (!mDeferHidingClient && !visible) {
1585 // Hiding the client is no longer deferred and the app isn't visible still, go ahead and
1586 // update the visibility.
1587 setVisibility(false);
1588 }
Wale Ogunwale89973222017-04-23 18:39:45 -07001589 }
1590
Wale Ogunwaleec950642017-04-25 07:44:21 -07001591 void setVisibility(boolean visible) {
1592 mWindowContainerController.setVisibility(visible, mDeferHidingClient);
Jorim Jaggicdfc04e2017-04-28 19:06:24 +02001593 mStackSupervisor.mActivityMetricsLogger.notifyVisibilityChanged(this, visible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001594 }
1595
1596 // TODO: Look into merging with #setVisibility()
Wale Ogunwaleec950642017-04-25 07:44:21 -07001597 void setVisible(boolean newVisible) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001598 visible = newVisible;
Wale Ogunwaleec950642017-04-25 07:44:21 -07001599 mDeferHidingClient = !visible && mDeferHidingClient;
Andrii Kulian21713ac2016-10-12 22:05:05 -07001600 if (!visible && mUpdateTaskThumbnailWhenHidden) {
1601 updateThumbnailLocked(screenshotActivityLocked(), null /* description */);
1602 mUpdateTaskThumbnailWhenHidden = false;
1603 }
Wale Ogunwaleec950642017-04-25 07:44:21 -07001604 setVisibility(visible);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001605 final ArrayList<ActivityContainer> containers = mChildContainers;
1606 for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) {
1607 final ActivityContainer container = containers.get(containerNdx);
1608 container.setVisible(visible);
1609 }
1610 mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
1611 }
1612
Jorim Jaggibae01b12017-04-11 16:29:10 -07001613 void notifyAppResumed(boolean wasStopped) {
1614 mWindowContainerController.notifyAppResumed(wasStopped);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001615 }
1616
1617 void notifyUnknownVisibilityLaunched() {
1618 mWindowContainerController.notifyUnknownVisibilityLaunched();
1619 }
1620
Jorim Jaggi241ae102016-11-02 21:57:33 -07001621 /**
1622 * @return true if the input activity should be made visible, ignoring any effect Keyguard
1623 * might have on the visibility
1624 *
1625 * @see {@link ActivityStack#checkKeyguardVisibility}
1626 */
1627 boolean shouldBeVisibleIgnoringKeyguard(boolean behindTranslucentActivity,
1628 boolean stackVisibleBehind, ActivityRecord visibleBehind,
1629 boolean behindFullscreenActivity) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001630 if (!okToShowLocked()) {
1631 return false;
1632 }
1633
1634 // mLaunchingBehind: Activities launching behind are at the back of the task stack
1635 // but must be drawn initially for the animation as though they were visible.
1636 final boolean activityVisibleBehind =
1637 (behindTranslucentActivity || stackVisibleBehind) && visibleBehind == this;
1638
1639 boolean isVisible =
1640 !behindFullscreenActivity || mLaunchTaskBehind || activityVisibleBehind;
1641
1642 if (service.mSupportsLeanbackOnly && isVisible && isRecentsActivity()) {
1643 // On devices that support leanback only (Android TV), Recents activity can only be
1644 // visible if the home stack is the focused stack or we are in split-screen mode.
1645 isVisible = mStackSupervisor.getStack(DOCKED_STACK_ID) != null
1646 || mStackSupervisor.isFocusedStack(getStack());
1647 }
1648
1649 return isVisible;
1650 }
1651
1652 void makeVisibleIfNeeded(ActivityRecord starting) {
1653 // This activity is not currently visible, but is running. Tell it to become visible.
Ruben Brunkf53497c2017-03-27 20:26:17 -07001654 if (state == RESUMED || this == starting) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001655 if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY,
1656 "Not making visible, r=" + this + " state=" + state + " starting=" + starting);
1657 return;
1658 }
1659
1660 // If this activity is paused, tell it to now show its window.
1661 if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY,
1662 "Making visible and scheduling visibility: " + this);
1663 final ActivityStack stack = getStack();
1664 try {
1665 if (stack.mTranslucentActivityWaiting != null) {
1666 updateOptionsLocked(returningOptions);
1667 stack.mUndrawnActivitiesBelowTopTranslucent.add(this);
1668 }
1669 setVisible(true);
1670 sleeping = false;
1671 app.pendingUiClean = true;
1672 app.thread.scheduleWindowVisibility(appToken, true /* showWindow */);
1673 // The activity may be waiting for stop, but that is no longer appropriate for it.
1674 mStackSupervisor.mStoppingActivities.remove(this);
1675 mStackSupervisor.mGoingToSleepActivities.remove(this);
1676 } catch (Exception e) {
1677 // Just skip on any failure; we'll make it visible when it next restarts.
1678 Slog.w(TAG, "Exception thrown making visibile: " + intent.getComponent(), e);
1679 }
1680 handleAlreadyVisible();
1681 }
1682
1683 boolean handleAlreadyVisible() {
1684 stopFreezingScreenLocked(false);
1685 try {
1686 if (returningOptions != null) {
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001687 app.thread.scheduleOnNewActivityOptions(appToken, returningOptions.toBundle());
Andrii Kulian21713ac2016-10-12 22:05:05 -07001688 }
1689 } catch(RemoteException e) {
1690 }
Ruben Brunkf53497c2017-03-27 20:26:17 -07001691 return state == RESUMED;
Andrii Kulian21713ac2016-10-12 22:05:05 -07001692 }
1693
1694 static void activityResumedLocked(IBinder token) {
1695 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
1696 if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r);
1697 if (r != null) {
1698 r.icicle = null;
1699 r.haveState = false;
1700 }
1701 }
1702
1703 /**
1704 * Once we know that we have asked an application to put an activity in the resumed state
1705 * (either by launching it or explicitly telling it), this function updates the rest of our
1706 * state to match that fact.
1707 */
1708 void completeResumeLocked() {
1709 final boolean wasVisible = visible;
1710 visible = true;
1711 if (!wasVisible) {
1712 // Visibility has changed, so take a note of it so we call the TaskStackChangedListener
1713 mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
1714 }
1715 idle = false;
1716 results = null;
1717 newIntents = null;
1718 stopped = false;
1719
1720 if (isHomeActivity()) {
1721 ProcessRecord app = task.mActivities.get(0).app;
1722 if (app != null && app != service.mHomeProcess) {
1723 service.mHomeProcess = app;
1724 }
1725 }
1726
1727 if (nowVisible) {
1728 // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now.
1729 mStackSupervisor.reportActivityVisibleLocked(this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001730 }
1731
1732 // Schedule an idle timeout in case the app doesn't do it for us.
1733 mStackSupervisor.scheduleIdleTimeoutLocked(this);
1734
1735 mStackSupervisor.reportResumedActivityLocked(this);
1736
1737 resumeKeyDispatchingLocked();
1738 final ActivityStack stack = getStack();
1739 stack.mNoAnimActivities.clear();
1740
1741 // Mark the point when the activity is resuming
1742 // TODO: To be more accurate, the mark should be before the onCreate,
1743 // not after the onResume. But for subsequent starts, onResume is fine.
1744 if (app != null) {
1745 cpuTimeAtResume = service.mProcessCpuTracker.getCpuTimeForPid(app.pid);
1746 } else {
1747 cpuTimeAtResume = 0; // Couldn't get the cpu time of process
1748 }
1749
1750 returningOptions = null;
1751
1752 if (stack.getVisibleBehindActivity() == this) {
1753 // When resuming an activity, require it to call requestVisibleBehind() again.
1754 stack.setVisibleBehindActivity(null /* ActivityRecord */);
1755 }
1756 mStackSupervisor.checkReadyForSleepLocked();
1757 }
1758
1759 final void activityStoppedLocked(Bundle newIcicle, PersistableBundle newPersistentState,
1760 CharSequence description) {
1761 final ActivityStack stack = getStack();
Ruben Brunkf53497c2017-03-27 20:26:17 -07001762 if (state != STOPPING) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001763 Slog.i(TAG, "Activity reported stop, but no longer stopping: " + this);
Ruben Brunkf53497c2017-03-27 20:26:17 -07001764 stack.mHandler.removeMessages(STOP_TIMEOUT_MSG, this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001765 return;
1766 }
1767 if (newPersistentState != null) {
1768 persistentState = newPersistentState;
1769 service.notifyTaskPersisterLocked(task, false);
1770 }
1771 if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, "Saving icicle of " + this + ": " + icicle);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001772
Andrii Kulian21713ac2016-10-12 22:05:05 -07001773 if (newIcicle != null) {
1774 // If icicle is null, this is happening due to a timeout, so we haven't really saved
1775 // the state.
1776 icicle = newIcicle;
1777 haveState = true;
1778 launchCount = 0;
1779 updateThumbnailLocked(null /* newThumbnail */, description);
1780 }
1781 if (!stopped) {
1782 if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to STOPPED: " + this + " (stop complete)");
Ruben Brunkf53497c2017-03-27 20:26:17 -07001783 stack.mHandler.removeMessages(STOP_TIMEOUT_MSG, this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001784 stopped = true;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001785 state = STOPPED;
Andrii Kulian21713ac2016-10-12 22:05:05 -07001786
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001787 mWindowContainerController.notifyAppStopped();
Andrii Kulian21713ac2016-10-12 22:05:05 -07001788
1789 if (stack.getVisibleBehindActivity() == this) {
1790 mStackSupervisor.requestVisibleBehindLocked(this, false /* visible */);
1791 }
1792 if (finishing) {
1793 clearOptionsLocked();
1794 } else {
1795 if (deferRelaunchUntilPaused) {
1796 stack.destroyActivityLocked(this, true /* removeFromApp */, "stop-config");
1797 mStackSupervisor.resumeFocusedStackTopActivityLocked();
1798 } else {
1799 mStackSupervisor.updatePreviousProcessLocked(this);
1800 }
1801 }
1802 }
1803 }
1804
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001805 void startLaunchTickingLocked() {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001806 if (IS_USER_BUILD) {
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001807 return;
1808 }
1809 if (launchTickTime == 0) {
1810 launchTickTime = SystemClock.uptimeMillis();
1811 continueLaunchTickingLocked();
1812 }
1813 }
1814
1815 boolean continueLaunchTickingLocked() {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001816 if (launchTickTime == 0) {
1817 return false;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001818 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001819
Andrii Kulian02b7a832016-10-06 23:11:56 -07001820 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001821 if (stack == null) {
1822 return false;
1823 }
1824
Ruben Brunkf53497c2017-03-27 20:26:17 -07001825 Message msg = stack.mHandler.obtainMessage(LAUNCH_TICK_MSG, this);
1826 stack.mHandler.removeMessages(LAUNCH_TICK_MSG);
1827 stack.mHandler.sendMessageDelayed(msg, LAUNCH_TICK);
Wale Ogunwale7d701172015-03-11 15:36:30 -07001828 return true;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001829 }
1830
1831 void finishLaunchTickingLocked() {
1832 launchTickTime = 0;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001833 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001834 if (stack != null) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001835 stack.mHandler.removeMessages(LAUNCH_TICK_MSG);
Wale Ogunwale7d701172015-03-11 15:36:30 -07001836 }
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001837 }
1838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839 // IApplicationToken
1840
1841 public boolean mayFreezeScreenLocked(ProcessRecord app) {
1842 // Only freeze the screen if this activity is currently attached to
1843 // an application, and that application is not blocked or unresponding.
1844 // In any other case, we can't count on getting the screen unfrozen,
1845 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -08001846 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001847 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001849 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
1850 if (mayFreezeScreenLocked(app)) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001851 mWindowContainerController.startFreezingScreen(configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001852 }
1853 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001855 public void stopFreezingScreenLocked(boolean force) {
1856 if (force || frozenBeforeDestroy) {
1857 frozenBeforeDestroy = false;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001858 mWindowContainerController.stopFreezingScreen(force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001859 }
1860 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001861
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001862 public void reportFullyDrawnLocked() {
1863 final long curTime = SystemClock.uptimeMillis();
1864 if (displayStartTime != 0) {
1865 reportLaunchTimeLocked(curTime);
1866 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001867 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001868 if (fullyDrawnStartTime != 0 && stack != null) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001869 final long thisTime = curTime - fullyDrawnStartTime;
1870 final long totalTime = stack.mFullyDrawnStartTime != 0
1871 ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07001872 if (SHOW_ACTIVITY_START_TIME) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001873 Trace.asyncTraceEnd(TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
1874 EventLog.writeEvent(AM_ACTIVITY_FULLY_DRAWN_TIME,
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001875 userId, System.identityHashCode(this), shortComponentName,
1876 thisTime, totalTime);
1877 StringBuilder sb = service.mStringBuilder;
1878 sb.setLength(0);
1879 sb.append("Fully drawn ");
1880 sb.append(shortComponentName);
1881 sb.append(": ");
1882 TimeUtils.formatDuration(thisTime, sb);
1883 if (thisTime != totalTime) {
1884 sb.append(" (total ");
1885 TimeUtils.formatDuration(totalTime, sb);
1886 sb.append(")");
1887 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001888 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001889 }
1890 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001891 //service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001892 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001893 stack.mFullyDrawnStartTime = 0;
1894 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001895 fullyDrawnStartTime = 0;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001896 }
1897
1898 private void reportLaunchTimeLocked(final long curTime) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001899 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001900 if (stack == null) {
1901 return;
1902 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001903 final long thisTime = curTime - displayStartTime;
1904 final long totalTime = stack.mLaunchStartTime != 0
1905 ? (curTime - stack.mLaunchStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07001906 if (SHOW_ACTIVITY_START_TIME) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001907 Trace.asyncTraceEnd(TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0);
1908 EventLog.writeEvent(AM_ACTIVITY_LAUNCH_TIME,
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001909 userId, System.identityHashCode(this), shortComponentName,
1910 thisTime, totalTime);
1911 StringBuilder sb = service.mStringBuilder;
1912 sb.setLength(0);
1913 sb.append("Displayed ");
1914 sb.append(shortComponentName);
1915 sb.append(": ");
1916 TimeUtils.formatDuration(thisTime, sb);
1917 if (thisTime != totalTime) {
1918 sb.append(" (total ");
1919 TimeUtils.formatDuration(totalTime, sb);
1920 sb.append(")");
1921 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001922 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001923 }
1924 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
1925 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001926 //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001927 }
1928 displayStartTime = 0;
1929 stack.mLaunchStartTime = 0;
1930 }
1931
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001932 @Override
Sudheer Shankac766db02017-06-12 10:37:29 -07001933 public void onStartingWindowDrawn(long timestamp) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001934 synchronized (service) {
Sudheer Shankac766db02017-06-12 10:37:29 -07001935 mStackSupervisor.mActivityMetricsLogger.notifyStartingWindowDrawn(
1936 getStackId(), timestamp);
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001937 }
1938 }
1939
1940 @Override
Sudheer Shankac766db02017-06-12 10:37:29 -07001941 public void onWindowsDrawn(long timestamp) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001942 synchronized (service) {
Sudheer Shankac766db02017-06-12 10:37:29 -07001943 mStackSupervisor.mActivityMetricsLogger.notifyWindowsDrawn(getStackId(), timestamp);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001944 if (displayStartTime != 0) {
Sudheer Shankac766db02017-06-12 10:37:29 -07001945 reportLaunchTimeLocked(timestamp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001946 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001947 mStackSupervisor.sendWaitingVisibleReportLocked(this);
1948 startTime = 0;
1949 finishLaunchTickingLocked();
1950 if (task != null) {
1951 task.hasBeenVisible = true;
1952 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001953 }
1954 }
1955
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001956 @Override
1957 public void onWindowsVisible() {
1958 synchronized (service) {
1959 mStackSupervisor.reportActivityVisibleLocked(this);
1960 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this);
1961 if (!nowVisible) {
1962 nowVisible = true;
1963 lastVisibleTime = SystemClock.uptimeMillis();
Bryce Leeb7c9b802017-05-02 14:20:24 -07001964 if (idle || mStackSupervisor.isStoppingNoHistoryActivity()) {
1965 // If this activity was already idle or there is an activity that must be
1966 // stopped immediately after visible, then we now need to make sure we perform
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001967 // the full stop of any activities that are waiting to do so. This is because
1968 // we won't do that while they are still waiting for this one to become visible.
Bryce Lee4a194382017-04-04 14:32:48 -07001969 final int size = mStackSupervisor.mActivitiesWaitingForVisibleActivity.size();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001970 if (size > 0) {
1971 for (int i = 0; i < size; i++) {
Bryce Lee4a194382017-04-04 14:32:48 -07001972 final ActivityRecord r =
1973 mStackSupervisor.mActivitiesWaitingForVisibleActivity.get(i);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001974 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "Was waiting for visible: " + r);
1975 }
Bryce Lee4a194382017-04-04 14:32:48 -07001976 mStackSupervisor.mActivitiesWaitingForVisibleActivity.clear();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001977 mStackSupervisor.scheduleIdleLocked();
1978 }
Bryce Leeb7c9b802017-05-02 14:20:24 -07001979 } else {
1980 // Instead of doing the full stop routine here, let's just hide any activities
1981 // we now can, and let them stop when the normal idle happens.
1982 mStackSupervisor.processStoppingActivitiesLocked(null /* idleActivity */,
1983 false /* remove */, true /* processPausingActivities */);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001984 }
1985 service.scheduleAppGcsLocked();
1986 }
1987 }
1988 }
1989
1990 @Override
1991 public void onWindowsGone() {
1992 synchronized (service) {
1993 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + this);
1994 nowVisible = false;
1995 }
1996 }
1997
1998 @Override
Wale Ogunwale7402ddf2017-03-29 12:58:24 -07001999 public boolean keyDispatchingTimedOut(String reason, int windowPid) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002000 ActivityRecord anrActivity;
2001 ProcessRecord anrApp;
Wale Ogunwale7402ddf2017-03-29 12:58:24 -07002002 boolean windowFromSameProcessAsActivity;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002003 synchronized (service) {
2004 anrActivity = getWaitingHistoryRecordLocked();
2005 anrApp = app;
Brian Carlstrom7b0f2e82017-03-31 00:24:18 -07002006 windowFromSameProcessAsActivity =
2007 app == null || app.pid == windowPid || windowPid == -1;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002008 }
Wale Ogunwale7402ddf2017-03-29 12:58:24 -07002009 if (windowFromSameProcessAsActivity) {
2010 return service.inputDispatchingTimedOut(anrApp, anrActivity, this, false, reason);
2011 } else {
2012 // In this case another process added windows using this activity token. So, we call the
2013 // generic service input dispatch timed out method so that the right process is blamed.
2014 return service.inputDispatchingTimedOut(windowPid, false /* aboveSystem */, reason) < 0;
2015 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002016 }
2017
2018 private ActivityRecord getWaitingHistoryRecordLocked() {
riddle_hsudb46d6b2015-04-01 18:58:07 +08002019 // First find the real culprit... if this activity is waiting for
2020 // another activity to start or has stopped, then the key dispatching
2021 // timeout should not be caused by this.
Bryce Lee4a194382017-04-04 14:32:48 -07002022 if (mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(this) || stopped) {
Craig Mautner8f2adcb2014-04-07 22:21:33 +00002023 final ActivityStack stack = mStackSupervisor.getFocusedStack();
riddle_hsudb46d6b2015-04-01 18:58:07 +08002024 // Try to use the one which is closest to top.
2025 ActivityRecord r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002026 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -08002027 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002028 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08002029 if (r != null) {
2030 return r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002031 }
2032 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08002033 return this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002034 }
2035
Chong Zhang87761972016-08-22 13:53:24 -07002036 /** Checks whether the activity should be shown for current user. */
2037 public boolean okToShowLocked() {
2038 return (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0
2039 || (mStackSupervisor.isCurrentProfileLocked(userId)
2040 && !service.mUserController.isUserStoppingOrShuttingDownLocked(userId));
2041 }
2042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002043 /**
2044 * This method will return true if the activity is either visible, is becoming visible, is
2045 * currently pausing, or is resumed.
2046 */
2047 public boolean isInterestingToUserLocked() {
Ruben Brunkf53497c2017-03-27 20:26:17 -07002048 return visible || nowVisible || state == PAUSING ||
2049 state == RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002050 }
2051
Wale Ogunwale3e997362016-09-06 10:37:56 -07002052 void setSleeping(boolean _sleeping) {
2053 setSleeping(_sleeping, false);
2054 }
2055
2056 void setSleeping(boolean _sleeping, boolean force) {
2057 if (!force && sleeping == _sleeping) {
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002058 return;
2059 }
2060 if (app != null && app.thread != null) {
2061 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -08002062 app.thread.scheduleSleeping(appToken, _sleeping);
Craig Mautner0eea92c2013-05-16 13:35:39 -07002063 if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
2064 mStackSupervisor.mGoingToSleepActivities.add(this);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002065 }
2066 sleeping = _sleeping;
2067 } catch (RemoteException e) {
Craig Mautner0eea92c2013-05-16 13:35:39 -07002068 Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002069 }
2070 }
2071 }
Craig Mautnerf81b90872013-02-26 13:02:43 -08002072
Craig Mautnerd2328952013-03-05 12:46:26 -08002073 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07002074 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Craig Mautnerd2328952013-03-05 12:46:26 -08002075 if (r == null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08002076 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08002077 }
2078 final TaskRecord task = r.task;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07002079 final int activityNdx = task.mActivities.indexOf(r);
2080 if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08002081 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08002082 }
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07002083 return task.taskId;
Craig Mautnerd2328952013-03-05 12:46:26 -08002084 }
2085
2086 static ActivityRecord isInStackLocked(IBinder token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07002087 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Andrii Kulian02b7a832016-10-06 23:11:56 -07002088 return (r != null) ? r.getStack().isInStackLocked(r) : null;
Craig Mautnerd2328952013-03-05 12:46:26 -08002089 }
2090
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07002091 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -08002092 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
2093 if (r != null) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002094 return r.getStack();
Craig Mautnerd2328952013-03-05 12:46:26 -08002095 }
2096 return null;
2097 }
2098
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002099 /**
2100 * @return display id to which this record is attached, -1 if not attached.
2101 */
2102 int getDisplayId() {
2103 final ActivityStack stack = getStack();
2104 if (stack == null) {
2105 return -1;
2106 }
2107 return stack.mDisplayId;
2108 }
2109
Dianne Hackborn89ad4562014-08-24 16:45:38 -07002110 final boolean isDestroyable() {
Ruben Brunkf53497c2017-03-27 20:26:17 -07002111 if (finishing || app == null || state == DESTROYING
2112 || state == DESTROYED) {
Dianne Hackborn89ad4562014-08-24 16:45:38 -07002113 // This would be redundant.
2114 return false;
2115 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07002116 final ActivityStack stack = getStack();
2117 if (stack == null || this == stack.mResumedActivity || this == stack.mPausingActivity
2118 || !haveState || !stopped) {
Dianne Hackborn89ad4562014-08-24 16:45:38 -07002119 // We're not ready for this kind of thing.
2120 return false;
2121 }
2122 if (visible) {
2123 // The user would notice this!
2124 return false;
2125 }
2126 return true;
2127 }
2128
Winson Chung3bad5cc02014-08-19 17:44:32 -07002129 private static String createImageFilename(long createTime, int taskId) {
2130 return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime +
Ruben Brunkf53497c2017-03-27 20:26:17 -07002131 IMAGE_EXTENSION;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002132 }
2133
Craig Mautner648f69b2014-09-18 14:16:26 -07002134 void setTaskDescription(TaskDescription _taskDescription) {
2135 Bitmap icon;
2136 if (_taskDescription.getIconFilename() == null &&
2137 (icon = _taskDescription.getIcon()) != null) {
2138 final String iconFilename = createImageFilename(createTime, task.taskId);
Winson Chungc8408b82017-01-25 17:58:56 -08002139 final File iconFile = new File(TaskPersister.getUserImagesDir(task.userId),
2140 iconFilename);
Suprabh Shukla23593142015-11-03 17:31:15 -08002141 final String iconFilePath = iconFile.getAbsolutePath();
Suprabh Shukla09a88f52015-12-02 14:36:31 -08002142 service.mRecentTasks.saveImage(icon, iconFilePath);
Suprabh Shukla23593142015-11-03 17:31:15 -08002143 _taskDescription.setIconFilename(iconFilePath);
Craig Mautner648f69b2014-09-18 14:16:26 -07002144 }
2145 taskDescription = _taskDescription;
2146 }
2147
Amith Yamasani0af6fa72016-01-17 15:36:19 -08002148 void setVoiceSessionLocked(IVoiceInteractionSession session) {
2149 voiceSession = session;
2150 pendingVoiceInteractionStart = false;
2151 }
2152
2153 void clearVoiceSessionLocked() {
2154 voiceSession = null;
2155 pendingVoiceInteractionStart = false;
2156 }
2157
Jorim Jaggi02886a82016-12-06 09:10:06 -08002158 void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch) {
Jorim Jaggi42befc62017-06-13 11:54:04 -07002159 showStartingWindow(prev, newTask, taskSwitch, false /* fromRecents */);
2160 }
2161
2162 void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch,
2163 boolean fromRecents) {
Jorim Jaggi70176432017-01-18 12:52:13 +01002164 if (mWindowContainerController == null) {
2165 return;
2166 }
Wale Ogunwale19866e22017-04-19 06:05:13 -07002167 if (mTaskOverlay) {
2168 // We don't show starting window for overlay activities.
2169 return;
2170 }
2171
Wale Ogunwale3b232392016-05-13 15:37:13 -07002172 final CompatibilityInfo compatInfo =
2173 service.compatibilityInfoForPackageLocked(info.applicationInfo);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002174 final boolean shown = mWindowContainerController.addStartingWindow(packageName, theme,
2175 compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags,
Jorim Jaggibae01b12017-04-11 16:29:10 -07002176 prev != null ? prev.appToken : null, newTask, taskSwitch, isProcessRunning(),
Jorim Jaggi70aa4d12017-05-15 00:05:54 +02002177 allowTaskSnapshot(),
Jorim Jaggi42befc62017-06-13 11:54:04 -07002178 state.ordinal() >= RESUMED.ordinal() && state.ordinal() <= STOPPED.ordinal(),
2179 fromRecents);
Wale Ogunwale3b232392016-05-13 15:37:13 -07002180 if (shown) {
2181 mStartingWindowState = STARTING_WINDOW_SHOWN;
2182 }
2183 }
2184
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002185 void removeOrphanedStartingWindow(boolean behindFullscreenActivity) {
Jorim Jaggicb956052017-05-09 16:27:24 +02002186 if (mStartingWindowState == STARTING_WINDOW_SHOWN && behindFullscreenActivity) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002187 if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, "Found orphaned starting window " + this);
2188 mStartingWindowState = STARTING_WINDOW_REMOVED;
Jorim Jaggi19be6052017-08-03 18:33:43 +02002189 mWindowContainerController.removeStartingWindow();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002190 }
2191 }
2192
2193 int getRequestedOrientation() {
2194 return mWindowContainerController.getOrientation();
2195 }
2196
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002197 void setRequestedOrientation(int requestedOrientation) {
Bryce Lee39791592017-04-26 09:29:12 -07002198 if (ActivityInfo.isFixedOrientation(requestedOrientation) && !fullscreen
Bryce Leed1ac18c2017-05-11 07:59:41 -07002199 && appInfo.targetSdkVersion > O) {
Bryce Lee39791592017-04-26 09:29:12 -07002200 throw new IllegalStateException("Only fullscreen activities can request orientation");
2201 }
2202
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002203 final int displayId = getDisplayId();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002204 final Configuration displayConfig =
2205 mStackSupervisor.getDisplayOverrideConfiguration(displayId);
2206
2207 final Configuration config = mWindowContainerController.setOrientation(requestedOrientation,
2208 displayId, displayConfig, mayFreezeScreenLocked(app));
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002209 if (config != null) {
2210 frozenBeforeDestroy = true;
2211 if (!service.updateDisplayOverrideConfigurationLocked(config, this,
2212 false /* deferResume */, displayId)) {
2213 mStackSupervisor.resumeFocusedStackTopActivityLocked();
2214 }
2215 }
Yorke Leebd54c2a2016-10-25 13:49:23 -07002216 service.mTaskChangeNotificationController.notifyActivityRequestedOrientationChanged(
2217 task.taskId, requestedOrientation);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002218 }
2219
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01002220 void setDisablePreviewScreenshots(boolean disable) {
2221 mWindowContainerController.setDisablePreviewScreenshots(disable);
2222 }
2223
Bryce Leea163b762017-01-24 11:05:01 -08002224 /**
2225 * Set the last reported global configuration to the client. Should be called whenever a new
2226 * global configuration is sent to the client for this activity.
2227 */
2228 void setLastReportedGlobalConfiguration(@NonNull Configuration config) {
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002229 mLastReportedConfiguration.setGlobalConfiguration(config);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002230 }
2231
Bryce Leea163b762017-01-24 11:05:01 -08002232 /**
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002233 * Set the last reported configuration to the client. Should be called whenever
Bryce Leea163b762017-01-24 11:05:01 -08002234 * a new merged configuration is sent to the client for this activity.
2235 */
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002236 void setLastReportedConfiguration(@NonNull MergedConfiguration config) {
2237 mLastReportedConfiguration.setTo(config);
Bryce Leea163b762017-01-24 11:05:01 -08002238 }
2239
Andrii Kulian21713ac2016-10-12 22:05:05 -07002240 /** Call when override config was sent to the Window Manager to update internal records. */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002241 // TODO(b/36505427): Why do we set last reported based on sending the config to WM? Seems like
2242 // we should only set this when we actually report to the activity which is what the method
2243 // setLastReportedMergedOverrideConfiguration() does. Investigate if this is really needed.
Andrii Kulian21713ac2016-10-12 22:05:05 -07002244 void onOverrideConfigurationSent() {
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002245 mLastReportedConfiguration.setOverrideConfiguration(getMergedOverrideConfiguration());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002246 }
2247
2248 @Override
Wale Ogunwaled4b1d1e2017-04-10 06:35:59 -07002249 void onOverrideConfigurationChanged(Configuration newConfig) {
2250 final Configuration currentConfig = getOverrideConfiguration();
2251 if (currentConfig.equals(newConfig)) {
2252 return;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002253 }
Wale Ogunwaled4b1d1e2017-04-10 06:35:59 -07002254 super.onOverrideConfigurationChanged(newConfig);
2255 if (mWindowContainerController == null) {
2256 return;
2257 }
2258 mWindowContainerController.onOverrideConfigurationChanged(newConfig, mBounds);
2259 // TODO(b/36505427): Can we consolidate the call points of onOverrideConfigurationSent()
2260 // to just use this method instead?
2261 onOverrideConfigurationSent();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002262 }
2263
2264 // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer.
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002265 private void updateOverrideConfiguration() {
2266 mTmpConfig.unset();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002267 computeBounds(mTmpBounds);
2268 if (mTmpBounds.equals(mBounds)) {
Wale Ogunwaled4b1d1e2017-04-10 06:35:59 -07002269 final ActivityStack stack = getStack();
2270 if (!mBounds.isEmpty() || task == null || stack == null || !task.mFullscreen) {
2271 // We don't want to influence the override configuration here if our task is in
2272 // multi-window mode or there is a bounds specified to calculate the override
2273 // config. In both of this cases the app should be compatible with whatever the
2274 // current configuration is or will be.
2275 return;
2276 }
2277
2278 // Currently limited to the top activity for now to avoid situations where non-top
2279 // visible activity and top might have conflicting requests putting the non-top activity
2280 // windows in an odd state.
2281 final ActivityRecord top = mStackSupervisor.topRunningActivityLocked();
2282 final Configuration parentConfig = getParent().getConfiguration();
2283 if (top != this || isConfigurationCompatible(parentConfig)) {
2284 onOverrideConfigurationChanged(mTmpConfig);
2285 } else if (isConfigurationCompatible(
2286 mLastReportedConfiguration.getMergedConfiguration())) {
2287 onOverrideConfigurationChanged(mLastReportedConfiguration.getMergedConfiguration());
2288 }
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002289 return;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002290 }
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002291
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002292 mBounds.set(mTmpBounds);
2293 // Bounds changed...update configuration to match.
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002294 if (!mBounds.isEmpty()) {
2295 task.computeOverrideConfiguration(mTmpConfig, mBounds, null /* insetBounds */,
2296 false /* overrideWidth */, false /* overrideHeight */);
2297 }
2298 onOverrideConfigurationChanged(mTmpConfig);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002299 }
2300
Wale Ogunwaled4b1d1e2017-04-10 06:35:59 -07002301 /** Returns true if the configuration is compatible with this activity. */
Wale Ogunwale42f07d92017-05-01 21:32:58 -07002302 boolean isConfigurationCompatible(Configuration config) {
Wale Ogunwaled4b1d1e2017-04-10 06:35:59 -07002303 final int orientation = mWindowContainerController != null
2304 ? mWindowContainerController.getOrientation() : info.screenOrientation;
2305 if (isFixedOrientationPortrait(orientation)
2306 && config.orientation != ORIENTATION_PORTRAIT) {
2307 return false;
2308 }
2309 if (isFixedOrientationLandscape(orientation)
2310 && config.orientation != ORIENTATION_LANDSCAPE) {
2311 return false;
2312 }
2313 return true;
2314 }
2315
Bryce Lee7566d762017-03-30 09:34:15 -07002316 /**
2317 * Computes the bounds to fit the Activity within the bounds of the {@link Configuration}.
2318 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002319 // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer.
2320 private void computeBounds(Rect outBounds) {
2321 outBounds.setEmpty();
2322 final float maxAspectRatio = info.maxAspectRatio;
2323 final ActivityStack stack = getStack();
Bryce Leee5ab4502017-07-11 08:58:05 -07002324 if (task == null || stack == null || !task.mFullscreen || maxAspectRatio == 0
2325 || isInVrUiMode(getConfiguration())) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002326 // We don't set override configuration if that activity task isn't fullscreen. I.e. the
2327 // activity is in multi-window mode. Or, there isn't a max aspect ratio specified for
Bryce Leee5ab4502017-07-11 08:58:05 -07002328 // the activity. This is indicated by an empty {@link outBounds}. We also don't set it
2329 // if we are in VR mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002330 return;
2331 }
2332
Bryce Lee7566d762017-03-30 09:34:15 -07002333 // We must base this on the parent configuration, because we set our override
2334 // configuration's appBounds based on the result of this method. If we used our own
2335 // configuration, it would be influenced by past invocations.
2336 final Configuration configuration = getParent().getConfiguration();
2337 final int containingAppWidth = configuration.appBounds.width();
2338 final int containingAppHeight = configuration.appBounds.height();
2339 int maxActivityWidth = containingAppWidth;
2340 int maxActivityHeight = containingAppHeight;
2341
2342 if (containingAppWidth < containingAppHeight) {
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002343 // Width is the shorter side, so we use that to figure-out what the max. height
2344 // should be given the aspect ratio.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002345 maxActivityHeight = (int) ((maxActivityWidth * maxAspectRatio) + 0.5f);
2346 } else {
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002347 // Height is the shorter side, so we use that to figure-out what the max. width
2348 // should be given the aspect ratio.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002349 maxActivityWidth = (int) ((maxActivityHeight * maxAspectRatio) + 0.5f);
2350 }
2351
Bryce Lee7566d762017-03-30 09:34:15 -07002352 if (containingAppWidth <= maxActivityWidth && containingAppHeight <= maxActivityHeight) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002353 // The display matches or is less than the activity aspect ratio, so nothing else to do.
Bryce Lee7566d762017-03-30 09:34:15 -07002354 // Return the existing bounds. If this method is running for the first time,
2355 // {@link mBounds} will be empty (representing no override). If the method has run
2356 // before, then effect of {@link mBounds} will already have been applied to the
2357 // value returned from {@link getConfiguration}. Refer to
2358 // {@link TaskRecord#computeOverrideConfiguration}.
2359 outBounds.set(mBounds);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002360 return;
2361 }
2362
2363 // Compute configuration based on max supported width and height.
2364 outBounds.set(0, 0, maxActivityWidth, maxActivityHeight);
Andrii Kulian3a1619d2017-07-07 14:38:09 -07002365 // Position the activity frame on the opposite side of the nav bar.
2366 final int navBarPosition = service.mWindowManager.getNavBarPosition();
2367 final int left = navBarPosition == NAV_BAR_LEFT
2368 ? configuration.appBounds.right - outBounds.width() : 0;
2369 outBounds.offsetTo(left, 0 /* top */);
2370 }
2371
2372 /** Get bounds of the activity. */
2373 @VisibleForTesting
2374 Rect getBounds() {
2375 return new Rect(mBounds);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002376 }
2377
2378 /**
2379 * Make sure the given activity matches the current configuration. Returns false if the activity
2380 * had to be destroyed. Returns true if the configuration is the same, or the activity will
2381 * remain running as-is for whatever reason. Ensures the HistoryRecord is updated with the
2382 * correct configuration and all other bookkeeping is handled.
2383 */
2384 boolean ensureActivityConfigurationLocked(int globalChanges, boolean preserveWindow) {
2385 final ActivityStack stack = getStack();
2386 if (stack.mConfigWillChange) {
2387 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2388 "Skipping config check (will change): " + this);
2389 return true;
2390 }
2391
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002392 // We don't worry about activities that are finishing.
2393 if (finishing) {
2394 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2395 "Configuration doesn't matter in finishing " + this);
2396 stopFreezingScreenLocked(false);
2397 return true;
2398 }
2399
Wale Ogunwale9b7a8272017-04-10 08:05:41 -07002400 // Skip updating configuration for activity that are stopping or stopped.
2401 if (state == STOPPING || state == STOPPED) {
2402 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2403 "Skipping config check stopped or stopping: " + this);
2404 return true;
2405 }
2406
Wale Ogunwaleea3d3fd2017-05-01 07:41:08 -07002407 // TODO: We should add ActivityRecord.shouldBeVisible() that checks if the activity should
2408 // be visible based on the stack, task, and lockscreen state and use that here instead. The
2409 // method should be based on the logic in ActivityStack.ensureActivitiesVisibleLocked().
Wale Ogunwale9b7a8272017-04-10 08:05:41 -07002410 // Skip updating configuration for activity is a stack that shouldn't be visible.
2411 if (stack.shouldBeVisible(null /* starting */) == STACK_INVISIBLE) {
2412 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2413 "Skipping config check invisible stack: " + this);
2414 return true;
2415 }
2416
Andrii Kulian21713ac2016-10-12 22:05:05 -07002417 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2418 "Ensuring correct configuration: " + this);
2419
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002420 final int newDisplayId = getDisplayId();
2421 final boolean displayChanged = mLastReportedDisplayId != newDisplayId;
2422 if (displayChanged) {
2423 mLastReportedDisplayId = newDisplayId;
2424 }
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002425 // TODO(b/36505427): Is there a better place to do this?
2426 updateOverrideConfiguration();
2427
Winson Chungbdc646f2017-02-13 12:12:22 -08002428 // Short circuit: if the two full configurations are equal (the common case), then there is
2429 // nothing to do. We test the full configuration instead of the global and merged override
2430 // configurations because there are cases (like moving a task to the pinned stack) where
2431 // the combine configurations are equal, but would otherwise differ in the override config
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002432 mTmpConfig.setTo(mLastReportedConfiguration.getMergedConfiguration());
2433 if (getConfiguration().equals(mTmpConfig) && !forceNewConfig && !displayChanged) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002434 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002435 "Configuration & display unchanged in " + this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002436 return true;
2437 }
2438
2439 // Okay we now are going to make this activity have the new config.
2440 // But then we need to figure out how it needs to deal with that.
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002441
2442 // Find changes between last reported merged configuration and the current one. This is used
2443 // to decide whether to relaunch an activity or just report a configuration change.
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002444 final int changes = getConfigurationChanges(mTmpConfig);
Ruben Brunkf64af332017-03-22 22:03:25 -07002445
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002446 // Update last reported values.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002447 final Configuration newMergedOverrideConfig = getMergedOverrideConfiguration();
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002448 mLastReportedConfiguration.setConfiguration(service.getGlobalConfiguration(),
2449 newMergedOverrideConfig);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002450
Andrii Kulian21713ac2016-10-12 22:05:05 -07002451 if (changes == 0 && !forceNewConfig) {
2452 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2453 "Configuration no differences in " + this);
2454 // There are no significant differences, so we won't relaunch but should still deliver
2455 // the new configuration to the client process.
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002456 if (displayChanged) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002457 scheduleActivityMovedToDisplay(newDisplayId, newMergedOverrideConfig);
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002458 } else {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002459 scheduleConfigurationChanged(newMergedOverrideConfig);
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002460 }
Andrii Kulian21713ac2016-10-12 22:05:05 -07002461 return true;
2462 }
2463
2464 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002465 "Configuration changes for " + this + ", allChanges="
Andrii Kulian21713ac2016-10-12 22:05:05 -07002466 + Configuration.configurationDiffToString(changes));
2467
2468 // If the activity isn't currently running, just leave the new configuration and it will
2469 // pick that up next time it starts.
2470 if (app == null || app.thread == null) {
2471 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2472 "Configuration doesn't matter not running " + this);
2473 stopFreezingScreenLocked(false);
2474 forceNewConfig = false;
2475 return true;
2476 }
2477
2478 // Figure out how to handle the changes between the configurations.
2479 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2480 "Checking to restart " + info.name + ": changed=0x"
2481 + Integer.toHexString(changes) + ", handles=0x"
2482 + Integer.toHexString(info.getRealConfigChanged())
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002483 + ", mLastReportedConfiguration=" + mLastReportedConfiguration);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002484
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002485 if (shouldRelaunchLocked(changes, mTmpConfig) || forceNewConfig) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002486 // Aha, the activity isn't handling the change, so DIE DIE DIE.
2487 configChangeFlags |= changes;
2488 startFreezingScreenLocked(app, globalChanges);
2489 forceNewConfig = false;
2490 preserveWindow &= isResizeOnlyChange(changes);
2491 if (app == null || app.thread == null) {
2492 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2493 "Config is destroying non-running " + this);
2494 stack.destroyActivityLocked(this, true, "config");
Ruben Brunkf53497c2017-03-27 20:26:17 -07002495 } else if (state == PAUSING) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002496 // A little annoying: we are waiting for this activity to finish pausing. Let's not
2497 // do anything now, but just flag that it needs to be restarted when done pausing.
2498 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2499 "Config is skipping already pausing " + this);
2500 deferRelaunchUntilPaused = true;
2501 preserveWindowOnDeferredRelaunch = preserveWindow;
2502 return true;
Ruben Brunkf53497c2017-03-27 20:26:17 -07002503 } else if (state == RESUMED) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002504 // Try to optimize this case: the configuration is changing and we need to restart
2505 // the top, resumed activity. Instead of doing the normal handshaking, just say
2506 // "restart!".
2507 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2508 "Config is relaunching resumed " + this);
2509
2510 if (DEBUG_STATES && !visible) {
2511 Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + this
2512 + " called by " + Debug.getCallers(4));
2513 }
2514
2515 relaunchActivityLocked(true /* andResume */, preserveWindow);
2516 } else {
2517 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2518 "Config is relaunching non-resumed " + this);
2519 relaunchActivityLocked(false /* andResume */, preserveWindow);
2520 }
2521
2522 // All done... tell the caller we weren't able to keep this activity around.
2523 return false;
2524 }
2525
2526 // Default case: the activity can handle this new configuration, so hand it over.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002527 // NOTE: We only forward the override configuration as the system level configuration
Andrii Kulian21713ac2016-10-12 22:05:05 -07002528 // changes is always sent to all processes when they happen so it can just use whatever
2529 // system level configuration it last got.
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002530 if (displayChanged) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002531 scheduleActivityMovedToDisplay(newDisplayId, newMergedOverrideConfig);
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002532 } else {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002533 scheduleConfigurationChanged(newMergedOverrideConfig);
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002534 }
Andrii Kulian21713ac2016-10-12 22:05:05 -07002535 stopFreezingScreenLocked(false);
2536
2537 return true;
2538 }
2539
Zak Cohen90e7116742017-01-29 12:59:23 -08002540 /**
2541 * When assessing a configuration change, decide if the changes flags and the new configurations
2542 * should cause the Activity to relaunch.
Ruben Brunkf64af332017-03-22 22:03:25 -07002543 *
2544 * @param changes the changes due to the given configuration.
2545 * @param changesConfig the configuration that was used to calculate the given changes via a
2546 * call to getConfigurationChanges.
Zak Cohen90e7116742017-01-29 12:59:23 -08002547 */
Ruben Brunkf64af332017-03-22 22:03:25 -07002548 private boolean shouldRelaunchLocked(int changes, Configuration changesConfig) {
Zak Cohen90e7116742017-01-29 12:59:23 -08002549 int configChanged = info.getRealConfigChanged();
Ruben Brunkf64af332017-03-22 22:03:25 -07002550 boolean onlyVrUiModeChanged = onlyVrUiModeChanged(changes, changesConfig);
Zak Cohen90e7116742017-01-29 12:59:23 -08002551
2552 // Override for apps targeting pre-O sdks
2553 // If a device is in VR mode, and we're transitioning into VR ui mode, add ignore ui mode
2554 // to the config change.
2555 // For O and later, apps will be required to add configChanges="uimode" to their manifest.
2556 if (appInfo.targetSdkVersion < O
2557 && requestedVrComponent != null
Ruben Brunkf64af332017-03-22 22:03:25 -07002558 && onlyVrUiModeChanged) {
Zak Cohen90e7116742017-01-29 12:59:23 -08002559 configChanged |= CONFIG_UI_MODE;
2560 }
2561
2562 return (changes&(~configChanged)) != 0;
2563 }
2564
Ruben Brunkf64af332017-03-22 22:03:25 -07002565 /**
2566 * Returns true if the configuration change is solely due to the UI mode switching into or out
2567 * of UI_MODE_TYPE_VR_HEADSET.
2568 */
2569 private boolean onlyVrUiModeChanged(int changes, Configuration lastReportedConfig) {
2570 final Configuration currentConfig = getConfiguration();
Ruben Brunkf53497c2017-03-27 20:26:17 -07002571 return changes == CONFIG_UI_MODE && (isInVrUiMode(currentConfig)
Ruben Brunkf64af332017-03-22 22:03:25 -07002572 != isInVrUiMode(lastReportedConfig));
2573 }
2574
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002575 private int getConfigurationChanges(Configuration lastReportedConfig) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002576 // Determine what has changed. May be nothing, if this is a config that has come back from
2577 // the app after going idle. In that case we just want to leave the official config object
2578 // now in the activity and do nothing else.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002579 final Configuration currentConfig = getConfiguration();
2580 int changes = lastReportedConfig.diff(currentConfig);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002581 // We don't want to use size changes if they don't cross boundaries that are important to
2582 // the app.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002583 if ((changes & CONFIG_SCREEN_SIZE) != 0) {
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002584 final boolean crosses = crossesHorizontalSizeThreshold(lastReportedConfig.screenWidthDp,
2585 currentConfig.screenWidthDp)
2586 || crossesVerticalSizeThreshold(lastReportedConfig.screenHeightDp,
2587 currentConfig.screenHeightDp);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002588 if (!crosses) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002589 changes &= ~CONFIG_SCREEN_SIZE;
Andrii Kulian21713ac2016-10-12 22:05:05 -07002590 }
2591 }
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002592 if ((changes & CONFIG_SMALLEST_SCREEN_SIZE) != 0) {
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002593 final int oldSmallest = lastReportedConfig.smallestScreenWidthDp;
2594 final int newSmallest = currentConfig.smallestScreenWidthDp;
2595 if (!crossesSmallestSizeThreshold(oldSmallest, newSmallest)) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002596 changes &= ~CONFIG_SMALLEST_SCREEN_SIZE;
Andrii Kulian21713ac2016-10-12 22:05:05 -07002597 }
2598 }
Bryce Lee600dadd2017-07-25 10:48:42 -07002599
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002600 return changes;
Andrii Kulian21713ac2016-10-12 22:05:05 -07002601 }
2602
2603 private static boolean isResizeOnlyChange(int change) {
2604 return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION
2605 | CONFIG_SCREEN_LAYOUT)) == 0;
2606 }
2607
2608 void relaunchActivityLocked(boolean andResume, boolean preserveWindow) {
2609 if (service.mSuppressResizeConfigChanges && preserveWindow) {
2610 configChangeFlags = 0;
2611 return;
2612 }
2613
2614 List<ResultInfo> pendingResults = null;
2615 List<ReferrerIntent> pendingNewIntents = null;
2616 if (andResume) {
2617 pendingResults = results;
2618 pendingNewIntents = newIntents;
2619 }
2620 if (DEBUG_SWITCH) Slog.v(TAG_SWITCH,
2621 "Relaunching: " + this + " with results=" + pendingResults
2622 + " newIntents=" + pendingNewIntents + " andResume=" + andResume
2623 + " preserveWindow=" + preserveWindow);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002624 EventLog.writeEvent(andResume ? AM_RELAUNCH_RESUME_ACTIVITY
2625 : AM_RELAUNCH_ACTIVITY, userId, System.identityHashCode(this),
Andrii Kulian21713ac2016-10-12 22:05:05 -07002626 task.taskId, shortComponentName);
2627
2628 startFreezingScreenLocked(app, 0);
2629
2630 mStackSupervisor.removeChildActivityContainers(this);
2631
2632 try {
2633 if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH,
2634 "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + this
2635 + " callers=" + Debug.getCallers(6));
2636 forceNewConfig = false;
2637 mStackSupervisor.activityRelaunchingLocked(this);
2638 app.thread.scheduleRelaunchActivity(appToken, pendingResults, pendingNewIntents,
2639 configChangeFlags, !andResume,
2640 new Configuration(service.getGlobalConfiguration()),
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002641 new Configuration(getMergedOverrideConfiguration()), preserveWindow);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002642 // Note: don't need to call pauseIfSleepingLocked() here, because the caller will only
2643 // pass in 'andResume' if this activity is currently resumed, which implies we aren't
2644 // sleeping.
2645 } catch (RemoteException e) {
2646 if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e);
2647 }
2648
2649 if (andResume) {
2650 if (DEBUG_STATES) {
2651 Slog.d(TAG_STATES, "Resumed after relaunch " + this);
2652 }
2653 results = null;
2654 newIntents = null;
2655 service.showUnsupportedZoomDialogIfNeededLocked(this);
2656 service.showAskCompatModeDialogLocked(this);
2657 } else {
Ruben Brunkf53497c2017-03-27 20:26:17 -07002658 service.mHandler.removeMessages(PAUSE_TIMEOUT_MSG, this);
2659 state = PAUSED;
Andrii Kulian21713ac2016-10-12 22:05:05 -07002660 // if the app is relaunched when it's stopped, and we're not resuming,
2661 // put it back into stopped state.
2662 if (stopped) {
Winson Chung4dabf232017-01-25 13:25:22 -08002663 getStack().addToStopping(this, true /* scheduleIdle */, false /* idleDelayed */);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002664 }
2665 }
2666
2667 configChangeFlags = 0;
2668 deferRelaunchUntilPaused = false;
2669 preserveWindowOnDeferredRelaunch = false;
2670 }
2671
Jorim Jaggibae01b12017-04-11 16:29:10 -07002672 private boolean isProcessRunning() {
Jorim Jaggi02886a82016-12-06 09:10:06 -08002673 ProcessRecord proc = app;
2674 if (proc == null) {
2675 proc = service.mProcessNames.get(processName, info.applicationInfo.uid);
2676 }
2677 return proc != null && proc.thread != null;
2678 }
2679
Jorim Jaggibae01b12017-04-11 16:29:10 -07002680 /**
2681 * @return Whether a task snapshot starting window may be shown.
2682 */
2683 private boolean allowTaskSnapshot() {
2684 if (newIntents == null) {
2685 return true;
2686 }
2687
2688 // Restrict task snapshot starting window to launcher start, or there is no intent at all
2689 // (eg. task being brought to front). If the intent is something else, likely the app is
2690 // going to show some specific page or view, instead of what's left last time.
2691 for (int i = newIntents.size() - 1; i >= 0; i--) {
2692 final Intent intent = newIntents.get(i);
2693 if (intent != null && !ActivityRecord.isMainIntent(intent)) {
2694 return false;
2695 }
2696 }
2697 return true;
2698 }
2699
Bryce Leeb7c9b802017-05-02 14:20:24 -07002700 /**
2701 * Returns {@code true} if the associated activity has the no history flag set on it.
2702 * {@code false} otherwise.
2703 */
2704 boolean isNoHistory() {
2705 return (intent.getFlags() & FLAG_ACTIVITY_NO_HISTORY) != 0
2706 || (info.flags & FLAG_NO_HISTORY) != 0;
2707 }
2708
Craig Mautner21d24a22014-04-23 11:45:37 -07002709 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
2710 out.attribute(null, ATTR_ID, String.valueOf(createTime));
2711 out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
2712 if (launchedFromPackage != null) {
2713 out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage);
2714 }
2715 if (resolvedType != null) {
2716 out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType);
2717 }
2718 out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified));
2719 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Winson Chung2cb86c72014-06-25 12:03:30 -07002720
Craig Mautner21d24a22014-04-23 11:45:37 -07002721 if (taskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07002722 taskDescription.saveToXml(out);
Craig Mautner21d24a22014-04-23 11:45:37 -07002723 }
2724
2725 out.startTag(null, TAG_INTENT);
2726 intent.saveToXml(out);
2727 out.endTag(null, TAG_INTENT);
2728
2729 if (isPersistable() && persistentState != null) {
2730 out.startTag(null, TAG_PERSISTABLEBUNDLE);
2731 persistentState.saveToXml(out);
2732 out.endTag(null, TAG_PERSISTABLEBUNDLE);
2733 }
2734 }
2735
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07002736 static ActivityRecord restoreFromXml(XmlPullParser in,
2737 ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07002738 Intent intent = null;
2739 PersistableBundle persistentState = null;
2740 int launchedFromUid = 0;
2741 String launchedFromPackage = null;
2742 String resolvedType = null;
2743 boolean componentSpecified = false;
2744 int userId = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07002745 long createTime = -1;
2746 final int outerDepth = in.getDepth();
Winson Chung2cb86c72014-06-25 12:03:30 -07002747 TaskDescription taskDescription = new TaskDescription();
Craig Mautner21d24a22014-04-23 11:45:37 -07002748
2749 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
2750 final String attrName = in.getAttributeName(attrNdx);
2751 final String attrValue = in.getAttributeValue(attrNdx);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002752 if (DEBUG) Slog.d(TaskPersister.TAG,
Wale Ogunwale18795a22014-12-03 11:38:33 -08002753 "ActivityRecord: attribute name=" + attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002754 if (ATTR_ID.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01002755 createTime = Long.parseLong(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002756 } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01002757 launchedFromUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002758 } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
2759 launchedFromPackage = attrValue;
2760 } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
2761 resolvedType = attrValue;
2762 } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
Tobias Thiererb0800dc2016-04-21 17:51:41 +01002763 componentSpecified = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002764 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01002765 userId = Integer.parseInt(attrValue);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002766 } else if (attrName.startsWith(ATTR_TASKDESCRIPTION_PREFIX)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07002767 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002768 } else {
2769 Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName);
2770 }
2771 }
2772
2773 int event;
Ruben Brunkf53497c2017-03-27 20:26:17 -07002774 while (((event = in.next()) != END_DOCUMENT) &&
2775 (event != END_TAG || in.getDepth() >= outerDepth)) {
2776 if (event == START_TAG) {
Craig Mautner21d24a22014-04-23 11:45:37 -07002777 final String name = in.getName();
Ruben Brunkf53497c2017-03-27 20:26:17 -07002778 if (DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08002779 Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name);
Craig Mautner21d24a22014-04-23 11:45:37 -07002780 if (TAG_INTENT.equals(name)) {
2781 intent = Intent.restoreFromXml(in);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002782 if (DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08002783 Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07002784 } else if (TAG_PERSISTABLEBUNDLE.equals(name)) {
2785 persistentState = PersistableBundle.restoreFromXml(in);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002786 if (DEBUG) Slog.d(TaskPersister.TAG,
Craig Mautner21d24a22014-04-23 11:45:37 -07002787 "ActivityRecord: persistentState=" + persistentState);
2788 } else {
2789 Slog.w(TAG, "restoreActivity: unexpected name=" + name);
2790 XmlUtils.skipCurrentTag(in);
2791 }
2792 }
2793 }
2794
2795 if (intent == null) {
Craig Mautnere0129b32014-05-25 16:41:09 -07002796 throw new XmlPullParserException("restoreActivity error intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07002797 }
2798
2799 final ActivityManagerService service = stackSupervisor.mService;
2800 final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null,
Jeff Hao1b012d32014-08-20 10:35:34 -07002801 userId);
Craig Mautnere0129b32014-05-25 16:41:09 -07002802 if (aInfo == null) {
Craig Mautner77b04262014-06-27 15:22:12 -07002803 throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent +
2804 " resolvedType=" + resolvedType);
Craig Mautnere0129b32014-05-25 16:41:09 -07002805 }
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002806 final ActivityRecord r = new ActivityRecord(service, null /* caller */,
2807 0 /* launchedFromPid */, launchedFromUid, launchedFromPackage, intent, resolvedType,
2808 aInfo, service.getConfiguration(), null /* resultTo */, null /* resultWho */,
2809 0 /* reqCode */, componentSpecified, false /* rootVoiceInteraction */,
2810 stackSupervisor, null /* container */, null /* options */, null /* sourceRecord */);
Craig Mautner21d24a22014-04-23 11:45:37 -07002811
2812 r.persistentState = persistentState;
Winson Chung2cb86c72014-06-25 12:03:30 -07002813 r.taskDescription = taskDescription;
Craig Mautner21d24a22014-04-23 11:45:37 -07002814 r.createTime = createTime;
2815
2816 return r;
2817 }
2818
2819 private static String activityTypeToString(int type) {
Craig Mautnerae7ecab2013-09-18 11:48:14 -07002820 switch (type) {
2821 case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE";
2822 case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE";
2823 case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE";
Winson Chung83471632016-12-13 11:02:12 -08002824 case ASSISTANT_ACTIVITY_TYPE: return "ASSISTANT_ACTIVITY_TYPE";
Craig Mautnerae7ecab2013-09-18 11:48:14 -07002825 default: return Integer.toString(type);
2826 }
2827 }
2828
Zak Cohen90e7116742017-01-29 12:59:23 -08002829 private static boolean isInVrUiMode(Configuration config) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07002830 return (config.uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_VR_HEADSET;
Zak Cohen90e7116742017-01-29 12:59:23 -08002831 }
2832
David Stevens82ea6cb2017-03-03 16:18:50 -08002833 int getUid() {
2834 return info.applicationInfo.uid;
2835 }
2836
Craig Mautnerf81b90872013-02-26 13:02:43 -08002837 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002838 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002839 if (stringName != null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08002840 return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) +
Craig Mautnerf3333272013-04-22 10:55:53 -07002841 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002842 }
2843 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -08002844 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002845 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -07002846 sb.append(" u");
2847 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002848 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002849 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -08002850 stringName = sb.toString();
2851 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 }
2853}