blob: 6557a7a6682ab52c5fc5b6d074621c0ab30c1028 [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
Winson Chungbb348802017-01-30 12:01:45 -080019import static android.app.ActivityManager.LOCK_TASK_MODE_NONE;
Wale Ogunwale65ebd952018-04-25 15:41:44 -070020import static android.app.ActivityTaskManager.INVALID_STACK_ID;
Ruben Brunkf53497c2017-03-27 20:26:17 -070021import static android.app.ActivityManager.TaskDescription.ATTR_TASKDESCRIPTION_PREFIX;
22import static android.app.ActivityOptions.ANIM_CLIP_REVEAL;
23import static android.app.ActivityOptions.ANIM_CUSTOM;
Jorim Jaggi33a701a2017-12-01 14:58:18 +010024import static android.app.ActivityOptions.ANIM_REMOTE_ANIMATION;
Ruben Brunkf53497c2017-03-27 20:26:17 -070025import static android.app.ActivityOptions.ANIM_SCALE_UP;
26import static android.app.ActivityOptions.ANIM_SCENE_TRANSITION;
Tony Mak089c35e2017-12-18 20:34:14 +000027import static android.app.ActivityOptions.ANIM_OPEN_CROSS_PROFILE_APPS;
Ruben Brunkf53497c2017-03-27 20:26:17 -070028import static android.app.ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN;
29import static android.app.ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP;
30import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN;
31import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_UP;
Winson Chung59fda9e2017-01-20 16:14:51 -080032import static android.app.AppOpsManager.MODE_ALLOWED;
Winson Chungf4ac0632017-03-17 12:34:12 -070033import static android.app.AppOpsManager.OP_PICTURE_IN_PICTURE;
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -070034import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT;
35import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
36import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -070037import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
38import static android.app.WindowConfiguration.activityTypeToString;
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;
Wale Ogunwale822e5122017-07-26 06:02:24 -070049import static android.content.pm.ActivityInfo.CONFIG_WINDOW_CONFIGURATION;
Jorim Jaggi02886a82016-12-06 09:10:06 -080050import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080051import static android.content.pm.ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
52import static android.content.pm.ActivityInfo.FLAG_IMMERSIVE;
53import static android.content.pm.ActivityInfo.FLAG_MULTIPROCESS;
Jorim Jaggie7d2b852017-08-28 17:55:15 +020054import static android.content.pm.ActivityInfo.FLAG_NO_HISTORY;
Chong Zhang87761972016-08-22 13:53:24 -070055import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS;
Jorim Jaggie7d2b852017-08-28 17:55:15 +020056import static android.content.pm.ActivityInfo.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080057import static android.content.pm.ActivityInfo.FLAG_STATE_NOT_NEEDED;
chaviw59b98852017-06-13 12:05:44 -070058import static android.content.pm.ActivityInfo.FLAG_TURN_SCREEN_ON;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080059import static android.content.pm.ActivityInfo.LAUNCH_MULTIPLE;
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -080060import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE;
61import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080062import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP;
Charles He2bf28322017-10-12 22:24:49 +010063import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS;
64import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT;
65import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
66import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER;
Ruben Brunkf53497c2017-03-27 20:26:17 -070067import static android.content.pm.ActivityInfo.PERSIST_ACROSS_REBOOTS;
68import static android.content.pm.ActivityInfo.PERSIST_ROOT_ONLY;
Wale Ogunwaledf241e92016-10-13 15:14:21 -070069import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
Jorim Jaggicd13d332016-04-27 15:40:20 -070070import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
Wale Ogunwale72a73e32016-10-13 12:16:39 -070071import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Wale Ogunwaledf241e92016-10-13 15:14:21 -070072import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
Wale Ogunwaled4b1d1e2017-04-10 06:35:59 -070073import static android.content.pm.ActivityInfo.isFixedOrientationLandscape;
74import static android.content.pm.ActivityInfo.isFixedOrientationPortrait;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -070075import static android.content.res.Configuration.EMPTY;
Wale Ogunwalee610d3d2017-04-25 10:23:48 -070076import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
77import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
Ruben Brunkf53497c2017-03-27 20:26:17 -070078import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
Zak Cohen90e7116742017-01-29 12:59:23 -080079import static android.content.res.Configuration.UI_MODE_TYPE_VR_HEADSET;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080080import static android.os.Build.VERSION_CODES.HONEYCOMB;
Zak Cohen90e7116742017-01-29 12:59:23 -080081import static android.os.Build.VERSION_CODES.O;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080082import static android.os.Process.SYSTEM_UID;
Ruben Brunkf53497c2017-03-27 20:26:17 -070083import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080084import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION;
Andrii Kulian21713ac2016-10-12 22:05:05 -070085import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE;
Andrii Kulian21713ac2016-10-12 22:05:05 -070086import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080087import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH;
Andrii Kulian21713ac2016-10-12 22:05:05 -070088import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBILITY;
89import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONFIGURATION;
90import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SAVED_STATE;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080091import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES;
92import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH;
Andrii Kulian21713ac2016-10-12 22:05:05 -070093import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBILITY;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080094import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
95import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Ruben Brunkf53497c2017-03-27 20:26:17 -070096import static com.android.server.am.ActivityStack.ActivityState.INITIALIZING;
97import static com.android.server.am.ActivityStack.ActivityState.PAUSED;
98import static com.android.server.am.ActivityStack.ActivityState.PAUSING;
99import static com.android.server.am.ActivityStack.ActivityState.RESUMED;
100import static com.android.server.am.ActivityStack.ActivityState.STOPPED;
101import static com.android.server.am.ActivityStack.ActivityState.STOPPING;
102import static com.android.server.am.ActivityStack.LAUNCH_TICK;
103import static com.android.server.am.ActivityStack.LAUNCH_TICK_MSG;
104import static com.android.server.am.ActivityStack.PAUSE_TIMEOUT_MSG;
105import static com.android.server.am.ActivityStack.STOP_TIMEOUT_MSG;
106import static com.android.server.am.EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME;
107import static com.android.server.am.EventLogTags.AM_ACTIVITY_LAUNCH_TIME;
108import static com.android.server.am.EventLogTags.AM_RELAUNCH_ACTIVITY;
109import static com.android.server.am.EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY;
110import static com.android.server.am.TaskPersister.DEBUG;
111import static com.android.server.am.TaskPersister.IMAGE_EXTENSION;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800112import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700113import static com.android.server.am.ActivityRecordProto.CONFIGURATION_CONTAINER;
114import static com.android.server.am.ActivityRecordProto.FRONT_OF_TASK;
115import static com.android.server.am.ActivityRecordProto.IDENTIFIER;
116import static com.android.server.am.ActivityRecordProto.PROC_ID;
117import static com.android.server.am.ActivityRecordProto.STATE;
Wale Ogunwale30eab1f2018-05-24 18:25:25 -0700118import static com.android.server.am.ActivityRecordProto.TRANSLUCENT;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700119import static com.android.server.am.ActivityRecordProto.VISIBLE;
Adrian Roose99bc052017-11-20 17:55:31 +0100120import static com.android.server.policy.WindowManagerPolicy.NAV_BAR_LEFT;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700121import static com.android.server.wm.IdentifierProto.HASH_CODE;
122import static com.android.server.wm.IdentifierProto.TITLE;
123import static com.android.server.wm.IdentifierProto.USER_ID;
Steven Timotius4346f0a2017-09-12 11:07:21 -0700124
Ruben Brunkf53497c2017-03-27 20:26:17 -0700125import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
126import static org.xmlpull.v1.XmlPullParser.END_TAG;
127import static org.xmlpull.v1.XmlPullParser.START_TAG;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800128
Andrii Kulian21713ac2016-10-12 22:05:05 -0700129import android.annotation.NonNull;
Craig Mautner21d24a22014-04-23 11:45:37 -0700130import android.app.ActivityManager.TaskDescription;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700131import android.app.ActivityOptions;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800132import android.app.PendingIntent;
Winson Chung709904f2017-04-25 11:00:48 -0700133import android.app.PictureInPictureParams;
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800134import android.app.ResultInfo;
Andrii Kulianb372da62018-01-18 10:46:24 -0800135import android.app.servertransaction.ActivityLifecycleItem;
136import android.app.servertransaction.ActivityRelaunchItem;
137import android.app.servertransaction.ClientTransaction;
138import android.app.servertransaction.ClientTransactionItem;
Andrii Kulian446e8242017-10-26 15:17:29 -0700139import android.app.servertransaction.MoveToDisplayItem;
140import android.app.servertransaction.MultiWindowModeChangeItem;
141import android.app.servertransaction.NewIntentItem;
Bryce Lee0bd8d422018-01-09 09:45:57 -0800142import android.app.servertransaction.PauseActivityItem;
Andrii Kulian446e8242017-10-26 15:17:29 -0700143import android.app.servertransaction.PipModeChangeItem;
Andrii Kulianb372da62018-01-18 10:46:24 -0800144import android.app.servertransaction.ResumeActivityItem;
Andrii Kulian446e8242017-10-26 15:17:29 -0700145import android.app.servertransaction.WindowVisibilityItem;
146import android.app.servertransaction.ActivityConfigurationChangeItem;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147import android.content.ComponentName;
148import android.content.Intent;
149import android.content.pm.ActivityInfo;
150import android.content.pm.ApplicationInfo;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700151import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152import android.content.res.Configuration;
153import android.graphics.Bitmap;
Winson Chungaa7fa012017-05-24 15:50:06 -0700154import android.graphics.GraphicBuffer;
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700155import android.graphics.Rect;
Patrick Baumann78380272018-04-04 10:41:01 -0700156import android.os.Binder;
Bryce Lee39791592017-04-26 09:29:12 -0700157import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158import android.os.Bundle;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700159import android.os.Debug;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800160import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161import android.os.Message;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800162import android.os.PersistableBundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163import android.os.Process;
Dianne Hackborn39792d22010-08-19 18:01:52 -0700164import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165import android.os.SystemClock;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800166import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700167import android.os.UserHandle;
Bryce Lee8558ec72017-08-17 15:37:26 -0700168import android.os.storage.StorageManager;
Amith Yamasani0af6fa72016-01-17 15:36:19 -0800169import android.service.voice.IVoiceInteractionSession;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170import android.util.EventLog;
171import android.util.Log;
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700172import android.util.MergedConfiguration;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700173import android.util.Slog;
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700174import android.util.TimeUtils;
Steven Timotius4346f0a2017-09-12 11:07:21 -0700175import android.util.proto.ProtoOutputStream;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700176import android.view.AppTransitionAnimationSpec;
Jorim Jaggi34795e32017-05-12 17:27:46 +0200177import android.view.IAppTransitionAnimationSpecsFuture;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178import android.view.IApplicationToken;
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100179import android.view.RemoteAnimationDefinition;
Jorim Jaggife762342016-10-13 14:33:27 +0200180import android.view.WindowManager.LayoutParams;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700181
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -0700182import com.android.internal.R;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800183import com.android.internal.app.ResolverActivity;
184import com.android.internal.content.ReferrerIntent;
185import com.android.internal.util.XmlUtils;
186import com.android.server.AttributeCache;
Ruben Brunkf53497c2017-03-27 20:26:17 -0700187import com.android.server.AttributeCache.Entry;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800188import com.android.server.am.ActivityStack.ActivityState;
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -0700189import com.android.server.uri.UriPermissionOwner;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800190import com.android.server.wm.AppWindowContainerController;
191import com.android.server.wm.AppWindowContainerListener;
Wale Ogunwale98d62312017-07-12 09:24:56 -0700192import com.android.server.wm.ConfigurationContainer;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800193import com.android.server.wm.TaskWindowContainerController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194
Jorim Jaggi02886a82016-12-06 09:10:06 -0800195import org.xmlpull.v1.XmlPullParser;
196import org.xmlpull.v1.XmlPullParserException;
197import org.xmlpull.v1.XmlSerializer;
198
Suprabh Shukla23593142015-11-03 17:31:15 -0800199import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -0700200import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201import java.io.PrintWriter;
202import java.lang.ref.WeakReference;
203import java.util.ArrayList;
Todd Kennedy39bfee52016-02-24 10:28:21 -0800204import java.util.Arrays;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205import java.util.HashSet;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700206import java.util.List;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700207import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208
209/**
210 * An entry in the history stack, representing an activity.
211 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700212final class ActivityRecord extends ConfigurationContainer implements AppWindowContainerListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800213 private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityRecord" : TAG_AM;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700214 private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION;
215 private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700216 private static final String TAG_STATES = TAG + POSTFIX_STATES;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700217 private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700218 private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY;
Winson Chung16e185e2017-11-07 08:30:54 -0800219 // TODO(b/67864419): Remove once recents component is overridden
220 private static final String LEGACY_RECENTS_PACKAGE_NAME = "com.android.systemui.recents";
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800221
Wale Ogunwale3ab9a272015-03-16 09:55:45 -0700222 private static final boolean SHOW_ACTIVITY_START_TIME = true;
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700223
Craig Mautner21d24a22014-04-23 11:45:37 -0700224 private static final String ATTR_ID = "id";
225 private static final String TAG_INTENT = "intent";
226 private static final String ATTR_USERID = "user_id";
227 private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle";
228 private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700229 private static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package";
Craig Mautner21d24a22014-04-23 11:45:37 -0700230 private static final String ATTR_RESOLVEDTYPE = "resolved_type";
231 private static final String ATTR_COMPONENTSPECIFIED = "component_specified";
Dianne Hackborn337abb32014-09-24 12:44:29 -0700232 static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_";
Craig Mautner21d24a22014-04-23 11:45:37 -0700233
Wale Ogunwaled0412b32018-05-08 09:25:50 -0700234 final ActivityTaskManagerService service; // owner
Dianne Hackbornbe707852011-11-11 14:32:10 -0800235 final IApplicationToken.Stub appToken; // window manager token
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800236 AppWindowContainerController mWindowContainerController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 final ActivityInfo info; // all about me
Philip P. Moltmanncff8f0f2018-03-27 12:51:51 -0700238 // TODO: This is duplicated state already contained in info.applicationInfo - remove
239 ApplicationInfo appInfo; // information about activity's app
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800240 final int launchedFromPid; // always the pid who started the activity.
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700241 final int launchedFromUid; // always the uid who started the activity.
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800242 final String launchedFromPackage; // always the package who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -0700243 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 final Intent intent; // the original intent that generated us
245 final ComponentName realActivity; // the intent component, or target of an alias.
246 final String shortComponentName; // the short component name of the intent
247 final String resolvedType; // as per original caller;
248 final String packageName; // the package implementing intent's component
249 final String processName; // process where this component wants to run
250 final String taskAffinity; // as per ActivityInfo.taskAffinity
251 final boolean stateNotNeeded; // As per ActivityInfo.flags
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -0700252 boolean fullscreen; // The activity is opaque and fills the entire space of this task.
253 // TODO: See if it possible to combine this with the fullscreen field.
254 final boolean hasWallpaper; // Has a wallpaper window as a background.
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800255 final boolean noDisplay; // activity is not displayed?
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800256 private final boolean componentSpecified; // did caller specify an explicit component?
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700257 final boolean rootVoiceInteraction; // was this the root activity of a voice interaction?
Craig Mautner86d67a42013-05-14 10:34:38 -0700258
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800259 private CharSequence nonLocalizedLabel; // the label information from the package mgr.
260 private int labelRes; // the label information from the package mgr.
261 private int icon; // resource identifier of activity's icon.
262 private int logo; // resource identifier of activity's logo.
263 private int theme; // resource identifier of activity's theme.
264 private int realTheme; // actual theme resource we will use, never 0.
265 private int windowFlags; // custom window flags for preview window.
Bryce Leeaf691c02017-03-20 14:20:22 -0700266 private TaskRecord task; // the task this is in.
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800267 private long createTime = System.currentTimeMillis();
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700268 long displayStartTime; // when we started launching this activity
269 long fullyDrawnStartTime; // when we started launching this activity
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800270 private long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -0800271 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700272 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700273 long pauseTime; // last time we started pausing the activity
274 long launchTickTime; // base time for launch tick messages
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700275 // Last configuration reported to the activity in the client process.
276 private MergedConfiguration mLastReportedConfiguration;
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800277 private int mLastReportedDisplayId;
Winson Chung609e1e92017-05-08 10:52:12 -0700278 private boolean mLastReportedMultiWindowMode;
279 private boolean mLastReportedPictureInPictureMode;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700280 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700281 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 final String resultWho; // additional identifier for use by resultTo.
283 final int requestCode; // code given by requester (resultTo)
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800284 ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800286 ArrayList<ReferrerIntent> newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700287 ActivityOptions pendingOptions; // most recently given options
George Mount6ba042b2014-07-28 11:12:28 -0700288 ActivityOptions returningOptions; // options that are coming back via convertToTranslucent
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700289 AppTimeTracker appTimeTracker; // set if we are tracking the time in this app/task/activity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700291 UriPermissionOwner uriPermissions; // current special URI access perms.
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700292 WindowProcessController app; // if non-null, hosting application
Bryce Lee7ace3952018-02-16 14:34:32 -0800293 private ActivityState mState; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 Bundle icicle; // last saved activity state
Craig Mautnera0026042014-04-23 11:45:37 -0700295 PersistableBundle persistentState; // last persistently saved activity state
Wale Ogunwale66e16852017-10-19 13:35:52 -0700296 // TODO: See if this is still needed.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 boolean frontOfTask; // is this the root activity of its task?
298 boolean launchFailed; // set if a launched failed, to abort on 2nd try
299 boolean haveState; // have we gotten the last activity state?
300 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700301 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 boolean finishing; // activity in pending finish list?
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800303 boolean deferRelaunchUntilPaused; // relaunch of activity is being deferred until pause is
304 // completed
305 boolean preserveWindowOnDeferredRelaunch; // activity windows are preserved on deferred relaunch
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306 int configChangeFlags; // which config values have changed
Wale Ogunwaleec950642017-04-25 07:44:21 -0700307 private boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 int launchMode; // the launch mode activity attribute.
Charles He2bf28322017-10-12 22:24:49 +0100309 int lockTaskLaunchMode; // the lockTaskMode manifest attribute, subject to override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310 boolean visible; // does this activity's window need to be shown?
Jorim Jaggi241ae102016-11-02 21:57:33 -0700311 boolean visibleIgnoringKeyguard; // is this activity visible, ignoring the fact that Keyguard
312 // might hide this activity?
Wale Ogunwaleec950642017-04-25 07:44:21 -0700313 private boolean mDeferHidingClient; // If true we told WM to defer reporting to the client
314 // process that it is hidden.
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800315 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 boolean nowVisible; // is this activity's window visible?
Andrii Kuliana39ae3e2018-05-31 12:43:54 -0700317 boolean mClientVisibilityDeferred;// was the visibility change message to client deferred?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 boolean idle; // has the activity gone idle?
319 boolean hasBeenLaunched;// has this activity ever been launched?
320 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400321 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400322 boolean forceNewConfig; // force re-create with new config next time
Winson Chungf7e03e12017-08-22 11:32:16 -0700323 boolean supportsEnterPipOnTaskSwitch; // This flag is set by the system to indicate that the
324 // activity can enter picture in picture while pausing (only when switching to another task)
Winson Chung709904f2017-04-25 11:00:48 -0700325 PictureInPictureParams pictureInPictureArgs = new PictureInPictureParams.Builder().build();
326 // The PiP params used when deferring the entering of picture-in-picture.
Dianne Hackborn07981492013-01-28 11:36:23 -0800327 int launchCount; // count of launches since last state
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800328 long lastLaunchTime; // time of last launch of this activity
Ruben Brunke24b9a62016-02-16 21:38:24 -0800329 ComponentName requestedVrComponent; // the requested component for handling VR mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700331 String stringName; // for caching of toString().
Craig Mautnerde4ef022013-04-07 19:01:33 -0700332
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700333 private boolean inHistory; // are we in the history stack?
Craig Mautnerde4ef022013-04-07 19:01:33 -0700334 final ActivityStackSupervisor mStackSupervisor;
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800335
336 static final int STARTING_WINDOW_NOT_SHOWN = 0;
337 static final int STARTING_WINDOW_SHOWN = 1;
338 static final int STARTING_WINDOW_REMOVED = 2;
339 int mStartingWindowState = STARTING_WINDOW_NOT_SHOWN;
Wale Ogunwale3b232392016-05-13 15:37:13 -0700340 boolean mTaskOverlay = false; // Task is always on-top of other activities in the task.
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800341
Garfield Tan2746ab52018-07-25 12:33:01 -0700342 // This activity is not being relaunched, or being relaunched for a non-resize reason.
343 static final int RELAUNCH_REASON_NONE = 0;
344 // This activity is being relaunched due to windowing mode change.
345 static final int RELAUNCH_REASON_WINDOWING_MODE_RESIZE = 1;
346 // This activity is being relaunched due to a free-resize operation.
347 static final int RELAUNCH_REASON_FREE_RESIZE = 2;
348 // Marking the reason why this activity is being relaunched. Mainly used to track that this
349 // activity is being relaunched to fulfill a resize request due to compatibility issues, e.g. in
350 // pre-NYC apps that don't have a sense of being resized.
351 int mRelaunchReason = RELAUNCH_REASON_NONE;
352
Craig Mautner21d24a22014-04-23 11:45:37 -0700353 TaskDescription taskDescription; // the recents information for this activity
Craig Mautnerbb742462014-07-07 15:28:55 -0700354 boolean mLaunchTaskBehind; // this activity is actively being launched with
355 // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed.
Craig Mautner2fbd7542014-03-21 09:34:07 -0700356
Filip Gruszczynski23493322015-07-29 17:02:59 -0700357 // These configurations are collected from application's resources based on size-sensitive
358 // qualifiers. For example, layout-w800dp will be added to mHorizontalSizeConfigurations as 800
359 // and drawable-sw400dp will be added to both as 400.
360 private int[] mVerticalSizeConfigurations;
361 private int[] mHorizontalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700362 private int[] mSmallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700363
Amith Yamasani0af6fa72016-01-17 15:36:19 -0800364 boolean pendingVoiceInteractionStart; // Waiting for activity-invoked voice session
365 IVoiceInteractionSession voiceSession; // Voice interaction session for this activity
366
Robert Carrd2265122016-08-05 10:25:21 -0700367 // A hint to override the window specified rotation animation, or -1
368 // to use the window specified value. We use this so that
369 // we can select the right animation in the cases of starting
370 // windows, where the app hasn't had time to set a value
371 // on the window.
372 int mRotationAnimationHint = -1;
Robert Carrfd10cd12016-06-29 16:41:50 -0700373
chaviw59b98852017-06-13 12:05:44 -0700374 private boolean mShowWhenLocked;
375 private boolean mTurnScreenOn;
376
Andrii Kulian21713ac2016-10-12 22:05:05 -0700377 /**
Wale Ogunwaleb6d75f32018-02-22 20:44:56 -0800378 * Temp configs used in {@link #ensureActivityConfiguration(int, boolean)}
Andrii Kulian21713ac2016-10-12 22:05:05 -0700379 */
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700380 private final Configuration mTmpConfig = new Configuration();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700381 private final Rect mTmpBounds = new Rect();
Andrii Kulian21713ac2016-10-12 22:05:05 -0700382
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800383 private static String startingWindowStateToString(int state) {
384 switch (state) {
385 case STARTING_WINDOW_NOT_SHOWN:
386 return "STARTING_WINDOW_NOT_SHOWN";
387 case STARTING_WINDOW_SHOWN:
388 return "STARTING_WINDOW_SHOWN";
389 case STARTING_WINDOW_REMOVED:
390 return "STARTING_WINDOW_REMOVED";
391 default:
392 return "unknown state=" + state;
393 }
394 }
395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700397 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700398 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
399 pw.print(" processName="); pw.println(processName);
400 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Craig Mautnere11f2b72013-04-01 12:37:17 -0700401 pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800402 pw.print(" userId="); pw.println(userId);
403 pw.print(prefix); pw.print("app="); pw.println(app);
404 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700405 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
406 pw.print(" task="); pw.println(task);
407 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700408 pw.print(prefix); pw.print("realActivity=");
409 pw.println(realActivity.flattenToShortString());
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700410 if (appInfo != null) {
411 pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir);
412 if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) {
413 pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir);
414 }
415 pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir);
Todd Kennedy39bfee52016-02-24 10:28:21 -0800416 if (appInfo.splitSourceDirs != null) {
417 pw.print(prefix); pw.print("splitDir=");
418 pw.println(Arrays.toString(appInfo.splitSourceDirs));
419 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800420 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700421 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
422 pw.print(" componentSpecified="); pw.print(componentSpecified);
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -0700423 pw.print(" mActivityType="); pw.println(
424 activityTypeToString(getActivityType()));
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700425 if (rootVoiceInteraction) {
426 pw.print(prefix); pw.print("rootVoiceInteraction="); pw.println(rootVoiceInteraction);
427 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800428 pw.print(prefix); pw.print("compat="); pw.print(compat);
429 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
430 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
431 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700432 pw.println(prefix + "mLastReportedConfigurations:");
433 mLastReportedConfiguration.dump(pw, prefix + " ");
434
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700435 pw.print(prefix); pw.print("CurrentConfiguration="); pw.println(getConfiguration());
436 if (!getOverrideConfiguration().equals(EMPTY)) {
437 pw.println(prefix + "OverrideConfiguration=" + getOverrideConfiguration());
438 }
Bryce Leef3c6a472017-11-14 14:53:06 -0800439 if (!matchParentBounds()) {
440 pw.println(prefix + "bounds=" + getBounds());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700441 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700442 if (resultTo != null || resultWho != null) {
443 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
444 pw.print(" resultWho="); pw.print(resultWho);
445 pw.print(" resultCode="); pw.println(requestCode);
446 }
Craig Mautner29c58ca2014-10-14 16:17:06 -0700447 if (taskDescription != null) {
448 final String iconFilename = taskDescription.getIconFilename();
449 if (iconFilename != null || taskDescription.getLabel() != null ||
450 taskDescription.getPrimaryColor() != 0) {
451 pw.print(prefix); pw.print("taskDescription:");
Craig Mautner29c58ca2014-10-14 16:17:06 -0700452 pw.print(" label=\""); pw.print(taskDescription.getLabel());
453 pw.print("\"");
Matthew Ng54bc9422017-10-02 17:16:28 -0700454 pw.print(" icon="); pw.print(taskDescription.getInMemoryIcon() != null
455 ? taskDescription.getInMemoryIcon().getByteCount() + " bytes"
456 : "null");
457 pw.print(" iconResource="); pw.print(taskDescription.getIconResource());
458 pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename());
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200459 pw.print(" primaryColor=");
Craig Mautner29c58ca2014-10-14 16:17:06 -0700460 pw.println(Integer.toHexString(taskDescription.getPrimaryColor()));
Wale Ogunwale822e5122017-07-26 06:02:24 -0700461 pw.print(prefix + " backgroundColor=");
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200462 pw.println(Integer.toHexString(taskDescription.getBackgroundColor()));
Wale Ogunwale822e5122017-07-26 06:02:24 -0700463 pw.print(prefix + " statusBarColor=");
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200464 pw.println(Integer.toHexString(taskDescription.getStatusBarColor()));
Wale Ogunwale822e5122017-07-26 06:02:24 -0700465 pw.print(prefix + " navigationBarColor=");
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200466 pw.println(Integer.toHexString(taskDescription.getNavigationBarColor()));
Craig Mautner29c58ca2014-10-14 16:17:06 -0700467 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700468 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700469 if (results != null) {
470 pw.print(prefix); pw.print("results="); pw.println(results);
471 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700472 if (pendingResults != null && pendingResults.size() > 0) {
473 pw.print(prefix); pw.println("Pending Results:");
474 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
475 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
476 pw.print(prefix); pw.print(" - ");
477 if (pir == null) {
478 pw.println("null");
479 } else {
480 pw.println(pir);
481 pir.dump(pw, prefix + " ");
482 }
483 }
484 }
485 if (newIntents != null && newIntents.size() > 0) {
486 pw.print(prefix); pw.println("Pending New Intents:");
487 for (int i=0; i<newIntents.size(); i++) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800488 Intent intent = newIntents.get(i);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700489 pw.print(prefix); pw.print(" - ");
490 if (intent == null) {
491 pw.println("null");
492 } else {
493 pw.println(intent.toShortString(false, true, false, true));
494 }
495 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700496 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700497 if (pendingOptions != null) {
498 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
499 }
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700500 if (appTimeTracker != null) {
501 appTimeTracker.dumpWithHeader(pw, prefix, false);
502 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700503 if (uriPermissions != null) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700504 uriPermissions.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700505 }
506 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800507 pw.print(" launchCount="); pw.print(launchCount);
508 pw.print(" lastLaunchTime=");
509 if (lastLaunchTime == 0) pw.print("0");
510 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
511 pw.println();
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700512 pw.print(prefix); pw.print("haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700513 pw.print(" icicle="); pw.println(icicle);
Bryce Lee7ace3952018-02-16 14:34:32 -0800514 pw.print(prefix); pw.print("state="); pw.print(mState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700515 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700516 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700517 pw.print(" finishing="); pw.println(finishing);
518 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
519 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700520 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800521 pw.print(" sleeping="); pw.print(sleeping);
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800522 pw.print(" idle="); pw.print(idle);
523 pw.print(" mStartingWindowState=");
524 pw.println(startingWindowStateToString(mStartingWindowState));
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800525 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
526 pw.print(" noDisplay="); pw.print(noDisplay);
527 pw.print(" immersive="); pw.print(immersive);
528 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800529 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400530 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700531 pw.print(prefix); pw.print("mActivityType=");
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -0700532 pw.println(activityTypeToString(getActivityType()));
Ruben Brunke24b9a62016-02-16 21:38:24 -0800533 if (requestedVrComponent != null) {
534 pw.print(prefix);
535 pw.print("requestedVrComponent=");
536 pw.println(requestedVrComponent);
537 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700538 if (displayStartTime != 0 || startTime != 0) {
539 pw.print(prefix); pw.print("displayStartTime=");
540 if (displayStartTime == 0) pw.print("0");
541 else TimeUtils.formatDuration(displayStartTime, now, pw);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700542 pw.print(" startTime=");
543 if (startTime == 0) pw.print("0");
544 else TimeUtils.formatDuration(startTime, now, pw);
545 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700546 }
Bryce Lee4a194382017-04-04 14:32:48 -0700547 final boolean waitingVisible =
548 mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(this);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800549 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700550 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800551 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700552 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700553 if (lastVisibleTime == 0) pw.print("0");
554 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
555 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700556 }
Wale Ogunwaleec950642017-04-25 07:44:21 -0700557 if (mDeferHidingClient) {
558 pw.println(prefix + "mDeferHidingClient=" + mDeferHidingClient);
559 }
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800560 if (deferRelaunchUntilPaused || configChangeFlags != 0) {
561 pw.print(prefix); pw.print("deferRelaunchUntilPaused="); pw.print(deferRelaunchUntilPaused);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700562 pw.print(" configChangeFlags=");
563 pw.println(Integer.toHexString(configChangeFlags));
564 }
565 if (connections != null) {
566 pw.print(prefix); pw.print("connections="); pw.println(connections);
567 }
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800568 if (info != null) {
569 pw.println(prefix + "resizeMode=" + ActivityInfo.resizeModeToString(info.resizeMode));
Winson Chung609e1e92017-05-08 10:52:12 -0700570 pw.println(prefix + "mLastReportedMultiWindowMode=" + mLastReportedMultiWindowMode
571 + " mLastReportedPictureInPictureMode=" + mLastReportedPictureInPictureMode);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700572 if (info.supportsPictureInPicture()) {
573 pw.println(prefix + "supportsPictureInPicture=" + info.supportsPictureInPicture());
Winson Chungf7e03e12017-08-22 11:32:16 -0700574 pw.println(prefix + "supportsEnterPipOnTaskSwitch: "
575 + supportsEnterPipOnTaskSwitch);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700576 }
577 if (info.maxAspectRatio != 0) {
578 pw.println(prefix + "maxAspectRatio=" + info.maxAspectRatio);
579 }
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800580 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 }
582
Philip P. Moltmanncff8f0f2018-03-27 12:51:51 -0700583 void updateApplicationInfo(ApplicationInfo aInfo) {
584 appInfo = aInfo;
585 info.applicationInfo = aInfo;
586 }
587
Andrii Kulian21713ac2016-10-12 22:05:05 -0700588 private boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700589 return crossesSizeThreshold(mHorizontalSizeConfigurations, firstDp, secondDp);
590 }
591
Andrii Kulian21713ac2016-10-12 22:05:05 -0700592 private boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700593 return crossesSizeThreshold(mVerticalSizeConfigurations, firstDp, secondDp);
594 }
595
Andrii Kulian21713ac2016-10-12 22:05:05 -0700596 private boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700597 return crossesSizeThreshold(mSmallestSizeConfigurations, firstDp, secondDp);
598 }
599
Filip Gruszczynski23493322015-07-29 17:02:59 -0700600 /**
601 * The purpose of this method is to decide whether the activity needs to be relaunched upon
602 * changing its size. In most cases the activities don't need to be relaunched, if the resize
603 * is small, all the activity content has to do is relayout itself within new bounds. There are
604 * cases however, where the activity's content would be completely changed in the new size and
605 * the full relaunch is required.
606 *
607 * The activity will report to us vertical and horizontal thresholds after which a relaunch is
608 * required. These thresholds are collected from the application resource qualifiers. For
609 * example, if application has layout-w600dp resource directory, then it needs a relaunch when
610 * we resize from width of 650dp to 550dp, as it crosses the 600dp threshold. However, if
611 * it resizes width from 620dp to 700dp, it won't be relaunched as it stays on the same side
612 * of the threshold.
613 */
614 private static boolean crossesSizeThreshold(int[] thresholds, int firstDp,
615 int secondDp) {
616 if (thresholds == null) {
617 return false;
618 }
619 for (int i = thresholds.length - 1; i >= 0; i--) {
620 final int threshold = thresholds[i];
621 if ((firstDp < threshold && secondDp >= threshold)
622 || (firstDp >= threshold && secondDp < threshold)) {
623 return true;
624 }
625 }
626 return false;
627 }
628
Andrii Kulian21713ac2016-10-12 22:05:05 -0700629 void setSizeConfigurations(int[] horizontalSizeConfiguration,
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700630 int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700631 mHorizontalSizeConfigurations = horizontalSizeConfiguration;
632 mVerticalSizeConfigurations = verticalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700633 mSmallestSizeConfigurations = smallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700634 }
635
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800636 private void scheduleActivityMovedToDisplay(int displayId, Configuration config) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700637 if (!attachedToProcess()) {
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800638 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.w(TAG,
639 "Can't report activity moved to display - client not running, activityRecord="
640 + this + ", displayId=" + displayId);
Wale Ogunwale22e25262016-02-01 10:32:02 -0800641 return;
642 }
643 try {
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800644 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
645 "Reporting activity moved to display" + ", activityRecord=" + this
646 + ", displayId=" + displayId + ", config=" + config);
Chong Zhang6be533e2016-06-17 16:24:21 -0700647
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700648 service.getLifecycleManager().scheduleTransaction(app.getThread(), appToken,
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -0800649 MoveToDisplayItem.obtain(displayId, config));
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800650 } catch (RemoteException e) {
651 // If process died, whatever.
652 }
653 }
654
655 private void scheduleConfigurationChanged(Configuration config) {
Wale Ogunwalef6733932018-06-27 05:14:34 -0700656 if (!attachedToProcess()) {
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800657 if (DEBUG_CONFIGURATION) Slog.w(TAG,
658 "Can't report activity configuration update - client not running"
659 + ", activityRecord=" + this);
660 return;
661 }
662 try {
663 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + this + ", config: "
664 + config);
665
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700666 service.getLifecycleManager().scheduleTransaction(app.getThread(), appToken,
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -0800667 ActivityConfigurationChangeItem.obtain(config));
Wale Ogunwale22e25262016-02-01 10:32:02 -0800668 } catch (RemoteException e) {
669 // If process died, whatever.
670 }
671 }
672
Winson Chung5af42fc2017-03-24 17:11:33 -0700673 void updateMultiWindowMode() {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700674 if (task == null || task.getStack() == null || !attachedToProcess()) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800675 return;
676 }
Winson Chung5af42fc2017-03-24 17:11:33 -0700677
Wale Ogunwaleeb76b762017-11-17 10:08:04 -0800678 if (task.getStack().deferScheduleMultiWindowModeChanged()) {
679 // Don't do anything if we are currently deferring multi-window mode change.
680 return;
681 }
682
Winson Chung5af42fc2017-03-24 17:11:33 -0700683 // An activity is considered to be in multi-window mode if its task isn't fullscreen.
Wale Ogunwaleeb76b762017-11-17 10:08:04 -0800684 final boolean inMultiWindowMode = inMultiWindowMode();
Winson Chung609e1e92017-05-08 10:52:12 -0700685 if (inMultiWindowMode != mLastReportedMultiWindowMode) {
686 mLastReportedMultiWindowMode = inMultiWindowMode;
Winson Chung5af42fc2017-03-24 17:11:33 -0700687 scheduleMultiWindowModeChanged(getConfiguration());
688 }
689 }
690
691 private void scheduleMultiWindowModeChanged(Configuration overrideConfig) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800692 try {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700693 service.getLifecycleManager().scheduleTransaction(app.getThread(), appToken,
Wale Ogunwaled0412b32018-05-08 09:25:50 -0700694 MultiWindowModeChangeItem.obtain(mLastReportedMultiWindowMode, overrideConfig));
Wale Ogunwale22e25262016-02-01 10:32:02 -0800695 } catch (Exception e) {
696 // If process died, I don't care.
697 }
698 }
699
Winson Chungab76bbc2017-08-14 13:33:51 -0700700 void updatePictureInPictureMode(Rect targetStackBounds, boolean forceUpdate) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700701 if (task == null || task.getStack() == null || !attachedToProcess()) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800702 return;
703 }
Winson Chung5af42fc2017-03-24 17:11:33 -0700704
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700705 final boolean inPictureInPictureMode = inPinnedWindowingMode() && targetStackBounds != null;
Winson Chungab76bbc2017-08-14 13:33:51 -0700706 if (inPictureInPictureMode != mLastReportedPictureInPictureMode || forceUpdate) {
Winson Chung5af42fc2017-03-24 17:11:33 -0700707 // Picture-in-picture mode changes also trigger a multi-window mode change as well, so
Winson Chung059955f2018-08-08 16:10:20 -0700708 // update that here in order. Set the last reported MW state to the same as the PiP
709 // state since we haven't yet actually resized the task (these callbacks need to
710 // preceed the configuration change from the resiez.
711 // TODO(110009072): Once we move these callbacks to the client, remove all logic related
712 // to forcing the update of the picture-in-picture mode as a part of the PiP animation.
Winson Chung609e1e92017-05-08 10:52:12 -0700713 mLastReportedPictureInPictureMode = inPictureInPictureMode;
Winson Chung059955f2018-08-08 16:10:20 -0700714 mLastReportedMultiWindowMode = inPictureInPictureMode;
Winson Chung5af42fc2017-03-24 17:11:33 -0700715 final Configuration newConfig = task.computeNewOverrideConfigurationForBounds(
716 targetStackBounds, null);
717 schedulePictureInPictureModeChanged(newConfig);
718 scheduleMultiWindowModeChanged(newConfig);
719 }
720 }
721
722 private void schedulePictureInPictureModeChanged(Configuration overrideConfig) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800723 try {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700724 service.getLifecycleManager().scheduleTransaction(app.getThread(), appToken,
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -0800725 PipModeChangeItem.obtain(mLastReportedPictureInPictureMode,
Andrii Kulian446e8242017-10-26 15:17:29 -0700726 overrideConfig));
Wale Ogunwale22e25262016-02-01 10:32:02 -0800727 } catch (Exception e) {
728 // If process died, no one cares.
Filip Gruszczynskica664812015-12-04 12:43:36 -0800729 }
730 }
731
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700732 @Override
733 protected int getChildCount() {
734 // {@link ActivityRecord} is a leaf node and has no children.
735 return 0;
736 }
737
738 @Override
739 protected ConfigurationContainer getChildAt(int index) {
740 return null;
741 }
742
743 @Override
744 protected ConfigurationContainer getParent() {
Bryce Leeaf691c02017-03-20 14:20:22 -0700745 return getTask();
746 }
747
748 TaskRecord getTask() {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700749 return task;
750 }
751
Bryce Leeaf691c02017-03-20 14:20:22 -0700752 /**
753 * Sets reference to the {@link TaskRecord} the {@link ActivityRecord} will treat as its parent.
754 * Note that this does not actually add the {@link ActivityRecord} as a {@link TaskRecord}
755 * children. However, this method will clean up references to this {@link ActivityRecord} in
756 * {@link ActivityStack}.
757 * @param task The new parent {@link TaskRecord}.
758 */
759 void setTask(TaskRecord task) {
Bryce Lee84730a02018-04-03 14:10:04 -0700760 setTask(task /* task */, false /* reparenting */);
Bryce Leeaf691c02017-03-20 14:20:22 -0700761 }
762
763 /**
764 * This method should only be called by {@link TaskRecord#removeActivity(ActivityRecord)}.
Bryce Lee84730a02018-04-03 14:10:04 -0700765 * @param task The new parent task.
766 * @param reparenting Whether we're in the middle of reparenting.
Bryce Leeaf691c02017-03-20 14:20:22 -0700767 */
768 void setTask(TaskRecord task, boolean reparenting) {
769 // Do nothing if the {@link TaskRecord} is the same as the current {@link getTask}.
770 if (task != null && task == getTask()) {
771 return;
772 }
773
Bryce Lee84730a02018-04-03 14:10:04 -0700774 final ActivityStack oldStack = getStack();
775 final ActivityStack newStack = task != null ? task.getStack() : null;
Bryce Leeaf691c02017-03-20 14:20:22 -0700776
Bryce Lee84730a02018-04-03 14:10:04 -0700777 // Inform old stack (if present) of activity removal and new stack (if set) of activity
778 // addition.
779 if (oldStack != newStack) {
780 if (!reparenting && oldStack != null) {
781 oldStack.onActivityRemovedFromStack(this);
782 }
783
784 if (newStack != null) {
785 newStack.onActivityAddedToStack(this);
786 }
Bryce Leeaf691c02017-03-20 14:20:22 -0700787 }
788
789 this.task = task;
790
791 if (!reparenting) {
792 onParentChanged();
793 }
794 }
795
chaviw4ad54912018-05-30 11:05:44 -0700796 /**
797 * See {@link AppWindowContainerController#setWillCloseOrEnterPip(boolean)}
798 */
799 void setWillCloseOrEnterPip(boolean willCloseOrEnterPip) {
800 getWindowContainerController().setWillCloseOrEnterPip(willCloseOrEnterPip);
801 }
802
Dianne Hackbornbe707852011-11-11 14:32:10 -0800803 static class Token extends IApplicationToken.Stub {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700804 private final WeakReference<ActivityRecord> weakActivity;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700805 private final String name;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800806
Steven Timotiusaf03df62017-07-18 16:56:43 -0700807 Token(ActivityRecord activity, Intent intent) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800808 weakActivity = new WeakReference<>(activity);
Steven Timotiusaf03df62017-07-18 16:56:43 -0700809 name = intent.getComponent().flattenToShortString();
Wale Ogunwale7d701172015-03-11 15:36:30 -0700810 }
811
Andrii Kulian21713ac2016-10-12 22:05:05 -0700812 private static ActivityRecord tokenToActivityRecordLocked(Token token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700813 if (token == null) {
814 return null;
815 }
816 ActivityRecord r = token.weakActivity.get();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700817 if (r == null || r.getStack() == null) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700818 return null;
819 }
820 return r;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800821 }
822
Craig Mautnerde4ef022013-04-07 19:01:33 -0700823 @Override
Dianne Hackbornbe707852011-11-11 14:32:10 -0800824 public String toString() {
825 StringBuilder sb = new StringBuilder(128);
826 sb.append("Token{");
827 sb.append(Integer.toHexString(System.identityHashCode(this)));
828 sb.append(' ');
829 sb.append(weakActivity.get());
830 sb.append('}');
831 return sb.toString();
832 }
Steven Timotiusaf03df62017-07-18 16:56:43 -0700833
834 @Override
835 public String getName() {
836 return name;
837 }
Dianne Hackbornbe707852011-11-11 14:32:10 -0800838 }
839
Wale Ogunwale7d701172015-03-11 15:36:30 -0700840 static ActivityRecord forTokenLocked(IBinder token) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800841 try {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700842 return Token.tokenToActivityRecordLocked((Token)token);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800843 } catch (ClassCastException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800844 Slog.w(TAG, "Bad activity token: " + token, e);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800845 return null;
846 }
847 }
848
Chong Zhang85ee6542015-10-02 13:36:38 -0700849 boolean isResolverActivity() {
850 return ResolverActivity.class.getName().equals(realActivity.getClassName());
Craig Mautnerac6f8432013-07-17 13:24:59 -0700851 }
852
Patrick Baumann31426b22018-05-21 13:46:40 -0700853 boolean isResolverOrChildActivity() {
854 if (!"android".equals(packageName)) {
855 return false;
856 }
857 try {
858 return ResolverActivity.class.isAssignableFrom(
859 Object.class.getClassLoader().loadClass(realActivity.getClassName()));
860 } catch (ClassNotFoundException e) {
861 return false;
862 }
863 }
864
Wale Ogunwaled0412b32018-05-08 09:25:50 -0700865 ActivityRecord(ActivityTaskManagerService _service, ProcessRecord _caller, int _launchedFromPid,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800866 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800867 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700868 ActivityRecord _resultTo, String _resultWho, int _reqCode,
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700869 boolean _componentSpecified, boolean _rootVoiceInteraction,
Andrii Kulian94e82d9b02017-07-13 15:33:06 -0700870 ActivityStackSupervisor supervisor, ActivityOptions options,
871 ActivityRecord sourceRecord) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872 service = _service;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700873 appToken = new Token(this, _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800874 info = aInfo;
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800875 launchedFromPid = _launchedFromPid;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800876 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800877 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700878 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879 intent = _intent;
880 shortComponentName = _intent.getComponent().flattenToShortString();
881 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800882 componentSpecified = _componentSpecified;
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700883 rootVoiceInteraction = _rootVoiceInteraction;
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700884 mLastReportedConfiguration = new MergedConfiguration(_configuration);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800885 resultTo = _resultTo;
886 resultWho = _resultWho;
887 requestCode = _reqCode;
Bryce Lee7ace3952018-02-16 14:34:32 -0800888 setState(INITIALIZING, "ActivityRecord ctor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800889 frontOfTask = false;
890 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700892 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893 finishing = false;
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800894 deferRelaunchUntilPaused = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 keysPaused = false;
896 inHistory = false;
Chong Zhanga48ef662015-08-18 19:21:47 -0700897 visible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898 nowVisible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800899 idle = false;
900 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700901 mStackSupervisor = supervisor;
Robert Carr0f5d7532016-10-17 16:39:17 -0700902
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800903 // This starts out true, since the initial state of an activity is that we have everything,
904 // and we shouldn't never consider it lacking in state to be removed if it dies.
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700905 haveState = true;
906
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800907 // If the class name in the intent doesn't match that of the target, this is
908 // probably an alias. We have to create a new ComponentName object to keep track
909 // of the real activity name, so that FLAG_ACTIVITY_CLEAR_TOP is handled properly.
910 if (aInfo.targetActivity == null
911 || (aInfo.targetActivity.equals(_intent.getComponent().getClassName())
912 && (aInfo.launchMode == LAUNCH_MULTIPLE
913 || aInfo.launchMode == LAUNCH_SINGLE_TOP))) {
914 realActivity = _intent.getComponent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 } else {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800916 realActivity = new ComponentName(aInfo.packageName, aInfo.targetActivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800918 taskAffinity = aInfo.taskAffinity;
919 stateNotNeeded = (aInfo.flags & FLAG_STATE_NOT_NEEDED) != 0;
920 appInfo = aInfo.applicationInfo;
921 nonLocalizedLabel = aInfo.nonLocalizedLabel;
922 labelRes = aInfo.labelRes;
923 if (nonLocalizedLabel == null && labelRes == 0) {
924 ApplicationInfo app = aInfo.applicationInfo;
925 nonLocalizedLabel = app.nonLocalizedLabel;
926 labelRes = app.labelRes;
927 }
928 icon = aInfo.getIconResource();
929 logo = aInfo.getLogoResource();
930 theme = aInfo.getThemeResource();
931 realTheme = theme;
932 if (realTheme == 0) {
933 realTheme = aInfo.applicationInfo.targetSdkVersion < HONEYCOMB
934 ? android.R.style.Theme : android.R.style.Theme_Holo;
935 }
936 if ((aInfo.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
937 windowFlags |= LayoutParams.FLAG_HARDWARE_ACCELERATED;
938 }
939 if ((aInfo.flags & FLAG_MULTIPROCESS) != 0 && _caller != null
940 && (aInfo.applicationInfo.uid == SYSTEM_UID
941 || aInfo.applicationInfo.uid == _caller.info.uid)) {
942 processName = _caller.processName;
943 } else {
944 processName = aInfo.processName;
945 }
946
947 if ((aInfo.flags & FLAG_EXCLUDE_FROM_RECENTS) != 0) {
948 intent.addFlags(FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
949 }
950
951 packageName = aInfo.applicationInfo.packageName;
952 launchMode = aInfo.launchMode;
953
Ruben Brunkf53497c2017-03-27 20:26:17 -0700954 Entry ent = AttributeCache.instance().get(packageName,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800955 realTheme, com.android.internal.R.styleable.Window, userId);
Bryce Leee83f34cd2017-10-31 19:50:54 -0700956
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -0700957 if (ent != null) {
958 fullscreen = !ActivityInfo.isTranslucentOrFloating(ent.array);
959 hasWallpaper = ent.array.getBoolean(R.styleable.Window_windowShowWallpaper, false);
960 noDisplay = ent.array.getBoolean(R.styleable.Window_windowNoDisplay, false);
961 } else {
962 hasWallpaper = false;
963 noDisplay = false;
964 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800965
Winson Chung83471632016-12-13 11:02:12 -0800966 setActivityType(_componentSpecified, _launchedFromUid, _intent, options, sourceRecord);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800967
968 immersive = (aInfo.flags & FLAG_IMMERSIVE) != 0;
969
970 requestedVrComponent = (aInfo.requestedVrComponent == null) ?
971 null : ComponentName.unflattenFromString(aInfo.requestedVrComponent);
chaviw59b98852017-06-13 12:05:44 -0700972
973 mShowWhenLocked = (aInfo.flags & FLAG_SHOW_WHEN_LOCKED) != 0;
974 mTurnScreenOn = (aInfo.flags & FLAG_TURN_SCREEN_ON) != 0;
Charles He2bf28322017-10-12 22:24:49 +0100975
976 mRotationAnimationHint = aInfo.rotationAnimation;
977 lockTaskLaunchMode = aInfo.lockTaskLaunchMode;
978 if (appInfo.isPrivilegedApp() && (lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_ALWAYS
979 || lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_NEVER)) {
980 lockTaskLaunchMode = LOCK_TASK_LAUNCH_MODE_DEFAULT;
981 }
982
983 if (options != null) {
984 pendingOptions = options;
985 mLaunchTaskBehind = options.getLaunchTaskBehind();
986
987 final int rotationAnimation = pendingOptions.getRotationAnimationHint();
988 // Only override manifest supplied option if set.
989 if (rotationAnimation >= 0) {
990 mRotationAnimationHint = rotationAnimation;
991 }
992 final PendingIntent usageReport = pendingOptions.getUsageTimeReport();
993 if (usageReport != null) {
994 appTimeTracker = new AppTimeTracker(usageReport);
995 }
996 final boolean useLockTask = pendingOptions.getLockTaskMode();
997 if (useLockTask && lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_DEFAULT) {
998 lockTaskLaunchMode = LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
999 }
1000 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001001 }
1002
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001003 void setProcess(WindowProcessController proc) {
Dianne Hackborn68a06332017-11-15 17:54:18 -08001004 app = proc;
1005 final ActivityRecord root = task != null ? task.getRootActivity() : null;
1006 if (root == this) {
1007 task.setRootProcess(proc);
1008 }
1009 }
1010
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001011 boolean hasProcess() {
1012 return app != null;
1013 }
1014
1015 boolean attachedToProcess() {
1016 return hasProcess() && app.hasThread();
1017 }
1018
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -08001019 AppWindowContainerController getWindowContainerController() {
1020 return mWindowContainerController;
1021 }
1022
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001023 void createWindowContainer() {
1024 if (mWindowContainerController != null) {
1025 throw new IllegalArgumentException("Window container=" + mWindowContainerController
1026 + " already created for r=" + this);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001027 }
1028
1029 inHistory = true;
1030
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -08001031 final TaskWindowContainerController taskController = task.getWindowContainerController();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001032
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07001033 // TODO(b/36505427): Maybe this call should be moved inside updateOverrideConfiguration()
1034 task.updateOverrideConfigurationFromLaunchBounds();
1035 // Make sure override configuration is up-to-date before using to create window controller.
1036 updateOverrideConfiguration();
1037
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -08001038 mWindowContainerController = new AppWindowContainerController(taskController, appToken,
1039 this, Integer.MAX_VALUE /* add on top */, info.screenOrientation, fullscreen,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001040 (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, info.configChanges,
1041 task.voiceSession != null, mLaunchTaskBehind, isAlwaysFocusable(),
1042 appInfo.targetSdkVersion, mRotationAnimationHint,
Wale Ogunwale906f9c62018-07-23 11:23:44 -07001043 ActivityTaskManagerService.getInputDispatchingTimeoutLocked(this) * 1000000L);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001044
1045 task.addActivityToTop(this);
1046
Winson Chung609e1e92017-05-08 10:52:12 -07001047 // When an activity is started directly into a split-screen fullscreen stack, we need to
1048 // update the initial multi-window modes so that the callbacks are scheduled correctly when
1049 // the user leaves that mode.
Bryce Leef3c6a472017-11-14 14:53:06 -08001050 mLastReportedMultiWindowMode = inMultiWindowMode();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001051 mLastReportedPictureInPictureMode = inPinnedWindowingMode();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001052 }
1053
1054 void removeWindowContainer() {
Bryce Lee7ace3952018-02-16 14:34:32 -08001055 // Do not try to remove a window container if we have already removed it.
1056 if (mWindowContainerController == null) {
1057 return;
1058 }
1059
Wale Ogunwalecc367f42017-02-01 08:12:14 -08001060 // Resume key dispatching if it is currently paused before we remove the container.
1061 resumeKeyDispatchingLocked();
1062
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001063 mWindowContainerController.removeContainer(getDisplayId());
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -08001064 mWindowContainerController = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 }
1066
Winson Chung30480042017-01-26 10:55:34 -08001067 /**
1068 * Reparents this activity into {@param newTask} at the provided {@param position}. The caller
1069 * should ensure that the {@param newTask} is not already the parent of this activity.
1070 */
1071 void reparent(TaskRecord newTask, int position, String reason) {
1072 final TaskRecord prevTask = task;
1073 if (prevTask == newTask) {
1074 throw new IllegalArgumentException(reason + ": task=" + newTask
1075 + " is already the parent of r=" + this);
1076 }
1077
Winson Chung74666102017-02-22 17:49:24 -08001078 // TODO: Ensure that we do not directly reparent activities across stacks, as that may leave
1079 // the stacks in strange states. For now, we should use Task.reparent() to ensure that
1080 // the stack is left in an OK state.
1081 if (prevTask != null && newTask != null && prevTask.getStack() != newTask.getStack()) {
1082 throw new IllegalArgumentException(reason + ": task=" + newTask
1083 + " is in a different stack (" + newTask.getStackId() + ") than the parent of"
1084 + " r=" + this + " (" + prevTask.getStackId() + ")");
1085 }
1086
Winson Chung30480042017-01-26 10:55:34 -08001087 // Must reparent first in window manager
1088 mWindowContainerController.reparent(newTask.getWindowContainerController(), position);
1089
Bryce Lee84730a02018-04-03 14:10:04 -07001090 // Reparenting prevents informing the parent stack of activity removal in the case that
1091 // the new stack has the same parent. we must manually signal here if this is not the case.
1092 final ActivityStack prevStack = prevTask.getStack();
1093
1094 if (prevStack != newTask.getStack()) {
1095 prevStack.onActivityRemovedFromStack(this);
1096 }
Bryce Leeaf691c02017-03-20 14:20:22 -07001097 // Remove the activity from the old task and add it to the new task.
Bryce Lee84730a02018-04-03 14:10:04 -07001098 prevTask.removeActivity(this, true /* reparenting */);
Bryce Lee0f9bde82017-02-22 16:39:06 -08001099
Winson Chung30480042017-01-26 10:55:34 -08001100 newTask.addActivityAtIndex(position, this);
1101 }
1102
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001103 private boolean isHomeIntent(Intent intent) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001104 return ACTION_MAIN.equals(intent.getAction())
1105 && intent.hasCategory(CATEGORY_HOME)
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001106 && intent.getCategories().size() == 1
1107 && intent.getData() == null
1108 && intent.getType() == null;
1109 }
1110
Chong Zhangad24f962016-08-25 12:12:33 -07001111 static boolean isMainIntent(Intent intent) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001112 return ACTION_MAIN.equals(intent.getAction())
1113 && intent.hasCategory(CATEGORY_LAUNCHER)
Chong Zhangad24f962016-08-25 12:12:33 -07001114 && intent.getCategories().size() == 1
1115 && intent.getData() == null
1116 && intent.getType() == null;
1117 }
1118
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001119 private boolean canLaunchHomeActivity(int uid, ActivityRecord sourceRecord) {
1120 if (uid == Process.myUid() || uid == 0) {
1121 // System process can launch home activity.
1122 return true;
1123 }
Winson Chung547afd22018-05-17 16:03:25 -07001124 // Allow the recents component to launch the home activity.
Wale Ogunwalec9e57de2018-05-08 14:28:07 -07001125 final RecentTasks recentTasks = mStackSupervisor.mService.getRecentTasks();
Winson Chung547afd22018-05-17 16:03:25 -07001126 if (recentTasks != null && recentTasks.isCallerRecents(uid)) {
1127 return true;
1128 }
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001129 // Resolver activity can launch home activity.
1130 return sourceRecord != null && sourceRecord.isResolverActivity();
1131 }
1132
Winson Chung83471632016-12-13 11:02:12 -08001133 /**
1134 * @return whether the given package name can launch an assist activity.
1135 */
1136 private boolean canLaunchAssistActivity(String packageName) {
Wale Ogunwaled0412b32018-05-08 09:25:50 -07001137 final ComponentName assistComponent =
1138 service.mActiveVoiceInteractionServiceComponent;
Winson Chung83471632016-12-13 11:02:12 -08001139 if (assistComponent != null) {
1140 return assistComponent.getPackageName().equals(packageName);
1141 }
1142 return false;
1143 }
1144
1145 private void setActivityType(boolean componentSpecified, int launchedFromUid, Intent intent,
1146 ActivityOptions options, ActivityRecord sourceRecord) {
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001147 int activityType = ACTIVITY_TYPE_UNDEFINED;
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001148 if ((!componentSpecified || canLaunchHomeActivity(launchedFromUid, sourceRecord))
1149 && isHomeIntent(intent) && !isResolverActivity()) {
1150 // This sure looks like a home activity!
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001151 activityType = ACTIVITY_TYPE_HOME;
Wale Ogunwaledf241e92016-10-13 15:14:21 -07001152
1153 if (info.resizeMode == RESIZE_MODE_FORCE_RESIZEABLE
1154 || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) {
1155 // We only allow home activities to be resizeable if they explicitly requested it.
1156 info.resizeMode = RESIZE_MODE_UNRESIZEABLE;
1157 }
Wale Ogunwale16e505a2018-05-07 15:00:49 -07001158 } else if (realActivity.getClassName().contains(LEGACY_RECENTS_PACKAGE_NAME)
Wale Ogunwaled0412b32018-05-08 09:25:50 -07001159 || service.getRecentTasks().isRecentsComponent(realActivity, appInfo.uid)) {
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001160 activityType = ACTIVITY_TYPE_RECENTS;
Wale Ogunwale0568aed2017-09-08 13:29:37 -07001161 } else if (options != null && options.getLaunchActivityType() == ACTIVITY_TYPE_ASSISTANT
Winson Chung83471632016-12-13 11:02:12 -08001162 && canLaunchAssistActivity(launchedFromPackage)) {
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001163 activityType = ACTIVITY_TYPE_ASSISTANT;
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001164 }
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001165 setActivityType(activityType);
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001166 }
1167
Craig Mautnera228ae92014-07-09 05:44:55 -07001168 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001169 if (launchMode != LAUNCH_SINGLE_INSTANCE && launchMode != LAUNCH_SINGLE_TASK) {
Craig Mautnera228ae92014-07-09 05:44:55 -07001170 task.setTaskToAffiliateWith(taskToAffiliateWith);
1171 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001172 }
1173
Andrii Kulian02b7a832016-10-06 23:11:56 -07001174 /**
1175 * @return Stack value from current task, null if there is no task.
1176 */
Winson Chung55893332017-02-17 17:13:10 -08001177 <T extends ActivityStack> T getStack() {
1178 return task != null ? (T) task.getStack() : null;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001179 }
1180
Jorim Jaggicdfc04e2017-04-28 19:06:24 +02001181 int getStackId() {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001182 return getStack() != null ? getStack().mStackId : INVALID_STACK_ID;
1183 }
1184
Wale Ogunwale04a05ac2017-09-17 21:35:02 -07001185 ActivityDisplay getDisplay() {
1186 final ActivityStack stack = getStack();
1187 return stack != null ? stack.getDisplay() : null;
1188 }
1189
Craig Mautner5eda9b32013-07-02 11:58:16 -07001190 boolean changeWindowTranslucency(boolean toOpaque) {
1191 if (fullscreen == toOpaque) {
1192 return false;
1193 }
Craig Mautner4addfc52013-06-25 08:05:45 -07001194
Craig Mautner5eda9b32013-07-02 11:58:16 -07001195 // Keep track of the number of fullscreen activities in this task.
1196 task.numFullscreen += toOpaque ? +1 : -1;
1197
1198 fullscreen = toOpaque;
1199 return true;
Craig Mautner4addfc52013-06-25 08:05:45 -07001200 }
1201
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001202 void takeFromHistory() {
1203 if (inHistory) {
1204 inHistory = false;
1205 if (task != null && !finishing) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001206 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001207 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -07001208 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001209 }
1210 }
1211
1212 boolean isInHistory() {
1213 return inHistory;
1214 }
1215
Wale Ogunwale7d701172015-03-11 15:36:30 -07001216 boolean isInStackLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001217 final ActivityStack stack = getStack();
1218 return stack != null && stack.isInStackLocked(this) != null;
Wale Ogunwale7d701172015-03-11 15:36:30 -07001219 }
1220
Craig Mautner21d24a22014-04-23 11:45:37 -07001221 boolean isPersistable() {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001222 return (info.persistableMode == PERSIST_ROOT_ONLY ||
1223 info.persistableMode == PERSIST_ACROSS_REBOOTS) &&
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001224 (intent == null || (intent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
Craig Mautner21d24a22014-04-23 11:45:37 -07001225 }
1226
Wale Ogunwale4cea0f52015-12-25 06:30:31 -08001227 boolean isFocusable() {
Bryce Lee7b851cc2018-04-10 14:53:13 -07001228 return mStackSupervisor.isFocusable(this, isAlwaysFocusable());
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001229 }
1230
1231 boolean isResizeable() {
Winson Chungd3395382016-12-13 11:49:09 -08001232 return ActivityInfo.isResizeableMode(info.resizeMode) || info.supportsPictureInPicture();
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001233 }
1234
Winson Chungd3395382016-12-13 11:49:09 -08001235 /**
1236 * @return whether this activity is non-resizeable or forced to be resizeable
1237 */
1238 boolean isNonResizableOrForcedResizable() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -07001239 return info.resizeMode != RESIZE_MODE_RESIZEABLE
Wale Ogunwale72a73e32016-10-13 12:16:39 -07001240 && info.resizeMode != RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Jorim Jaggicd13d332016-04-27 15:40:20 -07001241 }
1242
Winson Chunge6308042016-10-31 09:24:01 -07001243 /**
Winson Chungd3395382016-12-13 11:49:09 -08001244 * @return whether this activity supports PiP multi-window and can be put in the pinned stack.
Winson Chunge6308042016-10-31 09:24:01 -07001245 */
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001246 boolean supportsPictureInPicture() {
Wale Ogunwalea6191b42018-05-09 07:41:32 -07001247 return service.mSupportsPictureInPicture && isActivityTypeStandardOrUndefined()
Winson Chungd3395382016-12-13 11:49:09 -08001248 && info.supportsPictureInPicture();
1249 }
1250
1251 /**
1252 * @return whether this activity supports split-screen multi-window and can be put in the docked
1253 * stack.
1254 */
Wale Ogunwale04a05ac2017-09-17 21:35:02 -07001255 @Override
1256 public boolean supportsSplitScreenWindowingMode() {
Winson Chungd3395382016-12-13 11:49:09 -08001257 // An activity can not be docked even if it is considered resizeable because it only
1258 // supports picture-in-picture mode but has a non-resizeable resizeMode
Wale Ogunwale04a05ac2017-09-17 21:35:02 -07001259 return super.supportsSplitScreenWindowingMode()
Wale Ogunwalea6191b42018-05-09 07:41:32 -07001260 && service.mSupportsSplitScreenMultiWindow && supportsResizeableMultiWindow();
Winson Chungd3395382016-12-13 11:49:09 -08001261 }
1262
1263 /**
1264 * @return whether this activity supports freeform multi-window and can be put in the freeform
1265 * stack.
1266 */
1267 boolean supportsFreeform() {
Wale Ogunwalea6191b42018-05-09 07:41:32 -07001268 return service.mSupportsFreeformWindowManagement && supportsResizeableMultiWindow();
Winson Chungd3395382016-12-13 11:49:09 -08001269 }
1270
1271 /**
1272 * @return whether this activity supports non-PiP multi-window.
1273 */
1274 private boolean supportsResizeableMultiWindow() {
Wale Ogunwalea6191b42018-05-09 07:41:32 -07001275 return service.mSupportsMultiWindow && !isActivityTypeHome()
Winson Chungd3395382016-12-13 11:49:09 -08001276 && (ActivityInfo.isResizeableMode(info.resizeMode)
Wale Ogunwalea6191b42018-05-09 07:41:32 -07001277 || service.mForceResizableActivities);
Wale Ogunwaled26176f2016-01-25 20:04:04 -08001278 }
1279
Winson Chunge6308042016-10-31 09:24:01 -07001280 /**
Andrii Kulian036e3ad2017-04-19 10:55:10 -07001281 * Check whether this activity can be launched on the specified display.
1282 * @param displayId Target display id.
1283 * @return {@code true} if either it is the default display or this activity is resizeable and
1284 * can be put a secondary screen.
1285 */
1286 boolean canBeLaunchedOnDisplay(int displayId) {
Bryce Lee1533b2b2017-09-14 17:06:41 -07001287 final TaskRecord task = getTask();
1288
1289 // The resizeability of an Activity's parent task takes precendence over the ActivityInfo.
1290 // This allows for a non resizable activity to be launched into a resizeable task.
1291 final boolean resizeable =
1292 task != null ? task.isResizeable() : supportsResizeableMultiWindow();
1293
Andrii Kulian036e3ad2017-04-19 10:55:10 -07001294 return service.mStackSupervisor.canPlaceEntityOnDisplay(displayId,
Bryce Lee1533b2b2017-09-14 17:06:41 -07001295 resizeable, launchedFromPid, launchedFromUid, info);
Andrii Kulian036e3ad2017-04-19 10:55:10 -07001296 }
1297
1298 /**
Robert Carrc33658e2017-04-11 18:24:20 -07001299 * @param beforeStopping Whether this check is for an auto-enter-pip operation, that is to say
1300 * the activity has requested to enter PiP when it would otherwise be stopped.
1301 *
Winson Chung298f95b2017-08-10 15:57:18 -07001302 * @return whether this activity is currently allowed to enter PIP.
Winson Chunge6308042016-10-31 09:24:01 -07001303 */
Winson Chung298f95b2017-08-10 15:57:18 -07001304 boolean checkEnterPictureInPictureState(String caller, boolean beforeStopping) {
Wale Ogunwaleb9a0c992017-04-18 07:25:20 -07001305 if (!supportsPictureInPicture()) {
1306 return false;
1307 }
1308
Winson Chungf4ac0632017-03-17 12:34:12 -07001309 // Check app-ops and see if PiP is supported for this package
1310 if (!checkEnterPictureInPictureAppOpsState()) {
1311 return false;
1312 }
1313
Winson Chungf1bfee12017-03-24 17:11:33 -07001314 // Check to see if we are in VR mode, and disallow PiP if so
1315 if (service.shouldDisableNonVrUiLocked()) {
1316 return false;
1317 }
1318
Winson Chungc2baac02017-01-11 13:34:47 -08001319 boolean isKeyguardLocked = service.isKeyguardLocked();
Wale Ogunwaled0412b32018-05-08 09:25:50 -07001320 boolean isCurrentAppLocked =
1321 service.getLockTaskModeState() != LOCK_TASK_MODE_NONE;
Wale Ogunwale04a05ac2017-09-17 21:35:02 -07001322 final ActivityDisplay display = getDisplay();
1323 boolean hasPinnedStack = display != null && display.hasPinnedStack();
Winson Chungbb348802017-01-30 12:01:45 -08001324 // Don't return early if !isNotLocked, since we want to throw an exception if the activity
1325 // is in an incorrect state
Winson Chunge581ebf2017-02-21 08:25:03 -08001326 boolean isNotLockedOrOnKeyguard = !isKeyguardLocked && !isCurrentAppLocked;
Robert Carrc33658e2017-04-11 18:24:20 -07001327
1328 // We don't allow auto-PiP when something else is already pipped.
1329 if (beforeStopping && hasPinnedStack) {
1330 return false;
1331 }
1332
Bryce Lee7ace3952018-02-16 14:34:32 -08001333 switch (mState) {
Winson Chungc2baac02017-01-11 13:34:47 -08001334 case RESUMED:
Winson Chunge581ebf2017-02-21 08:25:03 -08001335 // When visible, allow entering PiP if the app is not locked. If it is over the
1336 // keyguard, then we will prompt to unlock in the caller before entering PiP.
Robert Carrc33658e2017-04-11 18:24:20 -07001337 return !isCurrentAppLocked &&
Winson Chungf7e03e12017-08-22 11:32:16 -07001338 (supportsEnterPipOnTaskSwitch || !beforeStopping);
Winson Chungc2baac02017-01-11 13:34:47 -08001339 case PAUSING:
1340 case PAUSED:
Winson Chungbb348802017-01-30 12:01:45 -08001341 // When pausing, then only allow enter PiP as in the resume state, and in addition,
1342 // require that there is not an existing PiP activity and that the current system
1343 // state supports entering PiP
Winson Chunge581ebf2017-02-21 08:25:03 -08001344 return isNotLockedOrOnKeyguard && !hasPinnedStack
Winson Chungf7e03e12017-08-22 11:32:16 -07001345 && supportsEnterPipOnTaskSwitch;
Winson Chungc2baac02017-01-11 13:34:47 -08001346 case STOPPING:
1347 // When stopping in a valid state, then only allow enter PiP as in the pause state.
1348 // Otherwise, fall through to throw an exception if the caller is trying to enter
1349 // PiP in an invalid stopping state.
Winson Chungf7e03e12017-08-22 11:32:16 -07001350 if (supportsEnterPipOnTaskSwitch) {
Winson Chungf4ac0632017-03-17 12:34:12 -07001351 return isNotLockedOrOnKeyguard && !hasPinnedStack;
Winson Chungc2baac02017-01-11 13:34:47 -08001352 }
1353 default:
Winson Chung298f95b2017-08-10 15:57:18 -07001354 return false;
Winson Chungb5c41b72016-12-07 15:00:47 -08001355 }
Winson Chunge6308042016-10-31 09:24:01 -07001356 }
1357
Winson Chung59fda9e2017-01-20 16:14:51 -08001358 /**
Winson Chungf4ac0632017-03-17 12:34:12 -07001359 * @return Whether AppOps allows this package to enter picture-in-picture.
Winson Chung59fda9e2017-01-20 16:14:51 -08001360 */
Winson Chungf4ac0632017-03-17 12:34:12 -07001361 private boolean checkEnterPictureInPictureAppOpsState() {
Wale Ogunwalef6733932018-06-27 05:14:34 -07001362 return service.getAppOpsService().checkOperation(
1363 OP_PICTURE_IN_PICTURE, appInfo.uid, packageName) == MODE_ALLOWED;
Winson Chung59fda9e2017-01-20 16:14:51 -08001364 }
1365
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001366 boolean isAlwaysFocusable() {
1367 return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0;
Wale Ogunwale4cea0f52015-12-25 06:30:31 -08001368 }
1369
Jorim Jaggife762342016-10-13 14:33:27 +02001370
1371 /**
1372 * @return true if the activity contains windows that have
1373 * {@link LayoutParams#FLAG_DISMISS_KEYGUARD} set
1374 */
1375 boolean hasDismissKeyguardWindows() {
1376 return service.mWindowManager.containsDismissKeyguardWindow(appToken);
1377 }
1378
Wale Ogunwale7d701172015-03-11 15:36:30 -07001379 void makeFinishingLocked() {
Wale Ogunwalec981ad52017-06-13 11:40:06 -07001380 if (finishing) {
1381 return;
1382 }
1383 finishing = true;
1384 if (stopped) {
1385 clearOptionsLocked();
1386 }
Yorke Leebd54c2a2016-10-25 13:49:23 -07001387
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001388 if (service != null) {
Wale Ogunwaled0412b32018-05-08 09:25:50 -07001389 service.getTaskChangeNotificationController().notifyTaskStackChanged();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08001390 }
1391 }
1392
Dianne Hackborn7e269642010-08-25 19:50:20 -07001393 UriPermissionOwner getUriPermissionsLocked() {
1394 if (uriPermissions == null) {
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07001395 uriPermissions = new UriPermissionOwner(service.mUgmInternal, this);
Dianne Hackborn7e269642010-08-25 19:50:20 -07001396 }
1397 return uriPermissions;
1398 }
1399
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001400 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001401 int requestCode, int resultCode,
1402 Intent resultData) {
1403 ActivityResult r = new ActivityResult(from, resultWho,
John Spurlock8a985d22014-02-25 09:40:05 -05001404 requestCode, resultCode, resultData);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001405 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001406 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407 }
1408 results.add(r);
1409 }
1410
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001411 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001412 int requestCode) {
1413 if (results != null) {
1414 for (int i=results.size()-1; i>=0; i--) {
1415 ActivityResult r = (ActivityResult)results.get(i);
1416 if (r.mFrom != from) continue;
1417 if (r.mResultWho == null) {
1418 if (resultWho != null) continue;
1419 } else {
1420 if (!r.mResultWho.equals(resultWho)) continue;
1421 }
1422 if (r.mRequestCode != requestCode) continue;
1423
1424 results.remove(i);
1425 }
1426 }
1427 }
1428
Andrii Kulian21713ac2016-10-12 22:05:05 -07001429 private void addNewIntentLocked(ReferrerIntent intent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001430 if (newIntents == null) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001431 newIntents = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 }
1433 newIntents.add(intent);
1434 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001435
Robert Carr9e1bf7c2018-05-31 15:39:07 -07001436 final boolean isSleeping() {
1437 final ActivityStack stack = getStack();
Wale Ogunwalef6733932018-06-27 05:14:34 -07001438 return stack != null ? stack.shouldSleepActivities() : service.isSleepingLocked();
Robert Carr9e1bf7c2018-05-31 15:39:07 -07001439 }
1440
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001441 /**
1442 * Deliver a new Intent to an existing activity, so that its onNewIntent()
1443 * method will be called at the proper time.
1444 */
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001445 final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) {
Dianne Hackborn514074f2013-02-11 10:52:46 -08001446 // The activity now gets access to the data associated with this Intent.
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07001447 service.mUgmInternal.grantUriPermissionFromIntent(callingUid, packageName,
Nicolas Prevotc6cf95c2014-05-29 11:30:36 +01001448 intent, getUriPermissionsLocked(), userId);
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001449 final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
Craig Mautner86d67a42013-05-14 10:34:38 -07001450 boolean unsent = true;
Robert Carr9e1bf7c2018-05-31 15:39:07 -07001451 final boolean isTopActivityWhileSleeping = isTopRunningActivity() && isSleeping();
Wale Ogunwale826c7062016-09-13 08:25:54 -07001452
1453 // We want to immediately deliver the intent to the activity if:
Wale Ogunwale03f7e9e2016-09-22 09:04:09 -07001454 // - It is currently resumed or paused. i.e. it is currently visible to the user and we want
1455 // the user to see the visual effects caused by the intent delivery now.
Wale Ogunwale826c7062016-09-13 08:25:54 -07001456 // - The device is sleeping and it is the top activity behind the lock screen (b/6700897).
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001457 if ((mState == RESUMED || mState == PAUSED || isTopActivityWhileSleeping)
1458 && attachedToProcess()) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001459 try {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001460 ArrayList<ReferrerIntent> ar = new ArrayList<>(1);
1461 ar.add(rintent);
Wale Ogunwaled0412b32018-05-08 09:25:50 -07001462 service.getLifecycleManager().scheduleTransaction(
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001463 app.getThread(), appToken, NewIntentItem.obtain(ar, mState == PAUSED));
Craig Mautner86d67a42013-05-14 10:34:38 -07001464 unsent = false;
Dianne Hackborn39792d22010-08-19 18:01:52 -07001465 } catch (RemoteException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001466 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn39792d22010-08-19 18:01:52 -07001467 } catch (NullPointerException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001468 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001469 }
1470 }
Craig Mautner86d67a42013-05-14 10:34:38 -07001471 if (unsent) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001472 addNewIntentLocked(rintent);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001473 }
1474 }
1475
Dianne Hackborn9622ca42012-10-23 18:56:33 -07001476 void updateOptionsLocked(ActivityOptions options) {
1477 if (options != null) {
1478 if (pendingOptions != null) {
1479 pendingOptions.abort();
1480 }
1481 pendingOptions = options;
1482 }
1483 }
1484
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001485 void applyOptionsLocked() {
George Mount2c92c972014-03-20 09:38:23 -07001486 if (pendingOptions != null
Ruben Brunkf53497c2017-03-27 20:26:17 -07001487 && pendingOptions.getAnimationType() != ANIM_SCENE_TRANSITION) {
Michael Jurka21385cd2012-05-03 10:57:31 -07001488 final int animationType = pendingOptions.getAnimationType();
1489 switch (animationType) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001490 case ANIM_CUSTOM:
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001491 service.mWindowManager.overridePendingAppTransition(
1492 pendingOptions.getPackageName(),
1493 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -07001494 pendingOptions.getCustomExitResId(),
1495 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001496 break;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001497 case ANIM_CLIP_REVEAL:
Chet Haase10e23ab2015-02-11 15:08:38 -08001498 service.mWindowManager.overridePendingAppTransitionClipReveal(
1499 pendingOptions.getStartX(), pendingOptions.getStartY(),
1500 pendingOptions.getWidth(), pendingOptions.getHeight());
1501 if (intent.getSourceBounds() == null) {
1502 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1503 pendingOptions.getStartY(),
1504 pendingOptions.getStartX()+pendingOptions.getWidth(),
1505 pendingOptions.getStartY()+pendingOptions.getHeight()));
1506 }
1507 break;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001508 case ANIM_SCALE_UP:
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001509 service.mWindowManager.overridePendingAppTransitionScaleUp(
1510 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001511 pendingOptions.getWidth(), pendingOptions.getHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001512 if (intent.getSourceBounds() == null) {
1513 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1514 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001515 pendingOptions.getStartX()+pendingOptions.getWidth(),
1516 pendingOptions.getStartY()+pendingOptions.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001517 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001518 break;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001519 case ANIM_THUMBNAIL_SCALE_UP:
1520 case ANIM_THUMBNAIL_SCALE_DOWN:
Winson Chungaa7fa012017-05-24 15:50:06 -07001521 final boolean scaleUp = (animationType == ANIM_THUMBNAIL_SCALE_UP);
1522 final GraphicBuffer buffer = pendingOptions.getThumbnail();
1523 service.mWindowManager.overridePendingAppTransitionThumb(buffer,
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001524 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -07001525 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -07001526 scaleUp);
Winson Chungf229ae52017-06-02 14:34:52 -07001527 if (intent.getSourceBounds() == null && buffer != null) {
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001528 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1529 pendingOptions.getStartY(),
Winson Chungaa7fa012017-05-24 15:50:06 -07001530 pendingOptions.getStartX() + buffer.getWidth(),
1531 pendingOptions.getStartY() + buffer.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001532 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001533 break;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001534 case ANIM_THUMBNAIL_ASPECT_SCALE_UP:
1535 case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001536 final AppTransitionAnimationSpec[] specs = pendingOptions.getAnimSpecs();
Jorim Jaggi34795e32017-05-12 17:27:46 +02001537 final IAppTransitionAnimationSpecsFuture specsFuture =
1538 pendingOptions.getSpecsFuture();
1539 if (specsFuture != null) {
1540 service.mWindowManager.overridePendingAppTransitionMultiThumbFuture(
1541 specsFuture, pendingOptions.getOnAnimationStartListener(),
1542 animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP);
1543 } else if (animationType == ANIM_THUMBNAIL_ASPECT_SCALE_DOWN
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001544 && specs != null) {
1545 service.mWindowManager.overridePendingAppTransitionMultiThumb(
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001546 specs, pendingOptions.getOnAnimationStartListener(),
1547 pendingOptions.getAnimationFinishedListener(), false);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001548 } else {
1549 service.mWindowManager.overridePendingAppTransitionAspectScaledThumb(
1550 pendingOptions.getThumbnail(),
1551 pendingOptions.getStartX(), pendingOptions.getStartY(),
1552 pendingOptions.getWidth(), pendingOptions.getHeight(),
1553 pendingOptions.getOnAnimationStartListener(),
Ruben Brunkf53497c2017-03-27 20:26:17 -07001554 (animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP));
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001555 if (intent.getSourceBounds() == null) {
1556 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1557 pendingOptions.getStartY(),
1558 pendingOptions.getStartX() + pendingOptions.getWidth(),
1559 pendingOptions.getStartY() + pendingOptions.getHeight()));
1560 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001561 }
1562 break;
Tony Mak089c35e2017-12-18 20:34:14 +00001563 case ANIM_OPEN_CROSS_PROFILE_APPS:
1564 service.mWindowManager.overridePendingAppTransitionStartCrossProfileApps();
1565 break;
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001566 case ANIM_REMOTE_ANIMATION:
1567 service.mWindowManager.overridePendingAppTransitionRemote(
1568 pendingOptions.getRemoteAnimationAdapter());
1569 break;
Craig Mautner233ceee2014-05-09 17:05:11 -07001570 default:
1571 Slog.e(TAG, "applyOptionsLocked: Unknown animationType=" + animationType);
1572 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001573 }
chaviw82a0ba82018-03-15 14:26:29 -07001574
1575 if (task == null) {
1576 clearOptionsLocked(false /* withAbort */);
1577 } else {
1578 // This will clear the options for all the ActivityRecords for this Task.
1579 task.clearAllPendingOptions();
1580 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001581 }
1582 }
1583
Adam Powellcfbe9be2013-11-06 14:58:58 -08001584 ActivityOptions getOptionsForTargetActivityLocked() {
1585 return pendingOptions != null ? pendingOptions.forTargetActivity() : null;
1586 }
1587
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001588 void clearOptionsLocked() {
chaviw82a0ba82018-03-15 14:26:29 -07001589 clearOptionsLocked(true /* withAbort */);
1590 }
1591
1592 void clearOptionsLocked(boolean withAbort) {
1593 if (withAbort && pendingOptions != null) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001594 pendingOptions.abort();
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001595 }
chaviw82a0ba82018-03-15 14:26:29 -07001596 pendingOptions = null;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001597 }
1598
Dianne Hackborn9622ca42012-10-23 18:56:33 -07001599 ActivityOptions takeOptionsLocked() {
1600 ActivityOptions opts = pendingOptions;
1601 pendingOptions = null;
1602 return opts;
1603 }
1604
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001605 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -07001606 if (uriPermissions != null) {
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07001607 uriPermissions.removeUriPermissions();
Dianne Hackborn7e269642010-08-25 19:50:20 -07001608 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001609 }
1610 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611
1612 void pauseKeyDispatchingLocked() {
1613 if (!keysPaused) {
1614 keysPaused = true;
Bryce Lee2b8e0372018-04-05 17:01:37 -07001615
1616 if (mWindowContainerController != null) {
1617 mWindowContainerController.pauseKeyDispatching();
1618 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001619 }
1620 }
1621
1622 void resumeKeyDispatchingLocked() {
1623 if (keysPaused) {
1624 keysPaused = false;
Bryce Lee2b8e0372018-04-05 17:01:37 -07001625
1626 if (mWindowContainerController != null) {
1627 mWindowContainerController.resumeKeyDispatching();
1628 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 }
1630 }
1631
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001632 private void updateTaskDescription(CharSequence description) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001633 task.lastDescription = description;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001634 }
1635
Wale Ogunwaleec950642017-04-25 07:44:21 -07001636 void setDeferHidingClient(boolean deferHidingClient) {
1637 if (mDeferHidingClient == deferHidingClient) {
1638 return;
1639 }
1640 mDeferHidingClient = deferHidingClient;
1641 if (!mDeferHidingClient && !visible) {
1642 // Hiding the client is no longer deferred and the app isn't visible still, go ahead and
1643 // update the visibility.
1644 setVisibility(false);
1645 }
Wale Ogunwale89973222017-04-23 18:39:45 -07001646 }
1647
Wale Ogunwaleec950642017-04-25 07:44:21 -07001648 void setVisibility(boolean visible) {
Tim Murray68ed8442017-08-29 23:21:27 +00001649 mWindowContainerController.setVisibility(visible, mDeferHidingClient);
Bryce Lee2a3cc462017-10-27 10:57:35 -07001650 mStackSupervisor.getActivityMetricsLogger().notifyVisibilityChanged(this);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001651 }
1652
1653 // TODO: Look into merging with #setVisibility()
Wale Ogunwaleec950642017-04-25 07:44:21 -07001654 void setVisible(boolean newVisible) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001655 visible = newVisible;
Wale Ogunwaleec950642017-04-25 07:44:21 -07001656 mDeferHidingClient = !visible && mDeferHidingClient;
Wale Ogunwaleec950642017-04-25 07:44:21 -07001657 setVisibility(visible);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001658 mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
1659 }
1660
Bryce Lee7ace3952018-02-16 14:34:32 -08001661 void setState(ActivityState state, String reason) {
1662 if (DEBUG_STATES) Slog.v(TAG_STATES, "State movement: " + this + " from:" + getState()
1663 + " to:" + state + " reason:" + reason);
Bryce Lee6ff17072018-02-28 07:26:17 -08001664
Bryce Leeb0f993f2018-03-02 15:38:01 -08001665 if (state == mState) {
1666 // No need to do anything if state doesn't change.
1667 if (DEBUG_STATES) Slog.v(TAG_STATES, "State unchanged from:" + state);
1668 return;
1669 }
1670
Bryce Leeb0f993f2018-03-02 15:38:01 -08001671 mState = state;
1672
Bryce Leec4ab62a2018-03-05 14:19:26 -08001673 final TaskRecord parent = getTask();
1674
1675 if (parent != null) {
1676 parent.onActivityStateChanged(this, state, reason);
1677 }
Robert Carr29daa922018-04-27 11:56:48 -07001678
Robert Carr9e1bf7c2018-05-31 15:39:07 -07001679 // The WindowManager interprets the app stopping signal as
1680 // an indication that the Surface will eventually be destroyed.
1681 // This however isn't necessarily true if we are going to sleep.
1682 if (state == STOPPING && !isSleeping()) {
Robert Carr29daa922018-04-27 11:56:48 -07001683 mWindowContainerController.notifyAppStopping();
1684 }
Bryce Lee7ace3952018-02-16 14:34:32 -08001685 }
1686
1687 ActivityState getState() {
1688 return mState;
1689 }
1690
1691 /**
1692 * Returns {@code true} if the Activity is in the specified state.
1693 */
1694 boolean isState(ActivityState state) {
1695 return state == mState;
1696 }
1697
1698 /**
1699 * Returns {@code true} if the Activity is in one of the specified states.
1700 */
1701 boolean isState(ActivityState state1, ActivityState state2) {
1702 return state1 == mState || state2 == mState;
1703 }
1704
1705 /**
1706 * Returns {@code true} if the Activity is in one of the specified states.
1707 */
1708 boolean isState(ActivityState state1, ActivityState state2, ActivityState state3) {
1709 return state1 == mState || state2 == mState || state3 == mState;
1710 }
1711
1712 /**
1713 * Returns {@code true} if the Activity is in one of the specified states.
1714 */
1715 boolean isState(ActivityState state1, ActivityState state2, ActivityState state3,
1716 ActivityState state4) {
1717 return state1 == mState || state2 == mState || state3 == mState || state4 == mState;
1718 }
1719
Jorim Jaggibae01b12017-04-11 16:29:10 -07001720 void notifyAppResumed(boolean wasStopped) {
1721 mWindowContainerController.notifyAppResumed(wasStopped);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001722 }
1723
1724 void notifyUnknownVisibilityLaunched() {
Jorim Jaggi838c2452017-08-28 15:44:43 +02001725
1726 // No display activities never add a window, so there is no point in waiting them for
1727 // relayout.
1728 if (!noDisplay) {
1729 mWindowContainerController.notifyUnknownVisibilityLaunched();
1730 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001731 }
1732
Jorim Jaggi241ae102016-11-02 21:57:33 -07001733 /**
1734 * @return true if the input activity should be made visible, ignoring any effect Keyguard
1735 * might have on the visibility
1736 *
1737 * @see {@link ActivityStack#checkKeyguardVisibility}
1738 */
Wale Ogunwalec981ad52017-06-13 11:40:06 -07001739 boolean shouldBeVisibleIgnoringKeyguard(boolean behindFullscreenActivity) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001740 if (!okToShowLocked()) {
1741 return false;
1742 }
1743
Winson Chung3f0e59a2017-10-25 10:19:05 -07001744 return !behindFullscreenActivity || mLaunchTaskBehind;
Andrii Kulian21713ac2016-10-12 22:05:05 -07001745 }
1746
Andrii Kuliana39ae3e2018-05-31 12:43:54 -07001747 void makeVisibleIfNeeded(ActivityRecord starting, boolean reportToClient) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001748 // This activity is not currently visible, but is running. Tell it to become visible.
Bryce Lee7ace3952018-02-16 14:34:32 -08001749 if (mState == RESUMED || this == starting) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001750 if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY,
Bryce Lee7ace3952018-02-16 14:34:32 -08001751 "Not making visible, r=" + this + " state=" + mState + " starting=" + starting);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001752 return;
1753 }
1754
1755 // If this activity is paused, tell it to now show its window.
1756 if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY,
1757 "Making visible and scheduling visibility: " + this);
1758 final ActivityStack stack = getStack();
1759 try {
1760 if (stack.mTranslucentActivityWaiting != null) {
1761 updateOptionsLocked(returningOptions);
1762 stack.mUndrawnActivitiesBelowTopTranslucent.add(this);
1763 }
1764 setVisible(true);
1765 sleeping = false;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001766 app.setPendingUiClean(true);
Andrii Kuliana39ae3e2018-05-31 12:43:54 -07001767 if (reportToClient) {
1768 makeClientVisible();
1769 } else {
1770 mClientVisibilityDeferred = true;
1771 }
Andrii Kulian21713ac2016-10-12 22:05:05 -07001772 // The activity may be waiting for stop, but that is no longer appropriate for it.
1773 mStackSupervisor.mStoppingActivities.remove(this);
1774 mStackSupervisor.mGoingToSleepActivities.remove(this);
Andrii Kuliana39ae3e2018-05-31 12:43:54 -07001775 } catch (Exception e) {
1776 // Just skip on any failure; we'll make it visible when it next restarts.
1777 Slog.w(TAG, "Exception thrown making visible: " + intent.getComponent(), e);
1778 }
1779 handleAlreadyVisible();
1780 }
Andrii Kulian0d595f32018-02-21 15:47:33 -08001781
Andrii Kuliana39ae3e2018-05-31 12:43:54 -07001782 /** Send visibility change message to the client and pause if needed. */
1783 void makeClientVisible() {
1784 mClientVisibilityDeferred = false;
1785 try {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001786 service.getLifecycleManager().scheduleTransaction(app.getThread(), appToken,
Andrii Kuliana39ae3e2018-05-31 12:43:54 -07001787 WindowVisibilityItem.obtain(true /* showWindow */));
Andrii Kulian09e1afa2018-05-16 21:29:34 -07001788 if (shouldPauseWhenBecomingVisible()) {
Andrii Kulian0d595f32018-02-21 15:47:33 -08001789 // An activity must be in the {@link PAUSING} state for the system to validate
1790 // the move to {@link PAUSED}.
Bryce Lee7ace3952018-02-16 14:34:32 -08001791 setState(PAUSING, "makeVisibleIfNeeded");
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001792 service.getLifecycleManager().scheduleTransaction(app.getThread(), appToken,
Andrii Kulian0d595f32018-02-21 15:47:33 -08001793 PauseActivityItem.obtain(finishing, false /* userLeaving */,
Bryce Lee1d0d5142018-04-12 10:35:07 -07001794 configChangeFlags, false /* dontReport */));
Andrii Kulian0d595f32018-02-21 15:47:33 -08001795 }
Andrii Kulian21713ac2016-10-12 22:05:05 -07001796 } catch (Exception e) {
Andrii Kuliana39ae3e2018-05-31 12:43:54 -07001797 Slog.w(TAG, "Exception thrown sending visibility update: " + intent.getComponent(), e);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001798 }
Andrii Kulian21713ac2016-10-12 22:05:05 -07001799 }
1800
Andrii Kulian09e1afa2018-05-16 21:29:34 -07001801 /** Check if activity should be moved to PAUSED state when it becomes visible. */
1802 private boolean shouldPauseWhenBecomingVisible() {
1803 // If the activity is stopped or stopping, cycle to the paused state. We avoid doing
1804 // this when there is an activity waiting to become translucent as the extra binder
1805 // calls will lead to noticeable jank. A later call to
1806 // ActivityStack#ensureActivitiesVisibleLocked will bring the activity to the proper
1807 // paused state. We also avoid doing this for the activity the stack supervisor
1808 // considers the resumed activity, as normal means will bring the activity from STOPPED
1809 // to RESUMED. Adding PAUSING in this scenario will lead to double lifecycles.
1810 if (!isState(STOPPED, STOPPING) || getStack().mTranslucentActivityWaiting != null
Andrii Kulian52d255c2018-07-13 11:32:19 -07001811 || isResumedActivityOnDisplay()) {
Andrii Kulian09e1afa2018-05-16 21:29:34 -07001812 return false;
1813 }
1814
1815 // Check if position in task allows to become paused
1816 final int positionInTask = task.mActivities.indexOf(this);
1817 if (positionInTask == -1) {
1818 throw new IllegalStateException("Activity not found in its task");
1819 }
1820 if (positionInTask == task.mActivities.size() - 1) {
1821 // It's the topmost activity in the task - should become paused now
1822 return true;
1823 }
1824 // Check if activity above is finishing now and this one becomes the topmost in task.
1825 final ActivityRecord activityAbove = task.mActivities.get(positionInTask + 1);
1826 if (activityAbove.finishing && results == null) {
1827 // We will only allow pausing if activity above wasn't launched for result. Otherwise it
1828 // will cause this activity to resume before getting result.
1829 return true;
1830 }
1831 return false;
1832 }
1833
Andrii Kulian21713ac2016-10-12 22:05:05 -07001834 boolean handleAlreadyVisible() {
1835 stopFreezingScreenLocked(false);
1836 try {
1837 if (returningOptions != null) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001838 app.getThread().scheduleOnNewActivityOptions(appToken, returningOptions.toBundle());
Andrii Kulian21713ac2016-10-12 22:05:05 -07001839 }
1840 } catch(RemoteException e) {
1841 }
Bryce Lee7ace3952018-02-16 14:34:32 -08001842 return mState == RESUMED;
Andrii Kulian21713ac2016-10-12 22:05:05 -07001843 }
1844
1845 static void activityResumedLocked(IBinder token) {
1846 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
1847 if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r);
1848 if (r != null) {
1849 r.icicle = null;
1850 r.haveState = false;
1851 }
1852 }
1853
1854 /**
1855 * Once we know that we have asked an application to put an activity in the resumed state
1856 * (either by launching it or explicitly telling it), this function updates the rest of our
1857 * state to match that fact.
1858 */
1859 void completeResumeLocked() {
1860 final boolean wasVisible = visible;
Jorim Jaggi8d062052017-08-22 14:55:17 +02001861 setVisible(true);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001862 if (!wasVisible) {
1863 // Visibility has changed, so take a note of it so we call the TaskStackChangedListener
1864 mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
1865 }
1866 idle = false;
1867 results = null;
1868 newIntents = null;
1869 stopped = false;
1870
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001871 if (isActivityTypeHome()) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001872 WindowProcessController app = task.mActivities.get(0).app;
1873 if (hasProcess() && app != service.mHomeProcess) {
1874 service.mHomeProcess = app;
Andrii Kulian21713ac2016-10-12 22:05:05 -07001875 }
1876 }
1877
1878 if (nowVisible) {
1879 // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now.
1880 mStackSupervisor.reportActivityVisibleLocked(this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001881 }
1882
1883 // Schedule an idle timeout in case the app doesn't do it for us.
1884 mStackSupervisor.scheduleIdleTimeoutLocked(this);
1885
1886 mStackSupervisor.reportResumedActivityLocked(this);
1887
1888 resumeKeyDispatchingLocked();
1889 final ActivityStack stack = getStack();
Jorim Jaggifa9ed962018-01-25 00:16:49 +01001890 mStackSupervisor.mNoAnimActivities.clear();
Andrii Kulian21713ac2016-10-12 22:05:05 -07001891
1892 // Mark the point when the activity is resuming
1893 // TODO: To be more accurate, the mark should be before the onCreate,
1894 // not after the onResume. But for subsequent starts, onResume is fine.
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001895 if (hasProcess()) {
Wale Ogunwale86b74462018-07-02 08:42:43 -07001896 cpuTimeAtResume = app.getCpuTime();
Andrii Kulian21713ac2016-10-12 22:05:05 -07001897 } else {
1898 cpuTimeAtResume = 0; // Couldn't get the cpu time of process
1899 }
1900
1901 returningOptions = null;
chaviw59b98852017-06-13 12:05:44 -07001902
1903 if (canTurnScreenOn()) {
1904 mStackSupervisor.wakeUp("turnScreenOnFlag");
1905 } else {
1906 // If the screen is going to turn on because the caller explicitly requested it and
1907 // the keyguard is not showing don't attempt to sleep. Otherwise the Activity will
1908 // pause and then resume again later, which will result in a double life-cycle event.
David Stevens9440dc82017-03-16 19:00:20 -07001909 stack.checkReadyForSleep();
chaviw59b98852017-06-13 12:05:44 -07001910 }
Andrii Kulian21713ac2016-10-12 22:05:05 -07001911 }
1912
1913 final void activityStoppedLocked(Bundle newIcicle, PersistableBundle newPersistentState,
1914 CharSequence description) {
1915 final ActivityStack stack = getStack();
Bryce Lee7ace3952018-02-16 14:34:32 -08001916 if (mState != STOPPING) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001917 Slog.i(TAG, "Activity reported stop, but no longer stopping: " + this);
Ruben Brunkf53497c2017-03-27 20:26:17 -07001918 stack.mHandler.removeMessages(STOP_TIMEOUT_MSG, this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001919 return;
1920 }
1921 if (newPersistentState != null) {
1922 persistentState = newPersistentState;
1923 service.notifyTaskPersisterLocked(task, false);
1924 }
1925 if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, "Saving icicle of " + this + ": " + icicle);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001926
Andrii Kulian21713ac2016-10-12 22:05:05 -07001927 if (newIcicle != null) {
1928 // If icicle is null, this is happening due to a timeout, so we haven't really saved
1929 // the state.
1930 icicle = newIcicle;
1931 haveState = true;
1932 launchCount = 0;
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001933 updateTaskDescription(description);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001934 }
1935 if (!stopped) {
1936 if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to STOPPED: " + this + " (stop complete)");
Ruben Brunkf53497c2017-03-27 20:26:17 -07001937 stack.mHandler.removeMessages(STOP_TIMEOUT_MSG, this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001938 stopped = true;
Bryce Lee7ace3952018-02-16 14:34:32 -08001939 setState(STOPPED, "activityStoppedLocked");
Andrii Kulian21713ac2016-10-12 22:05:05 -07001940
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001941 mWindowContainerController.notifyAppStopped();
Andrii Kulian21713ac2016-10-12 22:05:05 -07001942
Andrii Kulian21713ac2016-10-12 22:05:05 -07001943 if (finishing) {
1944 clearOptionsLocked();
1945 } else {
1946 if (deferRelaunchUntilPaused) {
1947 stack.destroyActivityLocked(this, true /* removeFromApp */, "stop-config");
Andrii Kulianab132ee2018-07-24 22:10:21 +08001948 mStackSupervisor.resumeFocusedStacksTopActivitiesLocked();
Andrii Kulian21713ac2016-10-12 22:05:05 -07001949 } else {
1950 mStackSupervisor.updatePreviousProcessLocked(this);
1951 }
1952 }
1953 }
1954 }
1955
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001956 void startLaunchTickingLocked() {
Jeff Sharkey5ab02432017-06-27 11:01:36 -06001957 if (Build.IS_USER) {
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001958 return;
1959 }
1960 if (launchTickTime == 0) {
1961 launchTickTime = SystemClock.uptimeMillis();
1962 continueLaunchTickingLocked();
1963 }
1964 }
1965
1966 boolean continueLaunchTickingLocked() {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001967 if (launchTickTime == 0) {
1968 return false;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001969 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001970
Andrii Kulian02b7a832016-10-06 23:11:56 -07001971 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001972 if (stack == null) {
1973 return false;
1974 }
1975
Ruben Brunkf53497c2017-03-27 20:26:17 -07001976 Message msg = stack.mHandler.obtainMessage(LAUNCH_TICK_MSG, this);
1977 stack.mHandler.removeMessages(LAUNCH_TICK_MSG);
1978 stack.mHandler.sendMessageDelayed(msg, LAUNCH_TICK);
Wale Ogunwale7d701172015-03-11 15:36:30 -07001979 return true;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001980 }
1981
1982 void finishLaunchTickingLocked() {
1983 launchTickTime = 0;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001984 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001985 if (stack != null) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001986 stack.mHandler.removeMessages(LAUNCH_TICK_MSG);
Wale Ogunwale7d701172015-03-11 15:36:30 -07001987 }
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001988 }
1989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001990 // IApplicationToken
1991
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001992 public boolean mayFreezeScreenLocked(WindowProcessController app) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001993 // Only freeze the screen if this activity is currently attached to
1994 // an application, and that application is not blocked or unresponding.
1995 // In any other case, we can't count on getting the screen unfrozen,
1996 // so it is best to leave as-is.
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07001997 return hasProcess() && !app.isCrashing() && !app.isNotResponding();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001999
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07002000 public void startFreezingScreenLocked(WindowProcessController app, int configChanges) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 if (mayFreezeScreenLocked(app)) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002002 mWindowContainerController.startFreezingScreen(configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002003 }
2004 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07002005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002006 public void stopFreezingScreenLocked(boolean force) {
2007 if (force || frozenBeforeDestroy) {
2008 frozenBeforeDestroy = false;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002009 mWindowContainerController.stopFreezingScreen(force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002010 }
2011 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07002012
Jorim Jaggi4d27b842017-08-17 17:22:26 +02002013 public void reportFullyDrawnLocked(boolean restoredFromBundle) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07002014 final long curTime = SystemClock.uptimeMillis();
2015 if (displayStartTime != 0) {
2016 reportLaunchTimeLocked(curTime);
2017 }
Jorim Jaggide8305a2018-05-15 12:06:35 -07002018 final LaunchTimeTracker.Entry entry = mStackSupervisor.getLaunchTimeTracker().getEntry(
2019 getWindowingMode());
2020 if (fullyDrawnStartTime != 0 && entry != null) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07002021 final long thisTime = curTime - fullyDrawnStartTime;
Jorim Jaggide8305a2018-05-15 12:06:35 -07002022 final long totalTime = entry.mFullyDrawnStartTime != 0
2023 ? (curTime - entry.mFullyDrawnStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07002024 if (SHOW_ACTIVITY_START_TIME) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07002025 Trace.asyncTraceEnd(TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
2026 EventLog.writeEvent(AM_ACTIVITY_FULLY_DRAWN_TIME,
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07002027 userId, System.identityHashCode(this), shortComponentName,
2028 thisTime, totalTime);
Wale Ogunwalef6733932018-06-27 05:14:34 -07002029 StringBuilder sb = service.mStringBuilder;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07002030 sb.setLength(0);
2031 sb.append("Fully drawn ");
2032 sb.append(shortComponentName);
2033 sb.append(": ");
2034 TimeUtils.formatDuration(thisTime, sb);
2035 if (thisTime != totalTime) {
2036 sb.append(" (total ");
2037 TimeUtils.formatDuration(totalTime, sb);
2038 sb.append(")");
2039 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08002040 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07002041 }
2042 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07002043 //service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07002044 }
Jorim Jaggide8305a2018-05-15 12:06:35 -07002045 entry.mFullyDrawnStartTime = 0;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07002046 }
Bryce Lee2a3cc462017-10-27 10:57:35 -07002047 mStackSupervisor.getActivityMetricsLogger().logAppTransitionReportedDrawn(this,
Jorim Jaggi4d27b842017-08-17 17:22:26 +02002048 restoredFromBundle);
Wale Ogunwale7d701172015-03-11 15:36:30 -07002049 fullyDrawnStartTime = 0;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07002050 }
2051
2052 private void reportLaunchTimeLocked(final long curTime) {
Jorim Jaggide8305a2018-05-15 12:06:35 -07002053 final LaunchTimeTracker.Entry entry = mStackSupervisor.getLaunchTimeTracker().getEntry(
2054 getWindowingMode());
2055 if (entry == null) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07002056 return;
2057 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07002058 final long thisTime = curTime - displayStartTime;
Jorim Jaggide8305a2018-05-15 12:06:35 -07002059 final long totalTime = entry.mLaunchStartTime != 0
2060 ? (curTime - entry.mLaunchStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07002061 if (SHOW_ACTIVITY_START_TIME) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07002062 Trace.asyncTraceEnd(TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0);
2063 EventLog.writeEvent(AM_ACTIVITY_LAUNCH_TIME,
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07002064 userId, System.identityHashCode(this), shortComponentName,
2065 thisTime, totalTime);
Wale Ogunwalef6733932018-06-27 05:14:34 -07002066 StringBuilder sb = service.mStringBuilder;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07002067 sb.setLength(0);
2068 sb.append("Displayed ");
2069 sb.append(shortComponentName);
2070 sb.append(": ");
2071 TimeUtils.formatDuration(thisTime, sb);
2072 if (thisTime != totalTime) {
2073 sb.append(" (total ");
2074 TimeUtils.formatDuration(totalTime, sb);
2075 sb.append(")");
2076 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08002077 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07002078 }
2079 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
2080 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07002081 //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07002082 }
2083 displayStartTime = 0;
Jorim Jaggide8305a2018-05-15 12:06:35 -07002084 entry.mLaunchStartTime = 0;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07002085 }
2086
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002087 @Override
Sudheer Shankac766db02017-06-12 10:37:29 -07002088 public void onStartingWindowDrawn(long timestamp) {
Wale Ogunwaled0412b32018-05-08 09:25:50 -07002089 synchronized (service.mGlobalLock) {
Bryce Lee2a3cc462017-10-27 10:57:35 -07002090 mStackSupervisor.getActivityMetricsLogger().notifyStartingWindowDrawn(
Jorim Jaggi9b58f2d2018-02-19 17:48:44 +01002091 getWindowingMode(), timestamp);
Jorim Jaggi3878ca32017-02-02 17:13:05 -08002092 }
2093 }
2094
2095 @Override
Sudheer Shankac766db02017-06-12 10:37:29 -07002096 public void onWindowsDrawn(long timestamp) {
Wale Ogunwaled0412b32018-05-08 09:25:50 -07002097 synchronized (service.mGlobalLock) {
Jorim Jaggi9b58f2d2018-02-19 17:48:44 +01002098 mStackSupervisor.getActivityMetricsLogger().notifyWindowsDrawn(getWindowingMode(),
2099 timestamp);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002100 if (displayStartTime != 0) {
Sudheer Shankac766db02017-06-12 10:37:29 -07002101 reportLaunchTimeLocked(timestamp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002103 mStackSupervisor.sendWaitingVisibleReportLocked(this);
2104 startTime = 0;
2105 finishLaunchTickingLocked();
2106 if (task != null) {
2107 task.hasBeenVisible = true;
2108 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002109 }
2110 }
2111
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002112 @Override
2113 public void onWindowsVisible() {
Wale Ogunwaled0412b32018-05-08 09:25:50 -07002114 synchronized (service.mGlobalLock) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002115 mStackSupervisor.reportActivityVisibleLocked(this);
2116 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this);
2117 if (!nowVisible) {
2118 nowVisible = true;
2119 lastVisibleTime = SystemClock.uptimeMillis();
Bryce Leeb7c9b802017-05-02 14:20:24 -07002120 if (idle || mStackSupervisor.isStoppingNoHistoryActivity()) {
2121 // If this activity was already idle or there is an activity that must be
2122 // stopped immediately after visible, then we now need to make sure we perform
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002123 // the full stop of any activities that are waiting to do so. This is because
2124 // we won't do that while they are still waiting for this one to become visible.
Bryce Lee4a194382017-04-04 14:32:48 -07002125 final int size = mStackSupervisor.mActivitiesWaitingForVisibleActivity.size();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002126 if (size > 0) {
2127 for (int i = 0; i < size; i++) {
Bryce Lee4a194382017-04-04 14:32:48 -07002128 final ActivityRecord r =
2129 mStackSupervisor.mActivitiesWaitingForVisibleActivity.get(i);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002130 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "Was waiting for visible: " + r);
2131 }
Bryce Lee4a194382017-04-04 14:32:48 -07002132 mStackSupervisor.mActivitiesWaitingForVisibleActivity.clear();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002133 mStackSupervisor.scheduleIdleLocked();
2134 }
Bryce Leeb7c9b802017-05-02 14:20:24 -07002135 } else {
2136 // Instead of doing the full stop routine here, let's just hide any activities
2137 // we now can, and let them stop when the normal idle happens.
2138 mStackSupervisor.processStoppingActivitiesLocked(null /* idleActivity */,
2139 false /* remove */, true /* processPausingActivities */);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002140 }
Wale Ogunwale906f9c62018-07-23 11:23:44 -07002141 service.scheduleAppGcsLocked();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002142 }
2143 }
2144 }
2145
2146 @Override
2147 public void onWindowsGone() {
Wale Ogunwaled0412b32018-05-08 09:25:50 -07002148 synchronized (service.mGlobalLock) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002149 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + this);
2150 nowVisible = false;
2151 }
2152 }
2153
2154 @Override
Wale Ogunwale7402ddf2017-03-29 12:58:24 -07002155 public boolean keyDispatchingTimedOut(String reason, int windowPid) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002156 ActivityRecord anrActivity;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07002157 WindowProcessController anrApp;
Wale Ogunwale7402ddf2017-03-29 12:58:24 -07002158 boolean windowFromSameProcessAsActivity;
Wale Ogunwaled0412b32018-05-08 09:25:50 -07002159 synchronized (service.mGlobalLock) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002160 anrActivity = getWaitingHistoryRecordLocked();
2161 anrApp = app;
Brian Carlstrom7b0f2e82017-03-31 00:24:18 -07002162 windowFromSameProcessAsActivity =
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07002163 !hasProcess() || app.getPid() == windowPid || windowPid == -1;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002164 }
Wale Ogunwale7402ddf2017-03-29 12:58:24 -07002165 if (windowFromSameProcessAsActivity) {
Wale Ogunwale906f9c62018-07-23 11:23:44 -07002166 return service.inputDispatchingTimedOut(anrApp, anrActivity, this, false, reason);
Wale Ogunwale7402ddf2017-03-29 12:58:24 -07002167 } else {
2168 // In this case another process added windows using this activity token. So, we call the
2169 // generic service input dispatch timed out method so that the right process is blamed.
Wale Ogunwale906f9c62018-07-23 11:23:44 -07002170 return service.inputDispatchingTimedOut(windowPid, false /* aboveSystem */, reason) < 0;
Wale Ogunwale7402ddf2017-03-29 12:58:24 -07002171 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002172 }
2173
2174 private ActivityRecord getWaitingHistoryRecordLocked() {
riddle_hsudb46d6b2015-04-01 18:58:07 +08002175 // First find the real culprit... if this activity is waiting for
2176 // another activity to start or has stopped, then the key dispatching
2177 // timeout should not be caused by this.
Bryce Lee4a194382017-04-04 14:32:48 -07002178 if (mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(this) || stopped) {
Andrii Kulian5f750bc2018-07-17 08:57:23 -07002179 final ActivityStack stack = mStackSupervisor.getTopDisplayFocusedStack();
riddle_hsudb46d6b2015-04-01 18:58:07 +08002180 // Try to use the one which is closest to top.
Bryce Leec4ab62a2018-03-05 14:19:26 -08002181 ActivityRecord r = stack.getResumedActivity();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002182 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -08002183 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002184 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08002185 if (r != null) {
2186 return r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002187 }
2188 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08002189 return this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002190 }
2191
Chong Zhang87761972016-08-22 13:53:24 -07002192 /** Checks whether the activity should be shown for current user. */
2193 public boolean okToShowLocked() {
Bryce Lee8558ec72017-08-17 15:37:26 -07002194 // We cannot show activities when the device is locked and the application is not
2195 // encryption aware.
2196 if (!StorageManager.isUserKeyUnlocked(userId)
2197 && !info.applicationInfo.isEncryptionAware()) {
2198 return false;
2199 }
2200
Chong Zhang87761972016-08-22 13:53:24 -07002201 return (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0
2202 || (mStackSupervisor.isCurrentProfileLocked(userId)
Wale Ogunwale86b74462018-07-02 08:42:43 -07002203 && service.mAmInternal.isUserRunning(userId, 0 /* flags */));
Chong Zhang87761972016-08-22 13:53:24 -07002204 }
2205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206 /**
2207 * This method will return true if the activity is either visible, is becoming visible, is
2208 * currently pausing, or is resumed.
2209 */
2210 public boolean isInterestingToUserLocked() {
Bryce Lee7ace3952018-02-16 14:34:32 -08002211 return visible || nowVisible || mState == PAUSING || mState == RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002212 }
2213
Wale Ogunwale3e997362016-09-06 10:37:56 -07002214 void setSleeping(boolean _sleeping) {
2215 setSleeping(_sleeping, false);
2216 }
2217
2218 void setSleeping(boolean _sleeping, boolean force) {
2219 if (!force && sleeping == _sleeping) {
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002220 return;
2221 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07002222 if (attachedToProcess()) {
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002223 try {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07002224 app.getThread().scheduleSleeping(appToken, _sleeping);
Craig Mautner0eea92c2013-05-16 13:35:39 -07002225 if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
2226 mStackSupervisor.mGoingToSleepActivities.add(this);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002227 }
2228 sleeping = _sleeping;
2229 } catch (RemoteException e) {
Craig Mautner0eea92c2013-05-16 13:35:39 -07002230 Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002231 }
2232 }
2233 }
Craig Mautnerf81b90872013-02-26 13:02:43 -08002234
Craig Mautnerd2328952013-03-05 12:46:26 -08002235 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07002236 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Craig Mautnerd2328952013-03-05 12:46:26 -08002237 if (r == null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08002238 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08002239 }
2240 final TaskRecord task = r.task;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07002241 final int activityNdx = task.mActivities.indexOf(r);
2242 if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08002243 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08002244 }
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07002245 return task.taskId;
Craig Mautnerd2328952013-03-05 12:46:26 -08002246 }
2247
2248 static ActivityRecord isInStackLocked(IBinder token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07002249 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Andrii Kulian02b7a832016-10-06 23:11:56 -07002250 return (r != null) ? r.getStack().isInStackLocked(r) : null;
Craig Mautnerd2328952013-03-05 12:46:26 -08002251 }
2252
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07002253 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -08002254 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
2255 if (r != null) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002256 return r.getStack();
Craig Mautnerd2328952013-03-05 12:46:26 -08002257 }
2258 return null;
2259 }
2260
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002261 /**
2262 * @return display id to which this record is attached, -1 if not attached.
2263 */
2264 int getDisplayId() {
2265 final ActivityStack stack = getStack();
2266 if (stack == null) {
2267 return -1;
2268 }
2269 return stack.mDisplayId;
2270 }
2271
Dianne Hackborn89ad4562014-08-24 16:45:38 -07002272 final boolean isDestroyable() {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07002273 if (finishing || !hasProcess()) {
Dianne Hackborn89ad4562014-08-24 16:45:38 -07002274 // This would be redundant.
2275 return false;
2276 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07002277 final ActivityStack stack = getStack();
Bryce Leec4ab62a2018-03-05 14:19:26 -08002278 if (stack == null || this == stack.getResumedActivity() || this == stack.mPausingActivity
Andrii Kulian02b7a832016-10-06 23:11:56 -07002279 || !haveState || !stopped) {
Dianne Hackborn89ad4562014-08-24 16:45:38 -07002280 // We're not ready for this kind of thing.
2281 return false;
2282 }
2283 if (visible) {
2284 // The user would notice this!
2285 return false;
2286 }
2287 return true;
2288 }
2289
Winson Chung3bad5cc02014-08-19 17:44:32 -07002290 private static String createImageFilename(long createTime, int taskId) {
2291 return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime +
Ruben Brunkf53497c2017-03-27 20:26:17 -07002292 IMAGE_EXTENSION;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002293 }
2294
Craig Mautner648f69b2014-09-18 14:16:26 -07002295 void setTaskDescription(TaskDescription _taskDescription) {
2296 Bitmap icon;
2297 if (_taskDescription.getIconFilename() == null &&
2298 (icon = _taskDescription.getIcon()) != null) {
2299 final String iconFilename = createImageFilename(createTime, task.taskId);
Winson Chungc8408b82017-01-25 17:58:56 -08002300 final File iconFile = new File(TaskPersister.getUserImagesDir(task.userId),
2301 iconFilename);
Suprabh Shukla23593142015-11-03 17:31:15 -08002302 final String iconFilePath = iconFile.getAbsolutePath();
Wale Ogunwaled0412b32018-05-08 09:25:50 -07002303 service.getRecentTasks().saveImage(icon, iconFilePath);
Suprabh Shukla23593142015-11-03 17:31:15 -08002304 _taskDescription.setIconFilename(iconFilePath);
Craig Mautner648f69b2014-09-18 14:16:26 -07002305 }
2306 taskDescription = _taskDescription;
2307 }
2308
Amith Yamasani0af6fa72016-01-17 15:36:19 -08002309 void setVoiceSessionLocked(IVoiceInteractionSession session) {
2310 voiceSession = session;
2311 pendingVoiceInteractionStart = false;
2312 }
2313
2314 void clearVoiceSessionLocked() {
2315 voiceSession = null;
2316 pendingVoiceInteractionStart = false;
2317 }
2318
Jorim Jaggi02886a82016-12-06 09:10:06 -08002319 void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch) {
Jorim Jaggi42befc62017-06-13 11:54:04 -07002320 showStartingWindow(prev, newTask, taskSwitch, false /* fromRecents */);
2321 }
2322
2323 void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch,
2324 boolean fromRecents) {
Jorim Jaggi70176432017-01-18 12:52:13 +01002325 if (mWindowContainerController == null) {
2326 return;
2327 }
Wale Ogunwale19866e22017-04-19 06:05:13 -07002328 if (mTaskOverlay) {
2329 // We don't show starting window for overlay activities.
2330 return;
2331 }
2332
Wale Ogunwale3b232392016-05-13 15:37:13 -07002333 final CompatibilityInfo compatInfo =
Wale Ogunwale53783742018-09-16 10:21:51 -07002334 service.compatibilityInfoForPackageLocked(info.applicationInfo);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002335 final boolean shown = mWindowContainerController.addStartingWindow(packageName, theme,
2336 compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags,
Jorim Jaggibae01b12017-04-11 16:29:10 -07002337 prev != null ? prev.appToken : null, newTask, taskSwitch, isProcessRunning(),
Jorim Jaggi70aa4d12017-05-15 00:05:54 +02002338 allowTaskSnapshot(),
Bryce Lee7ace3952018-02-16 14:34:32 -08002339 mState.ordinal() >= RESUMED.ordinal() && mState.ordinal() <= STOPPED.ordinal(),
Jorim Jaggi42befc62017-06-13 11:54:04 -07002340 fromRecents);
Wale Ogunwale3b232392016-05-13 15:37:13 -07002341 if (shown) {
2342 mStartingWindowState = STARTING_WINDOW_SHOWN;
2343 }
2344 }
2345
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002346 void removeOrphanedStartingWindow(boolean behindFullscreenActivity) {
Jorim Jaggicb956052017-05-09 16:27:24 +02002347 if (mStartingWindowState == STARTING_WINDOW_SHOWN && behindFullscreenActivity) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002348 if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, "Found orphaned starting window " + this);
2349 mStartingWindowState = STARTING_WINDOW_REMOVED;
Jorim Jaggi19be6052017-08-03 18:33:43 +02002350 mWindowContainerController.removeStartingWindow();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002351 }
2352 }
2353
2354 int getRequestedOrientation() {
2355 return mWindowContainerController.getOrientation();
2356 }
2357
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002358 void setRequestedOrientation(int requestedOrientation) {
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002359 final int displayId = getDisplayId();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002360 final Configuration displayConfig =
2361 mStackSupervisor.getDisplayOverrideConfiguration(displayId);
2362
2363 final Configuration config = mWindowContainerController.setOrientation(requestedOrientation,
2364 displayId, displayConfig, mayFreezeScreenLocked(app));
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002365 if (config != null) {
2366 frozenBeforeDestroy = true;
Wale Ogunwalea6191b42018-05-09 07:41:32 -07002367 if (!service.updateDisplayOverrideConfigurationLocked(config, this,
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002368 false /* deferResume */, displayId)) {
Andrii Kulianab132ee2018-07-24 22:10:21 +08002369 mStackSupervisor.resumeFocusedStacksTopActivitiesLocked();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002370 }
2371 }
Wale Ogunwaled0412b32018-05-08 09:25:50 -07002372 service.getTaskChangeNotificationController().notifyActivityRequestedOrientationChanged(
Yorke Leebd54c2a2016-10-25 13:49:23 -07002373 task.taskId, requestedOrientation);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002374 }
2375
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01002376 void setDisablePreviewScreenshots(boolean disable) {
2377 mWindowContainerController.setDisablePreviewScreenshots(disable);
2378 }
2379
Bryce Leea163b762017-01-24 11:05:01 -08002380 /**
2381 * Set the last reported global configuration to the client. Should be called whenever a new
2382 * global configuration is sent to the client for this activity.
2383 */
2384 void setLastReportedGlobalConfiguration(@NonNull Configuration config) {
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002385 mLastReportedConfiguration.setGlobalConfiguration(config);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002386 }
2387
Bryce Leea163b762017-01-24 11:05:01 -08002388 /**
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002389 * Set the last reported configuration to the client. Should be called whenever
Bryce Leea163b762017-01-24 11:05:01 -08002390 * a new merged configuration is sent to the client for this activity.
2391 */
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002392 void setLastReportedConfiguration(@NonNull MergedConfiguration config) {
Bryce Lee8104e7a2017-08-17 09:16:03 -07002393 setLastReportedConfiguration(config.getGlobalConfiguration(),
2394 config.getOverrideConfiguration());
Bryce Leea163b762017-01-24 11:05:01 -08002395 }
2396
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07002397 private void setLastReportedConfiguration(Configuration global, Configuration override) {
Bryce Lee8104e7a2017-08-17 09:16:03 -07002398 mLastReportedConfiguration.setConfiguration(global, override);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002399 }
2400
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002401 // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer.
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002402 private void updateOverrideConfiguration() {
2403 mTmpConfig.unset();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002404 computeBounds(mTmpBounds);
Bryce Leef3c6a472017-11-14 14:53:06 -08002405
2406 if (mTmpBounds.equals(getOverrideBounds())) {
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002407 return;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002408 }
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002409
Bryce Leef3c6a472017-11-14 14:53:06 -08002410 setBounds(mTmpBounds);
2411
2412 final Rect updatedBounds = getOverrideBounds();
2413
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002414 // Bounds changed...update configuration to match.
Bryce Leef3c6a472017-11-14 14:53:06 -08002415 if (!matchParentBounds()) {
2416 task.computeOverrideConfiguration(mTmpConfig, updatedBounds, null /* insetBounds */,
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002417 false /* overrideWidth */, false /* overrideHeight */);
2418 }
Bryce Leef3c6a472017-11-14 14:53:06 -08002419
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002420 onOverrideConfigurationChanged(mTmpConfig);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002421 }
2422
Wale Ogunwaled4b1d1e2017-04-10 06:35:59 -07002423 /** Returns true if the configuration is compatible with this activity. */
Wale Ogunwale42f07d92017-05-01 21:32:58 -07002424 boolean isConfigurationCompatible(Configuration config) {
Wale Ogunwaled4b1d1e2017-04-10 06:35:59 -07002425 final int orientation = mWindowContainerController != null
2426 ? mWindowContainerController.getOrientation() : info.screenOrientation;
2427 if (isFixedOrientationPortrait(orientation)
2428 && config.orientation != ORIENTATION_PORTRAIT) {
2429 return false;
2430 }
2431 if (isFixedOrientationLandscape(orientation)
2432 && config.orientation != ORIENTATION_LANDSCAPE) {
2433 return false;
2434 }
2435 return true;
2436 }
2437
Bryce Lee7566d762017-03-30 09:34:15 -07002438 /**
2439 * Computes the bounds to fit the Activity within the bounds of the {@link Configuration}.
2440 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002441 // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer.
2442 private void computeBounds(Rect outBounds) {
2443 outBounds.setEmpty();
2444 final float maxAspectRatio = info.maxAspectRatio;
2445 final ActivityStack stack = getStack();
Bryce Leef3c6a472017-11-14 14:53:06 -08002446 if (task == null || stack == null || task.inMultiWindowMode() || maxAspectRatio == 0
Bryce Leee5ab4502017-07-11 08:58:05 -07002447 || isInVrUiMode(getConfiguration())) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002448 // We don't set override configuration if that activity task isn't fullscreen. I.e. the
2449 // activity is in multi-window mode. Or, there isn't a max aspect ratio specified for
Bryce Leee5ab4502017-07-11 08:58:05 -07002450 // the activity. This is indicated by an empty {@link outBounds}. We also don't set it
2451 // if we are in VR mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002452 return;
2453 }
2454
Bryce Lee7566d762017-03-30 09:34:15 -07002455 // We must base this on the parent configuration, because we set our override
2456 // configuration's appBounds based on the result of this method. If we used our own
2457 // configuration, it would be influenced by past invocations.
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002458 final Rect appBounds = getParent().getWindowConfiguration().getAppBounds();
Wale Ogunwale822e5122017-07-26 06:02:24 -07002459 final int containingAppWidth = appBounds.width();
2460 final int containingAppHeight = appBounds.height();
Bryce Lee7566d762017-03-30 09:34:15 -07002461 int maxActivityWidth = containingAppWidth;
2462 int maxActivityHeight = containingAppHeight;
2463
2464 if (containingAppWidth < containingAppHeight) {
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002465 // Width is the shorter side, so we use that to figure-out what the max. height
2466 // should be given the aspect ratio.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002467 maxActivityHeight = (int) ((maxActivityWidth * maxAspectRatio) + 0.5f);
2468 } else {
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002469 // Height is the shorter side, so we use that to figure-out what the max. width
2470 // should be given the aspect ratio.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002471 maxActivityWidth = (int) ((maxActivityHeight * maxAspectRatio) + 0.5f);
2472 }
2473
Bryce Lee7566d762017-03-30 09:34:15 -07002474 if (containingAppWidth <= maxActivityWidth && containingAppHeight <= maxActivityHeight) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002475 // The display matches or is less than the activity aspect ratio, so nothing else to do.
Bryce Lee7566d762017-03-30 09:34:15 -07002476 // Return the existing bounds. If this method is running for the first time,
Bryce Leef3c6a472017-11-14 14:53:06 -08002477 // {@link #getOverrideBounds()} will be empty (representing no override). If the method has run
2478 // before, then effect of {@link #getOverrideBounds()} will already have been applied to the
Bryce Lee7566d762017-03-30 09:34:15 -07002479 // value returned from {@link getConfiguration}. Refer to
2480 // {@link TaskRecord#computeOverrideConfiguration}.
Bryce Leef3c6a472017-11-14 14:53:06 -08002481 outBounds.set(getOverrideBounds());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002482 return;
2483 }
2484
2485 // Compute configuration based on max supported width and height.
Adrian Roos24be34d2018-05-28 18:55:38 +02002486 // Also account for the left / top insets (e.g. from display cutouts), which will be clipped
2487 // away later in StackWindowController.adjustConfigurationForBounds(). Otherwise, the app
2488 // bounds would end up too small.
2489 outBounds.set(0, 0, maxActivityWidth + appBounds.left, maxActivityHeight + appBounds.top);
2490
2491 if (service.mWindowManager.getNavBarPosition() == NAV_BAR_LEFT) {
2492 // Position the activity frame on the opposite side of the nav bar.
2493 outBounds.left = appBounds.right - maxActivityWidth;
2494 outBounds.right = appBounds.right;
2495 }
Andrii Kulian3a1619d2017-07-07 14:38:09 -07002496 }
2497
Wale Ogunwaleb6d75f32018-02-22 20:44:56 -08002498 boolean ensureActivityConfiguration(int globalChanges, boolean preserveWindow) {
2499 return ensureActivityConfiguration(globalChanges, preserveWindow,
2500 false /* ignoreStopState */);
2501 }
2502
Andrii Kulian21713ac2016-10-12 22:05:05 -07002503 /**
Wale Ogunwaleb6d75f32018-02-22 20:44:56 -08002504 * Make sure the given activity matches the current configuration. Ensures the HistoryRecord
2505 * is updated with the correct configuration and all other bookkeeping is handled.
2506 *
2507 * @param globalChanges The changes to the global configuration.
2508 * @param preserveWindow If the activity window should be preserved on screen if the activity
2509 * is relaunched.
2510 * @param ignoreStopState If we should try to relaunch the activity even if it is in the stopped
2511 * state. This is useful for the case where we know the activity will be
2512 * visible soon and we want to ensure its configuration before we make it
2513 * visible.
2514 * @return True if the activity was relaunched and false if it wasn't relaunched because we
2515 * can't or the app handles the specific configuration that is changing.
Andrii Kulian21713ac2016-10-12 22:05:05 -07002516 */
Wale Ogunwaleb6d75f32018-02-22 20:44:56 -08002517 boolean ensureActivityConfiguration(int globalChanges, boolean preserveWindow,
2518 boolean ignoreStopState) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002519 final ActivityStack stack = getStack();
2520 if (stack.mConfigWillChange) {
2521 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2522 "Skipping config check (will change): " + this);
2523 return true;
2524 }
2525
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002526 // We don't worry about activities that are finishing.
2527 if (finishing) {
2528 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2529 "Configuration doesn't matter in finishing " + this);
2530 stopFreezingScreenLocked(false);
2531 return true;
2532 }
2533
Wale Ogunwaleb6d75f32018-02-22 20:44:56 -08002534 if (!ignoreStopState && (mState == STOPPING || mState == STOPPED)) {
Wale Ogunwale9b7a8272017-04-10 08:05:41 -07002535 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2536 "Skipping config check stopped or stopping: " + this);
2537 return true;
2538 }
2539
Wale Ogunwaleea3d3fd2017-05-01 07:41:08 -07002540 // TODO: We should add ActivityRecord.shouldBeVisible() that checks if the activity should
2541 // be visible based on the stack, task, and lockscreen state and use that here instead. The
2542 // method should be based on the logic in ActivityStack.ensureActivitiesVisibleLocked().
Wale Ogunwale9b7a8272017-04-10 08:05:41 -07002543 // Skip updating configuration for activity is a stack that shouldn't be visible.
Wale Ogunwale9dcf9462017-09-19 15:13:01 -07002544 if (!stack.shouldBeVisible(null /* starting */)) {
Wale Ogunwale9b7a8272017-04-10 08:05:41 -07002545 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2546 "Skipping config check invisible stack: " + this);
2547 return true;
2548 }
2549
Andrii Kulian21713ac2016-10-12 22:05:05 -07002550 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2551 "Ensuring correct configuration: " + this);
2552
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002553 final int newDisplayId = getDisplayId();
2554 final boolean displayChanged = mLastReportedDisplayId != newDisplayId;
2555 if (displayChanged) {
2556 mLastReportedDisplayId = newDisplayId;
2557 }
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002558 // TODO(b/36505427): Is there a better place to do this?
2559 updateOverrideConfiguration();
2560
Winson Chungbdc646f2017-02-13 12:12:22 -08002561 // Short circuit: if the two full configurations are equal (the common case), then there is
2562 // nothing to do. We test the full configuration instead of the global and merged override
2563 // configurations because there are cases (like moving a task to the pinned stack) where
2564 // the combine configurations are equal, but would otherwise differ in the override config
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002565 mTmpConfig.setTo(mLastReportedConfiguration.getMergedConfiguration());
2566 if (getConfiguration().equals(mTmpConfig) && !forceNewConfig && !displayChanged) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002567 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002568 "Configuration & display unchanged in " + this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002569 return true;
2570 }
2571
2572 // Okay we now are going to make this activity have the new config.
2573 // But then we need to figure out how it needs to deal with that.
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002574
2575 // Find changes between last reported merged configuration and the current one. This is used
2576 // to decide whether to relaunch an activity or just report a configuration change.
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002577 final int changes = getConfigurationChanges(mTmpConfig);
Ruben Brunkf64af332017-03-22 22:03:25 -07002578
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002579 // Update last reported values.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002580 final Configuration newMergedOverrideConfig = getMergedOverrideConfiguration();
Bryce Lee8104e7a2017-08-17 09:16:03 -07002581
Wale Ogunwalef6733932018-06-27 05:14:34 -07002582 setLastReportedConfiguration(service.getGlobalConfiguration(), newMergedOverrideConfig);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002583
Bryce Lee7ace3952018-02-16 14:34:32 -08002584 if (mState == INITIALIZING) {
Andrii Kulianb372da62018-01-18 10:46:24 -08002585 // No need to relaunch or schedule new config for activity that hasn't been launched
2586 // yet. We do, however, return after applying the config to activity record, so that
2587 // it will use it for launch transaction.
2588 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2589 "Skipping config check for initializing activity: " + this);
2590 return true;
2591 }
2592
Andrii Kulian21713ac2016-10-12 22:05:05 -07002593 if (changes == 0 && !forceNewConfig) {
2594 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2595 "Configuration no differences in " + this);
2596 // There are no significant differences, so we won't relaunch but should still deliver
2597 // the new configuration to the client process.
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002598 if (displayChanged) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002599 scheduleActivityMovedToDisplay(newDisplayId, newMergedOverrideConfig);
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002600 } else {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002601 scheduleConfigurationChanged(newMergedOverrideConfig);
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002602 }
Andrii Kulian21713ac2016-10-12 22:05:05 -07002603 return true;
2604 }
2605
2606 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002607 "Configuration changes for " + this + ", allChanges="
Andrii Kulian21713ac2016-10-12 22:05:05 -07002608 + Configuration.configurationDiffToString(changes));
2609
2610 // If the activity isn't currently running, just leave the new configuration and it will
2611 // pick that up next time it starts.
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07002612 if (!attachedToProcess()) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002613 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2614 "Configuration doesn't matter not running " + this);
2615 stopFreezingScreenLocked(false);
2616 forceNewConfig = false;
2617 return true;
2618 }
2619
2620 // Figure out how to handle the changes between the configurations.
2621 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2622 "Checking to restart " + info.name + ": changed=0x"
2623 + Integer.toHexString(changes) + ", handles=0x"
2624 + Integer.toHexString(info.getRealConfigChanged())
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002625 + ", mLastReportedConfiguration=" + mLastReportedConfiguration);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002626
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002627 if (shouldRelaunchLocked(changes, mTmpConfig) || forceNewConfig) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002628 // Aha, the activity isn't handling the change, so DIE DIE DIE.
2629 configChangeFlags |= changes;
2630 startFreezingScreenLocked(app, globalChanges);
2631 forceNewConfig = false;
2632 preserveWindow &= isResizeOnlyChange(changes);
Garfield Tan2746ab52018-07-25 12:33:01 -07002633 final boolean hasResizeChange = hasResizeChange(changes & ~info.getRealConfigChanged());
2634 if (hasResizeChange) {
2635 final boolean isDragResizing =
2636 getTask().getWindowContainerController().isDragResizing();
2637 mRelaunchReason = isDragResizing ? RELAUNCH_REASON_FREE_RESIZE
2638 : RELAUNCH_REASON_WINDOWING_MODE_RESIZE;
2639 } else {
2640 mRelaunchReason = RELAUNCH_REASON_NONE;
2641 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07002642 if (!attachedToProcess()) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002643 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2644 "Config is destroying non-running " + this);
2645 stack.destroyActivityLocked(this, true, "config");
Bryce Lee7ace3952018-02-16 14:34:32 -08002646 } else if (mState == PAUSING) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002647 // A little annoying: we are waiting for this activity to finish pausing. Let's not
2648 // do anything now, but just flag that it needs to be restarted when done pausing.
2649 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2650 "Config is skipping already pausing " + this);
2651 deferRelaunchUntilPaused = true;
2652 preserveWindowOnDeferredRelaunch = preserveWindow;
2653 return true;
Bryce Lee7ace3952018-02-16 14:34:32 -08002654 } else if (mState == RESUMED) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002655 // Try to optimize this case: the configuration is changing and we need to restart
2656 // the top, resumed activity. Instead of doing the normal handshaking, just say
2657 // "restart!".
2658 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2659 "Config is relaunching resumed " + this);
2660
2661 if (DEBUG_STATES && !visible) {
2662 Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + this
2663 + " called by " + Debug.getCallers(4));
2664 }
2665
2666 relaunchActivityLocked(true /* andResume */, preserveWindow);
2667 } else {
2668 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2669 "Config is relaunching non-resumed " + this);
2670 relaunchActivityLocked(false /* andResume */, preserveWindow);
2671 }
2672
2673 // All done... tell the caller we weren't able to keep this activity around.
2674 return false;
2675 }
2676
2677 // Default case: the activity can handle this new configuration, so hand it over.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002678 // NOTE: We only forward the override configuration as the system level configuration
Andrii Kulian21713ac2016-10-12 22:05:05 -07002679 // changes is always sent to all processes when they happen so it can just use whatever
2680 // system level configuration it last got.
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002681 if (displayChanged) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002682 scheduleActivityMovedToDisplay(newDisplayId, newMergedOverrideConfig);
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002683 } else {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002684 scheduleConfigurationChanged(newMergedOverrideConfig);
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002685 }
Andrii Kulian21713ac2016-10-12 22:05:05 -07002686 stopFreezingScreenLocked(false);
2687
2688 return true;
2689 }
2690
Zak Cohen90e7116742017-01-29 12:59:23 -08002691 /**
2692 * When assessing a configuration change, decide if the changes flags and the new configurations
2693 * should cause the Activity to relaunch.
Ruben Brunkf64af332017-03-22 22:03:25 -07002694 *
2695 * @param changes the changes due to the given configuration.
2696 * @param changesConfig the configuration that was used to calculate the given changes via a
2697 * call to getConfigurationChanges.
Zak Cohen90e7116742017-01-29 12:59:23 -08002698 */
Ruben Brunkf64af332017-03-22 22:03:25 -07002699 private boolean shouldRelaunchLocked(int changes, Configuration changesConfig) {
Zak Cohen90e7116742017-01-29 12:59:23 -08002700 int configChanged = info.getRealConfigChanged();
Ruben Brunkf64af332017-03-22 22:03:25 -07002701 boolean onlyVrUiModeChanged = onlyVrUiModeChanged(changes, changesConfig);
Zak Cohen90e7116742017-01-29 12:59:23 -08002702
2703 // Override for apps targeting pre-O sdks
2704 // If a device is in VR mode, and we're transitioning into VR ui mode, add ignore ui mode
2705 // to the config change.
2706 // For O and later, apps will be required to add configChanges="uimode" to their manifest.
2707 if (appInfo.targetSdkVersion < O
2708 && requestedVrComponent != null
Ruben Brunkf64af332017-03-22 22:03:25 -07002709 && onlyVrUiModeChanged) {
Zak Cohen90e7116742017-01-29 12:59:23 -08002710 configChanged |= CONFIG_UI_MODE;
2711 }
2712
2713 return (changes&(~configChanged)) != 0;
2714 }
2715
Ruben Brunkf64af332017-03-22 22:03:25 -07002716 /**
2717 * Returns true if the configuration change is solely due to the UI mode switching into or out
2718 * of UI_MODE_TYPE_VR_HEADSET.
2719 */
2720 private boolean onlyVrUiModeChanged(int changes, Configuration lastReportedConfig) {
2721 final Configuration currentConfig = getConfiguration();
Ruben Brunkf53497c2017-03-27 20:26:17 -07002722 return changes == CONFIG_UI_MODE && (isInVrUiMode(currentConfig)
Ruben Brunkf64af332017-03-22 22:03:25 -07002723 != isInVrUiMode(lastReportedConfig));
2724 }
2725
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002726 private int getConfigurationChanges(Configuration lastReportedConfig) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002727 // Determine what has changed. May be nothing, if this is a config that has come back from
2728 // the app after going idle. In that case we just want to leave the official config object
2729 // now in the activity and do nothing else.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002730 final Configuration currentConfig = getConfiguration();
2731 int changes = lastReportedConfig.diff(currentConfig);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002732 // We don't want to use size changes if they don't cross boundaries that are important to
2733 // the app.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002734 if ((changes & CONFIG_SCREEN_SIZE) != 0) {
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002735 final boolean crosses = crossesHorizontalSizeThreshold(lastReportedConfig.screenWidthDp,
2736 currentConfig.screenWidthDp)
2737 || crossesVerticalSizeThreshold(lastReportedConfig.screenHeightDp,
2738 currentConfig.screenHeightDp);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002739 if (!crosses) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002740 changes &= ~CONFIG_SCREEN_SIZE;
Andrii Kulian21713ac2016-10-12 22:05:05 -07002741 }
2742 }
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002743 if ((changes & CONFIG_SMALLEST_SCREEN_SIZE) != 0) {
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002744 final int oldSmallest = lastReportedConfig.smallestScreenWidthDp;
2745 final int newSmallest = currentConfig.smallestScreenWidthDp;
2746 if (!crossesSmallestSizeThreshold(oldSmallest, newSmallest)) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002747 changes &= ~CONFIG_SMALLEST_SCREEN_SIZE;
Andrii Kulian21713ac2016-10-12 22:05:05 -07002748 }
2749 }
Wale Ogunwale822e5122017-07-26 06:02:24 -07002750 // We don't want window configuration to cause relaunches.
2751 if ((changes & CONFIG_WINDOW_CONFIGURATION) != 0) {
2752 changes &= ~CONFIG_WINDOW_CONFIGURATION;
2753 }
Bryce Lee600dadd2017-07-25 10:48:42 -07002754
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002755 return changes;
Andrii Kulian21713ac2016-10-12 22:05:05 -07002756 }
2757
2758 private static boolean isResizeOnlyChange(int change) {
2759 return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION
2760 | CONFIG_SCREEN_LAYOUT)) == 0;
2761 }
2762
Garfield Tan2746ab52018-07-25 12:33:01 -07002763 private static boolean hasResizeChange(int change) {
2764 return (change & (CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION
2765 | CONFIG_SCREEN_LAYOUT)) != 0;
2766 }
2767
Andrii Kulian21713ac2016-10-12 22:05:05 -07002768 void relaunchActivityLocked(boolean andResume, boolean preserveWindow) {
Wale Ogunwaled0412b32018-05-08 09:25:50 -07002769 if (service.mSuppressResizeConfigChanges && preserveWindow) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002770 configChangeFlags = 0;
2771 return;
2772 }
2773
2774 List<ResultInfo> pendingResults = null;
2775 List<ReferrerIntent> pendingNewIntents = null;
2776 if (andResume) {
2777 pendingResults = results;
2778 pendingNewIntents = newIntents;
2779 }
2780 if (DEBUG_SWITCH) Slog.v(TAG_SWITCH,
2781 "Relaunching: " + this + " with results=" + pendingResults
2782 + " newIntents=" + pendingNewIntents + " andResume=" + andResume
2783 + " preserveWindow=" + preserveWindow);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002784 EventLog.writeEvent(andResume ? AM_RELAUNCH_RESUME_ACTIVITY
2785 : AM_RELAUNCH_ACTIVITY, userId, System.identityHashCode(this),
Andrii Kulian21713ac2016-10-12 22:05:05 -07002786 task.taskId, shortComponentName);
2787
2788 startFreezingScreenLocked(app, 0);
2789
Andrii Kulian21713ac2016-10-12 22:05:05 -07002790 try {
2791 if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH,
2792 "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + this
2793 + " callers=" + Debug.getCallers(6));
2794 forceNewConfig = false;
2795 mStackSupervisor.activityRelaunchingLocked(this);
Andrii Kulianb372da62018-01-18 10:46:24 -08002796 final ClientTransactionItem callbackItem = ActivityRelaunchItem.obtain(pendingResults,
2797 pendingNewIntents, configChangeFlags,
Wale Ogunwalef6733932018-06-27 05:14:34 -07002798 new MergedConfiguration(service.getGlobalConfiguration(),
Andrii Kulianb372da62018-01-18 10:46:24 -08002799 getMergedOverrideConfiguration()),
2800 preserveWindow);
2801 final ActivityLifecycleItem lifecycleItem;
2802 if (andResume) {
2803 lifecycleItem = ResumeActivityItem.obtain(service.isNextTransitionForward());
2804 } else {
Bryce Lee1d0d5142018-04-12 10:35:07 -07002805 lifecycleItem = PauseActivityItem.obtain();
Andrii Kulianb372da62018-01-18 10:46:24 -08002806 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07002807 final ClientTransaction transaction = ClientTransaction.obtain(app.getThread(), appToken);
Andrii Kulianb372da62018-01-18 10:46:24 -08002808 transaction.addCallback(callbackItem);
2809 transaction.setLifecycleStateRequest(lifecycleItem);
Bryce Leeb0f993f2018-03-02 15:38:01 -08002810 service.getLifecycleManager().scheduleTransaction(transaction);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002811 // Note: don't need to call pauseIfSleepingLocked() here, because the caller will only
Andrii Kulianb372da62018-01-18 10:46:24 -08002812 // request resume if this activity is currently resumed, which implies we aren't
Andrii Kulian21713ac2016-10-12 22:05:05 -07002813 // sleeping.
2814 } catch (RemoteException e) {
2815 if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e);
2816 }
2817
2818 if (andResume) {
2819 if (DEBUG_STATES) {
2820 Slog.d(TAG_STATES, "Resumed after relaunch " + this);
2821 }
2822 results = null;
2823 newIntents = null;
Wale Ogunwale008163e2018-07-23 23:11:08 -07002824 service.getAppWarningsLocked().onResumeActivity(this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002825 } else {
Wale Ogunwale008163e2018-07-23 23:11:08 -07002826 final ActivityStack stack = getStack();
2827 if (stack != null) {
2828 stack.mHandler.removeMessages(PAUSE_TIMEOUT_MSG, this);
2829 }
Bryce Lee7ace3952018-02-16 14:34:32 -08002830 setState(PAUSED, "relaunchActivityLocked");
Andrii Kulian21713ac2016-10-12 22:05:05 -07002831 }
2832
2833 configChangeFlags = 0;
2834 deferRelaunchUntilPaused = false;
2835 preserveWindowOnDeferredRelaunch = false;
2836 }
2837
Jorim Jaggibae01b12017-04-11 16:29:10 -07002838 private boolean isProcessRunning() {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07002839 WindowProcessController proc = app;
Jorim Jaggi02886a82016-12-06 09:10:06 -08002840 if (proc == null) {
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07002841 proc = service.mProcessNames.get(processName, info.applicationInfo.uid);
Jorim Jaggi02886a82016-12-06 09:10:06 -08002842 }
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07002843 return proc != null && proc.hasThread();
Jorim Jaggi02886a82016-12-06 09:10:06 -08002844 }
2845
Jorim Jaggibae01b12017-04-11 16:29:10 -07002846 /**
2847 * @return Whether a task snapshot starting window may be shown.
2848 */
2849 private boolean allowTaskSnapshot() {
2850 if (newIntents == null) {
2851 return true;
2852 }
2853
2854 // Restrict task snapshot starting window to launcher start, or there is no intent at all
2855 // (eg. task being brought to front). If the intent is something else, likely the app is
2856 // going to show some specific page or view, instead of what's left last time.
2857 for (int i = newIntents.size() - 1; i >= 0; i--) {
2858 final Intent intent = newIntents.get(i);
2859 if (intent != null && !ActivityRecord.isMainIntent(intent)) {
2860 return false;
2861 }
2862 }
2863 return true;
2864 }
2865
Bryce Leeb7c9b802017-05-02 14:20:24 -07002866 /**
2867 * Returns {@code true} if the associated activity has the no history flag set on it.
2868 * {@code false} otherwise.
2869 */
2870 boolean isNoHistory() {
2871 return (intent.getFlags() & FLAG_ACTIVITY_NO_HISTORY) != 0
2872 || (info.flags & FLAG_NO_HISTORY) != 0;
2873 }
2874
Craig Mautner21d24a22014-04-23 11:45:37 -07002875 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
2876 out.attribute(null, ATTR_ID, String.valueOf(createTime));
2877 out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
2878 if (launchedFromPackage != null) {
2879 out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage);
2880 }
2881 if (resolvedType != null) {
2882 out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType);
2883 }
2884 out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified));
2885 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Winson Chung2cb86c72014-06-25 12:03:30 -07002886
Craig Mautner21d24a22014-04-23 11:45:37 -07002887 if (taskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07002888 taskDescription.saveToXml(out);
Craig Mautner21d24a22014-04-23 11:45:37 -07002889 }
2890
2891 out.startTag(null, TAG_INTENT);
2892 intent.saveToXml(out);
2893 out.endTag(null, TAG_INTENT);
2894
2895 if (isPersistable() && persistentState != null) {
2896 out.startTag(null, TAG_PERSISTABLEBUNDLE);
2897 persistentState.saveToXml(out);
2898 out.endTag(null, TAG_PERSISTABLEBUNDLE);
2899 }
2900 }
2901
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07002902 static ActivityRecord restoreFromXml(XmlPullParser in,
2903 ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07002904 Intent intent = null;
2905 PersistableBundle persistentState = null;
2906 int launchedFromUid = 0;
2907 String launchedFromPackage = null;
2908 String resolvedType = null;
2909 boolean componentSpecified = false;
2910 int userId = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07002911 long createTime = -1;
2912 final int outerDepth = in.getDepth();
Winson Chung2cb86c72014-06-25 12:03:30 -07002913 TaskDescription taskDescription = new TaskDescription();
Craig Mautner21d24a22014-04-23 11:45:37 -07002914
2915 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
2916 final String attrName = in.getAttributeName(attrNdx);
2917 final String attrValue = in.getAttributeValue(attrNdx);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002918 if (DEBUG) Slog.d(TaskPersister.TAG,
Wale Ogunwale18795a22014-12-03 11:38:33 -08002919 "ActivityRecord: attribute name=" + attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002920 if (ATTR_ID.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01002921 createTime = Long.parseLong(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002922 } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01002923 launchedFromUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002924 } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
2925 launchedFromPackage = attrValue;
2926 } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
2927 resolvedType = attrValue;
2928 } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
Tobias Thiererb0800dc2016-04-21 17:51:41 +01002929 componentSpecified = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002930 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01002931 userId = Integer.parseInt(attrValue);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002932 } else if (attrName.startsWith(ATTR_TASKDESCRIPTION_PREFIX)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07002933 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002934 } else {
2935 Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName);
2936 }
2937 }
2938
2939 int event;
Ruben Brunkf53497c2017-03-27 20:26:17 -07002940 while (((event = in.next()) != END_DOCUMENT) &&
2941 (event != END_TAG || in.getDepth() >= outerDepth)) {
2942 if (event == START_TAG) {
Craig Mautner21d24a22014-04-23 11:45:37 -07002943 final String name = in.getName();
Ruben Brunkf53497c2017-03-27 20:26:17 -07002944 if (DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08002945 Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name);
Craig Mautner21d24a22014-04-23 11:45:37 -07002946 if (TAG_INTENT.equals(name)) {
2947 intent = Intent.restoreFromXml(in);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002948 if (DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08002949 Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07002950 } else if (TAG_PERSISTABLEBUNDLE.equals(name)) {
2951 persistentState = PersistableBundle.restoreFromXml(in);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002952 if (DEBUG) Slog.d(TaskPersister.TAG,
Craig Mautner21d24a22014-04-23 11:45:37 -07002953 "ActivityRecord: persistentState=" + persistentState);
2954 } else {
2955 Slog.w(TAG, "restoreActivity: unexpected name=" + name);
2956 XmlUtils.skipCurrentTag(in);
2957 }
2958 }
2959 }
2960
2961 if (intent == null) {
Craig Mautnere0129b32014-05-25 16:41:09 -07002962 throw new XmlPullParserException("restoreActivity error intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07002963 }
2964
Wale Ogunwalec9e57de2018-05-08 14:28:07 -07002965 final ActivityTaskManagerService service = stackSupervisor.mService;
Craig Mautner21d24a22014-04-23 11:45:37 -07002966 final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null,
Patrick Baumann78380272018-04-04 10:41:01 -07002967 userId, Binder.getCallingUid());
Craig Mautnere0129b32014-05-25 16:41:09 -07002968 if (aInfo == null) {
Craig Mautner77b04262014-06-27 15:22:12 -07002969 throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent +
2970 " resolvedType=" + resolvedType);
Craig Mautnere0129b32014-05-25 16:41:09 -07002971 }
Wale Ogunwalec9e57de2018-05-08 14:28:07 -07002972 final ActivityRecord r = new ActivityRecord(service, null /* caller */,
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002973 0 /* launchedFromPid */, launchedFromUid, launchedFromPackage, intent, resolvedType,
Wale Ogunwalef6733932018-06-27 05:14:34 -07002974 aInfo, service.getConfiguration(), null /* resultTo */, null /* resultWho */,
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002975 0 /* reqCode */, componentSpecified, false /* rootVoiceInteraction */,
Andrii Kulian94e82d9b02017-07-13 15:33:06 -07002976 stackSupervisor, null /* options */, null /* sourceRecord */);
Craig Mautner21d24a22014-04-23 11:45:37 -07002977
2978 r.persistentState = persistentState;
Winson Chung2cb86c72014-06-25 12:03:30 -07002979 r.taskDescription = taskDescription;
Craig Mautner21d24a22014-04-23 11:45:37 -07002980 r.createTime = createTime;
2981
2982 return r;
2983 }
2984
Zak Cohen90e7116742017-01-29 12:59:23 -08002985 private static boolean isInVrUiMode(Configuration config) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07002986 return (config.uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_VR_HEADSET;
Zak Cohen90e7116742017-01-29 12:59:23 -08002987 }
2988
David Stevens82ea6cb2017-03-03 16:18:50 -08002989 int getUid() {
2990 return info.applicationInfo.uid;
2991 }
2992
chaviw59b98852017-06-13 12:05:44 -07002993 void setShowWhenLocked(boolean showWhenLocked) {
2994 mShowWhenLocked = showWhenLocked;
Kevin Chyn44639482017-10-09 18:34:41 -07002995 mStackSupervisor.ensureActivitiesVisibleLocked(null, 0 /* configChanges */,
2996 false /* preserveWindows */);
chaviw59b98852017-06-13 12:05:44 -07002997 }
2998
2999 /**
chaviw2c500982018-01-04 17:05:05 -08003000 * @return true if the activity windowing mode is not
3001 * {@link android.app.WindowConfiguration#WINDOWING_MODE_PINNED} and activity contains
3002 * windows that have {@link LayoutParams#FLAG_SHOW_WHEN_LOCKED} set or if the activity
3003 * has set {@link #mShowWhenLocked}.
3004 * Multi-windowing mode will be exited if true is returned.
chaviw59b98852017-06-13 12:05:44 -07003005 */
3006 boolean canShowWhenLocked() {
chaviw2c500982018-01-04 17:05:05 -08003007 return !inPinnedWindowingMode() && (mShowWhenLocked
Wale Ogunwale2cca8622017-12-11 08:40:13 -08003008 || service.mWindowManager.containsShowWhenLockedWindow(appToken));
chaviw59b98852017-06-13 12:05:44 -07003009 }
3010
3011 void setTurnScreenOn(boolean turnScreenOn) {
3012 mTurnScreenOn = turnScreenOn;
3013 }
3014
3015 /**
3016 * Determines whether this ActivityRecord can turn the screen on. It checks whether the flag
3017 * {@link #mTurnScreenOn} is set and checks whether the ActivityRecord should be visible
3018 * depending on Keyguard state
3019 *
3020 * @return true if the screen can be turned on, false otherwise.
3021 */
3022 boolean canTurnScreenOn() {
3023 final ActivityStack stack = getStack();
3024 return mTurnScreenOn && stack != null &&
3025 stack.checkKeyguardVisibility(this, true /* shouldBeVisible */, true /* isTop */);
3026 }
3027
3028 boolean getTurnScreenOnFlag() {
3029 return mTurnScreenOn;
3030 }
3031
3032 boolean isTopRunningActivity() {
3033 return mStackSupervisor.topRunningActivityLocked() == this;
3034 }
3035
Andrii Kulian52d255c2018-07-13 11:32:19 -07003036 /**
3037 * @return {@code true} if this is the resumed activity on its current display, {@code false}
3038 * otherwise.
3039 */
3040 boolean isResumedActivityOnDisplay() {
3041 final ActivityDisplay display = getDisplay();
3042 return display != null && this == display.getResumedActivity();
3043 }
3044
Jorim Jaggif84e2f62018-01-16 14:17:59 +01003045 void registerRemoteAnimations(RemoteAnimationDefinition definition) {
3046 mWindowContainerController.registerRemoteAnimations(definition);
3047 }
3048
Garfield Tan2746ab52018-07-25 12:33:01 -07003049 static String relaunchReasonToString(int relaunchReason) {
3050 switch (relaunchReason) {
3051 case RELAUNCH_REASON_WINDOWING_MODE_RESIZE:
3052 return "window_resize";
3053 case RELAUNCH_REASON_FREE_RESIZE:
3054 return "free_resize";
3055 default:
3056 return null;
3057 }
3058 }
3059
Craig Mautnerf81b90872013-02-26 13:02:43 -08003060 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003061 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07003062 if (stringName != null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08003063 return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) +
Craig Mautnerf3333272013-04-22 10:55:53 -07003064 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07003065 }
3066 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -08003067 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07003068 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -07003069 sb.append(" u");
3070 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07003071 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003072 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -08003073 stringName = sb.toString();
3074 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003075 }
Steven Timotius4346f0a2017-09-12 11:07:21 -07003076
3077 void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
3078 final long token = proto.start(fieldId);
3079 proto.write(HASH_CODE, System.identityHashCode(this));
3080 proto.write(USER_ID, userId);
3081 proto.write(TITLE, intent.getComponent().flattenToShortString());
3082 proto.end(token);
3083 }
3084
3085 public void writeToProto(ProtoOutputStream proto, long fieldId) {
3086 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02003087 super.writeToProto(proto, CONFIGURATION_CONTAINER, false /* trim */);
Steven Timotius4346f0a2017-09-12 11:07:21 -07003088 writeIdentifierToProto(proto, IDENTIFIER);
Bryce Lee7ace3952018-02-16 14:34:32 -08003089 proto.write(STATE, mState.toString());
Steven Timotius4346f0a2017-09-12 11:07:21 -07003090 proto.write(VISIBLE, visible);
3091 proto.write(FRONT_OF_TASK, frontOfTask);
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -07003092 if (hasProcess()) {
3093 proto.write(PROC_ID, app.getPid());
Steven Timotius4346f0a2017-09-12 11:07:21 -07003094 }
Wale Ogunwale30eab1f2018-05-24 18:25:25 -07003095 proto.write(TRANSLUCENT, !fullscreen);
Steven Timotius4346f0a2017-09-12 11:07:21 -07003096 proto.end(token);
3097 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003098}