The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.am; |
| 18 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 19 | import static android.app.ActivityManager.ENABLE_TASK_SNAPSHOTS; |
Winson Chung | bb34880 | 2017-01-30 12:01:45 -0800 | [diff] [blame] | 20 | import static android.app.ActivityManager.LOCK_TASK_MODE_NONE; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 21 | import static android.app.ActivityManager.StackId; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame^] | 22 | import static android.app.ActivityManager.StackId.ASSISTANT_STACK_ID; |
Wale Ogunwale | eb915f2 | 2016-10-14 07:18:22 -0700 | [diff] [blame] | 23 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 24 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame^] | 25 | import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 26 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 27 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 28 | import static android.app.AppOpsManager.MODE_ALLOWED; |
| 29 | import static android.app.AppOpsManager.OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 30 | import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 31 | import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION; |
| 32 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT; |
| 33 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE; |
| 34 | import static android.content.pm.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 35 | import static android.content.pm.ActivityInfo.CONFIG_UI_MODE; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 36 | import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 37 | import static android.content.pm.ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 38 | import static android.content.pm.ActivityInfo.FLAG_IMMERSIVE; |
| 39 | import static android.content.pm.ActivityInfo.FLAG_MULTIPROCESS; |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 40 | import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 41 | import static android.content.pm.ActivityInfo.FLAG_STATE_NOT_NEEDED; |
| 42 | import static android.content.pm.ActivityInfo.LAUNCH_MULTIPLE; |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 43 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE; |
| 44 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 45 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP; |
Wale Ogunwale | df241e9 | 2016-10-13 15:14:21 -0700 | [diff] [blame] | 46 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE; |
Jorim Jaggi | cd13d33 | 2016-04-27 15:40:20 -0700 | [diff] [blame] | 47 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE; |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 48 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
Wale Ogunwale | df241e9 | 2016-10-13 15:14:21 -0700 | [diff] [blame] | 49 | import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 50 | import static android.content.res.Configuration.UI_MODE_TYPE_MASK; |
| 51 | import static android.content.res.Configuration.UI_MODE_TYPE_VR_HEADSET; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 52 | import static android.os.Build.VERSION_CODES.HONEYCOMB; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 53 | import static android.os.Build.VERSION_CODES.O; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 54 | import static android.os.Process.SYSTEM_UID; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 55 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 56 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE; |
| 57 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SCREENSHOTS; |
| 58 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 59 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH; |
| 60 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_THUMBNAILS; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 61 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBILITY; |
| 62 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONFIGURATION; |
| 63 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SAVED_STATE; |
| 64 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SCREENSHOTS; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 65 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES; |
| 66 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH; |
| 67 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_THUMBNAILS; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 68 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBILITY; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 69 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 70 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 71 | import static com.android.server.am.ActivityManagerService.TAKE_FULLSCREEN_SCREENSHOTS; |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 72 | import static com.android.server.am.TaskRecord.INVALID_TASK_ID; |
| 73 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 74 | import android.annotation.NonNull; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 75 | import android.app.ActivityManager.TaskDescription; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 76 | import android.app.ActivityOptions; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 77 | import android.app.PendingIntent; |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 78 | import android.app.PictureInPictureArgs; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 79 | import android.app.ResultInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | import android.content.ComponentName; |
| 81 | import android.content.Intent; |
| 82 | import android.content.pm.ActivityInfo; |
| 83 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 84 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | import android.content.res.Configuration; |
| 86 | import android.graphics.Bitmap; |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 87 | import android.graphics.Rect; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 88 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | import android.os.Bundle; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 90 | import android.os.Debug; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 91 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | import android.os.Message; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 93 | import android.os.PersistableBundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import android.os.Process; |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 95 | import android.os.RemoteException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.os.SystemClock; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 97 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 98 | import android.os.UserHandle; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 99 | import android.service.voice.IVoiceInteractionSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | import android.util.EventLog; |
| 101 | import android.util.Log; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 102 | import android.util.Slog; |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 103 | import android.util.TimeUtils; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 104 | import android.view.AppTransitionAnimationSpec; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | import android.view.IApplicationToken; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 106 | import android.view.WindowManager.LayoutParams; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 107 | |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 108 | import com.android.internal.app.ResolverActivity; |
| 109 | import com.android.internal.content.ReferrerIntent; |
| 110 | import com.android.internal.util.XmlUtils; |
| 111 | import com.android.server.AttributeCache; |
| 112 | import com.android.server.am.ActivityStack.ActivityState; |
| 113 | import com.android.server.am.ActivityStackSupervisor.ActivityContainer; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 114 | import com.android.server.wm.AppWindowContainerController; |
| 115 | import com.android.server.wm.AppWindowContainerListener; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 116 | import com.android.server.wm.TaskWindowContainerController; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 118 | import org.xmlpull.v1.XmlPullParser; |
| 119 | import org.xmlpull.v1.XmlPullParserException; |
| 120 | import org.xmlpull.v1.XmlSerializer; |
| 121 | |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 122 | import java.io.File; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 123 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | import java.io.PrintWriter; |
| 125 | import java.lang.ref.WeakReference; |
| 126 | import java.util.ArrayList; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 127 | import java.util.Arrays; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | import java.util.HashSet; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 129 | import java.util.List; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 130 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | |
| 132 | /** |
| 133 | * An entry in the history stack, representing an activity. |
| 134 | */ |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 135 | final class ActivityRecord implements AppWindowContainerListener { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 136 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityRecord" : TAG_AM; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 137 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
| 138 | private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE; |
| 139 | private static final String TAG_SCREENSHOTS = TAG + POSTFIX_SCREENSHOTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 140 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 141 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 142 | private static final String TAG_THUMBNAILS = TAG + POSTFIX_THUMBNAILS; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 143 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 144 | |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 145 | private static final boolean SHOW_ACTIVITY_START_TIME = true; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 146 | private static final String RECENTS_PACKAGE_NAME = "com.android.systemui.recents"; |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 147 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 148 | private static final String ATTR_ID = "id"; |
| 149 | private static final String TAG_INTENT = "intent"; |
| 150 | private static final String ATTR_USERID = "user_id"; |
| 151 | private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle"; |
| 152 | private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid"; |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 153 | private static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 154 | private static final String ATTR_RESOLVEDTYPE = "resolved_type"; |
| 155 | private static final String ATTR_COMPONENTSPECIFIED = "component_specified"; |
Dianne Hackborn | 337abb3 | 2014-09-24 12:44:29 -0700 | [diff] [blame] | 156 | static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | final ActivityManagerService service; // owner |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 159 | final IApplicationToken.Stub appToken; // window manager token |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 160 | AppWindowContainerController mWindowContainerController; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | final ActivityInfo info; // all about me |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 162 | final ApplicationInfo appInfo; // information about activity's app |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 163 | final int launchedFromPid; // always the pid who started the activity. |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 164 | final int launchedFromUid; // always the uid who started the activity. |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 165 | final String launchedFromPackage; // always the package who started the activity. |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 166 | final int userId; // Which user is this running for? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | final Intent intent; // the original intent that generated us |
| 168 | final ComponentName realActivity; // the intent component, or target of an alias. |
| 169 | final String shortComponentName; // the short component name of the intent |
| 170 | final String resolvedType; // as per original caller; |
| 171 | final String packageName; // the package implementing intent's component |
| 172 | final String processName; // process where this component wants to run |
| 173 | final String taskAffinity; // as per ActivityInfo.taskAffinity |
| 174 | final boolean stateNotNeeded; // As per ActivityInfo.flags |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 175 | boolean fullscreen; // covers the full screen? |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 176 | final boolean noDisplay; // activity is not displayed? |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 177 | private final boolean componentSpecified; // did caller specify an explicit component? |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 178 | final boolean rootVoiceInteraction; // was this the root activity of a voice interaction? |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 179 | |
| 180 | static final int APPLICATION_ACTIVITY_TYPE = 0; |
| 181 | static final int HOME_ACTIVITY_TYPE = 1; |
| 182 | static final int RECENTS_ACTIVITY_TYPE = 2; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame^] | 183 | static final int ASSISTANT_ACTIVITY_TYPE = 3; |
Craig Mautner | 2c1faed | 2013-07-23 12:56:02 -0700 | [diff] [blame] | 184 | int mActivityType; |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 185 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 186 | private CharSequence nonLocalizedLabel; // the label information from the package mgr. |
| 187 | private int labelRes; // the label information from the package mgr. |
| 188 | private int icon; // resource identifier of activity's icon. |
| 189 | private int logo; // resource identifier of activity's logo. |
| 190 | private int theme; // resource identifier of activity's theme. |
| 191 | private int realTheme; // actual theme resource we will use, never 0. |
| 192 | private int windowFlags; // custom window flags for preview window. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | TaskRecord task; // the task this is in. |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 194 | private long createTime = System.currentTimeMillis(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 195 | long displayStartTime; // when we started launching this activity |
| 196 | long fullyDrawnStartTime; // when we started launching this activity |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 197 | private long startTime; // last time this activity was started |
Dianne Hackborn | 5068560 | 2011-12-01 12:23:37 -0800 | [diff] [blame] | 198 | long lastVisibleTime; // last time this activity became visible |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 199 | long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 200 | long pauseTime; // last time we started pausing the activity |
| 201 | long launchTickTime; // base time for launch tick messages |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 202 | private Configuration mLastReportedConfiguration; // configuration activity was last running in |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 203 | // Overridden configuration by the activity task |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 204 | // WARNING: Reference points to {@link TaskRecord#getMergedOverrideConfig}, so its internal |
| 205 | // state should never be altered directly. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 206 | private Configuration mLastReportedOverrideConfiguration; |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 207 | CompatibilityInfo compat;// last used compatibility mode |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 208 | ActivityRecord resultTo; // who started this entry, so will get our reply |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | final String resultWho; // additional identifier for use by resultTo. |
| 210 | final int requestCode; // code given by requester (resultTo) |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 211 | ArrayList<ResultInfo> results; // pending ActivityResult objs we have received |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 213 | ArrayList<ReferrerIntent> newIntents; // any pending new intents for single-top mode |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 214 | ActivityOptions pendingOptions; // most recently given options |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 215 | ActivityOptions returningOptions; // options that are coming back via convertToTranslucent |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 216 | AppTimeTracker appTimeTracker; // set if we are tracking the time in this app/task/activity |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 218 | UriPermissionOwner uriPermissions; // current special URI access perms. |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 219 | ProcessRecord app; // if non-null, hosting application |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 220 | ActivityState state; // current state we are in |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | Bundle icicle; // last saved activity state |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 222 | PersistableBundle persistentState; // last persistently saved activity state |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | boolean frontOfTask; // is this the root activity of its task? |
| 224 | boolean launchFailed; // set if a launched failed, to abort on 2nd try |
| 225 | boolean haveState; // have we gotten the last activity state? |
| 226 | boolean stopped; // is activity pause finished? |
Dianne Hackborn | 95fc68f | 2009-05-19 18:37:45 -0700 | [diff] [blame] | 227 | boolean delayedResume; // not yet resumed because of stopped app switches? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | boolean finishing; // activity in pending finish list? |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 229 | boolean deferRelaunchUntilPaused; // relaunch of activity is being deferred until pause is |
| 230 | // completed |
| 231 | boolean preserveWindowOnDeferredRelaunch; // activity windows are preserved on deferred relaunch |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | int configChangeFlags; // which config values have changed |
| 233 | boolean keysPaused; // has key dispatching been paused for it? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | int launchMode; // the launch mode activity attribute. |
| 235 | boolean visible; // does this activity's window need to be shown? |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 236 | boolean visibleIgnoringKeyguard; // is this activity visible, ignoring the fact that Keyguard |
| 237 | // might hide this activity? |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 238 | boolean sleeping; // have we told the activity to sleep? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | boolean nowVisible; // is this activity's window visible? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | boolean idle; // has the activity gone idle? |
| 241 | boolean hasBeenLaunched;// has this activity ever been launched? |
| 242 | boolean frozenBeforeDestroy;// has been frozen but not yet destroyed. |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 243 | boolean immersive; // immersive mode (don't interrupt if possible) |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 244 | boolean forceNewConfig; // force re-create with new config next time |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 245 | boolean supportsPictureInPictureWhilePausing; // This flag is set by the system to indicate |
| 246 | // that the activity can enter picture in picture while pausing (ie. only when another |
| 247 | // task is brought to front or started) |
| 248 | PictureInPictureArgs pictureInPictureArgs = new PictureInPictureArgs(); // The PiP |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 249 | // arguments used when deferring the entering of picture-in-picture. |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 250 | int launchCount; // count of launches since last state |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 251 | long lastLaunchTime; // time of last launch of this activity |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 252 | ComponentName requestedVrComponent; // the requested component for handling VR mode. |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 253 | ArrayList<ActivityContainer> mChildContainers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 255 | String stringName; // for caching of toString(). |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 256 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 257 | private boolean inHistory; // are we in the history stack? |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 258 | final ActivityStackSupervisor mStackSupervisor; |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 259 | |
| 260 | static final int STARTING_WINDOW_NOT_SHOWN = 0; |
| 261 | static final int STARTING_WINDOW_SHOWN = 1; |
| 262 | static final int STARTING_WINDOW_REMOVED = 2; |
| 263 | int mStartingWindowState = STARTING_WINDOW_NOT_SHOWN; |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 264 | boolean mTaskOverlay = false; // Task is always on-top of other activities in the task. |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 265 | |
Jorim Jaggi | c2f262b | 2015-12-07 16:59:10 -0800 | [diff] [blame] | 266 | boolean mUpdateTaskThumbnailWhenHidden; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 267 | ActivityContainer mInitialActivityContainer; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 268 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 269 | TaskDescription taskDescription; // the recents information for this activity |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 270 | boolean mLaunchTaskBehind; // this activity is actively being launched with |
| 271 | // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed. |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 272 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 273 | // These configurations are collected from application's resources based on size-sensitive |
| 274 | // qualifiers. For example, layout-w800dp will be added to mHorizontalSizeConfigurations as 800 |
| 275 | // and drawable-sw400dp will be added to both as 400. |
| 276 | private int[] mVerticalSizeConfigurations; |
| 277 | private int[] mHorizontalSizeConfigurations; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 278 | private int[] mSmallestSizeConfigurations; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 279 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 280 | boolean pendingVoiceInteractionStart; // Waiting for activity-invoked voice session |
| 281 | IVoiceInteractionSession voiceSession; // Voice interaction session for this activity |
| 282 | |
Robert Carr | d226512 | 2016-08-05 10:25:21 -0700 | [diff] [blame] | 283 | // A hint to override the window specified rotation animation, or -1 |
| 284 | // to use the window specified value. We use this so that |
| 285 | // we can select the right animation in the cases of starting |
| 286 | // windows, where the app hasn't had time to set a value |
| 287 | // on the window. |
| 288 | int mRotationAnimationHint = -1; |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 289 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 290 | /** |
| 291 | * Temp configs used in {@link #ensureActivityConfigurationLocked(int, boolean)} |
| 292 | */ |
| 293 | private final Configuration mTmpGlobalConfig = new Configuration(); |
| 294 | private final Configuration mTmpTaskConfig = new Configuration(); |
| 295 | |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 296 | private static String startingWindowStateToString(int state) { |
| 297 | switch (state) { |
| 298 | case STARTING_WINDOW_NOT_SHOWN: |
| 299 | return "STARTING_WINDOW_NOT_SHOWN"; |
| 300 | case STARTING_WINDOW_SHOWN: |
| 301 | return "STARTING_WINDOW_SHOWN"; |
| 302 | case STARTING_WINDOW_REMOVED: |
| 303 | return "STARTING_WINDOW_REMOVED"; |
| 304 | default: |
| 305 | return "unknown state=" + state; |
| 306 | } |
| 307 | } |
| 308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 310 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 311 | pw.print(prefix); pw.print("packageName="); pw.print(packageName); |
| 312 | pw.print(" processName="); pw.println(processName); |
| 313 | pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid); |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 314 | pw.print(" launchedFromPackage="); pw.print(launchedFromPackage); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 315 | pw.print(" userId="); pw.println(userId); |
| 316 | pw.print(prefix); pw.print("app="); pw.println(app); |
| 317 | pw.print(prefix); pw.println(intent.toInsecureStringWithClip()); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 318 | pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask); |
| 319 | pw.print(" task="); pw.println(task); |
| 320 | pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 321 | pw.print(prefix); pw.print("realActivity="); |
| 322 | pw.println(realActivity.flattenToShortString()); |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 323 | if (appInfo != null) { |
| 324 | pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir); |
| 325 | if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) { |
| 326 | pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir); |
| 327 | } |
| 328 | pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 329 | if (appInfo.splitSourceDirs != null) { |
| 330 | pw.print(prefix); pw.print("splitDir="); |
| 331 | pw.println(Arrays.toString(appInfo.splitSourceDirs)); |
| 332 | } |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 333 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 334 | pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded); |
| 335 | pw.print(" componentSpecified="); pw.print(componentSpecified); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 336 | pw.print(" mActivityType="); pw.println(mActivityType); |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 337 | if (rootVoiceInteraction) { |
| 338 | pw.print(prefix); pw.print("rootVoiceInteraction="); pw.println(rootVoiceInteraction); |
| 339 | } |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 340 | pw.print(prefix); pw.print("compat="); pw.print(compat); |
| 341 | pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes)); |
| 342 | pw.print(" icon=0x"); pw.print(Integer.toHexString(icon)); |
| 343 | pw.print(" theme=0x"); pw.println(Integer.toHexString(theme)); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 344 | pw.print(prefix); pw.print("mLastReportedConfiguration="); |
| 345 | pw.println(mLastReportedConfiguration); |
| 346 | pw.print(prefix); pw.print("mLastReportedOverrideConfiguration="); |
| 347 | pw.println(mLastReportedOverrideConfiguration); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 348 | if (resultTo != null || resultWho != null) { |
| 349 | pw.print(prefix); pw.print("resultTo="); pw.print(resultTo); |
| 350 | pw.print(" resultWho="); pw.print(resultWho); |
| 351 | pw.print(" resultCode="); pw.println(requestCode); |
| 352 | } |
Craig Mautner | 29c58ca | 2014-10-14 16:17:06 -0700 | [diff] [blame] | 353 | if (taskDescription != null) { |
| 354 | final String iconFilename = taskDescription.getIconFilename(); |
| 355 | if (iconFilename != null || taskDescription.getLabel() != null || |
| 356 | taskDescription.getPrimaryColor() != 0) { |
| 357 | pw.print(prefix); pw.print("taskDescription:"); |
| 358 | pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename()); |
| 359 | pw.print(" label=\""); pw.print(taskDescription.getLabel()); |
| 360 | pw.print("\""); |
| 361 | pw.print(" color="); |
| 362 | pw.println(Integer.toHexString(taskDescription.getPrimaryColor())); |
| 363 | } |
| 364 | if (iconFilename == null && taskDescription.getIcon() != null) { |
| 365 | pw.print(prefix); pw.println("taskDescription contains Bitmap"); |
| 366 | } |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 367 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 368 | if (results != null) { |
| 369 | pw.print(prefix); pw.print("results="); pw.println(results); |
| 370 | } |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 371 | if (pendingResults != null && pendingResults.size() > 0) { |
| 372 | pw.print(prefix); pw.println("Pending Results:"); |
| 373 | for (WeakReference<PendingIntentRecord> wpir : pendingResults) { |
| 374 | PendingIntentRecord pir = wpir != null ? wpir.get() : null; |
| 375 | pw.print(prefix); pw.print(" - "); |
| 376 | if (pir == null) { |
| 377 | pw.println("null"); |
| 378 | } else { |
| 379 | pw.println(pir); |
| 380 | pir.dump(pw, prefix + " "); |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | if (newIntents != null && newIntents.size() > 0) { |
| 385 | pw.print(prefix); pw.println("Pending New Intents:"); |
| 386 | for (int i=0; i<newIntents.size(); i++) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 387 | Intent intent = newIntents.get(i); |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 388 | pw.print(prefix); pw.print(" - "); |
| 389 | if (intent == null) { |
| 390 | pw.println("null"); |
| 391 | } else { |
| 392 | pw.println(intent.toShortString(false, true, false, true)); |
| 393 | } |
| 394 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 395 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 396 | if (pendingOptions != null) { |
| 397 | pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions); |
| 398 | } |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 399 | if (appTimeTracker != null) { |
| 400 | appTimeTracker.dumpWithHeader(pw, prefix, false); |
| 401 | } |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 402 | if (uriPermissions != null) { |
Jeff Sharkey | 846318a | 2014-04-04 12:12:41 -0700 | [diff] [blame] | 403 | uriPermissions.dump(pw, prefix); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 404 | } |
| 405 | pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed); |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 406 | pw.print(" launchCount="); pw.print(launchCount); |
| 407 | pw.print(" lastLaunchTime="); |
| 408 | if (lastLaunchTime == 0) pw.print("0"); |
| 409 | else TimeUtils.formatDuration(lastLaunchTime, now, pw); |
| 410 | pw.println(); |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 411 | pw.print(prefix); pw.print("haveState="); pw.print(haveState); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 412 | pw.print(" icicle="); pw.println(icicle); |
| 413 | pw.print(prefix); pw.print("state="); pw.print(state); |
| 414 | pw.print(" stopped="); pw.print(stopped); |
Dianne Hackborn | 95fc68f | 2009-05-19 18:37:45 -0700 | [diff] [blame] | 415 | pw.print(" delayedResume="); pw.print(delayedResume); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 416 | pw.print(" finishing="); pw.println(finishing); |
| 417 | pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused); |
| 418 | pw.print(" inHistory="); pw.print(inHistory); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 419 | pw.print(" visible="); pw.print(visible); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 420 | pw.print(" sleeping="); pw.print(sleeping); |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 421 | pw.print(" idle="); pw.print(idle); |
| 422 | pw.print(" mStartingWindowState="); |
| 423 | pw.println(startingWindowStateToString(mStartingWindowState)); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 424 | pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen); |
| 425 | pw.print(" noDisplay="); pw.print(noDisplay); |
| 426 | pw.print(" immersive="); pw.print(immersive); |
| 427 | pw.print(" launchMode="); pw.println(launchMode); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 428 | pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 429 | pw.print(" forceNewConfig="); pw.println(forceNewConfig); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 430 | pw.print(prefix); pw.print("mActivityType="); |
| 431 | pw.println(activityTypeToString(mActivityType)); |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 432 | if (requestedVrComponent != null) { |
| 433 | pw.print(prefix); |
| 434 | pw.print("requestedVrComponent="); |
| 435 | pw.println(requestedVrComponent); |
| 436 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 437 | if (displayStartTime != 0 || startTime != 0) { |
| 438 | pw.print(prefix); pw.print("displayStartTime="); |
| 439 | if (displayStartTime == 0) pw.print("0"); |
| 440 | else TimeUtils.formatDuration(displayStartTime, now, pw); |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 441 | pw.print(" startTime="); |
| 442 | if (startTime == 0) pw.print("0"); |
| 443 | else TimeUtils.formatDuration(startTime, now, pw); |
| 444 | pw.println(); |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 445 | } |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 446 | final boolean waitingVisible = mStackSupervisor.mWaitingVisibleActivities.contains(this); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 447 | if (lastVisibleTime != 0 || waitingVisible || nowVisible) { |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 448 | pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 449 | pw.print(" nowVisible="); pw.print(nowVisible); |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 450 | pw.print(" lastVisibleTime="); |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 451 | if (lastVisibleTime == 0) pw.print("0"); |
| 452 | else TimeUtils.formatDuration(lastVisibleTime, now, pw); |
| 453 | pw.println(); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 454 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 455 | if (deferRelaunchUntilPaused || configChangeFlags != 0) { |
| 456 | pw.print(prefix); pw.print("deferRelaunchUntilPaused="); pw.print(deferRelaunchUntilPaused); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 457 | pw.print(" configChangeFlags="); |
| 458 | pw.println(Integer.toHexString(configChangeFlags)); |
| 459 | } |
| 460 | if (connections != null) { |
| 461 | pw.print(prefix); pw.print("connections="); pw.println(connections); |
| 462 | } |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 463 | if (info != null) { |
| 464 | pw.println(prefix + "resizeMode=" + ActivityInfo.resizeModeToString(info.resizeMode)); |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 465 | pw.println(prefix + "supportsPictureInPicture=" + info.supportsPictureInPicture()); |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 466 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 467 | pw.println(prefix + "supportsPictureInPictureWhilePausing: " |
| 468 | + supportsPictureInPictureWhilePausing); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | } |
| 470 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 471 | private boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 472 | return crossesSizeThreshold(mHorizontalSizeConfigurations, firstDp, secondDp); |
| 473 | } |
| 474 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 475 | private boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 476 | return crossesSizeThreshold(mVerticalSizeConfigurations, firstDp, secondDp); |
| 477 | } |
| 478 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 479 | private boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 480 | return crossesSizeThreshold(mSmallestSizeConfigurations, firstDp, secondDp); |
| 481 | } |
| 482 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 483 | /** |
| 484 | * The purpose of this method is to decide whether the activity needs to be relaunched upon |
| 485 | * changing its size. In most cases the activities don't need to be relaunched, if the resize |
| 486 | * is small, all the activity content has to do is relayout itself within new bounds. There are |
| 487 | * cases however, where the activity's content would be completely changed in the new size and |
| 488 | * the full relaunch is required. |
| 489 | * |
| 490 | * The activity will report to us vertical and horizontal thresholds after which a relaunch is |
| 491 | * required. These thresholds are collected from the application resource qualifiers. For |
| 492 | * example, if application has layout-w600dp resource directory, then it needs a relaunch when |
| 493 | * we resize from width of 650dp to 550dp, as it crosses the 600dp threshold. However, if |
| 494 | * it resizes width from 620dp to 700dp, it won't be relaunched as it stays on the same side |
| 495 | * of the threshold. |
| 496 | */ |
| 497 | private static boolean crossesSizeThreshold(int[] thresholds, int firstDp, |
| 498 | int secondDp) { |
| 499 | if (thresholds == null) { |
| 500 | return false; |
| 501 | } |
| 502 | for (int i = thresholds.length - 1; i >= 0; i--) { |
| 503 | final int threshold = thresholds[i]; |
| 504 | if ((firstDp < threshold && secondDp >= threshold) |
| 505 | || (firstDp >= threshold && secondDp < threshold)) { |
| 506 | return true; |
| 507 | } |
| 508 | } |
| 509 | return false; |
| 510 | } |
| 511 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 512 | void setSizeConfigurations(int[] horizontalSizeConfiguration, |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 513 | int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 514 | mHorizontalSizeConfigurations = horizontalSizeConfiguration; |
| 515 | mVerticalSizeConfigurations = verticalSizeConfigurations; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 516 | mSmallestSizeConfigurations = smallestSizeConfigurations; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 519 | private void scheduleConfigurationChanged(Configuration config, boolean reportToActivity) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 520 | if (app == null || app.thread == null) { |
| 521 | return; |
| 522 | } |
| 523 | try { |
| 524 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + this + " " + |
Adam Lesinski | bad43fc | 2016-07-19 13:35:01 -0700 | [diff] [blame] | 525 | "reportToActivity=" + reportToActivity + " and config: " + config); |
Chong Zhang | 6be533e | 2016-06-17 16:24:21 -0700 | [diff] [blame] | 526 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 527 | app.thread.scheduleActivityConfigurationChanged(appToken, new Configuration(config), |
| 528 | reportToActivity); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 529 | } catch (RemoteException e) { |
| 530 | // If process died, whatever. |
| 531 | } |
| 532 | } |
| 533 | |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 534 | void scheduleMultiWindowModeChanged() { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 535 | if (task == null || task.getStack() == null || app == null || app.thread == null) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 536 | return; |
| 537 | } |
| 538 | try { |
| 539 | // An activity is considered to be in multi-window mode if its task isn't fullscreen. |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 540 | app.thread.scheduleMultiWindowModeChanged(appToken, !task.mFullscreen); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 541 | } catch (Exception e) { |
| 542 | // If process died, I don't care. |
| 543 | } |
| 544 | } |
| 545 | |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 546 | void schedulePictureInPictureModeChanged() { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 547 | if (task == null || task.getStack() == null || app == null || app.thread == null) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 548 | return; |
| 549 | } |
| 550 | try { |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 551 | app.thread.schedulePictureInPictureModeChanged( |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 552 | appToken, task.getStackId() == PINNED_STACK_ID); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 553 | } catch (Exception e) { |
| 554 | // If process died, no one cares. |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 558 | boolean isFreeform() { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 559 | return task != null && task.getStackId() == FREEFORM_WORKSPACE_STACK_ID; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 560 | } |
| 561 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 562 | static class Token extends IApplicationToken.Stub { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 563 | private final WeakReference<ActivityRecord> weakActivity; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 564 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 565 | Token(ActivityRecord activity) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 566 | weakActivity = new WeakReference<>(activity); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 569 | private static ActivityRecord tokenToActivityRecordLocked(Token token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 570 | if (token == null) { |
| 571 | return null; |
| 572 | } |
| 573 | ActivityRecord r = token.weakActivity.get(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 574 | if (r == null || r.getStack() == null) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 575 | return null; |
| 576 | } |
| 577 | return r; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 578 | } |
| 579 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 580 | @Override |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 581 | public String toString() { |
| 582 | StringBuilder sb = new StringBuilder(128); |
| 583 | sb.append("Token{"); |
| 584 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 585 | sb.append(' '); |
| 586 | sb.append(weakActivity.get()); |
| 587 | sb.append('}'); |
| 588 | return sb.toString(); |
| 589 | } |
| 590 | } |
| 591 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 592 | static ActivityRecord forTokenLocked(IBinder token) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 593 | try { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 594 | return Token.tokenToActivityRecordLocked((Token)token); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 595 | } catch (ClassCastException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 596 | Slog.w(TAG, "Bad activity token: " + token, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 597 | return null; |
| 598 | } |
| 599 | } |
| 600 | |
Chong Zhang | 85ee654 | 2015-10-02 13:36:38 -0700 | [diff] [blame] | 601 | boolean isResolverActivity() { |
| 602 | return ResolverActivity.class.getName().equals(realActivity.getClassName()); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 605 | ActivityRecord(ActivityManagerService _service, ProcessRecord _caller, int _launchedFromPid, |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 606 | int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 607 | ActivityInfo aInfo, Configuration _configuration, |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 608 | ActivityRecord _resultTo, String _resultWho, int _reqCode, |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 609 | boolean _componentSpecified, boolean _rootVoiceInteraction, |
| 610 | ActivityStackSupervisor supervisor, |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 611 | ActivityContainer container, ActivityOptions options, ActivityRecord sourceRecord) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | service = _service; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 613 | appToken = new Token(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | info = aInfo; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 615 | launchedFromPid = _launchedFromPid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | launchedFromUid = _launchedFromUid; |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 617 | launchedFromPackage = _launchedFromPackage; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 618 | userId = UserHandle.getUserId(aInfo.applicationInfo.uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | intent = _intent; |
| 620 | shortComponentName = _intent.getComponent().flattenToShortString(); |
| 621 | resolvedType = _resolvedType; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 622 | componentSpecified = _componentSpecified; |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 623 | rootVoiceInteraction = _rootVoiceInteraction; |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 624 | mLastReportedConfiguration = new Configuration(_configuration); |
| 625 | mLastReportedOverrideConfiguration = new Configuration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 626 | resultTo = _resultTo; |
| 627 | resultWho = _resultWho; |
| 628 | requestCode = _reqCode; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 629 | state = ActivityState.INITIALIZING; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | frontOfTask = false; |
| 631 | launchFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | stopped = false; |
Dianne Hackborn | 95fc68f | 2009-05-19 18:37:45 -0700 | [diff] [blame] | 633 | delayedResume = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | finishing = false; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 635 | deferRelaunchUntilPaused = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 636 | keysPaused = false; |
| 637 | inHistory = false; |
Chong Zhang | a48ef66 | 2015-08-18 19:21:47 -0700 | [diff] [blame] | 638 | visible = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | nowVisible = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | idle = false; |
| 641 | hasBeenLaunched = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 642 | mStackSupervisor = supervisor; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 643 | mInitialActivityContainer = container; |
Robert Carr | 0f5d753 | 2016-10-17 16:39:17 -0700 | [diff] [blame] | 644 | |
| 645 | mRotationAnimationHint = aInfo.rotationAnimation; |
| 646 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 647 | if (options != null) { |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 648 | pendingOptions = options; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 649 | mLaunchTaskBehind = pendingOptions.getLaunchTaskBehind(); |
Robert Carr | 0f5d753 | 2016-10-17 16:39:17 -0700 | [diff] [blame] | 650 | |
| 651 | final int rotationAnimation = pendingOptions.getRotationAnimationHint(); |
| 652 | // Only override manifest supplied option if set. |
| 653 | if (rotationAnimation >= 0) { |
| 654 | mRotationAnimationHint = rotationAnimation; |
| 655 | } |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 656 | PendingIntent usageReport = pendingOptions.getUsageTimeReport(); |
| 657 | if (usageReport != null) { |
| 658 | appTimeTracker = new AppTimeTracker(usageReport); |
| 659 | } |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 660 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 661 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 662 | // This starts out true, since the initial state of an activity is that we have everything, |
| 663 | // and we shouldn't never consider it lacking in state to be removed if it dies. |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 664 | haveState = true; |
| 665 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 666 | // If the class name in the intent doesn't match that of the target, this is |
| 667 | // probably an alias. We have to create a new ComponentName object to keep track |
| 668 | // of the real activity name, so that FLAG_ACTIVITY_CLEAR_TOP is handled properly. |
| 669 | if (aInfo.targetActivity == null |
| 670 | || (aInfo.targetActivity.equals(_intent.getComponent().getClassName()) |
| 671 | && (aInfo.launchMode == LAUNCH_MULTIPLE |
| 672 | || aInfo.launchMode == LAUNCH_SINGLE_TOP))) { |
| 673 | realActivity = _intent.getComponent(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | } else { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 675 | realActivity = new ComponentName(aInfo.packageName, aInfo.targetActivity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 676 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 677 | taskAffinity = aInfo.taskAffinity; |
| 678 | stateNotNeeded = (aInfo.flags & FLAG_STATE_NOT_NEEDED) != 0; |
| 679 | appInfo = aInfo.applicationInfo; |
| 680 | nonLocalizedLabel = aInfo.nonLocalizedLabel; |
| 681 | labelRes = aInfo.labelRes; |
| 682 | if (nonLocalizedLabel == null && labelRes == 0) { |
| 683 | ApplicationInfo app = aInfo.applicationInfo; |
| 684 | nonLocalizedLabel = app.nonLocalizedLabel; |
| 685 | labelRes = app.labelRes; |
| 686 | } |
| 687 | icon = aInfo.getIconResource(); |
| 688 | logo = aInfo.getLogoResource(); |
| 689 | theme = aInfo.getThemeResource(); |
| 690 | realTheme = theme; |
| 691 | if (realTheme == 0) { |
| 692 | realTheme = aInfo.applicationInfo.targetSdkVersion < HONEYCOMB |
| 693 | ? android.R.style.Theme : android.R.style.Theme_Holo; |
| 694 | } |
| 695 | if ((aInfo.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) { |
| 696 | windowFlags |= LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 697 | } |
| 698 | if ((aInfo.flags & FLAG_MULTIPROCESS) != 0 && _caller != null |
| 699 | && (aInfo.applicationInfo.uid == SYSTEM_UID |
| 700 | || aInfo.applicationInfo.uid == _caller.info.uid)) { |
| 701 | processName = _caller.processName; |
| 702 | } else { |
| 703 | processName = aInfo.processName; |
| 704 | } |
| 705 | |
| 706 | if ((aInfo.flags & FLAG_EXCLUDE_FROM_RECENTS) != 0) { |
| 707 | intent.addFlags(FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 708 | } |
| 709 | |
| 710 | packageName = aInfo.applicationInfo.packageName; |
| 711 | launchMode = aInfo.launchMode; |
| 712 | |
| 713 | AttributeCache.Entry ent = AttributeCache.instance().get(packageName, |
| 714 | realTheme, com.android.internal.R.styleable.Window, userId); |
| 715 | final boolean translucent = ent != null && (ent.array.getBoolean( |
| 716 | com.android.internal.R.styleable.Window_windowIsTranslucent, false) |
| 717 | || (!ent.array.hasValue( |
| 718 | com.android.internal.R.styleable.Window_windowIsTranslucent) |
| 719 | && ent.array.getBoolean( |
| 720 | com.android.internal.R.styleable.Window_windowSwipeToDismiss, |
| 721 | false))); |
| 722 | fullscreen = ent != null && !ent.array.getBoolean( |
| 723 | com.android.internal.R.styleable.Window_windowIsFloating, false) && !translucent; |
| 724 | noDisplay = ent != null && ent.array.getBoolean( |
| 725 | com.android.internal.R.styleable.Window_windowNoDisplay, false); |
| 726 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame^] | 727 | setActivityType(_componentSpecified, _launchedFromUid, _intent, options, sourceRecord); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 728 | |
| 729 | immersive = (aInfo.flags & FLAG_IMMERSIVE) != 0; |
| 730 | |
| 731 | requestedVrComponent = (aInfo.requestedVrComponent == null) ? |
| 732 | null : ComponentName.unflattenFromString(aInfo.requestedVrComponent); |
| 733 | } |
| 734 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 735 | AppWindowContainerController getWindowContainerController() { |
| 736 | return mWindowContainerController; |
| 737 | } |
| 738 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 739 | void createWindowContainer() { |
| 740 | if (mWindowContainerController != null) { |
| 741 | throw new IllegalArgumentException("Window container=" + mWindowContainerController |
| 742 | + " already created for r=" + this); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | inHistory = true; |
| 746 | |
| 747 | task.updateOverrideConfigurationFromLaunchBounds(); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 748 | final TaskWindowContainerController taskController = task.getWindowContainerController(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 749 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 750 | mWindowContainerController = new AppWindowContainerController(taskController, appToken, |
| 751 | this, Integer.MAX_VALUE /* add on top */, info.screenOrientation, fullscreen, |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 752 | (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, info.configChanges, |
| 753 | task.voiceSession != null, mLaunchTaskBehind, isAlwaysFocusable(), |
| 754 | appInfo.targetSdkVersion, mRotationAnimationHint, |
| 755 | ActivityManagerService.getInputDispatchingTimeoutLocked(this) * 1000000L); |
| 756 | |
| 757 | task.addActivityToTop(this); |
| 758 | |
| 759 | onOverrideConfigurationSent(); |
| 760 | } |
| 761 | |
| 762 | void removeWindowContainer() { |
Wale Ogunwale | cc367f4 | 2017-02-01 08:12:14 -0800 | [diff] [blame] | 763 | // Resume key dispatching if it is currently paused before we remove the container. |
| 764 | resumeKeyDispatchingLocked(); |
| 765 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 766 | mWindowContainerController.removeContainer(getDisplayId()); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 767 | mWindowContainerController = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 768 | } |
| 769 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 770 | /** |
| 771 | * Reparents this activity into {@param newTask} at the provided {@param position}. The caller |
| 772 | * should ensure that the {@param newTask} is not already the parent of this activity. |
| 773 | */ |
| 774 | void reparent(TaskRecord newTask, int position, String reason) { |
| 775 | final TaskRecord prevTask = task; |
| 776 | if (prevTask == newTask) { |
| 777 | throw new IllegalArgumentException(reason + ": task=" + newTask |
| 778 | + " is already the parent of r=" + this); |
| 779 | } |
| 780 | |
| 781 | // Must reparent first in window manager |
| 782 | mWindowContainerController.reparent(newTask.getWindowContainerController(), position); |
| 783 | |
| 784 | // Remove the activity from the old task and add it to the new task |
| 785 | prevTask.removeActivity(this); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 786 | // TODO(b/34179495): This should really be set to null in removeActivity() call above, |
| 787 | // but really bad things that I can't track down right now happen when I do that. |
| 788 | // So, setting it here now and will change later when there is time for investigation. |
| 789 | task = null; |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 790 | newTask.addActivityAtIndex(position, this); |
| 791 | } |
| 792 | |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 793 | private boolean isHomeIntent(Intent intent) { |
| 794 | return Intent.ACTION_MAIN.equals(intent.getAction()) |
| 795 | && intent.hasCategory(Intent.CATEGORY_HOME) |
| 796 | && intent.getCategories().size() == 1 |
| 797 | && intent.getData() == null |
| 798 | && intent.getType() == null; |
| 799 | } |
| 800 | |
Chong Zhang | ad24f96 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 801 | static boolean isMainIntent(Intent intent) { |
| 802 | return Intent.ACTION_MAIN.equals(intent.getAction()) |
| 803 | && intent.hasCategory(Intent.CATEGORY_LAUNCHER) |
| 804 | && intent.getCategories().size() == 1 |
| 805 | && intent.getData() == null |
| 806 | && intent.getType() == null; |
| 807 | } |
| 808 | |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 809 | private boolean canLaunchHomeActivity(int uid, ActivityRecord sourceRecord) { |
| 810 | if (uid == Process.myUid() || uid == 0) { |
| 811 | // System process can launch home activity. |
| 812 | return true; |
| 813 | } |
| 814 | // Resolver activity can launch home activity. |
| 815 | return sourceRecord != null && sourceRecord.isResolverActivity(); |
| 816 | } |
| 817 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame^] | 818 | /** |
| 819 | * @return whether the given package name can launch an assist activity. |
| 820 | */ |
| 821 | private boolean canLaunchAssistActivity(String packageName) { |
| 822 | if (service.mAssistUtils == null) { |
| 823 | return false; |
| 824 | } |
| 825 | |
| 826 | final ComponentName assistComponent = service.mAssistUtils.getActiveServiceComponentName(); |
| 827 | if (assistComponent != null) { |
| 828 | return assistComponent.getPackageName().equals(packageName); |
| 829 | } |
| 830 | return false; |
| 831 | } |
| 832 | |
| 833 | private void setActivityType(boolean componentSpecified, int launchedFromUid, Intent intent, |
| 834 | ActivityOptions options, ActivityRecord sourceRecord) { |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 835 | if ((!componentSpecified || canLaunchHomeActivity(launchedFromUid, sourceRecord)) |
| 836 | && isHomeIntent(intent) && !isResolverActivity()) { |
| 837 | // This sure looks like a home activity! |
| 838 | mActivityType = HOME_ACTIVITY_TYPE; |
Wale Ogunwale | df241e9 | 2016-10-13 15:14:21 -0700 | [diff] [blame] | 839 | |
| 840 | if (info.resizeMode == RESIZE_MODE_FORCE_RESIZEABLE |
| 841 | || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) { |
| 842 | // We only allow home activities to be resizeable if they explicitly requested it. |
| 843 | info.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
| 844 | } |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 845 | } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) { |
| 846 | mActivityType = RECENTS_ACTIVITY_TYPE; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame^] | 847 | } else if (options != null && options.getLaunchStackId() == ASSISTANT_STACK_ID |
| 848 | && canLaunchAssistActivity(launchedFromPackage)) { |
| 849 | mActivityType = ASSISTANT_ACTIVITY_TYPE; |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 850 | } else { |
| 851 | mActivityType = APPLICATION_ACTIVITY_TYPE; |
| 852 | } |
| 853 | } |
| 854 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 855 | void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) { |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 856 | if (launchMode != LAUNCH_SINGLE_INSTANCE && launchMode != LAUNCH_SINGLE_TASK) { |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 857 | task.setTaskToAffiliateWith(taskToAffiliateWith); |
| 858 | } |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 861 | /** |
| 862 | * @return Stack value from current task, null if there is no task. |
| 863 | */ |
| 864 | ActivityStack getStack() { |
| 865 | return task != null ? task.getStack() : null; |
| 866 | } |
| 867 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 868 | boolean changeWindowTranslucency(boolean toOpaque) { |
| 869 | if (fullscreen == toOpaque) { |
| 870 | return false; |
| 871 | } |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 872 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 873 | // Keep track of the number of fullscreen activities in this task. |
| 874 | task.numFullscreen += toOpaque ? +1 : -1; |
| 875 | |
| 876 | fullscreen = toOpaque; |
| 877 | return true; |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 880 | void takeFromHistory() { |
| 881 | if (inHistory) { |
| 882 | inHistory = false; |
| 883 | if (task != null && !finishing) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 884 | task = null; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 885 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 886 | clearOptionsLocked(); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 887 | } |
| 888 | } |
| 889 | |
| 890 | boolean isInHistory() { |
| 891 | return inHistory; |
| 892 | } |
| 893 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 894 | boolean isInStackLocked() { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 895 | final ActivityStack stack = getStack(); |
| 896 | return stack != null && stack.isInStackLocked(this) != null; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 899 | boolean isHomeActivity() { |
| 900 | return mActivityType == HOME_ACTIVITY_TYPE; |
| 901 | } |
| 902 | |
| 903 | boolean isRecentsActivity() { |
| 904 | return mActivityType == RECENTS_ACTIVITY_TYPE; |
| 905 | } |
| 906 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame^] | 907 | boolean isAssistantActivity() { |
| 908 | return mActivityType == ASSISTANT_ACTIVITY_TYPE; |
| 909 | } |
| 910 | |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 911 | boolean isApplicationActivity() { |
| 912 | return mActivityType == APPLICATION_ACTIVITY_TYPE; |
| 913 | } |
| 914 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 915 | boolean isPersistable() { |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 916 | return (info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || |
| 917 | info.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS) && |
| 918 | (intent == null || |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 919 | (intent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 922 | boolean isFocusable() { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 923 | return StackId.canReceiveKeys(task.getStackId()) || isAlwaysFocusable(); |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | boolean isResizeable() { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 927 | return ActivityInfo.isResizeableMode(info.resizeMode) || info.supportsPictureInPicture(); |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 928 | } |
| 929 | |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 930 | /** |
| 931 | * @return whether this activity is non-resizeable or forced to be resizeable |
| 932 | */ |
| 933 | boolean isNonResizableOrForcedResizable() { |
Wale Ogunwale | df241e9 | 2016-10-13 15:14:21 -0700 | [diff] [blame] | 934 | return info.resizeMode != RESIZE_MODE_RESIZEABLE |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 935 | && info.resizeMode != RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
Jorim Jaggi | cd13d33 | 2016-04-27 15:40:20 -0700 | [diff] [blame] | 936 | } |
| 937 | |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 938 | /** |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 939 | * @return whether this activity supports PiP multi-window and can be put in the pinned stack. |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 940 | */ |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 941 | boolean supportsPictureInPicture() { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 942 | return service.mSupportsPictureInPicture && !isHomeActivity() |
| 943 | && info.supportsPictureInPicture(); |
| 944 | } |
| 945 | |
| 946 | /** |
| 947 | * @return whether this activity supports split-screen multi-window and can be put in the docked |
| 948 | * stack. |
| 949 | */ |
| 950 | boolean supportsSplitScreen() { |
| 951 | // An activity can not be docked even if it is considered resizeable because it only |
| 952 | // supports picture-in-picture mode but has a non-resizeable resizeMode |
| 953 | return service.mSupportsSplitScreenMultiWindow && supportsResizeableMultiWindow(); |
| 954 | } |
| 955 | |
| 956 | /** |
| 957 | * @return whether this activity supports freeform multi-window and can be put in the freeform |
| 958 | * stack. |
| 959 | */ |
| 960 | boolean supportsFreeform() { |
| 961 | return service.mSupportsFreeformWindowManagement && supportsResizeableMultiWindow(); |
| 962 | } |
| 963 | |
| 964 | /** |
| 965 | * @return whether this activity supports non-PiP multi-window. |
| 966 | */ |
| 967 | private boolean supportsResizeableMultiWindow() { |
| 968 | return service.mSupportsMultiWindow && !isHomeActivity() |
| 969 | && (ActivityInfo.isResizeableMode(info.resizeMode) |
| 970 | || service.mForceResizableActivities); |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 971 | } |
| 972 | |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 973 | /** |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 974 | * @return whether this activity is currently allowed to enter PIP, throwing an exception if |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 975 | * the activity is not currently visible and {@param noThrow} is not set. |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 976 | */ |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 977 | boolean checkEnterPictureInPictureState(String caller, boolean noThrow) { |
Winson Chung | bb34880 | 2017-01-30 12:01:45 -0800 | [diff] [blame] | 978 | boolean isCurrentAppLocked = mStackSupervisor.getLockTaskModeState() != LOCK_TASK_MODE_NONE; |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 979 | boolean isKeyguardLocked = service.isKeyguardLocked(); |
| 980 | boolean hasPinnedStack = mStackSupervisor.getStack(PINNED_STACK_ID) != null; |
Winson Chung | bb34880 | 2017-01-30 12:01:45 -0800 | [diff] [blame] | 981 | // Don't return early if !isNotLocked, since we want to throw an exception if the activity |
| 982 | // is in an incorrect state |
| 983 | boolean isNotLocked = !isKeyguardLocked && !isCurrentAppLocked; |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 984 | switch (state) { |
| 985 | case RESUMED: |
Winson Chung | bb34880 | 2017-01-30 12:01:45 -0800 | [diff] [blame] | 986 | // When visible, allow entering PiP if not on the lockscreen and if the task is not |
| 987 | // locked |
| 988 | return isNotLocked; |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 989 | case PAUSING: |
| 990 | case PAUSED: |
Winson Chung | bb34880 | 2017-01-30 12:01:45 -0800 | [diff] [blame] | 991 | // When pausing, then only allow enter PiP as in the resume state, and in addition, |
| 992 | // require that there is not an existing PiP activity and that the current system |
| 993 | // state supports entering PiP |
| 994 | return isNotLocked && !hasPinnedStack && supportsPictureInPictureWhilePausing |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 995 | && checkEnterPictureInPictureOnHideAppOpsState(); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 996 | case STOPPING: |
| 997 | // When stopping in a valid state, then only allow enter PiP as in the pause state. |
| 998 | // Otherwise, fall through to throw an exception if the caller is trying to enter |
| 999 | // PiP in an invalid stopping state. |
| 1000 | if (supportsPictureInPictureWhilePausing) { |
Winson Chung | bb34880 | 2017-01-30 12:01:45 -0800 | [diff] [blame] | 1001 | return isNotLocked && !hasPinnedStack |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 1002 | && checkEnterPictureInPictureOnHideAppOpsState(); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 1003 | } |
| 1004 | default: |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1005 | if (noThrow) { |
| 1006 | return false; |
| 1007 | } else { |
| 1008 | throw new IllegalStateException(caller |
| 1009 | + ": Current activity is not visible (state=" + state.name() + ") " |
| 1010 | + "r=" + this); |
| 1011 | } |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 1012 | } |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 1015 | /** |
| 1016 | * @return Whether AppOps allows this package to enter picture-in-picture when it is hidden. |
| 1017 | */ |
| 1018 | private boolean checkEnterPictureInPictureOnHideAppOpsState() { |
| 1019 | try { |
| 1020 | return service.getAppOpsService().checkOperation(OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE, |
| 1021 | appInfo.uid, packageName) == MODE_ALLOWED; |
| 1022 | } catch (RemoteException e) { |
| 1023 | // Local call |
| 1024 | } |
| 1025 | return false; |
| 1026 | } |
| 1027 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 1028 | boolean isAlwaysFocusable() { |
| 1029 | return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1030 | } |
| 1031 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1032 | /** |
| 1033 | * @return true if the activity contains windows that have |
| 1034 | * {@link LayoutParams#FLAG_SHOW_WHEN_LOCKED} set |
| 1035 | */ |
| 1036 | boolean hasShowWhenLockedWindows() { |
| 1037 | return service.mWindowManager.containsShowWhenLockedWindow(appToken); |
| 1038 | } |
| 1039 | |
| 1040 | /** |
| 1041 | * @return true if the activity contains windows that have |
| 1042 | * {@link LayoutParams#FLAG_DISMISS_KEYGUARD} set |
| 1043 | */ |
| 1044 | boolean hasDismissKeyguardWindows() { |
| 1045 | return service.mWindowManager.containsDismissKeyguardWindow(appToken); |
| 1046 | } |
| 1047 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1048 | void makeFinishingLocked() { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 1049 | if (!finishing) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1050 | final ActivityStack stack = getStack(); |
| 1051 | if (stack != null && this == stack.getVisibleBehindActivity()) { |
Jose Lima | 34ff492 | 2014-08-18 15:19:41 -0700 | [diff] [blame] | 1052 | // A finishing activity should not remain as visible in the background |
| 1053 | mStackSupervisor.requestVisibleBehindLocked(this, false); |
| 1054 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 1055 | finishing = true; |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 1056 | if (stopped) { |
| 1057 | clearOptionsLocked(); |
| 1058 | } |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 1059 | |
| 1060 | if (service != null) { |
| 1061 | service.mTaskChangeNotificationController.notifyTaskStackChanged(); |
| 1062 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 1063 | } |
| 1064 | } |
| 1065 | |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 1066 | UriPermissionOwner getUriPermissionsLocked() { |
| 1067 | if (uriPermissions == null) { |
| 1068 | uriPermissions = new UriPermissionOwner(service, this); |
| 1069 | } |
| 1070 | return uriPermissions; |
| 1071 | } |
| 1072 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1073 | void addResultLocked(ActivityRecord from, String resultWho, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1074 | int requestCode, int resultCode, |
| 1075 | Intent resultData) { |
| 1076 | ActivityResult r = new ActivityResult(from, resultWho, |
John Spurlock | 8a985d2 | 2014-02-25 09:40:05 -0500 | [diff] [blame] | 1077 | requestCode, resultCode, resultData); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1078 | if (results == null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1079 | results = new ArrayList<ResultInfo>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1080 | } |
| 1081 | results.add(r); |
| 1082 | } |
| 1083 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1084 | void removeResultsLocked(ActivityRecord from, String resultWho, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1085 | int requestCode) { |
| 1086 | if (results != null) { |
| 1087 | for (int i=results.size()-1; i>=0; i--) { |
| 1088 | ActivityResult r = (ActivityResult)results.get(i); |
| 1089 | if (r.mFrom != from) continue; |
| 1090 | if (r.mResultWho == null) { |
| 1091 | if (resultWho != null) continue; |
| 1092 | } else { |
| 1093 | if (!r.mResultWho.equals(resultWho)) continue; |
| 1094 | } |
| 1095 | if (r.mRequestCode != requestCode) continue; |
| 1096 | |
| 1097 | results.remove(i); |
| 1098 | } |
| 1099 | } |
| 1100 | } |
| 1101 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1102 | private void addNewIntentLocked(ReferrerIntent intent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | if (newIntents == null) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 1104 | newIntents = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | } |
| 1106 | newIntents.add(intent); |
| 1107 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1108 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1109 | /** |
| 1110 | * Deliver a new Intent to an existing activity, so that its onNewIntent() |
| 1111 | * method will be called at the proper time. |
| 1112 | */ |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 1113 | final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) { |
Dianne Hackborn | 514074f | 2013-02-11 10:52:46 -0800 | [diff] [blame] | 1114 | // The activity now gets access to the data associated with this Intent. |
| 1115 | service.grantUriPermissionFromIntentLocked(callingUid, packageName, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 1116 | intent, getUriPermissionsLocked(), userId); |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 1117 | final ReferrerIntent rintent = new ReferrerIntent(intent, referrer); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 1118 | boolean unsent = true; |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1119 | final ActivityStack stack = getStack(); |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 1120 | final boolean isTopActivityInStack = |
| 1121 | stack != null && stack.topRunningActivityLocked() == this; |
| 1122 | final boolean isTopActivityWhileSleeping = |
| 1123 | service.isSleepingLocked() && isTopActivityInStack; |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 1124 | |
| 1125 | // We want to immediately deliver the intent to the activity if: |
Wale Ogunwale | 03f7e9e | 2016-09-22 09:04:09 -0700 | [diff] [blame] | 1126 | // - It is currently resumed or paused. i.e. it is currently visible to the user and we want |
| 1127 | // the user to see the visual effects caused by the intent delivery now. |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 1128 | // - The device is sleeping and it is the top activity behind the lock screen (b/6700897). |
Wale Ogunwale | 03f7e9e | 2016-09-22 09:04:09 -0700 | [diff] [blame] | 1129 | if ((state == ActivityState.RESUMED || state == ActivityState.PAUSED |
| 1130 | || isTopActivityWhileSleeping) && app != null && app.thread != null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1131 | try { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 1132 | ArrayList<ReferrerIntent> ar = new ArrayList<>(1); |
| 1133 | ar.add(rintent); |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 1134 | app.thread.scheduleNewIntent( |
Wale Ogunwale | 03f7e9e | 2016-09-22 09:04:09 -0700 | [diff] [blame] | 1135 | ar, appToken, state == ActivityState.PAUSED /* andPause */); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 1136 | unsent = false; |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 1137 | } catch (RemoteException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1138 | Slog.w(TAG, "Exception thrown sending new intent to " + this, e); |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 1139 | } catch (NullPointerException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1140 | Slog.w(TAG, "Exception thrown sending new intent to " + this, e); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1141 | } |
| 1142 | } |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 1143 | if (unsent) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 1144 | addNewIntentLocked(rintent); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1145 | } |
| 1146 | } |
| 1147 | |
Dianne Hackborn | 9622ca4 | 2012-10-23 18:56:33 -0700 | [diff] [blame] | 1148 | void updateOptionsLocked(ActivityOptions options) { |
| 1149 | if (options != null) { |
| 1150 | if (pendingOptions != null) { |
| 1151 | pendingOptions.abort(); |
| 1152 | } |
| 1153 | pendingOptions = options; |
| 1154 | } |
| 1155 | } |
| 1156 | |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1157 | void applyOptionsLocked() { |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1158 | if (pendingOptions != null |
| 1159 | && pendingOptions.getAnimationType() != ActivityOptions.ANIM_SCENE_TRANSITION) { |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 1160 | final int animationType = pendingOptions.getAnimationType(); |
| 1161 | switch (animationType) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1162 | case ActivityOptions.ANIM_CUSTOM: |
| 1163 | service.mWindowManager.overridePendingAppTransition( |
| 1164 | pendingOptions.getPackageName(), |
| 1165 | pendingOptions.getCustomEnterResId(), |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1166 | pendingOptions.getCustomExitResId(), |
| 1167 | pendingOptions.getOnAnimationStartListener()); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1168 | break; |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 1169 | case ActivityOptions.ANIM_CLIP_REVEAL: |
| 1170 | service.mWindowManager.overridePendingAppTransitionClipReveal( |
| 1171 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 1172 | pendingOptions.getWidth(), pendingOptions.getHeight()); |
| 1173 | if (intent.getSourceBounds() == null) { |
| 1174 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 1175 | pendingOptions.getStartY(), |
| 1176 | pendingOptions.getStartX()+pendingOptions.getWidth(), |
| 1177 | pendingOptions.getStartY()+pendingOptions.getHeight())); |
| 1178 | } |
| 1179 | break; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1180 | case ActivityOptions.ANIM_SCALE_UP: |
| 1181 | service.mWindowManager.overridePendingAppTransitionScaleUp( |
| 1182 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 1183 | pendingOptions.getWidth(), pendingOptions.getHeight()); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 1184 | if (intent.getSourceBounds() == null) { |
| 1185 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 1186 | pendingOptions.getStartY(), |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 1187 | pendingOptions.getStartX()+pendingOptions.getWidth(), |
| 1188 | pendingOptions.getStartY()+pendingOptions.getHeight())); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 1189 | } |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1190 | break; |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 1191 | case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP: |
| 1192 | case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN: |
| 1193 | boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1194 | service.mWindowManager.overridePendingAppTransitionThumb( |
| 1195 | pendingOptions.getThumbnail(), |
| 1196 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 1197 | pendingOptions.getOnAnimationStartListener(), |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 1198 | scaleUp); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 1199 | if (intent.getSourceBounds() == null) { |
| 1200 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 1201 | pendingOptions.getStartY(), |
| 1202 | pendingOptions.getStartX() |
| 1203 | + pendingOptions.getThumbnail().getWidth(), |
| 1204 | pendingOptions.getStartY() |
| 1205 | + pendingOptions.getThumbnail().getHeight())); |
| 1206 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1207 | break; |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1208 | case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP: |
| 1209 | case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN: |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1210 | final AppTransitionAnimationSpec[] specs = pendingOptions.getAnimSpecs(); |
| 1211 | if (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN |
| 1212 | && specs != null) { |
| 1213 | service.mWindowManager.overridePendingAppTransitionMultiThumb( |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 1214 | specs, pendingOptions.getOnAnimationStartListener(), |
| 1215 | pendingOptions.getAnimationFinishedListener(), false); |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1216 | } else { |
| 1217 | service.mWindowManager.overridePendingAppTransitionAspectScaledThumb( |
| 1218 | pendingOptions.getThumbnail(), |
| 1219 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 1220 | pendingOptions.getWidth(), pendingOptions.getHeight(), |
| 1221 | pendingOptions.getOnAnimationStartListener(), |
| 1222 | (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP)); |
| 1223 | if (intent.getSourceBounds() == null) { |
| 1224 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 1225 | pendingOptions.getStartY(), |
| 1226 | pendingOptions.getStartX() + pendingOptions.getWidth(), |
| 1227 | pendingOptions.getStartY() + pendingOptions.getHeight())); |
| 1228 | } |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1229 | } |
| 1230 | break; |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 1231 | default: |
| 1232 | Slog.e(TAG, "applyOptionsLocked: Unknown animationType=" + animationType); |
| 1233 | break; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1234 | } |
| 1235 | pendingOptions = null; |
| 1236 | } |
| 1237 | } |
| 1238 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1239 | ActivityOptions getOptionsForTargetActivityLocked() { |
| 1240 | return pendingOptions != null ? pendingOptions.forTargetActivity() : null; |
| 1241 | } |
| 1242 | |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1243 | void clearOptionsLocked() { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1244 | if (pendingOptions != null) { |
| 1245 | pendingOptions.abort(); |
| 1246 | pendingOptions = null; |
| 1247 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
Dianne Hackborn | 9622ca4 | 2012-10-23 18:56:33 -0700 | [diff] [blame] | 1250 | ActivityOptions takeOptionsLocked() { |
| 1251 | ActivityOptions opts = pendingOptions; |
| 1252 | pendingOptions = null; |
| 1253 | return opts; |
| 1254 | } |
| 1255 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1256 | void removeUriPermissionsLocked() { |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 1257 | if (uriPermissions != null) { |
| 1258 | uriPermissions.removeUriPermissionsLocked(); |
| 1259 | uriPermissions = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1260 | } |
| 1261 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1262 | |
| 1263 | void pauseKeyDispatchingLocked() { |
| 1264 | if (!keysPaused) { |
| 1265 | keysPaused = true; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1266 | mWindowContainerController.pauseKeyDispatching(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | void resumeKeyDispatchingLocked() { |
| 1271 | if (keysPaused) { |
| 1272 | keysPaused = false; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1273 | mWindowContainerController.resumeKeyDispatching(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1274 | } |
| 1275 | } |
| 1276 | |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1277 | void updateThumbnailLocked(Bitmap newThumbnail, CharSequence description) { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1278 | if (newThumbnail != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1279 | if (DEBUG_THUMBNAILS) Slog.i(TAG_THUMBNAILS, |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1280 | "Setting thumbnail of " + this + " to " + newThumbnail); |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 1281 | boolean thumbnailUpdated = task.setLastThumbnailLocked(newThumbnail); |
Winson Chung | 096f36b | 2014-08-20 15:39:01 -0700 | [diff] [blame] | 1282 | if (thumbnailUpdated && isPersistable()) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1283 | service.notifyTaskPersisterLocked(task, false); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1284 | } |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1285 | } |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1286 | task.lastDescription = description; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1289 | final Bitmap screenshotActivityLocked() { |
| 1290 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "screenshotActivityLocked: " + this); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 1291 | |
| 1292 | if (ENABLE_TASK_SNAPSHOTS) { |
| 1293 | // No need to screenshot if snapshots are enabled. |
| 1294 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, |
| 1295 | "\tSnapshots are enabled, abort taking screenshot"); |
| 1296 | return null; |
| 1297 | } |
| 1298 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1299 | if (noDisplay) { |
| 1300 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tNo display"); |
| 1301 | return null; |
| 1302 | } |
| 1303 | |
| 1304 | final ActivityStack stack = getStack(); |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 1305 | if (stack.isHomeOrRecentsStack()) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1306 | // This is an optimization -- since we never show Home or Recents within Recents itself, |
| 1307 | // we can just go ahead and skip taking the screenshot if this is the home stack. |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 1308 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, stack.getStackId() == HOME_STACK_ID ? |
| 1309 | "\tHome stack" : "\tRecents stack"); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1310 | return null; |
| 1311 | } |
| 1312 | |
| 1313 | int w = service.mThumbnailWidth; |
| 1314 | int h = service.mThumbnailHeight; |
| 1315 | |
| 1316 | if (w <= 0) { |
| 1317 | Slog.e(TAG, "\tInvalid thumbnail dimensions: " + w + "x" + h); |
| 1318 | return null; |
| 1319 | } |
| 1320 | |
| 1321 | if (stack.mStackId == DOCKED_STACK_ID && mStackSupervisor.mIsDockMinimized) { |
| 1322 | // When the docked stack is minimized its app windows are cropped significantly so any |
| 1323 | // screenshot taken will not display the apps contain. So, we avoid taking a screenshot |
| 1324 | // in that case. |
| 1325 | if (DEBUG_SCREENSHOTS) Slog.e(TAG, "\tIn minimized docked stack"); |
| 1326 | return null; |
| 1327 | } |
| 1328 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1329 | float scale = 0; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1330 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tTaking screenshot"); |
| 1331 | |
| 1332 | // When this flag is set, we currently take the fullscreen screenshot of the activity but |
| 1333 | // scaled to half the size. This gives us a "good-enough" fullscreen thumbnail to use within |
| 1334 | // SystemUI while keeping memory usage low. |
| 1335 | if (TAKE_FULLSCREEN_SCREENSHOTS) { |
| 1336 | w = h = -1; |
| 1337 | scale = service.mFullscreenThumbnailScale; |
| 1338 | } |
| 1339 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1340 | return mWindowContainerController.screenshotApplications(getDisplayId(), w, h, scale); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1341 | } |
| 1342 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1343 | void setVisibility(boolean visible) { |
| 1344 | mWindowContainerController.setVisibility(visible); |
| 1345 | } |
| 1346 | |
| 1347 | // TODO: Look into merging with #setVisibility() |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1348 | void setVisible(boolean newVisible) { |
| 1349 | visible = newVisible; |
| 1350 | if (!visible && mUpdateTaskThumbnailWhenHidden) { |
| 1351 | updateThumbnailLocked(screenshotActivityLocked(), null /* description */); |
| 1352 | mUpdateTaskThumbnailWhenHidden = false; |
| 1353 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1354 | mWindowContainerController.setVisibility(visible); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1355 | final ArrayList<ActivityContainer> containers = mChildContainers; |
| 1356 | for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) { |
| 1357 | final ActivityContainer container = containers.get(containerNdx); |
| 1358 | container.setVisible(visible); |
| 1359 | } |
| 1360 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; |
| 1361 | } |
| 1362 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1363 | void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) { |
| 1364 | mWindowContainerController.notifyAppResumed(wasStopped, allowSavedSurface); |
| 1365 | } |
| 1366 | |
| 1367 | void notifyUnknownVisibilityLaunched() { |
| 1368 | mWindowContainerController.notifyUnknownVisibilityLaunched(); |
| 1369 | } |
| 1370 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1371 | /** |
| 1372 | * @return true if the input activity should be made visible, ignoring any effect Keyguard |
| 1373 | * might have on the visibility |
| 1374 | * |
| 1375 | * @see {@link ActivityStack#checkKeyguardVisibility} |
| 1376 | */ |
| 1377 | boolean shouldBeVisibleIgnoringKeyguard(boolean behindTranslucentActivity, |
| 1378 | boolean stackVisibleBehind, ActivityRecord visibleBehind, |
| 1379 | boolean behindFullscreenActivity) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1380 | if (!okToShowLocked()) { |
| 1381 | return false; |
| 1382 | } |
| 1383 | |
| 1384 | // mLaunchingBehind: Activities launching behind are at the back of the task stack |
| 1385 | // but must be drawn initially for the animation as though they were visible. |
| 1386 | final boolean activityVisibleBehind = |
| 1387 | (behindTranslucentActivity || stackVisibleBehind) && visibleBehind == this; |
| 1388 | |
| 1389 | boolean isVisible = |
| 1390 | !behindFullscreenActivity || mLaunchTaskBehind || activityVisibleBehind; |
| 1391 | |
| 1392 | if (service.mSupportsLeanbackOnly && isVisible && isRecentsActivity()) { |
| 1393 | // On devices that support leanback only (Android TV), Recents activity can only be |
| 1394 | // visible if the home stack is the focused stack or we are in split-screen mode. |
| 1395 | isVisible = mStackSupervisor.getStack(DOCKED_STACK_ID) != null |
| 1396 | || mStackSupervisor.isFocusedStack(getStack()); |
| 1397 | } |
| 1398 | |
| 1399 | return isVisible; |
| 1400 | } |
| 1401 | |
| 1402 | void makeVisibleIfNeeded(ActivityRecord starting) { |
| 1403 | // This activity is not currently visible, but is running. Tell it to become visible. |
| 1404 | if (state == ActivityState.RESUMED || this == starting) { |
| 1405 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, |
| 1406 | "Not making visible, r=" + this + " state=" + state + " starting=" + starting); |
| 1407 | return; |
| 1408 | } |
| 1409 | |
| 1410 | // If this activity is paused, tell it to now show its window. |
| 1411 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1412 | "Making visible and scheduling visibility: " + this); |
| 1413 | final ActivityStack stack = getStack(); |
| 1414 | try { |
| 1415 | if (stack.mTranslucentActivityWaiting != null) { |
| 1416 | updateOptionsLocked(returningOptions); |
| 1417 | stack.mUndrawnActivitiesBelowTopTranslucent.add(this); |
| 1418 | } |
| 1419 | setVisible(true); |
| 1420 | sleeping = false; |
| 1421 | app.pendingUiClean = true; |
| 1422 | app.thread.scheduleWindowVisibility(appToken, true /* showWindow */); |
| 1423 | // The activity may be waiting for stop, but that is no longer appropriate for it. |
| 1424 | mStackSupervisor.mStoppingActivities.remove(this); |
| 1425 | mStackSupervisor.mGoingToSleepActivities.remove(this); |
| 1426 | } catch (Exception e) { |
| 1427 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 1428 | Slog.w(TAG, "Exception thrown making visibile: " + intent.getComponent(), e); |
| 1429 | } |
| 1430 | handleAlreadyVisible(); |
| 1431 | } |
| 1432 | |
| 1433 | boolean handleAlreadyVisible() { |
| 1434 | stopFreezingScreenLocked(false); |
| 1435 | try { |
| 1436 | if (returningOptions != null) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1437 | app.thread.scheduleOnNewActivityOptions(appToken, returningOptions.toBundle()); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1438 | } |
| 1439 | } catch(RemoteException e) { |
| 1440 | } |
| 1441 | return state == ActivityState.RESUMED; |
| 1442 | } |
| 1443 | |
| 1444 | static void activityResumedLocked(IBinder token) { |
| 1445 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 1446 | if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r); |
| 1447 | if (r != null) { |
| 1448 | r.icicle = null; |
| 1449 | r.haveState = false; |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | /** |
| 1454 | * Once we know that we have asked an application to put an activity in the resumed state |
| 1455 | * (either by launching it or explicitly telling it), this function updates the rest of our |
| 1456 | * state to match that fact. |
| 1457 | */ |
| 1458 | void completeResumeLocked() { |
| 1459 | final boolean wasVisible = visible; |
| 1460 | visible = true; |
| 1461 | if (!wasVisible) { |
| 1462 | // Visibility has changed, so take a note of it so we call the TaskStackChangedListener |
| 1463 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; |
| 1464 | } |
| 1465 | idle = false; |
| 1466 | results = null; |
| 1467 | newIntents = null; |
| 1468 | stopped = false; |
| 1469 | |
| 1470 | if (isHomeActivity()) { |
| 1471 | ProcessRecord app = task.mActivities.get(0).app; |
| 1472 | if (app != null && app != service.mHomeProcess) { |
| 1473 | service.mHomeProcess = app; |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | if (nowVisible) { |
| 1478 | // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now. |
| 1479 | mStackSupervisor.reportActivityVisibleLocked(this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | // Schedule an idle timeout in case the app doesn't do it for us. |
| 1483 | mStackSupervisor.scheduleIdleTimeoutLocked(this); |
| 1484 | |
| 1485 | mStackSupervisor.reportResumedActivityLocked(this); |
| 1486 | |
| 1487 | resumeKeyDispatchingLocked(); |
| 1488 | final ActivityStack stack = getStack(); |
| 1489 | stack.mNoAnimActivities.clear(); |
| 1490 | |
| 1491 | // Mark the point when the activity is resuming |
| 1492 | // TODO: To be more accurate, the mark should be before the onCreate, |
| 1493 | // not after the onResume. But for subsequent starts, onResume is fine. |
| 1494 | if (app != null) { |
| 1495 | cpuTimeAtResume = service.mProcessCpuTracker.getCpuTimeForPid(app.pid); |
| 1496 | } else { |
| 1497 | cpuTimeAtResume = 0; // Couldn't get the cpu time of process |
| 1498 | } |
| 1499 | |
| 1500 | returningOptions = null; |
| 1501 | |
| 1502 | if (stack.getVisibleBehindActivity() == this) { |
| 1503 | // When resuming an activity, require it to call requestVisibleBehind() again. |
| 1504 | stack.setVisibleBehindActivity(null /* ActivityRecord */); |
| 1505 | } |
| 1506 | mStackSupervisor.checkReadyForSleepLocked(); |
| 1507 | } |
| 1508 | |
| 1509 | final void activityStoppedLocked(Bundle newIcicle, PersistableBundle newPersistentState, |
| 1510 | CharSequence description) { |
| 1511 | final ActivityStack stack = getStack(); |
| 1512 | if (state != ActivityState.STOPPING) { |
| 1513 | Slog.i(TAG, "Activity reported stop, but no longer stopping: " + this); |
| 1514 | stack.mHandler.removeMessages(ActivityStack.STOP_TIMEOUT_MSG, this); |
| 1515 | return; |
| 1516 | } |
| 1517 | if (newPersistentState != null) { |
| 1518 | persistentState = newPersistentState; |
| 1519 | service.notifyTaskPersisterLocked(task, false); |
| 1520 | } |
| 1521 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, "Saving icicle of " + this + ": " + icicle); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1522 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1523 | if (newIcicle != null) { |
| 1524 | // If icicle is null, this is happening due to a timeout, so we haven't really saved |
| 1525 | // the state. |
| 1526 | icicle = newIcicle; |
| 1527 | haveState = true; |
| 1528 | launchCount = 0; |
| 1529 | updateThumbnailLocked(null /* newThumbnail */, description); |
| 1530 | } |
| 1531 | if (!stopped) { |
| 1532 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to STOPPED: " + this + " (stop complete)"); |
| 1533 | stack.mHandler.removeMessages(ActivityStack.STOP_TIMEOUT_MSG, this); |
| 1534 | stopped = true; |
| 1535 | state = ActivityState.STOPPED; |
| 1536 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1537 | mWindowContainerController.notifyAppStopped(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1538 | |
| 1539 | if (stack.getVisibleBehindActivity() == this) { |
| 1540 | mStackSupervisor.requestVisibleBehindLocked(this, false /* visible */); |
| 1541 | } |
| 1542 | if (finishing) { |
| 1543 | clearOptionsLocked(); |
| 1544 | } else { |
| 1545 | if (deferRelaunchUntilPaused) { |
| 1546 | stack.destroyActivityLocked(this, true /* removeFromApp */, "stop-config"); |
| 1547 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
| 1548 | } else { |
| 1549 | mStackSupervisor.updatePreviousProcessLocked(this); |
| 1550 | } |
| 1551 | } |
| 1552 | } |
| 1553 | } |
| 1554 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 1555 | void startLaunchTickingLocked() { |
| 1556 | if (ActivityManagerService.IS_USER_BUILD) { |
| 1557 | return; |
| 1558 | } |
| 1559 | if (launchTickTime == 0) { |
| 1560 | launchTickTime = SystemClock.uptimeMillis(); |
| 1561 | continueLaunchTickingLocked(); |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | boolean continueLaunchTickingLocked() { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1566 | if (launchTickTime == 0) { |
| 1567 | return false; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 1568 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1569 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1570 | final ActivityStack stack = getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1571 | if (stack == null) { |
| 1572 | return false; |
| 1573 | } |
| 1574 | |
| 1575 | Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG, this); |
| 1576 | stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG); |
| 1577 | stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK); |
| 1578 | return true; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | void finishLaunchTickingLocked() { |
| 1582 | launchTickTime = 0; |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1583 | final ActivityStack stack = getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1584 | if (stack != null) { |
| 1585 | stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG); |
| 1586 | } |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | // IApplicationToken |
| 1590 | |
| 1591 | public boolean mayFreezeScreenLocked(ProcessRecord app) { |
| 1592 | // Only freeze the screen if this activity is currently attached to |
| 1593 | // an application, and that application is not blocked or unresponding. |
| 1594 | // In any other case, we can't count on getting the screen unfrozen, |
| 1595 | // so it is best to leave as-is. |
Dianne Hackborn | 5f4d643 | 2010-12-21 20:40:11 -0800 | [diff] [blame] | 1596 | return app != null && !app.crashing && !app.notResponding; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1597 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1599 | public void startFreezingScreenLocked(ProcessRecord app, int configChanges) { |
| 1600 | if (mayFreezeScreenLocked(app)) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1601 | mWindowContainerController.startFreezingScreen(configChanges); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1602 | } |
| 1603 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1604 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1605 | public void stopFreezingScreenLocked(boolean force) { |
| 1606 | if (force || frozenBeforeDestroy) { |
| 1607 | frozenBeforeDestroy = false; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1608 | mWindowContainerController.stopFreezingScreen(force); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1609 | } |
| 1610 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1611 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1612 | public void reportFullyDrawnLocked() { |
| 1613 | final long curTime = SystemClock.uptimeMillis(); |
| 1614 | if (displayStartTime != 0) { |
| 1615 | reportLaunchTimeLocked(curTime); |
| 1616 | } |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1617 | final ActivityStack stack = getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1618 | if (fullyDrawnStartTime != 0 && stack != null) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1619 | final long thisTime = curTime - fullyDrawnStartTime; |
| 1620 | final long totalTime = stack.mFullyDrawnStartTime != 0 |
| 1621 | ? (curTime - stack.mFullyDrawnStartTime) : thisTime; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 1622 | if (SHOW_ACTIVITY_START_TIME) { |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 1623 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1624 | EventLog.writeEvent(EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME, |
| 1625 | userId, System.identityHashCode(this), shortComponentName, |
| 1626 | thisTime, totalTime); |
| 1627 | StringBuilder sb = service.mStringBuilder; |
| 1628 | sb.setLength(0); |
| 1629 | sb.append("Fully drawn "); |
| 1630 | sb.append(shortComponentName); |
| 1631 | sb.append(": "); |
| 1632 | TimeUtils.formatDuration(thisTime, sb); |
| 1633 | if (thisTime != totalTime) { |
| 1634 | sb.append(" (total "); |
| 1635 | TimeUtils.formatDuration(totalTime, sb); |
| 1636 | sb.append(")"); |
| 1637 | } |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1638 | Log.i(TAG, sb.toString()); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1639 | } |
| 1640 | if (totalTime > 0) { |
Adam Lesinski | 0debc9a | 2014-07-16 19:09:13 -0700 | [diff] [blame] | 1641 | //service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1642 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1643 | stack.mFullyDrawnStartTime = 0; |
| 1644 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1645 | fullyDrawnStartTime = 0; |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | private void reportLaunchTimeLocked(final long curTime) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1649 | final ActivityStack stack = getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1650 | if (stack == null) { |
| 1651 | return; |
| 1652 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1653 | final long thisTime = curTime - displayStartTime; |
| 1654 | final long totalTime = stack.mLaunchStartTime != 0 |
| 1655 | ? (curTime - stack.mLaunchStartTime) : thisTime; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 1656 | if (SHOW_ACTIVITY_START_TIME) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 1657 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1658 | EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME, |
| 1659 | userId, System.identityHashCode(this), shortComponentName, |
| 1660 | thisTime, totalTime); |
| 1661 | StringBuilder sb = service.mStringBuilder; |
| 1662 | sb.setLength(0); |
| 1663 | sb.append("Displayed "); |
| 1664 | sb.append(shortComponentName); |
| 1665 | sb.append(": "); |
| 1666 | TimeUtils.formatDuration(thisTime, sb); |
| 1667 | if (thisTime != totalTime) { |
| 1668 | sb.append(" (total "); |
| 1669 | TimeUtils.formatDuration(totalTime, sb); |
| 1670 | sb.append(")"); |
| 1671 | } |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1672 | Log.i(TAG, sb.toString()); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1673 | } |
| 1674 | mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime); |
| 1675 | if (totalTime > 0) { |
Adam Lesinski | 0debc9a | 2014-07-16 19:09:13 -0700 | [diff] [blame] | 1676 | //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1677 | } |
| 1678 | displayStartTime = 0; |
| 1679 | stack.mLaunchStartTime = 0; |
| 1680 | } |
| 1681 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1682 | @Override |
| 1683 | public void onWindowsDrawn() { |
| 1684 | synchronized (service) { |
| 1685 | mStackSupervisor.mActivityMetricsLogger.notifyWindowsDrawn(); |
| 1686 | if (displayStartTime != 0) { |
| 1687 | reportLaunchTimeLocked(SystemClock.uptimeMillis()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1688 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1689 | mStackSupervisor.sendWaitingVisibleReportLocked(this); |
| 1690 | startTime = 0; |
| 1691 | finishLaunchTickingLocked(); |
| 1692 | if (task != null) { |
| 1693 | task.hasBeenVisible = true; |
| 1694 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1695 | } |
| 1696 | } |
| 1697 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1698 | @Override |
| 1699 | public void onWindowsVisible() { |
| 1700 | synchronized (service) { |
| 1701 | mStackSupervisor.reportActivityVisibleLocked(this); |
| 1702 | if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this); |
| 1703 | if (!nowVisible) { |
| 1704 | nowVisible = true; |
| 1705 | lastVisibleTime = SystemClock.uptimeMillis(); |
| 1706 | if (!idle) { |
| 1707 | // Instead of doing the full stop routine here, let's just hide any activities |
| 1708 | // we now can, and let them stop when the normal idle happens. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1709 | mStackSupervisor.processStoppingActivitiesLocked(null /* idleActivity */, |
| 1710 | false /* remove */, true /* processPausingActivities */); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1711 | } else { |
| 1712 | // If this activity was already idle, then we now need to make sure we perform |
| 1713 | // the full stop of any activities that are waiting to do so. This is because |
| 1714 | // we won't do that while they are still waiting for this one to become visible. |
| 1715 | final int size = mStackSupervisor.mWaitingVisibleActivities.size(); |
| 1716 | if (size > 0) { |
| 1717 | for (int i = 0; i < size; i++) { |
| 1718 | ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i); |
| 1719 | if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "Was waiting for visible: " + r); |
| 1720 | } |
| 1721 | mStackSupervisor.mWaitingVisibleActivities.clear(); |
| 1722 | mStackSupervisor.scheduleIdleLocked(); |
| 1723 | } |
| 1724 | } |
| 1725 | service.scheduleAppGcsLocked(); |
| 1726 | } |
| 1727 | } |
| 1728 | } |
| 1729 | |
| 1730 | @Override |
| 1731 | public void onWindowsGone() { |
| 1732 | synchronized (service) { |
| 1733 | if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + this); |
| 1734 | nowVisible = false; |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | @Override |
| 1739 | public boolean keyDispatchingTimedOut(String reason) { |
| 1740 | ActivityRecord anrActivity; |
| 1741 | ProcessRecord anrApp; |
| 1742 | synchronized (service) { |
| 1743 | anrActivity = getWaitingHistoryRecordLocked(); |
| 1744 | anrApp = app; |
| 1745 | } |
| 1746 | return service.inputDispatchingTimedOut(anrApp, anrActivity, this, false, reason); |
| 1747 | } |
| 1748 | |
| 1749 | private ActivityRecord getWaitingHistoryRecordLocked() { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1750 | // First find the real culprit... if this activity is waiting for |
| 1751 | // another activity to start or has stopped, then the key dispatching |
| 1752 | // timeout should not be caused by this. |
Wale Ogunwale | 16a6279 | 2015-04-01 11:50:31 -0700 | [diff] [blame] | 1753 | if (mStackSupervisor.mWaitingVisibleActivities.contains(this) || stopped) { |
Craig Mautner | 8f2adcb | 2014-04-07 22:21:33 +0000 | [diff] [blame] | 1754 | final ActivityStack stack = mStackSupervisor.getFocusedStack(); |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1755 | // Try to use the one which is closest to top. |
| 1756 | ActivityRecord r = stack.mResumedActivity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1757 | if (r == null) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1758 | r = stack.mPausingActivity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1759 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1760 | if (r != null) { |
| 1761 | return r; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1762 | } |
| 1763 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1764 | return this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1765 | } |
| 1766 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1767 | /** Checks whether the activity should be shown for current user. */ |
| 1768 | public boolean okToShowLocked() { |
| 1769 | return (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0 |
| 1770 | || (mStackSupervisor.isCurrentProfileLocked(userId) |
| 1771 | && !service.mUserController.isUserStoppingOrShuttingDownLocked(userId)); |
| 1772 | } |
| 1773 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1774 | /** |
| 1775 | * This method will return true if the activity is either visible, is becoming visible, is |
| 1776 | * currently pausing, or is resumed. |
| 1777 | */ |
| 1778 | public boolean isInterestingToUserLocked() { |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1779 | return visible || nowVisible || state == ActivityState.PAUSING || |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1780 | state == ActivityState.RESUMED; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1781 | } |
| 1782 | |
Wale Ogunwale | 3e99736 | 2016-09-06 10:37:56 -0700 | [diff] [blame] | 1783 | void setSleeping(boolean _sleeping) { |
| 1784 | setSleeping(_sleeping, false); |
| 1785 | } |
| 1786 | |
| 1787 | void setSleeping(boolean _sleeping, boolean force) { |
| 1788 | if (!force && sleeping == _sleeping) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1789 | return; |
| 1790 | } |
| 1791 | if (app != null && app.thread != null) { |
| 1792 | try { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1793 | app.thread.scheduleSleeping(appToken, _sleeping); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1794 | if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) { |
| 1795 | mStackSupervisor.mGoingToSleepActivities.add(this); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1796 | } |
| 1797 | sleeping = _sleeping; |
| 1798 | } catch (RemoteException e) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1799 | Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1800 | } |
| 1801 | } |
| 1802 | } |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 1803 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1804 | static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1805 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1806 | if (r == null) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 1807 | return INVALID_TASK_ID; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1808 | } |
| 1809 | final TaskRecord task = r.task; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1810 | final int activityNdx = task.mActivities.indexOf(r); |
| 1811 | if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 1812 | return INVALID_TASK_ID; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1813 | } |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1814 | return task.taskId; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | static ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1818 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1819 | return (r != null) ? r.getStack().isInStackLocked(r) : null; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1820 | } |
| 1821 | |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1822 | static ActivityStack getStackLocked(IBinder token) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1823 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1824 | if (r != null) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1825 | return r.getStack(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1826 | } |
| 1827 | return null; |
| 1828 | } |
| 1829 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 1830 | /** |
| 1831 | * @return display id to which this record is attached, -1 if not attached. |
| 1832 | */ |
| 1833 | int getDisplayId() { |
| 1834 | final ActivityStack stack = getStack(); |
| 1835 | if (stack == null) { |
| 1836 | return -1; |
| 1837 | } |
| 1838 | return stack.mDisplayId; |
| 1839 | } |
| 1840 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 1841 | final boolean isDestroyable() { |
| 1842 | if (finishing || app == null || state == ActivityState.DESTROYING |
| 1843 | || state == ActivityState.DESTROYED) { |
| 1844 | // This would be redundant. |
| 1845 | return false; |
| 1846 | } |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1847 | final ActivityStack stack = getStack(); |
| 1848 | if (stack == null || this == stack.mResumedActivity || this == stack.mPausingActivity |
| 1849 | || !haveState || !stopped) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 1850 | // We're not ready for this kind of thing. |
| 1851 | return false; |
| 1852 | } |
| 1853 | if (visible) { |
| 1854 | // The user would notice this! |
| 1855 | return false; |
| 1856 | } |
| 1857 | return true; |
| 1858 | } |
| 1859 | |
Winson Chung | 3bad5cc0 | 2014-08-19 17:44:32 -0700 | [diff] [blame] | 1860 | private static String createImageFilename(long createTime, int taskId) { |
| 1861 | return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime + |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1862 | TaskPersister.IMAGE_EXTENSION; |
| 1863 | } |
| 1864 | |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1865 | void setTaskDescription(TaskDescription _taskDescription) { |
| 1866 | Bitmap icon; |
| 1867 | if (_taskDescription.getIconFilename() == null && |
| 1868 | (icon = _taskDescription.getIcon()) != null) { |
| 1869 | final String iconFilename = createImageFilename(createTime, task.taskId); |
Winson Chung | c8408b8 | 2017-01-25 17:58:56 -0800 | [diff] [blame] | 1870 | final File iconFile = new File(TaskPersister.getUserImagesDir(task.userId), |
| 1871 | iconFilename); |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 1872 | final String iconFilePath = iconFile.getAbsolutePath(); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 1873 | service.mRecentTasks.saveImage(icon, iconFilePath); |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 1874 | _taskDescription.setIconFilename(iconFilePath); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1875 | } |
| 1876 | taskDescription = _taskDescription; |
| 1877 | } |
| 1878 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1879 | void setVoiceSessionLocked(IVoiceInteractionSession session) { |
| 1880 | voiceSession = session; |
| 1881 | pendingVoiceInteractionStart = false; |
| 1882 | } |
| 1883 | |
| 1884 | void clearVoiceSessionLocked() { |
| 1885 | voiceSession = null; |
| 1886 | pendingVoiceInteractionStart = false; |
| 1887 | } |
| 1888 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 1889 | void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch) { |
Jorim Jaggi | 7017643 | 2017-01-18 12:52:13 +0100 | [diff] [blame] | 1890 | if (mWindowContainerController == null) { |
| 1891 | return; |
| 1892 | } |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1893 | final CompatibilityInfo compatInfo = |
| 1894 | service.compatibilityInfoForPackageLocked(info.applicationInfo); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1895 | final boolean shown = mWindowContainerController.addStartingWindow(packageName, theme, |
| 1896 | compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags, |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 1897 | prev != null ? prev.appToken : null, newTask, taskSwitch, isProcessRunning()); |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1898 | if (shown) { |
| 1899 | mStartingWindowState = STARTING_WINDOW_SHOWN; |
| 1900 | } |
| 1901 | } |
| 1902 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1903 | void removeOrphanedStartingWindow(boolean behindFullscreenActivity) { |
| 1904 | if (state == ActivityState.INITIALIZING |
| 1905 | && mStartingWindowState == STARTING_WINDOW_SHOWN |
| 1906 | && behindFullscreenActivity) { |
| 1907 | if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, "Found orphaned starting window " + this); |
| 1908 | mStartingWindowState = STARTING_WINDOW_REMOVED; |
| 1909 | mWindowContainerController.removeStartingWindow(); |
| 1910 | } |
| 1911 | } |
| 1912 | |
| 1913 | int getRequestedOrientation() { |
| 1914 | return mWindowContainerController.getOrientation(); |
| 1915 | } |
| 1916 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 1917 | void setRequestedOrientation(int requestedOrientation) { |
| 1918 | if (task != null && (!task.mFullscreen || !task.getStack().mFullscreen)) { |
| 1919 | // Fixed screen orientation isn't supported when activities aren't in full screen mode. |
| 1920 | return; |
| 1921 | } |
| 1922 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 1923 | final int displayId = getDisplayId(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1924 | final Configuration displayConfig = |
| 1925 | mStackSupervisor.getDisplayOverrideConfiguration(displayId); |
| 1926 | |
| 1927 | final Configuration config = mWindowContainerController.setOrientation(requestedOrientation, |
| 1928 | displayId, displayConfig, mayFreezeScreenLocked(app)); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 1929 | if (config != null) { |
| 1930 | frozenBeforeDestroy = true; |
| 1931 | if (!service.updateDisplayOverrideConfigurationLocked(config, this, |
| 1932 | false /* deferResume */, displayId)) { |
| 1933 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
| 1934 | } |
| 1935 | } |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 1936 | service.mTaskChangeNotificationController.notifyActivityRequestedOrientationChanged( |
| 1937 | task.taskId, requestedOrientation); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 1938 | } |
| 1939 | |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1940 | /** |
| 1941 | * Set the last reported global configuration to the client. Should be called whenever a new |
| 1942 | * global configuration is sent to the client for this activity. |
| 1943 | */ |
| 1944 | void setLastReportedGlobalConfiguration(@NonNull Configuration config) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1945 | mLastReportedConfiguration.setTo(config); |
| 1946 | } |
| 1947 | |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1948 | /** |
| 1949 | * Set the last reported merged override configuration to the client. Should be called whenever |
| 1950 | * a new merged configuration is sent to the client for this activity. |
| 1951 | */ |
| 1952 | void setLastReportedMergedOverrideConfiguration(@NonNull Configuration config) { |
| 1953 | mLastReportedOverrideConfiguration.setTo(config); |
| 1954 | } |
| 1955 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1956 | /** Call when override config was sent to the Window Manager to update internal records. */ |
| 1957 | void onOverrideConfigurationSent() { |
| 1958 | mLastReportedOverrideConfiguration.setTo(task.getMergedOverrideConfiguration()); |
| 1959 | } |
| 1960 | |
| 1961 | /** |
| 1962 | * Make sure the given activity matches the current configuration. Returns false if the activity |
| 1963 | * had to be destroyed. Returns true if the configuration is the same, or the activity will |
| 1964 | * remain running as-is for whatever reason. Ensures the HistoryRecord is updated with the |
| 1965 | * correct configuration and all other bookkeeping is handled. |
| 1966 | */ |
| 1967 | boolean ensureActivityConfigurationLocked(int globalChanges, boolean preserveWindow) { |
| 1968 | final ActivityStack stack = getStack(); |
| 1969 | if (stack.mConfigWillChange) { |
| 1970 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 1971 | "Skipping config check (will change): " + this); |
| 1972 | return true; |
| 1973 | } |
| 1974 | |
| 1975 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 1976 | "Ensuring correct configuration: " + this); |
| 1977 | |
| 1978 | // Short circuit: if the two configurations are equal (the common case), then there is |
| 1979 | // nothing to do. |
| 1980 | final Configuration newGlobalConfig = service.getGlobalConfiguration(); |
| 1981 | final Configuration newTaskMergedOverrideConfig = task.getMergedOverrideConfiguration(); |
| 1982 | if (mLastReportedConfiguration.equals(newGlobalConfig) |
| 1983 | && mLastReportedOverrideConfiguration.equals(newTaskMergedOverrideConfig) |
| 1984 | && !forceNewConfig) { |
| 1985 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 1986 | "Configuration unchanged in " + this); |
| 1987 | return true; |
| 1988 | } |
| 1989 | |
| 1990 | // We don't worry about activities that are finishing. |
| 1991 | if (finishing) { |
| 1992 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 1993 | "Configuration doesn't matter in finishing " + this); |
| 1994 | stopFreezingScreenLocked(false); |
| 1995 | return true; |
| 1996 | } |
| 1997 | |
| 1998 | // Okay we now are going to make this activity have the new config. |
| 1999 | // But then we need to figure out how it needs to deal with that. |
| 2000 | mTmpGlobalConfig.setTo(mLastReportedConfiguration); |
| 2001 | mTmpTaskConfig.setTo(mLastReportedOverrideConfiguration); |
| 2002 | mLastReportedConfiguration.setTo(newGlobalConfig); |
| 2003 | mLastReportedOverrideConfiguration.setTo(newTaskMergedOverrideConfig); |
| 2004 | |
| 2005 | int taskChanges = getTaskConfigurationChanges(this, newTaskMergedOverrideConfig, |
| 2006 | mTmpTaskConfig); |
| 2007 | final int changes = mTmpGlobalConfig.diff(newGlobalConfig) | taskChanges; |
| 2008 | if (changes == 0 && !forceNewConfig) { |
| 2009 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2010 | "Configuration no differences in " + this); |
| 2011 | // There are no significant differences, so we won't relaunch but should still deliver |
| 2012 | // the new configuration to the client process. |
| 2013 | scheduleConfigurationChanged(newTaskMergedOverrideConfig, true); |
| 2014 | return true; |
| 2015 | } |
| 2016 | |
| 2017 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2018 | "Configuration changes for " + this + " ; taskChanges=" |
| 2019 | + Configuration.configurationDiffToString(taskChanges) + ", allChanges=" |
| 2020 | + Configuration.configurationDiffToString(changes)); |
| 2021 | |
| 2022 | // If the activity isn't currently running, just leave the new configuration and it will |
| 2023 | // pick that up next time it starts. |
| 2024 | if (app == null || app.thread == null) { |
| 2025 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2026 | "Configuration doesn't matter not running " + this); |
| 2027 | stopFreezingScreenLocked(false); |
| 2028 | forceNewConfig = false; |
| 2029 | return true; |
| 2030 | } |
| 2031 | |
| 2032 | // Figure out how to handle the changes between the configurations. |
| 2033 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2034 | "Checking to restart " + info.name + ": changed=0x" |
| 2035 | + Integer.toHexString(changes) + ", handles=0x" |
| 2036 | + Integer.toHexString(info.getRealConfigChanged()) |
| 2037 | + ", newGlobalConfig=" + newGlobalConfig |
| 2038 | + ", newTaskMergedOverrideConfig=" + newTaskMergedOverrideConfig); |
| 2039 | |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 2040 | if (shouldRelaunchLocked(changes, newGlobalConfig, newTaskMergedOverrideConfig) |
| 2041 | || forceNewConfig) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2042 | // Aha, the activity isn't handling the change, so DIE DIE DIE. |
| 2043 | configChangeFlags |= changes; |
| 2044 | startFreezingScreenLocked(app, globalChanges); |
| 2045 | forceNewConfig = false; |
| 2046 | preserveWindow &= isResizeOnlyChange(changes); |
| 2047 | if (app == null || app.thread == null) { |
| 2048 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2049 | "Config is destroying non-running " + this); |
| 2050 | stack.destroyActivityLocked(this, true, "config"); |
| 2051 | } else if (state == ActivityState.PAUSING) { |
| 2052 | // A little annoying: we are waiting for this activity to finish pausing. Let's not |
| 2053 | // do anything now, but just flag that it needs to be restarted when done pausing. |
| 2054 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2055 | "Config is skipping already pausing " + this); |
| 2056 | deferRelaunchUntilPaused = true; |
| 2057 | preserveWindowOnDeferredRelaunch = preserveWindow; |
| 2058 | return true; |
| 2059 | } else if (state == ActivityState.RESUMED) { |
| 2060 | // Try to optimize this case: the configuration is changing and we need to restart |
| 2061 | // the top, resumed activity. Instead of doing the normal handshaking, just say |
| 2062 | // "restart!". |
| 2063 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2064 | "Config is relaunching resumed " + this); |
| 2065 | |
| 2066 | if (DEBUG_STATES && !visible) { |
| 2067 | Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + this |
| 2068 | + " called by " + Debug.getCallers(4)); |
| 2069 | } |
| 2070 | |
| 2071 | relaunchActivityLocked(true /* andResume */, preserveWindow); |
| 2072 | } else { |
| 2073 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2074 | "Config is relaunching non-resumed " + this); |
| 2075 | relaunchActivityLocked(false /* andResume */, preserveWindow); |
| 2076 | } |
| 2077 | |
| 2078 | // All done... tell the caller we weren't able to keep this activity around. |
| 2079 | return false; |
| 2080 | } |
| 2081 | |
| 2082 | // Default case: the activity can handle this new configuration, so hand it over. |
| 2083 | // NOTE: We only forward the task override configuration as the system level configuration |
| 2084 | // changes is always sent to all processes when they happen so it can just use whatever |
| 2085 | // system level configuration it last got. |
| 2086 | scheduleConfigurationChanged(newTaskMergedOverrideConfig, true); |
| 2087 | stopFreezingScreenLocked(false); |
| 2088 | |
| 2089 | return true; |
| 2090 | } |
| 2091 | |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 2092 | /** |
| 2093 | * When assessing a configuration change, decide if the changes flags and the new configurations |
| 2094 | * should cause the Activity to relaunch. |
| 2095 | */ |
| 2096 | private boolean shouldRelaunchLocked(int changes, Configuration newGlobalConfig, |
| 2097 | Configuration newTaskMergedOverrideConfig) { |
| 2098 | int configChanged = info.getRealConfigChanged(); |
| 2099 | |
| 2100 | // Override for apps targeting pre-O sdks |
| 2101 | // If a device is in VR mode, and we're transitioning into VR ui mode, add ignore ui mode |
| 2102 | // to the config change. |
| 2103 | // For O and later, apps will be required to add configChanges="uimode" to their manifest. |
| 2104 | if (appInfo.targetSdkVersion < O |
| 2105 | && requestedVrComponent != null |
| 2106 | && (isInVrUiMode(newGlobalConfig) || isInVrUiMode(newTaskMergedOverrideConfig))) { |
| 2107 | configChanged |= CONFIG_UI_MODE; |
| 2108 | } |
| 2109 | |
| 2110 | return (changes&(~configChanged)) != 0; |
| 2111 | } |
| 2112 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2113 | private static int getTaskConfigurationChanges(ActivityRecord record, Configuration taskConfig, |
| 2114 | Configuration oldTaskOverride) { |
| 2115 | // If we went from full-screen to non-full-screen, make sure to use the correct |
| 2116 | // configuration task diff, so the diff stays as small as possible. |
| 2117 | if (Configuration.EMPTY.equals(oldTaskOverride) |
| 2118 | && !Configuration.EMPTY.equals(taskConfig)) { |
| 2119 | oldTaskOverride = record.task.extractOverrideConfig(record.mLastReportedConfiguration); |
| 2120 | } |
| 2121 | |
| 2122 | // Conversely, do the same when going the other direction. |
| 2123 | if (Configuration.EMPTY.equals(taskConfig) |
| 2124 | && !Configuration.EMPTY.equals(oldTaskOverride)) { |
| 2125 | taskConfig = record.task.extractOverrideConfig(record.mLastReportedConfiguration); |
| 2126 | } |
| 2127 | |
| 2128 | // Determine what has changed. May be nothing, if this is a config that has come back from |
| 2129 | // the app after going idle. In that case we just want to leave the official config object |
| 2130 | // now in the activity and do nothing else. |
| 2131 | int taskChanges = oldTaskOverride.diff(taskConfig, true /* skipUndefined */); |
| 2132 | // We don't want to use size changes if they don't cross boundaries that are important to |
| 2133 | // the app. |
| 2134 | if ((taskChanges & CONFIG_SCREEN_SIZE) != 0) { |
| 2135 | final boolean crosses = record.crossesHorizontalSizeThreshold( |
| 2136 | oldTaskOverride.screenWidthDp, taskConfig.screenWidthDp) |
| 2137 | || record.crossesVerticalSizeThreshold( |
| 2138 | oldTaskOverride.screenHeightDp, taskConfig.screenHeightDp); |
| 2139 | if (!crosses) { |
| 2140 | taskChanges &= ~CONFIG_SCREEN_SIZE; |
| 2141 | } |
| 2142 | } |
| 2143 | if ((taskChanges & CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
| 2144 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 2145 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
| 2146 | if (!record.crossesSmallestSizeThreshold(oldSmallest, newSmallest)) { |
| 2147 | taskChanges &= ~CONFIG_SMALLEST_SCREEN_SIZE; |
| 2148 | } |
| 2149 | } |
| 2150 | return taskChanges; |
| 2151 | } |
| 2152 | |
| 2153 | private static boolean isResizeOnlyChange(int change) { |
| 2154 | return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION |
| 2155 | | CONFIG_SCREEN_LAYOUT)) == 0; |
| 2156 | } |
| 2157 | |
| 2158 | void relaunchActivityLocked(boolean andResume, boolean preserveWindow) { |
| 2159 | if (service.mSuppressResizeConfigChanges && preserveWindow) { |
| 2160 | configChangeFlags = 0; |
| 2161 | return; |
| 2162 | } |
| 2163 | |
| 2164 | List<ResultInfo> pendingResults = null; |
| 2165 | List<ReferrerIntent> pendingNewIntents = null; |
| 2166 | if (andResume) { |
| 2167 | pendingResults = results; |
| 2168 | pendingNewIntents = newIntents; |
| 2169 | } |
| 2170 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2171 | "Relaunching: " + this + " with results=" + pendingResults |
| 2172 | + " newIntents=" + pendingNewIntents + " andResume=" + andResume |
| 2173 | + " preserveWindow=" + preserveWindow); |
| 2174 | EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY |
| 2175 | : EventLogTags.AM_RELAUNCH_ACTIVITY, userId, System.identityHashCode(this), |
| 2176 | task.taskId, shortComponentName); |
| 2177 | |
| 2178 | startFreezingScreenLocked(app, 0); |
| 2179 | |
| 2180 | mStackSupervisor.removeChildActivityContainers(this); |
| 2181 | |
| 2182 | try { |
| 2183 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, |
| 2184 | "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + this |
| 2185 | + " callers=" + Debug.getCallers(6)); |
| 2186 | forceNewConfig = false; |
| 2187 | mStackSupervisor.activityRelaunchingLocked(this); |
| 2188 | app.thread.scheduleRelaunchActivity(appToken, pendingResults, pendingNewIntents, |
| 2189 | configChangeFlags, !andResume, |
| 2190 | new Configuration(service.getGlobalConfiguration()), |
| 2191 | new Configuration(task.getMergedOverrideConfiguration()), preserveWindow); |
| 2192 | // Note: don't need to call pauseIfSleepingLocked() here, because the caller will only |
| 2193 | // pass in 'andResume' if this activity is currently resumed, which implies we aren't |
| 2194 | // sleeping. |
| 2195 | } catch (RemoteException e) { |
| 2196 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e); |
| 2197 | } |
| 2198 | |
| 2199 | if (andResume) { |
| 2200 | if (DEBUG_STATES) { |
| 2201 | Slog.d(TAG_STATES, "Resumed after relaunch " + this); |
| 2202 | } |
| 2203 | results = null; |
| 2204 | newIntents = null; |
| 2205 | service.showUnsupportedZoomDialogIfNeededLocked(this); |
| 2206 | service.showAskCompatModeDialogLocked(this); |
| 2207 | } else { |
| 2208 | service.mHandler.removeMessages(ActivityStack.PAUSE_TIMEOUT_MSG, this); |
| 2209 | state = ActivityState.PAUSED; |
| 2210 | // if the app is relaunched when it's stopped, and we're not resuming, |
| 2211 | // put it back into stopped state. |
| 2212 | if (stopped) { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 2213 | getStack().addToStopping(this, true /* scheduleIdle */, false /* idleDelayed */); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2214 | } |
| 2215 | } |
| 2216 | |
| 2217 | configChangeFlags = 0; |
| 2218 | deferRelaunchUntilPaused = false; |
| 2219 | preserveWindowOnDeferredRelaunch = false; |
| 2220 | } |
| 2221 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2222 | boolean isProcessRunning() { |
| 2223 | ProcessRecord proc = app; |
| 2224 | if (proc == null) { |
| 2225 | proc = service.mProcessNames.get(processName, info.applicationInfo.uid); |
| 2226 | } |
| 2227 | return proc != null && proc.thread != null; |
| 2228 | } |
| 2229 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2230 | void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException { |
| 2231 | out.attribute(null, ATTR_ID, String.valueOf(createTime)); |
| 2232 | out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid)); |
| 2233 | if (launchedFromPackage != null) { |
| 2234 | out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage); |
| 2235 | } |
| 2236 | if (resolvedType != null) { |
| 2237 | out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType); |
| 2238 | } |
| 2239 | out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified)); |
| 2240 | out.attribute(null, ATTR_USERID, String.valueOf(userId)); |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 2241 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2242 | if (taskDescription != null) { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 2243 | taskDescription.saveToXml(out); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | out.startTag(null, TAG_INTENT); |
| 2247 | intent.saveToXml(out); |
| 2248 | out.endTag(null, TAG_INTENT); |
| 2249 | |
| 2250 | if (isPersistable() && persistentState != null) { |
| 2251 | out.startTag(null, TAG_PERSISTABLEBUNDLE); |
| 2252 | persistentState.saveToXml(out); |
| 2253 | out.endTag(null, TAG_PERSISTABLEBUNDLE); |
| 2254 | } |
| 2255 | } |
| 2256 | |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 2257 | static ActivityRecord restoreFromXml(XmlPullParser in, |
| 2258 | ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2259 | Intent intent = null; |
| 2260 | PersistableBundle persistentState = null; |
| 2261 | int launchedFromUid = 0; |
| 2262 | String launchedFromPackage = null; |
| 2263 | String resolvedType = null; |
| 2264 | boolean componentSpecified = false; |
| 2265 | int userId = 0; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2266 | long createTime = -1; |
| 2267 | final int outerDepth = in.getDepth(); |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 2268 | TaskDescription taskDescription = new TaskDescription(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2269 | |
| 2270 | for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) { |
| 2271 | final String attrName = in.getAttributeName(attrNdx); |
| 2272 | final String attrValue = in.getAttributeValue(attrNdx); |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 2273 | if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 2274 | "ActivityRecord: attribute name=" + attrName + " value=" + attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2275 | if (ATTR_ID.equals(attrName)) { |
Tobias Thierer | 28532d0 | 2016-04-21 14:52:10 +0100 | [diff] [blame] | 2276 | createTime = Long.parseLong(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2277 | } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 2278 | launchedFromUid = Integer.parseInt(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2279 | } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) { |
| 2280 | launchedFromPackage = attrValue; |
| 2281 | } else if (ATTR_RESOLVEDTYPE.equals(attrName)) { |
| 2282 | resolvedType = attrValue; |
| 2283 | } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) { |
Tobias Thierer | b0800dc | 2016-04-21 17:51:41 +0100 | [diff] [blame] | 2284 | componentSpecified = Boolean.parseBoolean(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2285 | } else if (ATTR_USERID.equals(attrName)) { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 2286 | userId = Integer.parseInt(attrValue); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 2287 | } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) { |
| 2288 | taskDescription.restoreFromXml(attrName, attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2289 | } else { |
| 2290 | Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName); |
| 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | int event; |
| 2295 | while (((event = in.next()) != XmlPullParser.END_DOCUMENT) && |
Ben Kwa | 8814cf4 | 2015-07-08 10:54:56 -0700 | [diff] [blame] | 2296 | (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2297 | if (event == XmlPullParser.START_TAG) { |
| 2298 | final String name = in.getName(); |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 2299 | if (TaskPersister.DEBUG) |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 2300 | Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2301 | if (TAG_INTENT.equals(name)) { |
| 2302 | intent = Intent.restoreFromXml(in); |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 2303 | if (TaskPersister.DEBUG) |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 2304 | Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2305 | } else if (TAG_PERSISTABLEBUNDLE.equals(name)) { |
| 2306 | persistentState = PersistableBundle.restoreFromXml(in); |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 2307 | if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2308 | "ActivityRecord: persistentState=" + persistentState); |
| 2309 | } else { |
| 2310 | Slog.w(TAG, "restoreActivity: unexpected name=" + name); |
| 2311 | XmlUtils.skipCurrentTag(in); |
| 2312 | } |
| 2313 | } |
| 2314 | } |
| 2315 | |
| 2316 | if (intent == null) { |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 2317 | throw new XmlPullParserException("restoreActivity error intent=" + intent); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | final ActivityManagerService service = stackSupervisor.mService; |
| 2321 | final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 2322 | userId); |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 2323 | if (aInfo == null) { |
Craig Mautner | 77b0426 | 2014-06-27 15:22:12 -0700 | [diff] [blame] | 2324 | throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent + |
| 2325 | " resolvedType=" + resolvedType); |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 2326 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2327 | final ActivityRecord r = new ActivityRecord(service, null /* caller */, |
| 2328 | 0 /* launchedFromPid */, launchedFromUid, launchedFromPackage, intent, resolvedType, |
| 2329 | aInfo, service.getConfiguration(), null /* resultTo */, null /* resultWho */, |
| 2330 | 0 /* reqCode */, componentSpecified, false /* rootVoiceInteraction */, |
| 2331 | stackSupervisor, null /* container */, null /* options */, null /* sourceRecord */); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2332 | |
| 2333 | r.persistentState = persistentState; |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 2334 | r.taskDescription = taskDescription; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2335 | r.createTime = createTime; |
| 2336 | |
| 2337 | return r; |
| 2338 | } |
| 2339 | |
| 2340 | private static String activityTypeToString(int type) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 2341 | switch (type) { |
| 2342 | case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE"; |
| 2343 | case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE"; |
| 2344 | case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE"; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame^] | 2345 | case ASSISTANT_ACTIVITY_TYPE: return "ASSISTANT_ACTIVITY_TYPE"; |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 2346 | default: return Integer.toString(type); |
| 2347 | } |
| 2348 | } |
| 2349 | |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 2350 | private static boolean isInVrUiMode(Configuration config) { |
| 2351 | return (config.uiMode & Configuration.UI_MODE_TYPE_MASK) == UI_MODE_TYPE_VR_HEADSET; |
| 2352 | } |
| 2353 | |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 2354 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2355 | public String toString() { |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 2356 | if (stringName != null) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 2357 | return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) + |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2358 | (finishing ? " f}" : "}"); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 2359 | } |
| 2360 | StringBuilder sb = new StringBuilder(128); |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 2361 | sb.append("ActivityRecord{"); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 2362 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 2363 | sb.append(" u"); |
| 2364 | sb.append(userId); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 2365 | sb.append(' '); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2366 | sb.append(intent.getComponent().flattenToShortString()); |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 2367 | stringName = sb.toString(); |
| 2368 | return toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2369 | } |
| 2370 | } |