blob: 7fea843b5ff2e1ec4638372f5ef847265ac7a7db [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.am;
18
Jorim Jaggi02886a82016-12-06 09:10:06 -080019import static android.app.ActivityManager.ENABLE_TASK_SNAPSHOTS;
Winson Chungbb348802017-01-30 12:01:45 -080020import static android.app.ActivityManager.LOCK_TASK_MODE_NONE;
Wale Ogunwale4cea0f52015-12-25 06:30:31 -080021import static android.app.ActivityManager.StackId;
Wale Ogunwaleeb915f22016-10-14 07:18:22 -070022import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080023import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Matthew Ngae1ff4f2016-11-10 15:49:14 -080024import static android.app.ActivityManager.StackId.HOME_STACK_ID;
Wale Ogunwale22e25262016-02-01 10:32:02 -080025import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Winson Chung59fda9e2017-01-20 16:14:51 -080026import static android.app.AppOpsManager.MODE_ALLOWED;
27import static android.app.AppOpsManager.OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080028import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
Andrii Kulian21713ac2016-10-12 22:05:05 -070029import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
30import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT;
31import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
32import static android.content.pm.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080033import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080034import static android.content.pm.ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
35import static android.content.pm.ActivityInfo.FLAG_IMMERSIVE;
36import static android.content.pm.ActivityInfo.FLAG_MULTIPROCESS;
Chong Zhang87761972016-08-22 13:53:24 -070037import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080038import static android.content.pm.ActivityInfo.FLAG_STATE_NOT_NEEDED;
39import static android.content.pm.ActivityInfo.LAUNCH_MULTIPLE;
40import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP;
Wale Ogunwaledf241e92016-10-13 15:14:21 -070041import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
Jorim Jaggicd13d332016-04-27 15:40:20 -070042import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
Wale Ogunwale72a73e32016-10-13 12:16:39 -070043import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Wale Ogunwaledf241e92016-10-13 15:14:21 -070044import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080045import static android.os.Build.VERSION_CODES.HONEYCOMB;
46import static android.os.Process.SYSTEM_UID;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080047import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION;
Andrii Kulian21713ac2016-10-12 22:05:05 -070048import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE;
49import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SCREENSHOTS;
50import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080051import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH;
52import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_THUMBNAILS;
Andrii Kulian21713ac2016-10-12 22:05:05 -070053import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBILITY;
54import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONFIGURATION;
55import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SAVED_STATE;
56import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SCREENSHOTS;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080057import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES;
58import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH;
59import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_THUMBNAILS;
Andrii Kulian21713ac2016-10-12 22:05:05 -070060import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBILITY;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080061import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
62import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Andrii Kulian21713ac2016-10-12 22:05:05 -070063import static com.android.server.am.ActivityManagerService.TAKE_FULLSCREEN_SCREENSHOTS;
Wale Ogunwale18795a22014-12-03 11:38:33 -080064import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
65
Andrii Kulian21713ac2016-10-12 22:05:05 -070066import android.annotation.NonNull;
Craig Mautner21d24a22014-04-23 11:45:37 -070067import android.app.ActivityManager.TaskDescription;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -070068import android.app.ActivityOptions;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080069import android.app.PendingIntent;
Winson Chungc2baac02017-01-11 13:34:47 -080070import android.app.PictureInPictureArgs;
Craig Mautner05d6272ba2013-02-11 09:39:27 -080071import android.app.ResultInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.content.ComponentName;
73import android.content.Intent;
74import android.content.pm.ActivityInfo;
75import android.content.pm.ApplicationInfo;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -070076import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077import android.content.res.Configuration;
78import android.graphics.Bitmap;
Dianne Hackbornd367ca82012-05-07 15:49:39 -070079import android.graphics.Rect;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080import android.os.Bundle;
Andrii Kulian21713ac2016-10-12 22:05:05 -070081import android.os.Debug;
Dianne Hackbornbe707852011-11-11 14:32:10 -080082import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083import android.os.Message;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080084import android.os.PersistableBundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085import android.os.Process;
Dianne Hackborn39792d22010-08-19 18:01:52 -070086import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087import android.os.SystemClock;
Filip Gruszczynski3d026712015-12-16 13:46:38 -080088import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070089import android.os.UserHandle;
Amith Yamasani0af6fa72016-01-17 15:36:19 -080090import android.service.voice.IVoiceInteractionSession;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091import android.util.EventLog;
92import android.util.Log;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -070093import android.util.Slog;
Dianne Hackborn0dad3642010-09-09 21:25:35 -070094import android.util.TimeUtils;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -070095import android.view.AppTransitionAnimationSpec;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096import android.view.IApplicationToken;
Jorim Jaggife762342016-10-13 14:33:27 +020097import android.view.WindowManager.LayoutParams;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -070098
Filip Gruszczynski3d026712015-12-16 13:46:38 -080099import com.android.internal.app.ResolverActivity;
100import com.android.internal.content.ReferrerIntent;
101import com.android.internal.util.XmlUtils;
102import com.android.server.AttributeCache;
103import com.android.server.am.ActivityStack.ActivityState;
104import com.android.server.am.ActivityStackSupervisor.ActivityContainer;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800105import com.android.server.wm.AppWindowContainerController;
106import com.android.server.wm.AppWindowContainerListener;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800107import com.android.server.wm.TaskWindowContainerController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108
Jorim Jaggi02886a82016-12-06 09:10:06 -0800109import org.xmlpull.v1.XmlPullParser;
110import org.xmlpull.v1.XmlPullParserException;
111import org.xmlpull.v1.XmlSerializer;
112
Suprabh Shukla23593142015-11-03 17:31:15 -0800113import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -0700114import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import java.io.PrintWriter;
116import java.lang.ref.WeakReference;
117import java.util.ArrayList;
Todd Kennedy39bfee52016-02-24 10:28:21 -0800118import java.util.Arrays;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119import java.util.HashSet;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700120import java.util.List;
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700121import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122
123/**
124 * An entry in the history stack, representing an activity.
125 */
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800126final class ActivityRecord implements AppWindowContainerListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800127 private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityRecord" : TAG_AM;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700128 private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION;
129 private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE;
130 private static final String TAG_SCREENSHOTS = TAG + POSTFIX_SCREENSHOTS;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700131 private static final String TAG_STATES = TAG + POSTFIX_STATES;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700132 private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH;
133 private static final String TAG_THUMBNAILS = TAG + POSTFIX_THUMBNAILS;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700134 private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY;
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800135
Wale Ogunwale3ab9a272015-03-16 09:55:45 -0700136 private static final boolean SHOW_ACTIVITY_START_TIME = true;
Andrii Kulian21713ac2016-10-12 22:05:05 -0700137 private static final String RECENTS_PACKAGE_NAME = "com.android.systemui.recents";
Craig Mautnerb59dcfd2013-05-06 13:12:58 -0700138
Craig Mautner21d24a22014-04-23 11:45:37 -0700139 private static final String ATTR_ID = "id";
140 private static final String TAG_INTENT = "intent";
141 private static final String ATTR_USERID = "user_id";
142 private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle";
143 private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700144 private static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package";
Craig Mautner21d24a22014-04-23 11:45:37 -0700145 private static final String ATTR_RESOLVEDTYPE = "resolved_type";
146 private static final String ATTR_COMPONENTSPECIFIED = "component_specified";
Dianne Hackborn337abb32014-09-24 12:44:29 -0700147 static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_";
Craig Mautner21d24a22014-04-23 11:45:37 -0700148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 final ActivityManagerService service; // owner
Dianne Hackbornbe707852011-11-11 14:32:10 -0800150 final IApplicationToken.Stub appToken; // window manager token
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800151 AppWindowContainerController mWindowContainerController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 final ActivityInfo info; // all about me
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700153 final ApplicationInfo appInfo; // information about activity's app
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800154 final int launchedFromPid; // always the pid who started the activity.
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700155 final int launchedFromUid; // always the uid who started the activity.
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800156 final String launchedFromPackage; // always the package who started the activity.
Amith Yamasani742a6712011-05-04 14:49:28 -0700157 final int userId; // Which user is this running for?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 final Intent intent; // the original intent that generated us
159 final ComponentName realActivity; // the intent component, or target of an alias.
160 final String shortComponentName; // the short component name of the intent
161 final String resolvedType; // as per original caller;
162 final String packageName; // the package implementing intent's component
163 final String processName; // process where this component wants to run
164 final String taskAffinity; // as per ActivityInfo.taskAffinity
165 final boolean stateNotNeeded; // As per ActivityInfo.flags
Craig Mautner4addfc52013-06-25 08:05:45 -0700166 boolean fullscreen; // covers the full screen?
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800167 final boolean noDisplay; // activity is not displayed?
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800168 private final boolean componentSpecified; // did caller specify an explicit component?
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700169 final boolean rootVoiceInteraction; // was this the root activity of a voice interaction?
Craig Mautner86d67a42013-05-14 10:34:38 -0700170
171 static final int APPLICATION_ACTIVITY_TYPE = 0;
172 static final int HOME_ACTIVITY_TYPE = 1;
173 static final int RECENTS_ACTIVITY_TYPE = 2;
Craig Mautner2c1faed2013-07-23 12:56:02 -0700174 int mActivityType;
Craig Mautner86d67a42013-05-14 10:34:38 -0700175
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800176 private CharSequence nonLocalizedLabel; // the label information from the package mgr.
177 private int labelRes; // the label information from the package mgr.
178 private int icon; // resource identifier of activity's icon.
179 private int logo; // resource identifier of activity's logo.
180 private int theme; // resource identifier of activity's theme.
181 private int realTheme; // actual theme resource we will use, never 0.
182 private int windowFlags; // custom window flags for preview window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 TaskRecord task; // the task this is in.
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800184 private long createTime = System.currentTimeMillis();
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700185 long displayStartTime; // when we started launching this activity
186 long fullyDrawnStartTime; // when we started launching this activity
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800187 private long startTime; // last time this activity was started
Dianne Hackborn50685602011-12-01 12:23:37 -0800188 long lastVisibleTime; // last time this activity became visible
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700189 long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -0700190 long pauseTime; // last time we started pausing the activity
191 long launchTickTime; // base time for launch tick messages
Andrii Kulian21713ac2016-10-12 22:05:05 -0700192 private Configuration mLastReportedConfiguration; // configuration activity was last running in
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700193 // Overridden configuration by the activity task
Andrii Kulian1779e612016-10-12 21:58:25 -0700194 // WARNING: Reference points to {@link TaskRecord#getMergedOverrideConfig}, so its internal
195 // state should never be altered directly.
Andrii Kulian21713ac2016-10-12 22:05:05 -0700196 private Configuration mLastReportedOverrideConfiguration;
Dianne Hackborn8ea5e1d2011-05-27 16:45:31 -0700197 CompatibilityInfo compat;// last used compatibility mode
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700198 ActivityRecord resultTo; // who started this entry, so will get our reply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 final String resultWho; // additional identifier for use by resultTo.
200 final int requestCode; // code given by requester (resultTo)
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800201 ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
Dianne Hackborn85d558c2014-11-04 10:31:54 -0800203 ArrayList<ReferrerIntent> newIntents; // any pending new intents for single-top mode
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700204 ActivityOptions pendingOptions; // most recently given options
George Mount6ba042b2014-07-28 11:12:28 -0700205 ActivityOptions returningOptions; // options that are coming back via convertToTranslucent
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700206 AppTimeTracker appTimeTracker; // set if we are tracking the time in this app/task/activity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
Dianne Hackborn7e269642010-08-25 19:50:20 -0700208 UriPermissionOwner uriPermissions; // current special URI access perms.
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700209 ProcessRecord app; // if non-null, hosting application
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700210 ActivityState state; // current state we are in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 Bundle icicle; // last saved activity state
Craig Mautnera0026042014-04-23 11:45:37 -0700212 PersistableBundle persistentState; // last persistently saved activity state
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 boolean frontOfTask; // is this the root activity of its task?
214 boolean launchFailed; // set if a launched failed, to abort on 2nd try
215 boolean haveState; // have we gotten the last activity state?
216 boolean stopped; // is activity pause finished?
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700217 boolean delayedResume; // not yet resumed because of stopped app switches?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 boolean finishing; // activity in pending finish list?
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800219 boolean deferRelaunchUntilPaused; // relaunch of activity is being deferred until pause is
220 // completed
221 boolean preserveWindowOnDeferredRelaunch; // activity windows are preserved on deferred relaunch
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 int configChangeFlags; // which config values have changed
223 boolean keysPaused; // has key dispatching been paused for it?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 int launchMode; // the launch mode activity attribute.
225 boolean visible; // does this activity's window need to be shown?
Jorim Jaggi241ae102016-11-02 21:57:33 -0700226 boolean visibleIgnoringKeyguard; // is this activity visible, ignoring the fact that Keyguard
227 // might hide this activity?
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800228 boolean sleeping; // have we told the activity to sleep?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 boolean nowVisible; // is this activity's window visible?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 boolean idle; // has the activity gone idle?
231 boolean hasBeenLaunched;// has this activity ever been launched?
232 boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
Daniel Sandler69a48172010-06-23 16:29:36 -0400233 boolean immersive; // immersive mode (don't interrupt if possible)
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400234 boolean forceNewConfig; // force re-create with new config next time
Winson Chungc2baac02017-01-11 13:34:47 -0800235 boolean supportsPictureInPictureWhilePausing; // This flag is set by the system to indicate
236 // that the activity can enter picture in picture while pausing (ie. only when another
237 // task is brought to front or started)
238 PictureInPictureArgs pictureInPictureArgs = new PictureInPictureArgs(); // The PiP
Winson Chunga29eb982016-12-14 12:01:27 -0800239 // arguments used when deferring the entering of picture-in-picture.
Dianne Hackborn07981492013-01-28 11:36:23 -0800240 int launchCount; // count of launches since last state
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800241 long lastLaunchTime; // time of last launch of this activity
Ruben Brunke24b9a62016-02-16 21:38:24 -0800242 ComponentName requestedVrComponent; // the requested component for handling VR mode.
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800243 ArrayList<ActivityContainer> mChildContainers = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700245 String stringName; // for caching of toString().
Craig Mautnerde4ef022013-04-07 19:01:33 -0700246
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700247 private boolean inHistory; // are we in the history stack?
Craig Mautnerde4ef022013-04-07 19:01:33 -0700248 final ActivityStackSupervisor mStackSupervisor;
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800249
250 static final int STARTING_WINDOW_NOT_SHOWN = 0;
251 static final int STARTING_WINDOW_SHOWN = 1;
252 static final int STARTING_WINDOW_REMOVED = 2;
253 int mStartingWindowState = STARTING_WINDOW_NOT_SHOWN;
Wale Ogunwale3b232392016-05-13 15:37:13 -0700254 boolean mTaskOverlay = false; // Task is always on-top of other activities in the task.
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800255
Jorim Jaggic2f262b2015-12-07 16:59:10 -0800256 boolean mUpdateTaskThumbnailWhenHidden;
Craig Mautnere0a38842013-12-16 16:14:02 -0800257 ActivityContainer mInitialActivityContainer;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700258
Craig Mautner21d24a22014-04-23 11:45:37 -0700259 TaskDescription taskDescription; // the recents information for this activity
Craig Mautnerbb742462014-07-07 15:28:55 -0700260 boolean mLaunchTaskBehind; // this activity is actively being launched with
261 // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed.
Craig Mautner2fbd7542014-03-21 09:34:07 -0700262
Filip Gruszczynski23493322015-07-29 17:02:59 -0700263 // These configurations are collected from application's resources based on size-sensitive
264 // qualifiers. For example, layout-w800dp will be added to mHorizontalSizeConfigurations as 800
265 // and drawable-sw400dp will be added to both as 400.
266 private int[] mVerticalSizeConfigurations;
267 private int[] mHorizontalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700268 private int[] mSmallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700269
Amith Yamasani0af6fa72016-01-17 15:36:19 -0800270 boolean pendingVoiceInteractionStart; // Waiting for activity-invoked voice session
271 IVoiceInteractionSession voiceSession; // Voice interaction session for this activity
272
Robert Carrd2265122016-08-05 10:25:21 -0700273 // A hint to override the window specified rotation animation, or -1
274 // to use the window specified value. We use this so that
275 // we can select the right animation in the cases of starting
276 // windows, where the app hasn't had time to set a value
277 // on the window.
278 int mRotationAnimationHint = -1;
Robert Carrfd10cd12016-06-29 16:41:50 -0700279
Andrii Kulian21713ac2016-10-12 22:05:05 -0700280 /**
281 * Temp configs used in {@link #ensureActivityConfigurationLocked(int, boolean)}
282 */
283 private final Configuration mTmpGlobalConfig = new Configuration();
284 private final Configuration mTmpTaskConfig = new Configuration();
285
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800286 private static String startingWindowStateToString(int state) {
287 switch (state) {
288 case STARTING_WINDOW_NOT_SHOWN:
289 return "STARTING_WINDOW_NOT_SHOWN";
290 case STARTING_WINDOW_SHOWN:
291 return "STARTING_WINDOW_SHOWN";
292 case STARTING_WINDOW_REMOVED:
293 return "STARTING_WINDOW_REMOVED";
294 default:
295 return "unknown state=" + state;
296 }
297 }
298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700300 final long now = SystemClock.uptimeMillis();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700301 pw.print(prefix); pw.print("packageName="); pw.print(packageName);
302 pw.print(" processName="); pw.println(processName);
303 pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
Craig Mautnere11f2b72013-04-01 12:37:17 -0700304 pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800305 pw.print(" userId="); pw.println(userId);
306 pw.print(prefix); pw.print("app="); pw.println(app);
307 pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700308 pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
309 pw.print(" task="); pw.println(task);
310 pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700311 pw.print(prefix); pw.print("realActivity=");
312 pw.println(realActivity.flattenToShortString());
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700313 if (appInfo != null) {
314 pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir);
315 if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) {
316 pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir);
317 }
318 pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir);
Todd Kennedy39bfee52016-02-24 10:28:21 -0800319 if (appInfo.splitSourceDirs != null) {
320 pw.print(prefix); pw.print("splitDir=");
321 pw.println(Arrays.toString(appInfo.splitSourceDirs));
322 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800323 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700324 pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
325 pw.print(" componentSpecified="); pw.print(componentSpecified);
Craig Mautner86d67a42013-05-14 10:34:38 -0700326 pw.print(" mActivityType="); pw.println(mActivityType);
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700327 if (rootVoiceInteraction) {
328 pw.print(prefix); pw.print("rootVoiceInteraction="); pw.println(rootVoiceInteraction);
329 }
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800330 pw.print(prefix); pw.print("compat="); pw.print(compat);
331 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
332 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
333 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
Andrii Kulian1779e612016-10-12 21:58:25 -0700334 pw.print(prefix); pw.print("mLastReportedConfiguration=");
335 pw.println(mLastReportedConfiguration);
336 pw.print(prefix); pw.print("mLastReportedOverrideConfiguration=");
337 pw.println(mLastReportedOverrideConfiguration);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700338 if (resultTo != null || resultWho != null) {
339 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
340 pw.print(" resultWho="); pw.print(resultWho);
341 pw.print(" resultCode="); pw.println(requestCode);
342 }
Craig Mautner29c58ca2014-10-14 16:17:06 -0700343 if (taskDescription != null) {
344 final String iconFilename = taskDescription.getIconFilename();
345 if (iconFilename != null || taskDescription.getLabel() != null ||
346 taskDescription.getPrimaryColor() != 0) {
347 pw.print(prefix); pw.print("taskDescription:");
348 pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename());
349 pw.print(" label=\""); pw.print(taskDescription.getLabel());
350 pw.print("\"");
351 pw.print(" color=");
352 pw.println(Integer.toHexString(taskDescription.getPrimaryColor()));
353 }
354 if (iconFilename == null && taskDescription.getIcon() != null) {
355 pw.print(prefix); pw.println("taskDescription contains Bitmap");
356 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700357 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700358 if (results != null) {
359 pw.print(prefix); pw.print("results="); pw.println(results);
360 }
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700361 if (pendingResults != null && pendingResults.size() > 0) {
362 pw.print(prefix); pw.println("Pending Results:");
363 for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
364 PendingIntentRecord pir = wpir != null ? wpir.get() : null;
365 pw.print(prefix); pw.print(" - ");
366 if (pir == null) {
367 pw.println("null");
368 } else {
369 pw.println(pir);
370 pir.dump(pw, prefix + " ");
371 }
372 }
373 }
374 if (newIntents != null && newIntents.size() > 0) {
375 pw.print(prefix); pw.println("Pending New Intents:");
376 for (int i=0; i<newIntents.size(); i++) {
Craig Mautnerd2328952013-03-05 12:46:26 -0800377 Intent intent = newIntents.get(i);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700378 pw.print(prefix); pw.print(" - ");
379 if (intent == null) {
380 pw.println("null");
381 } else {
382 pw.println(intent.toShortString(false, true, false, true));
383 }
384 }
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700385 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700386 if (pendingOptions != null) {
387 pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
388 }
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700389 if (appTimeTracker != null) {
390 appTimeTracker.dumpWithHeader(pw, prefix, false);
391 }
Dianne Hackborn7e269642010-08-25 19:50:20 -0700392 if (uriPermissions != null) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700393 uriPermissions.dump(pw, prefix);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700394 }
395 pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
Dianne Hackborn07981492013-01-28 11:36:23 -0800396 pw.print(" launchCount="); pw.print(launchCount);
397 pw.print(" lastLaunchTime=");
398 if (lastLaunchTime == 0) pw.print("0");
399 else TimeUtils.formatDuration(lastLaunchTime, now, pw);
400 pw.println();
Dianne Hackborncfc837f2013-06-27 18:32:07 -0700401 pw.print(prefix); pw.print("haveState="); pw.print(haveState);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700402 pw.print(" icicle="); pw.println(icicle);
403 pw.print(prefix); pw.print("state="); pw.print(state);
404 pw.print(" stopped="); pw.print(stopped);
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700405 pw.print(" delayedResume="); pw.print(delayedResume);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700406 pw.print(" finishing="); pw.println(finishing);
407 pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
408 pw.print(" inHistory="); pw.print(inHistory);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700409 pw.print(" visible="); pw.print(visible);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800410 pw.print(" sleeping="); pw.print(sleeping);
Wale Ogunwalef40c11b2016-02-26 08:16:02 -0800411 pw.print(" idle="); pw.print(idle);
412 pw.print(" mStartingWindowState=");
413 pw.println(startingWindowStateToString(mStartingWindowState));
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800414 pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
415 pw.print(" noDisplay="); pw.print(noDisplay);
416 pw.print(" immersive="); pw.print(immersive);
417 pw.print(" launchMode="); pw.println(launchMode);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800418 pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400419 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700420 pw.print(prefix); pw.print("mActivityType=");
421 pw.println(activityTypeToString(mActivityType));
Ruben Brunke24b9a62016-02-16 21:38:24 -0800422 if (requestedVrComponent != null) {
423 pw.print(prefix);
424 pw.print("requestedVrComponent=");
425 pw.println(requestedVrComponent);
426 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -0700427 if (displayStartTime != 0 || startTime != 0) {
428 pw.print(prefix); pw.print("displayStartTime=");
429 if (displayStartTime == 0) pw.print("0");
430 else TimeUtils.formatDuration(displayStartTime, now, pw);
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700431 pw.print(" startTime=");
432 if (startTime == 0) pw.print("0");
433 else TimeUtils.formatDuration(startTime, now, pw);
434 pw.println();
Dianne Hackborn0dad3642010-09-09 21:25:35 -0700435 }
Craig Mautner8c14c152015-01-15 17:32:07 -0800436 final boolean waitingVisible = mStackSupervisor.mWaitingVisibleActivities.contains(this);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800437 if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700438 pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800439 pw.print(" nowVisible="); pw.print(nowVisible);
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700440 pw.print(" lastVisibleTime=");
Dianne Hackbornf530ac32012-06-21 14:17:48 -0700441 if (lastVisibleTime == 0) pw.print("0");
442 else TimeUtils.formatDuration(lastVisibleTime, now, pw);
443 pw.println();
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700444 }
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800445 if (deferRelaunchUntilPaused || configChangeFlags != 0) {
446 pw.print(prefix); pw.print("deferRelaunchUntilPaused="); pw.print(deferRelaunchUntilPaused);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700447 pw.print(" configChangeFlags=");
448 pw.println(Integer.toHexString(configChangeFlags));
449 }
450 if (connections != null) {
451 pw.print(prefix); pw.print("connections="); pw.println(connections);
452 }
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800453 if (info != null) {
454 pw.println(prefix + "resizeMode=" + ActivityInfo.resizeModeToString(info.resizeMode));
Winson Chungd3395382016-12-13 11:49:09 -0800455 pw.println(prefix + "supportsPictureInPicture=" + info.supportsPictureInPicture());
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800456 }
Winson Chungc2baac02017-01-11 13:34:47 -0800457 pw.println(prefix + "supportsPictureInPictureWhilePausing: "
458 + supportsPictureInPictureWhilePausing);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 }
460
Andrii Kulian21713ac2016-10-12 22:05:05 -0700461 private boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700462 return crossesSizeThreshold(mHorizontalSizeConfigurations, firstDp, secondDp);
463 }
464
Andrii Kulian21713ac2016-10-12 22:05:05 -0700465 private boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700466 return crossesSizeThreshold(mVerticalSizeConfigurations, firstDp, secondDp);
467 }
468
Andrii Kulian21713ac2016-10-12 22:05:05 -0700469 private boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) {
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700470 return crossesSizeThreshold(mSmallestSizeConfigurations, firstDp, secondDp);
471 }
472
Filip Gruszczynski23493322015-07-29 17:02:59 -0700473 /**
474 * The purpose of this method is to decide whether the activity needs to be relaunched upon
475 * changing its size. In most cases the activities don't need to be relaunched, if the resize
476 * is small, all the activity content has to do is relayout itself within new bounds. There are
477 * cases however, where the activity's content would be completely changed in the new size and
478 * the full relaunch is required.
479 *
480 * The activity will report to us vertical and horizontal thresholds after which a relaunch is
481 * required. These thresholds are collected from the application resource qualifiers. For
482 * example, if application has layout-w600dp resource directory, then it needs a relaunch when
483 * we resize from width of 650dp to 550dp, as it crosses the 600dp threshold. However, if
484 * it resizes width from 620dp to 700dp, it won't be relaunched as it stays on the same side
485 * of the threshold.
486 */
487 private static boolean crossesSizeThreshold(int[] thresholds, int firstDp,
488 int secondDp) {
489 if (thresholds == null) {
490 return false;
491 }
492 for (int i = thresholds.length - 1; i >= 0; i--) {
493 final int threshold = thresholds[i];
494 if ((firstDp < threshold && secondDp >= threshold)
495 || (firstDp >= threshold && secondDp < threshold)) {
496 return true;
497 }
498 }
499 return false;
500 }
501
Andrii Kulian21713ac2016-10-12 22:05:05 -0700502 void setSizeConfigurations(int[] horizontalSizeConfiguration,
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700503 int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) {
Filip Gruszczynski23493322015-07-29 17:02:59 -0700504 mHorizontalSizeConfigurations = horizontalSizeConfiguration;
505 mVerticalSizeConfigurations = verticalSizeConfigurations;
Filip Gruszczynski20aa0ae2015-10-30 10:08:27 -0700506 mSmallestSizeConfigurations = smallestSizeConfigurations;
Filip Gruszczynski23493322015-07-29 17:02:59 -0700507 }
508
Andrii Kulian21713ac2016-10-12 22:05:05 -0700509 private void scheduleConfigurationChanged(Configuration config, boolean reportToActivity) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800510 if (app == null || app.thread == null) {
511 return;
512 }
513 try {
514 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + this + " " +
Adam Lesinskibad43fc2016-07-19 13:35:01 -0700515 "reportToActivity=" + reportToActivity + " and config: " + config);
Chong Zhang6be533e2016-06-17 16:24:21 -0700516
Andrii Kulian1779e612016-10-12 21:58:25 -0700517 app.thread.scheduleActivityConfigurationChanged(appToken, new Configuration(config),
518 reportToActivity);
Wale Ogunwale22e25262016-02-01 10:32:02 -0800519 } catch (RemoteException e) {
520 // If process died, whatever.
521 }
522 }
523
Andrii Kulian933076d2016-03-29 17:04:42 -0700524 void scheduleMultiWindowModeChanged() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700525 if (task == null || task.getStack() == null || app == null || app.thread == null) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800526 return;
527 }
528 try {
529 // An activity is considered to be in multi-window mode if its task isn't fullscreen.
Andrii Kulian933076d2016-03-29 17:04:42 -0700530 app.thread.scheduleMultiWindowModeChanged(appToken, !task.mFullscreen);
Wale Ogunwale22e25262016-02-01 10:32:02 -0800531 } catch (Exception e) {
532 // If process died, I don't care.
533 }
534 }
535
Andrii Kulian933076d2016-03-29 17:04:42 -0700536 void schedulePictureInPictureModeChanged() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700537 if (task == null || task.getStack() == null || app == null || app.thread == null) {
Wale Ogunwale22e25262016-02-01 10:32:02 -0800538 return;
539 }
540 try {
Andrii Kulian933076d2016-03-29 17:04:42 -0700541 app.thread.schedulePictureInPictureModeChanged(
Andrii Kulian02b7a832016-10-06 23:11:56 -0700542 appToken, task.getStackId() == PINNED_STACK_ID);
Wale Ogunwale22e25262016-02-01 10:32:02 -0800543 } catch (Exception e) {
544 // If process died, no one cares.
Filip Gruszczynskica664812015-12-04 12:43:36 -0800545 }
546 }
547
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800548 boolean isFreeform() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700549 return task != null && task.getStackId() == FREEFORM_WORKSPACE_STACK_ID;
Filip Gruszczynski3d026712015-12-16 13:46:38 -0800550 }
551
Dianne Hackbornbe707852011-11-11 14:32:10 -0800552 static class Token extends IApplicationToken.Stub {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700553 private final WeakReference<ActivityRecord> weakActivity;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800554
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800555 Token(ActivityRecord activity) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800556 weakActivity = new WeakReference<>(activity);
Wale Ogunwale7d701172015-03-11 15:36:30 -0700557 }
558
Andrii Kulian21713ac2016-10-12 22:05:05 -0700559 private static ActivityRecord tokenToActivityRecordLocked(Token token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700560 if (token == null) {
561 return null;
562 }
563 ActivityRecord r = token.weakActivity.get();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700564 if (r == null || r.getStack() == null) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700565 return null;
566 }
567 return r;
Dianne Hackbornbe707852011-11-11 14:32:10 -0800568 }
569
Craig Mautnerde4ef022013-04-07 19:01:33 -0700570 @Override
Dianne Hackbornbe707852011-11-11 14:32:10 -0800571 public String toString() {
572 StringBuilder sb = new StringBuilder(128);
573 sb.append("Token{");
574 sb.append(Integer.toHexString(System.identityHashCode(this)));
575 sb.append(' ');
576 sb.append(weakActivity.get());
577 sb.append('}');
578 return sb.toString();
579 }
580 }
581
Wale Ogunwale7d701172015-03-11 15:36:30 -0700582 static ActivityRecord forTokenLocked(IBinder token) {
Dianne Hackbornbe707852011-11-11 14:32:10 -0800583 try {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700584 return Token.tokenToActivityRecordLocked((Token)token);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800585 } catch (ClassCastException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800586 Slog.w(TAG, "Bad activity token: " + token, e);
Dianne Hackbornbe707852011-11-11 14:32:10 -0800587 return null;
588 }
589 }
590
Chong Zhang85ee6542015-10-02 13:36:38 -0700591 boolean isResolverActivity() {
592 return ResolverActivity.class.getName().equals(realActivity.getClassName());
Craig Mautnerac6f8432013-07-17 13:24:59 -0700593 }
594
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800595 ActivityRecord(ActivityManagerService _service, ProcessRecord _caller, int _launchedFromPid,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800596 int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597 ActivityInfo aInfo, Configuration _configuration,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700598 ActivityRecord _resultTo, String _resultWho, int _reqCode,
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700599 boolean _componentSpecified, boolean _rootVoiceInteraction,
600 ActivityStackSupervisor supervisor,
Wale Ogunwale1affbbc2016-05-01 09:03:52 -0700601 ActivityContainer container, ActivityOptions options, ActivityRecord sourceRecord) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 service = _service;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800603 appToken = new Token(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 info = aInfo;
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800605 launchedFromPid = _launchedFromPid;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 launchedFromUid = _launchedFromUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800607 launchedFromPackage = _launchedFromPackage;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700608 userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 intent = _intent;
610 shortComponentName = _intent.getComponent().flattenToShortString();
611 resolvedType = _resolvedType;
The Android Open Source Project4df24232009-03-05 14:34:35 -0800612 componentSpecified = _componentSpecified;
Dianne Hackbornfb81d092015-08-03 17:14:46 -0700613 rootVoiceInteraction = _rootVoiceInteraction;
Andrii Kulian1779e612016-10-12 21:58:25 -0700614 mLastReportedConfiguration = new Configuration(_configuration);
615 mLastReportedOverrideConfiguration = new Configuration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800616 resultTo = _resultTo;
617 resultWho = _resultWho;
618 requestCode = _reqCode;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -0700619 state = ActivityState.INITIALIZING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 frontOfTask = false;
621 launchFailed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 stopped = false;
Dianne Hackborn95fc68f2009-05-19 18:37:45 -0700623 delayedResume = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 finishing = false;
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800625 deferRelaunchUntilPaused = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 keysPaused = false;
627 inHistory = false;
Chong Zhanga48ef662015-08-18 19:21:47 -0700628 visible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 nowVisible = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 idle = false;
631 hasBeenLaunched = false;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700632 mStackSupervisor = supervisor;
Craig Mautnere0a38842013-12-16 16:14:02 -0800633 mInitialActivityContainer = container;
Robert Carr0f5d7532016-10-17 16:39:17 -0700634
635 mRotationAnimationHint = aInfo.rotationAnimation;
636
Craig Mautner233ceee2014-05-09 17:05:11 -0700637 if (options != null) {
Chong Zhang280d3322015-11-03 17:27:26 -0800638 pendingOptions = options;
Craig Mautnerbb742462014-07-07 15:28:55 -0700639 mLaunchTaskBehind = pendingOptions.getLaunchTaskBehind();
Robert Carr0f5d7532016-10-17 16:39:17 -0700640
641 final int rotationAnimation = pendingOptions.getRotationAnimationHint();
642 // Only override manifest supplied option if set.
643 if (rotationAnimation >= 0) {
644 mRotationAnimationHint = rotationAnimation;
645 }
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700646 PendingIntent usageReport = pendingOptions.getUsageTimeReport();
647 if (usageReport != null) {
648 appTimeTracker = new AppTimeTracker(usageReport);
649 }
Craig Mautner233ceee2014-05-09 17:05:11 -0700650 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800652 // This starts out true, since the initial state of an activity is that we have everything,
653 // and we shouldn't never consider it lacking in state to be removed if it dies.
Dianne Hackborn2d1b3782012-09-09 17:49:39 -0700654 haveState = true;
655
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800656 // If the class name in the intent doesn't match that of the target, this is
657 // probably an alias. We have to create a new ComponentName object to keep track
658 // of the real activity name, so that FLAG_ACTIVITY_CLEAR_TOP is handled properly.
659 if (aInfo.targetActivity == null
660 || (aInfo.targetActivity.equals(_intent.getComponent().getClassName())
661 && (aInfo.launchMode == LAUNCH_MULTIPLE
662 || aInfo.launchMode == LAUNCH_SINGLE_TOP))) {
663 realActivity = _intent.getComponent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 } else {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800665 realActivity = new ComponentName(aInfo.packageName, aInfo.targetActivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800667 taskAffinity = aInfo.taskAffinity;
668 stateNotNeeded = (aInfo.flags & FLAG_STATE_NOT_NEEDED) != 0;
669 appInfo = aInfo.applicationInfo;
670 nonLocalizedLabel = aInfo.nonLocalizedLabel;
671 labelRes = aInfo.labelRes;
672 if (nonLocalizedLabel == null && labelRes == 0) {
673 ApplicationInfo app = aInfo.applicationInfo;
674 nonLocalizedLabel = app.nonLocalizedLabel;
675 labelRes = app.labelRes;
676 }
677 icon = aInfo.getIconResource();
678 logo = aInfo.getLogoResource();
679 theme = aInfo.getThemeResource();
680 realTheme = theme;
681 if (realTheme == 0) {
682 realTheme = aInfo.applicationInfo.targetSdkVersion < HONEYCOMB
683 ? android.R.style.Theme : android.R.style.Theme_Holo;
684 }
685 if ((aInfo.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
686 windowFlags |= LayoutParams.FLAG_HARDWARE_ACCELERATED;
687 }
688 if ((aInfo.flags & FLAG_MULTIPROCESS) != 0 && _caller != null
689 && (aInfo.applicationInfo.uid == SYSTEM_UID
690 || aInfo.applicationInfo.uid == _caller.info.uid)) {
691 processName = _caller.processName;
692 } else {
693 processName = aInfo.processName;
694 }
695
696 if ((aInfo.flags & FLAG_EXCLUDE_FROM_RECENTS) != 0) {
697 intent.addFlags(FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
698 }
699
700 packageName = aInfo.applicationInfo.packageName;
701 launchMode = aInfo.launchMode;
702
703 AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
704 realTheme, com.android.internal.R.styleable.Window, userId);
705 final boolean translucent = ent != null && (ent.array.getBoolean(
706 com.android.internal.R.styleable.Window_windowIsTranslucent, false)
707 || (!ent.array.hasValue(
708 com.android.internal.R.styleable.Window_windowIsTranslucent)
709 && ent.array.getBoolean(
710 com.android.internal.R.styleable.Window_windowSwipeToDismiss,
711 false)));
712 fullscreen = ent != null && !ent.array.getBoolean(
713 com.android.internal.R.styleable.Window_windowIsFloating, false) && !translucent;
714 noDisplay = ent != null && ent.array.getBoolean(
715 com.android.internal.R.styleable.Window_windowNoDisplay, false);
716
717 setActivityType(_componentSpecified, _launchedFromUid, _intent, sourceRecord);
718
719 immersive = (aInfo.flags & FLAG_IMMERSIVE) != 0;
720
721 requestedVrComponent = (aInfo.requestedVrComponent == null) ?
722 null : ComponentName.unflattenFromString(aInfo.requestedVrComponent);
723 }
724
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800725 AppWindowContainerController getWindowContainerController() {
726 return mWindowContainerController;
727 }
728
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800729 void createWindowContainer() {
730 if (mWindowContainerController != null) {
731 throw new IllegalArgumentException("Window container=" + mWindowContainerController
732 + " already created for r=" + this);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800733 }
734
735 inHistory = true;
736
737 task.updateOverrideConfigurationFromLaunchBounds();
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800738 final TaskWindowContainerController taskController = task.getWindowContainerController();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800739
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800740 mWindowContainerController = new AppWindowContainerController(taskController, appToken,
741 this, Integer.MAX_VALUE /* add on top */, info.screenOrientation, fullscreen,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800742 (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, info.configChanges,
743 task.voiceSession != null, mLaunchTaskBehind, isAlwaysFocusable(),
744 appInfo.targetSdkVersion, mRotationAnimationHint,
745 ActivityManagerService.getInputDispatchingTimeoutLocked(this) * 1000000L);
746
747 task.addActivityToTop(this);
748
749 onOverrideConfigurationSent();
750 }
751
752 void removeWindowContainer() {
753 mWindowContainerController.removeContainer(getDisplayId());
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800754 mWindowContainerController = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 }
756
Winson Chung30480042017-01-26 10:55:34 -0800757 /**
758 * Reparents this activity into {@param newTask} at the provided {@param position}. The caller
759 * should ensure that the {@param newTask} is not already the parent of this activity.
760 */
761 void reparent(TaskRecord newTask, int position, String reason) {
762 final TaskRecord prevTask = task;
763 if (prevTask == newTask) {
764 throw new IllegalArgumentException(reason + ": task=" + newTask
765 + " is already the parent of r=" + this);
766 }
767
768 // Must reparent first in window manager
769 mWindowContainerController.reparent(newTask.getWindowContainerController(), position);
770
771 // Remove the activity from the old task and add it to the new task
772 prevTask.removeActivity(this);
773 setTask(newTask, null);
774 newTask.addActivityAtIndex(position, this);
775 }
776
Wale Ogunwale1affbbc2016-05-01 09:03:52 -0700777 private boolean isHomeIntent(Intent intent) {
778 return Intent.ACTION_MAIN.equals(intent.getAction())
779 && intent.hasCategory(Intent.CATEGORY_HOME)
780 && intent.getCategories().size() == 1
781 && intent.getData() == null
782 && intent.getType() == null;
783 }
784
Chong Zhangad24f962016-08-25 12:12:33 -0700785 static boolean isMainIntent(Intent intent) {
786 return Intent.ACTION_MAIN.equals(intent.getAction())
787 && intent.hasCategory(Intent.CATEGORY_LAUNCHER)
788 && intent.getCategories().size() == 1
789 && intent.getData() == null
790 && intent.getType() == null;
791 }
792
Wale Ogunwale1affbbc2016-05-01 09:03:52 -0700793 private boolean canLaunchHomeActivity(int uid, ActivityRecord sourceRecord) {
794 if (uid == Process.myUid() || uid == 0) {
795 // System process can launch home activity.
796 return true;
797 }
798 // Resolver activity can launch home activity.
799 return sourceRecord != null && sourceRecord.isResolverActivity();
800 }
801
802 private void setActivityType(boolean componentSpecified,
803 int launchedFromUid, Intent intent, ActivityRecord sourceRecord) {
804 if ((!componentSpecified || canLaunchHomeActivity(launchedFromUid, sourceRecord))
805 && isHomeIntent(intent) && !isResolverActivity()) {
806 // This sure looks like a home activity!
807 mActivityType = HOME_ACTIVITY_TYPE;
Wale Ogunwaledf241e92016-10-13 15:14:21 -0700808
809 if (info.resizeMode == RESIZE_MODE_FORCE_RESIZEABLE
810 || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) {
811 // We only allow home activities to be resizeable if they explicitly requested it.
812 info.resizeMode = RESIZE_MODE_UNRESIZEABLE;
813 }
Wale Ogunwale1affbbc2016-05-01 09:03:52 -0700814 } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) {
815 mActivityType = RECENTS_ACTIVITY_TYPE;
816 } else {
817 mActivityType = APPLICATION_ACTIVITY_TYPE;
818 }
819 }
820
Craig Mautnera228ae92014-07-09 05:44:55 -0700821 void setTask(TaskRecord newTask, TaskRecord taskToAffiliateWith) {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700822 if (task != null && task.removeActivity(this) && task != newTask
823 && task.getStack() != null) {
824 task.getStack().removeTask(task, "setTask");
Craig Mautnerde4ef022013-04-07 19:01:33 -0700825 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700826 task = newTask;
Craig Mautnera228ae92014-07-09 05:44:55 -0700827 setTaskToAffiliateWith(taskToAffiliateWith);
828 }
829
830 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
831 if (taskToAffiliateWith != null &&
832 launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE &&
833 launchMode != ActivityInfo.LAUNCH_SINGLE_TASK) {
834 task.setTaskToAffiliateWith(taskToAffiliateWith);
835 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700836 }
837
Andrii Kulian02b7a832016-10-06 23:11:56 -0700838 /**
839 * @return Stack value from current task, null if there is no task.
840 */
841 ActivityStack getStack() {
842 return task != null ? task.getStack() : null;
843 }
844
Craig Mautner5eda9b32013-07-02 11:58:16 -0700845 boolean changeWindowTranslucency(boolean toOpaque) {
846 if (fullscreen == toOpaque) {
847 return false;
848 }
Craig Mautner4addfc52013-06-25 08:05:45 -0700849
Craig Mautner5eda9b32013-07-02 11:58:16 -0700850 // Keep track of the number of fullscreen activities in this task.
851 task.numFullscreen += toOpaque ? +1 : -1;
852
853 fullscreen = toOpaque;
854 return true;
Craig Mautner4addfc52013-06-25 08:05:45 -0700855 }
856
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700857 void takeFromHistory() {
858 if (inHistory) {
859 inHistory = false;
860 if (task != null && !finishing) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800861 task = null;
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700862 }
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -0700863 clearOptionsLocked();
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700864 }
865 }
866
867 boolean isInHistory() {
868 return inHistory;
869 }
870
Wale Ogunwale7d701172015-03-11 15:36:30 -0700871 boolean isInStackLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700872 final ActivityStack stack = getStack();
873 return stack != null && stack.isInStackLocked(this) != null;
Wale Ogunwale7d701172015-03-11 15:36:30 -0700874 }
875
Craig Mautner86d67a42013-05-14 10:34:38 -0700876 boolean isHomeActivity() {
877 return mActivityType == HOME_ACTIVITY_TYPE;
878 }
879
880 boolean isRecentsActivity() {
881 return mActivityType == RECENTS_ACTIVITY_TYPE;
882 }
883
884 boolean isApplicationActivity() {
885 return mActivityType == APPLICATION_ACTIVITY_TYPE;
886 }
887
Craig Mautner21d24a22014-04-23 11:45:37 -0700888 boolean isPersistable() {
Craig Mautner43e52ed2014-06-16 17:18:52 -0700889 return (info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY ||
890 info.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS) &&
891 (intent == null ||
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800892 (intent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
Craig Mautner21d24a22014-04-23 11:45:37 -0700893 }
894
Wale Ogunwale4cea0f52015-12-25 06:30:31 -0800895 boolean isFocusable() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700896 return StackId.canReceiveKeys(task.getStackId()) || isAlwaysFocusable();
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800897 }
898
899 boolean isResizeable() {
Winson Chungd3395382016-12-13 11:49:09 -0800900 return ActivityInfo.isResizeableMode(info.resizeMode) || info.supportsPictureInPicture();
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800901 }
902
Winson Chungd3395382016-12-13 11:49:09 -0800903 /**
904 * @return whether this activity is non-resizeable or forced to be resizeable
905 */
906 boolean isNonResizableOrForcedResizable() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -0700907 return info.resizeMode != RESIZE_MODE_RESIZEABLE
Wale Ogunwale72a73e32016-10-13 12:16:39 -0700908 && info.resizeMode != RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Jorim Jaggicd13d332016-04-27 15:40:20 -0700909 }
910
Winson Chunge6308042016-10-31 09:24:01 -0700911 /**
Winson Chungd3395382016-12-13 11:49:09 -0800912 * @return whether this activity supports PiP multi-window and can be put in the pinned stack.
Winson Chunge6308042016-10-31 09:24:01 -0700913 */
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800914 boolean supportsPictureInPicture() {
Winson Chungd3395382016-12-13 11:49:09 -0800915 return service.mSupportsPictureInPicture && !isHomeActivity()
916 && info.supportsPictureInPicture();
917 }
918
919 /**
920 * @return whether this activity supports split-screen multi-window and can be put in the docked
921 * stack.
922 */
923 boolean supportsSplitScreen() {
924 // An activity can not be docked even if it is considered resizeable because it only
925 // supports picture-in-picture mode but has a non-resizeable resizeMode
926 return service.mSupportsSplitScreenMultiWindow && supportsResizeableMultiWindow();
927 }
928
929 /**
930 * @return whether this activity supports freeform multi-window and can be put in the freeform
931 * stack.
932 */
933 boolean supportsFreeform() {
934 return service.mSupportsFreeformWindowManagement && supportsResizeableMultiWindow();
935 }
936
937 /**
938 * @return whether this activity supports non-PiP multi-window.
939 */
940 private boolean supportsResizeableMultiWindow() {
941 return service.mSupportsMultiWindow && !isHomeActivity()
942 && (ActivityInfo.isResizeableMode(info.resizeMode)
943 || service.mForceResizableActivities);
Wale Ogunwaled26176f2016-01-25 20:04:04 -0800944 }
945
Winson Chunge6308042016-10-31 09:24:01 -0700946 /**
Winson Chungc2baac02017-01-11 13:34:47 -0800947 * @return whether this activity is currently allowed to enter PIP, throwing an exception if
Winson Chung4dabf232017-01-25 13:25:22 -0800948 * the activity is not currently visible and {@param noThrow} is not set.
Winson Chunge6308042016-10-31 09:24:01 -0700949 */
Winson Chung4dabf232017-01-25 13:25:22 -0800950 boolean checkEnterPictureInPictureState(String caller, boolean noThrow) {
Winson Chungbb348802017-01-30 12:01:45 -0800951 boolean isCurrentAppLocked = mStackSupervisor.getLockTaskModeState() != LOCK_TASK_MODE_NONE;
Winson Chungc2baac02017-01-11 13:34:47 -0800952 boolean isKeyguardLocked = service.isKeyguardLocked();
953 boolean hasPinnedStack = mStackSupervisor.getStack(PINNED_STACK_ID) != null;
Winson Chungbb348802017-01-30 12:01:45 -0800954 // Don't return early if !isNotLocked, since we want to throw an exception if the activity
955 // is in an incorrect state
956 boolean isNotLocked = !isKeyguardLocked && !isCurrentAppLocked;
Winson Chungc2baac02017-01-11 13:34:47 -0800957 switch (state) {
958 case RESUMED:
Winson Chungbb348802017-01-30 12:01:45 -0800959 // When visible, allow entering PiP if not on the lockscreen and if the task is not
960 // locked
961 return isNotLocked;
Winson Chungc2baac02017-01-11 13:34:47 -0800962 case PAUSING:
963 case PAUSED:
Winson Chungbb348802017-01-30 12:01:45 -0800964 // When pausing, then only allow enter PiP as in the resume state, and in addition,
965 // require that there is not an existing PiP activity and that the current system
966 // state supports entering PiP
967 return isNotLocked && !hasPinnedStack && supportsPictureInPictureWhilePausing
Winson Chung59fda9e2017-01-20 16:14:51 -0800968 && checkEnterPictureInPictureOnHideAppOpsState();
Winson Chungc2baac02017-01-11 13:34:47 -0800969 case STOPPING:
970 // When stopping in a valid state, then only allow enter PiP as in the pause state.
971 // Otherwise, fall through to throw an exception if the caller is trying to enter
972 // PiP in an invalid stopping state.
973 if (supportsPictureInPictureWhilePausing) {
Winson Chungbb348802017-01-30 12:01:45 -0800974 return isNotLocked && !hasPinnedStack
Winson Chung59fda9e2017-01-20 16:14:51 -0800975 && checkEnterPictureInPictureOnHideAppOpsState();
Winson Chungc2baac02017-01-11 13:34:47 -0800976 }
977 default:
Winson Chung4dabf232017-01-25 13:25:22 -0800978 if (noThrow) {
979 return false;
980 } else {
981 throw new IllegalStateException(caller
982 + ": Current activity is not visible (state=" + state.name() + ") "
983 + "r=" + this);
984 }
Winson Chungb5c41b72016-12-07 15:00:47 -0800985 }
Winson Chunge6308042016-10-31 09:24:01 -0700986 }
987
Winson Chung59fda9e2017-01-20 16:14:51 -0800988 /**
989 * @return Whether AppOps allows this package to enter picture-in-picture when it is hidden.
990 */
991 private boolean checkEnterPictureInPictureOnHideAppOpsState() {
992 try {
993 return service.getAppOpsService().checkOperation(OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE,
994 appInfo.uid, packageName) == MODE_ALLOWED;
995 } catch (RemoteException e) {
996 // Local call
997 }
998 return false;
999 }
1000
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001001 boolean isAlwaysFocusable() {
1002 return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0;
Wale Ogunwale4cea0f52015-12-25 06:30:31 -08001003 }
1004
Jorim Jaggife762342016-10-13 14:33:27 +02001005 /**
1006 * @return true if the activity contains windows that have
1007 * {@link LayoutParams#FLAG_SHOW_WHEN_LOCKED} set
1008 */
1009 boolean hasShowWhenLockedWindows() {
1010 return service.mWindowManager.containsShowWhenLockedWindow(appToken);
1011 }
1012
1013 /**
1014 * @return true if the activity contains windows that have
1015 * {@link LayoutParams#FLAG_DISMISS_KEYGUARD} set
1016 */
1017 boolean hasDismissKeyguardWindows() {
1018 return service.mWindowManager.containsDismissKeyguardWindow(appToken);
1019 }
1020
Wale Ogunwale7d701172015-03-11 15:36:30 -07001021 void makeFinishingLocked() {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08001022 if (!finishing) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001023 final ActivityStack stack = getStack();
1024 if (stack != null && this == stack.getVisibleBehindActivity()) {
Jose Lima34ff4922014-08-18 15:19:41 -07001025 // A finishing activity should not remain as visible in the background
1026 mStackSupervisor.requestVisibleBehindLocked(this, false);
1027 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08001028 finishing = true;
Dianne Hackborn6e3d6da2012-06-15 12:05:27 -07001029 if (stopped) {
1030 clearOptionsLocked();
1031 }
Yorke Leebd54c2a2016-10-25 13:49:23 -07001032
1033 if (service != null) {
1034 service.mTaskChangeNotificationController.notifyTaskStackChanged();
1035 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08001036 }
1037 }
1038
Dianne Hackborn7e269642010-08-25 19:50:20 -07001039 UriPermissionOwner getUriPermissionsLocked() {
1040 if (uriPermissions == null) {
1041 uriPermissions = new UriPermissionOwner(service, this);
1042 }
1043 return uriPermissions;
1044 }
1045
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001046 void addResultLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 int requestCode, int resultCode,
1048 Intent resultData) {
1049 ActivityResult r = new ActivityResult(from, resultWho,
John Spurlock8a985d22014-02-25 09:40:05 -05001050 requestCode, resultCode, resultData);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 if (results == null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001052 results = new ArrayList<ResultInfo>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 }
1054 results.add(r);
1055 }
1056
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001057 void removeResultsLocked(ActivityRecord from, String resultWho,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 int requestCode) {
1059 if (results != null) {
1060 for (int i=results.size()-1; i>=0; i--) {
1061 ActivityResult r = (ActivityResult)results.get(i);
1062 if (r.mFrom != from) continue;
1063 if (r.mResultWho == null) {
1064 if (resultWho != null) continue;
1065 } else {
1066 if (!r.mResultWho.equals(resultWho)) continue;
1067 }
1068 if (r.mRequestCode != requestCode) continue;
1069
1070 results.remove(i);
1071 }
1072 }
1073 }
1074
Andrii Kulian21713ac2016-10-12 22:05:05 -07001075 private void addNewIntentLocked(ReferrerIntent intent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 if (newIntents == null) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001077 newIntents = new ArrayList<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 }
1079 newIntents.add(intent);
1080 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001081
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001082 /**
1083 * Deliver a new Intent to an existing activity, so that its onNewIntent()
1084 * method will be called at the proper time.
1085 */
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001086 final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) {
Dianne Hackborn514074f2013-02-11 10:52:46 -08001087 // The activity now gets access to the data associated with this Intent.
1088 service.grantUriPermissionFromIntentLocked(callingUid, packageName,
Nicolas Prevotc6cf95c2014-05-29 11:30:36 +01001089 intent, getUriPermissionsLocked(), userId);
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001090 final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
Craig Mautner86d67a42013-05-14 10:34:38 -07001091 boolean unsent = true;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001092 final ActivityStack stack = getStack();
Wale Ogunwale826c7062016-09-13 08:25:54 -07001093 final boolean isTopActivityInStack =
1094 stack != null && stack.topRunningActivityLocked() == this;
1095 final boolean isTopActivityWhileSleeping =
1096 service.isSleepingLocked() && isTopActivityInStack;
Wale Ogunwale826c7062016-09-13 08:25:54 -07001097
1098 // We want to immediately deliver the intent to the activity if:
Wale Ogunwale03f7e9e2016-09-22 09:04:09 -07001099 // - It is currently resumed or paused. i.e. it is currently visible to the user and we want
1100 // the user to see the visual effects caused by the intent delivery now.
Wale Ogunwale826c7062016-09-13 08:25:54 -07001101 // - The device is sleeping and it is the top activity behind the lock screen (b/6700897).
Wale Ogunwale03f7e9e2016-09-22 09:04:09 -07001102 if ((state == ActivityState.RESUMED || state == ActivityState.PAUSED
1103 || isTopActivityWhileSleeping) && app != null && app.thread != null) {
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001104 try {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001105 ArrayList<ReferrerIntent> ar = new ArrayList<>(1);
1106 ar.add(rintent);
Wale Ogunwale826c7062016-09-13 08:25:54 -07001107 app.thread.scheduleNewIntent(
Wale Ogunwale03f7e9e2016-09-22 09:04:09 -07001108 ar, appToken, state == ActivityState.PAUSED /* andPause */);
Craig Mautner86d67a42013-05-14 10:34:38 -07001109 unsent = false;
Dianne Hackborn39792d22010-08-19 18:01:52 -07001110 } catch (RemoteException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001111 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn39792d22010-08-19 18:01:52 -07001112 } catch (NullPointerException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001113 Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001114 }
1115 }
Craig Mautner86d67a42013-05-14 10:34:38 -07001116 if (unsent) {
Dianne Hackborn85d558c2014-11-04 10:31:54 -08001117 addNewIntentLocked(rintent);
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001118 }
1119 }
1120
Dianne Hackborn9622ca42012-10-23 18:56:33 -07001121 void updateOptionsLocked(ActivityOptions options) {
1122 if (options != null) {
1123 if (pendingOptions != null) {
1124 pendingOptions.abort();
1125 }
1126 pendingOptions = options;
1127 }
1128 }
1129
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001130 void applyOptionsLocked() {
George Mount2c92c972014-03-20 09:38:23 -07001131 if (pendingOptions != null
1132 && pendingOptions.getAnimationType() != ActivityOptions.ANIM_SCENE_TRANSITION) {
Michael Jurka21385cd2012-05-03 10:57:31 -07001133 final int animationType = pendingOptions.getAnimationType();
1134 switch (animationType) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001135 case ActivityOptions.ANIM_CUSTOM:
1136 service.mWindowManager.overridePendingAppTransition(
1137 pendingOptions.getPackageName(),
1138 pendingOptions.getCustomEnterResId(),
Dianne Hackborn84375872012-06-01 19:03:50 -07001139 pendingOptions.getCustomExitResId(),
1140 pendingOptions.getOnAnimationStartListener());
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001141 break;
Chet Haase10e23ab2015-02-11 15:08:38 -08001142 case ActivityOptions.ANIM_CLIP_REVEAL:
1143 service.mWindowManager.overridePendingAppTransitionClipReveal(
1144 pendingOptions.getStartX(), pendingOptions.getStartY(),
1145 pendingOptions.getWidth(), pendingOptions.getHeight());
1146 if (intent.getSourceBounds() == null) {
1147 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1148 pendingOptions.getStartY(),
1149 pendingOptions.getStartX()+pendingOptions.getWidth(),
1150 pendingOptions.getStartY()+pendingOptions.getHeight()));
1151 }
1152 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001153 case ActivityOptions.ANIM_SCALE_UP:
1154 service.mWindowManager.overridePendingAppTransitionScaleUp(
1155 pendingOptions.getStartX(), pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001156 pendingOptions.getWidth(), pendingOptions.getHeight());
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001157 if (intent.getSourceBounds() == null) {
1158 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1159 pendingOptions.getStartY(),
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001160 pendingOptions.getStartX()+pendingOptions.getWidth(),
1161 pendingOptions.getStartY()+pendingOptions.getHeight()));
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001162 }
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001163 break;
Michael Jurka832cb222012-04-13 09:32:47 -07001164 case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
1165 case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
1166 boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001167 service.mWindowManager.overridePendingAppTransitionThumb(
1168 pendingOptions.getThumbnail(),
1169 pendingOptions.getStartX(), pendingOptions.getStartY(),
Michael Jurka21385cd2012-05-03 10:57:31 -07001170 pendingOptions.getOnAnimationStartListener(),
Michael Jurka832cb222012-04-13 09:32:47 -07001171 scaleUp);
Dianne Hackbornd367ca82012-05-07 15:49:39 -07001172 if (intent.getSourceBounds() == null) {
1173 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1174 pendingOptions.getStartY(),
1175 pendingOptions.getStartX()
1176 + pendingOptions.getThumbnail().getWidth(),
1177 pendingOptions.getStartY()
1178 + pendingOptions.getThumbnail().getHeight()));
1179 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001180 break;
Winson Chunga4ccb862014-08-22 15:26:27 -07001181 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP:
1182 case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001183 final AppTransitionAnimationSpec[] specs = pendingOptions.getAnimSpecs();
1184 if (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN
1185 && specs != null) {
1186 service.mWindowManager.overridePendingAppTransitionMultiThumb(
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001187 specs, pendingOptions.getOnAnimationStartListener(),
1188 pendingOptions.getAnimationFinishedListener(), false);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001189 } else {
1190 service.mWindowManager.overridePendingAppTransitionAspectScaledThumb(
1191 pendingOptions.getThumbnail(),
1192 pendingOptions.getStartX(), pendingOptions.getStartY(),
1193 pendingOptions.getWidth(), pendingOptions.getHeight(),
1194 pendingOptions.getOnAnimationStartListener(),
1195 (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP));
1196 if (intent.getSourceBounds() == null) {
1197 intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
1198 pendingOptions.getStartY(),
1199 pendingOptions.getStartX() + pendingOptions.getWidth(),
1200 pendingOptions.getStartY() + pendingOptions.getHeight()));
1201 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001202 }
1203 break;
Craig Mautner233ceee2014-05-09 17:05:11 -07001204 default:
1205 Slog.e(TAG, "applyOptionsLocked: Unknown animationType=" + animationType);
1206 break;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001207 }
1208 pendingOptions = null;
1209 }
1210 }
1211
Adam Powellcfbe9be2013-11-06 14:58:58 -08001212 ActivityOptions getOptionsForTargetActivityLocked() {
1213 return pendingOptions != null ? pendingOptions.forTargetActivity() : null;
1214 }
1215
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001216 void clearOptionsLocked() {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001217 if (pendingOptions != null) {
1218 pendingOptions.abort();
1219 pendingOptions = null;
1220 }
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001221 }
1222
Dianne Hackborn9622ca42012-10-23 18:56:33 -07001223 ActivityOptions takeOptionsLocked() {
1224 ActivityOptions opts = pendingOptions;
1225 pendingOptions = null;
1226 return opts;
1227 }
1228
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001229 void removeUriPermissionsLocked() {
Dianne Hackborn7e269642010-08-25 19:50:20 -07001230 if (uriPermissions != null) {
1231 uriPermissions.removeUriPermissionsLocked();
1232 uriPermissions = null;
Dianne Hackborn50dc3bc2010-06-25 10:05:59 -07001233 }
1234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235
1236 void pauseKeyDispatchingLocked() {
1237 if (!keysPaused) {
1238 keysPaused = true;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001239 mWindowContainerController.pauseKeyDispatching();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240 }
1241 }
1242
1243 void resumeKeyDispatchingLocked() {
1244 if (keysPaused) {
1245 keysPaused = false;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001246 mWindowContainerController.resumeKeyDispatching();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 }
1248 }
1249
Winson Chung740c3ac2014-11-12 16:14:38 -08001250 void updateThumbnailLocked(Bitmap newThumbnail, CharSequence description) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001251 if (newThumbnail != null) {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001252 if (DEBUG_THUMBNAILS) Slog.i(TAG_THUMBNAILS,
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001253 "Setting thumbnail of " + this + " to " + newThumbnail);
Winsonc809cbb2015-11-02 12:06:15 -08001254 boolean thumbnailUpdated = task.setLastThumbnailLocked(newThumbnail);
Winson Chung096f36b2014-08-20 15:39:01 -07001255 if (thumbnailUpdated && isPersistable()) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001256 service.notifyTaskPersisterLocked(task, false);
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001257 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001258 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001259 task.lastDescription = description;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001260 }
1261
Andrii Kulian21713ac2016-10-12 22:05:05 -07001262 final Bitmap screenshotActivityLocked() {
1263 if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "screenshotActivityLocked: " + this);
Jorim Jaggi02886a82016-12-06 09:10:06 -08001264
1265 if (ENABLE_TASK_SNAPSHOTS) {
1266 // No need to screenshot if snapshots are enabled.
1267 if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS,
1268 "\tSnapshots are enabled, abort taking screenshot");
1269 return null;
1270 }
1271
Andrii Kulian21713ac2016-10-12 22:05:05 -07001272 if (noDisplay) {
1273 if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tNo display");
1274 return null;
1275 }
1276
1277 final ActivityStack stack = getStack();
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001278 if (stack.isHomeOrRecentsStack()) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001279 // This is an optimization -- since we never show Home or Recents within Recents itself,
1280 // we can just go ahead and skip taking the screenshot if this is the home stack.
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001281 if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, stack.getStackId() == HOME_STACK_ID ?
1282 "\tHome stack" : "\tRecents stack");
Andrii Kulian21713ac2016-10-12 22:05:05 -07001283 return null;
1284 }
1285
1286 int w = service.mThumbnailWidth;
1287 int h = service.mThumbnailHeight;
1288
1289 if (w <= 0) {
1290 Slog.e(TAG, "\tInvalid thumbnail dimensions: " + w + "x" + h);
1291 return null;
1292 }
1293
1294 if (stack.mStackId == DOCKED_STACK_ID && mStackSupervisor.mIsDockMinimized) {
1295 // When the docked stack is minimized its app windows are cropped significantly so any
1296 // screenshot taken will not display the apps contain. So, we avoid taking a screenshot
1297 // in that case.
1298 if (DEBUG_SCREENSHOTS) Slog.e(TAG, "\tIn minimized docked stack");
1299 return null;
1300 }
1301
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001302 float scale = 0;
Andrii Kulian21713ac2016-10-12 22:05:05 -07001303 if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tTaking screenshot");
1304
1305 // When this flag is set, we currently take the fullscreen screenshot of the activity but
1306 // scaled to half the size. This gives us a "good-enough" fullscreen thumbnail to use within
1307 // SystemUI while keeping memory usage low.
1308 if (TAKE_FULLSCREEN_SCREENSHOTS) {
1309 w = h = -1;
1310 scale = service.mFullscreenThumbnailScale;
1311 }
1312
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001313 return mWindowContainerController.screenshotApplications(getDisplayId(), w, h, scale);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001314 }
1315
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001316 void setVisibility(boolean visible) {
1317 mWindowContainerController.setVisibility(visible);
1318 }
1319
1320 // TODO: Look into merging with #setVisibility()
Andrii Kulian21713ac2016-10-12 22:05:05 -07001321 void setVisible(boolean newVisible) {
1322 visible = newVisible;
1323 if (!visible && mUpdateTaskThumbnailWhenHidden) {
1324 updateThumbnailLocked(screenshotActivityLocked(), null /* description */);
1325 mUpdateTaskThumbnailWhenHidden = false;
1326 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001327 mWindowContainerController.setVisibility(visible);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001328 final ArrayList<ActivityContainer> containers = mChildContainers;
1329 for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) {
1330 final ActivityContainer container = containers.get(containerNdx);
1331 container.setVisible(visible);
1332 }
1333 mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
1334 }
1335
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001336 void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
1337 mWindowContainerController.notifyAppResumed(wasStopped, allowSavedSurface);
1338 }
1339
1340 void notifyUnknownVisibilityLaunched() {
1341 mWindowContainerController.notifyUnknownVisibilityLaunched();
1342 }
1343
Jorim Jaggi241ae102016-11-02 21:57:33 -07001344 /**
1345 * @return true if the input activity should be made visible, ignoring any effect Keyguard
1346 * might have on the visibility
1347 *
1348 * @see {@link ActivityStack#checkKeyguardVisibility}
1349 */
1350 boolean shouldBeVisibleIgnoringKeyguard(boolean behindTranslucentActivity,
1351 boolean stackVisibleBehind, ActivityRecord visibleBehind,
1352 boolean behindFullscreenActivity) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001353 if (!okToShowLocked()) {
1354 return false;
1355 }
1356
1357 // mLaunchingBehind: Activities launching behind are at the back of the task stack
1358 // but must be drawn initially for the animation as though they were visible.
1359 final boolean activityVisibleBehind =
1360 (behindTranslucentActivity || stackVisibleBehind) && visibleBehind == this;
1361
1362 boolean isVisible =
1363 !behindFullscreenActivity || mLaunchTaskBehind || activityVisibleBehind;
1364
1365 if (service.mSupportsLeanbackOnly && isVisible && isRecentsActivity()) {
1366 // On devices that support leanback only (Android TV), Recents activity can only be
1367 // visible if the home stack is the focused stack or we are in split-screen mode.
1368 isVisible = mStackSupervisor.getStack(DOCKED_STACK_ID) != null
1369 || mStackSupervisor.isFocusedStack(getStack());
1370 }
1371
1372 return isVisible;
1373 }
1374
1375 void makeVisibleIfNeeded(ActivityRecord starting) {
1376 // This activity is not currently visible, but is running. Tell it to become visible.
1377 if (state == ActivityState.RESUMED || this == starting) {
1378 if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY,
1379 "Not making visible, r=" + this + " state=" + state + " starting=" + starting);
1380 return;
1381 }
1382
1383 // If this activity is paused, tell it to now show its window.
1384 if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY,
1385 "Making visible and scheduling visibility: " + this);
1386 final ActivityStack stack = getStack();
1387 try {
1388 if (stack.mTranslucentActivityWaiting != null) {
1389 updateOptionsLocked(returningOptions);
1390 stack.mUndrawnActivitiesBelowTopTranslucent.add(this);
1391 }
1392 setVisible(true);
1393 sleeping = false;
1394 app.pendingUiClean = true;
1395 app.thread.scheduleWindowVisibility(appToken, true /* showWindow */);
1396 // The activity may be waiting for stop, but that is no longer appropriate for it.
1397 mStackSupervisor.mStoppingActivities.remove(this);
1398 mStackSupervisor.mGoingToSleepActivities.remove(this);
1399 } catch (Exception e) {
1400 // Just skip on any failure; we'll make it visible when it next restarts.
1401 Slog.w(TAG, "Exception thrown making visibile: " + intent.getComponent(), e);
1402 }
1403 handleAlreadyVisible();
1404 }
1405
1406 boolean handleAlreadyVisible() {
1407 stopFreezingScreenLocked(false);
1408 try {
1409 if (returningOptions != null) {
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001410 app.thread.scheduleOnNewActivityOptions(appToken, returningOptions.toBundle());
Andrii Kulian21713ac2016-10-12 22:05:05 -07001411 }
1412 } catch(RemoteException e) {
1413 }
1414 return state == ActivityState.RESUMED;
1415 }
1416
1417 static void activityResumedLocked(IBinder token) {
1418 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
1419 if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r);
1420 if (r != null) {
1421 r.icicle = null;
1422 r.haveState = false;
1423 }
1424 }
1425
1426 /**
1427 * Once we know that we have asked an application to put an activity in the resumed state
1428 * (either by launching it or explicitly telling it), this function updates the rest of our
1429 * state to match that fact.
1430 */
1431 void completeResumeLocked() {
1432 final boolean wasVisible = visible;
1433 visible = true;
1434 if (!wasVisible) {
1435 // Visibility has changed, so take a note of it so we call the TaskStackChangedListener
1436 mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
1437 }
1438 idle = false;
1439 results = null;
1440 newIntents = null;
1441 stopped = false;
1442
1443 if (isHomeActivity()) {
1444 ProcessRecord app = task.mActivities.get(0).app;
1445 if (app != null && app != service.mHomeProcess) {
1446 service.mHomeProcess = app;
1447 }
1448 }
1449
1450 if (nowVisible) {
1451 // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now.
1452 mStackSupervisor.reportActivityVisibleLocked(this);
Andrii Kulian21713ac2016-10-12 22:05:05 -07001453 }
1454
1455 // Schedule an idle timeout in case the app doesn't do it for us.
1456 mStackSupervisor.scheduleIdleTimeoutLocked(this);
1457
1458 mStackSupervisor.reportResumedActivityLocked(this);
1459
1460 resumeKeyDispatchingLocked();
1461 final ActivityStack stack = getStack();
1462 stack.mNoAnimActivities.clear();
1463
1464 // Mark the point when the activity is resuming
1465 // TODO: To be more accurate, the mark should be before the onCreate,
1466 // not after the onResume. But for subsequent starts, onResume is fine.
1467 if (app != null) {
1468 cpuTimeAtResume = service.mProcessCpuTracker.getCpuTimeForPid(app.pid);
1469 } else {
1470 cpuTimeAtResume = 0; // Couldn't get the cpu time of process
1471 }
1472
1473 returningOptions = null;
1474
1475 if (stack.getVisibleBehindActivity() == this) {
1476 // When resuming an activity, require it to call requestVisibleBehind() again.
1477 stack.setVisibleBehindActivity(null /* ActivityRecord */);
1478 }
1479 mStackSupervisor.checkReadyForSleepLocked();
1480 }
1481
1482 final void activityStoppedLocked(Bundle newIcicle, PersistableBundle newPersistentState,
1483 CharSequence description) {
1484 final ActivityStack stack = getStack();
1485 if (state != ActivityState.STOPPING) {
1486 Slog.i(TAG, "Activity reported stop, but no longer stopping: " + this);
1487 stack.mHandler.removeMessages(ActivityStack.STOP_TIMEOUT_MSG, this);
1488 return;
1489 }
1490 if (newPersistentState != null) {
1491 persistentState = newPersistentState;
1492 service.notifyTaskPersisterLocked(task, false);
1493 }
1494 if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, "Saving icicle of " + this + ": " + icicle);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001495
Andrii Kulian21713ac2016-10-12 22:05:05 -07001496 if (newIcicle != null) {
1497 // If icicle is null, this is happening due to a timeout, so we haven't really saved
1498 // the state.
1499 icicle = newIcicle;
1500 haveState = true;
1501 launchCount = 0;
1502 updateThumbnailLocked(null /* newThumbnail */, description);
1503 }
1504 if (!stopped) {
1505 if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to STOPPED: " + this + " (stop complete)");
1506 stack.mHandler.removeMessages(ActivityStack.STOP_TIMEOUT_MSG, this);
1507 stopped = true;
1508 state = ActivityState.STOPPED;
1509
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001510 mWindowContainerController.notifyAppStopped();
Andrii Kulian21713ac2016-10-12 22:05:05 -07001511
1512 if (stack.getVisibleBehindActivity() == this) {
1513 mStackSupervisor.requestVisibleBehindLocked(this, false /* visible */);
1514 }
1515 if (finishing) {
1516 clearOptionsLocked();
1517 } else {
1518 if (deferRelaunchUntilPaused) {
1519 stack.destroyActivityLocked(this, true /* removeFromApp */, "stop-config");
1520 mStackSupervisor.resumeFocusedStackTopActivityLocked();
1521 } else {
1522 mStackSupervisor.updatePreviousProcessLocked(this);
1523 }
1524 }
1525 }
1526 }
1527
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001528 void startLaunchTickingLocked() {
1529 if (ActivityManagerService.IS_USER_BUILD) {
1530 return;
1531 }
1532 if (launchTickTime == 0) {
1533 launchTickTime = SystemClock.uptimeMillis();
1534 continueLaunchTickingLocked();
1535 }
1536 }
1537
1538 boolean continueLaunchTickingLocked() {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001539 if (launchTickTime == 0) {
1540 return false;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001541 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001542
Andrii Kulian02b7a832016-10-06 23:11:56 -07001543 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001544 if (stack == null) {
1545 return false;
1546 }
1547
1548 Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG, this);
1549 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
1550 stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
1551 return true;
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001552 }
1553
1554 void finishLaunchTickingLocked() {
1555 launchTickTime = 0;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001556 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001557 if (stack != null) {
1558 stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
1559 }
Dianne Hackborn2a29b3a2012-03-15 15:48:38 -07001560 }
1561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 // IApplicationToken
1563
1564 public boolean mayFreezeScreenLocked(ProcessRecord app) {
1565 // Only freeze the screen if this activity is currently attached to
1566 // an application, and that application is not blocked or unresponding.
1567 // In any other case, we can't count on getting the screen unfrozen,
1568 // so it is best to leave as-is.
Dianne Hackborn5f4d6432010-12-21 20:40:11 -08001569 return app != null && !app.crashing && !app.notResponding;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001572 public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
1573 if (mayFreezeScreenLocked(app)) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001574 mWindowContainerController.startFreezingScreen(configChanges);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001575 }
1576 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 public void stopFreezingScreenLocked(boolean force) {
1579 if (force || frozenBeforeDestroy) {
1580 frozenBeforeDestroy = false;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001581 mWindowContainerController.stopFreezingScreen(force);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001582 }
1583 }
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001584
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001585 public void reportFullyDrawnLocked() {
1586 final long curTime = SystemClock.uptimeMillis();
1587 if (displayStartTime != 0) {
1588 reportLaunchTimeLocked(curTime);
1589 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001590 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001591 if (fullyDrawnStartTime != 0 && stack != null) {
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001592 final long thisTime = curTime - fullyDrawnStartTime;
1593 final long totalTime = stack.mFullyDrawnStartTime != 0
1594 ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07001595 if (SHOW_ACTIVITY_START_TIME) {
Dianne Hackborncee04b52013-07-03 17:01:28 -07001596 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001597 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME,
1598 userId, System.identityHashCode(this), shortComponentName,
1599 thisTime, totalTime);
1600 StringBuilder sb = service.mStringBuilder;
1601 sb.setLength(0);
1602 sb.append("Fully drawn ");
1603 sb.append(shortComponentName);
1604 sb.append(": ");
1605 TimeUtils.formatDuration(thisTime, sb);
1606 if (thisTime != totalTime) {
1607 sb.append(" (total ");
1608 TimeUtils.formatDuration(totalTime, sb);
1609 sb.append(")");
1610 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001611 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001612 }
1613 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001614 //service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001615 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001616 stack.mFullyDrawnStartTime = 0;
1617 }
Wale Ogunwale7d701172015-03-11 15:36:30 -07001618 fullyDrawnStartTime = 0;
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001619 }
1620
1621 private void reportLaunchTimeLocked(final long curTime) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001622 final ActivityStack stack = getStack();
Wale Ogunwale7d701172015-03-11 15:36:30 -07001623 if (stack == null) {
1624 return;
1625 }
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001626 final long thisTime = curTime - displayStartTime;
1627 final long totalTime = stack.mLaunchStartTime != 0
1628 ? (curTime - stack.mLaunchStartTime) : thisTime;
Wale Ogunwale3ab9a272015-03-16 09:55:45 -07001629 if (SHOW_ACTIVITY_START_TIME) {
Narayan Kamath7829c812015-06-08 17:39:43 +01001630 Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001631 EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
1632 userId, System.identityHashCode(this), shortComponentName,
1633 thisTime, totalTime);
1634 StringBuilder sb = service.mStringBuilder;
1635 sb.setLength(0);
1636 sb.append("Displayed ");
1637 sb.append(shortComponentName);
1638 sb.append(": ");
1639 TimeUtils.formatDuration(thisTime, sb);
1640 if (thisTime != totalTime) {
1641 sb.append(" (total ");
1642 TimeUtils.formatDuration(totalTime, sb);
1643 sb.append(")");
1644 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -08001645 Log.i(TAG, sb.toString());
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001646 }
1647 mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
1648 if (totalTime > 0) {
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001649 //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
Dianne Hackborn2286cdc2013-07-01 19:10:06 -07001650 }
1651 displayStartTime = 0;
1652 stack.mLaunchStartTime = 0;
1653 }
1654
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001655 @Override
1656 public void onWindowsDrawn() {
1657 synchronized (service) {
1658 mStackSupervisor.mActivityMetricsLogger.notifyWindowsDrawn();
1659 if (displayStartTime != 0) {
1660 reportLaunchTimeLocked(SystemClock.uptimeMillis());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001661 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001662 mStackSupervisor.sendWaitingVisibleReportLocked(this);
1663 startTime = 0;
1664 finishLaunchTickingLocked();
1665 if (task != null) {
1666 task.hasBeenVisible = true;
1667 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 }
1669 }
1670
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001671 @Override
1672 public void onWindowsVisible() {
1673 synchronized (service) {
1674 mStackSupervisor.reportActivityVisibleLocked(this);
1675 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this);
1676 if (!nowVisible) {
1677 nowVisible = true;
1678 lastVisibleTime = SystemClock.uptimeMillis();
1679 if (!idle) {
1680 // Instead of doing the full stop routine here, let's just hide any activities
1681 // we now can, and let them stop when the normal idle happens.
Winson Chung4dabf232017-01-25 13:25:22 -08001682 mStackSupervisor.processStoppingActivitiesLocked(null /* idleActivity */,
1683 false /* remove */, true /* processPausingActivities */);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001684 } else {
1685 // If this activity was already idle, then we now need to make sure we perform
1686 // the full stop of any activities that are waiting to do so. This is because
1687 // we won't do that while they are still waiting for this one to become visible.
1688 final int size = mStackSupervisor.mWaitingVisibleActivities.size();
1689 if (size > 0) {
1690 for (int i = 0; i < size; i++) {
1691 ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i);
1692 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "Was waiting for visible: " + r);
1693 }
1694 mStackSupervisor.mWaitingVisibleActivities.clear();
1695 mStackSupervisor.scheduleIdleLocked();
1696 }
1697 }
1698 service.scheduleAppGcsLocked();
1699 }
1700 }
1701 }
1702
1703 @Override
1704 public void onWindowsGone() {
1705 synchronized (service) {
1706 if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + this);
1707 nowVisible = false;
1708 }
1709 }
1710
1711 @Override
1712 public boolean keyDispatchingTimedOut(String reason) {
1713 ActivityRecord anrActivity;
1714 ProcessRecord anrApp;
1715 synchronized (service) {
1716 anrActivity = getWaitingHistoryRecordLocked();
1717 anrApp = app;
1718 }
1719 return service.inputDispatchingTimedOut(anrApp, anrActivity, this, false, reason);
1720 }
1721
1722 private ActivityRecord getWaitingHistoryRecordLocked() {
riddle_hsudb46d6b2015-04-01 18:58:07 +08001723 // First find the real culprit... if this activity is waiting for
1724 // another activity to start or has stopped, then the key dispatching
1725 // timeout should not be caused by this.
Wale Ogunwale16a62792015-04-01 11:50:31 -07001726 if (mStackSupervisor.mWaitingVisibleActivities.contains(this) || stopped) {
Craig Mautner8f2adcb2014-04-07 22:21:33 +00001727 final ActivityStack stack = mStackSupervisor.getFocusedStack();
riddle_hsudb46d6b2015-04-01 18:58:07 +08001728 // Try to use the one which is closest to top.
1729 ActivityRecord r = stack.mResumedActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001730 if (r == null) {
Dianne Hackborn621e2fe2012-02-16 17:07:33 -08001731 r = stack.mPausingActivity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001732 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001733 if (r != null) {
1734 return r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001735 }
1736 }
riddle_hsudb46d6b2015-04-01 18:58:07 +08001737 return this;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001738 }
1739
Chong Zhang87761972016-08-22 13:53:24 -07001740 /** Checks whether the activity should be shown for current user. */
1741 public boolean okToShowLocked() {
1742 return (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0
1743 || (mStackSupervisor.isCurrentProfileLocked(userId)
1744 && !service.mUserController.isUserStoppingOrShuttingDownLocked(userId));
1745 }
1746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001747 /**
1748 * This method will return true if the activity is either visible, is becoming visible, is
1749 * currently pausing, or is resumed.
1750 */
1751 public boolean isInterestingToUserLocked() {
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001752 return visible || nowVisible || state == ActivityState.PAUSING ||
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001753 state == ActivityState.RESUMED;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001754 }
1755
Wale Ogunwale3e997362016-09-06 10:37:56 -07001756 void setSleeping(boolean _sleeping) {
1757 setSleeping(_sleeping, false);
1758 }
1759
1760 void setSleeping(boolean _sleeping, boolean force) {
1761 if (!force && sleeping == _sleeping) {
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001762 return;
1763 }
1764 if (app != null && app.thread != null) {
1765 try {
Dianne Hackbornbe707852011-11-11 14:32:10 -08001766 app.thread.scheduleSleeping(appToken, _sleeping);
Craig Mautner0eea92c2013-05-16 13:35:39 -07001767 if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
1768 mStackSupervisor.mGoingToSleepActivities.add(this);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001769 }
1770 sleeping = _sleeping;
1771 } catch (RemoteException e) {
Craig Mautner0eea92c2013-05-16 13:35:39 -07001772 Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001773 }
1774 }
1775 }
Craig Mautnerf81b90872013-02-26 13:02:43 -08001776
Craig Mautnerd2328952013-03-05 12:46:26 -08001777 static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001778 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Craig Mautnerd2328952013-03-05 12:46:26 -08001779 if (r == null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001780 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08001781 }
1782 final TaskRecord task = r.task;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001783 final int activityNdx = task.mActivities.indexOf(r);
1784 if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001785 return INVALID_TASK_ID;
Craig Mautnerd2328952013-03-05 12:46:26 -08001786 }
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001787 return task.taskId;
Craig Mautnerd2328952013-03-05 12:46:26 -08001788 }
1789
1790 static ActivityRecord isInStackLocked(IBinder token) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001791 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
Andrii Kulian02b7a832016-10-06 23:11:56 -07001792 return (r != null) ? r.getStack().isInStackLocked(r) : null;
Craig Mautnerd2328952013-03-05 12:46:26 -08001793 }
1794
Craig Mautnerb59dcfd2013-05-06 13:12:58 -07001795 static ActivityStack getStackLocked(IBinder token) {
Craig Mautnerd2328952013-03-05 12:46:26 -08001796 final ActivityRecord r = ActivityRecord.isInStackLocked(token);
1797 if (r != null) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001798 return r.getStack();
Craig Mautnerd2328952013-03-05 12:46:26 -08001799 }
1800 return null;
1801 }
1802
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001803 /**
1804 * @return display id to which this record is attached, -1 if not attached.
1805 */
1806 int getDisplayId() {
1807 final ActivityStack stack = getStack();
1808 if (stack == null) {
1809 return -1;
1810 }
1811 return stack.mDisplayId;
1812 }
1813
Dianne Hackborn89ad4562014-08-24 16:45:38 -07001814 final boolean isDestroyable() {
1815 if (finishing || app == null || state == ActivityState.DESTROYING
1816 || state == ActivityState.DESTROYED) {
1817 // This would be redundant.
1818 return false;
1819 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001820 final ActivityStack stack = getStack();
1821 if (stack == null || this == stack.mResumedActivity || this == stack.mPausingActivity
1822 || !haveState || !stopped) {
Dianne Hackborn89ad4562014-08-24 16:45:38 -07001823 // We're not ready for this kind of thing.
1824 return false;
1825 }
1826 if (visible) {
1827 // The user would notice this!
1828 return false;
1829 }
1830 return true;
1831 }
1832
Winson Chung3bad5cc02014-08-19 17:44:32 -07001833 private static String createImageFilename(long createTime, int taskId) {
1834 return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime +
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001835 TaskPersister.IMAGE_EXTENSION;
1836 }
1837
Craig Mautner648f69b2014-09-18 14:16:26 -07001838 void setTaskDescription(TaskDescription _taskDescription) {
1839 Bitmap icon;
1840 if (_taskDescription.getIconFilename() == null &&
1841 (icon = _taskDescription.getIcon()) != null) {
1842 final String iconFilename = createImageFilename(createTime, task.taskId);
Winson Chungc8408b82017-01-25 17:58:56 -08001843 final File iconFile = new File(TaskPersister.getUserImagesDir(task.userId),
1844 iconFilename);
Suprabh Shukla23593142015-11-03 17:31:15 -08001845 final String iconFilePath = iconFile.getAbsolutePath();
Suprabh Shukla09a88f52015-12-02 14:36:31 -08001846 service.mRecentTasks.saveImage(icon, iconFilePath);
Suprabh Shukla23593142015-11-03 17:31:15 -08001847 _taskDescription.setIconFilename(iconFilePath);
Craig Mautner648f69b2014-09-18 14:16:26 -07001848 }
1849 taskDescription = _taskDescription;
1850 }
1851
Amith Yamasani0af6fa72016-01-17 15:36:19 -08001852 void setVoiceSessionLocked(IVoiceInteractionSession session) {
1853 voiceSession = session;
1854 pendingVoiceInteractionStart = false;
1855 }
1856
1857 void clearVoiceSessionLocked() {
1858 voiceSession = null;
1859 pendingVoiceInteractionStart = false;
1860 }
1861
Jorim Jaggi02886a82016-12-06 09:10:06 -08001862 void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch) {
Jorim Jaggi70176432017-01-18 12:52:13 +01001863 if (mWindowContainerController == null) {
1864 return;
1865 }
Wale Ogunwale3b232392016-05-13 15:37:13 -07001866 final CompatibilityInfo compatInfo =
1867 service.compatibilityInfoForPackageLocked(info.applicationInfo);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001868 final boolean shown = mWindowContainerController.addStartingWindow(packageName, theme,
1869 compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags,
Jorim Jaggi02886a82016-12-06 09:10:06 -08001870 prev != null ? prev.appToken : null, newTask, taskSwitch, isProcessRunning());
Wale Ogunwale3b232392016-05-13 15:37:13 -07001871 if (shown) {
1872 mStartingWindowState = STARTING_WINDOW_SHOWN;
1873 }
1874 }
1875
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001876 void removeOrphanedStartingWindow(boolean behindFullscreenActivity) {
1877 if (state == ActivityState.INITIALIZING
1878 && mStartingWindowState == STARTING_WINDOW_SHOWN
1879 && behindFullscreenActivity) {
1880 if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, "Found orphaned starting window " + this);
1881 mStartingWindowState = STARTING_WINDOW_REMOVED;
1882 mWindowContainerController.removeStartingWindow();
1883 }
1884 }
1885
1886 int getRequestedOrientation() {
1887 return mWindowContainerController.getOrientation();
1888 }
1889
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001890 void setRequestedOrientation(int requestedOrientation) {
1891 if (task != null && (!task.mFullscreen || !task.getStack().mFullscreen)) {
1892 // Fixed screen orientation isn't supported when activities aren't in full screen mode.
1893 return;
1894 }
1895
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001896 final int displayId = getDisplayId();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001897 final Configuration displayConfig =
1898 mStackSupervisor.getDisplayOverrideConfiguration(displayId);
1899
1900 final Configuration config = mWindowContainerController.setOrientation(requestedOrientation,
1901 displayId, displayConfig, mayFreezeScreenLocked(app));
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001902 if (config != null) {
1903 frozenBeforeDestroy = true;
1904 if (!service.updateDisplayOverrideConfigurationLocked(config, this,
1905 false /* deferResume */, displayId)) {
1906 mStackSupervisor.resumeFocusedStackTopActivityLocked();
1907 }
1908 }
Yorke Leebd54c2a2016-10-25 13:49:23 -07001909 service.mTaskChangeNotificationController.notifyActivityRequestedOrientationChanged(
1910 task.taskId, requestedOrientation);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001911 }
1912
Andrii Kulian21713ac2016-10-12 22:05:05 -07001913 // TODO: now used only in one place to address race-condition. Remove when that will be fixed.
1914 void setLastReportedConfiguration(@NonNull Configuration config) {
1915 mLastReportedConfiguration.setTo(config);
1916 }
1917
1918 /** Call when override config was sent to the Window Manager to update internal records. */
1919 void onOverrideConfigurationSent() {
1920 mLastReportedOverrideConfiguration.setTo(task.getMergedOverrideConfiguration());
1921 }
1922
1923 /**
1924 * Make sure the given activity matches the current configuration. Returns false if the activity
1925 * had to be destroyed. Returns true if the configuration is the same, or the activity will
1926 * remain running as-is for whatever reason. Ensures the HistoryRecord is updated with the
1927 * correct configuration and all other bookkeeping is handled.
1928 */
1929 boolean ensureActivityConfigurationLocked(int globalChanges, boolean preserveWindow) {
1930 final ActivityStack stack = getStack();
1931 if (stack.mConfigWillChange) {
1932 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1933 "Skipping config check (will change): " + this);
1934 return true;
1935 }
1936
1937 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1938 "Ensuring correct configuration: " + this);
1939
1940 // Short circuit: if the two configurations are equal (the common case), then there is
1941 // nothing to do.
1942 final Configuration newGlobalConfig = service.getGlobalConfiguration();
1943 final Configuration newTaskMergedOverrideConfig = task.getMergedOverrideConfiguration();
1944 if (mLastReportedConfiguration.equals(newGlobalConfig)
1945 && mLastReportedOverrideConfiguration.equals(newTaskMergedOverrideConfig)
1946 && !forceNewConfig) {
1947 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1948 "Configuration unchanged in " + this);
1949 return true;
1950 }
1951
1952 // We don't worry about activities that are finishing.
1953 if (finishing) {
1954 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1955 "Configuration doesn't matter in finishing " + this);
1956 stopFreezingScreenLocked(false);
1957 return true;
1958 }
1959
1960 // Okay we now are going to make this activity have the new config.
1961 // But then we need to figure out how it needs to deal with that.
1962 mTmpGlobalConfig.setTo(mLastReportedConfiguration);
1963 mTmpTaskConfig.setTo(mLastReportedOverrideConfiguration);
1964 mLastReportedConfiguration.setTo(newGlobalConfig);
1965 mLastReportedOverrideConfiguration.setTo(newTaskMergedOverrideConfig);
1966
1967 int taskChanges = getTaskConfigurationChanges(this, newTaskMergedOverrideConfig,
1968 mTmpTaskConfig);
1969 final int changes = mTmpGlobalConfig.diff(newGlobalConfig) | taskChanges;
1970 if (changes == 0 && !forceNewConfig) {
1971 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1972 "Configuration no differences in " + this);
1973 // There are no significant differences, so we won't relaunch but should still deliver
1974 // the new configuration to the client process.
1975 scheduleConfigurationChanged(newTaskMergedOverrideConfig, true);
1976 return true;
1977 }
1978
1979 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1980 "Configuration changes for " + this + " ; taskChanges="
1981 + Configuration.configurationDiffToString(taskChanges) + ", allChanges="
1982 + Configuration.configurationDiffToString(changes));
1983
1984 // If the activity isn't currently running, just leave the new configuration and it will
1985 // pick that up next time it starts.
1986 if (app == null || app.thread == null) {
1987 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1988 "Configuration doesn't matter not running " + this);
1989 stopFreezingScreenLocked(false);
1990 forceNewConfig = false;
1991 return true;
1992 }
1993
1994 // Figure out how to handle the changes between the configurations.
1995 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
1996 "Checking to restart " + info.name + ": changed=0x"
1997 + Integer.toHexString(changes) + ", handles=0x"
1998 + Integer.toHexString(info.getRealConfigChanged())
1999 + ", newGlobalConfig=" + newGlobalConfig
2000 + ", newTaskMergedOverrideConfig=" + newTaskMergedOverrideConfig);
2001
2002 if ((changes&(~info.getRealConfigChanged())) != 0 || forceNewConfig) {
2003 // Aha, the activity isn't handling the change, so DIE DIE DIE.
2004 configChangeFlags |= changes;
2005 startFreezingScreenLocked(app, globalChanges);
2006 forceNewConfig = false;
2007 preserveWindow &= isResizeOnlyChange(changes);
2008 if (app == null || app.thread == null) {
2009 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2010 "Config is destroying non-running " + this);
2011 stack.destroyActivityLocked(this, true, "config");
2012 } else if (state == ActivityState.PAUSING) {
2013 // A little annoying: we are waiting for this activity to finish pausing. Let's not
2014 // do anything now, but just flag that it needs to be restarted when done pausing.
2015 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2016 "Config is skipping already pausing " + this);
2017 deferRelaunchUntilPaused = true;
2018 preserveWindowOnDeferredRelaunch = preserveWindow;
2019 return true;
2020 } else if (state == ActivityState.RESUMED) {
2021 // Try to optimize this case: the configuration is changing and we need to restart
2022 // the top, resumed activity. Instead of doing the normal handshaking, just say
2023 // "restart!".
2024 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2025 "Config is relaunching resumed " + this);
2026
2027 if (DEBUG_STATES && !visible) {
2028 Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + this
2029 + " called by " + Debug.getCallers(4));
2030 }
2031
2032 relaunchActivityLocked(true /* andResume */, preserveWindow);
2033 } else {
2034 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
2035 "Config is relaunching non-resumed " + this);
2036 relaunchActivityLocked(false /* andResume */, preserveWindow);
2037 }
2038
2039 // All done... tell the caller we weren't able to keep this activity around.
2040 return false;
2041 }
2042
2043 // Default case: the activity can handle this new configuration, so hand it over.
2044 // NOTE: We only forward the task override configuration as the system level configuration
2045 // changes is always sent to all processes when they happen so it can just use whatever
2046 // system level configuration it last got.
2047 scheduleConfigurationChanged(newTaskMergedOverrideConfig, true);
2048 stopFreezingScreenLocked(false);
2049
2050 return true;
2051 }
2052
2053 private static int getTaskConfigurationChanges(ActivityRecord record, Configuration taskConfig,
2054 Configuration oldTaskOverride) {
2055 // If we went from full-screen to non-full-screen, make sure to use the correct
2056 // configuration task diff, so the diff stays as small as possible.
2057 if (Configuration.EMPTY.equals(oldTaskOverride)
2058 && !Configuration.EMPTY.equals(taskConfig)) {
2059 oldTaskOverride = record.task.extractOverrideConfig(record.mLastReportedConfiguration);
2060 }
2061
2062 // Conversely, do the same when going the other direction.
2063 if (Configuration.EMPTY.equals(taskConfig)
2064 && !Configuration.EMPTY.equals(oldTaskOverride)) {
2065 taskConfig = record.task.extractOverrideConfig(record.mLastReportedConfiguration);
2066 }
2067
2068 // Determine what has changed. May be nothing, if this is a config that has come back from
2069 // the app after going idle. In that case we just want to leave the official config object
2070 // now in the activity and do nothing else.
2071 int taskChanges = oldTaskOverride.diff(taskConfig, true /* skipUndefined */);
2072 // We don't want to use size changes if they don't cross boundaries that are important to
2073 // the app.
2074 if ((taskChanges & CONFIG_SCREEN_SIZE) != 0) {
2075 final boolean crosses = record.crossesHorizontalSizeThreshold(
2076 oldTaskOverride.screenWidthDp, taskConfig.screenWidthDp)
2077 || record.crossesVerticalSizeThreshold(
2078 oldTaskOverride.screenHeightDp, taskConfig.screenHeightDp);
2079 if (!crosses) {
2080 taskChanges &= ~CONFIG_SCREEN_SIZE;
2081 }
2082 }
2083 if ((taskChanges & CONFIG_SMALLEST_SCREEN_SIZE) != 0) {
2084 final int oldSmallest = oldTaskOverride.smallestScreenWidthDp;
2085 final int newSmallest = taskConfig.smallestScreenWidthDp;
2086 if (!record.crossesSmallestSizeThreshold(oldSmallest, newSmallest)) {
2087 taskChanges &= ~CONFIG_SMALLEST_SCREEN_SIZE;
2088 }
2089 }
2090 return taskChanges;
2091 }
2092
2093 private static boolean isResizeOnlyChange(int change) {
2094 return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION
2095 | CONFIG_SCREEN_LAYOUT)) == 0;
2096 }
2097
2098 void relaunchActivityLocked(boolean andResume, boolean preserveWindow) {
2099 if (service.mSuppressResizeConfigChanges && preserveWindow) {
2100 configChangeFlags = 0;
2101 return;
2102 }
2103
2104 List<ResultInfo> pendingResults = null;
2105 List<ReferrerIntent> pendingNewIntents = null;
2106 if (andResume) {
2107 pendingResults = results;
2108 pendingNewIntents = newIntents;
2109 }
2110 if (DEBUG_SWITCH) Slog.v(TAG_SWITCH,
2111 "Relaunching: " + this + " with results=" + pendingResults
2112 + " newIntents=" + pendingNewIntents + " andResume=" + andResume
2113 + " preserveWindow=" + preserveWindow);
2114 EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY
2115 : EventLogTags.AM_RELAUNCH_ACTIVITY, userId, System.identityHashCode(this),
2116 task.taskId, shortComponentName);
2117
2118 startFreezingScreenLocked(app, 0);
2119
2120 mStackSupervisor.removeChildActivityContainers(this);
2121
2122 try {
2123 if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH,
2124 "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + this
2125 + " callers=" + Debug.getCallers(6));
2126 forceNewConfig = false;
2127 mStackSupervisor.activityRelaunchingLocked(this);
2128 app.thread.scheduleRelaunchActivity(appToken, pendingResults, pendingNewIntents,
2129 configChangeFlags, !andResume,
2130 new Configuration(service.getGlobalConfiguration()),
2131 new Configuration(task.getMergedOverrideConfiguration()), preserveWindow);
2132 // Note: don't need to call pauseIfSleepingLocked() here, because the caller will only
2133 // pass in 'andResume' if this activity is currently resumed, which implies we aren't
2134 // sleeping.
2135 } catch (RemoteException e) {
2136 if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e);
2137 }
2138
2139 if (andResume) {
2140 if (DEBUG_STATES) {
2141 Slog.d(TAG_STATES, "Resumed after relaunch " + this);
2142 }
2143 results = null;
2144 newIntents = null;
2145 service.showUnsupportedZoomDialogIfNeededLocked(this);
2146 service.showAskCompatModeDialogLocked(this);
2147 } else {
2148 service.mHandler.removeMessages(ActivityStack.PAUSE_TIMEOUT_MSG, this);
2149 state = ActivityState.PAUSED;
2150 // if the app is relaunched when it's stopped, and we're not resuming,
2151 // put it back into stopped state.
2152 if (stopped) {
Winson Chung4dabf232017-01-25 13:25:22 -08002153 getStack().addToStopping(this, true /* scheduleIdle */, false /* idleDelayed */);
Andrii Kulian21713ac2016-10-12 22:05:05 -07002154 }
2155 }
2156
2157 configChangeFlags = 0;
2158 deferRelaunchUntilPaused = false;
2159 preserveWindowOnDeferredRelaunch = false;
2160 }
2161
Jorim Jaggi02886a82016-12-06 09:10:06 -08002162 boolean isProcessRunning() {
2163 ProcessRecord proc = app;
2164 if (proc == null) {
2165 proc = service.mProcessNames.get(processName, info.applicationInfo.uid);
2166 }
2167 return proc != null && proc.thread != null;
2168 }
2169
Craig Mautner21d24a22014-04-23 11:45:37 -07002170 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
2171 out.attribute(null, ATTR_ID, String.valueOf(createTime));
2172 out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
2173 if (launchedFromPackage != null) {
2174 out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage);
2175 }
2176 if (resolvedType != null) {
2177 out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType);
2178 }
2179 out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified));
2180 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Winson Chung2cb86c72014-06-25 12:03:30 -07002181
Craig Mautner21d24a22014-04-23 11:45:37 -07002182 if (taskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07002183 taskDescription.saveToXml(out);
Craig Mautner21d24a22014-04-23 11:45:37 -07002184 }
2185
2186 out.startTag(null, TAG_INTENT);
2187 intent.saveToXml(out);
2188 out.endTag(null, TAG_INTENT);
2189
2190 if (isPersistable() && persistentState != null) {
2191 out.startTag(null, TAG_PERSISTABLEBUNDLE);
2192 persistentState.saveToXml(out);
2193 out.endTag(null, TAG_PERSISTABLEBUNDLE);
2194 }
2195 }
2196
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07002197 static ActivityRecord restoreFromXml(XmlPullParser in,
2198 ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07002199 Intent intent = null;
2200 PersistableBundle persistentState = null;
2201 int launchedFromUid = 0;
2202 String launchedFromPackage = null;
2203 String resolvedType = null;
2204 boolean componentSpecified = false;
2205 int userId = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07002206 long createTime = -1;
2207 final int outerDepth = in.getDepth();
Winson Chung2cb86c72014-06-25 12:03:30 -07002208 TaskDescription taskDescription = new TaskDescription();
Craig Mautner21d24a22014-04-23 11:45:37 -07002209
2210 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
2211 final String attrName = in.getAttributeName(attrNdx);
2212 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07002213 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
Wale Ogunwale18795a22014-12-03 11:38:33 -08002214 "ActivityRecord: attribute name=" + attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002215 if (ATTR_ID.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01002216 createTime = Long.parseLong(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002217 } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01002218 launchedFromUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002219 } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
2220 launchedFromPackage = attrValue;
2221 } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
2222 resolvedType = attrValue;
2223 } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
Tobias Thiererb0800dc2016-04-21 17:51:41 +01002224 componentSpecified = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002225 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01002226 userId = Integer.parseInt(attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07002227 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
2228 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07002229 } else {
2230 Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName);
2231 }
2232 }
2233
2234 int event;
2235 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07002236 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07002237 if (event == XmlPullParser.START_TAG) {
2238 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07002239 if (TaskPersister.DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08002240 Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name);
Craig Mautner21d24a22014-04-23 11:45:37 -07002241 if (TAG_INTENT.equals(name)) {
2242 intent = Intent.restoreFromXml(in);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07002243 if (TaskPersister.DEBUG)
Wale Ogunwale18795a22014-12-03 11:38:33 -08002244 Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07002245 } else if (TAG_PERSISTABLEBUNDLE.equals(name)) {
2246 persistentState = PersistableBundle.restoreFromXml(in);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07002247 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
Craig Mautner21d24a22014-04-23 11:45:37 -07002248 "ActivityRecord: persistentState=" + persistentState);
2249 } else {
2250 Slog.w(TAG, "restoreActivity: unexpected name=" + name);
2251 XmlUtils.skipCurrentTag(in);
2252 }
2253 }
2254 }
2255
2256 if (intent == null) {
Craig Mautnere0129b32014-05-25 16:41:09 -07002257 throw new XmlPullParserException("restoreActivity error intent=" + intent);
Craig Mautner21d24a22014-04-23 11:45:37 -07002258 }
2259
2260 final ActivityManagerService service = stackSupervisor.mService;
2261 final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null,
Jeff Hao1b012d32014-08-20 10:35:34 -07002262 userId);
Craig Mautnere0129b32014-05-25 16:41:09 -07002263 if (aInfo == null) {
Craig Mautner77b04262014-06-27 15:22:12 -07002264 throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent +
2265 " resolvedType=" + resolvedType);
Craig Mautnere0129b32014-05-25 16:41:09 -07002266 }
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002267 final ActivityRecord r = new ActivityRecord(service, null /* caller */,
2268 0 /* launchedFromPid */, launchedFromUid, launchedFromPackage, intent, resolvedType,
2269 aInfo, service.getConfiguration(), null /* resultTo */, null /* resultWho */,
2270 0 /* reqCode */, componentSpecified, false /* rootVoiceInteraction */,
2271 stackSupervisor, null /* container */, null /* options */, null /* sourceRecord */);
Craig Mautner21d24a22014-04-23 11:45:37 -07002272
2273 r.persistentState = persistentState;
Winson Chung2cb86c72014-06-25 12:03:30 -07002274 r.taskDescription = taskDescription;
Craig Mautner21d24a22014-04-23 11:45:37 -07002275 r.createTime = createTime;
2276
2277 return r;
2278 }
2279
2280 private static String activityTypeToString(int type) {
Craig Mautnerae7ecab2013-09-18 11:48:14 -07002281 switch (type) {
2282 case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE";
2283 case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE";
2284 case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE";
2285 default: return Integer.toString(type);
2286 }
2287 }
2288
Craig Mautnerf81b90872013-02-26 13:02:43 -08002289 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002290 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002291 if (stringName != null) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08002292 return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) +
Craig Mautnerf3333272013-04-22 10:55:53 -07002293 (finishing ? " f}" : "}");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002294 }
2295 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn30d71892010-12-11 10:37:55 -08002296 sb.append("ActivityRecord{");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002297 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -07002298 sb.append(" u");
2299 sb.append(userId);
Dianne Hackbornf210d6b2009-04-13 18:42:49 -07002300 sb.append(' ');
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002301 sb.append(intent.getComponent().flattenToShortString());
Craig Mautnerf81b90872013-02-26 13:02:43 -08002302 stringName = sb.toString();
2303 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 }
2305}