blob: 11590d6ca83b433085e1338409ccb6526fcc95d4 [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;
24import static android.app.ActivityOptions.ANIM_SCALE_UP;
25import static android.app.ActivityOptions.ANIM_SCENE_TRANSITION;
26import static android.app.ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN;
27import static android.app.ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP;
28import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN;
29import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_UP;
Winson Chung59fda9e2017-01-20 16:14:51 -080030import static android.app.AppOpsManager.MODE_ALLOWED;
Winson Chungf4ac0632017-03-17 12:34:12 -070031import static android.app.AppOpsManager.OP_PICTURE_IN_PICTURE;
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -070032import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT;
33import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
34import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -070035import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
36import static android.app.WindowConfiguration.activityTypeToString;
Ruben Brunkf53497c2017-03-27 20:26:17 -070037import static android.content.Intent.ACTION_MAIN;
38import static android.content.Intent.CATEGORY_HOME;
39import static android.content.Intent.CATEGORY_LAUNCHER;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080040import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
Bryce Leeb7c9b802017-05-02 14:20:24 -070041import static android.content.Intent.FLAG_ACTIVITY_NO_HISTORY;
Andrii Kulian21713ac2016-10-12 22:05:05 -070042import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
43import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT;
44import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
45import static android.content.pm.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
Zak Cohen90e7116742017-01-29 12:59:23 -080046import static android.content.pm.ActivityInfo.CONFIG_UI_MODE;
Wale Ogunwale822e5122017-07-26 06:02:24 -070047import static android.content.pm.ActivityInfo.CONFIG_WINDOW_CONFIGURATION;
Jorim Jaggi02886a82016-12-06 09:10:06 -080048import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080049import static android.content.pm.ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
50import static android.content.pm.ActivityInfo.FLAG_IMMERSIVE;
51import static android.content.pm.ActivityInfo.FLAG_MULTIPROCESS;
Jorim Jaggie7d2b852017-08-28 17:55:15 +020052import static android.content.pm.ActivityInfo.FLAG_NO_HISTORY;
Chong Zhang87761972016-08-22 13:53:24 -070053import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS;
Jorim Jaggie7d2b852017-08-28 17:55:15 +020054import static android.content.pm.ActivityInfo.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080055import static android.content.pm.ActivityInfo.FLAG_STATE_NOT_NEEDED;
chaviw59b98852017-06-13 12:05:44 -070056import static android.content.pm.ActivityInfo.FLAG_TURN_SCREEN_ON;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080057import static android.content.pm.ActivityInfo.LAUNCH_MULTIPLE;
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -080058import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE;
59import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080060import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP;
Charles He2bf28322017-10-12 22:24:49 +010061import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS;
62import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT;
63import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
64import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER;
Ruben Brunkf53497c2017-03-27 20:26:17 -070065import static android.content.pm.ActivityInfo.PERSIST_ACROSS_REBOOTS;
66import static android.content.pm.ActivityInfo.PERSIST_ROOT_ONLY;
Wale Ogunwaledf241e92016-10-13 15:14:21 -070067import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
Jorim Jaggicd13d332016-04-27 15:40:20 -070068import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
Wale Ogunwale72a73e32016-10-13 12:16:39 -070069import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Wale Ogunwaledf241e92016-10-13 15:14:21 -070070import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
Wale Ogunwaled4b1d1e2017-04-10 06:35:59 -070071import static android.content.pm.ActivityInfo.isFixedOrientationLandscape;
72import static android.content.pm.ActivityInfo.isFixedOrientationPortrait;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -070073import static android.content.res.Configuration.EMPTY;
Wale Ogunwalee610d3d2017-04-25 10:23:48 -070074import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
75import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
Ruben Brunkf53497c2017-03-27 20:26:17 -070076import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
Zak Cohen90e7116742017-01-29 12:59:23 -080077import static android.content.res.Configuration.UI_MODE_TYPE_VR_HEADSET;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080078import static android.os.Build.VERSION_CODES.HONEYCOMB;
Zak Cohen90e7116742017-01-29 12:59:23 -080079import static android.os.Build.VERSION_CODES.O;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080080import static android.os.Process.SYSTEM_UID;
Ruben Brunkf53497c2017-03-27 20:26:17 -070081import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080082import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION;
Andrii Kulian21713ac2016-10-12 22:05:05 -070083import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE;
Andrii Kulian21713ac2016-10-12 22:05:05 -070084import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080085import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH;
Andrii Kulian21713ac2016-10-12 22:05:05 -070086import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBILITY;
87import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONFIGURATION;
88import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SAVED_STATE;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080089import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES;
90import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH;
Andrii Kulian21713ac2016-10-12 22:05:05 -070091import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBILITY;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080092import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
93import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Ruben Brunkf53497c2017-03-27 20:26:17 -070094import static com.android.server.am.ActivityStack.ActivityState.DESTROYED;
95import static com.android.server.am.ActivityStack.ActivityState.DESTROYING;
96import static com.android.server.am.ActivityStack.ActivityState.INITIALIZING;
97import static com.android.server.am.ActivityStack.ActivityState.PAUSED;
98import static com.android.server.am.ActivityStack.ActivityState.PAUSING;
99import static com.android.server.am.ActivityStack.ActivityState.RESUMED;
100import static com.android.server.am.ActivityStack.ActivityState.STOPPED;
101import static com.android.server.am.ActivityStack.ActivityState.STOPPING;
102import static com.android.server.am.ActivityStack.LAUNCH_TICK;
103import static com.android.server.am.ActivityStack.LAUNCH_TICK_MSG;
104import static com.android.server.am.ActivityStack.PAUSE_TIMEOUT_MSG;
105import static com.android.server.am.ActivityStack.STOP_TIMEOUT_MSG;
106import static com.android.server.am.EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME;
107import static com.android.server.am.EventLogTags.AM_ACTIVITY_LAUNCH_TIME;
108import static com.android.server.am.EventLogTags.AM_RELAUNCH_ACTIVITY;
109import static com.android.server.am.EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY;
110import static com.android.server.am.TaskPersister.DEBUG;
111import static com.android.server.am.TaskPersister.IMAGE_EXTENSION;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800112import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
Steven Timotius4346f0a2017-09-12 11:07:21 -0700113import static com.android.server.am.proto.ActivityRecordProto.CONFIGURATION_CONTAINER;
114import static com.android.server.am.proto.ActivityRecordProto.FRONT_OF_TASK;
115import static com.android.server.am.proto.ActivityRecordProto.IDENTIFIER;
116import static com.android.server.am.proto.ActivityRecordProto.PROC_ID;
117import static com.android.server.am.proto.ActivityRecordProto.STATE;
118import static com.android.server.am.proto.ActivityRecordProto.VISIBLE;
Adrian Roose99bc052017-11-20 17:55:31 +0100119import static com.android.server.policy.WindowManagerPolicy.NAV_BAR_LEFT;
Steven Timotius4346f0a2017-09-12 11:07:21 -0700120import static com.android.server.wm.proto.IdentifierProto.HASH_CODE;
121import static com.android.server.wm.proto.IdentifierProto.TITLE;
122import static com.android.server.wm.proto.IdentifierProto.USER_ID;
123
Ruben Brunkf53497c2017-03-27 20:26:17 -0700124import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
125import static org.xmlpull.v1.XmlPullParser.END_TAG;
126import static org.xmlpull.v1.XmlPullParser.START_TAG;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800127
Andrii Kulian21713ac2016-10-12 22:05:05 -0700128import android.annotation.NonNull;
Craig Mautner21d24a22014-04-23 11:45:37 -0700129import android.app.ActivityManager.TaskDescription;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700130import android.app.ActivityOptions;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800131import android.app.PendingIntent;
Winson Chung709904f2017-04-25 11:00:48 -0700132import android.app.PictureInPictureParams;
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800133import android.app.ResultInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134import android.content.ComponentName;
135import android.content.Intent;
136import android.content.pm.ActivityInfo;
137import android.content.pm.ApplicationInfo;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700138import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139import android.content.res.Configuration;
140import android.graphics.Bitmap;
Winson Chungaa7fa012017-05-24 15:50:06 -0700141import android.graphics.GraphicBuffer;
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700142import android.graphics.Rect;
Bryce Lee39791592017-04-26 09:29:12 -0700143import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144import android.os.Bundle;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700145import android.os.Debug;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800146import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147import android.os.Message;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800148import android.os.PersistableBundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149import android.os.Process;
Dianne Hackborn39792d22010-08-19 18:01:52 -0700150import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151import android.os.SystemClock;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800152import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700153import android.os.UserHandle;
Bryce Lee8558ec72017-08-17 15:37:26 -0700154import android.os.storage.StorageManager;
Amith Yamasani0af6fa72016-01-17 15:36:19 -0800155import android.service.voice.IVoiceInteractionSession;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156import android.util.EventLog;
157import android.util.Log;
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700158import android.util.MergedConfiguration;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700159import android.util.Slog;
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700160import android.util.TimeUtils;
Steven Timotius4346f0a2017-09-12 11:07:21 -0700161import android.util.proto.ProtoOutputStream;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700162import android.view.AppTransitionAnimationSpec;
Jorim Jaggi34795e32017-05-12 17:27:46 +0200163import android.view.IAppTransitionAnimationSpecsFuture;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164import android.view.IApplicationToken;
Jorim Jaggife762342016-10-13 14:33:27 +0200165import android.view.WindowManager.LayoutParams;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700166
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -0700167import com.android.internal.R;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800168import com.android.internal.app.ResolverActivity;
169import com.android.internal.content.ReferrerIntent;
170import com.android.internal.util.XmlUtils;
171import com.android.server.AttributeCache;
Ruben Brunkf53497c2017-03-27 20:26:17 -0700172import com.android.server.AttributeCache.Entry;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800173import com.android.server.am.ActivityStack.ActivityState;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800174import com.android.server.wm.AppWindowContainerController;
175import com.android.server.wm.AppWindowContainerListener;
Wale Ogunwale98d62312017-07-12 09:24:56 -0700176import com.android.server.wm.ConfigurationContainer;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800177import com.android.server.wm.TaskWindowContainerController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178
Jorim Jaggi02886a82016-12-06 09:10:06 -0800179import org.xmlpull.v1.XmlPullParser;
180import org.xmlpull.v1.XmlPullParserException;
181import org.xmlpull.v1.XmlSerializer;
182
Suprabh Shukla23593142015-11-03 17:31:15 -0800183import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -0700184import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185import java.io.PrintWriter;
186import java.lang.ref.WeakReference;
187import java.util.ArrayList;
Todd Kennedy39bfee52016-02-24 10:28:21 -0800188import java.util.Arrays;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189import java.util.HashSet;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700190import java.util.List;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700191import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192
193/**
194 * An entry in the history stack, representing an activity.
195 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700196final class ActivityRecord extends ConfigurationContainer implements AppWindowContainerListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800197 private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityRecord" : TAG_AM;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700198 private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION;
199 private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700200 private static final String TAG_STATES = TAG + POSTFIX_STATES;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700201 private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700202 private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY;
Winson Chung16e185e2017-11-07 08:30:54 -0800203 // TODO(b/67864419): Remove once recents component is overridden
204 private static final String LEGACY_RECENTS_PACKAGE_NAME = "com.android.systemui.recents";
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800205
Wale Ogunwale3ab9a272015-03-16 09:55:45 -0700206 private static final boolean SHOW_ACTIVITY_START_TIME = true;
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700207
Craig Mautner21d24a22014-04-23 11:45:37 -0700208 private static final String ATTR_ID = "id";
209 private static final String TAG_INTENT = "intent";
210 private static final String ATTR_USERID = "user_id";
211 private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle";
212 private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700213 private static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package";
Craig Mautner21d24a22014-04-23 11:45:37 -0700214 private static final String ATTR_RESOLVEDTYPE = "resolved_type";
215 private static final String ATTR_COMPONENTSPECIFIED = "component_specified";
Dianne Hackborn337abb32014-09-24 12:44:29 -0700216 static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_";
Craig Mautner21d24a22014-04-23 11:45:37 -0700217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 final ActivityManagerService service; // owner
Dianne Hackbornbe707852011-11-11 14:32:10 -0800219 final IApplicationToken.Stub appToken; // window manager token
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800220 AppWindowContainerController mWindowContainerController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 final ActivityInfo info; // all about me
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700222 final ApplicationInfo appInfo; // information about activity's app
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800223 final int launchedFromPid; // always the pid who started the activity.
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700224 final int launchedFromUid; // always the uid who started the activity.
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800225 final String launchedFromPackage; // always the package who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -0700226 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 final Intent intent; // the original intent that generated us
228 final ComponentName realActivity; // the intent component, or target of an alias.
229 final String shortComponentName; // the short component name of the intent
230 final String resolvedType; // as per original caller;
231 final String packageName; // the package implementing intent's component
232 final String processName; // process where this component wants to run
233 final String taskAffinity; // as per ActivityInfo.taskAffinity
234 final boolean stateNotNeeded; // As per ActivityInfo.flags
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -0700235 boolean fullscreen; // The activity is opaque and fills the entire space of this task.
236 // TODO: See if it possible to combine this with the fullscreen field.
237 final boolean hasWallpaper; // Has a wallpaper window as a background.
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800238 final boolean noDisplay; // activity is not displayed?
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800239 private final boolean componentSpecified; // did caller specify an explicit component?
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700240 final boolean rootVoiceInteraction; // was this the root activity of a voice interaction?
Craig Mautner86d67a42013-05-14 10:34:38 -0700241
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800242 private CharSequence nonLocalizedLabel; // the label information from the package mgr.
243 private int labelRes; // the label information from the package mgr.
244 private int icon; // resource identifier of activity's icon.
245 private int logo; // resource identifier of activity's logo.
246 private int theme; // resource identifier of activity's theme.
247 private int realTheme; // actual theme resource we will use, never 0.
248 private int windowFlags; // custom window flags for preview window.
Bryce Leeaf691c02017-03-20 14:20:22 -0700249 private TaskRecord task; // the task this is in.
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800250 private long createTime = System.currentTimeMillis();
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700251 long displayStartTime; // when we started launching this activity
252 long fullyDrawnStartTime; // when we started launching this activity
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800253 private long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -0800254 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700255 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700256 long pauseTime; // last time we started pausing the activity
257 long launchTickTime; // base time for launch tick messages
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700258 // Last configuration reported to the activity in the client process.
259 private MergedConfiguration mLastReportedConfiguration;
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800260 private int mLastReportedDisplayId;
Winson Chung609e1e92017-05-08 10:52:12 -0700261 private boolean mLastReportedMultiWindowMode;
262 private boolean mLastReportedPictureInPictureMode;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700263 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700264 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 final String resultWho; // additional identifier for use by resultTo.
266 final int requestCode; // code given by requester (resultTo)
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800267 ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800269 ArrayList<ReferrerIntent> newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700270 ActivityOptions pendingOptions; // most recently given options
George Mount6ba042b2014-07-28 11:12:28 -0700271 ActivityOptions returningOptions; // options that are coming back via convertToTranslucent
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700272 AppTimeTracker appTimeTracker; // set if we are tracking the time in this app/task/activity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700274 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700275 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700276 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 Bundle icicle; // last saved activity state
Craig Mautnera0026042014-04-23 11:45:37 -0700278 PersistableBundle persistentState; // last persistently saved activity state
Wale Ogunwale66e16852017-10-19 13:35:52 -0700279 // TODO: See if this is still needed.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 boolean frontOfTask; // is this the root activity of its task?
281 boolean launchFailed; // set if a launched failed, to abort on 2nd try
282 boolean haveState; // have we gotten the last activity state?
283 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700284 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 boolean finishing; // activity in pending finish list?
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800286 boolean deferRelaunchUntilPaused; // relaunch of activity is being deferred until pause is
287 // completed
288 boolean preserveWindowOnDeferredRelaunch; // activity windows are preserved on deferred relaunch
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 int configChangeFlags; // which config values have changed
Wale Ogunwaleec950642017-04-25 07:44:21 -0700290 private boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 int launchMode; // the launch mode activity attribute.
Charles He2bf28322017-10-12 22:24:49 +0100292 int lockTaskLaunchMode; // the lockTaskMode manifest attribute, subject to override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 boolean visible; // does this activity's window need to be shown?
Jorim Jaggi241ae102016-11-02 21:57:33 -0700294 boolean visibleIgnoringKeyguard; // is this activity visible, ignoring the fact that Keyguard
295 // might hide this activity?
Wale Ogunwaleec950642017-04-25 07:44:21 -0700296 private boolean mDeferHidingClient; // If true we told WM to defer reporting to the client
297 // process that it is hidden.
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800298 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299 boolean nowVisible; // is this activity's window visible?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300 boolean idle; // has the activity gone idle?
301 boolean hasBeenLaunched;// has this activity ever been launched?
302 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400303 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400304 boolean forceNewConfig; // force re-create with new config next time
Winson Chungf7e03e12017-08-22 11:32:16 -0700305 boolean supportsEnterPipOnTaskSwitch; // This flag is set by the system to indicate that the
306 // activity can enter picture in picture while pausing (only when switching to another task)
Winson Chung709904f2017-04-25 11:00:48 -0700307 PictureInPictureParams pictureInPictureArgs = new PictureInPictureParams.Builder().build();
308 // The PiP params used when deferring the entering of picture-in-picture.
Dianne Hackborn07981492013-01-28 11:36:23 -0800309 int launchCount; // count of launches since last state
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800310 long lastLaunchTime; // time of last launch of this activity
Ruben Brunke24b9a62016-02-16 21:38:24 -0800311 ComponentName requestedVrComponent; // the requested component for handling VR mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700313 String stringName; // for caching of toString().
Craig Mautnerde4ef022013-04-07 19:01:33 -0700314
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700315 private boolean inHistory; // are we in the history stack?
Craig Mautnerde4ef022013-04-07 19:01:33 -0700316 final ActivityStackSupervisor mStackSupervisor;
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800317
318 static final int STARTING_WINDOW_NOT_SHOWN = 0;
319 static final int STARTING_WINDOW_SHOWN = 1;
320 static final int STARTING_WINDOW_REMOVED = 2;
321 int mStartingWindowState = STARTING_WINDOW_NOT_SHOWN;
Wale Ogunwale3b232392016-05-13 15:37:13 -0700322 boolean mTaskOverlay = false; // Task is always on-top of other activities in the task.
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800323
Craig Mautner21d24a22014-04-23 11:45:37 -0700324 TaskDescription taskDescription; // the recents information for this activity
Craig Mautnerbb742462014-07-07 15:28:55 -0700325 boolean mLaunchTaskBehind; // this activity is actively being launched with
326 // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed.
Craig Mautner2fbd7542014-03-21 09:34:07 -0700327
Filip Gruszczynski23493322015-07-29 17:02:59 -0700328 // These configurations are collected from application's resources based on size-sensitive
329 // qualifiers. For example, layout-w800dp will be added to mHorizontalSizeConfigurations as 800
330 // and drawable-sw400dp will be added to both as 400.
331 private int[] mVerticalSizeConfigurations;
332 private int[] mHorizontalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700333 private int[] mSmallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700334
Amith Yamasani0af6fa72016-01-17 15:36:19 -0800335 boolean pendingVoiceInteractionStart; // Waiting for activity-invoked voice session
336 IVoiceInteractionSession voiceSession; // Voice interaction session for this activity
337
Robert Carrd2265122016-08-05 10:25:21 -0700338 // A hint to override the window specified rotation animation, or -1
339 // to use the window specified value. We use this so that
340 // we can select the right animation in the cases of starting
341 // windows, where the app hasn't had time to set a value
342 // on the window.
343 int mRotationAnimationHint = -1;
Robert Carrfd10cd12016-06-29 16:41:50 -0700344
chaviw59b98852017-06-13 12:05:44 -0700345 private boolean mShowWhenLocked;
346 private boolean mTurnScreenOn;
347
Andrii Kulian21713ac2016-10-12 22:05:05 -0700348 /**
349 * Temp configs used in {@link #ensureActivityConfigurationLocked(int, boolean)}
350 */
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700351 private final Configuration mTmpConfig = new Configuration();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700352 private final Rect mTmpBounds = new Rect();
Andrii Kulian21713ac2016-10-12 22:05:05 -0700353
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800354 private static String startingWindowStateToString(int state) {
355 switch (state) {
356 case STARTING_WINDOW_NOT_SHOWN:
357 return "STARTING_WINDOW_NOT_SHOWN";
358 case STARTING_WINDOW_SHOWN:
359 return "STARTING_WINDOW_SHOWN";
360 case STARTING_WINDOW_REMOVED:
361 return "STARTING_WINDOW_REMOVED";
362 default:
363 return "unknown state=" + state;
364 }
365 }
366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700368 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700369 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
370 pw.print(" processName="); pw.println(processName);
371 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Craig Mautnere11f2b72013-04-01 12:37:17 -0700372 pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800373 pw.print(" userId="); pw.println(userId);
374 pw.print(prefix); pw.print("app="); pw.println(app);
375 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700376 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
377 pw.print(" task="); pw.println(task);
378 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700379 pw.print(prefix); pw.print("realActivity=");
380 pw.println(realActivity.flattenToShortString());
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700381 if (appInfo != null) {
382 pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir);
383 if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) {
384 pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir);
385 }
386 pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir);
Todd Kennedy39bfee52016-02-24 10:28:21 -0800387 if (appInfo.splitSourceDirs != null) {
388 pw.print(prefix); pw.print("splitDir=");
389 pw.println(Arrays.toString(appInfo.splitSourceDirs));
390 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800391 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700392 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
393 pw.print(" componentSpecified="); pw.print(componentSpecified);
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -0700394 pw.print(" mActivityType="); pw.println(
395 activityTypeToString(getActivityType()));
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700396 if (rootVoiceInteraction) {
397 pw.print(prefix); pw.print("rootVoiceInteraction="); pw.println(rootVoiceInteraction);
398 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800399 pw.print(prefix); pw.print("compat="); pw.print(compat);
400 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
401 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
402 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700403 pw.println(prefix + "mLastReportedConfigurations:");
404 mLastReportedConfiguration.dump(pw, prefix + " ");
405
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700406 pw.print(prefix); pw.print("CurrentConfiguration="); pw.println(getConfiguration());
407 if (!getOverrideConfiguration().equals(EMPTY)) {
408 pw.println(prefix + "OverrideConfiguration=" + getOverrideConfiguration());
409 }
Bryce Leef3c6a472017-11-14 14:53:06 -0800410 if (!matchParentBounds()) {
411 pw.println(prefix + "bounds=" + getBounds());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700412 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700413 if (resultTo != null || resultWho != null) {
414 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
415 pw.print(" resultWho="); pw.print(resultWho);
416 pw.print(" resultCode="); pw.println(requestCode);
417 }
Craig Mautner29c58ca2014-10-14 16:17:06 -0700418 if (taskDescription != null) {
419 final String iconFilename = taskDescription.getIconFilename();
420 if (iconFilename != null || taskDescription.getLabel() != null ||
421 taskDescription.getPrimaryColor() != 0) {
422 pw.print(prefix); pw.print("taskDescription:");
Craig Mautner29c58ca2014-10-14 16:17:06 -0700423 pw.print(" label=\""); pw.print(taskDescription.getLabel());
424 pw.print("\"");
Matthew Ng54bc9422017-10-02 17:16:28 -0700425 pw.print(" icon="); pw.print(taskDescription.getInMemoryIcon() != null
426 ? taskDescription.getInMemoryIcon().getByteCount() + " bytes"
427 : "null");
428 pw.print(" iconResource="); pw.print(taskDescription.getIconResource());
429 pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename());
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200430 pw.print(" primaryColor=");
Craig Mautner29c58ca2014-10-14 16:17:06 -0700431 pw.println(Integer.toHexString(taskDescription.getPrimaryColor()));
Wale Ogunwale822e5122017-07-26 06:02:24 -0700432 pw.print(prefix + " backgroundColor=");
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200433 pw.println(Integer.toHexString(taskDescription.getBackgroundColor()));
Wale Ogunwale822e5122017-07-26 06:02:24 -0700434 pw.print(prefix + " statusBarColor=");
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200435 pw.println(Integer.toHexString(taskDescription.getStatusBarColor()));
Wale Ogunwale822e5122017-07-26 06:02:24 -0700436 pw.print(prefix + " navigationBarColor=");
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200437 pw.println(Integer.toHexString(taskDescription.getNavigationBarColor()));
Craig Mautner29c58ca2014-10-14 16:17:06 -0700438 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700439 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700440 if (results != null) {
441 pw.print(prefix); pw.print("results="); pw.println(results);
442 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700443 if (pendingResults != null && pendingResults.size() > 0) {
444 pw.print(prefix); pw.println("Pending Results:");
445 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
446 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
447 pw.print(prefix); pw.print(" - ");
448 if (pir == null) {
449 pw.println("null");
450 } else {
451 pw.println(pir);
452 pir.dump(pw, prefix + " ");
453 }
454 }
455 }
456 if (newIntents != null && newIntents.size() > 0) {
457 pw.print(prefix); pw.println("Pending New Intents:");
458 for (int i=0; i<newIntents.size(); i++) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800459 Intent intent = newIntents.get(i);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700460 pw.print(prefix); pw.print(" - ");
461 if (intent == null) {
462 pw.println("null");
463 } else {
464 pw.println(intent.toShortString(false, true, false, true));
465 }
466 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700467 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700468 if (pendingOptions != null) {
469 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
470 }
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700471 if (appTimeTracker != null) {
472 appTimeTracker.dumpWithHeader(pw, prefix, false);
473 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700474 if (uriPermissions != null) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700475 uriPermissions.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700476 }
477 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800478 pw.print(" launchCount="); pw.print(launchCount);
479 pw.print(" lastLaunchTime=");
480 if (lastLaunchTime == 0) pw.print("0");
481 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
482 pw.println();
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700483 pw.print(prefix); pw.print("haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700484 pw.print(" icicle="); pw.println(icicle);
485 pw.print(prefix); pw.print("state="); pw.print(state);
486 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700487 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700488 pw.print(" finishing="); pw.println(finishing);
489 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
490 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700491 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800492 pw.print(" sleeping="); pw.print(sleeping);
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800493 pw.print(" idle="); pw.print(idle);
494 pw.print(" mStartingWindowState=");
495 pw.println(startingWindowStateToString(mStartingWindowState));
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800496 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
497 pw.print(" noDisplay="); pw.print(noDisplay);
498 pw.print(" immersive="); pw.print(immersive);
499 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800500 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400501 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700502 pw.print(prefix); pw.print("mActivityType=");
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -0700503 pw.println(activityTypeToString(getActivityType()));
Ruben Brunke24b9a62016-02-16 21:38:24 -0800504 if (requestedVrComponent != null) {
505 pw.print(prefix);
506 pw.print("requestedVrComponent=");
507 pw.println(requestedVrComponent);
508 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700509 if (displayStartTime != 0 || startTime != 0) {
510 pw.print(prefix); pw.print("displayStartTime=");
511 if (displayStartTime == 0) pw.print("0");
512 else TimeUtils.formatDuration(displayStartTime, now, pw);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700513 pw.print(" startTime=");
514 if (startTime == 0) pw.print("0");
515 else TimeUtils.formatDuration(startTime, now, pw);
516 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700517 }
Bryce Lee4a194382017-04-04 14:32:48 -0700518 final boolean waitingVisible =
519 mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(this);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800520 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700521 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800522 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700523 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700524 if (lastVisibleTime == 0) pw.print("0");
525 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
526 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700527 }
Wale Ogunwaleec950642017-04-25 07:44:21 -0700528 if (mDeferHidingClient) {
529 pw.println(prefix + "mDeferHidingClient=" + mDeferHidingClient);
530 }
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800531 if (deferRelaunchUntilPaused || configChangeFlags != 0) {
532 pw.print(prefix); pw.print("deferRelaunchUntilPaused="); pw.print(deferRelaunchUntilPaused);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700533 pw.print(" configChangeFlags=");
534 pw.println(Integer.toHexString(configChangeFlags));
535 }
536 if (connections != null) {
537 pw.print(prefix); pw.print("connections="); pw.println(connections);
538 }
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800539 if (info != null) {
540 pw.println(prefix + "resizeMode=" + ActivityInfo.resizeModeToString(info.resizeMode));
Winson Chung609e1e92017-05-08 10:52:12 -0700541 pw.println(prefix + "mLastReportedMultiWindowMode=" + mLastReportedMultiWindowMode
542 + " mLastReportedPictureInPictureMode=" + mLastReportedPictureInPictureMode);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700543 if (info.supportsPictureInPicture()) {
544 pw.println(prefix + "supportsPictureInPicture=" + info.supportsPictureInPicture());
Winson Chungf7e03e12017-08-22 11:32:16 -0700545 pw.println(prefix + "supportsEnterPipOnTaskSwitch: "
546 + supportsEnterPipOnTaskSwitch);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700547 }
548 if (info.maxAspectRatio != 0) {
549 pw.println(prefix + "maxAspectRatio=" + info.maxAspectRatio);
550 }
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800551 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 }
553
Andrii Kulian21713ac2016-10-12 22:05:05 -0700554 private boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700555 return crossesSizeThreshold(mHorizontalSizeConfigurations, firstDp, secondDp);
556 }
557
Andrii Kulian21713ac2016-10-12 22:05:05 -0700558 private boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700559 return crossesSizeThreshold(mVerticalSizeConfigurations, firstDp, secondDp);
560 }
561
Andrii Kulian21713ac2016-10-12 22:05:05 -0700562 private boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700563 return crossesSizeThreshold(mSmallestSizeConfigurations, firstDp, secondDp);
564 }
565
Filip Gruszczynski23493322015-07-29 17:02:59 -0700566 /**
567 * The purpose of this method is to decide whether the activity needs to be relaunched upon
568 * changing its size. In most cases the activities don't need to be relaunched, if the resize
569 * is small, all the activity content has to do is relayout itself within new bounds. There are
570 * cases however, where the activity's content would be completely changed in the new size and
571 * the full relaunch is required.
572 *
573 * The activity will report to us vertical and horizontal thresholds after which a relaunch is
574 * required. These thresholds are collected from the application resource qualifiers. For
575 * example, if application has layout-w600dp resource directory, then it needs a relaunch when
576 * we resize from width of 650dp to 550dp, as it crosses the 600dp threshold. However, if
577 * it resizes width from 620dp to 700dp, it won't be relaunched as it stays on the same side
578 * of the threshold.
579 */
580 private static boolean crossesSizeThreshold(int[] thresholds, int firstDp,
581 int secondDp) {
582 if (thresholds == null) {
583 return false;
584 }
585 for (int i = thresholds.length - 1; i >= 0; i--) {
586 final int threshold = thresholds[i];
587 if ((firstDp < threshold && secondDp >= threshold)
588 || (firstDp >= threshold && secondDp < threshold)) {
589 return true;
590 }
591 }
592 return false;
593 }
594
Andrii Kulian21713ac2016-10-12 22:05:05 -0700595 void setSizeConfigurations(int[] horizontalSizeConfiguration,
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700596 int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700597 mHorizontalSizeConfigurations = horizontalSizeConfiguration;
598 mVerticalSizeConfigurations = verticalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700599 mSmallestSizeConfigurations = smallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700600 }
601
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800602 private void scheduleActivityMovedToDisplay(int displayId, Configuration config) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800603 if (app == null || app.thread == null) {
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800604 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.w(TAG,
605 "Can't report activity moved to display - client not running, activityRecord="
606 + this + ", displayId=" + displayId);
Wale Ogunwale22e25262016-02-01 10:32:02 -0800607 return;
608 }
609 try {
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800610 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
611 "Reporting activity moved to display" + ", activityRecord=" + this
612 + ", displayId=" + displayId + ", config=" + config);
Chong Zhang6be533e2016-06-17 16:24:21 -0700613
Andrii Kulianb047b8b2017-02-08 18:38:26 -0800614 app.thread.scheduleActivityMovedToDisplay(appToken, displayId,
615 new Configuration(config));
616 } catch (RemoteException e) {
617 // If process died, whatever.
618 }
619 }
620
621 private void scheduleConfigurationChanged(Configuration config) {
622 if (app == null || app.thread == null) {
623 if (DEBUG_CONFIGURATION) Slog.w(TAG,
624 "Can't report activity configuration update - client not running"
625 + ", activityRecord=" + this);
626 return;
627 }
628 try {
629 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + this + ", config: "
630 + config);
631
632 app.thread.scheduleActivityConfigurationChanged(appToken, new Configuration(config));
Wale Ogunwale22e25262016-02-01 10:32:02 -0800633 } catch (RemoteException e) {
634 // If process died, whatever.
635 }
636 }
637
Winson Chung5af42fc2017-03-24 17:11:33 -0700638 void updateMultiWindowMode() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700639 if (task == null || task.getStack() == null || app == null || app.thread == null) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800640 return;
641 }
Winson Chung5af42fc2017-03-24 17:11:33 -0700642
643 // An activity is considered to be in multi-window mode if its task isn't fullscreen.
Bryce Leef3c6a472017-11-14 14:53:06 -0800644 final boolean inMultiWindowMode = task.inMultiWindowMode();
Winson Chung609e1e92017-05-08 10:52:12 -0700645 if (inMultiWindowMode != mLastReportedMultiWindowMode) {
646 mLastReportedMultiWindowMode = inMultiWindowMode;
Winson Chung5af42fc2017-03-24 17:11:33 -0700647 scheduleMultiWindowModeChanged(getConfiguration());
648 }
649 }
650
651 private void scheduleMultiWindowModeChanged(Configuration overrideConfig) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800652 try {
Winson Chung609e1e92017-05-08 10:52:12 -0700653 app.thread.scheduleMultiWindowModeChanged(appToken, mLastReportedMultiWindowMode,
Winson Chung5af42fc2017-03-24 17:11:33 -0700654 overrideConfig);
Wale Ogunwale22e25262016-02-01 10:32:02 -0800655 } catch (Exception e) {
656 // If process died, I don't care.
657 }
658 }
659
Winson Chungab76bbc2017-08-14 13:33:51 -0700660 void updatePictureInPictureMode(Rect targetStackBounds, boolean forceUpdate) {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700661 if (task == null || task.getStack() == null || app == null || app.thread == null) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800662 return;
663 }
Winson Chung5af42fc2017-03-24 17:11:33 -0700664
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700665 final boolean inPictureInPictureMode = inPinnedWindowingMode() && targetStackBounds != null;
Winson Chungab76bbc2017-08-14 13:33:51 -0700666 if (inPictureInPictureMode != mLastReportedPictureInPictureMode || forceUpdate) {
Winson Chung5af42fc2017-03-24 17:11:33 -0700667 // Picture-in-picture mode changes also trigger a multi-window mode change as well, so
668 // update that here in order
Winson Chung609e1e92017-05-08 10:52:12 -0700669 mLastReportedPictureInPictureMode = inPictureInPictureMode;
670 mLastReportedMultiWindowMode = inPictureInPictureMode;
Winson Chung5af42fc2017-03-24 17:11:33 -0700671 final Configuration newConfig = task.computeNewOverrideConfigurationForBounds(
672 targetStackBounds, null);
673 schedulePictureInPictureModeChanged(newConfig);
674 scheduleMultiWindowModeChanged(newConfig);
675 }
676 }
677
678 private void schedulePictureInPictureModeChanged(Configuration overrideConfig) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800679 try {
Winson Chung609e1e92017-05-08 10:52:12 -0700680 app.thread.schedulePictureInPictureModeChanged(appToken,
Winson Chungab76bbc2017-08-14 13:33:51 -0700681 mLastReportedPictureInPictureMode, overrideConfig);
Wale Ogunwale22e25262016-02-01 10:32:02 -0800682 } catch (Exception e) {
683 // If process died, no one cares.
Filip Gruszczynskica664812015-12-04 12:43:36 -0800684 }
685 }
686
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700687 @Override
688 protected int getChildCount() {
689 // {@link ActivityRecord} is a leaf node and has no children.
690 return 0;
691 }
692
693 @Override
694 protected ConfigurationContainer getChildAt(int index) {
695 return null;
696 }
697
698 @Override
699 protected ConfigurationContainer getParent() {
Bryce Leeaf691c02017-03-20 14:20:22 -0700700 return getTask();
701 }
702
703 TaskRecord getTask() {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700704 return task;
705 }
706
Bryce Leeaf691c02017-03-20 14:20:22 -0700707 /**
708 * Sets reference to the {@link TaskRecord} the {@link ActivityRecord} will treat as its parent.
709 * Note that this does not actually add the {@link ActivityRecord} as a {@link TaskRecord}
710 * children. However, this method will clean up references to this {@link ActivityRecord} in
711 * {@link ActivityStack}.
712 * @param task The new parent {@link TaskRecord}.
713 */
714 void setTask(TaskRecord task) {
715 setTask(task, false /*reparenting*/);
716 }
717
718 /**
719 * This method should only be called by {@link TaskRecord#removeActivity(ActivityRecord)}.
720 */
721 void setTask(TaskRecord task, boolean reparenting) {
722 // Do nothing if the {@link TaskRecord} is the same as the current {@link getTask}.
723 if (task != null && task == getTask()) {
724 return;
725 }
726
727 final ActivityStack stack = getStack();
728
729 // If the new {@link TaskRecord} is from a different {@link ActivityStack}, remove this
730 // {@link ActivityRecord} from its current {@link ActivityStack}.
731 if (!reparenting && stack != null && (task == null || stack != task.getStack())) {
732 stack.onActivityRemovedFromStack(this);
733 }
734
735 this.task = task;
736
737 if (!reparenting) {
738 onParentChanged();
739 }
740 }
741
Dianne Hackbornbe707852011-11-11 14:32:10 -0800742 static class Token extends IApplicationToken.Stub {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700743 private final WeakReference<ActivityRecord> weakActivity;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700744 private final String name;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800745
Steven Timotiusaf03df62017-07-18 16:56:43 -0700746 Token(ActivityRecord activity, Intent intent) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800747 weakActivity = new WeakReference<>(activity);
Steven Timotiusaf03df62017-07-18 16:56:43 -0700748 name = intent.getComponent().flattenToShortString();
Wale Ogunwale7d701172015-03-11 15:36:30 -0700749 }
750
Andrii Kulian21713ac2016-10-12 22:05:05 -0700751 private static ActivityRecord tokenToActivityRecordLocked(Token token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700752 if (token == null) {
753 return null;
754 }
755 ActivityRecord r = token.weakActivity.get();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700756 if (r == null || r.getStack() == null) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700757 return null;
758 }
759 return r;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800760 }
761
Craig Mautnerde4ef022013-04-07 19:01:33 -0700762 @Override
Dianne Hackbornbe707852011-11-11 14:32:10 -0800763 public String toString() {
764 StringBuilder sb = new StringBuilder(128);
765 sb.append("Token{");
766 sb.append(Integer.toHexString(System.identityHashCode(this)));
767 sb.append(' ');
768 sb.append(weakActivity.get());
769 sb.append('}');
770 return sb.toString();
771 }
Steven Timotiusaf03df62017-07-18 16:56:43 -0700772
773 @Override
774 public String getName() {
775 return name;
776 }
Dianne Hackbornbe707852011-11-11 14:32:10 -0800777 }
778
Wale Ogunwale7d701172015-03-11 15:36:30 -0700779 static ActivityRecord forTokenLocked(IBinder token) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800780 try {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700781 return Token.tokenToActivityRecordLocked((Token)token);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800782 } catch (ClassCastException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800783 Slog.w(TAG, "Bad activity token: " + token, e);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800784 return null;
785 }
786 }
787
Chong Zhang85ee6542015-10-02 13:36:38 -0700788 boolean isResolverActivity() {
789 return ResolverActivity.class.getName().equals(realActivity.getClassName());
Craig Mautnerac6f8432013-07-17 13:24:59 -0700790 }
791
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800792 ActivityRecord(ActivityManagerService _service, ProcessRecord _caller, int _launchedFromPid,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800793 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700795 ActivityRecord _resultTo, String _resultWho, int _reqCode,
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700796 boolean _componentSpecified, boolean _rootVoiceInteraction,
Andrii Kulian94e82d9b02017-07-13 15:33:06 -0700797 ActivityStackSupervisor supervisor, ActivityOptions options,
798 ActivityRecord sourceRecord) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 service = _service;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700800 appToken = new Token(this, _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800801 info = aInfo;
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800802 launchedFromPid = _launchedFromPid;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800803 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800804 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700805 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 intent = _intent;
807 shortComponentName = _intent.getComponent().flattenToShortString();
808 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800809 componentSpecified = _componentSpecified;
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700810 rootVoiceInteraction = _rootVoiceInteraction;
Wale Ogunwalee610d3d2017-04-25 10:23:48 -0700811 mLastReportedConfiguration = new MergedConfiguration(_configuration);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 resultTo = _resultTo;
813 resultWho = _resultWho;
814 requestCode = _reqCode;
Ruben Brunkf53497c2017-03-27 20:26:17 -0700815 state = INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800816 frontOfTask = false;
817 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800818 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700819 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 finishing = false;
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800821 deferRelaunchUntilPaused = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 keysPaused = false;
823 inHistory = false;
Chong Zhanga48ef662015-08-18 19:21:47 -0700824 visible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 nowVisible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826 idle = false;
827 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700828 mStackSupervisor = supervisor;
Robert Carr0f5d7532016-10-17 16:39:17 -0700829
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800830 // This starts out true, since the initial state of an activity is that we have everything,
831 // and we shouldn't never consider it lacking in state to be removed if it dies.
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700832 haveState = true;
833
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800834 // If the class name in the intent doesn't match that of the target, this is
835 // probably an alias. We have to create a new ComponentName object to keep track
836 // of the real activity name, so that FLAG_ACTIVITY_CLEAR_TOP is handled properly.
837 if (aInfo.targetActivity == null
838 || (aInfo.targetActivity.equals(_intent.getComponent().getClassName())
839 && (aInfo.launchMode == LAUNCH_MULTIPLE
840 || aInfo.launchMode == LAUNCH_SINGLE_TOP))) {
841 realActivity = _intent.getComponent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 } else {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800843 realActivity = new ComponentName(aInfo.packageName, aInfo.targetActivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800845 taskAffinity = aInfo.taskAffinity;
846 stateNotNeeded = (aInfo.flags & FLAG_STATE_NOT_NEEDED) != 0;
847 appInfo = aInfo.applicationInfo;
848 nonLocalizedLabel = aInfo.nonLocalizedLabel;
849 labelRes = aInfo.labelRes;
850 if (nonLocalizedLabel == null && labelRes == 0) {
851 ApplicationInfo app = aInfo.applicationInfo;
852 nonLocalizedLabel = app.nonLocalizedLabel;
853 labelRes = app.labelRes;
854 }
855 icon = aInfo.getIconResource();
856 logo = aInfo.getLogoResource();
857 theme = aInfo.getThemeResource();
858 realTheme = theme;
859 if (realTheme == 0) {
860 realTheme = aInfo.applicationInfo.targetSdkVersion < HONEYCOMB
861 ? android.R.style.Theme : android.R.style.Theme_Holo;
862 }
863 if ((aInfo.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
864 windowFlags |= LayoutParams.FLAG_HARDWARE_ACCELERATED;
865 }
866 if ((aInfo.flags & FLAG_MULTIPROCESS) != 0 && _caller != null
867 && (aInfo.applicationInfo.uid == SYSTEM_UID
868 || aInfo.applicationInfo.uid == _caller.info.uid)) {
869 processName = _caller.processName;
870 } else {
871 processName = aInfo.processName;
872 }
873
874 if ((aInfo.flags & FLAG_EXCLUDE_FROM_RECENTS) != 0) {
875 intent.addFlags(FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
876 }
877
878 packageName = aInfo.applicationInfo.packageName;
879 launchMode = aInfo.launchMode;
880
Ruben Brunkf53497c2017-03-27 20:26:17 -0700881 Entry ent = AttributeCache.instance().get(packageName,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800882 realTheme, com.android.internal.R.styleable.Window, userId);
Bryce Leee83f34cd2017-10-31 19:50:54 -0700883
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -0700884 if (ent != null) {
885 fullscreen = !ActivityInfo.isTranslucentOrFloating(ent.array);
886 hasWallpaper = ent.array.getBoolean(R.styleable.Window_windowShowWallpaper, false);
887 noDisplay = ent.array.getBoolean(R.styleable.Window_windowNoDisplay, false);
888 } else {
889 hasWallpaper = false;
890 noDisplay = false;
891 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800892
Winson Chung83471632016-12-13 11:02:12 -0800893 setActivityType(_componentSpecified, _launchedFromUid, _intent, options, sourceRecord);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800894
895 immersive = (aInfo.flags & FLAG_IMMERSIVE) != 0;
896
897 requestedVrComponent = (aInfo.requestedVrComponent == null) ?
898 null : ComponentName.unflattenFromString(aInfo.requestedVrComponent);
chaviw59b98852017-06-13 12:05:44 -0700899
900 mShowWhenLocked = (aInfo.flags & FLAG_SHOW_WHEN_LOCKED) != 0;
901 mTurnScreenOn = (aInfo.flags & FLAG_TURN_SCREEN_ON) != 0;
Charles He2bf28322017-10-12 22:24:49 +0100902
903 mRotationAnimationHint = aInfo.rotationAnimation;
904 lockTaskLaunchMode = aInfo.lockTaskLaunchMode;
905 if (appInfo.isPrivilegedApp() && (lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_ALWAYS
906 || lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_NEVER)) {
907 lockTaskLaunchMode = LOCK_TASK_LAUNCH_MODE_DEFAULT;
908 }
909
910 if (options != null) {
911 pendingOptions = options;
912 mLaunchTaskBehind = options.getLaunchTaskBehind();
913
914 final int rotationAnimation = pendingOptions.getRotationAnimationHint();
915 // Only override manifest supplied option if set.
916 if (rotationAnimation >= 0) {
917 mRotationAnimationHint = rotationAnimation;
918 }
919 final PendingIntent usageReport = pendingOptions.getUsageTimeReport();
920 if (usageReport != null) {
921 appTimeTracker = new AppTimeTracker(usageReport);
922 }
923 final boolean useLockTask = pendingOptions.getLockTaskMode();
924 if (useLockTask && lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_DEFAULT) {
925 lockTaskLaunchMode = LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
926 }
927 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800928 }
929
Dianne Hackborn68a06332017-11-15 17:54:18 -0800930 void setProcess(ProcessRecord proc) {
931 app = proc;
932 final ActivityRecord root = task != null ? task.getRootActivity() : null;
933 if (root == this) {
934 task.setRootProcess(proc);
935 }
936 }
937
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800938 AppWindowContainerController getWindowContainerController() {
939 return mWindowContainerController;
940 }
941
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800942 void createWindowContainer() {
943 if (mWindowContainerController != null) {
944 throw new IllegalArgumentException("Window container=" + mWindowContainerController
945 + " already created for r=" + this);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800946 }
947
948 inHistory = true;
949
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800950 final TaskWindowContainerController taskController = task.getWindowContainerController();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800951
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700952 // TODO(b/36505427): Maybe this call should be moved inside updateOverrideConfiguration()
953 task.updateOverrideConfigurationFromLaunchBounds();
954 // Make sure override configuration is up-to-date before using to create window controller.
955 updateOverrideConfiguration();
956
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800957 mWindowContainerController = new AppWindowContainerController(taskController, appToken,
958 this, Integer.MAX_VALUE /* add on top */, info.screenOrientation, fullscreen,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800959 (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, info.configChanges,
960 task.voiceSession != null, mLaunchTaskBehind, isAlwaysFocusable(),
961 appInfo.targetSdkVersion, mRotationAnimationHint,
Bryce Leef3c6a472017-11-14 14:53:06 -0800962 ActivityManagerService.getInputDispatchingTimeoutLocked(this) * 1000000L);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800963
964 task.addActivityToTop(this);
965
Winson Chung609e1e92017-05-08 10:52:12 -0700966 // When an activity is started directly into a split-screen fullscreen stack, we need to
967 // update the initial multi-window modes so that the callbacks are scheduled correctly when
968 // the user leaves that mode.
Bryce Leef3c6a472017-11-14 14:53:06 -0800969 mLastReportedMultiWindowMode = inMultiWindowMode();
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700970 mLastReportedPictureInPictureMode = inPinnedWindowingMode();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800971 }
972
973 void removeWindowContainer() {
Wale Ogunwalecc367f42017-02-01 08:12:14 -0800974 // Resume key dispatching if it is currently paused before we remove the container.
975 resumeKeyDispatchingLocked();
976
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800977 mWindowContainerController.removeContainer(getDisplayId());
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800978 mWindowContainerController = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 }
980
Winson Chung30480042017-01-26 10:55:34 -0800981 /**
982 * Reparents this activity into {@param newTask} at the provided {@param position}. The caller
983 * should ensure that the {@param newTask} is not already the parent of this activity.
984 */
985 void reparent(TaskRecord newTask, int position, String reason) {
986 final TaskRecord prevTask = task;
987 if (prevTask == newTask) {
988 throw new IllegalArgumentException(reason + ": task=" + newTask
989 + " is already the parent of r=" + this);
990 }
991
Winson Chung74666102017-02-22 17:49:24 -0800992 // TODO: Ensure that we do not directly reparent activities across stacks, as that may leave
993 // the stacks in strange states. For now, we should use Task.reparent() to ensure that
994 // the stack is left in an OK state.
995 if (prevTask != null && newTask != null && prevTask.getStack() != newTask.getStack()) {
996 throw new IllegalArgumentException(reason + ": task=" + newTask
997 + " is in a different stack (" + newTask.getStackId() + ") than the parent of"
998 + " r=" + this + " (" + prevTask.getStackId() + ")");
999 }
1000
Winson Chung30480042017-01-26 10:55:34 -08001001 // Must reparent first in window manager
1002 mWindowContainerController.reparent(newTask.getWindowContainerController(), position);
1003
Bryce Leeaf691c02017-03-20 14:20:22 -07001004 // Remove the activity from the old task and add it to the new task.
1005 prevTask.removeActivity(this, true /*reparenting*/);
Bryce Lee0f9bde82017-02-22 16:39:06 -08001006
Winson Chung30480042017-01-26 10:55:34 -08001007 newTask.addActivityAtIndex(position, this);
1008 }
1009
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001010 private boolean isHomeIntent(Intent intent) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001011 return ACTION_MAIN.equals(intent.getAction())
1012 && intent.hasCategory(CATEGORY_HOME)
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001013 && intent.getCategories().size() == 1
1014 && intent.getData() == null
1015 && intent.getType() == null;
1016 }
1017
Chong Zhangad24f962016-08-25 12:12:33 -07001018 static boolean isMainIntent(Intent intent) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001019 return ACTION_MAIN.equals(intent.getAction())
1020 && intent.hasCategory(CATEGORY_LAUNCHER)
Chong Zhangad24f962016-08-25 12:12:33 -07001021 && intent.getCategories().size() == 1
1022 && intent.getData() == null
1023 && intent.getType() == null;
1024 }
1025
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001026 private boolean canLaunchHomeActivity(int uid, ActivityRecord sourceRecord) {
1027 if (uid == Process.myUid() || uid == 0) {
1028 // System process can launch home activity.
1029 return true;
1030 }
1031 // Resolver activity can launch home activity.
1032 return sourceRecord != null && sourceRecord.isResolverActivity();
1033 }
1034
Winson Chung83471632016-12-13 11:02:12 -08001035 /**
1036 * @return whether the given package name can launch an assist activity.
1037 */
1038 private boolean canLaunchAssistActivity(String packageName) {
1039 if (service.mAssistUtils == null) {
1040 return false;
1041 }
1042
1043 final ComponentName assistComponent = service.mAssistUtils.getActiveServiceComponentName();
1044 if (assistComponent != null) {
1045 return assistComponent.getPackageName().equals(packageName);
1046 }
1047 return false;
1048 }
1049
1050 private void setActivityType(boolean componentSpecified, int launchedFromUid, Intent intent,
1051 ActivityOptions options, ActivityRecord sourceRecord) {
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001052 int activityType = ACTIVITY_TYPE_UNDEFINED;
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001053 if ((!componentSpecified || canLaunchHomeActivity(launchedFromUid, sourceRecord))
1054 && isHomeIntent(intent) && !isResolverActivity()) {
1055 // This sure looks like a home activity!
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001056 activityType = ACTIVITY_TYPE_HOME;
Wale Ogunwaledf241e92016-10-13 15:14:21 -07001057
1058 if (info.resizeMode == RESIZE_MODE_FORCE_RESIZEABLE
1059 || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) {
1060 // We only allow home activities to be resizeable if they explicitly requested it.
1061 info.resizeMode = RESIZE_MODE_UNRESIZEABLE;
1062 }
Winson Chung16e185e2017-11-07 08:30:54 -08001063 } else if (realActivity.getClassName().contains(LEGACY_RECENTS_PACKAGE_NAME) ||
1064 service.getRecentTasks().isRecentsComponent(realActivity, appInfo.uid)) {
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001065 activityType = ACTIVITY_TYPE_RECENTS;
Wale Ogunwale0568aed2017-09-08 13:29:37 -07001066 } else if (options != null && options.getLaunchActivityType() == ACTIVITY_TYPE_ASSISTANT
Winson Chung83471632016-12-13 11:02:12 -08001067 && canLaunchAssistActivity(launchedFromPackage)) {
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001068 activityType = ACTIVITY_TYPE_ASSISTANT;
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001069 }
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001070 setActivityType(activityType);
Wale Ogunwale1affbbc2016-05-01 09:03:52 -07001071 }
1072
Craig Mautnera228ae92014-07-09 05:44:55 -07001073 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001074 if (launchMode != LAUNCH_SINGLE_INSTANCE && launchMode != LAUNCH_SINGLE_TASK) {
Craig Mautnera228ae92014-07-09 05:44:55 -07001075 task.setTaskToAffiliateWith(taskToAffiliateWith);
1076 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001077 }
1078
Andrii Kulian02b7a832016-10-06 23:11:56 -07001079 /**
1080 * @return Stack value from current task, null if there is no task.
1081 */
Winson Chung55893332017-02-17 17:13:10 -08001082 <T extends ActivityStack> T getStack() {
1083 return task != null ? (T) task.getStack() : null;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001084 }
1085
Jorim Jaggicdfc04e2017-04-28 19:06:24 +02001086 int getStackId() {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001087 return getStack() != null ? getStack().mStackId : INVALID_STACK_ID;
1088 }
1089
Wale Ogunwale04a05ac2017-09-17 21:35:02 -07001090 ActivityDisplay getDisplay() {
1091 final ActivityStack stack = getStack();
1092 return stack != null ? stack.getDisplay() : null;
1093 }
1094
Craig Mautner5eda9b32013-07-02 11:58:16 -07001095 boolean changeWindowTranslucency(boolean toOpaque) {
1096 if (fullscreen == toOpaque) {
1097 return false;
1098 }
Craig Mautner4addfc52013-06-25 08:05:45 -07001099
Craig Mautner5eda9b32013-07-02 11:58:16 -07001100 // Keep track of the number of fullscreen activities in this task.
1101 task.numFullscreen += toOpaque ? +1 : -1;
1102
1103 fullscreen = toOpaque;
1104 return true;
Craig Mautner4addfc52013-06-25 08:05:45 -07001105 }
1106
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001107 void takeFromHistory() {
1108 if (inHistory) {
1109 inHistory = false;
1110 if (task != null && !finishing) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001111 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001112 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -07001113 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001114 }
1115 }
1116
1117 boolean isInHistory() {
1118 return inHistory;
1119 }
1120
Wale Ogunwale7d701172015-03-11 15:36:30 -07001121 boolean isInStackLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001122 final ActivityStack stack = getStack();
1123 return stack != null && stack.isInStackLocked(this) != null;
Wale Ogunwale7d701172015-03-11 15:36:30 -07001124 }
1125
Craig Mautner21d24a22014-04-23 11:45:37 -07001126 boolean isPersistable() {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001127 return (info.persistableMode == PERSIST_ROOT_ONLY ||
1128 info.persistableMode == PERSIST_ACROSS_REBOOTS) &&
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001129 (intent == null || (intent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
Craig Mautner21d24a22014-04-23 11:45:37 -07001130 }
1131
Wale Ogunwale4cea0f52015-12-25 06:30:31 -08001132 boolean isFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001133 return getWindowConfiguration().canReceiveKeys() || isAlwaysFocusable();
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001134 }
1135
1136 boolean isResizeable() {
Winson Chungd3395382016-12-13 11:49:09 -08001137 return ActivityInfo.isResizeableMode(info.resizeMode) || info.supportsPictureInPicture();
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001138 }
1139
Winson Chungd3395382016-12-13 11:49:09 -08001140 /**
1141 * @return whether this activity is non-resizeable or forced to be resizeable
1142 */
1143 boolean isNonResizableOrForcedResizable() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -07001144 return info.resizeMode != RESIZE_MODE_RESIZEABLE
Wale Ogunwale72a73e32016-10-13 12:16:39 -07001145 && info.resizeMode != RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Jorim Jaggicd13d332016-04-27 15:40:20 -07001146 }
1147
Winson Chunge6308042016-10-31 09:24:01 -07001148 /**
Winson Chungd3395382016-12-13 11:49:09 -08001149 * @return whether this activity supports PiP multi-window and can be put in the pinned stack.
Winson Chunge6308042016-10-31 09:24:01 -07001150 */
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001151 boolean supportsPictureInPicture() {
Wale Ogunwale034a8ec2017-09-02 17:14:40 -07001152 return service.mSupportsPictureInPicture && isActivityTypeStandardOrUndefined()
Winson Chungd3395382016-12-13 11:49:09 -08001153 && info.supportsPictureInPicture();
1154 }
1155
1156 /**
1157 * @return whether this activity supports split-screen multi-window and can be put in the docked
1158 * stack.
1159 */
Wale Ogunwale04a05ac2017-09-17 21:35:02 -07001160 @Override
1161 public boolean supportsSplitScreenWindowingMode() {
Winson Chungd3395382016-12-13 11:49:09 -08001162 // An activity can not be docked even if it is considered resizeable because it only
1163 // supports picture-in-picture mode but has a non-resizeable resizeMode
Wale Ogunwale04a05ac2017-09-17 21:35:02 -07001164 return super.supportsSplitScreenWindowingMode()
1165 && service.mSupportsSplitScreenMultiWindow && supportsResizeableMultiWindow();
Winson Chungd3395382016-12-13 11:49:09 -08001166 }
1167
1168 /**
1169 * @return whether this activity supports freeform multi-window and can be put in the freeform
1170 * stack.
1171 */
1172 boolean supportsFreeform() {
1173 return service.mSupportsFreeformWindowManagement && supportsResizeableMultiWindow();
1174 }
1175
1176 /**
1177 * @return whether this activity supports non-PiP multi-window.
1178 */
1179 private boolean supportsResizeableMultiWindow() {
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001180 return service.mSupportsMultiWindow && !isActivityTypeHome()
Winson Chungd3395382016-12-13 11:49:09 -08001181 && (ActivityInfo.isResizeableMode(info.resizeMode)
1182 || service.mForceResizableActivities);
Wale Ogunwaled26176f2016-01-25 20:04:04 -08001183 }
1184
Winson Chunge6308042016-10-31 09:24:01 -07001185 /**
Andrii Kulian036e3ad2017-04-19 10:55:10 -07001186 * Check whether this activity can be launched on the specified display.
1187 * @param displayId Target display id.
1188 * @return {@code true} if either it is the default display or this activity is resizeable and
1189 * can be put a secondary screen.
1190 */
1191 boolean canBeLaunchedOnDisplay(int displayId) {
Bryce Lee1533b2b2017-09-14 17:06:41 -07001192 final TaskRecord task = getTask();
1193
1194 // The resizeability of an Activity's parent task takes precendence over the ActivityInfo.
1195 // This allows for a non resizable activity to be launched into a resizeable task.
1196 final boolean resizeable =
1197 task != null ? task.isResizeable() : supportsResizeableMultiWindow();
1198
Andrii Kulian036e3ad2017-04-19 10:55:10 -07001199 return service.mStackSupervisor.canPlaceEntityOnDisplay(displayId,
Bryce Lee1533b2b2017-09-14 17:06:41 -07001200 resizeable, launchedFromPid, launchedFromUid, info);
Andrii Kulian036e3ad2017-04-19 10:55:10 -07001201 }
1202
1203 /**
Robert Carrc33658e2017-04-11 18:24:20 -07001204 * @param beforeStopping Whether this check is for an auto-enter-pip operation, that is to say
1205 * the activity has requested to enter PiP when it would otherwise be stopped.
1206 *
Winson Chung298f95b2017-08-10 15:57:18 -07001207 * @return whether this activity is currently allowed to enter PIP.
Winson Chunge6308042016-10-31 09:24:01 -07001208 */
Winson Chung298f95b2017-08-10 15:57:18 -07001209 boolean checkEnterPictureInPictureState(String caller, boolean beforeStopping) {
Wale Ogunwaleb9a0c992017-04-18 07:25:20 -07001210 if (!supportsPictureInPicture()) {
1211 return false;
1212 }
1213
Winson Chungf4ac0632017-03-17 12:34:12 -07001214 // Check app-ops and see if PiP is supported for this package
1215 if (!checkEnterPictureInPictureAppOpsState()) {
1216 return false;
1217 }
1218
Winson Chungf1bfee12017-03-24 17:11:33 -07001219 // Check to see if we are in VR mode, and disallow PiP if so
1220 if (service.shouldDisableNonVrUiLocked()) {
1221 return false;
1222 }
1223
Winson Chungc2baac02017-01-11 13:34:47 -08001224 boolean isKeyguardLocked = service.isKeyguardLocked();
Benjamin Franza83859f2017-07-03 16:34:14 +01001225 boolean isCurrentAppLocked = service.getLockTaskModeState() != LOCK_TASK_MODE_NONE;
Wale Ogunwale04a05ac2017-09-17 21:35:02 -07001226 final ActivityDisplay display = getDisplay();
1227 boolean hasPinnedStack = display != null && display.hasPinnedStack();
Winson Chungbb348802017-01-30 12:01:45 -08001228 // Don't return early if !isNotLocked, since we want to throw an exception if the activity
1229 // is in an incorrect state
Winson Chunge581ebf2017-02-21 08:25:03 -08001230 boolean isNotLockedOrOnKeyguard = !isKeyguardLocked && !isCurrentAppLocked;
Robert Carrc33658e2017-04-11 18:24:20 -07001231
1232 // We don't allow auto-PiP when something else is already pipped.
1233 if (beforeStopping && hasPinnedStack) {
1234 return false;
1235 }
1236
Winson Chungc2baac02017-01-11 13:34:47 -08001237 switch (state) {
1238 case RESUMED:
Winson Chunge581ebf2017-02-21 08:25:03 -08001239 // When visible, allow entering PiP if the app is not locked. If it is over the
1240 // keyguard, then we will prompt to unlock in the caller before entering PiP.
Robert Carrc33658e2017-04-11 18:24:20 -07001241 return !isCurrentAppLocked &&
Winson Chungf7e03e12017-08-22 11:32:16 -07001242 (supportsEnterPipOnTaskSwitch || !beforeStopping);
Winson Chungc2baac02017-01-11 13:34:47 -08001243 case PAUSING:
1244 case PAUSED:
Winson Chungbb348802017-01-30 12:01:45 -08001245 // When pausing, then only allow enter PiP as in the resume state, and in addition,
1246 // require that there is not an existing PiP activity and that the current system
1247 // state supports entering PiP
Winson Chunge581ebf2017-02-21 08:25:03 -08001248 return isNotLockedOrOnKeyguard && !hasPinnedStack
Winson Chungf7e03e12017-08-22 11:32:16 -07001249 && supportsEnterPipOnTaskSwitch;
Winson Chungc2baac02017-01-11 13:34:47 -08001250 case STOPPING:
1251 // When stopping in a valid state, then only allow enter PiP as in the pause state.
1252 // Otherwise, fall through to throw an exception if the caller is trying to enter
1253 // PiP in an invalid stopping state.
Winson Chungf7e03e12017-08-22 11:32:16 -07001254 if (supportsEnterPipOnTaskSwitch) {
Winson Chungf4ac0632017-03-17 12:34:12 -07001255 return isNotLockedOrOnKeyguard && !hasPinnedStack;
Winson Chungc2baac02017-01-11 13:34:47 -08001256 }
1257 default:
Winson Chung298f95b2017-08-10 15:57:18 -07001258 return false;
Winson Chungb5c41b72016-12-07 15:00:47 -08001259 }
Winson Chunge6308042016-10-31 09:24:01 -07001260 }
1261
Winson Chung59fda9e2017-01-20 16:14:51 -08001262 /**
Winson Chungf4ac0632017-03-17 12:34:12 -07001263 * @return Whether AppOps allows this package to enter picture-in-picture.
Winson Chung59fda9e2017-01-20 16:14:51 -08001264 */
Winson Chungf4ac0632017-03-17 12:34:12 -07001265 private boolean checkEnterPictureInPictureAppOpsState() {
Winson Chung59fda9e2017-01-20 16:14:51 -08001266 try {
Winson Chungf4ac0632017-03-17 12:34:12 -07001267 return service.getAppOpsService().checkOperation(OP_PICTURE_IN_PICTURE,
Winson Chung59fda9e2017-01-20 16:14:51 -08001268 appInfo.uid, packageName) == MODE_ALLOWED;
1269 } catch (RemoteException e) {
1270 // Local call
1271 }
1272 return false;
1273 }
1274
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001275 boolean isAlwaysFocusable() {
1276 return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0;
Wale Ogunwale4cea0f52015-12-25 06:30:31 -08001277 }
1278
Jorim Jaggife762342016-10-13 14:33:27 +02001279
1280 /**
1281 * @return true if the activity contains windows that have
1282 * {@link LayoutParams#FLAG_DISMISS_KEYGUARD} set
1283 */
1284 boolean hasDismissKeyguardWindows() {
1285 return service.mWindowManager.containsDismissKeyguardWindow(appToken);
1286 }
1287
Wale Ogunwale7d701172015-03-11 15:36:30 -07001288 void makeFinishingLocked() {
Wale Ogunwalec981ad52017-06-13 11:40:06 -07001289 if (finishing) {
1290 return;
1291 }
1292 finishing = true;
1293 if (stopped) {
1294 clearOptionsLocked();
1295 }
Yorke Leebd54c2a2016-10-25 13:49:23 -07001296
Wale Ogunwalec981ad52017-06-13 11:40:06 -07001297 if (service != null) {
1298 service.mTaskChangeNotificationController.notifyTaskStackChanged();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08001299 }
1300 }
1301
Dianne Hackborn7e269642010-08-25 19:50:20 -07001302 UriPermissionOwner getUriPermissionsLocked() {
1303 if (uriPermissions == null) {
1304 uriPermissions = new UriPermissionOwner(service, this);
1305 }
1306 return uriPermissions;
1307 }
1308
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001309 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 int requestCode, int resultCode,
1311 Intent resultData) {
1312 ActivityResult r = new ActivityResult(from, resultWho,
John Spurlock8a985d22014-02-25 09:40:05 -05001313 requestCode, resultCode, resultData);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001315 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 }
1317 results.add(r);
1318 }
1319
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001320 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 int requestCode) {
1322 if (results != null) {
1323 for (int i=results.size()-1; i>=0; i--) {
1324 ActivityResult r = (ActivityResult)results.get(i);
1325 if (r.mFrom != from) continue;
1326 if (r.mResultWho == null) {
1327 if (resultWho != null) continue;
1328 } else {
1329 if (!r.mResultWho.equals(resultWho)) continue;
1330 }
1331 if (r.mRequestCode != requestCode) continue;
1332
1333 results.remove(i);
1334 }
1335 }
1336 }
1337
Andrii Kulian21713ac2016-10-12 22:05:05 -07001338 private void addNewIntentLocked(ReferrerIntent intent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001339 if (newIntents == null) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001340 newIntents = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001341 }
1342 newIntents.add(intent);
1343 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001344
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001345 /**
1346 * Deliver a new Intent to an existing activity, so that its onNewIntent()
1347 * method will be called at the proper time.
1348 */
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001349 final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) {
Dianne Hackborn514074f2013-02-11 10:52:46 -08001350 // The activity now gets access to the data associated with this Intent.
1351 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
Nicolas Prevotc6cf95c2014-05-29 11:30:36 +01001352 intent, getUriPermissionsLocked(), userId);
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001353 final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
Craig Mautner86d67a42013-05-14 10:34:38 -07001354 boolean unsent = true;
David Stevens9440dc82017-03-16 19:00:20 -07001355 final ActivityStack stack = getStack();
1356 final boolean isTopActivityWhileSleeping = isTopRunningActivity()
1357 && (stack != null ? stack.shouldSleepActivities() : service.isSleepingLocked());
Wale Ogunwale826c7062016-09-13 08:25:54 -07001358
1359 // We want to immediately deliver the intent to the activity if:
Wale Ogunwale03f7e9e2016-09-22 09:04:09 -07001360 // - It is currently resumed or paused. i.e. it is currently visible to the user and we want
1361 // the user to see the visual effects caused by the intent delivery now.
Wale Ogunwale826c7062016-09-13 08:25:54 -07001362 // - The device is sleeping and it is the top activity behind the lock screen (b/6700897).
Ruben Brunkf53497c2017-03-27 20:26:17 -07001363 if ((state == RESUMED || state == PAUSED
Wale Ogunwale03f7e9e2016-09-22 09:04:09 -07001364 || isTopActivityWhileSleeping) && app != null && app.thread != null) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001365 try {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001366 ArrayList<ReferrerIntent> ar = new ArrayList<>(1);
1367 ar.add(rintent);
Wale Ogunwale826c7062016-09-13 08:25:54 -07001368 app.thread.scheduleNewIntent(
Ruben Brunkf53497c2017-03-27 20:26:17 -07001369 ar, appToken, state == PAUSED /* andPause */);
Craig Mautner86d67a42013-05-14 10:34:38 -07001370 unsent = false;
Dianne Hackborn39792d22010-08-19 18:01:52 -07001371 } catch (RemoteException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001372 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn39792d22010-08-19 18:01:52 -07001373 } catch (NullPointerException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001374 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001375 }
1376 }
Craig Mautner86d67a42013-05-14 10:34:38 -07001377 if (unsent) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001378 addNewIntentLocked(rintent);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001379 }
1380 }
1381
Dianne Hackborn9622ca42012-10-23 18:56:33 -07001382 void updateOptionsLocked(ActivityOptions options) {
1383 if (options != null) {
1384 if (pendingOptions != null) {
1385 pendingOptions.abort();
1386 }
1387 pendingOptions = options;
1388 }
1389 }
1390
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001391 void applyOptionsLocked() {
George Mount2c92c972014-03-20 09:38:23 -07001392 if (pendingOptions != null
Ruben Brunkf53497c2017-03-27 20:26:17 -07001393 && pendingOptions.getAnimationType() != ANIM_SCENE_TRANSITION) {
Michael Jurka21385cd2012-05-03 10:57:31 -07001394 final int animationType = pendingOptions.getAnimationType();
1395 switch (animationType) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001396 case ANIM_CUSTOM:
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001397 service.mWindowManager.overridePendingAppTransition(
1398 pendingOptions.getPackageName(),
1399 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -07001400 pendingOptions.getCustomExitResId(),
1401 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001402 break;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001403 case ANIM_CLIP_REVEAL:
Chet Haase10e23ab2015-02-11 15:08:38 -08001404 service.mWindowManager.overridePendingAppTransitionClipReveal(
1405 pendingOptions.getStartX(), pendingOptions.getStartY(),
1406 pendingOptions.getWidth(), pendingOptions.getHeight());
1407 if (intent.getSourceBounds() == null) {
1408 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1409 pendingOptions.getStartY(),
1410 pendingOptions.getStartX()+pendingOptions.getWidth(),
1411 pendingOptions.getStartY()+pendingOptions.getHeight()));
1412 }
1413 break;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001414 case ANIM_SCALE_UP:
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001415 service.mWindowManager.overridePendingAppTransitionScaleUp(
1416 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001417 pendingOptions.getWidth(), pendingOptions.getHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001418 if (intent.getSourceBounds() == null) {
1419 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1420 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001421 pendingOptions.getStartX()+pendingOptions.getWidth(),
1422 pendingOptions.getStartY()+pendingOptions.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001423 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001424 break;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001425 case ANIM_THUMBNAIL_SCALE_UP:
1426 case ANIM_THUMBNAIL_SCALE_DOWN:
Winson Chungaa7fa012017-05-24 15:50:06 -07001427 final boolean scaleUp = (animationType == ANIM_THUMBNAIL_SCALE_UP);
1428 final GraphicBuffer buffer = pendingOptions.getThumbnail();
1429 service.mWindowManager.overridePendingAppTransitionThumb(buffer,
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001430 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -07001431 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -07001432 scaleUp);
Winson Chungf229ae52017-06-02 14:34:52 -07001433 if (intent.getSourceBounds() == null && buffer != null) {
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001434 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1435 pendingOptions.getStartY(),
Winson Chungaa7fa012017-05-24 15:50:06 -07001436 pendingOptions.getStartX() + buffer.getWidth(),
1437 pendingOptions.getStartY() + buffer.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001438 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001439 break;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001440 case ANIM_THUMBNAIL_ASPECT_SCALE_UP:
1441 case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001442 final AppTransitionAnimationSpec[] specs = pendingOptions.getAnimSpecs();
Jorim Jaggi34795e32017-05-12 17:27:46 +02001443 final IAppTransitionAnimationSpecsFuture specsFuture =
1444 pendingOptions.getSpecsFuture();
1445 if (specsFuture != null) {
1446 service.mWindowManager.overridePendingAppTransitionMultiThumbFuture(
1447 specsFuture, pendingOptions.getOnAnimationStartListener(),
1448 animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP);
1449 } else if (animationType == ANIM_THUMBNAIL_ASPECT_SCALE_DOWN
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001450 && specs != null) {
1451 service.mWindowManager.overridePendingAppTransitionMultiThumb(
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001452 specs, pendingOptions.getOnAnimationStartListener(),
1453 pendingOptions.getAnimationFinishedListener(), false);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001454 } else {
1455 service.mWindowManager.overridePendingAppTransitionAspectScaledThumb(
1456 pendingOptions.getThumbnail(),
1457 pendingOptions.getStartX(), pendingOptions.getStartY(),
1458 pendingOptions.getWidth(), pendingOptions.getHeight(),
1459 pendingOptions.getOnAnimationStartListener(),
Ruben Brunkf53497c2017-03-27 20:26:17 -07001460 (animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP));
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001461 if (intent.getSourceBounds() == null) {
1462 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1463 pendingOptions.getStartY(),
1464 pendingOptions.getStartX() + pendingOptions.getWidth(),
1465 pendingOptions.getStartY() + pendingOptions.getHeight()));
1466 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001467 }
1468 break;
Craig Mautner233ceee2014-05-09 17:05:11 -07001469 default:
1470 Slog.e(TAG, "applyOptionsLocked: Unknown animationType=" + animationType);
1471 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001472 }
1473 pendingOptions = null;
1474 }
1475 }
1476
Adam Powellcfbe9be2013-11-06 14:58:58 -08001477 ActivityOptions getOptionsForTargetActivityLocked() {
1478 return pendingOptions != null ? pendingOptions.forTargetActivity() : null;
1479 }
1480
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001481 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001482 if (pendingOptions != null) {
1483 pendingOptions.abort();
1484 pendingOptions = null;
1485 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001486 }
1487
Dianne Hackborn9622ca42012-10-23 18:56:33 -07001488 ActivityOptions takeOptionsLocked() {
1489 ActivityOptions opts = pendingOptions;
1490 pendingOptions = null;
1491 return opts;
1492 }
1493
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001494 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -07001495 if (uriPermissions != null) {
1496 uriPermissions.removeUriPermissionsLocked();
1497 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001498 }
1499 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001500
1501 void pauseKeyDispatchingLocked() {
1502 if (!keysPaused) {
1503 keysPaused = true;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001504 mWindowContainerController.pauseKeyDispatching();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 }
1506 }
1507
1508 void resumeKeyDispatchingLocked() {
1509 if (keysPaused) {
1510 keysPaused = false;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001511 mWindowContainerController.resumeKeyDispatching();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001512 }
1513 }
1514
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001515 private void updateTaskDescription(CharSequence description) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001516 task.lastDescription = description;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001517 }
1518
Wale Ogunwaleec950642017-04-25 07:44:21 -07001519 void setDeferHidingClient(boolean deferHidingClient) {
1520 if (mDeferHidingClient == deferHidingClient) {
1521 return;
1522 }
1523 mDeferHidingClient = deferHidingClient;
1524 if (!mDeferHidingClient && !visible) {
1525 // Hiding the client is no longer deferred and the app isn't visible still, go ahead and
1526 // update the visibility.
1527 setVisibility(false);
1528 }
Wale Ogunwale89973222017-04-23 18:39:45 -07001529 }
1530
Wale Ogunwaleec950642017-04-25 07:44:21 -07001531 void setVisibility(boolean visible) {
Tim Murray68ed8442017-08-29 23:21:27 +00001532 mWindowContainerController.setVisibility(visible, mDeferHidingClient);
Bryce Lee2a3cc462017-10-27 10:57:35 -07001533 mStackSupervisor.getActivityMetricsLogger().notifyVisibilityChanged(this);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001534 }
1535
1536 // TODO: Look into merging with #setVisibility()
Wale Ogunwaleec950642017-04-25 07:44:21 -07001537 void setVisible(boolean newVisible) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001538 visible = newVisible;
Wale Ogunwaleec950642017-04-25 07:44:21 -07001539 mDeferHidingClient = !visible && mDeferHidingClient;
Wale Ogunwaleec950642017-04-25 07:44:21 -07001540 setVisibility(visible);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001541 mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
1542 }
1543
Jorim Jaggibae01b12017-04-11 16:29:10 -07001544 void notifyAppResumed(boolean wasStopped) {
1545 mWindowContainerController.notifyAppResumed(wasStopped);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001546 }
1547
1548 void notifyUnknownVisibilityLaunched() {
Jorim Jaggi838c2452017-08-28 15:44:43 +02001549
1550 // No display activities never add a window, so there is no point in waiting them for
1551 // relayout.
1552 if (!noDisplay) {
1553 mWindowContainerController.notifyUnknownVisibilityLaunched();
1554 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001555 }
1556
Jorim Jaggi241ae102016-11-02 21:57:33 -07001557 /**
1558 * @return true if the input activity should be made visible, ignoring any effect Keyguard
1559 * might have on the visibility
1560 *
1561 * @see {@link ActivityStack#checkKeyguardVisibility}
1562 */
Wale Ogunwalec981ad52017-06-13 11:40:06 -07001563 boolean shouldBeVisibleIgnoringKeyguard(boolean behindFullscreenActivity) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001564 if (!okToShowLocked()) {
1565 return false;
1566 }
1567
Winson Chung3f0e59a2017-10-25 10:19:05 -07001568 return !behindFullscreenActivity || mLaunchTaskBehind;
Andrii Kulian21713ac2016-10-12 22:05:05 -07001569 }
1570
1571 void makeVisibleIfNeeded(ActivityRecord starting) {
1572 // This activity is not currently visible, but is running. Tell it to become visible.
Ruben Brunkf53497c2017-03-27 20:26:17 -07001573 if (state == RESUMED || this == starting) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001574 if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY,
1575 "Not making visible, r=" + this + " state=" + state + " starting=" + starting);
1576 return;
1577 }
1578
1579 // If this activity is paused, tell it to now show its window.
1580 if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY,
1581 "Making visible and scheduling visibility: " + this);
1582 final ActivityStack stack = getStack();
1583 try {
1584 if (stack.mTranslucentActivityWaiting != null) {
1585 updateOptionsLocked(returningOptions);
1586 stack.mUndrawnActivitiesBelowTopTranslucent.add(this);
1587 }
1588 setVisible(true);
1589 sleeping = false;
1590 app.pendingUiClean = true;
1591 app.thread.scheduleWindowVisibility(appToken, true /* showWindow */);
1592 // The activity may be waiting for stop, but that is no longer appropriate for it.
1593 mStackSupervisor.mStoppingActivities.remove(this);
1594 mStackSupervisor.mGoingToSleepActivities.remove(this);
1595 } catch (Exception e) {
1596 // Just skip on any failure; we'll make it visible when it next restarts.
1597 Slog.w(TAG, "Exception thrown making visibile: " + intent.getComponent(), e);
1598 }
1599 handleAlreadyVisible();
1600 }
1601
1602 boolean handleAlreadyVisible() {
1603 stopFreezingScreenLocked(false);
1604 try {
1605 if (returningOptions != null) {
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001606 app.thread.scheduleOnNewActivityOptions(appToken, returningOptions.toBundle());
Andrii Kulian21713ac2016-10-12 22:05:05 -07001607 }
1608 } catch(RemoteException e) {
1609 }
Ruben Brunkf53497c2017-03-27 20:26:17 -07001610 return state == RESUMED;
Andrii Kulian21713ac2016-10-12 22:05:05 -07001611 }
1612
1613 static void activityResumedLocked(IBinder token) {
1614 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
1615 if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r);
1616 if (r != null) {
1617 r.icicle = null;
1618 r.haveState = false;
1619 }
1620 }
1621
1622 /**
1623 * Once we know that we have asked an application to put an activity in the resumed state
1624 * (either by launching it or explicitly telling it), this function updates the rest of our
1625 * state to match that fact.
1626 */
1627 void completeResumeLocked() {
1628 final boolean wasVisible = visible;
Jorim Jaggi8d062052017-08-22 14:55:17 +02001629 setVisible(true);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001630 if (!wasVisible) {
1631 // Visibility has changed, so take a note of it so we call the TaskStackChangedListener
1632 mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
1633 }
1634 idle = false;
1635 results = null;
1636 newIntents = null;
1637 stopped = false;
1638
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07001639 if (isActivityTypeHome()) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001640 ProcessRecord app = task.mActivities.get(0).app;
1641 if (app != null && app != service.mHomeProcess) {
1642 service.mHomeProcess = app;
1643 }
1644 }
1645
1646 if (nowVisible) {
1647 // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now.
1648 mStackSupervisor.reportActivityVisibleLocked(this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001649 }
1650
1651 // Schedule an idle timeout in case the app doesn't do it for us.
1652 mStackSupervisor.scheduleIdleTimeoutLocked(this);
1653
1654 mStackSupervisor.reportResumedActivityLocked(this);
1655
1656 resumeKeyDispatchingLocked();
1657 final ActivityStack stack = getStack();
1658 stack.mNoAnimActivities.clear();
1659
1660 // Mark the point when the activity is resuming
1661 // TODO: To be more accurate, the mark should be before the onCreate,
1662 // not after the onResume. But for subsequent starts, onResume is fine.
1663 if (app != null) {
1664 cpuTimeAtResume = service.mProcessCpuTracker.getCpuTimeForPid(app.pid);
1665 } else {
1666 cpuTimeAtResume = 0; // Couldn't get the cpu time of process
1667 }
1668
1669 returningOptions = null;
chaviw59b98852017-06-13 12:05:44 -07001670
1671 if (canTurnScreenOn()) {
1672 mStackSupervisor.wakeUp("turnScreenOnFlag");
1673 } else {
1674 // If the screen is going to turn on because the caller explicitly requested it and
1675 // the keyguard is not showing don't attempt to sleep. Otherwise the Activity will
1676 // pause and then resume again later, which will result in a double life-cycle event.
David Stevens9440dc82017-03-16 19:00:20 -07001677 stack.checkReadyForSleep();
chaviw59b98852017-06-13 12:05:44 -07001678 }
Andrii Kulian21713ac2016-10-12 22:05:05 -07001679 }
1680
1681 final void activityStoppedLocked(Bundle newIcicle, PersistableBundle newPersistentState,
1682 CharSequence description) {
1683 final ActivityStack stack = getStack();
Ruben Brunkf53497c2017-03-27 20:26:17 -07001684 if (state != STOPPING) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001685 Slog.i(TAG, "Activity reported stop, but no longer stopping: " + this);
Ruben Brunkf53497c2017-03-27 20:26:17 -07001686 stack.mHandler.removeMessages(STOP_TIMEOUT_MSG, this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001687 return;
1688 }
1689 if (newPersistentState != null) {
1690 persistentState = newPersistentState;
1691 service.notifyTaskPersisterLocked(task, false);
1692 }
1693 if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, "Saving icicle of " + this + ": " + icicle);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001694
Andrii Kulian21713ac2016-10-12 22:05:05 -07001695 if (newIcicle != null) {
1696 // If icicle is null, this is happening due to a timeout, so we haven't really saved
1697 // the state.
1698 icicle = newIcicle;
1699 haveState = true;
1700 launchCount = 0;
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001701 updateTaskDescription(description);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001702 }
1703 if (!stopped) {
1704 if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to STOPPED: " + this + " (stop complete)");
Ruben Brunkf53497c2017-03-27 20:26:17 -07001705 stack.mHandler.removeMessages(STOP_TIMEOUT_MSG, this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001706 stopped = true;
Ruben Brunkf53497c2017-03-27 20:26:17 -07001707 state = STOPPED;
Andrii Kulian21713ac2016-10-12 22:05:05 -07001708
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001709 mWindowContainerController.notifyAppStopped();
Andrii Kulian21713ac2016-10-12 22:05:05 -07001710
Andrii Kulian21713ac2016-10-12 22:05:05 -07001711 if (finishing) {
1712 clearOptionsLocked();
1713 } else {
1714 if (deferRelaunchUntilPaused) {
1715 stack.destroyActivityLocked(this, true /* removeFromApp */, "stop-config");
1716 mStackSupervisor.resumeFocusedStackTopActivityLocked();
1717 } else {
1718 mStackSupervisor.updatePreviousProcessLocked(this);
1719 }
1720 }
1721 }
1722 }
1723
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001724 void startLaunchTickingLocked() {
Jeff Sharkey5ab02432017-06-27 11:01:36 -06001725 if (Build.IS_USER) {
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001726 return;
1727 }
1728 if (launchTickTime == 0) {
1729 launchTickTime = SystemClock.uptimeMillis();
1730 continueLaunchTickingLocked();
1731 }
1732 }
1733
1734 boolean continueLaunchTickingLocked() {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001735 if (launchTickTime == 0) {
1736 return false;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001737 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001738
Andrii Kulian02b7a832016-10-06 23:11:56 -07001739 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001740 if (stack == null) {
1741 return false;
1742 }
1743
Ruben Brunkf53497c2017-03-27 20:26:17 -07001744 Message msg = stack.mHandler.obtainMessage(LAUNCH_TICK_MSG, this);
1745 stack.mHandler.removeMessages(LAUNCH_TICK_MSG);
1746 stack.mHandler.sendMessageDelayed(msg, LAUNCH_TICK);
Wale Ogunwale7d701172015-03-11 15:36:30 -07001747 return true;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001748 }
1749
1750 void finishLaunchTickingLocked() {
1751 launchTickTime = 0;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001752 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001753 if (stack != null) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001754 stack.mHandler.removeMessages(LAUNCH_TICK_MSG);
Wale Ogunwale7d701172015-03-11 15:36:30 -07001755 }
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001756 }
1757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001758 // IApplicationToken
1759
1760 public boolean mayFreezeScreenLocked(ProcessRecord app) {
1761 // Only freeze the screen if this activity is currently attached to
1762 // an application, and that application is not blocked or unresponding.
1763 // In any other case, we can't count on getting the screen unfrozen,
1764 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -08001765 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001766 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001768 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
1769 if (mayFreezeScreenLocked(app)) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001770 mWindowContainerController.startFreezingScreen(configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001771 }
1772 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001774 public void stopFreezingScreenLocked(boolean force) {
1775 if (force || frozenBeforeDestroy) {
1776 frozenBeforeDestroy = false;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001777 mWindowContainerController.stopFreezingScreen(force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001778 }
1779 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001780
Jorim Jaggi4d27b842017-08-17 17:22:26 +02001781 public void reportFullyDrawnLocked(boolean restoredFromBundle) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001782 final long curTime = SystemClock.uptimeMillis();
1783 if (displayStartTime != 0) {
1784 reportLaunchTimeLocked(curTime);
1785 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001786 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001787 if (fullyDrawnStartTime != 0 && stack != null) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001788 final long thisTime = curTime - fullyDrawnStartTime;
1789 final long totalTime = stack.mFullyDrawnStartTime != 0
1790 ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07001791 if (SHOW_ACTIVITY_START_TIME) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001792 Trace.asyncTraceEnd(TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
1793 EventLog.writeEvent(AM_ACTIVITY_FULLY_DRAWN_TIME,
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001794 userId, System.identityHashCode(this), shortComponentName,
1795 thisTime, totalTime);
1796 StringBuilder sb = service.mStringBuilder;
1797 sb.setLength(0);
1798 sb.append("Fully drawn ");
1799 sb.append(shortComponentName);
1800 sb.append(": ");
1801 TimeUtils.formatDuration(thisTime, sb);
1802 if (thisTime != totalTime) {
1803 sb.append(" (total ");
1804 TimeUtils.formatDuration(totalTime, sb);
1805 sb.append(")");
1806 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001807 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001808 }
1809 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001810 //service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001811 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001812 stack.mFullyDrawnStartTime = 0;
1813 }
Bryce Lee2a3cc462017-10-27 10:57:35 -07001814 mStackSupervisor.getActivityMetricsLogger().logAppTransitionReportedDrawn(this,
Jorim Jaggi4d27b842017-08-17 17:22:26 +02001815 restoredFromBundle);
Wale Ogunwale7d701172015-03-11 15:36:30 -07001816 fullyDrawnStartTime = 0;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001817 }
1818
1819 private void reportLaunchTimeLocked(final long curTime) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001820 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001821 if (stack == null) {
1822 return;
1823 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001824 final long thisTime = curTime - displayStartTime;
1825 final long totalTime = stack.mLaunchStartTime != 0
1826 ? (curTime - stack.mLaunchStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07001827 if (SHOW_ACTIVITY_START_TIME) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001828 Trace.asyncTraceEnd(TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0);
1829 EventLog.writeEvent(AM_ACTIVITY_LAUNCH_TIME,
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001830 userId, System.identityHashCode(this), shortComponentName,
1831 thisTime, totalTime);
1832 StringBuilder sb = service.mStringBuilder;
1833 sb.setLength(0);
1834 sb.append("Displayed ");
1835 sb.append(shortComponentName);
1836 sb.append(": ");
1837 TimeUtils.formatDuration(thisTime, sb);
1838 if (thisTime != totalTime) {
1839 sb.append(" (total ");
1840 TimeUtils.formatDuration(totalTime, sb);
1841 sb.append(")");
1842 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001843 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001844 }
1845 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
1846 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001847 //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001848 }
1849 displayStartTime = 0;
1850 stack.mLaunchStartTime = 0;
1851 }
1852
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001853 @Override
Sudheer Shankac766db02017-06-12 10:37:29 -07001854 public void onStartingWindowDrawn(long timestamp) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001855 synchronized (service) {
Bryce Lee2a3cc462017-10-27 10:57:35 -07001856 mStackSupervisor.getActivityMetricsLogger().notifyStartingWindowDrawn(
Sudheer Shankac766db02017-06-12 10:37:29 -07001857 getStackId(), timestamp);
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001858 }
1859 }
1860
1861 @Override
Sudheer Shankac766db02017-06-12 10:37:29 -07001862 public void onWindowsDrawn(long timestamp) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001863 synchronized (service) {
Bryce Lee2a3cc462017-10-27 10:57:35 -07001864 mStackSupervisor.getActivityMetricsLogger().notifyWindowsDrawn(getStackId(), timestamp);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001865 if (displayStartTime != 0) {
Sudheer Shankac766db02017-06-12 10:37:29 -07001866 reportLaunchTimeLocked(timestamp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001867 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001868 mStackSupervisor.sendWaitingVisibleReportLocked(this);
1869 startTime = 0;
1870 finishLaunchTickingLocked();
1871 if (task != null) {
1872 task.hasBeenVisible = true;
1873 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001874 }
1875 }
1876
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001877 @Override
1878 public void onWindowsVisible() {
1879 synchronized (service) {
1880 mStackSupervisor.reportActivityVisibleLocked(this);
1881 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this);
1882 if (!nowVisible) {
1883 nowVisible = true;
1884 lastVisibleTime = SystemClock.uptimeMillis();
Bryce Leeb7c9b802017-05-02 14:20:24 -07001885 if (idle || mStackSupervisor.isStoppingNoHistoryActivity()) {
1886 // If this activity was already idle or there is an activity that must be
1887 // stopped immediately after visible, then we now need to make sure we perform
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001888 // the full stop of any activities that are waiting to do so. This is because
1889 // we won't do that while they are still waiting for this one to become visible.
Bryce Lee4a194382017-04-04 14:32:48 -07001890 final int size = mStackSupervisor.mActivitiesWaitingForVisibleActivity.size();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001891 if (size > 0) {
1892 for (int i = 0; i < size; i++) {
Bryce Lee4a194382017-04-04 14:32:48 -07001893 final ActivityRecord r =
1894 mStackSupervisor.mActivitiesWaitingForVisibleActivity.get(i);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001895 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "Was waiting for visible: " + r);
1896 }
Bryce Lee4a194382017-04-04 14:32:48 -07001897 mStackSupervisor.mActivitiesWaitingForVisibleActivity.clear();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001898 mStackSupervisor.scheduleIdleLocked();
1899 }
Bryce Leeb7c9b802017-05-02 14:20:24 -07001900 } else {
1901 // Instead of doing the full stop routine here, let's just hide any activities
1902 // we now can, and let them stop when the normal idle happens.
1903 mStackSupervisor.processStoppingActivitiesLocked(null /* idleActivity */,
1904 false /* remove */, true /* processPausingActivities */);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001905 }
1906 service.scheduleAppGcsLocked();
1907 }
1908 }
1909 }
1910
1911 @Override
1912 public void onWindowsGone() {
1913 synchronized (service) {
1914 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + this);
1915 nowVisible = false;
1916 }
1917 }
1918
1919 @Override
Wale Ogunwale7402ddf2017-03-29 12:58:24 -07001920 public boolean keyDispatchingTimedOut(String reason, int windowPid) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001921 ActivityRecord anrActivity;
1922 ProcessRecord anrApp;
Wale Ogunwale7402ddf2017-03-29 12:58:24 -07001923 boolean windowFromSameProcessAsActivity;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001924 synchronized (service) {
1925 anrActivity = getWaitingHistoryRecordLocked();
1926 anrApp = app;
Brian Carlstrom7b0f2e82017-03-31 00:24:18 -07001927 windowFromSameProcessAsActivity =
1928 app == null || app.pid == windowPid || windowPid == -1;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001929 }
Wale Ogunwale7402ddf2017-03-29 12:58:24 -07001930 if (windowFromSameProcessAsActivity) {
1931 return service.inputDispatchingTimedOut(anrApp, anrActivity, this, false, reason);
1932 } else {
1933 // In this case another process added windows using this activity token. So, we call the
1934 // generic service input dispatch timed out method so that the right process is blamed.
1935 return service.inputDispatchingTimedOut(windowPid, false /* aboveSystem */, reason) < 0;
1936 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001937 }
1938
1939 private ActivityRecord getWaitingHistoryRecordLocked() {
riddle_hsudb46d6b2015-04-01 18:58:07 +08001940 // First find the real culprit... if this activity is waiting for
1941 // another activity to start or has stopped, then the key dispatching
1942 // timeout should not be caused by this.
Bryce Lee4a194382017-04-04 14:32:48 -07001943 if (mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(this) || stopped) {
Craig Mautner8f2adcb2014-04-07 22:21:33 +00001944 final ActivityStack stack = mStackSupervisor.getFocusedStack();
riddle_hsudb46d6b2015-04-01 18:58:07 +08001945 // Try to use the one which is closest to top.
1946 ActivityRecord r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -08001948 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001949 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001950 if (r != null) {
1951 return r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001952 }
1953 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001954 return this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001955 }
1956
Chong Zhang87761972016-08-22 13:53:24 -07001957 /** Checks whether the activity should be shown for current user. */
1958 public boolean okToShowLocked() {
Bryce Lee8558ec72017-08-17 15:37:26 -07001959 // We cannot show activities when the device is locked and the application is not
1960 // encryption aware.
1961 if (!StorageManager.isUserKeyUnlocked(userId)
1962 && !info.applicationInfo.isEncryptionAware()) {
1963 return false;
1964 }
1965
Chong Zhang87761972016-08-22 13:53:24 -07001966 return (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0
1967 || (mStackSupervisor.isCurrentProfileLocked(userId)
Fyodor Kupolov1b3edac2017-09-19 15:48:06 -07001968 && service.mUserController.isUserRunning(userId, 0 /* flags */));
Chong Zhang87761972016-08-22 13:53:24 -07001969 }
1970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001971 /**
1972 * This method will return true if the activity is either visible, is becoming visible, is
1973 * currently pausing, or is resumed.
1974 */
1975 public boolean isInterestingToUserLocked() {
Ruben Brunkf53497c2017-03-27 20:26:17 -07001976 return visible || nowVisible || state == PAUSING ||
1977 state == RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001978 }
1979
Wale Ogunwale3e997362016-09-06 10:37:56 -07001980 void setSleeping(boolean _sleeping) {
1981 setSleeping(_sleeping, false);
1982 }
1983
1984 void setSleeping(boolean _sleeping, boolean force) {
1985 if (!force && sleeping == _sleeping) {
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001986 return;
1987 }
1988 if (app != null && app.thread != null) {
1989 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -08001990 app.thread.scheduleSleeping(appToken, _sleeping);
Craig Mautner0eea92c2013-05-16 13:35:39 -07001991 if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
1992 mStackSupervisor.mGoingToSleepActivities.add(this);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001993 }
1994 sleeping = _sleeping;
1995 } catch (RemoteException e) {
Craig Mautner0eea92c2013-05-16 13:35:39 -07001996 Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001997 }
1998 }
1999 }
Craig Mautnerf81b90872013-02-26 13:02:43 -08002000
Craig Mautnerd2328952013-03-05 12:46:26 -08002001 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07002002 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Craig Mautnerd2328952013-03-05 12:46:26 -08002003 if (r == null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08002004 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08002005 }
2006 final TaskRecord task = r.task;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07002007 final int activityNdx = task.mActivities.indexOf(r);
2008 if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08002009 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08002010 }
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07002011 return task.taskId;
Craig Mautnerd2328952013-03-05 12:46:26 -08002012 }
2013
2014 static ActivityRecord isInStackLocked(IBinder token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07002015 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Andrii Kulian02b7a832016-10-06 23:11:56 -07002016 return (r != null) ? r.getStack().isInStackLocked(r) : null;
Craig Mautnerd2328952013-03-05 12:46:26 -08002017 }
2018
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07002019 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -08002020 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
2021 if (r != null) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002022 return r.getStack();
Craig Mautnerd2328952013-03-05 12:46:26 -08002023 }
2024 return null;
2025 }
2026
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002027 /**
2028 * @return display id to which this record is attached, -1 if not attached.
2029 */
2030 int getDisplayId() {
2031 final ActivityStack stack = getStack();
2032 if (stack == null) {
2033 return -1;
2034 }
2035 return stack.mDisplayId;
2036 }
2037
Dianne Hackborn89ad4562014-08-24 16:45:38 -07002038 final boolean isDestroyable() {
Ruben Brunkf53497c2017-03-27 20:26:17 -07002039 if (finishing || app == null || state == DESTROYING
2040 || state == DESTROYED) {
Dianne Hackborn89ad4562014-08-24 16:45:38 -07002041 // This would be redundant.
2042 return false;
2043 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07002044 final ActivityStack stack = getStack();
2045 if (stack == null || this == stack.mResumedActivity || this == stack.mPausingActivity
2046 || !haveState || !stopped) {
Dianne Hackborn89ad4562014-08-24 16:45:38 -07002047 // We're not ready for this kind of thing.
2048 return false;
2049 }
2050 if (visible) {
2051 // The user would notice this!
2052 return false;
2053 }
2054 return true;
2055 }
2056
Winson Chung3bad5cc02014-08-19 17:44:32 -07002057 private static String createImageFilename(long createTime, int taskId) {
2058 return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime +
Ruben Brunkf53497c2017-03-27 20:26:17 -07002059 IMAGE_EXTENSION;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002060 }
2061
Craig Mautner648f69b2014-09-18 14:16:26 -07002062 void setTaskDescription(TaskDescription _taskDescription) {
2063 Bitmap icon;
2064 if (_taskDescription.getIconFilename() == null &&
2065 (icon = _taskDescription.getIcon()) != null) {
2066 final String iconFilename = createImageFilename(createTime, task.taskId);
Winson Chungc8408b82017-01-25 17:58:56 -08002067 final File iconFile = new File(TaskPersister.getUserImagesDir(task.userId),
2068 iconFilename);
Suprabh Shukla23593142015-11-03 17:31:15 -08002069 final String iconFilePath = iconFile.getAbsolutePath();
Winson Chung3f0e59a2017-10-25 10:19:05 -07002070 service.getRecentTasks().saveImage(icon, iconFilePath);
Suprabh Shukla23593142015-11-03 17:31:15 -08002071 _taskDescription.setIconFilename(iconFilePath);
Craig Mautner648f69b2014-09-18 14:16:26 -07002072 }
2073 taskDescription = _taskDescription;
2074 }
2075
Amith Yamasani0af6fa72016-01-17 15:36:19 -08002076 void setVoiceSessionLocked(IVoiceInteractionSession session) {
2077 voiceSession = session;
2078 pendingVoiceInteractionStart = false;
2079 }
2080
2081 void clearVoiceSessionLocked() {
2082 voiceSession = null;
2083 pendingVoiceInteractionStart = false;
2084 }
2085
Jorim Jaggi02886a82016-12-06 09:10:06 -08002086 void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch) {
Jorim Jaggi42befc62017-06-13 11:54:04 -07002087 showStartingWindow(prev, newTask, taskSwitch, false /* fromRecents */);
2088 }
2089
2090 void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch,
2091 boolean fromRecents) {
Jorim Jaggi70176432017-01-18 12:52:13 +01002092 if (mWindowContainerController == null) {
2093 return;
2094 }
Wale Ogunwale19866e22017-04-19 06:05:13 -07002095 if (mTaskOverlay) {
2096 // We don't show starting window for overlay activities.
2097 return;
2098 }
2099
Wale Ogunwale3b232392016-05-13 15:37:13 -07002100 final CompatibilityInfo compatInfo =
2101 service.compatibilityInfoForPackageLocked(info.applicationInfo);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002102 final boolean shown = mWindowContainerController.addStartingWindow(packageName, theme,
2103 compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags,
Jorim Jaggibae01b12017-04-11 16:29:10 -07002104 prev != null ? prev.appToken : null, newTask, taskSwitch, isProcessRunning(),
Jorim Jaggi70aa4d12017-05-15 00:05:54 +02002105 allowTaskSnapshot(),
Jorim Jaggi42befc62017-06-13 11:54:04 -07002106 state.ordinal() >= RESUMED.ordinal() && state.ordinal() <= STOPPED.ordinal(),
2107 fromRecents);
Wale Ogunwale3b232392016-05-13 15:37:13 -07002108 if (shown) {
2109 mStartingWindowState = STARTING_WINDOW_SHOWN;
2110 }
2111 }
2112
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002113 void removeOrphanedStartingWindow(boolean behindFullscreenActivity) {
Jorim Jaggicb956052017-05-09 16:27:24 +02002114 if (mStartingWindowState == STARTING_WINDOW_SHOWN && behindFullscreenActivity) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002115 if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, "Found orphaned starting window " + this);
2116 mStartingWindowState = STARTING_WINDOW_REMOVED;
Jorim Jaggi19be6052017-08-03 18:33:43 +02002117 mWindowContainerController.removeStartingWindow();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002118 }
2119 }
2120
2121 int getRequestedOrientation() {
2122 return mWindowContainerController.getOrientation();
2123 }
2124
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002125 void setRequestedOrientation(int requestedOrientation) {
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002126 final int displayId = getDisplayId();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08002127 final Configuration displayConfig =
2128 mStackSupervisor.getDisplayOverrideConfiguration(displayId);
2129
2130 final Configuration config = mWindowContainerController.setOrientation(requestedOrientation,
2131 displayId, displayConfig, mayFreezeScreenLocked(app));
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002132 if (config != null) {
2133 frozenBeforeDestroy = true;
2134 if (!service.updateDisplayOverrideConfigurationLocked(config, this,
2135 false /* deferResume */, displayId)) {
2136 mStackSupervisor.resumeFocusedStackTopActivityLocked();
2137 }
2138 }
Yorke Leebd54c2a2016-10-25 13:49:23 -07002139 service.mTaskChangeNotificationController.notifyActivityRequestedOrientationChanged(
2140 task.taskId, requestedOrientation);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002141 }
2142
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01002143 void setDisablePreviewScreenshots(boolean disable) {
2144 mWindowContainerController.setDisablePreviewScreenshots(disable);
2145 }
2146
Bryce Leea163b762017-01-24 11:05:01 -08002147 /**
2148 * Set the last reported global configuration to the client. Should be called whenever a new
2149 * global configuration is sent to the client for this activity.
2150 */
2151 void setLastReportedGlobalConfiguration(@NonNull Configuration config) {
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002152 mLastReportedConfiguration.setGlobalConfiguration(config);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002153 }
2154
Bryce Leea163b762017-01-24 11:05:01 -08002155 /**
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002156 * Set the last reported configuration to the client. Should be called whenever
Bryce Leea163b762017-01-24 11:05:01 -08002157 * a new merged configuration is sent to the client for this activity.
2158 */
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002159 void setLastReportedConfiguration(@NonNull MergedConfiguration config) {
Bryce Lee8104e7a2017-08-17 09:16:03 -07002160 setLastReportedConfiguration(config.getGlobalConfiguration(),
2161 config.getOverrideConfiguration());
Bryce Leea163b762017-01-24 11:05:01 -08002162 }
2163
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -07002164 private void setLastReportedConfiguration(Configuration global, Configuration override) {
Bryce Lee8104e7a2017-08-17 09:16:03 -07002165 mLastReportedConfiguration.setConfiguration(global, override);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002166 }
2167
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002168 // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer.
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002169 private void updateOverrideConfiguration() {
2170 mTmpConfig.unset();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002171 computeBounds(mTmpBounds);
Bryce Leef3c6a472017-11-14 14:53:06 -08002172
2173 if (mTmpBounds.equals(getOverrideBounds())) {
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002174 return;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002175 }
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002176
Bryce Leef3c6a472017-11-14 14:53:06 -08002177 setBounds(mTmpBounds);
2178
2179 final Rect updatedBounds = getOverrideBounds();
2180
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002181 // Bounds changed...update configuration to match.
Bryce Leef3c6a472017-11-14 14:53:06 -08002182 if (!matchParentBounds()) {
2183 task.computeOverrideConfiguration(mTmpConfig, updatedBounds, null /* insetBounds */,
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002184 false /* overrideWidth */, false /* overrideHeight */);
2185 }
Bryce Leef3c6a472017-11-14 14:53:06 -08002186
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002187 onOverrideConfigurationChanged(mTmpConfig);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002188 }
2189
Wale Ogunwaled4b1d1e2017-04-10 06:35:59 -07002190 /** Returns true if the configuration is compatible with this activity. */
Wale Ogunwale42f07d92017-05-01 21:32:58 -07002191 boolean isConfigurationCompatible(Configuration config) {
Wale Ogunwaled4b1d1e2017-04-10 06:35:59 -07002192 final int orientation = mWindowContainerController != null
2193 ? mWindowContainerController.getOrientation() : info.screenOrientation;
2194 if (isFixedOrientationPortrait(orientation)
2195 && config.orientation != ORIENTATION_PORTRAIT) {
2196 return false;
2197 }
2198 if (isFixedOrientationLandscape(orientation)
2199 && config.orientation != ORIENTATION_LANDSCAPE) {
2200 return false;
2201 }
2202 return true;
2203 }
2204
Bryce Lee7566d762017-03-30 09:34:15 -07002205 /**
2206 * Computes the bounds to fit the Activity within the bounds of the {@link Configuration}.
2207 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002208 // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer.
2209 private void computeBounds(Rect outBounds) {
2210 outBounds.setEmpty();
2211 final float maxAspectRatio = info.maxAspectRatio;
2212 final ActivityStack stack = getStack();
Bryce Leef3c6a472017-11-14 14:53:06 -08002213 if (task == null || stack == null || task.inMultiWindowMode() || maxAspectRatio == 0
Bryce Leee5ab4502017-07-11 08:58:05 -07002214 || isInVrUiMode(getConfiguration())) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002215 // We don't set override configuration if that activity task isn't fullscreen. I.e. the
2216 // activity is in multi-window mode. Or, there isn't a max aspect ratio specified for
Bryce Leee5ab4502017-07-11 08:58:05 -07002217 // the activity. This is indicated by an empty {@link outBounds}. We also don't set it
2218 // if we are in VR mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002219 return;
2220 }
2221
Bryce Lee7566d762017-03-30 09:34:15 -07002222 // We must base this on the parent configuration, because we set our override
2223 // configuration's appBounds based on the result of this method. If we used our own
2224 // configuration, it would be influenced by past invocations.
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002225 final Rect appBounds = getParent().getWindowConfiguration().getAppBounds();
Wale Ogunwale822e5122017-07-26 06:02:24 -07002226 final int containingAppWidth = appBounds.width();
2227 final int containingAppHeight = appBounds.height();
Bryce Lee7566d762017-03-30 09:34:15 -07002228 int maxActivityWidth = containingAppWidth;
2229 int maxActivityHeight = containingAppHeight;
2230
2231 if (containingAppWidth < containingAppHeight) {
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002232 // Width is the shorter side, so we use that to figure-out what the max. height
2233 // should be given the aspect ratio.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002234 maxActivityHeight = (int) ((maxActivityWidth * maxAspectRatio) + 0.5f);
2235 } else {
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002236 // Height is the shorter side, so we use that to figure-out what the max. width
2237 // should be given the aspect ratio.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002238 maxActivityWidth = (int) ((maxActivityHeight * maxAspectRatio) + 0.5f);
2239 }
2240
Bryce Lee7566d762017-03-30 09:34:15 -07002241 if (containingAppWidth <= maxActivityWidth && containingAppHeight <= maxActivityHeight) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002242 // The display matches or is less than the activity aspect ratio, so nothing else to do.
Bryce Lee7566d762017-03-30 09:34:15 -07002243 // Return the existing bounds. If this method is running for the first time,
Bryce Leef3c6a472017-11-14 14:53:06 -08002244 // {@link #getOverrideBounds()} will be empty (representing no override). If the method has run
2245 // before, then effect of {@link #getOverrideBounds()} will already have been applied to the
Bryce Lee7566d762017-03-30 09:34:15 -07002246 // value returned from {@link getConfiguration}. Refer to
2247 // {@link TaskRecord#computeOverrideConfiguration}.
Bryce Leef3c6a472017-11-14 14:53:06 -08002248 outBounds.set(getOverrideBounds());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002249 return;
2250 }
2251
2252 // Compute configuration based on max supported width and height.
2253 outBounds.set(0, 0, maxActivityWidth, maxActivityHeight);
Andrii Kulian3a1619d2017-07-07 14:38:09 -07002254 // Position the activity frame on the opposite side of the nav bar.
2255 final int navBarPosition = service.mWindowManager.getNavBarPosition();
Wale Ogunwale822e5122017-07-26 06:02:24 -07002256 final int left = navBarPosition == NAV_BAR_LEFT ? appBounds.right - outBounds.width() : 0;
Andrii Kulian3a1619d2017-07-07 14:38:09 -07002257 outBounds.offsetTo(left, 0 /* top */);
2258 }
2259
Andrii Kulian21713ac2016-10-12 22:05:05 -07002260 /**
2261 * Make sure the given activity matches the current configuration. Returns false if the activity
2262 * had to be destroyed. Returns true if the configuration is the same, or the activity will
2263 * remain running as-is for whatever reason. Ensures the HistoryRecord is updated with the
2264 * correct configuration and all other bookkeeping is handled.
2265 */
2266 boolean ensureActivityConfigurationLocked(int globalChanges, boolean preserveWindow) {
2267 final ActivityStack stack = getStack();
2268 if (stack.mConfigWillChange) {
2269 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2270 "Skipping config check (will change): " + this);
2271 return true;
2272 }
2273
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002274 // We don't worry about activities that are finishing.
2275 if (finishing) {
2276 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2277 "Configuration doesn't matter in finishing " + this);
2278 stopFreezingScreenLocked(false);
2279 return true;
2280 }
2281
Wale Ogunwale9b7a8272017-04-10 08:05:41 -07002282 // Skip updating configuration for activity that are stopping or stopped.
2283 if (state == STOPPING || state == STOPPED) {
2284 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2285 "Skipping config check stopped or stopping: " + this);
2286 return true;
2287 }
2288
Wale Ogunwaleea3d3fd2017-05-01 07:41:08 -07002289 // TODO: We should add ActivityRecord.shouldBeVisible() that checks if the activity should
2290 // be visible based on the stack, task, and lockscreen state and use that here instead. The
2291 // method should be based on the logic in ActivityStack.ensureActivitiesVisibleLocked().
Wale Ogunwale9b7a8272017-04-10 08:05:41 -07002292 // Skip updating configuration for activity is a stack that shouldn't be visible.
Wale Ogunwale9dcf9462017-09-19 15:13:01 -07002293 if (!stack.shouldBeVisible(null /* starting */)) {
Wale Ogunwale9b7a8272017-04-10 08:05:41 -07002294 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2295 "Skipping config check invisible stack: " + this);
2296 return true;
2297 }
2298
Andrii Kulian21713ac2016-10-12 22:05:05 -07002299 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2300 "Ensuring correct configuration: " + this);
2301
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002302 final int newDisplayId = getDisplayId();
2303 final boolean displayChanged = mLastReportedDisplayId != newDisplayId;
2304 if (displayChanged) {
2305 mLastReportedDisplayId = newDisplayId;
2306 }
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002307 // TODO(b/36505427): Is there a better place to do this?
2308 updateOverrideConfiguration();
2309
Winson Chungbdc646f2017-02-13 12:12:22 -08002310 // Short circuit: if the two full configurations are equal (the common case), then there is
2311 // nothing to do. We test the full configuration instead of the global and merged override
2312 // configurations because there are cases (like moving a task to the pinned stack) where
2313 // the combine configurations are equal, but would otherwise differ in the override config
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002314 mTmpConfig.setTo(mLastReportedConfiguration.getMergedConfiguration());
2315 if (getConfiguration().equals(mTmpConfig) && !forceNewConfig && !displayChanged) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002316 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002317 "Configuration & display unchanged in " + this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002318 return true;
2319 }
2320
2321 // Okay we now are going to make this activity have the new config.
2322 // But then we need to figure out how it needs to deal with that.
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002323
2324 // Find changes between last reported merged configuration and the current one. This is used
2325 // to decide whether to relaunch an activity or just report a configuration change.
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002326 final int changes = getConfigurationChanges(mTmpConfig);
Ruben Brunkf64af332017-03-22 22:03:25 -07002327
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002328 // Update last reported values.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002329 final Configuration newMergedOverrideConfig = getMergedOverrideConfiguration();
Bryce Lee8104e7a2017-08-17 09:16:03 -07002330
2331 setLastReportedConfiguration(service.getGlobalConfiguration(), newMergedOverrideConfig);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002332
Andrii Kulian21713ac2016-10-12 22:05:05 -07002333 if (changes == 0 && !forceNewConfig) {
2334 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2335 "Configuration no differences in " + this);
2336 // There are no significant differences, so we won't relaunch but should still deliver
2337 // the new configuration to the client process.
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002338 if (displayChanged) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002339 scheduleActivityMovedToDisplay(newDisplayId, newMergedOverrideConfig);
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002340 } else {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002341 scheduleConfigurationChanged(newMergedOverrideConfig);
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002342 }
Andrii Kulian21713ac2016-10-12 22:05:05 -07002343 return true;
2344 }
2345
2346 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002347 "Configuration changes for " + this + ", allChanges="
Andrii Kulian21713ac2016-10-12 22:05:05 -07002348 + Configuration.configurationDiffToString(changes));
2349
2350 // If the activity isn't currently running, just leave the new configuration and it will
2351 // pick that up next time it starts.
2352 if (app == null || app.thread == null) {
2353 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2354 "Configuration doesn't matter not running " + this);
2355 stopFreezingScreenLocked(false);
2356 forceNewConfig = false;
2357 return true;
2358 }
2359
2360 // Figure out how to handle the changes between the configurations.
2361 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2362 "Checking to restart " + info.name + ": changed=0x"
2363 + Integer.toHexString(changes) + ", handles=0x"
2364 + Integer.toHexString(info.getRealConfigChanged())
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002365 + ", mLastReportedConfiguration=" + mLastReportedConfiguration);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002366
Wale Ogunwalee610d3d2017-04-25 10:23:48 -07002367 if (shouldRelaunchLocked(changes, mTmpConfig) || forceNewConfig) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002368 // Aha, the activity isn't handling the change, so DIE DIE DIE.
2369 configChangeFlags |= changes;
2370 startFreezingScreenLocked(app, globalChanges);
2371 forceNewConfig = false;
2372 preserveWindow &= isResizeOnlyChange(changes);
2373 if (app == null || app.thread == null) {
2374 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2375 "Config is destroying non-running " + this);
2376 stack.destroyActivityLocked(this, true, "config");
Ruben Brunkf53497c2017-03-27 20:26:17 -07002377 } else if (state == PAUSING) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002378 // A little annoying: we are waiting for this activity to finish pausing. Let's not
2379 // do anything now, but just flag that it needs to be restarted when done pausing.
2380 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2381 "Config is skipping already pausing " + this);
2382 deferRelaunchUntilPaused = true;
2383 preserveWindowOnDeferredRelaunch = preserveWindow;
2384 return true;
Ruben Brunkf53497c2017-03-27 20:26:17 -07002385 } else if (state == RESUMED) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002386 // Try to optimize this case: the configuration is changing and we need to restart
2387 // the top, resumed activity. Instead of doing the normal handshaking, just say
2388 // "restart!".
2389 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2390 "Config is relaunching resumed " + this);
2391
2392 if (DEBUG_STATES && !visible) {
2393 Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + this
2394 + " called by " + Debug.getCallers(4));
2395 }
2396
2397 relaunchActivityLocked(true /* andResume */, preserveWindow);
2398 } else {
2399 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2400 "Config is relaunching non-resumed " + this);
2401 relaunchActivityLocked(false /* andResume */, preserveWindow);
2402 }
2403
2404 // All done... tell the caller we weren't able to keep this activity around.
2405 return false;
2406 }
2407
2408 // Default case: the activity can handle this new configuration, so hand it over.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002409 // NOTE: We only forward the override configuration as the system level configuration
Andrii Kulian21713ac2016-10-12 22:05:05 -07002410 // changes is always sent to all processes when they happen so it can just use whatever
2411 // system level configuration it last got.
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002412 if (displayChanged) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002413 scheduleActivityMovedToDisplay(newDisplayId, newMergedOverrideConfig);
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002414 } else {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002415 scheduleConfigurationChanged(newMergedOverrideConfig);
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002416 }
Andrii Kulian21713ac2016-10-12 22:05:05 -07002417 stopFreezingScreenLocked(false);
2418
2419 return true;
2420 }
2421
Zak Cohen90e7116742017-01-29 12:59:23 -08002422 /**
2423 * When assessing a configuration change, decide if the changes flags and the new configurations
2424 * should cause the Activity to relaunch.
Ruben Brunkf64af332017-03-22 22:03:25 -07002425 *
2426 * @param changes the changes due to the given configuration.
2427 * @param changesConfig the configuration that was used to calculate the given changes via a
2428 * call to getConfigurationChanges.
Zak Cohen90e7116742017-01-29 12:59:23 -08002429 */
Ruben Brunkf64af332017-03-22 22:03:25 -07002430 private boolean shouldRelaunchLocked(int changes, Configuration changesConfig) {
Zak Cohen90e7116742017-01-29 12:59:23 -08002431 int configChanged = info.getRealConfigChanged();
Ruben Brunkf64af332017-03-22 22:03:25 -07002432 boolean onlyVrUiModeChanged = onlyVrUiModeChanged(changes, changesConfig);
Zak Cohen90e7116742017-01-29 12:59:23 -08002433
2434 // Override for apps targeting pre-O sdks
2435 // If a device is in VR mode, and we're transitioning into VR ui mode, add ignore ui mode
2436 // to the config change.
2437 // For O and later, apps will be required to add configChanges="uimode" to their manifest.
2438 if (appInfo.targetSdkVersion < O
2439 && requestedVrComponent != null
Ruben Brunkf64af332017-03-22 22:03:25 -07002440 && onlyVrUiModeChanged) {
Zak Cohen90e7116742017-01-29 12:59:23 -08002441 configChanged |= CONFIG_UI_MODE;
2442 }
2443
2444 return (changes&(~configChanged)) != 0;
2445 }
2446
Ruben Brunkf64af332017-03-22 22:03:25 -07002447 /**
2448 * Returns true if the configuration change is solely due to the UI mode switching into or out
2449 * of UI_MODE_TYPE_VR_HEADSET.
2450 */
2451 private boolean onlyVrUiModeChanged(int changes, Configuration lastReportedConfig) {
2452 final Configuration currentConfig = getConfiguration();
Ruben Brunkf53497c2017-03-27 20:26:17 -07002453 return changes == CONFIG_UI_MODE && (isInVrUiMode(currentConfig)
Ruben Brunkf64af332017-03-22 22:03:25 -07002454 != isInVrUiMode(lastReportedConfig));
2455 }
2456
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002457 private int getConfigurationChanges(Configuration lastReportedConfig) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07002458 // Determine what has changed. May be nothing, if this is a config that has come back from
2459 // the app after going idle. In that case we just want to leave the official config object
2460 // now in the activity and do nothing else.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002461 final Configuration currentConfig = getConfiguration();
2462 int changes = lastReportedConfig.diff(currentConfig);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002463 // We don't want to use size changes if they don't cross boundaries that are important to
2464 // the app.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002465 if ((changes & CONFIG_SCREEN_SIZE) != 0) {
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002466 final boolean crosses = crossesHorizontalSizeThreshold(lastReportedConfig.screenWidthDp,
2467 currentConfig.screenWidthDp)
2468 || crossesVerticalSizeThreshold(lastReportedConfig.screenHeightDp,
2469 currentConfig.screenHeightDp);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002470 if (!crosses) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002471 changes &= ~CONFIG_SCREEN_SIZE;
Andrii Kulian21713ac2016-10-12 22:05:05 -07002472 }
2473 }
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002474 if ((changes & CONFIG_SMALLEST_SCREEN_SIZE) != 0) {
Andrii Kulianb43be0a2017-03-02 17:29:40 -08002475 final int oldSmallest = lastReportedConfig.smallestScreenWidthDp;
2476 final int newSmallest = currentConfig.smallestScreenWidthDp;
2477 if (!crossesSmallestSizeThreshold(oldSmallest, newSmallest)) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002478 changes &= ~CONFIG_SMALLEST_SCREEN_SIZE;
Andrii Kulian21713ac2016-10-12 22:05:05 -07002479 }
2480 }
Wale Ogunwale822e5122017-07-26 06:02:24 -07002481 // We don't want window configuration to cause relaunches.
2482 if ((changes & CONFIG_WINDOW_CONFIGURATION) != 0) {
2483 changes &= ~CONFIG_WINDOW_CONFIGURATION;
2484 }
Bryce Lee600dadd2017-07-25 10:48:42 -07002485
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002486 return changes;
Andrii Kulian21713ac2016-10-12 22:05:05 -07002487 }
2488
2489 private static boolean isResizeOnlyChange(int change) {
2490 return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION
2491 | CONFIG_SCREEN_LAYOUT)) == 0;
2492 }
2493
2494 void relaunchActivityLocked(boolean andResume, boolean preserveWindow) {
2495 if (service.mSuppressResizeConfigChanges && preserveWindow) {
2496 configChangeFlags = 0;
2497 return;
2498 }
2499
2500 List<ResultInfo> pendingResults = null;
2501 List<ReferrerIntent> pendingNewIntents = null;
2502 if (andResume) {
2503 pendingResults = results;
2504 pendingNewIntents = newIntents;
2505 }
2506 if (DEBUG_SWITCH) Slog.v(TAG_SWITCH,
2507 "Relaunching: " + this + " with results=" + pendingResults
2508 + " newIntents=" + pendingNewIntents + " andResume=" + andResume
2509 + " preserveWindow=" + preserveWindow);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002510 EventLog.writeEvent(andResume ? AM_RELAUNCH_RESUME_ACTIVITY
2511 : AM_RELAUNCH_ACTIVITY, userId, System.identityHashCode(this),
Andrii Kulian21713ac2016-10-12 22:05:05 -07002512 task.taskId, shortComponentName);
2513
2514 startFreezingScreenLocked(app, 0);
2515
Andrii Kulian21713ac2016-10-12 22:05:05 -07002516 try {
2517 if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH,
2518 "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + this
2519 + " callers=" + Debug.getCallers(6));
2520 forceNewConfig = false;
2521 mStackSupervisor.activityRelaunchingLocked(this);
2522 app.thread.scheduleRelaunchActivity(appToken, pendingResults, pendingNewIntents,
2523 configChangeFlags, !andResume,
2524 new Configuration(service.getGlobalConfiguration()),
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002525 new Configuration(getMergedOverrideConfiguration()), preserveWindow);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002526 // Note: don't need to call pauseIfSleepingLocked() here, because the caller will only
2527 // pass in 'andResume' if this activity is currently resumed, which implies we aren't
2528 // sleeping.
2529 } catch (RemoteException e) {
2530 if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e);
2531 }
2532
2533 if (andResume) {
2534 if (DEBUG_STATES) {
2535 Slog.d(TAG_STATES, "Resumed after relaunch " + this);
2536 }
2537 results = null;
2538 newIntents = null;
Alan Viveretteb6a25732017-11-21 14:49:24 -05002539 service.getAppWarningsLocked().onResumeActivity(this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002540 service.showAskCompatModeDialogLocked(this);
2541 } else {
Ruben Brunkf53497c2017-03-27 20:26:17 -07002542 service.mHandler.removeMessages(PAUSE_TIMEOUT_MSG, this);
2543 state = PAUSED;
Andrii Kulian21713ac2016-10-12 22:05:05 -07002544 // if the app is relaunched when it's stopped, and we're not resuming,
2545 // put it back into stopped state.
2546 if (stopped) {
Winson Chung4dabf232017-01-25 13:25:22 -08002547 getStack().addToStopping(this, true /* scheduleIdle */, false /* idleDelayed */);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002548 }
2549 }
2550
2551 configChangeFlags = 0;
2552 deferRelaunchUntilPaused = false;
2553 preserveWindowOnDeferredRelaunch = false;
2554 }
2555
Jorim Jaggibae01b12017-04-11 16:29:10 -07002556 private boolean isProcessRunning() {
Jorim Jaggi02886a82016-12-06 09:10:06 -08002557 ProcessRecord proc = app;
2558 if (proc == null) {
2559 proc = service.mProcessNames.get(processName, info.applicationInfo.uid);
2560 }
2561 return proc != null && proc.thread != null;
2562 }
2563
Jorim Jaggibae01b12017-04-11 16:29:10 -07002564 /**
2565 * @return Whether a task snapshot starting window may be shown.
2566 */
2567 private boolean allowTaskSnapshot() {
2568 if (newIntents == null) {
2569 return true;
2570 }
2571
2572 // Restrict task snapshot starting window to launcher start, or there is no intent at all
2573 // (eg. task being brought to front). If the intent is something else, likely the app is
2574 // going to show some specific page or view, instead of what's left last time.
2575 for (int i = newIntents.size() - 1; i >= 0; i--) {
2576 final Intent intent = newIntents.get(i);
2577 if (intent != null && !ActivityRecord.isMainIntent(intent)) {
2578 return false;
2579 }
2580 }
2581 return true;
2582 }
2583
Bryce Leeb7c9b802017-05-02 14:20:24 -07002584 /**
2585 * Returns {@code true} if the associated activity has the no history flag set on it.
2586 * {@code false} otherwise.
2587 */
2588 boolean isNoHistory() {
2589 return (intent.getFlags() & FLAG_ACTIVITY_NO_HISTORY) != 0
2590 || (info.flags & FLAG_NO_HISTORY) != 0;
2591 }
2592
Craig Mautner21d24a22014-04-23 11:45:37 -07002593 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
2594 out.attribute(null, ATTR_ID, String.valueOf(createTime));
2595 out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
2596 if (launchedFromPackage != null) {
2597 out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage);
2598 }
2599 if (resolvedType != null) {
2600 out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType);
2601 }
2602 out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified));
2603 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Winson Chung2cb86c72014-06-25 12:03:30 -07002604
Craig Mautner21d24a22014-04-23 11:45:37 -07002605 if (taskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07002606 taskDescription.saveToXml(out);
Craig Mautner21d24a22014-04-23 11:45:37 -07002607 }
2608
2609 out.startTag(null, TAG_INTENT);
2610 intent.saveToXml(out);
2611 out.endTag(null, TAG_INTENT);
2612
2613 if (isPersistable() && persistentState != null) {
2614 out.startTag(null, TAG_PERSISTABLEBUNDLE);
2615 persistentState.saveToXml(out);
2616 out.endTag(null, TAG_PERSISTABLEBUNDLE);
2617 }
2618 }
2619
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07002620 static ActivityRecord restoreFromXml(XmlPullParser in,
2621 ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07002622 Intent intent = null;
2623 PersistableBundle persistentState = null;
2624 int launchedFromUid = 0;
2625 String launchedFromPackage = null;
2626 String resolvedType = null;
2627 boolean componentSpecified = false;
2628 int userId = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07002629 long createTime = -1;
2630 final int outerDepth = in.getDepth();
Winson Chung2cb86c72014-06-25 12:03:30 -07002631 TaskDescription taskDescription = new TaskDescription();
Craig Mautner21d24a22014-04-23 11:45:37 -07002632
2633 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
2634 final String attrName = in.getAttributeName(attrNdx);
2635 final String attrValue = in.getAttributeValue(attrNdx);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002636 if (DEBUG) Slog.d(TaskPersister.TAG,
Wale Ogunwale18795a22014-12-03 11:38:33 -08002637 "ActivityRecord: attribute name=" + attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002638 if (ATTR_ID.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01002639 createTime = Long.parseLong(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002640 } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01002641 launchedFromUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002642 } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
2643 launchedFromPackage = attrValue;
2644 } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
2645 resolvedType = attrValue;
2646 } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
Tobias Thiererb0800dc2016-04-21 17:51:41 +01002647 componentSpecified = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002648 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01002649 userId = Integer.parseInt(attrValue);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002650 } else if (attrName.startsWith(ATTR_TASKDESCRIPTION_PREFIX)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07002651 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002652 } else {
2653 Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName);
2654 }
2655 }
2656
2657 int event;
Ruben Brunkf53497c2017-03-27 20:26:17 -07002658 while (((event = in.next()) != END_DOCUMENT) &&
2659 (event != END_TAG || in.getDepth() >= outerDepth)) {
2660 if (event == START_TAG) {
Craig Mautner21d24a22014-04-23 11:45:37 -07002661 final String name = in.getName();
Ruben Brunkf53497c2017-03-27 20:26:17 -07002662 if (DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08002663 Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name);
Craig Mautner21d24a22014-04-23 11:45:37 -07002664 if (TAG_INTENT.equals(name)) {
2665 intent = Intent.restoreFromXml(in);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002666 if (DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08002667 Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07002668 } else if (TAG_PERSISTABLEBUNDLE.equals(name)) {
2669 persistentState = PersistableBundle.restoreFromXml(in);
Ruben Brunkf53497c2017-03-27 20:26:17 -07002670 if (DEBUG) Slog.d(TaskPersister.TAG,
Craig Mautner21d24a22014-04-23 11:45:37 -07002671 "ActivityRecord: persistentState=" + persistentState);
2672 } else {
2673 Slog.w(TAG, "restoreActivity: unexpected name=" + name);
2674 XmlUtils.skipCurrentTag(in);
2675 }
2676 }
2677 }
2678
2679 if (intent == null) {
Craig Mautnere0129b32014-05-25 16:41:09 -07002680 throw new XmlPullParserException("restoreActivity error intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07002681 }
2682
2683 final ActivityManagerService service = stackSupervisor.mService;
2684 final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null,
Jeff Hao1b012d32014-08-20 10:35:34 -07002685 userId);
Craig Mautnere0129b32014-05-25 16:41:09 -07002686 if (aInfo == null) {
Craig Mautner77b04262014-06-27 15:22:12 -07002687 throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent +
2688 " resolvedType=" + resolvedType);
Craig Mautnere0129b32014-05-25 16:41:09 -07002689 }
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002690 final ActivityRecord r = new ActivityRecord(service, null /* caller */,
2691 0 /* launchedFromPid */, launchedFromUid, launchedFromPackage, intent, resolvedType,
2692 aInfo, service.getConfiguration(), null /* resultTo */, null /* resultWho */,
2693 0 /* reqCode */, componentSpecified, false /* rootVoiceInteraction */,
Andrii Kulian94e82d9b02017-07-13 15:33:06 -07002694 stackSupervisor, null /* options */, null /* sourceRecord */);
Craig Mautner21d24a22014-04-23 11:45:37 -07002695
2696 r.persistentState = persistentState;
Winson Chung2cb86c72014-06-25 12:03:30 -07002697 r.taskDescription = taskDescription;
Craig Mautner21d24a22014-04-23 11:45:37 -07002698 r.createTime = createTime;
2699
2700 return r;
2701 }
2702
Zak Cohen90e7116742017-01-29 12:59:23 -08002703 private static boolean isInVrUiMode(Configuration config) {
Ruben Brunkf53497c2017-03-27 20:26:17 -07002704 return (config.uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_VR_HEADSET;
Zak Cohen90e7116742017-01-29 12:59:23 -08002705 }
2706
David Stevens82ea6cb2017-03-03 16:18:50 -08002707 int getUid() {
2708 return info.applicationInfo.uid;
2709 }
2710
chaviw59b98852017-06-13 12:05:44 -07002711 void setShowWhenLocked(boolean showWhenLocked) {
2712 mShowWhenLocked = showWhenLocked;
Kevin Chyn44639482017-10-09 18:34:41 -07002713 mStackSupervisor.ensureActivitiesVisibleLocked(null, 0 /* configChanges */,
2714 false /* preserveWindows */);
chaviw59b98852017-06-13 12:05:44 -07002715 }
2716
2717 /**
2718 * @return true if the activity contains windows that have
2719 * {@link LayoutParams#FLAG_SHOW_WHEN_LOCKED} set or if the activity has set
2720 * {@link #mShowWhenLocked}.
2721 */
2722 boolean canShowWhenLocked() {
2723 return mShowWhenLocked || service.mWindowManager.containsShowWhenLockedWindow(appToken);
2724 }
2725
2726 void setTurnScreenOn(boolean turnScreenOn) {
2727 mTurnScreenOn = turnScreenOn;
2728 }
2729
2730 /**
2731 * Determines whether this ActivityRecord can turn the screen on. It checks whether the flag
2732 * {@link #mTurnScreenOn} is set and checks whether the ActivityRecord should be visible
2733 * depending on Keyguard state
2734 *
2735 * @return true if the screen can be turned on, false otherwise.
2736 */
2737 boolean canTurnScreenOn() {
2738 final ActivityStack stack = getStack();
2739 return mTurnScreenOn && stack != null &&
2740 stack.checkKeyguardVisibility(this, true /* shouldBeVisible */, true /* isTop */);
2741 }
2742
2743 boolean getTurnScreenOnFlag() {
2744 return mTurnScreenOn;
2745 }
2746
2747 boolean isTopRunningActivity() {
2748 return mStackSupervisor.topRunningActivityLocked() == this;
2749 }
2750
Craig Mautnerf81b90872013-02-26 13:02:43 -08002751 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002752 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002753 if (stringName != null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08002754 return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) +
Craig Mautnerf3333272013-04-22 10:55:53 -07002755 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002756 }
2757 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -08002758 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002759 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -07002760 sb.append(" u");
2761 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002762 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002763 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -08002764 stringName = sb.toString();
2765 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002766 }
Steven Timotius4346f0a2017-09-12 11:07:21 -07002767
2768 void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
2769 final long token = proto.start(fieldId);
2770 proto.write(HASH_CODE, System.identityHashCode(this));
2771 proto.write(USER_ID, userId);
2772 proto.write(TITLE, intent.getComponent().flattenToShortString());
2773 proto.end(token);
2774 }
2775
2776 public void writeToProto(ProtoOutputStream proto, long fieldId) {
2777 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002778 super.writeToProto(proto, CONFIGURATION_CONTAINER, false /* trim */);
Steven Timotius4346f0a2017-09-12 11:07:21 -07002779 writeIdentifierToProto(proto, IDENTIFIER);
2780 proto.write(STATE, state.toString());
2781 proto.write(VISIBLE, visible);
2782 proto.write(FRONT_OF_TASK, frontOfTask);
2783 if (app != null) {
2784 proto.write(PROC_ID, app.pid);
2785 }
2786 proto.end(token);
2787 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002788}