blob: 4bb18e2b0f010b499715f305cec4237428e74797 [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;
Jorim Jaggi3878ca32017-02-02 17:13:05 -080020import static android.app.ActivityManager.StackId.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.DESTROYED;
97import static com.android.server.am.ActivityStack.ActivityState.DESTROYING;
98import static com.android.server.am.ActivityStack.ActivityState.INITIALIZING;
99import static com.android.server.am.ActivityStack.ActivityState.PAUSED;
100import static com.android.server.am.ActivityStack.ActivityState.PAUSING;
101import static com.android.server.am.ActivityStack.ActivityState.RESUMED;
102import static com.android.server.am.ActivityStack.ActivityState.STOPPED;
103import static com.android.server.am.ActivityStack.ActivityState.STOPPING;
104import static com.android.server.am.ActivityStack.LAUNCH_TICK;
105import static com.android.server.am.ActivityStack.LAUNCH_TICK_MSG;
106import static com.android.server.am.ActivityStack.PAUSE_TIMEOUT_MSG;
107import static com.android.server.am.ActivityStack.STOP_TIMEOUT_MSG;
108import static com.android.server.am.EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME;
109import static com.android.server.am.EventLogTags.AM_ACTIVITY_LAUNCH_TIME;
110import static com.android.server.am.EventLogTags.AM_RELAUNCH_ACTIVITY;
111import static com.android.server.am.EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY;
112import static com.android.server.am.TaskPersister.DEBUG;
113import static com.android.server.am.TaskPersister.IMAGE_EXTENSION;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800114import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
Steven Timotius4346f0a2017-09-12 11:07:21 -0700115import static com.android.server.am.proto.ActivityRecordProto.CONFIGURATION_CONTAINER;
116import static com.android.server.am.proto.ActivityRecordProto.FRONT_OF_TASK;
117import static com.android.server.am.proto.ActivityRecordProto.IDENTIFIER;
118import static com.android.server.am.proto.ActivityRecordProto.PROC_ID;
119import static com.android.server.am.proto.ActivityRecordProto.STATE;
120import static com.android.server.am.proto.ActivityRecordProto.VISIBLE;
Adrian Roose99bc052017-11-20 17:55:31 +0100121import static com.android.server.policy.WindowManagerPolicy.NAV_BAR_LEFT;
Steven Timotius4346f0a2017-09-12 11:07:21 -0700122import static com.android.server.wm.proto.IdentifierProto.HASH_CODE;
123import static com.android.server.wm.proto.IdentifierProto.TITLE;
124import static com.android.server.wm.proto.IdentifierProto.USER_ID;
125
Ruben Brunkf53497c2017-03-27 20:26:17 -0700126import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
127import static org.xmlpull.v1.XmlPullParser.END_TAG;
128import static org.xmlpull.v1.XmlPullParser.START_TAG;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800129
Andrii Kulian21713ac2016-10-12 22:05:05 -0700130import android.annotation.NonNull;
Craig Mautner21d24a22014-04-23 11:45:37 -0700131import android.app.ActivityManager.TaskDescription;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700132import android.app.ActivityOptions;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800133import android.app.PendingIntent;
Winson Chung709904f2017-04-25 11:00:48 -0700134import android.app.PictureInPictureParams;
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800135import android.app.ResultInfo;
Andrii Kulianb372da62018-01-18 10:46:24 -0800136import android.app.servertransaction.ActivityLifecycleItem;
137import android.app.servertransaction.ActivityRelaunchItem;
138import android.app.servertransaction.ClientTransaction;
139import android.app.servertransaction.ClientTransactionItem;
Andrii Kulian446e8242017-10-26 15:17:29 -0700140import android.app.servertransaction.MoveToDisplayItem;
141import android.app.servertransaction.MultiWindowModeChangeItem;
142import android.app.servertransaction.NewIntentItem;
Bryce Lee0bd8d422018-01-09 09:45:57 -0800143import android.app.servertransaction.PauseActivityItem;
Andrii Kulian446e8242017-10-26 15:17:29 -0700144import android.app.servertransaction.PipModeChangeItem;
Andrii Kulianb372da62018-01-18 10:46:24 -0800145import android.app.servertransaction.ResumeActivityItem;
Andrii Kulian446e8242017-10-26 15:17:29 -0700146import android.app.servertransaction.WindowVisibilityItem;
147import android.app.servertransaction.ActivityConfigurationChangeItem;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148import android.content.ComponentName;
149import android.content.Intent;
150import android.content.pm.ActivityInfo;
151import android.content.pm.ApplicationInfo;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700152import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153import android.content.res.Configuration;
154import android.graphics.Bitmap;
Winson Chungaa7fa012017-05-24 15:50:06 -0700155import android.graphics.GraphicBuffer;
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700156import android.graphics.Rect;
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 Ogunwale26c0dfe2016-12-14 14:42:30 -0800189import com.android.server.wm.AppWindowContainerController;
190import com.android.server.wm.AppWindowContainerListener;
Wale Ogunwale98d62312017-07-12 09:24:56 -0700191import com.android.server.wm.ConfigurationContainer;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800192import com.android.server.wm.TaskWindowContainerController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193
Jorim Jaggi02886a82016-12-06 09:10:06 -0800194import org.xmlpull.v1.XmlPullParser;
195import org.xmlpull.v1.XmlPullParserException;
196import org.xmlpull.v1.XmlSerializer;
197
Suprabh Shukla23593142015-11-03 17:31:15 -0800198import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -0700199import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200import java.io.PrintWriter;
201import java.lang.ref.WeakReference;
202import java.util.ArrayList;
Todd Kennedy39bfee52016-02-24 10:28:21 -0800203import java.util.Arrays;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204import java.util.HashSet;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700205import java.util.List;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700206import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207
208/**
209 * An entry in the history stack, representing an activity.
210 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700211final class ActivityRecord extends ConfigurationContainer implements AppWindowContainerListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800212 private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityRecord" : TAG_AM;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700213 private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION;
214 private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700215 private static final String TAG_STATES = TAG + POSTFIX_STATES;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700216 private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700217 private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY;
Winson Chung16e185e2017-11-07 08:30:54 -0800218 // TODO(b/67864419): Remove once recents component is overridden
219 private static final String LEGACY_RECENTS_PACKAGE_NAME = "com.android.systemui.recents";
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800220
Wale Ogunwale3ab9a272015-03-16 09:55:45 -0700221 private static final boolean SHOW_ACTIVITY_START_TIME = true;
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700222
Craig Mautner21d24a22014-04-23 11:45:37 -0700223 private static final String ATTR_ID = "id";
224 private static final String TAG_INTENT = "intent";
225 private static final String ATTR_USERID = "user_id";
226 private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle";
227 private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700228 private static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package";
Craig Mautner21d24a22014-04-23 11:45:37 -0700229 private static final String ATTR_RESOLVEDTYPE = "resolved_type";
230 private static final String ATTR_COMPONENTSPECIFIED = "component_specified";
Dianne Hackborn337abb32014-09-24 12:44:29 -0700231 static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_";
Craig Mautner21d24a22014-04-23 11:45:37 -0700232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 final ActivityManagerService service; // owner
Dianne Hackbornbe707852011-11-11 14:32:10 -0800234 final IApplicationToken.Stub appToken; // window manager token
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800235 AppWindowContainerController mWindowContainerController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 final ActivityInfo info; // all about me
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700237 final ApplicationInfo appInfo; // information about activity's app
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800238 final int launchedFromPid; // always the pid who started the activity.
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700239 final int launchedFromUid; // always the uid who started the activity.
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800240 final String launchedFromPackage; // always the package who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -0700241 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 final Intent intent; // the original intent that generated us
243 final ComponentName realActivity; // the intent component, or target of an alias.
244 final String shortComponentName; // the short component name of the intent
245 final String resolvedType; // as per original caller;
246 final String packageName; // the package implementing intent's component
247 final String processName; // process where this component wants to run
248 final String taskAffinity; // as per ActivityInfo.taskAffinity
249 final boolean stateNotNeeded; // As per ActivityInfo.flags
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -0700250 boolean fullscreen; // The activity is opaque and fills the entire space of this task.
251 // TODO: See if it possible to combine this with the fullscreen field.
252 final boolean hasWallpaper; // Has a wallpaper window as a background.
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800253 final boolean noDisplay; // activity is not displayed?
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800254 private final boolean componentSpecified; // did caller specify an explicit component?
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700255 final boolean rootVoiceInteraction; // was this the root activity of a voice interaction?
Craig Mautner86d67a42013-05-14 10:34:38 -0700256
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800257 private CharSequence nonLocalizedLabel; // the label information from the package mgr.
258 private int labelRes; // the label information from the package mgr.
259 private int icon; // resource identifier of activity's icon.
260 private int logo; // resource identifier of activity's logo.
261 private int theme; // resource identifier of activity's theme.
262 private int realTheme; // actual theme resource we will use, never 0.
263 private int windowFlags; // custom window flags for preview window.
Bryce Leeaf691c02017-03-20 14:20:22 -0700264 private TaskRecord task; // the task this is in.
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800265 private long createTime = System.currentTimeMillis();
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700266 long displayStartTime; // when we started launching this activity
267 long fullyDrawnStartTime; // when we started launching this activity
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800268 private long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -0800269 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700270 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700271 long pauseTime; // last time we started pausing the activity
272 long launchTickTime; // base time for launch tick messages
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700273 // Last configuration reported to the activity in the client process.
274 private MergedConfiguration mLastReportedConfiguration;
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800275 private int mLastReportedDisplayId;
Winson Chung609e1e92017-05-08 10:52:12 -0700276 private boolean mLastReportedMultiWindowMode;
277 private boolean mLastReportedPictureInPictureMode;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700278 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700279 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 final String resultWho; // additional identifier for use by resultTo.
281 final int requestCode; // code given by requester (resultTo)
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800282 ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800284 ArrayList<ReferrerIntent> newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700285 ActivityOptions pendingOptions; // most recently given options
George Mount6ba042b2014-07-28 11:12:28 -0700286 ActivityOptions returningOptions; // options that are coming back via convertToTranslucent
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700287 AppTimeTracker appTimeTracker; // set if we are tracking the time in this app/task/activity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800288 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700289 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700290 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700291 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 Bundle icicle; // last saved activity state
Craig Mautnera0026042014-04-23 11:45:37 -0700293 PersistableBundle persistentState; // last persistently saved activity state
Wale Ogunwale66e16852017-10-19 13:35:52 -0700294 // TODO: See if this is still needed.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 boolean frontOfTask; // is this the root activity of its task?
296 boolean launchFailed; // set if a launched failed, to abort on 2nd try
297 boolean haveState; // have we gotten the last activity state?
298 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700299 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300 boolean finishing; // activity in pending finish list?
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800301 boolean deferRelaunchUntilPaused; // relaunch of activity is being deferred until pause is
302 // completed
303 boolean preserveWindowOnDeferredRelaunch; // activity windows are preserved on deferred relaunch
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 int configChangeFlags; // which config values have changed
Wale Ogunwaleec950642017-04-25 07:44:21 -0700305 private boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306 int launchMode; // the launch mode activity attribute.
Charles He2bf28322017-10-12 22:24:49 +0100307 int lockTaskLaunchMode; // the lockTaskMode manifest attribute, subject to override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 boolean visible; // does this activity's window need to be shown?
Jorim Jaggi241ae102016-11-02 21:57:33 -0700309 boolean visibleIgnoringKeyguard; // is this activity visible, ignoring the fact that Keyguard
310 // might hide this activity?
Wale Ogunwaleec950642017-04-25 07:44:21 -0700311 private boolean mDeferHidingClient; // If true we told WM to defer reporting to the client
312 // process that it is hidden.
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800313 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 boolean nowVisible; // is this activity's window visible?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 boolean idle; // has the activity gone idle?
316 boolean hasBeenLaunched;// has this activity ever been launched?
317 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400318 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400319 boolean forceNewConfig; // force re-create with new config next time
Winson Chungf7e03e12017-08-22 11:32:16 -0700320 boolean supportsEnterPipOnTaskSwitch; // This flag is set by the system to indicate that the
321 // activity can enter picture in picture while pausing (only when switching to another task)
Winson Chung709904f2017-04-25 11:00:48 -0700322 PictureInPictureParams pictureInPictureArgs = new PictureInPictureParams.Builder().build();
323 // The PiP params used when deferring the entering of picture-in-picture.
Dianne Hackborn07981492013-01-28 11:36:23 -0800324 int launchCount; // count of launches since last state
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800325 long lastLaunchTime; // time of last launch of this activity
Ruben Brunke24b9a62016-02-16 21:38:24 -0800326 ComponentName requestedVrComponent; // the requested component for handling VR mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700328 String stringName; // for caching of toString().
Craig Mautnerde4ef022013-04-07 19:01:33 -0700329
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700330 private boolean inHistory; // are we in the history stack?
Craig Mautnerde4ef022013-04-07 19:01:33 -0700331 final ActivityStackSupervisor mStackSupervisor;
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800332
333 static final int STARTING_WINDOW_NOT_SHOWN = 0;
334 static final int STARTING_WINDOW_SHOWN = 1;
335 static final int STARTING_WINDOW_REMOVED = 2;
336 int mStartingWindowState = STARTING_WINDOW_NOT_SHOWN;
Wale Ogunwale3b232392016-05-13 15:37:13 -0700337 boolean mTaskOverlay = false; // Task is always on-top of other activities in the task.
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800338
Craig Mautner21d24a22014-04-23 11:45:37 -0700339 TaskDescription taskDescription; // the recents information for this activity
Craig Mautnerbb742462014-07-07 15:28:55 -0700340 boolean mLaunchTaskBehind; // this activity is actively being launched with
341 // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed.
Craig Mautner2fbd7542014-03-21 09:34:07 -0700342
Filip Gruszczynski23493322015-07-29 17:02:59 -0700343 // These configurations are collected from application's resources based on size-sensitive
344 // qualifiers. For example, layout-w800dp will be added to mHorizontalSizeConfigurations as 800
345 // and drawable-sw400dp will be added to both as 400.
346 private int[] mVerticalSizeConfigurations;
347 private int[] mHorizontalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700348 private int[] mSmallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700349
Amith Yamasani0af6fa72016-01-17 15:36:19 -0800350 boolean pendingVoiceInteractionStart; // Waiting for activity-invoked voice session
351 IVoiceInteractionSession voiceSession; // Voice interaction session for this activity
352
Robert Carrd2265122016-08-05 10:25:21 -0700353 // A hint to override the window specified rotation animation, or -1
354 // to use the window specified value. We use this so that
355 // we can select the right animation in the cases of starting
356 // windows, where the app hasn't had time to set a value
357 // on the window.
358 int mRotationAnimationHint = -1;
Robert Carrfd10cd12016-06-29 16:41:50 -0700359
chaviw59b98852017-06-13 12:05:44 -0700360 private boolean mShowWhenLocked;
361 private boolean mTurnScreenOn;
362
Andrii Kulian21713ac2016-10-12 22:05:05 -0700363 /**
364 * Temp configs used in {@link #ensureActivityConfigurationLocked(int, boolean)}
365 */
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700366 private final Configuration mTmpConfig = new Configuration();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700367 private final Rect mTmpBounds = new Rect();
Andrii Kulian21713ac2016-10-12 22:05:05 -0700368
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800369 private static String startingWindowStateToString(int state) {
370 switch (state) {
371 case STARTING_WINDOW_NOT_SHOWN:
372 return "STARTING_WINDOW_NOT_SHOWN";
373 case STARTING_WINDOW_SHOWN:
374 return "STARTING_WINDOW_SHOWN";
375 case STARTING_WINDOW_REMOVED:
376 return "STARTING_WINDOW_REMOVED";
377 default:
378 return "unknown state=" + state;
379 }
380 }
381
Bryce Leed946f862018-01-16 15:59:47 -0800382 String getLifecycleDescription(String reason) {
383 return "packageName=" + packageName + ", state=" + state + ", reason=" + reason;
384 }
385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700387 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700388 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
389 pw.print(" processName="); pw.println(processName);
390 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Craig Mautnere11f2b72013-04-01 12:37:17 -0700391 pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800392 pw.print(" userId="); pw.println(userId);
393 pw.print(prefix); pw.print("app="); pw.println(app);
394 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700395 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
396 pw.print(" task="); pw.println(task);
397 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700398 pw.print(prefix); pw.print("realActivity=");
399 pw.println(realActivity.flattenToShortString());
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700400 if (appInfo != null) {
401 pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir);
402 if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) {
403 pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir);
404 }
405 pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir);
Todd Kennedy39bfee52016-02-24 10:28:21 -0800406 if (appInfo.splitSourceDirs != null) {
407 pw.print(prefix); pw.print("splitDir=");
408 pw.println(Arrays.toString(appInfo.splitSourceDirs));
409 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800410 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700411 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
412 pw.print(" componentSpecified="); pw.print(componentSpecified);
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -0700413 pw.print(" mActivityType="); pw.println(
414 activityTypeToString(getActivityType()));
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700415 if (rootVoiceInteraction) {
416 pw.print(prefix); pw.print("rootVoiceInteraction="); pw.println(rootVoiceInteraction);
417 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800418 pw.print(prefix); pw.print("compat="); pw.print(compat);
419 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
420 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
421 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700422 pw.println(prefix + "mLastReportedConfigurations:");
423 mLastReportedConfiguration.dump(pw, prefix + " ");
424
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700425 pw.print(prefix); pw.print("CurrentConfiguration="); pw.println(getConfiguration());
426 if (!getOverrideConfiguration().equals(EMPTY)) {
427 pw.println(prefix + "OverrideConfiguration=" + getOverrideConfiguration());
428 }
Bryce Leef3c6a472017-11-14 14:53:06 -0800429 if (!matchParentBounds()) {
430 pw.println(prefix + "bounds=" + getBounds());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700431 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700432 if (resultTo != null || resultWho != null) {
433 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
434 pw.print(" resultWho="); pw.print(resultWho);
435 pw.print(" resultCode="); pw.println(requestCode);
436 }
Craig Mautner29c58ca2014-10-14 16:17:06 -0700437 if (taskDescription != null) {
438 final String iconFilename = taskDescription.getIconFilename();
439 if (iconFilename != null || taskDescription.getLabel() != null ||
440 taskDescription.getPrimaryColor() != 0) {
441 pw.print(prefix); pw.print("taskDescription:");
Craig Mautner29c58ca2014-10-14 16:17:06 -0700442 pw.print(" label=\""); pw.print(taskDescription.getLabel());
443 pw.print("\"");
Matthew Ng54bc9422017-10-02 17:16:28 -0700444 pw.print(" icon="); pw.print(taskDescription.getInMemoryIcon() != null
445 ? taskDescription.getInMemoryIcon().getByteCount() + " bytes"
446 : "null");
447 pw.print(" iconResource="); pw.print(taskDescription.getIconResource());
448 pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename());
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200449 pw.print(" primaryColor=");
Craig Mautner29c58ca2014-10-14 16:17:06 -0700450 pw.println(Integer.toHexString(taskDescription.getPrimaryColor()));
Wale Ogunwale822e5122017-07-26 06:02:24 -0700451 pw.print(prefix + " backgroundColor=");
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200452 pw.println(Integer.toHexString(taskDescription.getBackgroundColor()));
Wale Ogunwale822e5122017-07-26 06:02:24 -0700453 pw.print(prefix + " statusBarColor=");
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200454 pw.println(Integer.toHexString(taskDescription.getStatusBarColor()));
Wale Ogunwale822e5122017-07-26 06:02:24 -0700455 pw.print(prefix + " navigationBarColor=");
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200456 pw.println(Integer.toHexString(taskDescription.getNavigationBarColor()));
Craig Mautner29c58ca2014-10-14 16:17:06 -0700457 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700458 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700459 if (results != null) {
460 pw.print(prefix); pw.print("results="); pw.println(results);
461 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700462 if (pendingResults != null && pendingResults.size() > 0) {
463 pw.print(prefix); pw.println("Pending Results:");
464 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
465 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
466 pw.print(prefix); pw.print(" - ");
467 if (pir == null) {
468 pw.println("null");
469 } else {
470 pw.println(pir);
471 pir.dump(pw, prefix + " ");
472 }
473 }
474 }
475 if (newIntents != null && newIntents.size() > 0) {
476 pw.print(prefix); pw.println("Pending New Intents:");
477 for (int i=0; i<newIntents.size(); i++) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800478 Intent intent = newIntents.get(i);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700479 pw.print(prefix); pw.print(" - ");
480 if (intent == null) {
481 pw.println("null");
482 } else {
483 pw.println(intent.toShortString(false, true, false, true));
484 }
485 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700486 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700487 if (pendingOptions != null) {
488 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
489 }
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700490 if (appTimeTracker != null) {
491 appTimeTracker.dumpWithHeader(pw, prefix, false);
492 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700493 if (uriPermissions != null) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700494 uriPermissions.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700495 }
496 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800497 pw.print(" launchCount="); pw.print(launchCount);
498 pw.print(" lastLaunchTime=");
499 if (lastLaunchTime == 0) pw.print("0");
500 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
501 pw.println();
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700502 pw.print(prefix); pw.print("haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700503 pw.print(" icicle="); pw.println(icicle);
504 pw.print(prefix); pw.print("state="); pw.print(state);
505 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700506 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700507 pw.print(" finishing="); pw.println(finishing);
508 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
509 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700510 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800511 pw.print(" sleeping="); pw.print(sleeping);
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800512 pw.print(" idle="); pw.print(idle);
513 pw.print(" mStartingWindowState=");
514 pw.println(startingWindowStateToString(mStartingWindowState));
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800515 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
516 pw.print(" noDisplay="); pw.print(noDisplay);
517 pw.print(" immersive="); pw.print(immersive);
518 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800519 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400520 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700521 pw.print(prefix); pw.print("mActivityType=");
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -0700522 pw.println(activityTypeToString(getActivityType()));
Ruben Brunke24b9a62016-02-16 21:38:24 -0800523 if (requestedVrComponent != null) {
524 pw.print(prefix);
525 pw.print("requestedVrComponent=");
526 pw.println(requestedVrComponent);
527 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700528 if (displayStartTime != 0 || startTime != 0) {
529 pw.print(prefix); pw.print("displayStartTime=");
530 if (displayStartTime == 0) pw.print("0");
531 else TimeUtils.formatDuration(displayStartTime, now, pw);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700532 pw.print(" startTime=");
533 if (startTime == 0) pw.print("0");
534 else TimeUtils.formatDuration(startTime, now, pw);
535 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700536 }
Bryce Lee4a194382017-04-04 14:32:48 -0700537 final boolean waitingVisible =
538 mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(this);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800539 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700540 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800541 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700542 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700543 if (lastVisibleTime == 0) pw.print("0");
544 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
545 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700546 }
Wale Ogunwaleec950642017-04-25 07:44:21 -0700547 if (mDeferHidingClient) {
548 pw.println(prefix + "mDeferHidingClient=" + mDeferHidingClient);
549 }
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800550 if (deferRelaunchUntilPaused || configChangeFlags != 0) {
551 pw.print(prefix); pw.print("deferRelaunchUntilPaused="); pw.print(deferRelaunchUntilPaused);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700552 pw.print(" configChangeFlags=");
553 pw.println(Integer.toHexString(configChangeFlags));
554 }
555 if (connections != null) {
556 pw.print(prefix); pw.print("connections="); pw.println(connections);
557 }
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800558 if (info != null) {
559 pw.println(prefix + "resizeMode=" + ActivityInfo.resizeModeToString(info.resizeMode));
Winson Chung609e1e92017-05-08 10:52:12 -0700560 pw.println(prefix + "mLastReportedMultiWindowMode=" + mLastReportedMultiWindowMode
561 + " mLastReportedPictureInPictureMode=" + mLastReportedPictureInPictureMode);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700562 if (info.supportsPictureInPicture()) {
563 pw.println(prefix + "supportsPictureInPicture=" + info.supportsPictureInPicture());
Winson Chungf7e03e12017-08-22 11:32:16 -0700564 pw.println(prefix + "supportsEnterPipOnTaskSwitch: "
565 + supportsEnterPipOnTaskSwitch);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700566 }
567 if (info.maxAspectRatio != 0) {
568 pw.println(prefix + "maxAspectRatio=" + info.maxAspectRatio);
569 }
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800570 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 }
572
Andrii Kulian21713ac2016-10-12 22:05:05 -0700573 private boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700574 return crossesSizeThreshold(mHorizontalSizeConfigurations, firstDp, secondDp);
575 }
576
Andrii Kulian21713ac2016-10-12 22:05:05 -0700577 private boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700578 return crossesSizeThreshold(mVerticalSizeConfigurations, firstDp, secondDp);
579 }
580
Andrii Kulian21713ac2016-10-12 22:05:05 -0700581 private boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700582 return crossesSizeThreshold(mSmallestSizeConfigurations, firstDp, secondDp);
583 }
584
Filip Gruszczynski23493322015-07-29 17:02:59 -0700585 /**
586 * The purpose of this method is to decide whether the activity needs to be relaunched upon
587 * changing its size. In most cases the activities don't need to be relaunched, if the resize
588 * is small, all the activity content has to do is relayout itself within new bounds. There are
589 * cases however, where the activity's content would be completely changed in the new size and
590 * the full relaunch is required.
591 *
592 * The activity will report to us vertical and horizontal thresholds after which a relaunch is
593 * required. These thresholds are collected from the application resource qualifiers. For
594 * example, if application has layout-w600dp resource directory, then it needs a relaunch when
595 * we resize from width of 650dp to 550dp, as it crosses the 600dp threshold. However, if
596 * it resizes width from 620dp to 700dp, it won't be relaunched as it stays on the same side
597 * of the threshold.
598 */
599 private static boolean crossesSizeThreshold(int[] thresholds, int firstDp,
600 int secondDp) {
601 if (thresholds == null) {
602 return false;
603 }
604 for (int i = thresholds.length - 1; i >= 0; i--) {
605 final int threshold = thresholds[i];
606 if ((firstDp < threshold && secondDp >= threshold)
607 || (firstDp >= threshold && secondDp < threshold)) {
608 return true;
609 }
610 }
611 return false;
612 }
613
Andrii Kulian21713ac2016-10-12 22:05:05 -0700614 void setSizeConfigurations(int[] horizontalSizeConfiguration,
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700615 int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700616 mHorizontalSizeConfigurations = horizontalSizeConfiguration;
617 mVerticalSizeConfigurations = verticalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700618 mSmallestSizeConfigurations = smallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700619 }
620
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800621 private void scheduleActivityMovedToDisplay(int displayId, Configuration config) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800622 if (app == null || app.thread == null) {
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800623 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.w(TAG,
624 "Can't report activity moved to display - client not running, activityRecord="
625 + this + ", displayId=" + displayId);
Wale Ogunwale22e25262016-02-01 10:32:02 -0800626 return;
627 }
628 try {
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800629 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
630 "Reporting activity moved to display" + ", activityRecord=" + this
631 + ", displayId=" + displayId + ", config=" + config);
Chong Zhang6be533e2016-06-17 16:24:21 -0700632
Andrii Kulian446e8242017-10-26 15:17:29 -0700633 service.mLifecycleManager.scheduleTransaction(app.thread, appToken,
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -0800634 MoveToDisplayItem.obtain(displayId, config));
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800635 } catch (RemoteException e) {
636 // If process died, whatever.
637 }
638 }
639
640 private void scheduleConfigurationChanged(Configuration config) {
641 if (app == null || app.thread == null) {
642 if (DEBUG_CONFIGURATION) Slog.w(TAG,
643 "Can't report activity configuration update - client not running"
644 + ", activityRecord=" + this);
645 return;
646 }
647 try {
648 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + this + ", config: "
649 + config);
650
Andrii Kulian446e8242017-10-26 15:17:29 -0700651 service.mLifecycleManager.scheduleTransaction(app.thread, appToken,
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -0800652 ActivityConfigurationChangeItem.obtain(config));
Wale Ogunwale22e25262016-02-01 10:32:02 -0800653 } catch (RemoteException e) {
654 // If process died, whatever.
655 }
656 }
657
Winson Chung5af42fc2017-03-24 17:11:33 -0700658 void updateMultiWindowMode() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700659 if (task == null || task.getStack() == null || app == null || app.thread == null) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800660 return;
661 }
Winson Chung5af42fc2017-03-24 17:11:33 -0700662
Wale Ogunwaleeb76b762017-11-17 10:08:04 -0800663 if (task.getStack().deferScheduleMultiWindowModeChanged()) {
664 // Don't do anything if we are currently deferring multi-window mode change.
665 return;
666 }
667
Winson Chung5af42fc2017-03-24 17:11:33 -0700668 // An activity is considered to be in multi-window mode if its task isn't fullscreen.
Wale Ogunwaleeb76b762017-11-17 10:08:04 -0800669 final boolean inMultiWindowMode = inMultiWindowMode();
Winson Chung609e1e92017-05-08 10:52:12 -0700670 if (inMultiWindowMode != mLastReportedMultiWindowMode) {
671 mLastReportedMultiWindowMode = inMultiWindowMode;
Winson Chung5af42fc2017-03-24 17:11:33 -0700672 scheduleMultiWindowModeChanged(getConfiguration());
673 }
674 }
675
676 private void scheduleMultiWindowModeChanged(Configuration overrideConfig) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800677 try {
Andrii Kulian446e8242017-10-26 15:17:29 -0700678 service.mLifecycleManager.scheduleTransaction(app.thread, appToken,
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -0800679 MultiWindowModeChangeItem.obtain(mLastReportedMultiWindowMode,
Andrii Kulian446e8242017-10-26 15:17:29 -0700680 overrideConfig));
Wale Ogunwale22e25262016-02-01 10:32:02 -0800681 } catch (Exception e) {
682 // If process died, I don't care.
683 }
684 }
685
Winson Chungab76bbc2017-08-14 13:33:51 -0700686 void updatePictureInPictureMode(Rect targetStackBounds, boolean forceUpdate) {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700687 if (task == null || task.getStack() == null || app == null || app.thread == null) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800688 return;
689 }
Winson Chung5af42fc2017-03-24 17:11:33 -0700690
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700691 final boolean inPictureInPictureMode = inPinnedWindowingMode() && targetStackBounds != null;
Winson Chungab76bbc2017-08-14 13:33:51 -0700692 if (inPictureInPictureMode != mLastReportedPictureInPictureMode || forceUpdate) {
Winson Chung5af42fc2017-03-24 17:11:33 -0700693 // Picture-in-picture mode changes also trigger a multi-window mode change as well, so
694 // update that here in order
Winson Chung609e1e92017-05-08 10:52:12 -0700695 mLastReportedPictureInPictureMode = inPictureInPictureMode;
Wale Ogunwaleeb76b762017-11-17 10:08:04 -0800696 mLastReportedMultiWindowMode = inMultiWindowMode();
Winson Chung5af42fc2017-03-24 17:11:33 -0700697 final Configuration newConfig = task.computeNewOverrideConfigurationForBounds(
698 targetStackBounds, null);
699 schedulePictureInPictureModeChanged(newConfig);
700 scheduleMultiWindowModeChanged(newConfig);
701 }
702 }
703
704 private void schedulePictureInPictureModeChanged(Configuration overrideConfig) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800705 try {
Andrii Kulian446e8242017-10-26 15:17:29 -0700706 service.mLifecycleManager.scheduleTransaction(app.thread, appToken,
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -0800707 PipModeChangeItem.obtain(mLastReportedPictureInPictureMode,
Andrii Kulian446e8242017-10-26 15:17:29 -0700708 overrideConfig));
Wale Ogunwale22e25262016-02-01 10:32:02 -0800709 } catch (Exception e) {
710 // If process died, no one cares.
Filip Gruszczynskica664812015-12-04 12:43:36 -0800711 }
712 }
713
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700714 @Override
715 protected int getChildCount() {
716 // {@link ActivityRecord} is a leaf node and has no children.
717 return 0;
718 }
719
720 @Override
721 protected ConfigurationContainer getChildAt(int index) {
722 return null;
723 }
724
725 @Override
726 protected ConfigurationContainer getParent() {
Bryce Leeaf691c02017-03-20 14:20:22 -0700727 return getTask();
728 }
729
730 TaskRecord getTask() {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700731 return task;
732 }
733
Bryce Leeaf691c02017-03-20 14:20:22 -0700734 /**
735 * Sets reference to the {@link TaskRecord} the {@link ActivityRecord} will treat as its parent.
736 * Note that this does not actually add the {@link ActivityRecord} as a {@link TaskRecord}
737 * children. However, this method will clean up references to this {@link ActivityRecord} in
738 * {@link ActivityStack}.
739 * @param task The new parent {@link TaskRecord}.
740 */
741 void setTask(TaskRecord task) {
742 setTask(task, false /*reparenting*/);
743 }
744
745 /**
746 * This method should only be called by {@link TaskRecord#removeActivity(ActivityRecord)}.
747 */
748 void setTask(TaskRecord task, boolean reparenting) {
749 // Do nothing if the {@link TaskRecord} is the same as the current {@link getTask}.
750 if (task != null && task == getTask()) {
751 return;
752 }
753
754 final ActivityStack stack = getStack();
755
756 // If the new {@link TaskRecord} is from a different {@link ActivityStack}, remove this
757 // {@link ActivityRecord} from its current {@link ActivityStack}.
758 if (!reparenting && stack != null && (task == null || stack != task.getStack())) {
759 stack.onActivityRemovedFromStack(this);
760 }
761
762 this.task = task;
763
764 if (!reparenting) {
765 onParentChanged();
766 }
767 }
768
Dianne Hackbornbe707852011-11-11 14:32:10 -0800769 static class Token extends IApplicationToken.Stub {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700770 private final WeakReference<ActivityRecord> weakActivity;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700771 private final String name;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800772
Steven Timotiusaf03df62017-07-18 16:56:43 -0700773 Token(ActivityRecord activity, Intent intent) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800774 weakActivity = new WeakReference<>(activity);
Steven Timotiusaf03df62017-07-18 16:56:43 -0700775 name = intent.getComponent().flattenToShortString();
Wale Ogunwale7d701172015-03-11 15:36:30 -0700776 }
777
Andrii Kulian21713ac2016-10-12 22:05:05 -0700778 private static ActivityRecord tokenToActivityRecordLocked(Token token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700779 if (token == null) {
780 return null;
781 }
782 ActivityRecord r = token.weakActivity.get();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700783 if (r == null || r.getStack() == null) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700784 return null;
785 }
786 return r;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800787 }
788
Craig Mautnerde4ef022013-04-07 19:01:33 -0700789 @Override
Dianne Hackbornbe707852011-11-11 14:32:10 -0800790 public String toString() {
791 StringBuilder sb = new StringBuilder(128);
792 sb.append("Token{");
793 sb.append(Integer.toHexString(System.identityHashCode(this)));
794 sb.append(' ');
795 sb.append(weakActivity.get());
796 sb.append('}');
797 return sb.toString();
798 }
Steven Timotiusaf03df62017-07-18 16:56:43 -0700799
800 @Override
801 public String getName() {
802 return name;
803 }
Dianne Hackbornbe707852011-11-11 14:32:10 -0800804 }
805
Wale Ogunwale7d701172015-03-11 15:36:30 -0700806 static ActivityRecord forTokenLocked(IBinder token) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800807 try {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700808 return Token.tokenToActivityRecordLocked((Token)token);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800809 } catch (ClassCastException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800810 Slog.w(TAG, "Bad activity token: " + token, e);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800811 return null;
812 }
813 }
814
Chong Zhang85ee6542015-10-02 13:36:38 -0700815 boolean isResolverActivity() {
816 return ResolverActivity.class.getName().equals(realActivity.getClassName());
Craig Mautnerac6f8432013-07-17 13:24:59 -0700817 }
818
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800819 ActivityRecord(ActivityManagerService _service, ProcessRecord _caller, int _launchedFromPid,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800820 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700822 ActivityRecord _resultTo, String _resultWho, int _reqCode,
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700823 boolean _componentSpecified, boolean _rootVoiceInteraction,
Andrii Kulian94e82d9b02017-07-13 15:33:06 -0700824 ActivityStackSupervisor supervisor, ActivityOptions options,
825 ActivityRecord sourceRecord) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826 service = _service;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700827 appToken = new Token(this, _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 info = aInfo;
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800829 launchedFromPid = _launchedFromPid;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800831 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700832 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 intent = _intent;
834 shortComponentName = _intent.getComponent().flattenToShortString();
835 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800836 componentSpecified = _componentSpecified;
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700837 rootVoiceInteraction = _rootVoiceInteraction;
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700838 mLastReportedConfiguration = new MergedConfiguration(_configuration);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 resultTo = _resultTo;
840 resultWho = _resultWho;
841 requestCode = _reqCode;
Ruben Brunkf53497c2017-03-27 20:26:17 -0700842 state = INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843 frontOfTask = false;
844 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800845 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700846 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800847 finishing = false;
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800848 deferRelaunchUntilPaused = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 keysPaused = false;
850 inHistory = false;
Chong Zhanga48ef662015-08-18 19:21:47 -0700851 visible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 nowVisible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853 idle = false;
854 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700855 mStackSupervisor = supervisor;
Robert Carr0f5d7532016-10-17 16:39:17 -0700856
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800857 // This starts out true, since the initial state of an activity is that we have everything,
858 // and we shouldn't never consider it lacking in state to be removed if it dies.
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700859 haveState = true;
860
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800861 // If the class name in the intent doesn't match that of the target, this is
862 // probably an alias. We have to create a new ComponentName object to keep track
863 // of the real activity name, so that FLAG_ACTIVITY_CLEAR_TOP is handled properly.
864 if (aInfo.targetActivity == null
865 || (aInfo.targetActivity.equals(_intent.getComponent().getClassName())
866 && (aInfo.launchMode == LAUNCH_MULTIPLE
867 || aInfo.launchMode == LAUNCH_SINGLE_TOP))) {
868 realActivity = _intent.getComponent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 } else {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800870 realActivity = new ComponentName(aInfo.packageName, aInfo.targetActivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800871 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800872 taskAffinity = aInfo.taskAffinity;
873 stateNotNeeded = (aInfo.flags & FLAG_STATE_NOT_NEEDED) != 0;
874 appInfo = aInfo.applicationInfo;
875 nonLocalizedLabel = aInfo.nonLocalizedLabel;
876 labelRes = aInfo.labelRes;
877 if (nonLocalizedLabel == null && labelRes == 0) {
878 ApplicationInfo app = aInfo.applicationInfo;
879 nonLocalizedLabel = app.nonLocalizedLabel;
880 labelRes = app.labelRes;
881 }
882 icon = aInfo.getIconResource();
883 logo = aInfo.getLogoResource();
884 theme = aInfo.getThemeResource();
885 realTheme = theme;
886 if (realTheme == 0) {
887 realTheme = aInfo.applicationInfo.targetSdkVersion < HONEYCOMB
888 ? android.R.style.Theme : android.R.style.Theme_Holo;
889 }
890 if ((aInfo.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
891 windowFlags |= LayoutParams.FLAG_HARDWARE_ACCELERATED;
892 }
893 if ((aInfo.flags & FLAG_MULTIPROCESS) != 0 && _caller != null
894 && (aInfo.applicationInfo.uid == SYSTEM_UID
895 || aInfo.applicationInfo.uid == _caller.info.uid)) {
896 processName = _caller.processName;
897 } else {
898 processName = aInfo.processName;
899 }
900
901 if ((aInfo.flags & FLAG_EXCLUDE_FROM_RECENTS) != 0) {
902 intent.addFlags(FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
903 }
904
905 packageName = aInfo.applicationInfo.packageName;
906 launchMode = aInfo.launchMode;
907
Ruben Brunkf53497c2017-03-27 20:26:17 -0700908 Entry ent = AttributeCache.instance().get(packageName,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800909 realTheme, com.android.internal.R.styleable.Window, userId);
Bryce Leee83f34cd2017-10-31 19:50:54 -0700910
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -0700911 if (ent != null) {
912 fullscreen = !ActivityInfo.isTranslucentOrFloating(ent.array);
913 hasWallpaper = ent.array.getBoolean(R.styleable.Window_windowShowWallpaper, false);
914 noDisplay = ent.array.getBoolean(R.styleable.Window_windowNoDisplay, false);
915 } else {
916 hasWallpaper = false;
917 noDisplay = false;
918 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800919
Winson Chung83471632016-12-13 11:02:12 -0800920 setActivityType(_componentSpecified, _launchedFromUid, _intent, options, sourceRecord);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800921
922 immersive = (aInfo.flags & FLAG_IMMERSIVE) != 0;
923
924 requestedVrComponent = (aInfo.requestedVrComponent == null) ?
925 null : ComponentName.unflattenFromString(aInfo.requestedVrComponent);
chaviw59b98852017-06-13 12:05:44 -0700926
927 mShowWhenLocked = (aInfo.flags & FLAG_SHOW_WHEN_LOCKED) != 0;
928 mTurnScreenOn = (aInfo.flags & FLAG_TURN_SCREEN_ON) != 0;
Charles He2bf28322017-10-12 22:24:49 +0100929
930 mRotationAnimationHint = aInfo.rotationAnimation;
931 lockTaskLaunchMode = aInfo.lockTaskLaunchMode;
932 if (appInfo.isPrivilegedApp() && (lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_ALWAYS
933 || lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_NEVER)) {
934 lockTaskLaunchMode = LOCK_TASK_LAUNCH_MODE_DEFAULT;
935 }
936
937 if (options != null) {
938 pendingOptions = options;
939 mLaunchTaskBehind = options.getLaunchTaskBehind();
940
941 final int rotationAnimation = pendingOptions.getRotationAnimationHint();
942 // Only override manifest supplied option if set.
943 if (rotationAnimation >= 0) {
944 mRotationAnimationHint = rotationAnimation;
945 }
946 final PendingIntent usageReport = pendingOptions.getUsageTimeReport();
947 if (usageReport != null) {
948 appTimeTracker = new AppTimeTracker(usageReport);
949 }
950 final boolean useLockTask = pendingOptions.getLockTaskMode();
951 if (useLockTask && lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_DEFAULT) {
952 lockTaskLaunchMode = LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
953 }
954 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800955 }
956
Dianne Hackborn68a06332017-11-15 17:54:18 -0800957 void setProcess(ProcessRecord proc) {
958 app = proc;
959 final ActivityRecord root = task != null ? task.getRootActivity() : null;
960 if (root == this) {
961 task.setRootProcess(proc);
962 }
963 }
964
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800965 AppWindowContainerController getWindowContainerController() {
966 return mWindowContainerController;
967 }
968
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800969 void createWindowContainer() {
970 if (mWindowContainerController != null) {
971 throw new IllegalArgumentException("Window container=" + mWindowContainerController
972 + " already created for r=" + this);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800973 }
974
975 inHistory = true;
976
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800977 final TaskWindowContainerController taskController = task.getWindowContainerController();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800978
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700979 // TODO(b/36505427): Maybe this call should be moved inside updateOverrideConfiguration()
980 task.updateOverrideConfigurationFromLaunchBounds();
981 // Make sure override configuration is up-to-date before using to create window controller.
982 updateOverrideConfiguration();
983
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800984 mWindowContainerController = new AppWindowContainerController(taskController, appToken,
985 this, Integer.MAX_VALUE /* add on top */, info.screenOrientation, fullscreen,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800986 (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, info.configChanges,
987 task.voiceSession != null, mLaunchTaskBehind, isAlwaysFocusable(),
988 appInfo.targetSdkVersion, mRotationAnimationHint,
Bryce Leef3c6a472017-11-14 14:53:06 -0800989 ActivityManagerService.getInputDispatchingTimeoutLocked(this) * 1000000L);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800990
991 task.addActivityToTop(this);
992
Winson Chung609e1e92017-05-08 10:52:12 -0700993 // When an activity is started directly into a split-screen fullscreen stack, we need to
994 // update the initial multi-window modes so that the callbacks are scheduled correctly when
995 // the user leaves that mode.
Bryce Leef3c6a472017-11-14 14:53:06 -0800996 mLastReportedMultiWindowMode = inMultiWindowMode();
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700997 mLastReportedPictureInPictureMode = inPinnedWindowingMode();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800998 }
999
1000 void removeWindowContainer() {
Wale Ogunwalecc367f42017-02-01 08:12:14 -08001001 // Resume key dispatching if it is currently paused before we remove the container.
1002 resumeKeyDispatchingLocked();
1003
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001004 mWindowContainerController.removeContainer(getDisplayId());
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -08001005 mWindowContainerController = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 }
1007
Winson Chung30480042017-01-26 10:55:34 -08001008 /**
1009 * Reparents this activity into {@param newTask} at the provided {@param position}. The caller
1010 * should ensure that the {@param newTask} is not already the parent of this activity.
1011 */
1012 void reparent(TaskRecord newTask, int position, String reason) {
1013 final TaskRecord prevTask = task;
1014 if (prevTask == newTask) {
1015 throw new IllegalArgumentException(reason + ": task=" + newTask
1016 + " is already the parent of r=" + this);
1017 }
1018
Winson Chung74666102017-02-22 17:49:24 -08001019 // TODO: Ensure that we do not directly reparent activities across stacks, as that may leave
1020 // the stacks in strange states. For now, we should use Task.reparent() to ensure that
1021 // the stack is left in an OK state.
1022 if (prevTask != null && newTask != null && prevTask.getStack() != newTask.getStack()) {
1023 throw new IllegalArgumentException(reason + ": task=" + newTask
1024 + " is in a different stack (" + newTask.getStackId() + ") than the parent of"
1025 + " r=" + this + " (" + prevTask.getStackId() + ")");
1026 }
1027
Winson Chung30480042017-01-26 10:55:34 -08001028 // Must reparent first in window manager
1029 mWindowContainerController.reparent(newTask.getWindowContainerController(), position);
1030
Bryce Leeaf691c02017-03-20 14:20:22 -07001031 // Remove the activity from the old task and add it to the new task.
1032 prevTask.removeActivity(this, true /*reparenting*/);
Bryce Lee0f9bde82017-02-22 16:39:06 -08001033
Winson Chung30480042017-01-26 10:55:34 -08001034 newTask.addActivityAtIndex(position, this);
1035 }
1036
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001037 private boolean isHomeIntent(Intent intent) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001038 return ACTION_MAIN.equals(intent.getAction())
1039 && intent.hasCategory(CATEGORY_HOME)
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001040 && intent.getCategories().size() == 1
1041 && intent.getData() == null
1042 && intent.getType() == null;
1043 }
1044
Chong Zhangad24f962016-08-25 12:12:33 -07001045 static boolean isMainIntent(Intent intent) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001046 return ACTION_MAIN.equals(intent.getAction())
1047 && intent.hasCategory(CATEGORY_LAUNCHER)
Chong Zhangad24f962016-08-25 12:12:33 -07001048 && intent.getCategories().size() == 1
1049 && intent.getData() == null
1050 && intent.getType() == null;
1051 }
1052
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001053 private boolean canLaunchHomeActivity(int uid, ActivityRecord sourceRecord) {
1054 if (uid == Process.myUid() || uid == 0) {
1055 // System process can launch home activity.
1056 return true;
1057 }
1058 // Resolver activity can launch home activity.
1059 return sourceRecord != null && sourceRecord.isResolverActivity();
1060 }
1061
Winson Chung83471632016-12-13 11:02:12 -08001062 /**
1063 * @return whether the given package name can launch an assist activity.
1064 */
1065 private boolean canLaunchAssistActivity(String packageName) {
Winson Chungbccd4b52017-12-13 11:08:39 -08001066 final ComponentName assistComponent = service.mActiveVoiceInteractionServiceComponent;
Winson Chung83471632016-12-13 11:02:12 -08001067 if (assistComponent != null) {
1068 return assistComponent.getPackageName().equals(packageName);
1069 }
1070 return false;
1071 }
1072
1073 private void setActivityType(boolean componentSpecified, int launchedFromUid, Intent intent,
1074 ActivityOptions options, ActivityRecord sourceRecord) {
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001075 int activityType = ACTIVITY_TYPE_UNDEFINED;
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001076 if ((!componentSpecified || canLaunchHomeActivity(launchedFromUid, sourceRecord))
1077 && isHomeIntent(intent) && !isResolverActivity()) {
1078 // This sure looks like a home activity!
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001079 activityType = ACTIVITY_TYPE_HOME;
Wale Ogunwaledf241e92016-10-13 15:14:21 -07001080
1081 if (info.resizeMode == RESIZE_MODE_FORCE_RESIZEABLE
1082 || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) {
1083 // We only allow home activities to be resizeable if they explicitly requested it.
1084 info.resizeMode = RESIZE_MODE_UNRESIZEABLE;
1085 }
Winson Chung16e185e2017-11-07 08:30:54 -08001086 } else if (realActivity.getClassName().contains(LEGACY_RECENTS_PACKAGE_NAME) ||
1087 service.getRecentTasks().isRecentsComponent(realActivity, appInfo.uid)) {
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001088 activityType = ACTIVITY_TYPE_RECENTS;
Wale Ogunwale0568aed2017-09-08 13:29:37 -07001089 } else if (options != null && options.getLaunchActivityType() == ACTIVITY_TYPE_ASSISTANT
Winson Chung83471632016-12-13 11:02:12 -08001090 && canLaunchAssistActivity(launchedFromPackage)) {
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001091 activityType = ACTIVITY_TYPE_ASSISTANT;
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001092 }
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001093 setActivityType(activityType);
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001094 }
1095
Craig Mautnera228ae92014-07-09 05:44:55 -07001096 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001097 if (launchMode != LAUNCH_SINGLE_INSTANCE && launchMode != LAUNCH_SINGLE_TASK) {
Craig Mautnera228ae92014-07-09 05:44:55 -07001098 task.setTaskToAffiliateWith(taskToAffiliateWith);
1099 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001100 }
1101
Andrii Kulian02b7a832016-10-06 23:11:56 -07001102 /**
1103 * @return Stack value from current task, null if there is no task.
1104 */
Winson Chung55893332017-02-17 17:13:10 -08001105 <T extends ActivityStack> T getStack() {
1106 return task != null ? (T) task.getStack() : null;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001107 }
1108
Jorim Jaggicdfc04e2017-04-28 19:06:24 +02001109 int getStackId() {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001110 return getStack() != null ? getStack().mStackId : INVALID_STACK_ID;
1111 }
1112
Wale Ogunwale04a05ac2017-09-17 21:35:02 -07001113 ActivityDisplay getDisplay() {
1114 final ActivityStack stack = getStack();
1115 return stack != null ? stack.getDisplay() : null;
1116 }
1117
Craig Mautner5eda9b32013-07-02 11:58:16 -07001118 boolean changeWindowTranslucency(boolean toOpaque) {
1119 if (fullscreen == toOpaque) {
1120 return false;
1121 }
Craig Mautner4addfc52013-06-25 08:05:45 -07001122
Craig Mautner5eda9b32013-07-02 11:58:16 -07001123 // Keep track of the number of fullscreen activities in this task.
1124 task.numFullscreen += toOpaque ? +1 : -1;
1125
1126 fullscreen = toOpaque;
1127 return true;
Craig Mautner4addfc52013-06-25 08:05:45 -07001128 }
1129
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001130 void takeFromHistory() {
1131 if (inHistory) {
1132 inHistory = false;
1133 if (task != null && !finishing) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001134 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001135 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -07001136 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001137 }
1138 }
1139
1140 boolean isInHistory() {
1141 return inHistory;
1142 }
1143
Wale Ogunwale7d701172015-03-11 15:36:30 -07001144 boolean isInStackLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001145 final ActivityStack stack = getStack();
1146 return stack != null && stack.isInStackLocked(this) != null;
Wale Ogunwale7d701172015-03-11 15:36:30 -07001147 }
1148
Craig Mautner21d24a22014-04-23 11:45:37 -07001149 boolean isPersistable() {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001150 return (info.persistableMode == PERSIST_ROOT_ONLY ||
1151 info.persistableMode == PERSIST_ACROSS_REBOOTS) &&
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001152 (intent == null || (intent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
Craig Mautner21d24a22014-04-23 11:45:37 -07001153 }
1154
Wale Ogunwale4cea0f52015-12-25 06:30:31 -08001155 boolean isFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001156 return getWindowConfiguration().canReceiveKeys() || isAlwaysFocusable();
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001157 }
1158
1159 boolean isResizeable() {
Winson Chungd3395382016-12-13 11:49:09 -08001160 return ActivityInfo.isResizeableMode(info.resizeMode) || info.supportsPictureInPicture();
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001161 }
1162
Winson Chungd3395382016-12-13 11:49:09 -08001163 /**
1164 * @return whether this activity is non-resizeable or forced to be resizeable
1165 */
1166 boolean isNonResizableOrForcedResizable() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -07001167 return info.resizeMode != RESIZE_MODE_RESIZEABLE
Wale Ogunwale72a73e32016-10-13 12:16:39 -07001168 && info.resizeMode != RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Jorim Jaggicd13d332016-04-27 15:40:20 -07001169 }
1170
Winson Chunge6308042016-10-31 09:24:01 -07001171 /**
Winson Chungd3395382016-12-13 11:49:09 -08001172 * @return whether this activity supports PiP multi-window and can be put in the pinned stack.
Winson Chunge6308042016-10-31 09:24:01 -07001173 */
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001174 boolean supportsPictureInPicture() {
Wale Ogunwale034a8ec2017-09-02 17:14:40 -07001175 return service.mSupportsPictureInPicture && isActivityTypeStandardOrUndefined()
Winson Chungd3395382016-12-13 11:49:09 -08001176 && info.supportsPictureInPicture();
1177 }
1178
1179 /**
1180 * @return whether this activity supports split-screen multi-window and can be put in the docked
1181 * stack.
1182 */
Wale Ogunwale04a05ac2017-09-17 21:35:02 -07001183 @Override
1184 public boolean supportsSplitScreenWindowingMode() {
Winson Chungd3395382016-12-13 11:49:09 -08001185 // An activity can not be docked even if it is considered resizeable because it only
1186 // supports picture-in-picture mode but has a non-resizeable resizeMode
Wale Ogunwale04a05ac2017-09-17 21:35:02 -07001187 return super.supportsSplitScreenWindowingMode()
1188 && service.mSupportsSplitScreenMultiWindow && supportsResizeableMultiWindow();
Winson Chungd3395382016-12-13 11:49:09 -08001189 }
1190
1191 /**
1192 * @return whether this activity supports freeform multi-window and can be put in the freeform
1193 * stack.
1194 */
1195 boolean supportsFreeform() {
1196 return service.mSupportsFreeformWindowManagement && supportsResizeableMultiWindow();
1197 }
1198
1199 /**
1200 * @return whether this activity supports non-PiP multi-window.
1201 */
1202 private boolean supportsResizeableMultiWindow() {
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001203 return service.mSupportsMultiWindow && !isActivityTypeHome()
Winson Chungd3395382016-12-13 11:49:09 -08001204 && (ActivityInfo.isResizeableMode(info.resizeMode)
1205 || service.mForceResizableActivities);
Wale Ogunwaled26176f2016-01-25 20:04:04 -08001206 }
1207
Winson Chunge6308042016-10-31 09:24:01 -07001208 /**
Andrii Kulian036e3ad2017-04-19 10:55:10 -07001209 * Check whether this activity can be launched on the specified display.
1210 * @param displayId Target display id.
1211 * @return {@code true} if either it is the default display or this activity is resizeable and
1212 * can be put a secondary screen.
1213 */
1214 boolean canBeLaunchedOnDisplay(int displayId) {
Bryce Lee1533b2b2017-09-14 17:06:41 -07001215 final TaskRecord task = getTask();
1216
1217 // The resizeability of an Activity's parent task takes precendence over the ActivityInfo.
1218 // This allows for a non resizable activity to be launched into a resizeable task.
1219 final boolean resizeable =
1220 task != null ? task.isResizeable() : supportsResizeableMultiWindow();
1221
Andrii Kulian036e3ad2017-04-19 10:55:10 -07001222 return service.mStackSupervisor.canPlaceEntityOnDisplay(displayId,
Bryce Lee1533b2b2017-09-14 17:06:41 -07001223 resizeable, launchedFromPid, launchedFromUid, info);
Andrii Kulian036e3ad2017-04-19 10:55:10 -07001224 }
1225
1226 /**
Robert Carrc33658e2017-04-11 18:24:20 -07001227 * @param beforeStopping Whether this check is for an auto-enter-pip operation, that is to say
1228 * the activity has requested to enter PiP when it would otherwise be stopped.
1229 *
Winson Chung298f95b2017-08-10 15:57:18 -07001230 * @return whether this activity is currently allowed to enter PIP.
Winson Chunge6308042016-10-31 09:24:01 -07001231 */
Winson Chung298f95b2017-08-10 15:57:18 -07001232 boolean checkEnterPictureInPictureState(String caller, boolean beforeStopping) {
Wale Ogunwaleb9a0c992017-04-18 07:25:20 -07001233 if (!supportsPictureInPicture()) {
1234 return false;
1235 }
1236
Winson Chungf4ac0632017-03-17 12:34:12 -07001237 // Check app-ops and see if PiP is supported for this package
1238 if (!checkEnterPictureInPictureAppOpsState()) {
1239 return false;
1240 }
1241
Winson Chungf1bfee12017-03-24 17:11:33 -07001242 // Check to see if we are in VR mode, and disallow PiP if so
1243 if (service.shouldDisableNonVrUiLocked()) {
1244 return false;
1245 }
1246
Winson Chungc2baac02017-01-11 13:34:47 -08001247 boolean isKeyguardLocked = service.isKeyguardLocked();
Benjamin Franza83859f2017-07-03 16:34:14 +01001248 boolean isCurrentAppLocked = service.getLockTaskModeState() != LOCK_TASK_MODE_NONE;
Wale Ogunwale04a05ac2017-09-17 21:35:02 -07001249 final ActivityDisplay display = getDisplay();
1250 boolean hasPinnedStack = display != null && display.hasPinnedStack();
Winson Chungbb348802017-01-30 12:01:45 -08001251 // Don't return early if !isNotLocked, since we want to throw an exception if the activity
1252 // is in an incorrect state
Winson Chunge581ebf2017-02-21 08:25:03 -08001253 boolean isNotLockedOrOnKeyguard = !isKeyguardLocked && !isCurrentAppLocked;
Robert Carrc33658e2017-04-11 18:24:20 -07001254
1255 // We don't allow auto-PiP when something else is already pipped.
1256 if (beforeStopping && hasPinnedStack) {
1257 return false;
1258 }
1259
Winson Chungc2baac02017-01-11 13:34:47 -08001260 switch (state) {
1261 case RESUMED:
Winson Chunge581ebf2017-02-21 08:25:03 -08001262 // When visible, allow entering PiP if the app is not locked. If it is over the
1263 // keyguard, then we will prompt to unlock in the caller before entering PiP.
Robert Carrc33658e2017-04-11 18:24:20 -07001264 return !isCurrentAppLocked &&
Winson Chungf7e03e12017-08-22 11:32:16 -07001265 (supportsEnterPipOnTaskSwitch || !beforeStopping);
Winson Chungc2baac02017-01-11 13:34:47 -08001266 case PAUSING:
1267 case PAUSED:
Winson Chungbb348802017-01-30 12:01:45 -08001268 // When pausing, then only allow enter PiP as in the resume state, and in addition,
1269 // require that there is not an existing PiP activity and that the current system
1270 // state supports entering PiP
Winson Chunge581ebf2017-02-21 08:25:03 -08001271 return isNotLockedOrOnKeyguard && !hasPinnedStack
Winson Chungf7e03e12017-08-22 11:32:16 -07001272 && supportsEnterPipOnTaskSwitch;
Winson Chungc2baac02017-01-11 13:34:47 -08001273 case STOPPING:
1274 // When stopping in a valid state, then only allow enter PiP as in the pause state.
1275 // Otherwise, fall through to throw an exception if the caller is trying to enter
1276 // PiP in an invalid stopping state.
Winson Chungf7e03e12017-08-22 11:32:16 -07001277 if (supportsEnterPipOnTaskSwitch) {
Winson Chungf4ac0632017-03-17 12:34:12 -07001278 return isNotLockedOrOnKeyguard && !hasPinnedStack;
Winson Chungc2baac02017-01-11 13:34:47 -08001279 }
1280 default:
Winson Chung298f95b2017-08-10 15:57:18 -07001281 return false;
Winson Chungb5c41b72016-12-07 15:00:47 -08001282 }
Winson Chunge6308042016-10-31 09:24:01 -07001283 }
1284
Winson Chung59fda9e2017-01-20 16:14:51 -08001285 /**
Winson Chungf4ac0632017-03-17 12:34:12 -07001286 * @return Whether AppOps allows this package to enter picture-in-picture.
Winson Chung59fda9e2017-01-20 16:14:51 -08001287 */
Winson Chungf4ac0632017-03-17 12:34:12 -07001288 private boolean checkEnterPictureInPictureAppOpsState() {
Winson Chung59fda9e2017-01-20 16:14:51 -08001289 try {
Winson Chungf4ac0632017-03-17 12:34:12 -07001290 return service.getAppOpsService().checkOperation(OP_PICTURE_IN_PICTURE,
Winson Chung59fda9e2017-01-20 16:14:51 -08001291 appInfo.uid, packageName) == MODE_ALLOWED;
1292 } catch (RemoteException e) {
1293 // Local call
1294 }
1295 return false;
1296 }
1297
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001298 boolean isAlwaysFocusable() {
1299 return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0;
Wale Ogunwale4cea0f52015-12-25 06:30:31 -08001300 }
1301
Jorim Jaggife762342016-10-13 14:33:27 +02001302
1303 /**
1304 * @return true if the activity contains windows that have
1305 * {@link LayoutParams#FLAG_DISMISS_KEYGUARD} set
1306 */
1307 boolean hasDismissKeyguardWindows() {
1308 return service.mWindowManager.containsDismissKeyguardWindow(appToken);
1309 }
1310
Wale Ogunwale7d701172015-03-11 15:36:30 -07001311 void makeFinishingLocked() {
Wale Ogunwalec981ad52017-06-13 11:40:06 -07001312 if (finishing) {
1313 return;
1314 }
1315 finishing = true;
1316 if (stopped) {
1317 clearOptionsLocked();
1318 }
Yorke Leebd54c2a2016-10-25 13:49:23 -07001319
Wale Ogunwalec981ad52017-06-13 11:40:06 -07001320 if (service != null) {
1321 service.mTaskChangeNotificationController.notifyTaskStackChanged();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08001322 }
1323 }
1324
Dianne Hackborn7e269642010-08-25 19:50:20 -07001325 UriPermissionOwner getUriPermissionsLocked() {
1326 if (uriPermissions == null) {
1327 uriPermissions = new UriPermissionOwner(service, this);
1328 }
1329 return uriPermissions;
1330 }
1331
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001332 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333 int requestCode, int resultCode,
1334 Intent resultData) {
1335 ActivityResult r = new ActivityResult(from, resultWho,
John Spurlock8a985d22014-02-25 09:40:05 -05001336 requestCode, resultCode, resultData);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001338 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001339 }
1340 results.add(r);
1341 }
1342
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001343 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001344 int requestCode) {
1345 if (results != null) {
1346 for (int i=results.size()-1; i>=0; i--) {
1347 ActivityResult r = (ActivityResult)results.get(i);
1348 if (r.mFrom != from) continue;
1349 if (r.mResultWho == null) {
1350 if (resultWho != null) continue;
1351 } else {
1352 if (!r.mResultWho.equals(resultWho)) continue;
1353 }
1354 if (r.mRequestCode != requestCode) continue;
1355
1356 results.remove(i);
1357 }
1358 }
1359 }
1360
Andrii Kulian21713ac2016-10-12 22:05:05 -07001361 private void addNewIntentLocked(ReferrerIntent intent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001362 if (newIntents == null) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001363 newIntents = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001364 }
1365 newIntents.add(intent);
1366 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001367
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001368 /**
1369 * Deliver a new Intent to an existing activity, so that its onNewIntent()
1370 * method will be called at the proper time.
1371 */
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001372 final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) {
Dianne Hackborn514074f2013-02-11 10:52:46 -08001373 // The activity now gets access to the data associated with this Intent.
1374 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
Nicolas Prevotc6cf95c2014-05-29 11:30:36 +01001375 intent, getUriPermissionsLocked(), userId);
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001376 final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
Craig Mautner86d67a42013-05-14 10:34:38 -07001377 boolean unsent = true;
David Stevens9440dc82017-03-16 19:00:20 -07001378 final ActivityStack stack = getStack();
1379 final boolean isTopActivityWhileSleeping = isTopRunningActivity()
1380 && (stack != null ? stack.shouldSleepActivities() : service.isSleepingLocked());
Wale Ogunwale826c7062016-09-13 08:25:54 -07001381
1382 // We want to immediately deliver the intent to the activity if:
Wale Ogunwale03f7e9e2016-09-22 09:04:09 -07001383 // - It is currently resumed or paused. i.e. it is currently visible to the user and we want
1384 // the user to see the visual effects caused by the intent delivery now.
Wale Ogunwale826c7062016-09-13 08:25:54 -07001385 // - The device is sleeping and it is the top activity behind the lock screen (b/6700897).
Ruben Brunkf53497c2017-03-27 20:26:17 -07001386 if ((state == RESUMED || state == PAUSED
Wale Ogunwale03f7e9e2016-09-22 09:04:09 -07001387 || isTopActivityWhileSleeping) && app != null && app.thread != null) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001388 try {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001389 ArrayList<ReferrerIntent> ar = new ArrayList<>(1);
1390 ar.add(rintent);
Andrii Kulian446e8242017-10-26 15:17:29 -07001391 service.mLifecycleManager.scheduleTransaction(app.thread, appToken,
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -08001392 NewIntentItem.obtain(ar, state == PAUSED));
Craig Mautner86d67a42013-05-14 10:34:38 -07001393 unsent = false;
Dianne Hackborn39792d22010-08-19 18:01:52 -07001394 } catch (RemoteException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001395 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn39792d22010-08-19 18:01:52 -07001396 } catch (NullPointerException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001397 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001398 }
1399 }
Craig Mautner86d67a42013-05-14 10:34:38 -07001400 if (unsent) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001401 addNewIntentLocked(rintent);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001402 }
1403 }
1404
Dianne Hackborn9622ca42012-10-23 18:56:33 -07001405 void updateOptionsLocked(ActivityOptions options) {
1406 if (options != null) {
1407 if (pendingOptions != null) {
1408 pendingOptions.abort();
1409 }
1410 pendingOptions = options;
1411 }
1412 }
1413
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001414 void applyOptionsLocked() {
George Mount2c92c972014-03-20 09:38:23 -07001415 if (pendingOptions != null
Ruben Brunkf53497c2017-03-27 20:26:17 -07001416 && pendingOptions.getAnimationType() != ANIM_SCENE_TRANSITION) {
Michael Jurka21385cd2012-05-03 10:57:31 -07001417 final int animationType = pendingOptions.getAnimationType();
1418 switch (animationType) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001419 case ANIM_CUSTOM:
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001420 service.mWindowManager.overridePendingAppTransition(
1421 pendingOptions.getPackageName(),
1422 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -07001423 pendingOptions.getCustomExitResId(),
1424 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001425 break;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001426 case ANIM_CLIP_REVEAL:
Chet Haase10e23ab2015-02-11 15:08:38 -08001427 service.mWindowManager.overridePendingAppTransitionClipReveal(
1428 pendingOptions.getStartX(), pendingOptions.getStartY(),
1429 pendingOptions.getWidth(), pendingOptions.getHeight());
1430 if (intent.getSourceBounds() == null) {
1431 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1432 pendingOptions.getStartY(),
1433 pendingOptions.getStartX()+pendingOptions.getWidth(),
1434 pendingOptions.getStartY()+pendingOptions.getHeight()));
1435 }
1436 break;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001437 case ANIM_SCALE_UP:
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001438 service.mWindowManager.overridePendingAppTransitionScaleUp(
1439 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001440 pendingOptions.getWidth(), pendingOptions.getHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001441 if (intent.getSourceBounds() == null) {
1442 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1443 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001444 pendingOptions.getStartX()+pendingOptions.getWidth(),
1445 pendingOptions.getStartY()+pendingOptions.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001446 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001447 break;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001448 case ANIM_THUMBNAIL_SCALE_UP:
1449 case ANIM_THUMBNAIL_SCALE_DOWN:
Winson Chungaa7fa012017-05-24 15:50:06 -07001450 final boolean scaleUp = (animationType == ANIM_THUMBNAIL_SCALE_UP);
1451 final GraphicBuffer buffer = pendingOptions.getThumbnail();
1452 service.mWindowManager.overridePendingAppTransitionThumb(buffer,
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001453 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -07001454 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -07001455 scaleUp);
Winson Chungf229ae52017-06-02 14:34:52 -07001456 if (intent.getSourceBounds() == null && buffer != null) {
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001457 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1458 pendingOptions.getStartY(),
Winson Chungaa7fa012017-05-24 15:50:06 -07001459 pendingOptions.getStartX() + buffer.getWidth(),
1460 pendingOptions.getStartY() + buffer.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001461 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001462 break;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001463 case ANIM_THUMBNAIL_ASPECT_SCALE_UP:
1464 case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001465 final AppTransitionAnimationSpec[] specs = pendingOptions.getAnimSpecs();
Jorim Jaggi34795e32017-05-12 17:27:46 +02001466 final IAppTransitionAnimationSpecsFuture specsFuture =
1467 pendingOptions.getSpecsFuture();
1468 if (specsFuture != null) {
1469 service.mWindowManager.overridePendingAppTransitionMultiThumbFuture(
1470 specsFuture, pendingOptions.getOnAnimationStartListener(),
1471 animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP);
1472 } else if (animationType == ANIM_THUMBNAIL_ASPECT_SCALE_DOWN
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001473 && specs != null) {
1474 service.mWindowManager.overridePendingAppTransitionMultiThumb(
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001475 specs, pendingOptions.getOnAnimationStartListener(),
1476 pendingOptions.getAnimationFinishedListener(), false);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001477 } else {
1478 service.mWindowManager.overridePendingAppTransitionAspectScaledThumb(
1479 pendingOptions.getThumbnail(),
1480 pendingOptions.getStartX(), pendingOptions.getStartY(),
1481 pendingOptions.getWidth(), pendingOptions.getHeight(),
1482 pendingOptions.getOnAnimationStartListener(),
Ruben Brunkf53497c2017-03-27 20:26:17 -07001483 (animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP));
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001484 if (intent.getSourceBounds() == null) {
1485 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1486 pendingOptions.getStartY(),
1487 pendingOptions.getStartX() + pendingOptions.getWidth(),
1488 pendingOptions.getStartY() + pendingOptions.getHeight()));
1489 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001490 }
1491 break;
Tony Mak089c35e2017-12-18 20:34:14 +00001492 case ANIM_OPEN_CROSS_PROFILE_APPS:
1493 service.mWindowManager.overridePendingAppTransitionStartCrossProfileApps();
1494 break;
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001495 case ANIM_REMOTE_ANIMATION:
1496 service.mWindowManager.overridePendingAppTransitionRemote(
1497 pendingOptions.getRemoteAnimationAdapter());
1498 break;
Craig Mautner233ceee2014-05-09 17:05:11 -07001499 default:
1500 Slog.e(TAG, "applyOptionsLocked: Unknown animationType=" + animationType);
1501 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001502 }
1503 pendingOptions = null;
1504 }
1505 }
1506
Adam Powellcfbe9be2013-11-06 14:58:58 -08001507 ActivityOptions getOptionsForTargetActivityLocked() {
1508 return pendingOptions != null ? pendingOptions.forTargetActivity() : null;
1509 }
1510
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001511 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001512 if (pendingOptions != null) {
1513 pendingOptions.abort();
1514 pendingOptions = null;
1515 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001516 }
1517
Dianne Hackborn9622ca42012-10-23 18:56:33 -07001518 ActivityOptions takeOptionsLocked() {
1519 ActivityOptions opts = pendingOptions;
1520 pendingOptions = null;
1521 return opts;
1522 }
1523
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001524 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -07001525 if (uriPermissions != null) {
1526 uriPermissions.removeUriPermissionsLocked();
1527 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001528 }
1529 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001530
1531 void pauseKeyDispatchingLocked() {
1532 if (!keysPaused) {
1533 keysPaused = true;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001534 mWindowContainerController.pauseKeyDispatching();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535 }
1536 }
1537
1538 void resumeKeyDispatchingLocked() {
1539 if (keysPaused) {
1540 keysPaused = false;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001541 mWindowContainerController.resumeKeyDispatching();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 }
1543 }
1544
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001545 private void updateTaskDescription(CharSequence description) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001546 task.lastDescription = description;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001547 }
1548
Wale Ogunwaleec950642017-04-25 07:44:21 -07001549 void setDeferHidingClient(boolean deferHidingClient) {
1550 if (mDeferHidingClient == deferHidingClient) {
1551 return;
1552 }
1553 mDeferHidingClient = deferHidingClient;
1554 if (!mDeferHidingClient && !visible) {
1555 // Hiding the client is no longer deferred and the app isn't visible still, go ahead and
1556 // update the visibility.
1557 setVisibility(false);
1558 }
Wale Ogunwale89973222017-04-23 18:39:45 -07001559 }
1560
Wale Ogunwaleec950642017-04-25 07:44:21 -07001561 void setVisibility(boolean visible) {
Tim Murray68ed8442017-08-29 23:21:27 +00001562 mWindowContainerController.setVisibility(visible, mDeferHidingClient);
Bryce Lee2a3cc462017-10-27 10:57:35 -07001563 mStackSupervisor.getActivityMetricsLogger().notifyVisibilityChanged(this);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001564 }
1565
1566 // TODO: Look into merging with #setVisibility()
Wale Ogunwaleec950642017-04-25 07:44:21 -07001567 void setVisible(boolean newVisible) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001568 visible = newVisible;
Wale Ogunwaleec950642017-04-25 07:44:21 -07001569 mDeferHidingClient = !visible && mDeferHidingClient;
Wale Ogunwaleec950642017-04-25 07:44:21 -07001570 setVisibility(visible);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001571 mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
1572 }
1573
Jorim Jaggibae01b12017-04-11 16:29:10 -07001574 void notifyAppResumed(boolean wasStopped) {
1575 mWindowContainerController.notifyAppResumed(wasStopped);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001576 }
1577
1578 void notifyUnknownVisibilityLaunched() {
Jorim Jaggi838c2452017-08-28 15:44:43 +02001579
1580 // No display activities never add a window, so there is no point in waiting them for
1581 // relayout.
1582 if (!noDisplay) {
1583 mWindowContainerController.notifyUnknownVisibilityLaunched();
1584 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001585 }
1586
Jorim Jaggi241ae102016-11-02 21:57:33 -07001587 /**
1588 * @return true if the input activity should be made visible, ignoring any effect Keyguard
1589 * might have on the visibility
1590 *
1591 * @see {@link ActivityStack#checkKeyguardVisibility}
1592 */
Wale Ogunwalec981ad52017-06-13 11:40:06 -07001593 boolean shouldBeVisibleIgnoringKeyguard(boolean behindFullscreenActivity) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001594 if (!okToShowLocked()) {
1595 return false;
1596 }
1597
Winson Chung3f0e59a2017-10-25 10:19:05 -07001598 return !behindFullscreenActivity || mLaunchTaskBehind;
Andrii Kulian21713ac2016-10-12 22:05:05 -07001599 }
1600
1601 void makeVisibleIfNeeded(ActivityRecord starting) {
1602 // This activity is not currently visible, but is running. Tell it to become visible.
Ruben Brunkf53497c2017-03-27 20:26:17 -07001603 if (state == RESUMED || this == starting) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001604 if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY,
1605 "Not making visible, r=" + this + " state=" + state + " starting=" + starting);
1606 return;
1607 }
1608
1609 // If this activity is paused, tell it to now show its window.
1610 if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY,
1611 "Making visible and scheduling visibility: " + this);
1612 final ActivityStack stack = getStack();
1613 try {
1614 if (stack.mTranslucentActivityWaiting != null) {
1615 updateOptionsLocked(returningOptions);
1616 stack.mUndrawnActivitiesBelowTopTranslucent.add(this);
1617 }
1618 setVisible(true);
1619 sleeping = false;
1620 app.pendingUiClean = true;
Andrii Kulian446e8242017-10-26 15:17:29 -07001621 service.mLifecycleManager.scheduleTransaction(app.thread, appToken,
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -08001622 WindowVisibilityItem.obtain(true /* showWindow */));
Andrii Kulian21713ac2016-10-12 22:05:05 -07001623 // The activity may be waiting for stop, but that is no longer appropriate for it.
1624 mStackSupervisor.mStoppingActivities.remove(this);
1625 mStackSupervisor.mGoingToSleepActivities.remove(this);
Bryce Lee0bd8d422018-01-09 09:45:57 -08001626
Bryce Lee052957b2018-01-16 11:13:30 -08001627 // If the activity is stopped or stopping, cycle to the paused state.
1628 if (state == STOPPED || state == STOPPING) {
Bryce Leed946f862018-01-16 15:59:47 -08001629 // Capture reason before state change
1630 final String reason = getLifecycleDescription("makeVisibleIfNeeded");
1631
Bryce Lee0bd8d422018-01-09 09:45:57 -08001632 // An activity must be in the {@link PAUSING} state for the system to validate
1633 // the move to {@link PAUSED}.
1634 state = PAUSING;
1635 service.mLifecycleManager.scheduleTransaction(app.thread, appToken,
1636 PauseActivityItem.obtain(finishing, false /* userLeaving */,
Bryce Leed946f862018-01-16 15:59:47 -08001637 configChangeFlags, false /* dontReport */)
1638 .setDescription(reason));
Bryce Lee0bd8d422018-01-09 09:45:57 -08001639 }
Andrii Kulian21713ac2016-10-12 22:05:05 -07001640 } catch (Exception e) {
1641 // Just skip on any failure; we'll make it visible when it next restarts.
1642 Slog.w(TAG, "Exception thrown making visibile: " + intent.getComponent(), e);
1643 }
1644 handleAlreadyVisible();
1645 }
1646
1647 boolean handleAlreadyVisible() {
1648 stopFreezingScreenLocked(false);
1649 try {
1650 if (returningOptions != null) {
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001651 app.thread.scheduleOnNewActivityOptions(appToken, returningOptions.toBundle());
Andrii Kulian21713ac2016-10-12 22:05:05 -07001652 }
1653 } catch(RemoteException e) {
1654 }
Ruben Brunkf53497c2017-03-27 20:26:17 -07001655 return state == RESUMED;
Andrii Kulian21713ac2016-10-12 22:05:05 -07001656 }
1657
1658 static void activityResumedLocked(IBinder token) {
1659 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
1660 if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r);
1661 if (r != null) {
1662 r.icicle = null;
1663 r.haveState = false;
1664 }
1665 }
1666
1667 /**
1668 * Once we know that we have asked an application to put an activity in the resumed state
1669 * (either by launching it or explicitly telling it), this function updates the rest of our
1670 * state to match that fact.
1671 */
1672 void completeResumeLocked() {
1673 final boolean wasVisible = visible;
Jorim Jaggi8d062052017-08-22 14:55:17 +02001674 setVisible(true);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001675 if (!wasVisible) {
1676 // Visibility has changed, so take a note of it so we call the TaskStackChangedListener
1677 mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
1678 }
1679 idle = false;
1680 results = null;
1681 newIntents = null;
1682 stopped = false;
1683
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001684 if (isActivityTypeHome()) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001685 ProcessRecord app = task.mActivities.get(0).app;
1686 if (app != null && app != service.mHomeProcess) {
1687 service.mHomeProcess = app;
1688 }
1689 }
1690
1691 if (nowVisible) {
1692 // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now.
1693 mStackSupervisor.reportActivityVisibleLocked(this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001694 }
1695
1696 // Schedule an idle timeout in case the app doesn't do it for us.
1697 mStackSupervisor.scheduleIdleTimeoutLocked(this);
1698
1699 mStackSupervisor.reportResumedActivityLocked(this);
1700
1701 resumeKeyDispatchingLocked();
1702 final ActivityStack stack = getStack();
Jorim Jaggifa9ed962018-01-25 00:16:49 +01001703 mStackSupervisor.mNoAnimActivities.clear();
Andrii Kulian21713ac2016-10-12 22:05:05 -07001704
1705 // Mark the point when the activity is resuming
1706 // TODO: To be more accurate, the mark should be before the onCreate,
1707 // not after the onResume. But for subsequent starts, onResume is fine.
1708 if (app != null) {
1709 cpuTimeAtResume = service.mProcessCpuTracker.getCpuTimeForPid(app.pid);
1710 } else {
1711 cpuTimeAtResume = 0; // Couldn't get the cpu time of process
1712 }
1713
1714 returningOptions = null;
chaviw59b98852017-06-13 12:05:44 -07001715
1716 if (canTurnScreenOn()) {
1717 mStackSupervisor.wakeUp("turnScreenOnFlag");
1718 } else {
1719 // If the screen is going to turn on because the caller explicitly requested it and
1720 // the keyguard is not showing don't attempt to sleep. Otherwise the Activity will
1721 // pause and then resume again later, which will result in a double life-cycle event.
David Stevens9440dc82017-03-16 19:00:20 -07001722 stack.checkReadyForSleep();
chaviw59b98852017-06-13 12:05:44 -07001723 }
Andrii Kulian21713ac2016-10-12 22:05:05 -07001724 }
1725
1726 final void activityStoppedLocked(Bundle newIcicle, PersistableBundle newPersistentState,
1727 CharSequence description) {
1728 final ActivityStack stack = getStack();
Ruben Brunkf53497c2017-03-27 20:26:17 -07001729 if (state != STOPPING) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001730 Slog.i(TAG, "Activity reported stop, but no longer stopping: " + this);
Ruben Brunkf53497c2017-03-27 20:26:17 -07001731 stack.mHandler.removeMessages(STOP_TIMEOUT_MSG, this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001732 return;
1733 }
1734 if (newPersistentState != null) {
1735 persistentState = newPersistentState;
1736 service.notifyTaskPersisterLocked(task, false);
1737 }
1738 if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, "Saving icicle of " + this + ": " + icicle);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001739
Andrii Kulian21713ac2016-10-12 22:05:05 -07001740 if (newIcicle != null) {
1741 // If icicle is null, this is happening due to a timeout, so we haven't really saved
1742 // the state.
1743 icicle = newIcicle;
1744 haveState = true;
1745 launchCount = 0;
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001746 updateTaskDescription(description);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001747 }
1748 if (!stopped) {
1749 if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to STOPPED: " + this + " (stop complete)");
Ruben Brunkf53497c2017-03-27 20:26:17 -07001750 stack.mHandler.removeMessages(STOP_TIMEOUT_MSG, this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001751 stopped = true;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001752 state = STOPPED;
Andrii Kulian21713ac2016-10-12 22:05:05 -07001753
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001754 mWindowContainerController.notifyAppStopped();
Andrii Kulian21713ac2016-10-12 22:05:05 -07001755
Andrii Kulian21713ac2016-10-12 22:05:05 -07001756 if (finishing) {
1757 clearOptionsLocked();
1758 } else {
1759 if (deferRelaunchUntilPaused) {
1760 stack.destroyActivityLocked(this, true /* removeFromApp */, "stop-config");
1761 mStackSupervisor.resumeFocusedStackTopActivityLocked();
1762 } else {
1763 mStackSupervisor.updatePreviousProcessLocked(this);
1764 }
1765 }
1766 }
1767 }
1768
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001769 void startLaunchTickingLocked() {
Jeff Sharkey5ab02432017-06-27 11:01:36 -06001770 if (Build.IS_USER) {
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001771 return;
1772 }
1773 if (launchTickTime == 0) {
1774 launchTickTime = SystemClock.uptimeMillis();
1775 continueLaunchTickingLocked();
1776 }
1777 }
1778
1779 boolean continueLaunchTickingLocked() {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001780 if (launchTickTime == 0) {
1781 return false;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001782 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001783
Andrii Kulian02b7a832016-10-06 23:11:56 -07001784 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001785 if (stack == null) {
1786 return false;
1787 }
1788
Ruben Brunkf53497c2017-03-27 20:26:17 -07001789 Message msg = stack.mHandler.obtainMessage(LAUNCH_TICK_MSG, this);
1790 stack.mHandler.removeMessages(LAUNCH_TICK_MSG);
1791 stack.mHandler.sendMessageDelayed(msg, LAUNCH_TICK);
Wale Ogunwale7d701172015-03-11 15:36:30 -07001792 return true;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001793 }
1794
1795 void finishLaunchTickingLocked() {
1796 launchTickTime = 0;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001797 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001798 if (stack != null) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001799 stack.mHandler.removeMessages(LAUNCH_TICK_MSG);
Wale Ogunwale7d701172015-03-11 15:36:30 -07001800 }
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001801 }
1802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803 // IApplicationToken
1804
1805 public boolean mayFreezeScreenLocked(ProcessRecord app) {
1806 // Only freeze the screen if this activity is currently attached to
1807 // an application, and that application is not blocked or unresponding.
1808 // In any other case, we can't count on getting the screen unfrozen,
1809 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -08001810 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001811 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001813 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
1814 if (mayFreezeScreenLocked(app)) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001815 mWindowContainerController.startFreezingScreen(configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001816 }
1817 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001819 public void stopFreezingScreenLocked(boolean force) {
1820 if (force || frozenBeforeDestroy) {
1821 frozenBeforeDestroy = false;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001822 mWindowContainerController.stopFreezingScreen(force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001823 }
1824 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001825
Jorim Jaggi4d27b842017-08-17 17:22:26 +02001826 public void reportFullyDrawnLocked(boolean restoredFromBundle) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001827 final long curTime = SystemClock.uptimeMillis();
1828 if (displayStartTime != 0) {
1829 reportLaunchTimeLocked(curTime);
1830 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001831 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001832 if (fullyDrawnStartTime != 0 && stack != null) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001833 final long thisTime = curTime - fullyDrawnStartTime;
1834 final long totalTime = stack.mFullyDrawnStartTime != 0
1835 ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07001836 if (SHOW_ACTIVITY_START_TIME) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001837 Trace.asyncTraceEnd(TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
1838 EventLog.writeEvent(AM_ACTIVITY_FULLY_DRAWN_TIME,
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001839 userId, System.identityHashCode(this), shortComponentName,
1840 thisTime, totalTime);
1841 StringBuilder sb = service.mStringBuilder;
1842 sb.setLength(0);
1843 sb.append("Fully drawn ");
1844 sb.append(shortComponentName);
1845 sb.append(": ");
1846 TimeUtils.formatDuration(thisTime, sb);
1847 if (thisTime != totalTime) {
1848 sb.append(" (total ");
1849 TimeUtils.formatDuration(totalTime, sb);
1850 sb.append(")");
1851 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001852 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001853 }
1854 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001855 //service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001856 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001857 stack.mFullyDrawnStartTime = 0;
1858 }
Bryce Lee2a3cc462017-10-27 10:57:35 -07001859 mStackSupervisor.getActivityMetricsLogger().logAppTransitionReportedDrawn(this,
Jorim Jaggi4d27b842017-08-17 17:22:26 +02001860 restoredFromBundle);
Wale Ogunwale7d701172015-03-11 15:36:30 -07001861 fullyDrawnStartTime = 0;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001862 }
1863
1864 private void reportLaunchTimeLocked(final long curTime) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001865 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001866 if (stack == null) {
1867 return;
1868 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001869 final long thisTime = curTime - displayStartTime;
1870 final long totalTime = stack.mLaunchStartTime != 0
1871 ? (curTime - stack.mLaunchStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07001872 if (SHOW_ACTIVITY_START_TIME) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001873 Trace.asyncTraceEnd(TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0);
1874 EventLog.writeEvent(AM_ACTIVITY_LAUNCH_TIME,
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001875 userId, System.identityHashCode(this), shortComponentName,
1876 thisTime, totalTime);
1877 StringBuilder sb = service.mStringBuilder;
1878 sb.setLength(0);
1879 sb.append("Displayed ");
1880 sb.append(shortComponentName);
1881 sb.append(": ");
1882 TimeUtils.formatDuration(thisTime, sb);
1883 if (thisTime != totalTime) {
1884 sb.append(" (total ");
1885 TimeUtils.formatDuration(totalTime, sb);
1886 sb.append(")");
1887 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001888 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001889 }
1890 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
1891 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001892 //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001893 }
1894 displayStartTime = 0;
1895 stack.mLaunchStartTime = 0;
1896 }
1897
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001898 @Override
Sudheer Shankac766db02017-06-12 10:37:29 -07001899 public void onStartingWindowDrawn(long timestamp) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001900 synchronized (service) {
Bryce Lee2a3cc462017-10-27 10:57:35 -07001901 mStackSupervisor.getActivityMetricsLogger().notifyStartingWindowDrawn(
Sudheer Shankac766db02017-06-12 10:37:29 -07001902 getStackId(), timestamp);
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001903 }
1904 }
1905
1906 @Override
Sudheer Shankac766db02017-06-12 10:37:29 -07001907 public void onWindowsDrawn(long timestamp) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001908 synchronized (service) {
Bryce Lee2a3cc462017-10-27 10:57:35 -07001909 mStackSupervisor.getActivityMetricsLogger().notifyWindowsDrawn(getStackId(), timestamp);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001910 if (displayStartTime != 0) {
Sudheer Shankac766db02017-06-12 10:37:29 -07001911 reportLaunchTimeLocked(timestamp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001912 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001913 mStackSupervisor.sendWaitingVisibleReportLocked(this);
1914 startTime = 0;
1915 finishLaunchTickingLocked();
1916 if (task != null) {
1917 task.hasBeenVisible = true;
1918 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001919 }
1920 }
1921
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001922 @Override
1923 public void onWindowsVisible() {
1924 synchronized (service) {
1925 mStackSupervisor.reportActivityVisibleLocked(this);
1926 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this);
1927 if (!nowVisible) {
1928 nowVisible = true;
1929 lastVisibleTime = SystemClock.uptimeMillis();
Bryce Leeb7c9b802017-05-02 14:20:24 -07001930 if (idle || mStackSupervisor.isStoppingNoHistoryActivity()) {
1931 // If this activity was already idle or there is an activity that must be
1932 // stopped immediately after visible, then we now need to make sure we perform
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001933 // the full stop of any activities that are waiting to do so. This is because
1934 // we won't do that while they are still waiting for this one to become visible.
Bryce Lee4a194382017-04-04 14:32:48 -07001935 final int size = mStackSupervisor.mActivitiesWaitingForVisibleActivity.size();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001936 if (size > 0) {
1937 for (int i = 0; i < size; i++) {
Bryce Lee4a194382017-04-04 14:32:48 -07001938 final ActivityRecord r =
1939 mStackSupervisor.mActivitiesWaitingForVisibleActivity.get(i);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001940 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "Was waiting for visible: " + r);
1941 }
Bryce Lee4a194382017-04-04 14:32:48 -07001942 mStackSupervisor.mActivitiesWaitingForVisibleActivity.clear();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001943 mStackSupervisor.scheduleIdleLocked();
1944 }
Bryce Leeb7c9b802017-05-02 14:20:24 -07001945 } else {
1946 // Instead of doing the full stop routine here, let's just hide any activities
1947 // we now can, and let them stop when the normal idle happens.
1948 mStackSupervisor.processStoppingActivitiesLocked(null /* idleActivity */,
1949 false /* remove */, true /* processPausingActivities */);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001950 }
1951 service.scheduleAppGcsLocked();
1952 }
1953 }
1954 }
1955
1956 @Override
1957 public void onWindowsGone() {
1958 synchronized (service) {
1959 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + this);
1960 nowVisible = false;
1961 }
1962 }
1963
1964 @Override
Wale Ogunwale7402ddf2017-03-29 12:58:24 -07001965 public boolean keyDispatchingTimedOut(String reason, int windowPid) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001966 ActivityRecord anrActivity;
1967 ProcessRecord anrApp;
Wale Ogunwale7402ddf2017-03-29 12:58:24 -07001968 boolean windowFromSameProcessAsActivity;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001969 synchronized (service) {
1970 anrActivity = getWaitingHistoryRecordLocked();
1971 anrApp = app;
Brian Carlstrom7b0f2e82017-03-31 00:24:18 -07001972 windowFromSameProcessAsActivity =
1973 app == null || app.pid == windowPid || windowPid == -1;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001974 }
Wale Ogunwale7402ddf2017-03-29 12:58:24 -07001975 if (windowFromSameProcessAsActivity) {
1976 return service.inputDispatchingTimedOut(anrApp, anrActivity, this, false, reason);
1977 } else {
1978 // In this case another process added windows using this activity token. So, we call the
1979 // generic service input dispatch timed out method so that the right process is blamed.
1980 return service.inputDispatchingTimedOut(windowPid, false /* aboveSystem */, reason) < 0;
1981 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001982 }
1983
1984 private ActivityRecord getWaitingHistoryRecordLocked() {
riddle_hsudb46d6b2015-04-01 18:58:07 +08001985 // First find the real culprit... if this activity is waiting for
1986 // another activity to start or has stopped, then the key dispatching
1987 // timeout should not be caused by this.
Bryce Lee4a194382017-04-04 14:32:48 -07001988 if (mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(this) || stopped) {
Craig Mautner8f2adcb2014-04-07 22:21:33 +00001989 final ActivityStack stack = mStackSupervisor.getFocusedStack();
riddle_hsudb46d6b2015-04-01 18:58:07 +08001990 // Try to use the one which is closest to top.
1991 ActivityRecord r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -08001993 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001994 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001995 if (r != null) {
1996 return r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001997 }
1998 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001999 return this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002000 }
2001
Chong Zhang87761972016-08-22 13:53:24 -07002002 /** Checks whether the activity should be shown for current user. */
2003 public boolean okToShowLocked() {
Bryce Lee8558ec72017-08-17 15:37:26 -07002004 // We cannot show activities when the device is locked and the application is not
2005 // encryption aware.
2006 if (!StorageManager.isUserKeyUnlocked(userId)
2007 && !info.applicationInfo.isEncryptionAware()) {
2008 return false;
2009 }
2010
Chong Zhang87761972016-08-22 13:53:24 -07002011 return (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0
2012 || (mStackSupervisor.isCurrentProfileLocked(userId)
Fyodor Kupolov1b3edac2017-09-19 15:48:06 -07002013 && service.mUserController.isUserRunning(userId, 0 /* flags */));
Chong Zhang87761972016-08-22 13:53:24 -07002014 }
2015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002016 /**
2017 * This method will return true if the activity is either visible, is becoming visible, is
2018 * currently pausing, or is resumed.
2019 */
2020 public boolean isInterestingToUserLocked() {
Ruben Brunkf53497c2017-03-27 20:26:17 -07002021 return visible || nowVisible || state == PAUSING ||
2022 state == RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002023 }
2024
Wale Ogunwale3e997362016-09-06 10:37:56 -07002025 void setSleeping(boolean _sleeping) {
2026 setSleeping(_sleeping, false);
2027 }
2028
2029 void setSleeping(boolean _sleeping, boolean force) {
2030 if (!force && sleeping == _sleeping) {
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002031 return;
2032 }
2033 if (app != null && app.thread != null) {
2034 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -08002035 app.thread.scheduleSleeping(appToken, _sleeping);
Craig Mautner0eea92c2013-05-16 13:35:39 -07002036 if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
2037 mStackSupervisor.mGoingToSleepActivities.add(this);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002038 }
2039 sleeping = _sleeping;
2040 } catch (RemoteException e) {
Craig Mautner0eea92c2013-05-16 13:35:39 -07002041 Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002042 }
2043 }
2044 }
Craig Mautnerf81b90872013-02-26 13:02:43 -08002045
Craig Mautnerd2328952013-03-05 12:46:26 -08002046 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07002047 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Craig Mautnerd2328952013-03-05 12:46:26 -08002048 if (r == null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08002049 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08002050 }
2051 final TaskRecord task = r.task;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07002052 final int activityNdx = task.mActivities.indexOf(r);
2053 if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08002054 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08002055 }
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07002056 return task.taskId;
Craig Mautnerd2328952013-03-05 12:46:26 -08002057 }
2058
2059 static ActivityRecord isInStackLocked(IBinder token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07002060 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Andrii Kulian02b7a832016-10-06 23:11:56 -07002061 return (r != null) ? r.getStack().isInStackLocked(r) : null;
Craig Mautnerd2328952013-03-05 12:46:26 -08002062 }
2063
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07002064 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -08002065 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
2066 if (r != null) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002067 return r.getStack();
Craig Mautnerd2328952013-03-05 12:46:26 -08002068 }
2069 return null;
2070 }
2071
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002072 /**
2073 * @return display id to which this record is attached, -1 if not attached.
2074 */
2075 int getDisplayId() {
2076 final ActivityStack stack = getStack();
2077 if (stack == null) {
2078 return -1;
2079 }
2080 return stack.mDisplayId;
2081 }
2082
Dianne Hackborn89ad4562014-08-24 16:45:38 -07002083 final boolean isDestroyable() {
Ruben Brunkf53497c2017-03-27 20:26:17 -07002084 if (finishing || app == null || state == DESTROYING
2085 || state == DESTROYED) {
Dianne Hackborn89ad4562014-08-24 16:45:38 -07002086 // This would be redundant.
2087 return false;
2088 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07002089 final ActivityStack stack = getStack();
2090 if (stack == null || this == stack.mResumedActivity || this == stack.mPausingActivity
2091 || !haveState || !stopped) {
Dianne Hackborn89ad4562014-08-24 16:45:38 -07002092 // We're not ready for this kind of thing.
2093 return false;
2094 }
2095 if (visible) {
2096 // The user would notice this!
2097 return false;
2098 }
2099 return true;
2100 }
2101
Winson Chung3bad5cc02014-08-19 17:44:32 -07002102 private static String createImageFilename(long createTime, int taskId) {
2103 return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime +
Ruben Brunkf53497c2017-03-27 20:26:17 -07002104 IMAGE_EXTENSION;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002105 }
2106
Craig Mautner648f69b2014-09-18 14:16:26 -07002107 void setTaskDescription(TaskDescription _taskDescription) {
2108 Bitmap icon;
2109 if (_taskDescription.getIconFilename() == null &&
2110 (icon = _taskDescription.getIcon()) != null) {
2111 final String iconFilename = createImageFilename(createTime, task.taskId);
Winson Chungc8408b82017-01-25 17:58:56 -08002112 final File iconFile = new File(TaskPersister.getUserImagesDir(task.userId),
2113 iconFilename);
Suprabh Shukla23593142015-11-03 17:31:15 -08002114 final String iconFilePath = iconFile.getAbsolutePath();
Winson Chung3f0e59a2017-10-25 10:19:05 -07002115 service.getRecentTasks().saveImage(icon, iconFilePath);
Suprabh Shukla23593142015-11-03 17:31:15 -08002116 _taskDescription.setIconFilename(iconFilePath);
Craig Mautner648f69b2014-09-18 14:16:26 -07002117 }
2118 taskDescription = _taskDescription;
2119 }
2120
Amith Yamasani0af6fa72016-01-17 15:36:19 -08002121 void setVoiceSessionLocked(IVoiceInteractionSession session) {
2122 voiceSession = session;
2123 pendingVoiceInteractionStart = false;
2124 }
2125
2126 void clearVoiceSessionLocked() {
2127 voiceSession = null;
2128 pendingVoiceInteractionStart = false;
2129 }
2130
Jorim Jaggi02886a82016-12-06 09:10:06 -08002131 void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch) {
Jorim Jaggi42befc62017-06-13 11:54:04 -07002132 showStartingWindow(prev, newTask, taskSwitch, false /* fromRecents */);
2133 }
2134
2135 void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch,
2136 boolean fromRecents) {
Jorim Jaggi70176432017-01-18 12:52:13 +01002137 if (mWindowContainerController == null) {
2138 return;
2139 }
Wale Ogunwale19866e22017-04-19 06:05:13 -07002140 if (mTaskOverlay) {
2141 // We don't show starting window for overlay activities.
2142 return;
2143 }
2144
Wale Ogunwale3b232392016-05-13 15:37:13 -07002145 final CompatibilityInfo compatInfo =
2146 service.compatibilityInfoForPackageLocked(info.applicationInfo);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002147 final boolean shown = mWindowContainerController.addStartingWindow(packageName, theme,
2148 compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags,
Jorim Jaggibae01b12017-04-11 16:29:10 -07002149 prev != null ? prev.appToken : null, newTask, taskSwitch, isProcessRunning(),
Jorim Jaggi70aa4d12017-05-15 00:05:54 +02002150 allowTaskSnapshot(),
Jorim Jaggi42befc62017-06-13 11:54:04 -07002151 state.ordinal() >= RESUMED.ordinal() && state.ordinal() <= STOPPED.ordinal(),
2152 fromRecents);
Wale Ogunwale3b232392016-05-13 15:37:13 -07002153 if (shown) {
2154 mStartingWindowState = STARTING_WINDOW_SHOWN;
2155 }
2156 }
2157
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002158 void removeOrphanedStartingWindow(boolean behindFullscreenActivity) {
Jorim Jaggicb956052017-05-09 16:27:24 +02002159 if (mStartingWindowState == STARTING_WINDOW_SHOWN && behindFullscreenActivity) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002160 if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, "Found orphaned starting window " + this);
2161 mStartingWindowState = STARTING_WINDOW_REMOVED;
Jorim Jaggi19be6052017-08-03 18:33:43 +02002162 mWindowContainerController.removeStartingWindow();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002163 }
2164 }
2165
2166 int getRequestedOrientation() {
2167 return mWindowContainerController.getOrientation();
2168 }
2169
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002170 void setRequestedOrientation(int requestedOrientation) {
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002171 final int displayId = getDisplayId();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002172 final Configuration displayConfig =
2173 mStackSupervisor.getDisplayOverrideConfiguration(displayId);
2174
2175 final Configuration config = mWindowContainerController.setOrientation(requestedOrientation,
2176 displayId, displayConfig, mayFreezeScreenLocked(app));
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002177 if (config != null) {
2178 frozenBeforeDestroy = true;
2179 if (!service.updateDisplayOverrideConfigurationLocked(config, this,
2180 false /* deferResume */, displayId)) {
2181 mStackSupervisor.resumeFocusedStackTopActivityLocked();
2182 }
2183 }
Yorke Leebd54c2a2016-10-25 13:49:23 -07002184 service.mTaskChangeNotificationController.notifyActivityRequestedOrientationChanged(
2185 task.taskId, requestedOrientation);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002186 }
2187
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01002188 void setDisablePreviewScreenshots(boolean disable) {
2189 mWindowContainerController.setDisablePreviewScreenshots(disable);
2190 }
2191
Bryce Leea163b762017-01-24 11:05:01 -08002192 /**
2193 * Set the last reported global configuration to the client. Should be called whenever a new
2194 * global configuration is sent to the client for this activity.
2195 */
2196 void setLastReportedGlobalConfiguration(@NonNull Configuration config) {
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002197 mLastReportedConfiguration.setGlobalConfiguration(config);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002198 }
2199
Bryce Leea163b762017-01-24 11:05:01 -08002200 /**
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002201 * Set the last reported configuration to the client. Should be called whenever
Bryce Leea163b762017-01-24 11:05:01 -08002202 * a new merged configuration is sent to the client for this activity.
2203 */
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002204 void setLastReportedConfiguration(@NonNull MergedConfiguration config) {
Bryce Lee8104e7a2017-08-17 09:16:03 -07002205 setLastReportedConfiguration(config.getGlobalConfiguration(),
2206 config.getOverrideConfiguration());
Bryce Leea163b762017-01-24 11:05:01 -08002207 }
2208
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07002209 private void setLastReportedConfiguration(Configuration global, Configuration override) {
Bryce Lee8104e7a2017-08-17 09:16:03 -07002210 mLastReportedConfiguration.setConfiguration(global, override);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002211 }
2212
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002213 // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer.
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002214 private void updateOverrideConfiguration() {
2215 mTmpConfig.unset();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002216 computeBounds(mTmpBounds);
Bryce Leef3c6a472017-11-14 14:53:06 -08002217
2218 if (mTmpBounds.equals(getOverrideBounds())) {
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002219 return;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002220 }
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002221
Bryce Leef3c6a472017-11-14 14:53:06 -08002222 setBounds(mTmpBounds);
2223
2224 final Rect updatedBounds = getOverrideBounds();
2225
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002226 // Bounds changed...update configuration to match.
Bryce Leef3c6a472017-11-14 14:53:06 -08002227 if (!matchParentBounds()) {
2228 task.computeOverrideConfiguration(mTmpConfig, updatedBounds, null /* insetBounds */,
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002229 false /* overrideWidth */, false /* overrideHeight */);
2230 }
Bryce Leef3c6a472017-11-14 14:53:06 -08002231
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002232 onOverrideConfigurationChanged(mTmpConfig);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002233 }
2234
Wale Ogunwaled4b1d1e2017-04-10 06:35:59 -07002235 /** Returns true if the configuration is compatible with this activity. */
Wale Ogunwale42f07d92017-05-01 21:32:58 -07002236 boolean isConfigurationCompatible(Configuration config) {
Wale Ogunwaled4b1d1e2017-04-10 06:35:59 -07002237 final int orientation = mWindowContainerController != null
2238 ? mWindowContainerController.getOrientation() : info.screenOrientation;
2239 if (isFixedOrientationPortrait(orientation)
2240 && config.orientation != ORIENTATION_PORTRAIT) {
2241 return false;
2242 }
2243 if (isFixedOrientationLandscape(orientation)
2244 && config.orientation != ORIENTATION_LANDSCAPE) {
2245 return false;
2246 }
2247 return true;
2248 }
2249
Bryce Lee7566d762017-03-30 09:34:15 -07002250 /**
2251 * Computes the bounds to fit the Activity within the bounds of the {@link Configuration}.
2252 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002253 // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer.
2254 private void computeBounds(Rect outBounds) {
2255 outBounds.setEmpty();
2256 final float maxAspectRatio = info.maxAspectRatio;
2257 final ActivityStack stack = getStack();
Bryce Leef3c6a472017-11-14 14:53:06 -08002258 if (task == null || stack == null || task.inMultiWindowMode() || maxAspectRatio == 0
Bryce Leee5ab4502017-07-11 08:58:05 -07002259 || isInVrUiMode(getConfiguration())) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002260 // We don't set override configuration if that activity task isn't fullscreen. I.e. the
2261 // activity is in multi-window mode. Or, there isn't a max aspect ratio specified for
Bryce Leee5ab4502017-07-11 08:58:05 -07002262 // the activity. This is indicated by an empty {@link outBounds}. We also don't set it
2263 // if we are in VR mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002264 return;
2265 }
2266
Bryce Lee7566d762017-03-30 09:34:15 -07002267 // We must base this on the parent configuration, because we set our override
2268 // configuration's appBounds based on the result of this method. If we used our own
2269 // configuration, it would be influenced by past invocations.
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002270 final Rect appBounds = getParent().getWindowConfiguration().getAppBounds();
Wale Ogunwale822e5122017-07-26 06:02:24 -07002271 final int containingAppWidth = appBounds.width();
2272 final int containingAppHeight = appBounds.height();
Bryce Lee7566d762017-03-30 09:34:15 -07002273 int maxActivityWidth = containingAppWidth;
2274 int maxActivityHeight = containingAppHeight;
2275
2276 if (containingAppWidth < containingAppHeight) {
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002277 // Width is the shorter side, so we use that to figure-out what the max. height
2278 // should be given the aspect ratio.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002279 maxActivityHeight = (int) ((maxActivityWidth * maxAspectRatio) + 0.5f);
2280 } else {
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002281 // Height is the shorter side, so we use that to figure-out what the max. width
2282 // should be given the aspect ratio.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002283 maxActivityWidth = (int) ((maxActivityHeight * maxAspectRatio) + 0.5f);
2284 }
2285
Bryce Lee7566d762017-03-30 09:34:15 -07002286 if (containingAppWidth <= maxActivityWidth && containingAppHeight <= maxActivityHeight) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002287 // The display matches or is less than the activity aspect ratio, so nothing else to do.
Bryce Lee7566d762017-03-30 09:34:15 -07002288 // Return the existing bounds. If this method is running for the first time,
Bryce Leef3c6a472017-11-14 14:53:06 -08002289 // {@link #getOverrideBounds()} will be empty (representing no override). If the method has run
2290 // before, then effect of {@link #getOverrideBounds()} will already have been applied to the
Bryce Lee7566d762017-03-30 09:34:15 -07002291 // value returned from {@link getConfiguration}. Refer to
2292 // {@link TaskRecord#computeOverrideConfiguration}.
Bryce Leef3c6a472017-11-14 14:53:06 -08002293 outBounds.set(getOverrideBounds());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002294 return;
2295 }
2296
2297 // Compute configuration based on max supported width and height.
2298 outBounds.set(0, 0, maxActivityWidth, maxActivityHeight);
Andrii Kulian3a1619d2017-07-07 14:38:09 -07002299 // Position the activity frame on the opposite side of the nav bar.
2300 final int navBarPosition = service.mWindowManager.getNavBarPosition();
Wale Ogunwale822e5122017-07-26 06:02:24 -07002301 final int left = navBarPosition == NAV_BAR_LEFT ? appBounds.right - outBounds.width() : 0;
Andrii Kulian3a1619d2017-07-07 14:38:09 -07002302 outBounds.offsetTo(left, 0 /* top */);
2303 }
2304
Andrii Kulian21713ac2016-10-12 22:05:05 -07002305 /**
2306 * Make sure the given activity matches the current configuration. Returns false if the activity
2307 * had to be destroyed. Returns true if the configuration is the same, or the activity will
2308 * remain running as-is for whatever reason. Ensures the HistoryRecord is updated with the
2309 * correct configuration and all other bookkeeping is handled.
2310 */
2311 boolean ensureActivityConfigurationLocked(int globalChanges, boolean preserveWindow) {
2312 final ActivityStack stack = getStack();
2313 if (stack.mConfigWillChange) {
2314 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2315 "Skipping config check (will change): " + this);
2316 return true;
2317 }
2318
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002319 // We don't worry about activities that are finishing.
2320 if (finishing) {
2321 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2322 "Configuration doesn't matter in finishing " + this);
2323 stopFreezingScreenLocked(false);
2324 return true;
2325 }
2326
Wale Ogunwale9b7a8272017-04-10 08:05:41 -07002327 // Skip updating configuration for activity that are stopping or stopped.
2328 if (state == STOPPING || state == STOPPED) {
2329 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2330 "Skipping config check stopped or stopping: " + this);
2331 return true;
2332 }
2333
Wale Ogunwaleea3d3fd2017-05-01 07:41:08 -07002334 // TODO: We should add ActivityRecord.shouldBeVisible() that checks if the activity should
2335 // be visible based on the stack, task, and lockscreen state and use that here instead. The
2336 // method should be based on the logic in ActivityStack.ensureActivitiesVisibleLocked().
Wale Ogunwale9b7a8272017-04-10 08:05:41 -07002337 // Skip updating configuration for activity is a stack that shouldn't be visible.
Wale Ogunwale9dcf9462017-09-19 15:13:01 -07002338 if (!stack.shouldBeVisible(null /* starting */)) {
Wale Ogunwale9b7a8272017-04-10 08:05:41 -07002339 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2340 "Skipping config check invisible stack: " + this);
2341 return true;
2342 }
2343
Andrii Kulian21713ac2016-10-12 22:05:05 -07002344 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2345 "Ensuring correct configuration: " + this);
2346
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002347 final int newDisplayId = getDisplayId();
2348 final boolean displayChanged = mLastReportedDisplayId != newDisplayId;
2349 if (displayChanged) {
2350 mLastReportedDisplayId = newDisplayId;
2351 }
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002352 // TODO(b/36505427): Is there a better place to do this?
2353 updateOverrideConfiguration();
2354
Winson Chungbdc646f2017-02-13 12:12:22 -08002355 // Short circuit: if the two full configurations are equal (the common case), then there is
2356 // nothing to do. We test the full configuration instead of the global and merged override
2357 // configurations because there are cases (like moving a task to the pinned stack) where
2358 // the combine configurations are equal, but would otherwise differ in the override config
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002359 mTmpConfig.setTo(mLastReportedConfiguration.getMergedConfiguration());
2360 if (getConfiguration().equals(mTmpConfig) && !forceNewConfig && !displayChanged) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002361 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002362 "Configuration & display unchanged in " + this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002363 return true;
2364 }
2365
2366 // Okay we now are going to make this activity have the new config.
2367 // But then we need to figure out how it needs to deal with that.
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002368
2369 // Find changes between last reported merged configuration and the current one. This is used
2370 // to decide whether to relaunch an activity or just report a configuration change.
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002371 final int changes = getConfigurationChanges(mTmpConfig);
Ruben Brunkf64af332017-03-22 22:03:25 -07002372
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002373 // Update last reported values.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002374 final Configuration newMergedOverrideConfig = getMergedOverrideConfiguration();
Bryce Lee8104e7a2017-08-17 09:16:03 -07002375
2376 setLastReportedConfiguration(service.getGlobalConfiguration(), newMergedOverrideConfig);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002377
Andrii Kulianb372da62018-01-18 10:46:24 -08002378 if (state == INITIALIZING) {
2379 // No need to relaunch or schedule new config for activity that hasn't been launched
2380 // yet. We do, however, return after applying the config to activity record, so that
2381 // it will use it for launch transaction.
2382 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2383 "Skipping config check for initializing activity: " + this);
2384 return true;
2385 }
2386
Andrii Kulian21713ac2016-10-12 22:05:05 -07002387 if (changes == 0 && !forceNewConfig) {
2388 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2389 "Configuration no differences in " + this);
2390 // There are no significant differences, so we won't relaunch but should still deliver
2391 // the new configuration to the client process.
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002392 if (displayChanged) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002393 scheduleActivityMovedToDisplay(newDisplayId, newMergedOverrideConfig);
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002394 } else {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002395 scheduleConfigurationChanged(newMergedOverrideConfig);
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002396 }
Andrii Kulian21713ac2016-10-12 22:05:05 -07002397 return true;
2398 }
2399
2400 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002401 "Configuration changes for " + this + ", allChanges="
Andrii Kulian21713ac2016-10-12 22:05:05 -07002402 + Configuration.configurationDiffToString(changes));
2403
2404 // If the activity isn't currently running, just leave the new configuration and it will
2405 // pick that up next time it starts.
2406 if (app == null || app.thread == null) {
2407 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2408 "Configuration doesn't matter not running " + this);
2409 stopFreezingScreenLocked(false);
2410 forceNewConfig = false;
2411 return true;
2412 }
2413
2414 // Figure out how to handle the changes between the configurations.
2415 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2416 "Checking to restart " + info.name + ": changed=0x"
2417 + Integer.toHexString(changes) + ", handles=0x"
2418 + Integer.toHexString(info.getRealConfigChanged())
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002419 + ", mLastReportedConfiguration=" + mLastReportedConfiguration);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002420
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002421 if (shouldRelaunchLocked(changes, mTmpConfig) || forceNewConfig) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002422 // Aha, the activity isn't handling the change, so DIE DIE DIE.
2423 configChangeFlags |= changes;
2424 startFreezingScreenLocked(app, globalChanges);
2425 forceNewConfig = false;
2426 preserveWindow &= isResizeOnlyChange(changes);
2427 if (app == null || app.thread == null) {
2428 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2429 "Config is destroying non-running " + this);
2430 stack.destroyActivityLocked(this, true, "config");
Ruben Brunkf53497c2017-03-27 20:26:17 -07002431 } else if (state == PAUSING) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002432 // A little annoying: we are waiting for this activity to finish pausing. Let's not
2433 // do anything now, but just flag that it needs to be restarted when done pausing.
2434 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2435 "Config is skipping already pausing " + this);
2436 deferRelaunchUntilPaused = true;
2437 preserveWindowOnDeferredRelaunch = preserveWindow;
2438 return true;
Ruben Brunkf53497c2017-03-27 20:26:17 -07002439 } else if (state == RESUMED) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002440 // Try to optimize this case: the configuration is changing and we need to restart
2441 // the top, resumed activity. Instead of doing the normal handshaking, just say
2442 // "restart!".
2443 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2444 "Config is relaunching resumed " + this);
2445
2446 if (DEBUG_STATES && !visible) {
2447 Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + this
2448 + " called by " + Debug.getCallers(4));
2449 }
2450
2451 relaunchActivityLocked(true /* andResume */, preserveWindow);
2452 } else {
2453 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2454 "Config is relaunching non-resumed " + this);
2455 relaunchActivityLocked(false /* andResume */, preserveWindow);
2456 }
2457
2458 // All done... tell the caller we weren't able to keep this activity around.
2459 return false;
2460 }
2461
2462 // Default case: the activity can handle this new configuration, so hand it over.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002463 // NOTE: We only forward the override configuration as the system level configuration
Andrii Kulian21713ac2016-10-12 22:05:05 -07002464 // changes is always sent to all processes when they happen so it can just use whatever
2465 // system level configuration it last got.
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002466 if (displayChanged) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002467 scheduleActivityMovedToDisplay(newDisplayId, newMergedOverrideConfig);
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002468 } else {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002469 scheduleConfigurationChanged(newMergedOverrideConfig);
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002470 }
Andrii Kulian21713ac2016-10-12 22:05:05 -07002471 stopFreezingScreenLocked(false);
2472
2473 return true;
2474 }
2475
Zak Cohen90e7116742017-01-29 12:59:23 -08002476 /**
2477 * When assessing a configuration change, decide if the changes flags and the new configurations
2478 * should cause the Activity to relaunch.
Ruben Brunkf64af332017-03-22 22:03:25 -07002479 *
2480 * @param changes the changes due to the given configuration.
2481 * @param changesConfig the configuration that was used to calculate the given changes via a
2482 * call to getConfigurationChanges.
Zak Cohen90e7116742017-01-29 12:59:23 -08002483 */
Ruben Brunkf64af332017-03-22 22:03:25 -07002484 private boolean shouldRelaunchLocked(int changes, Configuration changesConfig) {
Zak Cohen90e7116742017-01-29 12:59:23 -08002485 int configChanged = info.getRealConfigChanged();
Ruben Brunkf64af332017-03-22 22:03:25 -07002486 boolean onlyVrUiModeChanged = onlyVrUiModeChanged(changes, changesConfig);
Zak Cohen90e7116742017-01-29 12:59:23 -08002487
2488 // Override for apps targeting pre-O sdks
2489 // If a device is in VR mode, and we're transitioning into VR ui mode, add ignore ui mode
2490 // to the config change.
2491 // For O and later, apps will be required to add configChanges="uimode" to their manifest.
2492 if (appInfo.targetSdkVersion < O
2493 && requestedVrComponent != null
Ruben Brunkf64af332017-03-22 22:03:25 -07002494 && onlyVrUiModeChanged) {
Zak Cohen90e7116742017-01-29 12:59:23 -08002495 configChanged |= CONFIG_UI_MODE;
2496 }
2497
2498 return (changes&(~configChanged)) != 0;
2499 }
2500
Ruben Brunkf64af332017-03-22 22:03:25 -07002501 /**
2502 * Returns true if the configuration change is solely due to the UI mode switching into or out
2503 * of UI_MODE_TYPE_VR_HEADSET.
2504 */
2505 private boolean onlyVrUiModeChanged(int changes, Configuration lastReportedConfig) {
2506 final Configuration currentConfig = getConfiguration();
Ruben Brunkf53497c2017-03-27 20:26:17 -07002507 return changes == CONFIG_UI_MODE && (isInVrUiMode(currentConfig)
Ruben Brunkf64af332017-03-22 22:03:25 -07002508 != isInVrUiMode(lastReportedConfig));
2509 }
2510
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002511 private int getConfigurationChanges(Configuration lastReportedConfig) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002512 // Determine what has changed. May be nothing, if this is a config that has come back from
2513 // the app after going idle. In that case we just want to leave the official config object
2514 // now in the activity and do nothing else.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002515 final Configuration currentConfig = getConfiguration();
2516 int changes = lastReportedConfig.diff(currentConfig);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002517 // We don't want to use size changes if they don't cross boundaries that are important to
2518 // the app.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002519 if ((changes & CONFIG_SCREEN_SIZE) != 0) {
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002520 final boolean crosses = crossesHorizontalSizeThreshold(lastReportedConfig.screenWidthDp,
2521 currentConfig.screenWidthDp)
2522 || crossesVerticalSizeThreshold(lastReportedConfig.screenHeightDp,
2523 currentConfig.screenHeightDp);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002524 if (!crosses) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002525 changes &= ~CONFIG_SCREEN_SIZE;
Andrii Kulian21713ac2016-10-12 22:05:05 -07002526 }
2527 }
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002528 if ((changes & CONFIG_SMALLEST_SCREEN_SIZE) != 0) {
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002529 final int oldSmallest = lastReportedConfig.smallestScreenWidthDp;
2530 final int newSmallest = currentConfig.smallestScreenWidthDp;
2531 if (!crossesSmallestSizeThreshold(oldSmallest, newSmallest)) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002532 changes &= ~CONFIG_SMALLEST_SCREEN_SIZE;
Andrii Kulian21713ac2016-10-12 22:05:05 -07002533 }
2534 }
Wale Ogunwale822e5122017-07-26 06:02:24 -07002535 // We don't want window configuration to cause relaunches.
2536 if ((changes & CONFIG_WINDOW_CONFIGURATION) != 0) {
2537 changes &= ~CONFIG_WINDOW_CONFIGURATION;
2538 }
Bryce Lee600dadd2017-07-25 10:48:42 -07002539
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002540 return changes;
Andrii Kulian21713ac2016-10-12 22:05:05 -07002541 }
2542
2543 private static boolean isResizeOnlyChange(int change) {
2544 return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION
2545 | CONFIG_SCREEN_LAYOUT)) == 0;
2546 }
2547
2548 void relaunchActivityLocked(boolean andResume, boolean preserveWindow) {
2549 if (service.mSuppressResizeConfigChanges && preserveWindow) {
2550 configChangeFlags = 0;
2551 return;
2552 }
2553
2554 List<ResultInfo> pendingResults = null;
2555 List<ReferrerIntent> pendingNewIntents = null;
2556 if (andResume) {
2557 pendingResults = results;
2558 pendingNewIntents = newIntents;
2559 }
2560 if (DEBUG_SWITCH) Slog.v(TAG_SWITCH,
2561 "Relaunching: " + this + " with results=" + pendingResults
2562 + " newIntents=" + pendingNewIntents + " andResume=" + andResume
2563 + " preserveWindow=" + preserveWindow);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002564 EventLog.writeEvent(andResume ? AM_RELAUNCH_RESUME_ACTIVITY
2565 : AM_RELAUNCH_ACTIVITY, userId, System.identityHashCode(this),
Andrii Kulian21713ac2016-10-12 22:05:05 -07002566 task.taskId, shortComponentName);
2567
2568 startFreezingScreenLocked(app, 0);
2569
Andrii Kulian21713ac2016-10-12 22:05:05 -07002570 try {
2571 if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH,
2572 "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + this
2573 + " callers=" + Debug.getCallers(6));
2574 forceNewConfig = false;
2575 mStackSupervisor.activityRelaunchingLocked(this);
Andrii Kulianb372da62018-01-18 10:46:24 -08002576 final ClientTransactionItem callbackItem = ActivityRelaunchItem.obtain(pendingResults,
2577 pendingNewIntents, configChangeFlags,
2578 new MergedConfiguration(service.getGlobalConfiguration(),
2579 getMergedOverrideConfiguration()),
2580 preserveWindow);
2581 final ActivityLifecycleItem lifecycleItem;
2582 if (andResume) {
2583 lifecycleItem = ResumeActivityItem.obtain(service.isNextTransitionForward());
2584 } else {
2585 lifecycleItem = PauseActivityItem.obtain();
2586 }
2587 final ClientTransaction transaction = ClientTransaction.obtain(app.thread, appToken);
2588 transaction.addCallback(callbackItem);
2589 transaction.setLifecycleStateRequest(lifecycleItem);
2590 service.mLifecycleManager.scheduleTransaction(transaction);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002591 // Note: don't need to call pauseIfSleepingLocked() here, because the caller will only
Andrii Kulianb372da62018-01-18 10:46:24 -08002592 // request resume if this activity is currently resumed, which implies we aren't
Andrii Kulian21713ac2016-10-12 22:05:05 -07002593 // sleeping.
2594 } catch (RemoteException e) {
2595 if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e);
2596 }
2597
2598 if (andResume) {
2599 if (DEBUG_STATES) {
2600 Slog.d(TAG_STATES, "Resumed after relaunch " + this);
2601 }
2602 results = null;
2603 newIntents = null;
Alan Viveretteb6a25732017-11-21 14:49:24 -05002604 service.getAppWarningsLocked().onResumeActivity(this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002605 service.showAskCompatModeDialogLocked(this);
2606 } else {
Ruben Brunkf53497c2017-03-27 20:26:17 -07002607 service.mHandler.removeMessages(PAUSE_TIMEOUT_MSG, this);
2608 state = PAUSED;
Andrii Kulian21713ac2016-10-12 22:05:05 -07002609 // if the app is relaunched when it's stopped, and we're not resuming,
2610 // put it back into stopped state.
2611 if (stopped) {
Winson Chung4dabf232017-01-25 13:25:22 -08002612 getStack().addToStopping(this, true /* scheduleIdle */, false /* idleDelayed */);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002613 }
2614 }
2615
2616 configChangeFlags = 0;
2617 deferRelaunchUntilPaused = false;
2618 preserveWindowOnDeferredRelaunch = false;
2619 }
2620
Jorim Jaggibae01b12017-04-11 16:29:10 -07002621 private boolean isProcessRunning() {
Jorim Jaggi02886a82016-12-06 09:10:06 -08002622 ProcessRecord proc = app;
2623 if (proc == null) {
2624 proc = service.mProcessNames.get(processName, info.applicationInfo.uid);
2625 }
2626 return proc != null && proc.thread != null;
2627 }
2628
Jorim Jaggibae01b12017-04-11 16:29:10 -07002629 /**
2630 * @return Whether a task snapshot starting window may be shown.
2631 */
2632 private boolean allowTaskSnapshot() {
2633 if (newIntents == null) {
2634 return true;
2635 }
2636
2637 // Restrict task snapshot starting window to launcher start, or there is no intent at all
2638 // (eg. task being brought to front). If the intent is something else, likely the app is
2639 // going to show some specific page or view, instead of what's left last time.
2640 for (int i = newIntents.size() - 1; i >= 0; i--) {
2641 final Intent intent = newIntents.get(i);
2642 if (intent != null && !ActivityRecord.isMainIntent(intent)) {
2643 return false;
2644 }
2645 }
2646 return true;
2647 }
2648
Bryce Leeb7c9b802017-05-02 14:20:24 -07002649 /**
2650 * Returns {@code true} if the associated activity has the no history flag set on it.
2651 * {@code false} otherwise.
2652 */
2653 boolean isNoHistory() {
2654 return (intent.getFlags() & FLAG_ACTIVITY_NO_HISTORY) != 0
2655 || (info.flags & FLAG_NO_HISTORY) != 0;
2656 }
2657
Craig Mautner21d24a22014-04-23 11:45:37 -07002658 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
2659 out.attribute(null, ATTR_ID, String.valueOf(createTime));
2660 out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
2661 if (launchedFromPackage != null) {
2662 out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage);
2663 }
2664 if (resolvedType != null) {
2665 out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType);
2666 }
2667 out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified));
2668 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Winson Chung2cb86c72014-06-25 12:03:30 -07002669
Craig Mautner21d24a22014-04-23 11:45:37 -07002670 if (taskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07002671 taskDescription.saveToXml(out);
Craig Mautner21d24a22014-04-23 11:45:37 -07002672 }
2673
2674 out.startTag(null, TAG_INTENT);
2675 intent.saveToXml(out);
2676 out.endTag(null, TAG_INTENT);
2677
2678 if (isPersistable() && persistentState != null) {
2679 out.startTag(null, TAG_PERSISTABLEBUNDLE);
2680 persistentState.saveToXml(out);
2681 out.endTag(null, TAG_PERSISTABLEBUNDLE);
2682 }
2683 }
2684
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07002685 static ActivityRecord restoreFromXml(XmlPullParser in,
2686 ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07002687 Intent intent = null;
2688 PersistableBundle persistentState = null;
2689 int launchedFromUid = 0;
2690 String launchedFromPackage = null;
2691 String resolvedType = null;
2692 boolean componentSpecified = false;
2693 int userId = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07002694 long createTime = -1;
2695 final int outerDepth = in.getDepth();
Winson Chung2cb86c72014-06-25 12:03:30 -07002696 TaskDescription taskDescription = new TaskDescription();
Craig Mautner21d24a22014-04-23 11:45:37 -07002697
2698 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
2699 final String attrName = in.getAttributeName(attrNdx);
2700 final String attrValue = in.getAttributeValue(attrNdx);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002701 if (DEBUG) Slog.d(TaskPersister.TAG,
Wale Ogunwale18795a22014-12-03 11:38:33 -08002702 "ActivityRecord: attribute name=" + attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002703 if (ATTR_ID.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01002704 createTime = Long.parseLong(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002705 } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01002706 launchedFromUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002707 } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
2708 launchedFromPackage = attrValue;
2709 } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
2710 resolvedType = attrValue;
2711 } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
Tobias Thiererb0800dc2016-04-21 17:51:41 +01002712 componentSpecified = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002713 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01002714 userId = Integer.parseInt(attrValue);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002715 } else if (attrName.startsWith(ATTR_TASKDESCRIPTION_PREFIX)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07002716 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002717 } else {
2718 Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName);
2719 }
2720 }
2721
2722 int event;
Ruben Brunkf53497c2017-03-27 20:26:17 -07002723 while (((event = in.next()) != END_DOCUMENT) &&
2724 (event != END_TAG || in.getDepth() >= outerDepth)) {
2725 if (event == START_TAG) {
Craig Mautner21d24a22014-04-23 11:45:37 -07002726 final String name = in.getName();
Ruben Brunkf53497c2017-03-27 20:26:17 -07002727 if (DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08002728 Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name);
Craig Mautner21d24a22014-04-23 11:45:37 -07002729 if (TAG_INTENT.equals(name)) {
2730 intent = Intent.restoreFromXml(in);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002731 if (DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08002732 Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07002733 } else if (TAG_PERSISTABLEBUNDLE.equals(name)) {
2734 persistentState = PersistableBundle.restoreFromXml(in);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002735 if (DEBUG) Slog.d(TaskPersister.TAG,
Craig Mautner21d24a22014-04-23 11:45:37 -07002736 "ActivityRecord: persistentState=" + persistentState);
2737 } else {
2738 Slog.w(TAG, "restoreActivity: unexpected name=" + name);
2739 XmlUtils.skipCurrentTag(in);
2740 }
2741 }
2742 }
2743
2744 if (intent == null) {
Craig Mautnere0129b32014-05-25 16:41:09 -07002745 throw new XmlPullParserException("restoreActivity error intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07002746 }
2747
2748 final ActivityManagerService service = stackSupervisor.mService;
2749 final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null,
Jeff Hao1b012d32014-08-20 10:35:34 -07002750 userId);
Craig Mautnere0129b32014-05-25 16:41:09 -07002751 if (aInfo == null) {
Craig Mautner77b04262014-06-27 15:22:12 -07002752 throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent +
2753 " resolvedType=" + resolvedType);
Craig Mautnere0129b32014-05-25 16:41:09 -07002754 }
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002755 final ActivityRecord r = new ActivityRecord(service, null /* caller */,
2756 0 /* launchedFromPid */, launchedFromUid, launchedFromPackage, intent, resolvedType,
2757 aInfo, service.getConfiguration(), null /* resultTo */, null /* resultWho */,
2758 0 /* reqCode */, componentSpecified, false /* rootVoiceInteraction */,
Andrii Kulian94e82d9b02017-07-13 15:33:06 -07002759 stackSupervisor, null /* options */, null /* sourceRecord */);
Craig Mautner21d24a22014-04-23 11:45:37 -07002760
2761 r.persistentState = persistentState;
Winson Chung2cb86c72014-06-25 12:03:30 -07002762 r.taskDescription = taskDescription;
Craig Mautner21d24a22014-04-23 11:45:37 -07002763 r.createTime = createTime;
2764
2765 return r;
2766 }
2767
Zak Cohen90e7116742017-01-29 12:59:23 -08002768 private static boolean isInVrUiMode(Configuration config) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07002769 return (config.uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_VR_HEADSET;
Zak Cohen90e7116742017-01-29 12:59:23 -08002770 }
2771
David Stevens82ea6cb2017-03-03 16:18:50 -08002772 int getUid() {
2773 return info.applicationInfo.uid;
2774 }
2775
chaviw59b98852017-06-13 12:05:44 -07002776 void setShowWhenLocked(boolean showWhenLocked) {
2777 mShowWhenLocked = showWhenLocked;
Kevin Chyn44639482017-10-09 18:34:41 -07002778 mStackSupervisor.ensureActivitiesVisibleLocked(null, 0 /* configChanges */,
2779 false /* preserveWindows */);
chaviw59b98852017-06-13 12:05:44 -07002780 }
2781
2782 /**
chaviw2c500982018-01-04 17:05:05 -08002783 * @return true if the activity windowing mode is not
2784 * {@link android.app.WindowConfiguration#WINDOWING_MODE_PINNED} and activity contains
2785 * windows that have {@link LayoutParams#FLAG_SHOW_WHEN_LOCKED} set or if the activity
2786 * has set {@link #mShowWhenLocked}.
2787 * Multi-windowing mode will be exited if true is returned.
chaviw59b98852017-06-13 12:05:44 -07002788 */
2789 boolean canShowWhenLocked() {
chaviw2c500982018-01-04 17:05:05 -08002790 return !inPinnedWindowingMode() && (mShowWhenLocked
Wale Ogunwale2cca8622017-12-11 08:40:13 -08002791 || service.mWindowManager.containsShowWhenLockedWindow(appToken));
chaviw59b98852017-06-13 12:05:44 -07002792 }
2793
2794 void setTurnScreenOn(boolean turnScreenOn) {
2795 mTurnScreenOn = turnScreenOn;
2796 }
2797
2798 /**
2799 * Determines whether this ActivityRecord can turn the screen on. It checks whether the flag
2800 * {@link #mTurnScreenOn} is set and checks whether the ActivityRecord should be visible
2801 * depending on Keyguard state
2802 *
2803 * @return true if the screen can be turned on, false otherwise.
2804 */
2805 boolean canTurnScreenOn() {
2806 final ActivityStack stack = getStack();
2807 return mTurnScreenOn && stack != null &&
2808 stack.checkKeyguardVisibility(this, true /* shouldBeVisible */, true /* isTop */);
2809 }
2810
2811 boolean getTurnScreenOnFlag() {
2812 return mTurnScreenOn;
2813 }
2814
2815 boolean isTopRunningActivity() {
2816 return mStackSupervisor.topRunningActivityLocked() == this;
2817 }
2818
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002819 void registerRemoteAnimations(RemoteAnimationDefinition definition) {
2820 mWindowContainerController.registerRemoteAnimations(definition);
2821 }
2822
Craig Mautnerf81b90872013-02-26 13:02:43 -08002823 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002824 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002825 if (stringName != null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08002826 return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) +
Craig Mautnerf3333272013-04-22 10:55:53 -07002827 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002828 }
2829 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -08002830 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002831 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -07002832 sb.append(" u");
2833 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002834 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002835 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -08002836 stringName = sb.toString();
2837 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002838 }
Steven Timotius4346f0a2017-09-12 11:07:21 -07002839
2840 void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
2841 final long token = proto.start(fieldId);
2842 proto.write(HASH_CODE, System.identityHashCode(this));
2843 proto.write(USER_ID, userId);
2844 proto.write(TITLE, intent.getComponent().flattenToShortString());
2845 proto.end(token);
2846 }
2847
2848 public void writeToProto(ProtoOutputStream proto, long fieldId) {
2849 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002850 super.writeToProto(proto, CONFIGURATION_CONTAINER, false /* trim */);
Steven Timotius4346f0a2017-09-12 11:07:21 -07002851 writeIdentifierToProto(proto, IDENTIFIER);
2852 proto.write(STATE, state.toString());
2853 proto.write(VISIBLE, visible);
2854 proto.write(FRONT_OF_TASK, frontOfTask);
2855 if (app != null) {
2856 proto.write(PROC_ID, app.pid);
2857 }
2858 proto.end(token);
2859 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860}