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 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Winson Chung | bb34880 | 2017-01-30 12:01:45 -0800 | [diff] [blame] | 19 | import static android.app.ActivityManager.LOCK_TASK_MODE_NONE; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 20 | import static android.app.ActivityManager.TaskDescription.ATTR_TASKDESCRIPTION_PREFIX; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 21 | import static android.app.ActivityOptions.ANIM_CLIP_REVEAL; |
| 22 | import static android.app.ActivityOptions.ANIM_CUSTOM; |
| 23 | import static android.app.ActivityOptions.ANIM_NONE; |
| 24 | import static android.app.ActivityOptions.ANIM_OPEN_CROSS_PROFILE_APPS; |
| 25 | import static android.app.ActivityOptions.ANIM_REMOTE_ANIMATION; |
| 26 | import static android.app.ActivityOptions.ANIM_SCALE_UP; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 27 | import static android.app.ActivityOptions.ANIM_SCENE_TRANSITION; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 28 | import static android.app.ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN; |
| 29 | import static android.app.ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP; |
| 30 | import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN; |
| 31 | import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_UP; |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 32 | import static android.app.ActivityTaskManager.INVALID_STACK_ID; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 33 | import static android.app.ActivityTaskManager.INVALID_TASK_ID; |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 34 | import static android.app.AppOpsManager.MODE_ALLOWED; |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 35 | import static android.app.AppOpsManager.OP_PICTURE_IN_PICTURE; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 36 | import static android.app.WaitResult.INVALID_DELAY; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 37 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; |
| 38 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
| 39 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 40 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
| 41 | import static android.app.WindowConfiguration.activityTypeToString; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 42 | import static android.content.Intent.ACTION_MAIN; |
| 43 | import static android.content.Intent.CATEGORY_HOME; |
| 44 | import static android.content.Intent.CATEGORY_LAUNCHER; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 45 | import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 46 | import static android.content.Intent.FLAG_ACTIVITY_NO_HISTORY; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 47 | import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION; |
| 48 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT; |
| 49 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE; |
| 50 | import static android.content.pm.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 51 | import static android.content.pm.ActivityInfo.CONFIG_UI_MODE; |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 52 | import static android.content.pm.ActivityInfo.CONFIG_WINDOW_CONFIGURATION; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 53 | import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 54 | import static android.content.pm.ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 55 | import static android.content.pm.ActivityInfo.FLAG_IMMERSIVE; |
| 56 | import static android.content.pm.ActivityInfo.FLAG_MULTIPROCESS; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 57 | import static android.content.pm.ActivityInfo.FLAG_NO_HISTORY; |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 58 | import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 59 | import static android.content.pm.ActivityInfo.FLAG_SHOW_WHEN_LOCKED; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 60 | import static android.content.pm.ActivityInfo.FLAG_STATE_NOT_NEEDED; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 61 | import static android.content.pm.ActivityInfo.FLAG_TURN_SCREEN_ON; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 62 | import static android.content.pm.ActivityInfo.LAUNCH_MULTIPLE; |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 63 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE; |
| 64 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 65 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP; |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 66 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS; |
| 67 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT; |
| 68 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED; |
| 69 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 70 | import static android.content.pm.ActivityInfo.PERSIST_ACROSS_REBOOTS; |
| 71 | import static android.content.pm.ActivityInfo.PERSIST_ROOT_ONLY; |
Wale Ogunwale | df241e9 | 2016-10-13 15:14:21 -0700 | [diff] [blame] | 72 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE; |
Jorim Jaggi | cd13d33 | 2016-04-27 15:40:20 -0700 | [diff] [blame] | 73 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE; |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 74 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
Wale Ogunwale | df241e9 | 2016-10-13 15:14:21 -0700 | [diff] [blame] | 75 | import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 76 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | d4b1d1e | 2017-04-10 06:35:59 -0700 | [diff] [blame] | 77 | import static android.content.pm.ActivityInfo.isFixedOrientationLandscape; |
| 78 | import static android.content.pm.ActivityInfo.isFixedOrientationPortrait; |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 79 | import static android.content.res.Configuration.EMPTY; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 80 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
| 81 | import static android.content.res.Configuration.ORIENTATION_PORTRAIT; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 82 | import static android.content.res.Configuration.UI_MODE_TYPE_MASK; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 83 | import static android.content.res.Configuration.UI_MODE_TYPE_VR_HEADSET; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 84 | import static android.os.Build.VERSION_CODES.HONEYCOMB; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 85 | import static android.os.Build.VERSION_CODES.O; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 86 | import static android.os.Process.SYSTEM_UID; |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 87 | import static android.view.Display.INVALID_DISPLAY; |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 88 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_LEFT; |
| 89 | |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 90 | import static com.android.server.am.ActivityRecordProto.CONFIGURATION_CONTAINER; |
| 91 | import static com.android.server.am.ActivityRecordProto.FRONT_OF_TASK; |
| 92 | import static com.android.server.am.ActivityRecordProto.IDENTIFIER; |
| 93 | import static com.android.server.am.ActivityRecordProto.PROC_ID; |
| 94 | import static com.android.server.am.ActivityRecordProto.STATE; |
| 95 | import static com.android.server.am.ActivityRecordProto.TRANSLUCENT; |
| 96 | import static com.android.server.am.ActivityRecordProto.VISIBLE; |
| 97 | import static com.android.server.am.EventLogTags.AM_RELAUNCH_ACTIVITY; |
| 98 | import static com.android.server.am.EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY; |
| 99 | import static com.android.server.wm.ActivityStack.ActivityState.INITIALIZING; |
| 100 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; |
| 101 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; |
| 102 | import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; |
| 103 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; |
| 104 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPING; |
| 105 | import static com.android.server.wm.ActivityStack.LAUNCH_TICK; |
| 106 | import static com.android.server.wm.ActivityStack.LAUNCH_TICK_MSG; |
| 107 | import static com.android.server.wm.ActivityStack.PAUSE_TIMEOUT_MSG; |
| 108 | import static com.android.server.wm.ActivityStack.STOP_TIMEOUT_MSG; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 109 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CONFIGURATION; |
| 110 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_FOCUS; |
| 111 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SAVED_STATE; |
| 112 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STATES; |
| 113 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH; |
| 114 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_VISIBILITY; |
| 115 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONFIGURATION; |
| 116 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_FOCUS; |
| 117 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SAVED_STATE; |
| 118 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STATES; |
| 119 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SWITCH; |
| 120 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_VISIBILITY; |
| 121 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 122 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 123 | import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_FREE_RESIZE; |
| 124 | import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_NONE; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 125 | import static com.android.server.wm.ActivityTaskManagerService |
| 126 | .RELAUNCH_REASON_WINDOWING_MODE_RESIZE; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 127 | import static com.android.server.wm.IdentifierProto.HASH_CODE; |
| 128 | import static com.android.server.wm.IdentifierProto.TITLE; |
| 129 | import static com.android.server.wm.IdentifierProto.USER_ID; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 130 | import static com.android.server.wm.TaskPersister.DEBUG; |
| 131 | import static com.android.server.wm.TaskPersister.IMAGE_EXTENSION; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 132 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 133 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
| 134 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW; |
| 135 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT; |
| 136 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 137 | |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 138 | import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT; |
| 139 | import static org.xmlpull.v1.XmlPullParser.END_TAG; |
| 140 | import static org.xmlpull.v1.XmlPullParser.START_TAG; |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 141 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 142 | import android.annotation.NonNull; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 143 | import android.app.ActivityManager.TaskDescription; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 144 | import android.app.ActivityOptions; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 145 | import android.app.PendingIntent; |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 146 | import android.app.PictureInPictureParams; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 147 | import android.app.ResultInfo; |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 148 | import android.app.servertransaction.ActivityConfigurationChangeItem; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 149 | import android.app.servertransaction.ActivityLifecycleItem; |
| 150 | import android.app.servertransaction.ActivityRelaunchItem; |
| 151 | import android.app.servertransaction.ClientTransaction; |
| 152 | import android.app.servertransaction.ClientTransactionItem; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 153 | import android.app.servertransaction.MoveToDisplayItem; |
| 154 | import android.app.servertransaction.MultiWindowModeChangeItem; |
| 155 | import android.app.servertransaction.NewIntentItem; |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 156 | import android.app.servertransaction.PauseActivityItem; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 157 | import android.app.servertransaction.PipModeChangeItem; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 158 | import android.app.servertransaction.ResumeActivityItem; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 159 | import android.app.servertransaction.WindowVisibilityItem; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | import android.content.ComponentName; |
| 161 | import android.content.Intent; |
| 162 | import android.content.pm.ActivityInfo; |
| 163 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 164 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | import android.content.res.Configuration; |
| 166 | import android.graphics.Bitmap; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 167 | import android.graphics.GraphicBuffer; |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 168 | import android.graphics.Rect; |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 169 | import android.os.Binder; |
Bryce Lee | 3979159 | 2017-04-26 09:29:12 -0700 | [diff] [blame] | 170 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | import android.os.Bundle; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 172 | import android.os.Debug; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 173 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | import android.os.Message; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 175 | import android.os.PersistableBundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | import android.os.Process; |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 177 | import android.os.RemoteException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | import android.os.SystemClock; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 179 | import android.os.UserHandle; |
Bryce Lee | 8558ec7 | 2017-08-17 15:37:26 -0700 | [diff] [blame] | 180 | import android.os.storage.StorageManager; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 181 | import android.service.voice.IVoiceInteractionSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | import android.util.EventLog; |
| 183 | import android.util.Log; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 184 | import android.util.MergedConfiguration; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 185 | import android.util.Slog; |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 186 | import android.util.TimeUtils; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 187 | import android.util.proto.ProtoOutputStream; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 188 | import android.view.AppTransitionAnimationSpec; |
| 189 | import android.view.IAppTransitionAnimationSpecsFuture; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | import android.view.IApplicationToken; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 191 | import android.view.RemoteAnimationDefinition; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 192 | import android.view.WindowManager.LayoutParams; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 193 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 194 | import com.android.internal.R; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 195 | import com.android.internal.annotations.VisibleForTesting; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 196 | import com.android.internal.app.ResolverActivity; |
| 197 | import com.android.internal.content.ReferrerIntent; |
| 198 | import com.android.internal.util.XmlUtils; |
| 199 | import com.android.server.AttributeCache; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 200 | import com.android.server.AttributeCache.Entry; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 201 | import com.android.server.am.AppTimeTracker; |
| 202 | import com.android.server.am.PendingIntentRecord; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 203 | import com.android.server.uri.UriPermissionOwner; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 204 | import com.android.server.wm.ActivityMetricsLogger.WindowingModeTransitionInfoSnapshot; |
| 205 | import com.android.server.wm.ActivityStack.ActivityState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 207 | import org.xmlpull.v1.XmlPullParser; |
| 208 | import org.xmlpull.v1.XmlPullParserException; |
| 209 | import org.xmlpull.v1.XmlSerializer; |
| 210 | |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 211 | import java.io.File; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 212 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | import java.io.PrintWriter; |
| 214 | import java.lang.ref.WeakReference; |
| 215 | import java.util.ArrayList; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 216 | import java.util.Arrays; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | import java.util.HashSet; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 218 | import java.util.List; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 219 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | |
| 221 | /** |
| 222 | * An entry in the history stack, representing an activity. |
| 223 | */ |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 224 | final class ActivityRecord extends ConfigurationContainer { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 225 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityRecord" : TAG_ATM; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 226 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
| 227 | private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 228 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 229 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 230 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 231 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
Winson Chung | 16e185e | 2017-11-07 08:30:54 -0800 | [diff] [blame] | 232 | // TODO(b/67864419): Remove once recents component is overridden |
| 233 | private static final String LEGACY_RECENTS_PACKAGE_NAME = "com.android.systemui.recents"; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 234 | |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 235 | private static final boolean SHOW_ACTIVITY_START_TIME = true; |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 236 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 237 | private static final String ATTR_ID = "id"; |
| 238 | private static final String TAG_INTENT = "intent"; |
| 239 | private static final String ATTR_USERID = "user_id"; |
| 240 | private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle"; |
| 241 | private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid"; |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 242 | private static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 243 | private static final String ATTR_RESOLVEDTYPE = "resolved_type"; |
| 244 | private static final String ATTR_COMPONENTSPECIFIED = "component_specified"; |
Dianne Hackborn | 337abb3 | 2014-09-24 12:44:29 -0700 | [diff] [blame] | 245 | static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 246 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 247 | final ActivityTaskManagerService mAtmService; // owner |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 248 | final IApplicationToken.Stub appToken; // window manager token |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 249 | // TODO: Remove after unification |
| 250 | AppWindowToken mAppWindowToken; |
| 251 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | final ActivityInfo info; // all about me |
Philip P. Moltmann | cff8f0f | 2018-03-27 12:51:51 -0700 | [diff] [blame] | 253 | // TODO: This is duplicated state already contained in info.applicationInfo - remove |
| 254 | ApplicationInfo appInfo; // information about activity's app |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 255 | final int launchedFromPid; // always the pid who started the activity. |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 256 | final int launchedFromUid; // always the uid who started the activity. |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 257 | final String launchedFromPackage; // always the package who started the activity. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 258 | final int mUserId; // Which user is this running for? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | final Intent intent; // the original intent that generated us |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 260 | final ComponentName mActivityComponent; // the intent component, or target of an alias. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | final String shortComponentName; // the short component name of the intent |
| 262 | final String resolvedType; // as per original caller; |
| 263 | final String packageName; // the package implementing intent's component |
| 264 | final String processName; // process where this component wants to run |
| 265 | final String taskAffinity; // as per ActivityInfo.taskAffinity |
| 266 | final boolean stateNotNeeded; // As per ActivityInfo.flags |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 267 | boolean fullscreen; // The activity is opaque and fills the entire space of this task. |
| 268 | // TODO: See if it possible to combine this with the fullscreen field. |
| 269 | final boolean hasWallpaper; // Has a wallpaper window as a background. |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 270 | final boolean noDisplay; // activity is not displayed? |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 271 | private final boolean componentSpecified; // did caller specify an explicit component? |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 272 | final boolean rootVoiceInteraction; // was this the root activity of a voice interaction? |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 273 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 274 | private CharSequence nonLocalizedLabel; // the label information from the package mgr. |
| 275 | private int labelRes; // the label information from the package mgr. |
| 276 | private int icon; // resource identifier of activity's icon. |
| 277 | private int logo; // resource identifier of activity's logo. |
| 278 | private int theme; // resource identifier of activity's theme. |
| 279 | private int realTheme; // actual theme resource we will use, never 0. |
| 280 | private int windowFlags; // custom window flags for preview window. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 281 | private TaskRecord task; // the task this is in. |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 282 | private long createTime = System.currentTimeMillis(); |
Dianne Hackborn | 5068560 | 2011-12-01 12:23:37 -0800 | [diff] [blame] | 283 | long lastVisibleTime; // last time this activity became visible |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 284 | 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] | 285 | long pauseTime; // last time we started pausing the activity |
| 286 | long launchTickTime; // base time for launch tick messages |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 287 | // Last configuration reported to the activity in the client process. |
| 288 | private MergedConfiguration mLastReportedConfiguration; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 289 | private int mLastReportedDisplayId; |
Winson Chung | 609e1e9 | 2017-05-08 10:52:12 -0700 | [diff] [blame] | 290 | private boolean mLastReportedMultiWindowMode; |
| 291 | private boolean mLastReportedPictureInPictureMode; |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 292 | CompatibilityInfo compat;// last used compatibility mode |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 293 | 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] | 294 | final String resultWho; // additional identifier for use by resultTo. |
| 295 | final int requestCode; // code given by requester (resultTo) |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 296 | ArrayList<ResultInfo> results; // pending ActivityResult objs we have received |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 298 | ArrayList<ReferrerIntent> newIntents; // any pending new intents for single-top mode |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 299 | ActivityOptions pendingOptions; // most recently given options |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 300 | ActivityOptions returningOptions; // options that are coming back via convertToTranslucent |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 301 | AppTimeTracker appTimeTracker; // set if we are tracking the time in this app/task/activity |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 302 | ActivityServiceConnectionsHolder mServiceConnectionsHolder; // Service connections. |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 303 | UriPermissionOwner uriPermissions; // current special URI access perms. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 304 | WindowProcessController app; // if non-null, hosting application |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 305 | private ActivityState mState; // current state we are in |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | Bundle icicle; // last saved activity state |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 307 | PersistableBundle persistentState; // last persistently saved activity state |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 308 | // TODO: See if this is still needed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | boolean frontOfTask; // is this the root activity of its task? |
| 310 | boolean launchFailed; // set if a launched failed, to abort on 2nd try |
| 311 | boolean haveState; // have we gotten the last activity state? |
| 312 | boolean stopped; // is activity pause finished? |
Dianne Hackborn | 95fc68f | 2009-05-19 18:37:45 -0700 | [diff] [blame] | 313 | 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] | 314 | boolean finishing; // activity in pending finish list? |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 315 | boolean deferRelaunchUntilPaused; // relaunch of activity is being deferred until pause is |
| 316 | // completed |
| 317 | boolean preserveWindowOnDeferredRelaunch; // activity windows are preserved on deferred relaunch |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | int configChangeFlags; // which config values have changed |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 319 | private boolean keysPaused; // has key dispatching been paused for it? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 320 | int launchMode; // the launch mode activity attribute. |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 321 | int lockTaskLaunchMode; // the lockTaskMode manifest attribute, subject to override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 322 | boolean visible; // does this activity's window need to be shown? |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 323 | boolean visibleIgnoringKeyguard; // is this activity visible, ignoring the fact that Keyguard |
| 324 | // might hide this activity? |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 325 | private boolean mDeferHidingClient; // If true we told WM to defer reporting to the client |
| 326 | // process that it is hidden. |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 327 | boolean sleeping; // have we told the activity to sleep? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | boolean nowVisible; // is this activity's window visible? |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 329 | boolean mDrawn; // is this activity's window drawn? |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 330 | boolean mClientVisibilityDeferred;// was the visibility change message to client deferred? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | boolean idle; // has the activity gone idle? |
| 332 | boolean hasBeenLaunched;// has this activity ever been launched? |
| 333 | boolean frozenBeforeDestroy;// has been frozen but not yet destroyed. |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 334 | boolean immersive; // immersive mode (don't interrupt if possible) |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 335 | boolean forceNewConfig; // force re-create with new config next time |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 336 | boolean supportsEnterPipOnTaskSwitch; // This flag is set by the system to indicate that the |
| 337 | // activity can enter picture in picture while pausing (only when switching to another task) |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 338 | PictureInPictureParams pictureInPictureArgs = new PictureInPictureParams.Builder().build(); |
| 339 | // The PiP params used when deferring the entering of picture-in-picture. |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 340 | int launchCount; // count of launches since last state |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 341 | long lastLaunchTime; // time of last launch of this activity |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 342 | ComponentName requestedVrComponent; // the requested component for handling VR mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 344 | String stringName; // for caching of toString(). |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 345 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 346 | private boolean inHistory; // are we in the history stack? |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 347 | final ActivityStackSupervisor mStackSupervisor; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 348 | final RootActivityContainer mRootActivityContainer; |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 349 | |
| 350 | static final int STARTING_WINDOW_NOT_SHOWN = 0; |
| 351 | static final int STARTING_WINDOW_SHOWN = 1; |
| 352 | static final int STARTING_WINDOW_REMOVED = 2; |
| 353 | int mStartingWindowState = STARTING_WINDOW_NOT_SHOWN; |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 354 | 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] | 355 | |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 356 | // Marking the reason why this activity is being relaunched. Mainly used to track that this |
| 357 | // activity is being relaunched to fulfill a resize request due to compatibility issues, e.g. in |
| 358 | // pre-NYC apps that don't have a sense of being resized. |
| 359 | int mRelaunchReason = RELAUNCH_REASON_NONE; |
| 360 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 361 | TaskDescription taskDescription; // the recents information for this activity |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 362 | boolean mLaunchTaskBehind; // this activity is actively being launched with |
| 363 | // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed. |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 364 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 365 | // These configurations are collected from application's resources based on size-sensitive |
| 366 | // qualifiers. For example, layout-w800dp will be added to mHorizontalSizeConfigurations as 800 |
| 367 | // and drawable-sw400dp will be added to both as 400. |
| 368 | private int[] mVerticalSizeConfigurations; |
| 369 | private int[] mHorizontalSizeConfigurations; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 370 | private int[] mSmallestSizeConfigurations; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 371 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 372 | boolean pendingVoiceInteractionStart; // Waiting for activity-invoked voice session |
| 373 | IVoiceInteractionSession voiceSession; // Voice interaction session for this activity |
| 374 | |
Robert Carr | d226512 | 2016-08-05 10:25:21 -0700 | [diff] [blame] | 375 | // A hint to override the window specified rotation animation, or -1 |
| 376 | // to use the window specified value. We use this so that |
| 377 | // we can select the right animation in the cases of starting |
| 378 | // windows, where the app hasn't had time to set a value |
| 379 | // on the window. |
| 380 | int mRotationAnimationHint = -1; |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 381 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 382 | private boolean mShowWhenLocked; |
| 383 | private boolean mTurnScreenOn; |
| 384 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 385 | /** |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 386 | * Temp configs used in {@link #ensureActivityConfiguration(int, boolean)} |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 387 | */ |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 388 | private final Configuration mTmpConfig = new Configuration(); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 389 | private final Rect mTmpBounds = new Rect(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 390 | |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 391 | private static String startingWindowStateToString(int state) { |
| 392 | switch (state) { |
| 393 | case STARTING_WINDOW_NOT_SHOWN: |
| 394 | return "STARTING_WINDOW_NOT_SHOWN"; |
| 395 | case STARTING_WINDOW_SHOWN: |
| 396 | return "STARTING_WINDOW_SHOWN"; |
| 397 | case STARTING_WINDOW_REMOVED: |
| 398 | return "STARTING_WINDOW_REMOVED"; |
| 399 | default: |
| 400 | return "unknown state=" + state; |
| 401 | } |
| 402 | } |
| 403 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 405 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 406 | pw.print(prefix); pw.print("packageName="); pw.print(packageName); |
| 407 | pw.print(" processName="); pw.println(processName); |
| 408 | pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid); |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 409 | pw.print(" launchedFromPackage="); pw.print(launchedFromPackage); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 410 | pw.print(" userId="); pw.println(mUserId); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 411 | pw.print(prefix); pw.print("app="); pw.println(app); |
| 412 | pw.print(prefix); pw.println(intent.toInsecureStringWithClip()); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 413 | pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask); |
| 414 | pw.print(" task="); pw.println(task); |
| 415 | pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 416 | pw.print(prefix); pw.print("mActivityComponent="); |
| 417 | pw.println(mActivityComponent.flattenToShortString()); |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 418 | if (appInfo != null) { |
| 419 | pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir); |
| 420 | if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) { |
| 421 | pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir); |
| 422 | } |
| 423 | pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 424 | if (appInfo.splitSourceDirs != null) { |
| 425 | pw.print(prefix); pw.print("splitDir="); |
| 426 | pw.println(Arrays.toString(appInfo.splitSourceDirs)); |
| 427 | } |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 428 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 429 | pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded); |
| 430 | pw.print(" componentSpecified="); pw.print(componentSpecified); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 431 | pw.print(" mActivityType="); pw.println( |
| 432 | activityTypeToString(getActivityType())); |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 433 | if (rootVoiceInteraction) { |
| 434 | pw.print(prefix); pw.print("rootVoiceInteraction="); pw.println(rootVoiceInteraction); |
| 435 | } |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 436 | pw.print(prefix); pw.print("compat="); pw.print(compat); |
| 437 | pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes)); |
| 438 | pw.print(" icon=0x"); pw.print(Integer.toHexString(icon)); |
| 439 | pw.print(" theme=0x"); pw.println(Integer.toHexString(theme)); |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 440 | pw.println(prefix + "mLastReportedConfigurations:"); |
| 441 | mLastReportedConfiguration.dump(pw, prefix + " "); |
| 442 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 443 | pw.print(prefix); pw.print("CurrentConfiguration="); pw.println(getConfiguration()); |
| 444 | if (!getOverrideConfiguration().equals(EMPTY)) { |
| 445 | pw.println(prefix + "OverrideConfiguration=" + getOverrideConfiguration()); |
| 446 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 447 | if (!matchParentBounds()) { |
| 448 | pw.println(prefix + "bounds=" + getBounds()); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 449 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 450 | if (resultTo != null || resultWho != null) { |
| 451 | pw.print(prefix); pw.print("resultTo="); pw.print(resultTo); |
| 452 | pw.print(" resultWho="); pw.print(resultWho); |
| 453 | pw.print(" resultCode="); pw.println(requestCode); |
| 454 | } |
Craig Mautner | 29c58ca | 2014-10-14 16:17:06 -0700 | [diff] [blame] | 455 | if (taskDescription != null) { |
| 456 | final String iconFilename = taskDescription.getIconFilename(); |
| 457 | if (iconFilename != null || taskDescription.getLabel() != null || |
| 458 | taskDescription.getPrimaryColor() != 0) { |
| 459 | pw.print(prefix); pw.print("taskDescription:"); |
Craig Mautner | 29c58ca | 2014-10-14 16:17:06 -0700 | [diff] [blame] | 460 | pw.print(" label=\""); pw.print(taskDescription.getLabel()); |
| 461 | pw.print("\""); |
Matthew Ng | 54bc942 | 2017-10-02 17:16:28 -0700 | [diff] [blame] | 462 | pw.print(" icon="); pw.print(taskDescription.getInMemoryIcon() != null |
| 463 | ? taskDescription.getInMemoryIcon().getByteCount() + " bytes" |
| 464 | : "null"); |
| 465 | pw.print(" iconResource="); pw.print(taskDescription.getIconResource()); |
| 466 | pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename()); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 467 | pw.print(" primaryColor="); |
Craig Mautner | 29c58ca | 2014-10-14 16:17:06 -0700 | [diff] [blame] | 468 | pw.println(Integer.toHexString(taskDescription.getPrimaryColor())); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 469 | pw.print(prefix + " backgroundColor="); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 470 | pw.println(Integer.toHexString(taskDescription.getBackgroundColor())); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 471 | pw.print(prefix + " statusBarColor="); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 472 | pw.println(Integer.toHexString(taskDescription.getStatusBarColor())); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 473 | pw.print(prefix + " navigationBarColor="); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 474 | pw.println(Integer.toHexString(taskDescription.getNavigationBarColor())); |
Craig Mautner | 29c58ca | 2014-10-14 16:17:06 -0700 | [diff] [blame] | 475 | } |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 476 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 477 | if (results != null) { |
| 478 | pw.print(prefix); pw.print("results="); pw.println(results); |
| 479 | } |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 480 | if (pendingResults != null && pendingResults.size() > 0) { |
| 481 | pw.print(prefix); pw.println("Pending Results:"); |
| 482 | for (WeakReference<PendingIntentRecord> wpir : pendingResults) { |
| 483 | PendingIntentRecord pir = wpir != null ? wpir.get() : null; |
| 484 | pw.print(prefix); pw.print(" - "); |
| 485 | if (pir == null) { |
| 486 | pw.println("null"); |
| 487 | } else { |
| 488 | pw.println(pir); |
| 489 | pir.dump(pw, prefix + " "); |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | if (newIntents != null && newIntents.size() > 0) { |
| 494 | pw.print(prefix); pw.println("Pending New Intents:"); |
| 495 | for (int i=0; i<newIntents.size(); i++) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 496 | Intent intent = newIntents.get(i); |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 497 | pw.print(prefix); pw.print(" - "); |
| 498 | if (intent == null) { |
| 499 | pw.println("null"); |
| 500 | } else { |
| 501 | pw.println(intent.toShortString(false, true, false, true)); |
| 502 | } |
| 503 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 504 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 505 | if (pendingOptions != null) { |
| 506 | pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions); |
| 507 | } |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 508 | if (appTimeTracker != null) { |
| 509 | appTimeTracker.dumpWithHeader(pw, prefix, false); |
| 510 | } |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 511 | if (uriPermissions != null) { |
Jeff Sharkey | 846318a | 2014-04-04 12:12:41 -0700 | [diff] [blame] | 512 | uriPermissions.dump(pw, prefix); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 513 | } |
| 514 | pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed); |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 515 | pw.print(" launchCount="); pw.print(launchCount); |
| 516 | pw.print(" lastLaunchTime="); |
| 517 | if (lastLaunchTime == 0) pw.print("0"); |
| 518 | else TimeUtils.formatDuration(lastLaunchTime, now, pw); |
| 519 | pw.println(); |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 520 | pw.print(prefix); pw.print("haveState="); pw.print(haveState); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 521 | pw.print(" icicle="); pw.println(icicle); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 522 | pw.print(prefix); pw.print("state="); pw.print(mState); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 523 | pw.print(" stopped="); pw.print(stopped); |
Dianne Hackborn | 95fc68f | 2009-05-19 18:37:45 -0700 | [diff] [blame] | 524 | pw.print(" delayedResume="); pw.print(delayedResume); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 525 | pw.print(" finishing="); pw.println(finishing); |
| 526 | pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused); |
| 527 | pw.print(" inHistory="); pw.print(inHistory); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 528 | pw.print(" visible="); pw.print(visible); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 529 | pw.print(" sleeping="); pw.print(sleeping); |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 530 | pw.print(" idle="); pw.print(idle); |
| 531 | pw.print(" mStartingWindowState="); |
| 532 | pw.println(startingWindowStateToString(mStartingWindowState)); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 533 | pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen); |
| 534 | pw.print(" noDisplay="); pw.print(noDisplay); |
| 535 | pw.print(" immersive="); pw.print(immersive); |
| 536 | pw.print(" launchMode="); pw.println(launchMode); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 537 | pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 538 | pw.print(" forceNewConfig="); pw.println(forceNewConfig); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 539 | pw.print(prefix); pw.print("mActivityType="); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 540 | pw.println(activityTypeToString(getActivityType())); |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 541 | if (requestedVrComponent != null) { |
| 542 | pw.print(prefix); |
| 543 | pw.print("requestedVrComponent="); |
| 544 | pw.println(requestedVrComponent); |
| 545 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 546 | final boolean waitingVisible = |
| 547 | mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(this); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 548 | if (lastVisibleTime != 0 || waitingVisible || nowVisible) { |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 549 | pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 550 | pw.print(" nowVisible="); pw.print(nowVisible); |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 551 | pw.print(" lastVisibleTime="); |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 552 | if (lastVisibleTime == 0) pw.print("0"); |
| 553 | else TimeUtils.formatDuration(lastVisibleTime, now, pw); |
| 554 | pw.println(); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 555 | } |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 556 | if (mDeferHidingClient) { |
| 557 | pw.println(prefix + "mDeferHidingClient=" + mDeferHidingClient); |
| 558 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 559 | if (deferRelaunchUntilPaused || configChangeFlags != 0) { |
| 560 | pw.print(prefix); pw.print("deferRelaunchUntilPaused="); pw.print(deferRelaunchUntilPaused); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 561 | pw.print(" configChangeFlags="); |
| 562 | pw.println(Integer.toHexString(configChangeFlags)); |
| 563 | } |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 564 | if (mServiceConnectionsHolder != null) { |
| 565 | pw.print(prefix); pw.print("connections="); pw.println(mServiceConnectionsHolder); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 566 | } |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 567 | if (info != null) { |
| 568 | pw.println(prefix + "resizeMode=" + ActivityInfo.resizeModeToString(info.resizeMode)); |
Winson Chung | 609e1e9 | 2017-05-08 10:52:12 -0700 | [diff] [blame] | 569 | pw.println(prefix + "mLastReportedMultiWindowMode=" + mLastReportedMultiWindowMode |
| 570 | + " mLastReportedPictureInPictureMode=" + mLastReportedPictureInPictureMode); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 571 | if (info.supportsPictureInPicture()) { |
| 572 | pw.println(prefix + "supportsPictureInPicture=" + info.supportsPictureInPicture()); |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 573 | pw.println(prefix + "supportsEnterPipOnTaskSwitch: " |
| 574 | + supportsEnterPipOnTaskSwitch); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 575 | } |
| 576 | if (info.maxAspectRatio != 0) { |
| 577 | pw.println(prefix + "maxAspectRatio=" + info.maxAspectRatio); |
| 578 | } |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 579 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 580 | } |
| 581 | |
Philip P. Moltmann | cff8f0f | 2018-03-27 12:51:51 -0700 | [diff] [blame] | 582 | void updateApplicationInfo(ApplicationInfo aInfo) { |
| 583 | appInfo = aInfo; |
| 584 | info.applicationInfo = aInfo; |
| 585 | } |
| 586 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 587 | private boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 588 | return crossesSizeThreshold(mHorizontalSizeConfigurations, firstDp, secondDp); |
| 589 | } |
| 590 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 591 | private boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 592 | return crossesSizeThreshold(mVerticalSizeConfigurations, firstDp, secondDp); |
| 593 | } |
| 594 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 595 | private boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 596 | return crossesSizeThreshold(mSmallestSizeConfigurations, firstDp, secondDp); |
| 597 | } |
| 598 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 599 | /** |
| 600 | * The purpose of this method is to decide whether the activity needs to be relaunched upon |
| 601 | * changing its size. In most cases the activities don't need to be relaunched, if the resize |
| 602 | * is small, all the activity content has to do is relayout itself within new bounds. There are |
| 603 | * cases however, where the activity's content would be completely changed in the new size and |
| 604 | * the full relaunch is required. |
| 605 | * |
| 606 | * The activity will report to us vertical and horizontal thresholds after which a relaunch is |
| 607 | * required. These thresholds are collected from the application resource qualifiers. For |
| 608 | * example, if application has layout-w600dp resource directory, then it needs a relaunch when |
| 609 | * we resize from width of 650dp to 550dp, as it crosses the 600dp threshold. However, if |
| 610 | * it resizes width from 620dp to 700dp, it won't be relaunched as it stays on the same side |
| 611 | * of the threshold. |
| 612 | */ |
| 613 | private static boolean crossesSizeThreshold(int[] thresholds, int firstDp, |
| 614 | int secondDp) { |
| 615 | if (thresholds == null) { |
| 616 | return false; |
| 617 | } |
| 618 | for (int i = thresholds.length - 1; i >= 0; i--) { |
| 619 | final int threshold = thresholds[i]; |
| 620 | if ((firstDp < threshold && secondDp >= threshold) |
| 621 | || (firstDp >= threshold && secondDp < threshold)) { |
| 622 | return true; |
| 623 | } |
| 624 | } |
| 625 | return false; |
| 626 | } |
| 627 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 628 | void setSizeConfigurations(int[] horizontalSizeConfiguration, |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 629 | int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 630 | mHorizontalSizeConfigurations = horizontalSizeConfiguration; |
| 631 | mVerticalSizeConfigurations = verticalSizeConfigurations; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 632 | mSmallestSizeConfigurations = smallestSizeConfigurations; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 635 | private void scheduleActivityMovedToDisplay(int displayId, Configuration config) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 636 | if (!attachedToProcess()) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 637 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.w(TAG, |
| 638 | "Can't report activity moved to display - client not running, activityRecord=" |
| 639 | + this + ", displayId=" + displayId); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 640 | return; |
| 641 | } |
| 642 | try { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 643 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
| 644 | "Reporting activity moved to display" + ", activityRecord=" + this |
| 645 | + ", displayId=" + displayId + ", config=" + config); |
Chong Zhang | 6be533e | 2016-06-17 16:24:21 -0700 | [diff] [blame] | 646 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 647 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 648 | MoveToDisplayItem.obtain(displayId, config)); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 649 | } catch (RemoteException e) { |
| 650 | // If process died, whatever. |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | private void scheduleConfigurationChanged(Configuration config) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 655 | if (!attachedToProcess()) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 656 | if (DEBUG_CONFIGURATION) Slog.w(TAG, |
| 657 | "Can't report activity configuration update - client not running" |
| 658 | + ", activityRecord=" + this); |
| 659 | return; |
| 660 | } |
| 661 | try { |
| 662 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + this + ", config: " |
| 663 | + config); |
| 664 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 665 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 666 | ActivityConfigurationChangeItem.obtain(config)); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 667 | } catch (RemoteException e) { |
| 668 | // If process died, whatever. |
| 669 | } |
| 670 | } |
| 671 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 672 | void updateMultiWindowMode() { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 673 | if (task == null || task.getStack() == null || !attachedToProcess()) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 674 | return; |
| 675 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 676 | |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 677 | if (task.getStack().deferScheduleMultiWindowModeChanged()) { |
| 678 | // Don't do anything if we are currently deferring multi-window mode change. |
| 679 | return; |
| 680 | } |
| 681 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 682 | // An activity is considered to be in multi-window mode if its task isn't fullscreen. |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 683 | final boolean inMultiWindowMode = inMultiWindowMode(); |
Winson Chung | 609e1e9 | 2017-05-08 10:52:12 -0700 | [diff] [blame] | 684 | if (inMultiWindowMode != mLastReportedMultiWindowMode) { |
| 685 | mLastReportedMultiWindowMode = inMultiWindowMode; |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 686 | scheduleMultiWindowModeChanged(getConfiguration()); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | private void scheduleMultiWindowModeChanged(Configuration overrideConfig) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 691 | try { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 692 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 693 | MultiWindowModeChangeItem.obtain(mLastReportedMultiWindowMode, overrideConfig)); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 694 | } catch (Exception e) { |
| 695 | // If process died, I don't care. |
| 696 | } |
| 697 | } |
| 698 | |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 699 | void updatePictureInPictureMode(Rect targetStackBounds, boolean forceUpdate) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 700 | if (task == null || task.getStack() == null || !attachedToProcess()) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 701 | return; |
| 702 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 703 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 704 | final boolean inPictureInPictureMode = inPinnedWindowingMode() && targetStackBounds != null; |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 705 | if (inPictureInPictureMode != mLastReportedPictureInPictureMode || forceUpdate) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 706 | // Picture-in-picture mode changes also trigger a multi-window mode change as well, so |
Winson Chung | 059955f | 2018-08-08 16:10:20 -0700 | [diff] [blame] | 707 | // update that here in order. Set the last reported MW state to the same as the PiP |
| 708 | // state since we haven't yet actually resized the task (these callbacks need to |
| 709 | // preceed the configuration change from the resiez. |
| 710 | // TODO(110009072): Once we move these callbacks to the client, remove all logic related |
| 711 | // to forcing the update of the picture-in-picture mode as a part of the PiP animation. |
Winson Chung | 609e1e9 | 2017-05-08 10:52:12 -0700 | [diff] [blame] | 712 | mLastReportedPictureInPictureMode = inPictureInPictureMode; |
Winson Chung | 059955f | 2018-08-08 16:10:20 -0700 | [diff] [blame] | 713 | mLastReportedMultiWindowMode = inPictureInPictureMode; |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 714 | final Configuration newConfig = task.computeNewOverrideConfigurationForBounds( |
| 715 | targetStackBounds, null); |
| 716 | schedulePictureInPictureModeChanged(newConfig); |
| 717 | scheduleMultiWindowModeChanged(newConfig); |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | private void schedulePictureInPictureModeChanged(Configuration overrideConfig) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 722 | try { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 723 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 724 | PipModeChangeItem.obtain(mLastReportedPictureInPictureMode, |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 725 | overrideConfig)); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 726 | } catch (Exception e) { |
| 727 | // If process died, no one cares. |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 731 | @Override |
| 732 | protected int getChildCount() { |
| 733 | // {@link ActivityRecord} is a leaf node and has no children. |
| 734 | return 0; |
| 735 | } |
| 736 | |
| 737 | @Override |
| 738 | protected ConfigurationContainer getChildAt(int index) { |
| 739 | return null; |
| 740 | } |
| 741 | |
| 742 | @Override |
| 743 | protected ConfigurationContainer getParent() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 744 | return getTaskRecord(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 747 | TaskRecord getTaskRecord() { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 748 | return task; |
| 749 | } |
| 750 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 751 | /** |
| 752 | * Sets reference to the {@link TaskRecord} the {@link ActivityRecord} will treat as its parent. |
| 753 | * Note that this does not actually add the {@link ActivityRecord} as a {@link TaskRecord} |
| 754 | * children. However, this method will clean up references to this {@link ActivityRecord} in |
| 755 | * {@link ActivityStack}. |
| 756 | * @param task The new parent {@link TaskRecord}. |
| 757 | */ |
| 758 | void setTask(TaskRecord task) { |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 759 | setTask(task /* task */, false /* reparenting */); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | /** |
| 763 | * This method should only be called by {@link TaskRecord#removeActivity(ActivityRecord)}. |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 764 | * @param task The new parent task. |
| 765 | * @param reparenting Whether we're in the middle of reparenting. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 766 | */ |
| 767 | void setTask(TaskRecord task, boolean reparenting) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 768 | // Do nothing if the {@link TaskRecord} is the same as the current {@link getTaskRecord}. |
| 769 | if (task != null && task == getTaskRecord()) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 770 | return; |
| 771 | } |
| 772 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 773 | final ActivityStack oldStack = getActivityStack(); |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 774 | final ActivityStack newStack = task != null ? task.getStack() : null; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 775 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 776 | // Inform old stack (if present) of activity removal and new stack (if set) of activity |
| 777 | // addition. |
| 778 | if (oldStack != newStack) { |
| 779 | if (!reparenting && oldStack != null) { |
| 780 | oldStack.onActivityRemovedFromStack(this); |
| 781 | } |
| 782 | |
| 783 | if (newStack != null) { |
| 784 | newStack.onActivityAddedToStack(this); |
| 785 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | this.task = task; |
| 789 | |
| 790 | if (!reparenting) { |
| 791 | onParentChanged(); |
| 792 | } |
| 793 | } |
| 794 | |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 795 | /** |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 796 | * Notifies AWT that this app is waiting to pause in order to determine if it will enter PIP. |
| 797 | * This information helps AWT know that the app is in the process of pausing before it gets the |
| 798 | * signal on the WM side. |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 799 | */ |
| 800 | void setWillCloseOrEnterPip(boolean willCloseOrEnterPip) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 801 | if (mAppWindowToken == null) { |
| 802 | return; |
| 803 | } |
| 804 | |
| 805 | mAppWindowToken.setWillCloseOrEnterPip(willCloseOrEnterPip); |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 808 | static class Token extends IApplicationToken.Stub { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 809 | private final WeakReference<ActivityRecord> weakActivity; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 810 | private final String name; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 811 | |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 812 | Token(ActivityRecord activity, Intent intent) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 813 | weakActivity = new WeakReference<>(activity); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 814 | name = intent.getComponent().flattenToShortString(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 817 | private static ActivityRecord tokenToActivityRecordLocked(Token token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 818 | if (token == null) { |
| 819 | return null; |
| 820 | } |
| 821 | ActivityRecord r = token.weakActivity.get(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 822 | if (r == null || r.getActivityStack() == null) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 823 | return null; |
| 824 | } |
| 825 | return r; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 826 | } |
| 827 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 828 | @Override |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 829 | public String toString() { |
| 830 | StringBuilder sb = new StringBuilder(128); |
| 831 | sb.append("Token{"); |
| 832 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 833 | sb.append(' '); |
| 834 | sb.append(weakActivity.get()); |
| 835 | sb.append('}'); |
| 836 | return sb.toString(); |
| 837 | } |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 838 | |
| 839 | @Override |
| 840 | public String getName() { |
| 841 | return name; |
| 842 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 843 | } |
| 844 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 845 | static ActivityRecord forTokenLocked(IBinder token) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 846 | try { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 847 | return Token.tokenToActivityRecordLocked((Token)token); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 848 | } catch (ClassCastException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 849 | Slog.w(TAG, "Bad activity token: " + token, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 850 | return null; |
| 851 | } |
| 852 | } |
| 853 | |
Chong Zhang | 85ee654 | 2015-10-02 13:36:38 -0700 | [diff] [blame] | 854 | boolean isResolverActivity() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 855 | return ResolverActivity.class.getName().equals(mActivityComponent.getClassName()); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Patrick Baumann | 31426b2 | 2018-05-21 13:46:40 -0700 | [diff] [blame] | 858 | boolean isResolverOrChildActivity() { |
| 859 | if (!"android".equals(packageName)) { |
| 860 | return false; |
| 861 | } |
| 862 | try { |
| 863 | return ResolverActivity.class.isAssignableFrom( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 864 | Object.class.getClassLoader().loadClass(mActivityComponent.getClassName())); |
Patrick Baumann | 31426b2 | 2018-05-21 13:46:40 -0700 | [diff] [blame] | 865 | } catch (ClassNotFoundException e) { |
| 866 | return false; |
| 867 | } |
| 868 | } |
| 869 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 870 | ActivityRecord(ActivityTaskManagerService _service, WindowProcessController _caller, |
| 871 | int _launchedFromPid, int _launchedFromUid, String _launchedFromPackage, Intent _intent, |
| 872 | String _resolvedType, ActivityInfo aInfo, Configuration _configuration, |
| 873 | ActivityRecord _resultTo, String _resultWho, int _reqCode, boolean _componentSpecified, |
| 874 | boolean _rootVoiceInteraction, ActivityStackSupervisor supervisor, |
| 875 | ActivityOptions options, ActivityRecord sourceRecord) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 876 | mAtmService = _service; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 877 | mRootActivityContainer = _service.mRootActivityContainer; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 878 | appToken = new Token(this, _intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 879 | info = aInfo; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 880 | launchedFromPid = _launchedFromPid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 881 | launchedFromUid = _launchedFromUid; |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 882 | launchedFromPackage = _launchedFromPackage; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 883 | mUserId = UserHandle.getUserId(aInfo.applicationInfo.uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 884 | intent = _intent; |
| 885 | shortComponentName = _intent.getComponent().flattenToShortString(); |
| 886 | resolvedType = _resolvedType; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 887 | componentSpecified = _componentSpecified; |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 888 | rootVoiceInteraction = _rootVoiceInteraction; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 889 | mLastReportedConfiguration = new MergedConfiguration(_configuration); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | resultTo = _resultTo; |
| 891 | resultWho = _resultWho; |
| 892 | requestCode = _reqCode; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 893 | setState(INITIALIZING, "ActivityRecord ctor"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 894 | frontOfTask = false; |
| 895 | launchFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 896 | stopped = false; |
Dianne Hackborn | 95fc68f | 2009-05-19 18:37:45 -0700 | [diff] [blame] | 897 | delayedResume = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 898 | finishing = false; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 899 | deferRelaunchUntilPaused = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 900 | keysPaused = false; |
| 901 | inHistory = false; |
Chong Zhang | a48ef66 | 2015-08-18 19:21:47 -0700 | [diff] [blame] | 902 | visible = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 903 | nowVisible = false; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 904 | mDrawn = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 905 | idle = false; |
| 906 | hasBeenLaunched = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 907 | mStackSupervisor = supervisor; |
Robert Carr | 0f5d753 | 2016-10-17 16:39:17 -0700 | [diff] [blame] | 908 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 909 | // This starts out true, since the initial state of an activity is that we have everything, |
| 910 | // 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] | 911 | haveState = true; |
| 912 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 913 | // If the class name in the intent doesn't match that of the target, this is |
| 914 | // probably an alias. We have to create a new ComponentName object to keep track |
| 915 | // of the real activity name, so that FLAG_ACTIVITY_CLEAR_TOP is handled properly. |
| 916 | if (aInfo.targetActivity == null |
| 917 | || (aInfo.targetActivity.equals(_intent.getComponent().getClassName()) |
| 918 | && (aInfo.launchMode == LAUNCH_MULTIPLE |
| 919 | || aInfo.launchMode == LAUNCH_SINGLE_TOP))) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 920 | mActivityComponent = _intent.getComponent(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | } else { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 922 | mActivityComponent = new ComponentName(aInfo.packageName, aInfo.targetActivity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 924 | taskAffinity = aInfo.taskAffinity; |
| 925 | stateNotNeeded = (aInfo.flags & FLAG_STATE_NOT_NEEDED) != 0; |
| 926 | appInfo = aInfo.applicationInfo; |
| 927 | nonLocalizedLabel = aInfo.nonLocalizedLabel; |
| 928 | labelRes = aInfo.labelRes; |
| 929 | if (nonLocalizedLabel == null && labelRes == 0) { |
| 930 | ApplicationInfo app = aInfo.applicationInfo; |
| 931 | nonLocalizedLabel = app.nonLocalizedLabel; |
| 932 | labelRes = app.labelRes; |
| 933 | } |
| 934 | icon = aInfo.getIconResource(); |
| 935 | logo = aInfo.getLogoResource(); |
| 936 | theme = aInfo.getThemeResource(); |
| 937 | realTheme = theme; |
| 938 | if (realTheme == 0) { |
| 939 | realTheme = aInfo.applicationInfo.targetSdkVersion < HONEYCOMB |
| 940 | ? android.R.style.Theme : android.R.style.Theme_Holo; |
| 941 | } |
| 942 | if ((aInfo.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) { |
| 943 | windowFlags |= LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 944 | } |
| 945 | if ((aInfo.flags & FLAG_MULTIPROCESS) != 0 && _caller != null |
| 946 | && (aInfo.applicationInfo.uid == SYSTEM_UID |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 947 | || aInfo.applicationInfo.uid == _caller.mInfo.uid)) { |
| 948 | processName = _caller.mName; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 949 | } else { |
| 950 | processName = aInfo.processName; |
| 951 | } |
| 952 | |
| 953 | if ((aInfo.flags & FLAG_EXCLUDE_FROM_RECENTS) != 0) { |
| 954 | intent.addFlags(FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 955 | } |
| 956 | |
| 957 | packageName = aInfo.applicationInfo.packageName; |
| 958 | launchMode = aInfo.launchMode; |
| 959 | |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 960 | Entry ent = AttributeCache.instance().get(packageName, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 961 | realTheme, com.android.internal.R.styleable.Window, mUserId); |
Bryce Lee | e83f34cd | 2017-10-31 19:50:54 -0700 | [diff] [blame] | 962 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 963 | if (ent != null) { |
| 964 | fullscreen = !ActivityInfo.isTranslucentOrFloating(ent.array); |
| 965 | hasWallpaper = ent.array.getBoolean(R.styleable.Window_windowShowWallpaper, false); |
| 966 | noDisplay = ent.array.getBoolean(R.styleable.Window_windowNoDisplay, false); |
| 967 | } else { |
| 968 | hasWallpaper = false; |
| 969 | noDisplay = false; |
| 970 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 971 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 972 | setActivityType(_componentSpecified, _launchedFromUid, _intent, options, sourceRecord); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 973 | |
| 974 | immersive = (aInfo.flags & FLAG_IMMERSIVE) != 0; |
| 975 | |
| 976 | requestedVrComponent = (aInfo.requestedVrComponent == null) ? |
| 977 | null : ComponentName.unflattenFromString(aInfo.requestedVrComponent); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 978 | |
| 979 | mShowWhenLocked = (aInfo.flags & FLAG_SHOW_WHEN_LOCKED) != 0; |
| 980 | mTurnScreenOn = (aInfo.flags & FLAG_TURN_SCREEN_ON) != 0; |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 981 | |
| 982 | mRotationAnimationHint = aInfo.rotationAnimation; |
| 983 | lockTaskLaunchMode = aInfo.lockTaskLaunchMode; |
| 984 | if (appInfo.isPrivilegedApp() && (lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_ALWAYS |
| 985 | || lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_NEVER)) { |
| 986 | lockTaskLaunchMode = LOCK_TASK_LAUNCH_MODE_DEFAULT; |
| 987 | } |
| 988 | |
| 989 | if (options != null) { |
| 990 | pendingOptions = options; |
| 991 | mLaunchTaskBehind = options.getLaunchTaskBehind(); |
| 992 | |
| 993 | final int rotationAnimation = pendingOptions.getRotationAnimationHint(); |
| 994 | // Only override manifest supplied option if set. |
| 995 | if (rotationAnimation >= 0) { |
| 996 | mRotationAnimationHint = rotationAnimation; |
| 997 | } |
| 998 | final PendingIntent usageReport = pendingOptions.getUsageTimeReport(); |
| 999 | if (usageReport != null) { |
| 1000 | appTimeTracker = new AppTimeTracker(usageReport); |
| 1001 | } |
| 1002 | final boolean useLockTask = pendingOptions.getLockTaskMode(); |
| 1003 | if (useLockTask && lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_DEFAULT) { |
| 1004 | lockTaskLaunchMode = LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED; |
| 1005 | } |
| 1006 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1007 | } |
| 1008 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1009 | void setProcess(WindowProcessController proc) { |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 1010 | app = proc; |
| 1011 | final ActivityRecord root = task != null ? task.getRootActivity() : null; |
| 1012 | if (root == this) { |
| 1013 | task.setRootProcess(proc); |
| 1014 | } |
| 1015 | } |
| 1016 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1017 | boolean hasProcess() { |
| 1018 | return app != null; |
| 1019 | } |
| 1020 | |
| 1021 | boolean attachedToProcess() { |
| 1022 | return hasProcess() && app.hasThread(); |
| 1023 | } |
| 1024 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1025 | void createAppWindowToken() { |
| 1026 | if (mAppWindowToken != null) { |
| 1027 | throw new IllegalArgumentException("App Window Token=" + mAppWindowToken |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1028 | + " already created for r=" + this); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | inHistory = true; |
| 1032 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 1033 | final TaskWindowContainerController taskController = task.getWindowContainerController(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1034 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 1035 | // TODO(b/36505427): Maybe this call should be moved inside updateOverrideConfiguration() |
| 1036 | task.updateOverrideConfigurationFromLaunchBounds(); |
| 1037 | // Make sure override configuration is up-to-date before using to create window controller. |
| 1038 | updateOverrideConfiguration(); |
| 1039 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1040 | // TODO: remove after unification |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1041 | mAppWindowToken = mAtmService.mWindowManager.mRoot.getAppWindowToken(appToken.asBinder()); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1042 | if (mAppWindowToken != null) { |
| 1043 | // TODO: Should this throw an exception instead? |
| 1044 | Slog.w(TAG, "Attempted to add existing app token: " + appToken); |
| 1045 | } else { |
| 1046 | final Task container = taskController.mContainer; |
| 1047 | if (container == null) { |
| 1048 | throw new IllegalArgumentException("AppWindowContainerController: invalid " |
| 1049 | + " controller=" + taskController); |
| 1050 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1051 | mAppWindowToken = createAppWindow(mAtmService.mWindowManager, appToken, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1052 | task.voiceSession != null, container.getDisplayContent(), |
| 1053 | ActivityTaskManagerService.getInputDispatchingTimeoutLocked(this) |
| 1054 | * 1000000L, fullscreen, |
| 1055 | (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, appInfo.targetSdkVersion, |
| 1056 | info.screenOrientation, mRotationAnimationHint, info.configChanges, |
| 1057 | mLaunchTaskBehind, isAlwaysFocusable()); |
| 1058 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1059 | Slog.v(TAG, "addAppToken: " |
| 1060 | + mAppWindowToken + " controller=" + taskController + " at " |
| 1061 | + Integer.MAX_VALUE); |
| 1062 | } |
| 1063 | container.addChild(mAppWindowToken, Integer.MAX_VALUE /* add on top */); |
| 1064 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1065 | |
| 1066 | task.addActivityToTop(this); |
| 1067 | |
Winson Chung | 609e1e9 | 2017-05-08 10:52:12 -0700 | [diff] [blame] | 1068 | // When an activity is started directly into a split-screen fullscreen stack, we need to |
| 1069 | // update the initial multi-window modes so that the callbacks are scheduled correctly when |
| 1070 | // the user leaves that mode. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1071 | mLastReportedMultiWindowMode = inMultiWindowMode(); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1072 | mLastReportedPictureInPictureMode = inPinnedWindowingMode(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1073 | } |
| 1074 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1075 | boolean addStartingWindow(String pkg, int theme, CompatibilityInfo compatInfo, |
| 1076 | CharSequence nonLocalizedLabel, int labelRes, int icon, int logo, int windowFlags, |
| 1077 | IBinder transferFrom, boolean newTask, boolean taskSwitch, boolean processRunning, |
| 1078 | boolean allowTaskSnapshot, boolean activityCreated, boolean fromRecents) { |
| 1079 | if (DEBUG_STARTING_WINDOW) { |
| 1080 | Slog.v(TAG, "setAppStartingWindow: token=" + appToken |
| 1081 | + " pkg=" + pkg + " transferFrom=" + transferFrom + " newTask=" + newTask |
| 1082 | + " taskSwitch=" + taskSwitch + " processRunning=" + processRunning |
| 1083 | + " allowTaskSnapshot=" + allowTaskSnapshot); |
| 1084 | } |
| 1085 | if (mAppWindowToken == null) { |
| 1086 | Slog.w(TAG_WM, "Attempted to set icon of non-existing app token: " + appToken); |
| 1087 | return false; |
| 1088 | } |
| 1089 | return mAppWindowToken.addStartingWindow(pkg, theme, compatInfo, nonLocalizedLabel, |
| 1090 | labelRes, icon, logo, windowFlags, transferFrom, newTask, taskSwitch, |
| 1091 | processRunning, allowTaskSnapshot, activityCreated, fromRecents); |
| 1092 | } |
| 1093 | |
| 1094 | // TODO: Remove after unification |
| 1095 | @VisibleForTesting |
| 1096 | AppWindowToken createAppWindow(WindowManagerService service, IApplicationToken token, |
| 1097 | boolean voiceInteraction, DisplayContent dc, long inputDispatchingTimeoutNanos, |
| 1098 | boolean fullscreen, boolean showForAllUsers, int targetSdk, int orientation, |
| 1099 | int rotationAnimationHint, int configChanges, boolean launchTaskBehind, |
| 1100 | boolean alwaysFocusable) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1101 | return new AppWindowToken(service, token, mActivityComponent, voiceInteraction, dc, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1102 | inputDispatchingTimeoutNanos, fullscreen, showForAllUsers, targetSdk, orientation, |
| 1103 | rotationAnimationHint, configChanges, launchTaskBehind, alwaysFocusable, |
| 1104 | this); |
| 1105 | } |
| 1106 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1107 | void removeWindowContainer() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1108 | if (mAtmService.mWindowManager.mRoot == null) return; |
Yunfan Chen | d4ef301 | 2018-11-28 21:14:32 -0800 | [diff] [blame] | 1109 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1110 | final DisplayContent dc = mAtmService.mWindowManager.mRoot.getDisplayContent( |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1111 | getDisplayId()); |
| 1112 | if (dc == null) { |
| 1113 | Slog.w(TAG, "removeWindowContainer: Attempted to remove token: " |
| 1114 | + appToken + " from non-existing displayId=" + getDisplayId()); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1115 | return; |
| 1116 | } |
Wale Ogunwale | cc367f4 | 2017-02-01 08:12:14 -0800 | [diff] [blame] | 1117 | // Resume key dispatching if it is currently paused before we remove the container. |
| 1118 | resumeKeyDispatchingLocked(); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1119 | dc.removeAppToken(appToken.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | } |
| 1121 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 1122 | /** |
| 1123 | * Reparents this activity into {@param newTask} at the provided {@param position}. The caller |
| 1124 | * should ensure that the {@param newTask} is not already the parent of this activity. |
| 1125 | */ |
| 1126 | void reparent(TaskRecord newTask, int position, String reason) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1127 | if (mAppWindowToken == null) { |
| 1128 | Slog.w(TAG, "reparent: Attempted to reparent non-existing app token: " + appToken); |
| 1129 | return; |
| 1130 | } |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 1131 | final TaskRecord prevTask = task; |
| 1132 | if (prevTask == newTask) { |
| 1133 | throw new IllegalArgumentException(reason + ": task=" + newTask |
| 1134 | + " is already the parent of r=" + this); |
| 1135 | } |
| 1136 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 1137 | // TODO: Ensure that we do not directly reparent activities across stacks, as that may leave |
| 1138 | // the stacks in strange states. For now, we should use Task.reparent() to ensure that |
| 1139 | // the stack is left in an OK state. |
| 1140 | if (prevTask != null && newTask != null && prevTask.getStack() != newTask.getStack()) { |
| 1141 | throw new IllegalArgumentException(reason + ": task=" + newTask |
| 1142 | + " is in a different stack (" + newTask.getStackId() + ") than the parent of" |
| 1143 | + " r=" + this + " (" + prevTask.getStackId() + ")"); |
| 1144 | } |
| 1145 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1146 | mAppWindowToken.reparent(newTask.getWindowContainerController(), position); |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 1147 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 1148 | // Reparenting prevents informing the parent stack of activity removal in the case that |
| 1149 | // the new stack has the same parent. we must manually signal here if this is not the case. |
| 1150 | final ActivityStack prevStack = prevTask.getStack(); |
| 1151 | |
| 1152 | if (prevStack != newTask.getStack()) { |
| 1153 | prevStack.onActivityRemovedFromStack(this); |
| 1154 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1155 | // Remove the activity from the old task and add it to the new task. |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 1156 | prevTask.removeActivity(this, true /* reparenting */); |
Bryce Lee | 0f9bde8 | 2017-02-22 16:39:06 -0800 | [diff] [blame] | 1157 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 1158 | newTask.addActivityAtIndex(position, this); |
| 1159 | } |
| 1160 | |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 1161 | private boolean isHomeIntent(Intent intent) { |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 1162 | return ACTION_MAIN.equals(intent.getAction()) |
| 1163 | && intent.hasCategory(CATEGORY_HOME) |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 1164 | && intent.getCategories().size() == 1 |
| 1165 | && intent.getData() == null |
| 1166 | && intent.getType() == null; |
| 1167 | } |
| 1168 | |
Chong Zhang | ad24f96 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 1169 | static boolean isMainIntent(Intent intent) { |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 1170 | return ACTION_MAIN.equals(intent.getAction()) |
| 1171 | && intent.hasCategory(CATEGORY_LAUNCHER) |
Chong Zhang | ad24f96 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 1172 | && intent.getCategories().size() == 1 |
| 1173 | && intent.getData() == null |
| 1174 | && intent.getType() == null; |
| 1175 | } |
| 1176 | |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 1177 | private boolean canLaunchHomeActivity(int uid, ActivityRecord sourceRecord) { |
| 1178 | if (uid == Process.myUid() || uid == 0) { |
| 1179 | // System process can launch home activity. |
| 1180 | return true; |
| 1181 | } |
Winson Chung | 547afd2 | 2018-05-17 16:03:25 -0700 | [diff] [blame] | 1182 | // Allow the recents component to launch the home activity. |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 1183 | final RecentTasks recentTasks = mStackSupervisor.mService.getRecentTasks(); |
Winson Chung | 547afd2 | 2018-05-17 16:03:25 -0700 | [diff] [blame] | 1184 | if (recentTasks != null && recentTasks.isCallerRecents(uid)) { |
| 1185 | return true; |
| 1186 | } |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 1187 | // Resolver activity can launch home activity. |
| 1188 | return sourceRecord != null && sourceRecord.isResolverActivity(); |
| 1189 | } |
| 1190 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 1191 | /** |
| 1192 | * @return whether the given package name can launch an assist activity. |
| 1193 | */ |
| 1194 | private boolean canLaunchAssistActivity(String packageName) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 1195 | final ComponentName assistComponent = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1196 | mAtmService.mActiveVoiceInteractionServiceComponent; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 1197 | if (assistComponent != null) { |
| 1198 | return assistComponent.getPackageName().equals(packageName); |
| 1199 | } |
| 1200 | return false; |
| 1201 | } |
| 1202 | |
| 1203 | private void setActivityType(boolean componentSpecified, int launchedFromUid, Intent intent, |
| 1204 | ActivityOptions options, ActivityRecord sourceRecord) { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1205 | int activityType = ACTIVITY_TYPE_UNDEFINED; |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 1206 | if ((!componentSpecified || canLaunchHomeActivity(launchedFromUid, sourceRecord)) |
| 1207 | && isHomeIntent(intent) && !isResolverActivity()) { |
| 1208 | // This sure looks like a home activity! |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1209 | activityType = ACTIVITY_TYPE_HOME; |
Wale Ogunwale | df241e9 | 2016-10-13 15:14:21 -0700 | [diff] [blame] | 1210 | |
| 1211 | if (info.resizeMode == RESIZE_MODE_FORCE_RESIZEABLE |
| 1212 | || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) { |
| 1213 | // We only allow home activities to be resizeable if they explicitly requested it. |
| 1214 | info.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
| 1215 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1216 | } else if (mActivityComponent.getClassName().contains(LEGACY_RECENTS_PACKAGE_NAME) |
| 1217 | || mAtmService.getRecentTasks().isRecentsComponent(mActivityComponent, appInfo.uid)) { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1218 | activityType = ACTIVITY_TYPE_RECENTS; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1219 | } else if (options != null && options.getLaunchActivityType() == ACTIVITY_TYPE_ASSISTANT |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 1220 | && canLaunchAssistActivity(launchedFromPackage)) { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1221 | activityType = ACTIVITY_TYPE_ASSISTANT; |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 1222 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1223 | setActivityType(activityType); |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 1226 | void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) { |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 1227 | if (launchMode != LAUNCH_SINGLE_INSTANCE && launchMode != LAUNCH_SINGLE_TASK) { |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 1228 | task.setTaskToAffiliateWith(taskToAffiliateWith); |
| 1229 | } |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1232 | /** |
| 1233 | * @return Stack value from current task, null if there is no task. |
| 1234 | */ |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1235 | <T extends ActivityStack> T getActivityStack() { |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 1236 | return task != null ? (T) task.getStack() : null; |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 1239 | int getStackId() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1240 | return getActivityStack() != null ? getActivityStack().mStackId : INVALID_STACK_ID; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 1241 | } |
| 1242 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1243 | ActivityDisplay getDisplay() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1244 | final ActivityStack stack = getActivityStack(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1245 | return stack != null ? stack.getDisplay() : null; |
| 1246 | } |
| 1247 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1248 | boolean changeWindowTranslucency(boolean toOpaque) { |
| 1249 | if (fullscreen == toOpaque) { |
| 1250 | return false; |
| 1251 | } |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 1252 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1253 | // Keep track of the number of fullscreen activities in this task. |
| 1254 | task.numFullscreen += toOpaque ? +1 : -1; |
| 1255 | |
| 1256 | fullscreen = toOpaque; |
| 1257 | return true; |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 1258 | } |
| 1259 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1260 | void takeFromHistory() { |
| 1261 | if (inHistory) { |
| 1262 | inHistory = false; |
| 1263 | if (task != null && !finishing) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1264 | task = null; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1265 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 1266 | clearOptionsLocked(); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | boolean isInHistory() { |
| 1271 | return inHistory; |
| 1272 | } |
| 1273 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1274 | boolean isInStackLocked() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1275 | final ActivityStack stack = getActivityStack(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1276 | return stack != null && stack.isInStackLocked(this) != null; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1277 | } |
| 1278 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1279 | boolean isPersistable() { |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 1280 | return (info.persistableMode == PERSIST_ROOT_ONLY || |
| 1281 | info.persistableMode == PERSIST_ACROSS_REBOOTS) && |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 1282 | (intent == null || (intent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1283 | } |
| 1284 | |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1285 | boolean isFocusable() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1286 | return mRootActivityContainer.isFocusable(this, isAlwaysFocusable()); |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | boolean isResizeable() { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1290 | return ActivityInfo.isResizeableMode(info.resizeMode) || info.supportsPictureInPicture(); |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 1291 | } |
| 1292 | |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1293 | /** |
| 1294 | * @return whether this activity is non-resizeable or forced to be resizeable |
| 1295 | */ |
| 1296 | boolean isNonResizableOrForcedResizable() { |
Wale Ogunwale | df241e9 | 2016-10-13 15:14:21 -0700 | [diff] [blame] | 1297 | return info.resizeMode != RESIZE_MODE_RESIZEABLE |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 1298 | && info.resizeMode != RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
Jorim Jaggi | cd13d33 | 2016-04-27 15:40:20 -0700 | [diff] [blame] | 1299 | } |
| 1300 | |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 1301 | /** |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1302 | * @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] | 1303 | */ |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 1304 | boolean supportsPictureInPicture() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1305 | return mAtmService.mSupportsPictureInPicture && isActivityTypeStandardOrUndefined() |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1306 | && info.supportsPictureInPicture(); |
| 1307 | } |
| 1308 | |
| 1309 | /** |
| 1310 | * @return whether this activity supports split-screen multi-window and can be put in the docked |
| 1311 | * stack. |
| 1312 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1313 | @Override |
| 1314 | public boolean supportsSplitScreenWindowingMode() { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1315 | // An activity can not be docked even if it is considered resizeable because it only |
| 1316 | // supports picture-in-picture mode but has a non-resizeable resizeMode |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1317 | return super.supportsSplitScreenWindowingMode() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1318 | && mAtmService.mSupportsSplitScreenMultiWindow && supportsResizeableMultiWindow(); |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | /** |
| 1322 | * @return whether this activity supports freeform multi-window and can be put in the freeform |
| 1323 | * stack. |
| 1324 | */ |
| 1325 | boolean supportsFreeform() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1326 | return mAtmService.mSupportsFreeformWindowManagement && supportsResizeableMultiWindow(); |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | /** |
| 1330 | * @return whether this activity supports non-PiP multi-window. |
| 1331 | */ |
| 1332 | private boolean supportsResizeableMultiWindow() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1333 | return mAtmService.mSupportsMultiWindow && !isActivityTypeHome() |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1334 | && (ActivityInfo.isResizeableMode(info.resizeMode) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1335 | || mAtmService.mForceResizableActivities); |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 1336 | } |
| 1337 | |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 1338 | /** |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 1339 | * Check whether this activity can be launched on the specified display. |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 1340 | * |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 1341 | * @param displayId Target display id. |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 1342 | * @return {@code true} if either it is the default display or this activity can be put on a |
| 1343 | * secondary screen. |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 1344 | */ |
| 1345 | boolean canBeLaunchedOnDisplay(int displayId) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1346 | return mAtmService.mStackSupervisor.canPlaceEntityOnDisplay(displayId, launchedFromPid, |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 1347 | launchedFromUid, info); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | /** |
Robert Carr | c33658e | 2017-04-11 18:24:20 -0700 | [diff] [blame] | 1351 | * @param beforeStopping Whether this check is for an auto-enter-pip operation, that is to say |
| 1352 | * the activity has requested to enter PiP when it would otherwise be stopped. |
| 1353 | * |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 1354 | * @return whether this activity is currently allowed to enter PIP. |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 1355 | */ |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 1356 | boolean checkEnterPictureInPictureState(String caller, boolean beforeStopping) { |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 1357 | if (!supportsPictureInPicture()) { |
| 1358 | return false; |
| 1359 | } |
| 1360 | |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1361 | // Check app-ops and see if PiP is supported for this package |
| 1362 | if (!checkEnterPictureInPictureAppOpsState()) { |
| 1363 | return false; |
| 1364 | } |
| 1365 | |
Winson Chung | f1bfee1 | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1366 | // Check to see if we are in VR mode, and disallow PiP if so |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1367 | if (mAtmService.shouldDisableNonVrUiLocked()) { |
Winson Chung | f1bfee1 | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1368 | return false; |
| 1369 | } |
| 1370 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1371 | boolean isKeyguardLocked = mAtmService.isKeyguardLocked(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 1372 | boolean isCurrentAppLocked = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1373 | mAtmService.getLockTaskModeState() != LOCK_TASK_MODE_NONE; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1374 | final ActivityDisplay display = getDisplay(); |
| 1375 | boolean hasPinnedStack = display != null && display.hasPinnedStack(); |
Winson Chung | bb34880 | 2017-01-30 12:01:45 -0800 | [diff] [blame] | 1376 | // Don't return early if !isNotLocked, since we want to throw an exception if the activity |
| 1377 | // is in an incorrect state |
Winson Chung | e581ebf | 2017-02-21 08:25:03 -0800 | [diff] [blame] | 1378 | boolean isNotLockedOrOnKeyguard = !isKeyguardLocked && !isCurrentAppLocked; |
Robert Carr | c33658e | 2017-04-11 18:24:20 -0700 | [diff] [blame] | 1379 | |
| 1380 | // We don't allow auto-PiP when something else is already pipped. |
| 1381 | if (beforeStopping && hasPinnedStack) { |
| 1382 | return false; |
| 1383 | } |
| 1384 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1385 | switch (mState) { |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 1386 | case RESUMED: |
Winson Chung | e581ebf | 2017-02-21 08:25:03 -0800 | [diff] [blame] | 1387 | // When visible, allow entering PiP if the app is not locked. If it is over the |
| 1388 | // keyguard, then we will prompt to unlock in the caller before entering PiP. |
Robert Carr | c33658e | 2017-04-11 18:24:20 -0700 | [diff] [blame] | 1389 | return !isCurrentAppLocked && |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 1390 | (supportsEnterPipOnTaskSwitch || !beforeStopping); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 1391 | case PAUSING: |
| 1392 | case PAUSED: |
Winson Chung | bb34880 | 2017-01-30 12:01:45 -0800 | [diff] [blame] | 1393 | // When pausing, then only allow enter PiP as in the resume state, and in addition, |
| 1394 | // require that there is not an existing PiP activity and that the current system |
| 1395 | // state supports entering PiP |
Winson Chung | e581ebf | 2017-02-21 08:25:03 -0800 | [diff] [blame] | 1396 | return isNotLockedOrOnKeyguard && !hasPinnedStack |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 1397 | && supportsEnterPipOnTaskSwitch; |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 1398 | case STOPPING: |
| 1399 | // When stopping in a valid state, then only allow enter PiP as in the pause state. |
| 1400 | // Otherwise, fall through to throw an exception if the caller is trying to enter |
| 1401 | // PiP in an invalid stopping state. |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 1402 | if (supportsEnterPipOnTaskSwitch) { |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1403 | return isNotLockedOrOnKeyguard && !hasPinnedStack; |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 1404 | } |
| 1405 | default: |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 1406 | return false; |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 1407 | } |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 1410 | /** |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1411 | * @return Whether AppOps allows this package to enter picture-in-picture. |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 1412 | */ |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1413 | private boolean checkEnterPictureInPictureAppOpsState() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1414 | return mAtmService.getAppOpsService().checkOperation( |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1415 | OP_PICTURE_IN_PICTURE, appInfo.uid, packageName) == MODE_ALLOWED; |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 1416 | } |
| 1417 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 1418 | boolean isAlwaysFocusable() { |
| 1419 | return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1420 | } |
| 1421 | |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 1422 | /** Move activity with its stack to front and make the stack focused. */ |
| 1423 | boolean moveFocusableActivityToTop(String reason) { |
| 1424 | if (!isFocusable()) { |
| 1425 | if (DEBUG_FOCUS) { |
| 1426 | Slog.d(TAG_FOCUS, "moveActivityStackToFront: unfocusable activity=" + this); |
| 1427 | } |
| 1428 | return false; |
| 1429 | } |
| 1430 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1431 | final TaskRecord task = getTaskRecord(); |
| 1432 | final ActivityStack stack = getActivityStack(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 1433 | if (stack == null) { |
| 1434 | Slog.w(TAG, "moveActivityStackToFront: invalid task or stack: activity=" |
| 1435 | + this + " task=" + task); |
| 1436 | return false; |
| 1437 | } |
| 1438 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1439 | if (mRootActivityContainer.getTopResumedActivity() == this) { |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 1440 | if (DEBUG_FOCUS) { |
| 1441 | Slog.d(TAG_FOCUS, "moveActivityStackToFront: already on top, activity=" + this); |
| 1442 | } |
| 1443 | return false; |
| 1444 | } |
| 1445 | |
| 1446 | if (DEBUG_FOCUS) { |
| 1447 | Slog.d(TAG_FOCUS, "moveActivityStackToFront: activity=" + this); |
| 1448 | } |
| 1449 | |
| 1450 | stack.moveToFront(reason, task); |
| 1451 | // Report top activity change to tracking services and WM |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1452 | if (mRootActivityContainer.getTopResumedActivity() == this) { |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 1453 | // TODO(b/111361570): Support multiple focused apps in WM |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1454 | mAtmService.setResumedActivityUncheckLocked(this, reason); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 1455 | } |
| 1456 | return true; |
| 1457 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1458 | |
| 1459 | /** |
| 1460 | * @return true if the activity contains windows that have |
| 1461 | * {@link LayoutParams#FLAG_DISMISS_KEYGUARD} set |
| 1462 | */ |
| 1463 | boolean hasDismissKeyguardWindows() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1464 | return mAtmService.mWindowManager.containsDismissKeyguardWindow(appToken); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1465 | } |
| 1466 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1467 | void makeFinishingLocked() { |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 1468 | if (finishing) { |
| 1469 | return; |
| 1470 | } |
| 1471 | finishing = true; |
| 1472 | if (stopped) { |
| 1473 | clearOptionsLocked(); |
| 1474 | } |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 1475 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1476 | if (mAtmService != null) { |
| 1477 | mAtmService.getTaskChangeNotificationController().notifyTaskStackChanged(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 1478 | } |
| 1479 | } |
| 1480 | |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 1481 | UriPermissionOwner getUriPermissionsLocked() { |
| 1482 | if (uriPermissions == null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1483 | uriPermissions = new UriPermissionOwner(mAtmService.mUgmInternal, this); |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 1484 | } |
| 1485 | return uriPermissions; |
| 1486 | } |
| 1487 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1488 | void addResultLocked(ActivityRecord from, String resultWho, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1489 | int requestCode, int resultCode, |
| 1490 | Intent resultData) { |
| 1491 | ActivityResult r = new ActivityResult(from, resultWho, |
John Spurlock | 8a985d2 | 2014-02-25 09:40:05 -0500 | [diff] [blame] | 1492 | requestCode, resultCode, resultData); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1493 | if (results == null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1494 | results = new ArrayList<ResultInfo>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | } |
| 1496 | results.add(r); |
| 1497 | } |
| 1498 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1499 | void removeResultsLocked(ActivityRecord from, String resultWho, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1500 | int requestCode) { |
| 1501 | if (results != null) { |
| 1502 | for (int i=results.size()-1; i>=0; i--) { |
| 1503 | ActivityResult r = (ActivityResult)results.get(i); |
| 1504 | if (r.mFrom != from) continue; |
| 1505 | if (r.mResultWho == null) { |
| 1506 | if (resultWho != null) continue; |
| 1507 | } else { |
| 1508 | if (!r.mResultWho.equals(resultWho)) continue; |
| 1509 | } |
| 1510 | if (r.mRequestCode != requestCode) continue; |
| 1511 | |
| 1512 | results.remove(i); |
| 1513 | } |
| 1514 | } |
| 1515 | } |
| 1516 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1517 | private void addNewIntentLocked(ReferrerIntent intent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1518 | if (newIntents == null) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 1519 | newIntents = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1520 | } |
| 1521 | newIntents.add(intent); |
| 1522 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1523 | |
Robert Carr | 9e1bf7c | 2018-05-31 15:39:07 -0700 | [diff] [blame] | 1524 | final boolean isSleeping() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1525 | final ActivityStack stack = getActivityStack(); |
| 1526 | return stack != null ? stack.shouldSleepActivities() : mAtmService.isSleepingLocked(); |
Robert Carr | 9e1bf7c | 2018-05-31 15:39:07 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1529 | /** |
| 1530 | * Deliver a new Intent to an existing activity, so that its onNewIntent() |
| 1531 | * method will be called at the proper time. |
| 1532 | */ |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 1533 | final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) { |
Dianne Hackborn | 514074f | 2013-02-11 10:52:46 -0800 | [diff] [blame] | 1534 | // The activity now gets access to the data associated with this Intent. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1535 | mAtmService.mUgmInternal.grantUriPermissionFromIntent(callingUid, packageName, |
| 1536 | intent, getUriPermissionsLocked(), mUserId); |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 1537 | final ReferrerIntent rintent = new ReferrerIntent(intent, referrer); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 1538 | boolean unsent = true; |
Robert Carr | 9e1bf7c | 2018-05-31 15:39:07 -0700 | [diff] [blame] | 1539 | final boolean isTopActivityWhileSleeping = isTopRunningActivity() && isSleeping(); |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 1540 | |
| 1541 | // We want to immediately deliver the intent to the activity if: |
Wale Ogunwale | 03f7e9e | 2016-09-22 09:04:09 -0700 | [diff] [blame] | 1542 | // - It is currently resumed or paused. i.e. it is currently visible to the user and we want |
| 1543 | // 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] | 1544 | // - The device is sleeping and it is the top activity behind the lock screen (b/6700897). |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1545 | if ((mState == RESUMED || mState == PAUSED || isTopActivityWhileSleeping) |
| 1546 | && attachedToProcess()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1547 | try { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 1548 | ArrayList<ReferrerIntent> ar = new ArrayList<>(1); |
| 1549 | ar.add(rintent); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1550 | mAtmService.getLifecycleManager().scheduleTransaction( |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1551 | app.getThread(), appToken, NewIntentItem.obtain(ar, mState == PAUSED)); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 1552 | unsent = false; |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 1553 | } catch (RemoteException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1554 | Slog.w(TAG, "Exception thrown sending new intent to " + this, e); |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 1555 | } catch (NullPointerException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1556 | Slog.w(TAG, "Exception thrown sending new intent to " + this, e); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1557 | } |
| 1558 | } |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 1559 | if (unsent) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 1560 | addNewIntentLocked(rintent); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1561 | } |
| 1562 | } |
| 1563 | |
Dianne Hackborn | 9622ca4 | 2012-10-23 18:56:33 -0700 | [diff] [blame] | 1564 | void updateOptionsLocked(ActivityOptions options) { |
| 1565 | if (options != null) { |
| 1566 | if (pendingOptions != null) { |
| 1567 | pendingOptions.abort(); |
| 1568 | } |
| 1569 | pendingOptions = options; |
| 1570 | } |
| 1571 | } |
| 1572 | |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1573 | void applyOptionsLocked() { |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1574 | if (pendingOptions != null |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 1575 | && pendingOptions.getAnimationType() != ANIM_SCENE_TRANSITION) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1576 | applyOptionsLocked(pendingOptions, intent); |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 1577 | if (task == null) { |
| 1578 | clearOptionsLocked(false /* withAbort */); |
| 1579 | } else { |
| 1580 | // This will clear the options for all the ActivityRecords for this Task. |
| 1581 | task.clearAllPendingOptions(); |
| 1582 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1583 | } |
| 1584 | } |
| 1585 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1586 | /** |
| 1587 | * Apply override app transition base on options & animation type. |
| 1588 | */ |
| 1589 | void applyOptionsLocked(ActivityOptions pendingOptions, Intent intent) { |
| 1590 | final int animationType = pendingOptions.getAnimationType(); |
| 1591 | final DisplayContent displayContent = mAppWindowToken.getDisplayContent(); |
| 1592 | switch (animationType) { |
| 1593 | case ANIM_CUSTOM: |
| 1594 | displayContent.mAppTransition.overridePendingAppTransition( |
| 1595 | pendingOptions.getPackageName(), |
| 1596 | pendingOptions.getCustomEnterResId(), |
| 1597 | pendingOptions.getCustomExitResId(), |
| 1598 | pendingOptions.getOnAnimationStartListener()); |
| 1599 | break; |
| 1600 | case ANIM_CLIP_REVEAL: |
| 1601 | displayContent.mAppTransition.overridePendingAppTransitionClipReveal( |
| 1602 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 1603 | pendingOptions.getWidth(), pendingOptions.getHeight()); |
| 1604 | if (intent.getSourceBounds() == null) { |
| 1605 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 1606 | pendingOptions.getStartY(), |
| 1607 | pendingOptions.getStartX() + pendingOptions.getWidth(), |
| 1608 | pendingOptions.getStartY() + pendingOptions.getHeight())); |
| 1609 | } |
| 1610 | break; |
| 1611 | case ANIM_SCALE_UP: |
| 1612 | displayContent.mAppTransition.overridePendingAppTransitionScaleUp( |
| 1613 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 1614 | pendingOptions.getWidth(), pendingOptions.getHeight()); |
| 1615 | if (intent.getSourceBounds() == null) { |
| 1616 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 1617 | pendingOptions.getStartY(), |
| 1618 | pendingOptions.getStartX() + pendingOptions.getWidth(), |
| 1619 | pendingOptions.getStartY() + pendingOptions.getHeight())); |
| 1620 | } |
| 1621 | break; |
| 1622 | case ANIM_THUMBNAIL_SCALE_UP: |
| 1623 | case ANIM_THUMBNAIL_SCALE_DOWN: |
| 1624 | final boolean scaleUp = (animationType == ANIM_THUMBNAIL_SCALE_UP); |
| 1625 | final GraphicBuffer buffer = pendingOptions.getThumbnail(); |
| 1626 | displayContent.mAppTransition.overridePendingAppTransitionThumb(buffer, |
| 1627 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 1628 | pendingOptions.getOnAnimationStartListener(), |
| 1629 | scaleUp); |
| 1630 | if (intent.getSourceBounds() == null && buffer != null) { |
| 1631 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 1632 | pendingOptions.getStartY(), |
| 1633 | pendingOptions.getStartX() + buffer.getWidth(), |
| 1634 | pendingOptions.getStartY() + buffer.getHeight())); |
| 1635 | } |
| 1636 | break; |
| 1637 | case ANIM_THUMBNAIL_ASPECT_SCALE_UP: |
| 1638 | case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN: |
| 1639 | final AppTransitionAnimationSpec[] specs = pendingOptions.getAnimSpecs(); |
| 1640 | final IAppTransitionAnimationSpecsFuture specsFuture = |
| 1641 | pendingOptions.getSpecsFuture(); |
| 1642 | if (specsFuture != null) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1643 | displayContent.mAppTransition.overridePendingAppTransitionMultiThumbFuture( |
| 1644 | specsFuture, pendingOptions.getOnAnimationStartListener(), |
| 1645 | animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP); |
| 1646 | } else if (animationType == ANIM_THUMBNAIL_ASPECT_SCALE_DOWN |
| 1647 | && specs != null) { |
| 1648 | displayContent.mAppTransition.overridePendingAppTransitionMultiThumb( |
| 1649 | specs, pendingOptions.getOnAnimationStartListener(), |
| 1650 | pendingOptions.getAnimationFinishedListener(), false); |
| 1651 | } else { |
| 1652 | displayContent.mAppTransition.overridePendingAppTransitionAspectScaledThumb( |
| 1653 | pendingOptions.getThumbnail(), |
| 1654 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 1655 | pendingOptions.getWidth(), pendingOptions.getHeight(), |
| 1656 | pendingOptions.getOnAnimationStartListener(), |
| 1657 | (animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP)); |
| 1658 | if (intent.getSourceBounds() == null) { |
| 1659 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 1660 | pendingOptions.getStartY(), |
| 1661 | pendingOptions.getStartX() + pendingOptions.getWidth(), |
| 1662 | pendingOptions.getStartY() + pendingOptions.getHeight())); |
| 1663 | } |
| 1664 | } |
| 1665 | break; |
| 1666 | case ANIM_OPEN_CROSS_PROFILE_APPS: |
| 1667 | displayContent.mAppTransition |
| 1668 | .overridePendingAppTransitionStartCrossProfileApps(); |
| 1669 | break; |
| 1670 | case ANIM_REMOTE_ANIMATION: |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1671 | displayContent.mAppTransition.overridePendingAppTransitionRemote( |
| 1672 | pendingOptions.getRemoteAnimationAdapter()); |
| 1673 | break; |
| 1674 | case ANIM_NONE: |
| 1675 | break; |
| 1676 | default: |
| 1677 | Slog.e(TAG_WM, "applyOptionsLocked: Unknown animationType=" + animationType); |
| 1678 | break; |
| 1679 | } |
| 1680 | } |
| 1681 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1682 | ActivityOptions getOptionsForTargetActivityLocked() { |
| 1683 | return pendingOptions != null ? pendingOptions.forTargetActivity() : null; |
| 1684 | } |
| 1685 | |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1686 | void clearOptionsLocked() { |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 1687 | clearOptionsLocked(true /* withAbort */); |
| 1688 | } |
| 1689 | |
| 1690 | void clearOptionsLocked(boolean withAbort) { |
| 1691 | if (withAbort && pendingOptions != null) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1692 | pendingOptions.abort(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1693 | } |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 1694 | pendingOptions = null; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
Dianne Hackborn | 9622ca4 | 2012-10-23 18:56:33 -0700 | [diff] [blame] | 1697 | ActivityOptions takeOptionsLocked() { |
| 1698 | ActivityOptions opts = pendingOptions; |
| 1699 | pendingOptions = null; |
| 1700 | return opts; |
| 1701 | } |
| 1702 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1703 | void removeUriPermissionsLocked() { |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 1704 | if (uriPermissions != null) { |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 1705 | uriPermissions.removeUriPermissions(); |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 1706 | uriPermissions = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1707 | } |
| 1708 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1709 | |
| 1710 | void pauseKeyDispatchingLocked() { |
| 1711 | if (!keysPaused) { |
| 1712 | keysPaused = true; |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1713 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1714 | // TODO: remove the check after unification with AppWindowToken. The DC check is not |
| 1715 | // needed after no mock mAppWindowToken in tests. |
| 1716 | if (mAppWindowToken != null && mAppWindowToken.getDisplayContent() != null) { |
| 1717 | mAppWindowToken.getDisplayContent().getInputMonitor().pauseDispatchingLw( |
| 1718 | mAppWindowToken); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1719 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1720 | } |
| 1721 | } |
| 1722 | |
| 1723 | void resumeKeyDispatchingLocked() { |
| 1724 | if (keysPaused) { |
| 1725 | keysPaused = false; |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1726 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1727 | // TODO: remove the check after unification with AppWindowToken. The DC check is not |
| 1728 | // needed after no mock mAppWindowToken in tests. |
| 1729 | if (mAppWindowToken != null && mAppWindowToken.getDisplayContent() != null) { |
| 1730 | mAppWindowToken.getDisplayContent().getInputMonitor().resumeDispatchingLw( |
| 1731 | mAppWindowToken); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1732 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1733 | } |
| 1734 | } |
| 1735 | |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 1736 | private void updateTaskDescription(CharSequence description) { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1737 | task.lastDescription = description; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1740 | void setDeferHidingClient(boolean deferHidingClient) { |
| 1741 | if (mDeferHidingClient == deferHidingClient) { |
| 1742 | return; |
| 1743 | } |
| 1744 | mDeferHidingClient = deferHidingClient; |
| 1745 | if (!mDeferHidingClient && !visible) { |
| 1746 | // Hiding the client is no longer deferred and the app isn't visible still, go ahead and |
| 1747 | // update the visibility. |
| 1748 | setVisibility(false); |
| 1749 | } |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1752 | void setVisibility(boolean visible) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1753 | if (mAppWindowToken == null) { |
| 1754 | Slog.w(TAG_WM, "Attempted to set visibility of non-existing app token: " |
| 1755 | + appToken); |
| 1756 | return; |
| 1757 | } |
| 1758 | mAppWindowToken.setVisibility(visible, mDeferHidingClient); |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 1759 | mStackSupervisor.getActivityMetricsLogger().notifyVisibilityChanged(this); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1760 | } |
| 1761 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1762 | // TODO: Look into merging with #commitVisibility() |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1763 | void setVisible(boolean newVisible) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1764 | visible = newVisible; |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1765 | mDeferHidingClient = !visible && mDeferHidingClient; |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1766 | setVisibility(visible); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1767 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; |
| 1768 | } |
| 1769 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1770 | void setState(ActivityState state, String reason) { |
| 1771 | if (DEBUG_STATES) Slog.v(TAG_STATES, "State movement: " + this + " from:" + getState() |
| 1772 | + " to:" + state + " reason:" + reason); |
Bryce Lee | 6ff1707 | 2018-02-28 07:26:17 -0800 | [diff] [blame] | 1773 | |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 1774 | if (state == mState) { |
| 1775 | // No need to do anything if state doesn't change. |
| 1776 | if (DEBUG_STATES) Slog.v(TAG_STATES, "State unchanged from:" + state); |
| 1777 | return; |
| 1778 | } |
| 1779 | |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 1780 | mState = state; |
| 1781 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1782 | final TaskRecord parent = getTaskRecord(); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1783 | |
| 1784 | if (parent != null) { |
| 1785 | parent.onActivityStateChanged(this, state, reason); |
| 1786 | } |
Robert Carr | 29daa92 | 2018-04-27 11:56:48 -0700 | [diff] [blame] | 1787 | |
Robert Carr | 9e1bf7c | 2018-05-31 15:39:07 -0700 | [diff] [blame] | 1788 | // The WindowManager interprets the app stopping signal as |
| 1789 | // an indication that the Surface will eventually be destroyed. |
| 1790 | // This however isn't necessarily true if we are going to sleep. |
| 1791 | if (state == STOPPING && !isSleeping()) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1792 | if (mAppWindowToken == null) { |
| 1793 | Slog.w(TAG_WM, "Attempted to notify stopping on non-existing app token: " |
| 1794 | + appToken); |
| 1795 | return; |
| 1796 | } |
| 1797 | mAppWindowToken.detachChildren(); |
Robert Carr | 29daa92 | 2018-04-27 11:56:48 -0700 | [diff] [blame] | 1798 | } |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | ActivityState getState() { |
| 1802 | return mState; |
| 1803 | } |
| 1804 | |
| 1805 | /** |
| 1806 | * Returns {@code true} if the Activity is in the specified state. |
| 1807 | */ |
| 1808 | boolean isState(ActivityState state) { |
| 1809 | return state == mState; |
| 1810 | } |
| 1811 | |
| 1812 | /** |
| 1813 | * Returns {@code true} if the Activity is in one of the specified states. |
| 1814 | */ |
| 1815 | boolean isState(ActivityState state1, ActivityState state2) { |
| 1816 | return state1 == mState || state2 == mState; |
| 1817 | } |
| 1818 | |
| 1819 | /** |
| 1820 | * Returns {@code true} if the Activity is in one of the specified states. |
| 1821 | */ |
| 1822 | boolean isState(ActivityState state1, ActivityState state2, ActivityState state3) { |
| 1823 | return state1 == mState || state2 == mState || state3 == mState; |
| 1824 | } |
| 1825 | |
| 1826 | /** |
| 1827 | * Returns {@code true} if the Activity is in one of the specified states. |
| 1828 | */ |
| 1829 | boolean isState(ActivityState state1, ActivityState state2, ActivityState state3, |
| 1830 | ActivityState state4) { |
| 1831 | return state1 == mState || state2 == mState || state3 == mState || state4 == mState; |
| 1832 | } |
| 1833 | |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 1834 | void notifyAppResumed(boolean wasStopped) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1835 | if (mAppWindowToken == null) { |
| 1836 | Slog.w(TAG_WM, "Attempted to notify resumed of non-existing app token: " |
| 1837 | + appToken); |
| 1838 | return; |
| 1839 | } |
| 1840 | mAppWindowToken.notifyAppResumed(wasStopped); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | void notifyUnknownVisibilityLaunched() { |
Jorim Jaggi | 838c245 | 2017-08-28 15:44:43 +0200 | [diff] [blame] | 1844 | |
| 1845 | // No display activities never add a window, so there is no point in waiting them for |
| 1846 | // relayout. |
| 1847 | if (!noDisplay) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1848 | if (mAppWindowToken != null) { |
| 1849 | mAppWindowToken.getDisplayContent().mUnknownAppVisibilityController |
| 1850 | .notifyLaunched(mAppWindowToken); |
| 1851 | } |
Jorim Jaggi | 838c245 | 2017-08-28 15:44:43 +0200 | [diff] [blame] | 1852 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1853 | } |
| 1854 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1855 | /** |
| 1856 | * @return true if the input activity should be made visible, ignoring any effect Keyguard |
| 1857 | * might have on the visibility |
| 1858 | * |
| 1859 | * @see {@link ActivityStack#checkKeyguardVisibility} |
| 1860 | */ |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 1861 | boolean shouldBeVisibleIgnoringKeyguard(boolean behindFullscreenActivity) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1862 | if (!okToShowLocked()) { |
| 1863 | return false; |
| 1864 | } |
| 1865 | |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 1866 | return !behindFullscreenActivity || mLaunchTaskBehind; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1867 | } |
| 1868 | |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1869 | void makeVisibleIfNeeded(ActivityRecord starting, boolean reportToClient) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1870 | // This activity is not currently visible, but is running. Tell it to become visible. |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1871 | if (mState == RESUMED || this == starting) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1872 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1873 | "Not making visible, r=" + this + " state=" + mState + " starting=" + starting); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1874 | return; |
| 1875 | } |
| 1876 | |
| 1877 | // If this activity is paused, tell it to now show its window. |
| 1878 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1879 | "Making visible and scheduling visibility: " + this); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1880 | final ActivityStack stack = getActivityStack(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1881 | try { |
| 1882 | if (stack.mTranslucentActivityWaiting != null) { |
| 1883 | updateOptionsLocked(returningOptions); |
| 1884 | stack.mUndrawnActivitiesBelowTopTranslucent.add(this); |
| 1885 | } |
| 1886 | setVisible(true); |
| 1887 | sleeping = false; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1888 | app.postPendingUiCleanMsg(true); |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1889 | if (reportToClient) { |
| 1890 | makeClientVisible(); |
| 1891 | } else { |
| 1892 | mClientVisibilityDeferred = true; |
| 1893 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1894 | // The activity may be waiting for stop, but that is no longer appropriate for it. |
| 1895 | mStackSupervisor.mStoppingActivities.remove(this); |
| 1896 | mStackSupervisor.mGoingToSleepActivities.remove(this); |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1897 | } catch (Exception e) { |
| 1898 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 1899 | Slog.w(TAG, "Exception thrown making visible: " + intent.getComponent(), e); |
| 1900 | } |
| 1901 | handleAlreadyVisible(); |
| 1902 | } |
Andrii Kulian | 0d595f3 | 2018-02-21 15:47:33 -0800 | [diff] [blame] | 1903 | |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1904 | /** Send visibility change message to the client and pause if needed. */ |
| 1905 | void makeClientVisible() { |
| 1906 | mClientVisibilityDeferred = false; |
| 1907 | try { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1908 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1909 | WindowVisibilityItem.obtain(true /* showWindow */)); |
Andrii Kulian | 09e1afa | 2018-05-16 21:29:34 -0700 | [diff] [blame] | 1910 | if (shouldPauseWhenBecomingVisible()) { |
Andrii Kulian | 0d595f3 | 2018-02-21 15:47:33 -0800 | [diff] [blame] | 1911 | // An activity must be in the {@link PAUSING} state for the system to validate |
| 1912 | // the move to {@link PAUSED}. |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1913 | setState(PAUSING, "makeVisibleIfNeeded"); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1914 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Andrii Kulian | 0d595f3 | 2018-02-21 15:47:33 -0800 | [diff] [blame] | 1915 | PauseActivityItem.obtain(finishing, false /* userLeaving */, |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 1916 | configChangeFlags, false /* dontReport */)); |
Andrii Kulian | 0d595f3 | 2018-02-21 15:47:33 -0800 | [diff] [blame] | 1917 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1918 | } catch (Exception e) { |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1919 | Slog.w(TAG, "Exception thrown sending visibility update: " + intent.getComponent(), e); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1920 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1921 | } |
| 1922 | |
Andrii Kulian | 09e1afa | 2018-05-16 21:29:34 -0700 | [diff] [blame] | 1923 | /** Check if activity should be moved to PAUSED state when it becomes visible. */ |
| 1924 | private boolean shouldPauseWhenBecomingVisible() { |
| 1925 | // If the activity is stopped or stopping, cycle to the paused state. We avoid doing |
| 1926 | // this when there is an activity waiting to become translucent as the extra binder |
| 1927 | // calls will lead to noticeable jank. A later call to |
| 1928 | // ActivityStack#ensureActivitiesVisibleLocked will bring the activity to the proper |
| 1929 | // paused state. We also avoid doing this for the activity the stack supervisor |
| 1930 | // considers the resumed activity, as normal means will bring the activity from STOPPED |
| 1931 | // to RESUMED. Adding PAUSING in this scenario will lead to double lifecycles. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1932 | if (!isState(STOPPED, STOPPING) || getActivityStack().mTranslucentActivityWaiting != null |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1933 | || isResumedActivityOnDisplay()) { |
Andrii Kulian | 09e1afa | 2018-05-16 21:29:34 -0700 | [diff] [blame] | 1934 | return false; |
| 1935 | } |
| 1936 | |
| 1937 | // Check if position in task allows to become paused |
| 1938 | final int positionInTask = task.mActivities.indexOf(this); |
| 1939 | if (positionInTask == -1) { |
| 1940 | throw new IllegalStateException("Activity not found in its task"); |
| 1941 | } |
| 1942 | if (positionInTask == task.mActivities.size() - 1) { |
| 1943 | // It's the topmost activity in the task - should become paused now |
| 1944 | return true; |
| 1945 | } |
| 1946 | // Check if activity above is finishing now and this one becomes the topmost in task. |
| 1947 | final ActivityRecord activityAbove = task.mActivities.get(positionInTask + 1); |
| 1948 | if (activityAbove.finishing && results == null) { |
| 1949 | // We will only allow pausing if activity above wasn't launched for result. Otherwise it |
| 1950 | // will cause this activity to resume before getting result. |
| 1951 | return true; |
| 1952 | } |
| 1953 | return false; |
| 1954 | } |
| 1955 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1956 | boolean handleAlreadyVisible() { |
| 1957 | stopFreezingScreenLocked(false); |
| 1958 | try { |
| 1959 | if (returningOptions != null) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1960 | app.getThread().scheduleOnNewActivityOptions(appToken, returningOptions.toBundle()); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1961 | } |
| 1962 | } catch(RemoteException e) { |
| 1963 | } |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1964 | return mState == RESUMED; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | static void activityResumedLocked(IBinder token) { |
| 1968 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 1969 | if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r); |
| 1970 | if (r != null) { |
| 1971 | r.icicle = null; |
| 1972 | r.haveState = false; |
| 1973 | } |
| 1974 | } |
| 1975 | |
| 1976 | /** |
| 1977 | * Once we know that we have asked an application to put an activity in the resumed state |
| 1978 | * (either by launching it or explicitly telling it), this function updates the rest of our |
| 1979 | * state to match that fact. |
| 1980 | */ |
| 1981 | void completeResumeLocked() { |
| 1982 | final boolean wasVisible = visible; |
Jorim Jaggi | 8d06205 | 2017-08-22 14:55:17 +0200 | [diff] [blame] | 1983 | setVisible(true); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1984 | if (!wasVisible) { |
| 1985 | // Visibility has changed, so take a note of it so we call the TaskStackChangedListener |
| 1986 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; |
| 1987 | } |
| 1988 | idle = false; |
| 1989 | results = null; |
| 1990 | newIntents = null; |
| 1991 | stopped = false; |
| 1992 | |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1993 | if (isActivityTypeHome()) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1994 | WindowProcessController app = task.mActivities.get(0).app; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1995 | if (hasProcess() && app != mAtmService.mHomeProcess) { |
| 1996 | mAtmService.mHomeProcess = app; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1997 | } |
| 1998 | } |
| 1999 | |
| 2000 | if (nowVisible) { |
| 2001 | // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now. |
| 2002 | mStackSupervisor.reportActivityVisibleLocked(this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | // Schedule an idle timeout in case the app doesn't do it for us. |
| 2006 | mStackSupervisor.scheduleIdleTimeoutLocked(this); |
| 2007 | |
| 2008 | mStackSupervisor.reportResumedActivityLocked(this); |
| 2009 | |
| 2010 | resumeKeyDispatchingLocked(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2011 | final ActivityStack stack = getActivityStack(); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2012 | mStackSupervisor.mNoAnimActivities.clear(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2013 | |
| 2014 | // Mark the point when the activity is resuming |
| 2015 | // TODO: To be more accurate, the mark should be before the onCreate, |
| 2016 | // not after the onResume. But for subsequent starts, onResume is fine. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2017 | if (hasProcess()) { |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 2018 | cpuTimeAtResume = app.getCpuTime(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2019 | } else { |
| 2020 | cpuTimeAtResume = 0; // Couldn't get the cpu time of process |
| 2021 | } |
| 2022 | |
| 2023 | returningOptions = null; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2024 | |
| 2025 | if (canTurnScreenOn()) { |
| 2026 | mStackSupervisor.wakeUp("turnScreenOnFlag"); |
| 2027 | } else { |
| 2028 | // If the screen is going to turn on because the caller explicitly requested it and |
| 2029 | // the keyguard is not showing don't attempt to sleep. Otherwise the Activity will |
| 2030 | // pause and then resume again later, which will result in a double life-cycle event. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2031 | stack.checkReadyForSleep(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2032 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | final void activityStoppedLocked(Bundle newIcicle, PersistableBundle newPersistentState, |
| 2036 | CharSequence description) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2037 | final ActivityStack stack = getActivityStack(); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2038 | if (mState != STOPPING) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2039 | Slog.i(TAG, "Activity reported stop, but no longer stopping: " + this); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2040 | stack.mHandler.removeMessages(STOP_TIMEOUT_MSG, this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2041 | return; |
| 2042 | } |
| 2043 | if (newPersistentState != null) { |
| 2044 | persistentState = newPersistentState; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2045 | mAtmService.notifyTaskPersisterLocked(task, false); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2046 | } |
| 2047 | 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] | 2048 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2049 | if (newIcicle != null) { |
| 2050 | // If icicle is null, this is happening due to a timeout, so we haven't really saved |
| 2051 | // the state. |
| 2052 | icicle = newIcicle; |
| 2053 | haveState = true; |
| 2054 | launchCount = 0; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 2055 | updateTaskDescription(description); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2056 | } |
| 2057 | if (!stopped) { |
| 2058 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to STOPPED: " + this + " (stop complete)"); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2059 | stack.mHandler.removeMessages(STOP_TIMEOUT_MSG, this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2060 | stopped = true; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2061 | setState(STOPPED, "activityStoppedLocked"); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2062 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2063 | if (mAppWindowToken != null) { |
| 2064 | mAppWindowToken.notifyAppStopped(); |
| 2065 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2066 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2067 | if (finishing) { |
| 2068 | clearOptionsLocked(); |
| 2069 | } else { |
| 2070 | if (deferRelaunchUntilPaused) { |
| 2071 | stack.destroyActivityLocked(this, true /* removeFromApp */, "stop-config"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2072 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2073 | } else { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2074 | mRootActivityContainer.updatePreviousProcess(this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2075 | } |
| 2076 | } |
| 2077 | } |
| 2078 | } |
| 2079 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2080 | void startLaunchTickingLocked() { |
Jeff Sharkey | 5ab0243 | 2017-06-27 11:01:36 -0600 | [diff] [blame] | 2081 | if (Build.IS_USER) { |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2082 | return; |
| 2083 | } |
| 2084 | if (launchTickTime == 0) { |
| 2085 | launchTickTime = SystemClock.uptimeMillis(); |
| 2086 | continueLaunchTickingLocked(); |
| 2087 | } |
| 2088 | } |
| 2089 | |
| 2090 | boolean continueLaunchTickingLocked() { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2091 | if (launchTickTime == 0) { |
| 2092 | return false; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2093 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2094 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2095 | final ActivityStack stack = getActivityStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2096 | if (stack == null) { |
| 2097 | return false; |
| 2098 | } |
| 2099 | |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2100 | Message msg = stack.mHandler.obtainMessage(LAUNCH_TICK_MSG, this); |
| 2101 | stack.mHandler.removeMessages(LAUNCH_TICK_MSG); |
| 2102 | stack.mHandler.sendMessageDelayed(msg, LAUNCH_TICK); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2103 | return true; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | void finishLaunchTickingLocked() { |
| 2107 | launchTickTime = 0; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2108 | final ActivityStack stack = getActivityStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2109 | if (stack != null) { |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2110 | stack.mHandler.removeMessages(LAUNCH_TICK_MSG); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2111 | } |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2114 | // IApplicationToken |
| 2115 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2116 | public boolean mayFreezeScreenLocked(WindowProcessController app) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2117 | // Only freeze the screen if this activity is currently attached to |
| 2118 | // an application, and that application is not blocked or unresponding. |
| 2119 | // In any other case, we can't count on getting the screen unfrozen, |
| 2120 | // so it is best to leave as-is. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2121 | return hasProcess() && !app.isCrashing() && !app.isNotResponding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2122 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 2123 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2124 | public void startFreezingScreenLocked(WindowProcessController app, int configChanges) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2125 | if (mayFreezeScreenLocked(app)) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2126 | if (mAppWindowToken == null) { |
| 2127 | Slog.w(TAG_WM, |
| 2128 | "Attempted to freeze screen with non-existing app token: " + appToken); |
| 2129 | return; |
| 2130 | } |
| 2131 | |
| 2132 | if (configChanges == 0 && mAppWindowToken.okToDisplay()) { |
| 2133 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Skipping set freeze of " + appToken); |
| 2134 | return; |
| 2135 | } |
| 2136 | |
| 2137 | mAppWindowToken.startFreezingScreen(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2138 | } |
| 2139 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 2140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2141 | public void stopFreezingScreenLocked(boolean force) { |
| 2142 | if (force || frozenBeforeDestroy) { |
| 2143 | frozenBeforeDestroy = false; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2144 | if (mAppWindowToken == null) { |
| 2145 | return; |
| 2146 | } |
| 2147 | if (DEBUG_ORIENTATION) { |
| 2148 | Slog.v(TAG_WM, "Clear freezing of " + appToken + ": hidden=" |
| 2149 | + mAppWindowToken.isHidden() + " freezing=" |
| 2150 | + mAppWindowToken.isFreezingScreen()); |
| 2151 | } |
| 2152 | mAppWindowToken.stopFreezingScreen(true, force); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2153 | } |
| 2154 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 2155 | |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 2156 | public void reportFullyDrawnLocked(boolean restoredFromBundle) { |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 2157 | final WindowingModeTransitionInfoSnapshot info = mStackSupervisor |
| 2158 | .getActivityMetricsLogger().logAppTransitionReportedDrawn(this, restoredFromBundle); |
| 2159 | if (info != null) { |
| 2160 | mStackSupervisor.reportActivityLaunchedLocked(false /* timeout */, this, |
| 2161 | info.windowsFullyDrawnDelayMs); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 2162 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 2163 | } |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2164 | |
| 2165 | /** |
| 2166 | * Called when the starting window for this container is drawn. |
| 2167 | */ |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 2168 | public void onStartingWindowDrawn(long timestamp) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2169 | synchronized (mAtmService.mGlobalLock) { |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2170 | mStackSupervisor.getActivityMetricsLogger().notifyStartingWindowDrawn( |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 2171 | getWindowingMode(), timestamp); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 2172 | } |
| 2173 | } |
| 2174 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2175 | /** Called when the windows associated app window container are drawn. */ |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 2176 | public void onWindowsDrawn(boolean drawn, long timestamp) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2177 | synchronized (mAtmService.mGlobalLock) { |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 2178 | mDrawn = drawn; |
| 2179 | if (!drawn) { |
| 2180 | return; |
| 2181 | } |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 2182 | final WindowingModeTransitionInfoSnapshot info = mStackSupervisor |
| 2183 | .getActivityMetricsLogger().notifyWindowsDrawn(getWindowingMode(), timestamp); |
| 2184 | final int windowsDrawnDelayMs = info != null ? info.windowsDrawnDelayMs : INVALID_DELAY; |
| 2185 | mStackSupervisor.reportActivityLaunchedLocked(false /* timeout */, this, |
| 2186 | windowsDrawnDelayMs); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2187 | mStackSupervisor.sendWaitingVisibleReportLocked(this); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2188 | finishLaunchTickingLocked(); |
| 2189 | if (task != null) { |
| 2190 | task.hasBeenVisible = true; |
| 2191 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2192 | } |
| 2193 | } |
| 2194 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2195 | /** Called when the windows associated app window container are visible. */ |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2196 | public void onWindowsVisible() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2197 | synchronized (mAtmService.mGlobalLock) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2198 | mStackSupervisor.reportActivityVisibleLocked(this); |
| 2199 | if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this); |
| 2200 | if (!nowVisible) { |
| 2201 | nowVisible = true; |
| 2202 | lastVisibleTime = SystemClock.uptimeMillis(); |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 2203 | if (idle || mStackSupervisor.isStoppingNoHistoryActivity()) { |
| 2204 | // If this activity was already idle or there is an activity that must be |
| 2205 | // stopped immediately after visible, then we now need to make sure we perform |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2206 | // the full stop of any activities that are waiting to do so. This is because |
| 2207 | // we won't do that while they are still waiting for this one to become visible. |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2208 | final int size = mStackSupervisor.mActivitiesWaitingForVisibleActivity.size(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2209 | if (size > 0) { |
| 2210 | for (int i = 0; i < size; i++) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2211 | final ActivityRecord r = |
| 2212 | mStackSupervisor.mActivitiesWaitingForVisibleActivity.get(i); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2213 | if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "Was waiting for visible: " + r); |
| 2214 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2215 | mStackSupervisor.mActivitiesWaitingForVisibleActivity.clear(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2216 | mStackSupervisor.scheduleIdleLocked(); |
| 2217 | } |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 2218 | } else { |
| 2219 | // Instead of doing the full stop routine here, let's just hide any activities |
| 2220 | // we now can, and let them stop when the normal idle happens. |
| 2221 | mStackSupervisor.processStoppingActivitiesLocked(null /* idleActivity */, |
| 2222 | false /* remove */, true /* processPausingActivities */); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2223 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2224 | mAtmService.scheduleAppGcsLocked(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2225 | } |
| 2226 | } |
| 2227 | } |
| 2228 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2229 | /** Called when the windows associated app window container are no longer visible. */ |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2230 | public void onWindowsGone() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2231 | synchronized (mAtmService.mGlobalLock) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2232 | if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + this); |
| 2233 | nowVisible = false; |
| 2234 | } |
| 2235 | } |
| 2236 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2237 | /** |
| 2238 | * Called when the key dispatching to a window associated with the app window container |
| 2239 | * timed-out. |
| 2240 | * |
| 2241 | * @param reason The reason for the key dispatching time out. |
| 2242 | * @param windowPid The pid of the window key dispatching timed out on. |
| 2243 | * @return True if input dispatching should be aborted. |
| 2244 | */ |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 2245 | public boolean keyDispatchingTimedOut(String reason, int windowPid) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2246 | ActivityRecord anrActivity; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2247 | WindowProcessController anrApp; |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 2248 | boolean windowFromSameProcessAsActivity; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2249 | synchronized (mAtmService.mGlobalLock) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2250 | anrActivity = getWaitingHistoryRecordLocked(); |
| 2251 | anrApp = app; |
Brian Carlstrom | 7b0f2e8 | 2017-03-31 00:24:18 -0700 | [diff] [blame] | 2252 | windowFromSameProcessAsActivity = |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2253 | !hasProcess() || app.getPid() == windowPid || windowPid == -1; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2254 | } |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 2255 | |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 2256 | if (windowFromSameProcessAsActivity) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2257 | return mAtmService.mAmInternal.inputDispatchingTimedOut(anrApp.mOwner, |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 2258 | anrActivity.shortComponentName, anrActivity.appInfo, shortComponentName, |
| 2259 | app, false, reason); |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 2260 | } else { |
| 2261 | // In this case another process added windows using this activity token. So, we call the |
| 2262 | // generic service input dispatch timed out method so that the right process is blamed. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2263 | return mAtmService.mAmInternal.inputDispatchingTimedOut( |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 2264 | windowPid, false /* aboveSystem */, reason) < 0; |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 2265 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | private ActivityRecord getWaitingHistoryRecordLocked() { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 2269 | // First find the real culprit... if this activity is waiting for |
| 2270 | // another activity to start or has stopped, then the key dispatching |
| 2271 | // timeout should not be caused by this. |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2272 | if (mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(this) || stopped) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2273 | final ActivityStack stack = mRootActivityContainer.getTopDisplayFocusedStack(); |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 2274 | // Try to use the one which is closest to top. |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2275 | ActivityRecord r = stack.getResumedActivity(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2276 | if (r == null) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2277 | r = stack.mPausingActivity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2278 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 2279 | if (r != null) { |
| 2280 | return r; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2281 | } |
| 2282 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 2283 | return this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2284 | } |
| 2285 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 2286 | /** Checks whether the activity should be shown for current user. */ |
| 2287 | public boolean okToShowLocked() { |
Bryce Lee | 8558ec7 | 2017-08-17 15:37:26 -0700 | [diff] [blame] | 2288 | // We cannot show activities when the device is locked and the application is not |
| 2289 | // encryption aware. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2290 | if (!StorageManager.isUserKeyUnlocked(mUserId) |
Bryce Lee | 8558ec7 | 2017-08-17 15:37:26 -0700 | [diff] [blame] | 2291 | && !info.applicationInfo.isEncryptionAware()) { |
| 2292 | return false; |
| 2293 | } |
| 2294 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 2295 | return (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0 |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2296 | || (mStackSupervisor.isCurrentProfileLocked(mUserId) |
| 2297 | && mAtmService.mAmInternal.isUserRunning(mUserId, 0 /* flags */)); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2300 | /** |
| 2301 | * This method will return true if the activity is either visible, is becoming visible, is |
| 2302 | * currently pausing, or is resumed. |
| 2303 | */ |
| 2304 | public boolean isInterestingToUserLocked() { |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2305 | return visible || nowVisible || mState == PAUSING || mState == RESUMED; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2306 | } |
| 2307 | |
Wale Ogunwale | 3e99736 | 2016-09-06 10:37:56 -0700 | [diff] [blame] | 2308 | void setSleeping(boolean _sleeping) { |
| 2309 | setSleeping(_sleeping, false); |
| 2310 | } |
| 2311 | |
| 2312 | void setSleeping(boolean _sleeping, boolean force) { |
| 2313 | if (!force && sleeping == _sleeping) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2314 | return; |
| 2315 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2316 | if (attachedToProcess()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2317 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2318 | app.getThread().scheduleSleeping(appToken, _sleeping); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2319 | if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) { |
| 2320 | mStackSupervisor.mGoingToSleepActivities.add(this); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2321 | } |
| 2322 | sleeping = _sleeping; |
| 2323 | } catch (RemoteException e) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2324 | Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2325 | } |
| 2326 | } |
| 2327 | } |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 2328 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2329 | static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2330 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2331 | if (r == null) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 2332 | return INVALID_TASK_ID; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2333 | } |
| 2334 | final TaskRecord task = r.task; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2335 | final int activityNdx = task.mActivities.indexOf(r); |
| 2336 | if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 2337 | return INVALID_TASK_ID; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2338 | } |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2339 | return task.taskId; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | static ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2343 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2344 | return (r != null) ? r.getActivityStack().isInStackLocked(r) : null; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2345 | } |
| 2346 | |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 2347 | static ActivityStack getStackLocked(IBinder token) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2348 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2349 | if (r != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2350 | return r.getActivityStack(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2351 | } |
| 2352 | return null; |
| 2353 | } |
| 2354 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2355 | /** |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 2356 | * @return display id to which this record is attached, |
| 2357 | * {@link android.view.Display#INVALID_DISPLAY} if not attached. |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2358 | */ |
| 2359 | int getDisplayId() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2360 | final ActivityStack stack = getActivityStack(); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2361 | if (stack == null) { |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 2362 | return INVALID_DISPLAY; |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2363 | } |
| 2364 | return stack.mDisplayId; |
| 2365 | } |
| 2366 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2367 | final boolean isDestroyable() { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2368 | if (finishing || !hasProcess()) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2369 | // This would be redundant. |
| 2370 | return false; |
| 2371 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2372 | final ActivityStack stack = getActivityStack(); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2373 | if (stack == null || this == stack.getResumedActivity() || this == stack.mPausingActivity |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2374 | || !haveState || !stopped) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2375 | // We're not ready for this kind of thing. |
| 2376 | return false; |
| 2377 | } |
| 2378 | if (visible) { |
| 2379 | // The user would notice this! |
| 2380 | return false; |
| 2381 | } |
| 2382 | return true; |
| 2383 | } |
| 2384 | |
Winson Chung | 3bad5cc0 | 2014-08-19 17:44:32 -0700 | [diff] [blame] | 2385 | private static String createImageFilename(long createTime, int taskId) { |
| 2386 | return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime + |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2387 | IMAGE_EXTENSION; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 2388 | } |
| 2389 | |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 2390 | void setTaskDescription(TaskDescription _taskDescription) { |
| 2391 | Bitmap icon; |
| 2392 | if (_taskDescription.getIconFilename() == null && |
| 2393 | (icon = _taskDescription.getIcon()) != null) { |
| 2394 | final String iconFilename = createImageFilename(createTime, task.taskId); |
Winson Chung | c8408b8 | 2017-01-25 17:58:56 -0800 | [diff] [blame] | 2395 | final File iconFile = new File(TaskPersister.getUserImagesDir(task.userId), |
| 2396 | iconFilename); |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 2397 | final String iconFilePath = iconFile.getAbsolutePath(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2398 | mAtmService.getRecentTasks().saveImage(icon, iconFilePath); |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 2399 | _taskDescription.setIconFilename(iconFilePath); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 2400 | } |
| 2401 | taskDescription = _taskDescription; |
| 2402 | } |
| 2403 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 2404 | void setVoiceSessionLocked(IVoiceInteractionSession session) { |
| 2405 | voiceSession = session; |
| 2406 | pendingVoiceInteractionStart = false; |
| 2407 | } |
| 2408 | |
| 2409 | void clearVoiceSessionLocked() { |
| 2410 | voiceSession = null; |
| 2411 | pendingVoiceInteractionStart = false; |
| 2412 | } |
| 2413 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2414 | void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch) { |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 2415 | showStartingWindow(prev, newTask, taskSwitch, false /* fromRecents */); |
| 2416 | } |
| 2417 | |
| 2418 | void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch, |
| 2419 | boolean fromRecents) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2420 | if (mAppWindowToken == null) { |
Jorim Jaggi | 7017643 | 2017-01-18 12:52:13 +0100 | [diff] [blame] | 2421 | return; |
| 2422 | } |
Wale Ogunwale | 19866e2 | 2017-04-19 06:05:13 -0700 | [diff] [blame] | 2423 | if (mTaskOverlay) { |
| 2424 | // We don't show starting window for overlay activities. |
| 2425 | return; |
| 2426 | } |
Sunny Goyal | d85bed5 | 2018-09-25 12:01:01 -0700 | [diff] [blame] | 2427 | if (pendingOptions != null |
| 2428 | && pendingOptions.getAnimationType() == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 2429 | // Don't show starting window when using shared element transition. |
| 2430 | return; |
| 2431 | } |
Wale Ogunwale | 19866e2 | 2017-04-19 06:05:13 -0700 | [diff] [blame] | 2432 | |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2433 | final CompatibilityInfo compatInfo = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2434 | mAtmService.compatibilityInfoForPackageLocked(info.applicationInfo); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2435 | final boolean shown = addStartingWindow(packageName, theme, |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2436 | compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags, |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 2437 | prev != null ? prev.appToken : null, newTask, taskSwitch, isProcessRunning(), |
Jorim Jaggi | 70aa4d1 | 2017-05-15 00:05:54 +0200 | [diff] [blame] | 2438 | allowTaskSnapshot(), |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2439 | mState.ordinal() >= RESUMED.ordinal() && mState.ordinal() <= STOPPED.ordinal(), |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 2440 | fromRecents); |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2441 | if (shown) { |
| 2442 | mStartingWindowState = STARTING_WINDOW_SHOWN; |
| 2443 | } |
| 2444 | } |
| 2445 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2446 | void removeOrphanedStartingWindow(boolean behindFullscreenActivity) { |
Jorim Jaggi | cb95605 | 2017-05-09 16:27:24 +0200 | [diff] [blame] | 2447 | if (mStartingWindowState == STARTING_WINDOW_SHOWN && behindFullscreenActivity) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2448 | if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, "Found orphaned starting window " + this); |
| 2449 | mStartingWindowState = STARTING_WINDOW_REMOVED; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2450 | mAppWindowToken.removeStartingWindow(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2451 | } |
| 2452 | } |
| 2453 | |
| 2454 | int getRequestedOrientation() { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2455 | return getOrientation(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2456 | } |
| 2457 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2458 | void setRequestedOrientation(int requestedOrientation) { |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2459 | final int displayId = getDisplayId(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2460 | final Configuration displayConfig = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2461 | mRootActivityContainer.getDisplayOverrideConfiguration(displayId); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2462 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2463 | final Configuration config = setOrientation(requestedOrientation, |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2464 | displayId, displayConfig, mayFreezeScreenLocked(app)); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2465 | if (config != null) { |
| 2466 | frozenBeforeDestroy = true; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2467 | if (!mAtmService.updateDisplayOverrideConfigurationLocked(config, this, |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2468 | false /* deferResume */, displayId)) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2469 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2470 | } |
| 2471 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2472 | mAtmService.getTaskChangeNotificationController().notifyActivityRequestedOrientationChanged( |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 2473 | task.taskId, requestedOrientation); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2474 | } |
| 2475 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2476 | Configuration setOrientation(int requestedOrientation, int displayId, |
| 2477 | Configuration displayConfig, boolean freezeScreenIfNeeded) { |
| 2478 | if (mAppWindowToken == null) { |
| 2479 | Slog.w(TAG_WM, |
| 2480 | "Attempted to set orientation of non-existing app token: " + appToken); |
| 2481 | return null; |
| 2482 | } |
| 2483 | |
| 2484 | mAppWindowToken.setOrientation(requestedOrientation); |
| 2485 | |
| 2486 | final IBinder binder = freezeScreenIfNeeded ? appToken.asBinder() : null; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2487 | return mAtmService.mWindowManager.updateOrientationFromAppTokens(displayConfig, binder, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2488 | displayId); |
| 2489 | } |
| 2490 | |
| 2491 | int getOrientation() { |
| 2492 | if (mAppWindowToken == null) { |
| 2493 | return SCREEN_ORIENTATION_UNSPECIFIED; |
| 2494 | } |
| 2495 | |
| 2496 | return mAppWindowToken.getOrientationIgnoreVisibility(); |
| 2497 | } |
| 2498 | |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 2499 | void setDisablePreviewScreenshots(boolean disable) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2500 | if (mAppWindowToken == null) { |
| 2501 | Slog.w(TAG_WM, "Attempted to set disable screenshots of non-existing app" |
| 2502 | + " token: " + appToken); |
| 2503 | return; |
| 2504 | } |
| 2505 | mAppWindowToken.setDisablePreviewScreenshots(disable); |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 2506 | } |
| 2507 | |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 2508 | /** |
| 2509 | * Set the last reported global configuration to the client. Should be called whenever a new |
| 2510 | * global configuration is sent to the client for this activity. |
| 2511 | */ |
| 2512 | void setLastReportedGlobalConfiguration(@NonNull Configuration config) { |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2513 | mLastReportedConfiguration.setGlobalConfiguration(config); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2514 | } |
| 2515 | |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 2516 | /** |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2517 | * Set the last reported configuration to the client. Should be called whenever |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 2518 | * a new merged configuration is sent to the client for this activity. |
| 2519 | */ |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2520 | void setLastReportedConfiguration(@NonNull MergedConfiguration config) { |
Bryce Lee | 8104e7a | 2017-08-17 09:16:03 -0700 | [diff] [blame] | 2521 | setLastReportedConfiguration(config.getGlobalConfiguration(), |
| 2522 | config.getOverrideConfiguration()); |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 2523 | } |
| 2524 | |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2525 | private void setLastReportedConfiguration(Configuration global, Configuration override) { |
Bryce Lee | 8104e7a | 2017-08-17 09:16:03 -0700 | [diff] [blame] | 2526 | mLastReportedConfiguration.setConfiguration(global, override); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2527 | } |
| 2528 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2529 | // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer. |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2530 | private void updateOverrideConfiguration() { |
| 2531 | mTmpConfig.unset(); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2532 | computeBounds(mTmpBounds); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2533 | |
| 2534 | if (mTmpBounds.equals(getOverrideBounds())) { |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2535 | return; |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2536 | } |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2537 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2538 | setBounds(mTmpBounds); |
| 2539 | |
| 2540 | final Rect updatedBounds = getOverrideBounds(); |
| 2541 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2542 | // Bounds changed...update configuration to match. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2543 | if (!matchParentBounds()) { |
| 2544 | task.computeOverrideConfiguration(mTmpConfig, updatedBounds, null /* insetBounds */, |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2545 | false /* overrideWidth */, false /* overrideHeight */); |
| 2546 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2547 | |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2548 | onOverrideConfigurationChanged(mTmpConfig); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2549 | } |
| 2550 | |
Wale Ogunwale | d4b1d1e | 2017-04-10 06:35:59 -0700 | [diff] [blame] | 2551 | /** Returns true if the configuration is compatible with this activity. */ |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 2552 | boolean isConfigurationCompatible(Configuration config) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2553 | final int orientation = mAppWindowToken != null |
| 2554 | ? getOrientation() : info.screenOrientation; |
Wale Ogunwale | d4b1d1e | 2017-04-10 06:35:59 -0700 | [diff] [blame] | 2555 | if (isFixedOrientationPortrait(orientation) |
| 2556 | && config.orientation != ORIENTATION_PORTRAIT) { |
| 2557 | return false; |
| 2558 | } |
| 2559 | if (isFixedOrientationLandscape(orientation) |
| 2560 | && config.orientation != ORIENTATION_LANDSCAPE) { |
| 2561 | return false; |
| 2562 | } |
| 2563 | return true; |
| 2564 | } |
| 2565 | |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 2566 | /** |
| 2567 | * Computes the bounds to fit the Activity within the bounds of the {@link Configuration}. |
| 2568 | */ |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2569 | // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer. |
| 2570 | private void computeBounds(Rect outBounds) { |
| 2571 | outBounds.setEmpty(); |
| 2572 | final float maxAspectRatio = info.maxAspectRatio; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2573 | final ActivityStack stack = getActivityStack(); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2574 | if (task == null || stack == null || task.inMultiWindowMode() || maxAspectRatio == 0 |
Bryce Lee | e5ab450 | 2017-07-11 08:58:05 -0700 | [diff] [blame] | 2575 | || isInVrUiMode(getConfiguration())) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2576 | // We don't set override configuration if that activity task isn't fullscreen. I.e. the |
| 2577 | // activity is in multi-window mode. Or, there isn't a max aspect ratio specified for |
Bryce Lee | e5ab450 | 2017-07-11 08:58:05 -0700 | [diff] [blame] | 2578 | // the activity. This is indicated by an empty {@link outBounds}. We also don't set it |
| 2579 | // if we are in VR mode. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2580 | return; |
| 2581 | } |
| 2582 | |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 2583 | // We must base this on the parent configuration, because we set our override |
| 2584 | // configuration's appBounds based on the result of this method. If we used our own |
| 2585 | // configuration, it would be influenced by past invocations. |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 2586 | final Rect appBounds = getParent().getWindowConfiguration().getAppBounds(); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 2587 | final int containingAppWidth = appBounds.width(); |
| 2588 | final int containingAppHeight = appBounds.height(); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 2589 | int maxActivityWidth = containingAppWidth; |
| 2590 | int maxActivityHeight = containingAppHeight; |
| 2591 | |
| 2592 | if (containingAppWidth < containingAppHeight) { |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2593 | // Width is the shorter side, so we use that to figure-out what the max. height |
| 2594 | // should be given the aspect ratio. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2595 | maxActivityHeight = (int) ((maxActivityWidth * maxAspectRatio) + 0.5f); |
| 2596 | } else { |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2597 | // Height is the shorter side, so we use that to figure-out what the max. width |
| 2598 | // should be given the aspect ratio. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2599 | maxActivityWidth = (int) ((maxActivityHeight * maxAspectRatio) + 0.5f); |
| 2600 | } |
| 2601 | |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 2602 | if (containingAppWidth <= maxActivityWidth && containingAppHeight <= maxActivityHeight) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2603 | // The display matches or is less than the activity aspect ratio, so nothing else to do. |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 2604 | // Return the existing bounds. If this method is running for the first time, |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2605 | // {@link #getOverrideBounds()} will be empty (representing no override). If the method has run |
| 2606 | // before, then effect of {@link #getOverrideBounds()} will already have been applied to the |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 2607 | // value returned from {@link getConfiguration}. Refer to |
| 2608 | // {@link TaskRecord#computeOverrideConfiguration}. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2609 | outBounds.set(getOverrideBounds()); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2610 | return; |
| 2611 | } |
| 2612 | |
| 2613 | // Compute configuration based on max supported width and height. |
Adrian Roos | 24be34d | 2018-05-28 18:55:38 +0200 | [diff] [blame] | 2614 | // Also account for the left / top insets (e.g. from display cutouts), which will be clipped |
| 2615 | // away later in StackWindowController.adjustConfigurationForBounds(). Otherwise, the app |
| 2616 | // bounds would end up too small. |
| 2617 | outBounds.set(0, 0, maxActivityWidth + appBounds.left, maxActivityHeight + appBounds.top); |
| 2618 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2619 | if (mAtmService.mWindowManager.getNavBarPosition(getDisplayId()) == NAV_BAR_LEFT) { |
Adrian Roos | 24be34d | 2018-05-28 18:55:38 +0200 | [diff] [blame] | 2620 | // Position the activity frame on the opposite side of the nav bar. |
| 2621 | outBounds.left = appBounds.right - maxActivityWidth; |
| 2622 | outBounds.right = appBounds.right; |
| 2623 | } |
Andrii Kulian | 3a1619d | 2017-07-07 14:38:09 -0700 | [diff] [blame] | 2624 | } |
| 2625 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 2626 | /** |
| 2627 | * @return {@code true} if this activity was reparented to another display but |
| 2628 | * {@link #ensureActivityConfiguration} is not called. |
| 2629 | */ |
| 2630 | boolean shouldUpdateConfigForDisplayChanged() { |
| 2631 | return mLastReportedDisplayId != getDisplayId(); |
| 2632 | } |
| 2633 | |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 2634 | boolean ensureActivityConfiguration(int globalChanges, boolean preserveWindow) { |
| 2635 | return ensureActivityConfiguration(globalChanges, preserveWindow, |
| 2636 | false /* ignoreStopState */); |
| 2637 | } |
| 2638 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2639 | /** |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 2640 | * Make sure the given activity matches the current configuration. Ensures the HistoryRecord |
| 2641 | * is updated with the correct configuration and all other bookkeeping is handled. |
| 2642 | * |
| 2643 | * @param globalChanges The changes to the global configuration. |
| 2644 | * @param preserveWindow If the activity window should be preserved on screen if the activity |
| 2645 | * is relaunched. |
| 2646 | * @param ignoreStopState If we should try to relaunch the activity even if it is in the stopped |
| 2647 | * state. This is useful for the case where we know the activity will be |
| 2648 | * visible soon and we want to ensure its configuration before we make it |
| 2649 | * visible. |
| 2650 | * @return True if the activity was relaunched and false if it wasn't relaunched because we |
| 2651 | * can't or the app handles the specific configuration that is changing. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2652 | */ |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 2653 | boolean ensureActivityConfiguration(int globalChanges, boolean preserveWindow, |
| 2654 | boolean ignoreStopState) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2655 | final ActivityStack stack = getActivityStack(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2656 | if (stack.mConfigWillChange) { |
| 2657 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2658 | "Skipping config check (will change): " + this); |
| 2659 | return true; |
| 2660 | } |
| 2661 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2662 | // We don't worry about activities that are finishing. |
| 2663 | if (finishing) { |
| 2664 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2665 | "Configuration doesn't matter in finishing " + this); |
| 2666 | stopFreezingScreenLocked(false); |
| 2667 | return true; |
| 2668 | } |
| 2669 | |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 2670 | if (!ignoreStopState && (mState == STOPPING || mState == STOPPED)) { |
Wale Ogunwale | 9b7a827 | 2017-04-10 08:05:41 -0700 | [diff] [blame] | 2671 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2672 | "Skipping config check stopped or stopping: " + this); |
| 2673 | return true; |
| 2674 | } |
| 2675 | |
Wale Ogunwale | ea3d3fd | 2017-05-01 07:41:08 -0700 | [diff] [blame] | 2676 | // TODO: We should add ActivityRecord.shouldBeVisible() that checks if the activity should |
| 2677 | // be visible based on the stack, task, and lockscreen state and use that here instead. The |
| 2678 | // method should be based on the logic in ActivityStack.ensureActivitiesVisibleLocked(). |
Wale Ogunwale | 9b7a827 | 2017-04-10 08:05:41 -0700 | [diff] [blame] | 2679 | // Skip updating configuration for activity is a stack that shouldn't be visible. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2680 | if (!stack.shouldBeVisible(null /* starting */)) { |
Wale Ogunwale | 9b7a827 | 2017-04-10 08:05:41 -0700 | [diff] [blame] | 2681 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2682 | "Skipping config check invisible stack: " + this); |
| 2683 | return true; |
| 2684 | } |
| 2685 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2686 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2687 | "Ensuring correct configuration: " + this); |
| 2688 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2689 | final int newDisplayId = getDisplayId(); |
| 2690 | final boolean displayChanged = mLastReportedDisplayId != newDisplayId; |
| 2691 | if (displayChanged) { |
| 2692 | mLastReportedDisplayId = newDisplayId; |
| 2693 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2694 | // TODO(b/36505427): Is there a better place to do this? |
| 2695 | updateOverrideConfiguration(); |
| 2696 | |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 2697 | // Short circuit: if the two full configurations are equal (the common case), then there is |
| 2698 | // nothing to do. We test the full configuration instead of the global and merged override |
| 2699 | // configurations because there are cases (like moving a task to the pinned stack) where |
| 2700 | // the combine configurations are equal, but would otherwise differ in the override config |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2701 | mTmpConfig.setTo(mLastReportedConfiguration.getMergedConfiguration()); |
| 2702 | if (getConfiguration().equals(mTmpConfig) && !forceNewConfig && !displayChanged) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2703 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2704 | "Configuration & display unchanged in " + this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2705 | return true; |
| 2706 | } |
| 2707 | |
| 2708 | // Okay we now are going to make this activity have the new config. |
| 2709 | // But then we need to figure out how it needs to deal with that. |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 2710 | |
| 2711 | // Find changes between last reported merged configuration and the current one. This is used |
| 2712 | // to decide whether to relaunch an activity or just report a configuration change. |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2713 | final int changes = getConfigurationChanges(mTmpConfig); |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 2714 | |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 2715 | // Update last reported values. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2716 | final Configuration newMergedOverrideConfig = getMergedOverrideConfiguration(); |
Bryce Lee | 8104e7a | 2017-08-17 09:16:03 -0700 | [diff] [blame] | 2717 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2718 | setLastReportedConfiguration(mAtmService.getGlobalConfiguration(), newMergedOverrideConfig); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2719 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2720 | if (mState == INITIALIZING) { |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 2721 | // No need to relaunch or schedule new config for activity that hasn't been launched |
| 2722 | // yet. We do, however, return after applying the config to activity record, so that |
| 2723 | // it will use it for launch transaction. |
| 2724 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2725 | "Skipping config check for initializing activity: " + this); |
| 2726 | return true; |
| 2727 | } |
| 2728 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2729 | if (changes == 0 && !forceNewConfig) { |
| 2730 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2731 | "Configuration no differences in " + this); |
| 2732 | // There are no significant differences, so we won't relaunch but should still deliver |
| 2733 | // the new configuration to the client process. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2734 | if (displayChanged) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2735 | scheduleActivityMovedToDisplay(newDisplayId, newMergedOverrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2736 | } else { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2737 | scheduleConfigurationChanged(newMergedOverrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2738 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2739 | return true; |
| 2740 | } |
| 2741 | |
| 2742 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 2743 | "Configuration changes for " + this + ", allChanges=" |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2744 | + Configuration.configurationDiffToString(changes)); |
| 2745 | |
| 2746 | // If the activity isn't currently running, just leave the new configuration and it will |
| 2747 | // pick that up next time it starts. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2748 | if (!attachedToProcess()) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2749 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2750 | "Configuration doesn't matter not running " + this); |
| 2751 | stopFreezingScreenLocked(false); |
| 2752 | forceNewConfig = false; |
| 2753 | return true; |
| 2754 | } |
| 2755 | |
| 2756 | // Figure out how to handle the changes between the configurations. |
| 2757 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2758 | "Checking to restart " + info.name + ": changed=0x" |
| 2759 | + Integer.toHexString(changes) + ", handles=0x" |
| 2760 | + Integer.toHexString(info.getRealConfigChanged()) |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2761 | + ", mLastReportedConfiguration=" + mLastReportedConfiguration); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2762 | |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2763 | if (shouldRelaunchLocked(changes, mTmpConfig) || forceNewConfig) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2764 | // Aha, the activity isn't handling the change, so DIE DIE DIE. |
| 2765 | configChangeFlags |= changes; |
| 2766 | startFreezingScreenLocked(app, globalChanges); |
| 2767 | forceNewConfig = false; |
| 2768 | preserveWindow &= isResizeOnlyChange(changes); |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 2769 | final boolean hasResizeChange = hasResizeChange(changes & ~info.getRealConfigChanged()); |
| 2770 | if (hasResizeChange) { |
| 2771 | final boolean isDragResizing = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2772 | getTaskRecord().getWindowContainerController().isDragResizing(); |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 2773 | mRelaunchReason = isDragResizing ? RELAUNCH_REASON_FREE_RESIZE |
| 2774 | : RELAUNCH_REASON_WINDOWING_MODE_RESIZE; |
| 2775 | } else { |
| 2776 | mRelaunchReason = RELAUNCH_REASON_NONE; |
| 2777 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2778 | if (!attachedToProcess()) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2779 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2780 | "Config is destroying non-running " + this); |
| 2781 | stack.destroyActivityLocked(this, true, "config"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2782 | } else if (mState == PAUSING) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2783 | // A little annoying: we are waiting for this activity to finish pausing. Let's not |
| 2784 | // do anything now, but just flag that it needs to be restarted when done pausing. |
| 2785 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2786 | "Config is skipping already pausing " + this); |
| 2787 | deferRelaunchUntilPaused = true; |
| 2788 | preserveWindowOnDeferredRelaunch = preserveWindow; |
| 2789 | return true; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2790 | } else if (mState == RESUMED) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2791 | // Try to optimize this case: the configuration is changing and we need to restart |
| 2792 | // the top, resumed activity. Instead of doing the normal handshaking, just say |
| 2793 | // "restart!". |
| 2794 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2795 | "Config is relaunching resumed " + this); |
| 2796 | |
| 2797 | if (DEBUG_STATES && !visible) { |
| 2798 | Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + this |
| 2799 | + " called by " + Debug.getCallers(4)); |
| 2800 | } |
| 2801 | |
| 2802 | relaunchActivityLocked(true /* andResume */, preserveWindow); |
| 2803 | } else { |
| 2804 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2805 | "Config is relaunching non-resumed " + this); |
| 2806 | relaunchActivityLocked(false /* andResume */, preserveWindow); |
| 2807 | } |
| 2808 | |
| 2809 | // All done... tell the caller we weren't able to keep this activity around. |
| 2810 | return false; |
| 2811 | } |
| 2812 | |
| 2813 | // Default case: the activity can handle this new configuration, so hand it over. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2814 | // NOTE: We only forward the override configuration as the system level configuration |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2815 | // changes is always sent to all processes when they happen so it can just use whatever |
| 2816 | // system level configuration it last got. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2817 | if (displayChanged) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2818 | scheduleActivityMovedToDisplay(newDisplayId, newMergedOverrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2819 | } else { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2820 | scheduleConfigurationChanged(newMergedOverrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2821 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2822 | stopFreezingScreenLocked(false); |
| 2823 | |
| 2824 | return true; |
| 2825 | } |
| 2826 | |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 2827 | /** |
| 2828 | * When assessing a configuration change, decide if the changes flags and the new configurations |
| 2829 | * should cause the Activity to relaunch. |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 2830 | * |
| 2831 | * @param changes the changes due to the given configuration. |
| 2832 | * @param changesConfig the configuration that was used to calculate the given changes via a |
| 2833 | * call to getConfigurationChanges. |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 2834 | */ |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 2835 | private boolean shouldRelaunchLocked(int changes, Configuration changesConfig) { |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 2836 | int configChanged = info.getRealConfigChanged(); |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 2837 | boolean onlyVrUiModeChanged = onlyVrUiModeChanged(changes, changesConfig); |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 2838 | |
| 2839 | // Override for apps targeting pre-O sdks |
| 2840 | // If a device is in VR mode, and we're transitioning into VR ui mode, add ignore ui mode |
| 2841 | // to the config change. |
| 2842 | // For O and later, apps will be required to add configChanges="uimode" to their manifest. |
| 2843 | if (appInfo.targetSdkVersion < O |
| 2844 | && requestedVrComponent != null |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 2845 | && onlyVrUiModeChanged) { |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 2846 | configChanged |= CONFIG_UI_MODE; |
| 2847 | } |
| 2848 | |
| 2849 | return (changes&(~configChanged)) != 0; |
| 2850 | } |
| 2851 | |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 2852 | /** |
| 2853 | * Returns true if the configuration change is solely due to the UI mode switching into or out |
| 2854 | * of UI_MODE_TYPE_VR_HEADSET. |
| 2855 | */ |
| 2856 | private boolean onlyVrUiModeChanged(int changes, Configuration lastReportedConfig) { |
| 2857 | final Configuration currentConfig = getConfiguration(); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2858 | return changes == CONFIG_UI_MODE && (isInVrUiMode(currentConfig) |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 2859 | != isInVrUiMode(lastReportedConfig)); |
| 2860 | } |
| 2861 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2862 | private int getConfigurationChanges(Configuration lastReportedConfig) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2863 | // Determine what has changed. May be nothing, if this is a config that has come back from |
| 2864 | // the app after going idle. In that case we just want to leave the official config object |
| 2865 | // now in the activity and do nothing else. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2866 | final Configuration currentConfig = getConfiguration(); |
| 2867 | int changes = lastReportedConfig.diff(currentConfig); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2868 | // We don't want to use size changes if they don't cross boundaries that are important to |
| 2869 | // the app. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2870 | if ((changes & CONFIG_SCREEN_SIZE) != 0) { |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 2871 | final boolean crosses = crossesHorizontalSizeThreshold(lastReportedConfig.screenWidthDp, |
| 2872 | currentConfig.screenWidthDp) |
| 2873 | || crossesVerticalSizeThreshold(lastReportedConfig.screenHeightDp, |
| 2874 | currentConfig.screenHeightDp); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2875 | if (!crosses) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2876 | changes &= ~CONFIG_SCREEN_SIZE; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2877 | } |
| 2878 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2879 | if ((changes & CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 2880 | final int oldSmallest = lastReportedConfig.smallestScreenWidthDp; |
| 2881 | final int newSmallest = currentConfig.smallestScreenWidthDp; |
| 2882 | if (!crossesSmallestSizeThreshold(oldSmallest, newSmallest)) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2883 | changes &= ~CONFIG_SMALLEST_SCREEN_SIZE; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2884 | } |
| 2885 | } |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 2886 | // We don't want window configuration to cause relaunches. |
| 2887 | if ((changes & CONFIG_WINDOW_CONFIGURATION) != 0) { |
| 2888 | changes &= ~CONFIG_WINDOW_CONFIGURATION; |
| 2889 | } |
Bryce Lee | 600dadd | 2017-07-25 10:48:42 -0700 | [diff] [blame] | 2890 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2891 | return changes; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2892 | } |
| 2893 | |
| 2894 | private static boolean isResizeOnlyChange(int change) { |
| 2895 | return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION |
| 2896 | | CONFIG_SCREEN_LAYOUT)) == 0; |
| 2897 | } |
| 2898 | |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 2899 | private static boolean hasResizeChange(int change) { |
| 2900 | return (change & (CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION |
| 2901 | | CONFIG_SCREEN_LAYOUT)) != 0; |
| 2902 | } |
| 2903 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2904 | void relaunchActivityLocked(boolean andResume, boolean preserveWindow) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2905 | if (mAtmService.mSuppressResizeConfigChanges && preserveWindow) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2906 | configChangeFlags = 0; |
| 2907 | return; |
| 2908 | } |
| 2909 | |
| 2910 | List<ResultInfo> pendingResults = null; |
| 2911 | List<ReferrerIntent> pendingNewIntents = null; |
| 2912 | if (andResume) { |
| 2913 | pendingResults = results; |
| 2914 | pendingNewIntents = newIntents; |
| 2915 | } |
| 2916 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2917 | "Relaunching: " + this + " with results=" + pendingResults |
| 2918 | + " newIntents=" + pendingNewIntents + " andResume=" + andResume |
| 2919 | + " preserveWindow=" + preserveWindow); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2920 | EventLog.writeEvent(andResume ? AM_RELAUNCH_RESUME_ACTIVITY |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2921 | : AM_RELAUNCH_ACTIVITY, mUserId, System.identityHashCode(this), |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2922 | task.taskId, shortComponentName); |
| 2923 | |
| 2924 | startFreezingScreenLocked(app, 0); |
| 2925 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2926 | try { |
| 2927 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, |
| 2928 | "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + this |
| 2929 | + " callers=" + Debug.getCallers(6)); |
| 2930 | forceNewConfig = false; |
| 2931 | mStackSupervisor.activityRelaunchingLocked(this); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 2932 | final ClientTransactionItem callbackItem = ActivityRelaunchItem.obtain(pendingResults, |
| 2933 | pendingNewIntents, configChangeFlags, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2934 | new MergedConfiguration(mAtmService.getGlobalConfiguration(), |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 2935 | getMergedOverrideConfiguration()), |
| 2936 | preserveWindow); |
| 2937 | final ActivityLifecycleItem lifecycleItem; |
| 2938 | if (andResume) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2939 | lifecycleItem = ResumeActivityItem.obtain( |
| 2940 | getDisplay().getWindowContainerController().isNextTransitionForward()); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 2941 | } else { |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 2942 | lifecycleItem = PauseActivityItem.obtain(); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 2943 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2944 | final ClientTransaction transaction = ClientTransaction.obtain(app.getThread(), appToken); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 2945 | transaction.addCallback(callbackItem); |
| 2946 | transaction.setLifecycleStateRequest(lifecycleItem); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2947 | mAtmService.getLifecycleManager().scheduleTransaction(transaction); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2948 | // Note: don't need to call pauseIfSleepingLocked() here, because the caller will only |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 2949 | // request resume if this activity is currently resumed, which implies we aren't |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2950 | // sleeping. |
| 2951 | } catch (RemoteException e) { |
| 2952 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e); |
| 2953 | } |
| 2954 | |
| 2955 | if (andResume) { |
| 2956 | if (DEBUG_STATES) { |
| 2957 | Slog.d(TAG_STATES, "Resumed after relaunch " + this); |
| 2958 | } |
| 2959 | results = null; |
| 2960 | newIntents = null; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2961 | mAtmService.getAppWarningsLocked().onResumeActivity(this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2962 | } else { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2963 | final ActivityStack stack = getActivityStack(); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 2964 | if (stack != null) { |
| 2965 | stack.mHandler.removeMessages(PAUSE_TIMEOUT_MSG, this); |
| 2966 | } |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2967 | setState(PAUSED, "relaunchActivityLocked"); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | configChangeFlags = 0; |
| 2971 | deferRelaunchUntilPaused = false; |
| 2972 | preserveWindowOnDeferredRelaunch = false; |
| 2973 | } |
| 2974 | |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 2975 | private boolean isProcessRunning() { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2976 | WindowProcessController proc = app; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2977 | if (proc == null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2978 | proc = mAtmService.mProcessNames.get(processName, info.applicationInfo.uid); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2979 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2980 | return proc != null && proc.hasThread(); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2981 | } |
| 2982 | |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 2983 | /** |
| 2984 | * @return Whether a task snapshot starting window may be shown. |
| 2985 | */ |
| 2986 | private boolean allowTaskSnapshot() { |
| 2987 | if (newIntents == null) { |
| 2988 | return true; |
| 2989 | } |
| 2990 | |
| 2991 | // Restrict task snapshot starting window to launcher start, or there is no intent at all |
| 2992 | // (eg. task being brought to front). If the intent is something else, likely the app is |
| 2993 | // going to show some specific page or view, instead of what's left last time. |
| 2994 | for (int i = newIntents.size() - 1; i >= 0; i--) { |
| 2995 | final Intent intent = newIntents.get(i); |
| 2996 | if (intent != null && !ActivityRecord.isMainIntent(intent)) { |
| 2997 | return false; |
| 2998 | } |
| 2999 | } |
| 3000 | return true; |
| 3001 | } |
| 3002 | |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 3003 | /** |
| 3004 | * Returns {@code true} if the associated activity has the no history flag set on it. |
| 3005 | * {@code false} otherwise. |
| 3006 | */ |
| 3007 | boolean isNoHistory() { |
| 3008 | return (intent.getFlags() & FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 3009 | || (info.flags & FLAG_NO_HISTORY) != 0; |
| 3010 | } |
| 3011 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3012 | void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException { |
| 3013 | out.attribute(null, ATTR_ID, String.valueOf(createTime)); |
| 3014 | out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid)); |
| 3015 | if (launchedFromPackage != null) { |
| 3016 | out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage); |
| 3017 | } |
| 3018 | if (resolvedType != null) { |
| 3019 | out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType); |
| 3020 | } |
| 3021 | out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified)); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3022 | out.attribute(null, ATTR_USERID, String.valueOf(mUserId)); |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 3023 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3024 | if (taskDescription != null) { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 3025 | taskDescription.saveToXml(out); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3026 | } |
| 3027 | |
| 3028 | out.startTag(null, TAG_INTENT); |
| 3029 | intent.saveToXml(out); |
| 3030 | out.endTag(null, TAG_INTENT); |
| 3031 | |
| 3032 | if (isPersistable() && persistentState != null) { |
| 3033 | out.startTag(null, TAG_PERSISTABLEBUNDLE); |
| 3034 | persistentState.saveToXml(out); |
| 3035 | out.endTag(null, TAG_PERSISTABLEBUNDLE); |
| 3036 | } |
| 3037 | } |
| 3038 | |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 3039 | static ActivityRecord restoreFromXml(XmlPullParser in, |
| 3040 | ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3041 | Intent intent = null; |
| 3042 | PersistableBundle persistentState = null; |
| 3043 | int launchedFromUid = 0; |
| 3044 | String launchedFromPackage = null; |
| 3045 | String resolvedType = null; |
| 3046 | boolean componentSpecified = false; |
| 3047 | int userId = 0; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3048 | long createTime = -1; |
| 3049 | final int outerDepth = in.getDepth(); |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 3050 | TaskDescription taskDescription = new TaskDescription(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3051 | |
| 3052 | for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) { |
| 3053 | final String attrName = in.getAttributeName(attrNdx); |
| 3054 | final String attrValue = in.getAttributeValue(attrNdx); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3055 | if (DEBUG) Slog.d(TaskPersister.TAG, |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 3056 | "ActivityRecord: attribute name=" + attrName + " value=" + attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3057 | if (ATTR_ID.equals(attrName)) { |
Tobias Thierer | 28532d0 | 2016-04-21 14:52:10 +0100 | [diff] [blame] | 3058 | createTime = Long.parseLong(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3059 | } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 3060 | launchedFromUid = Integer.parseInt(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3061 | } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) { |
| 3062 | launchedFromPackage = attrValue; |
| 3063 | } else if (ATTR_RESOLVEDTYPE.equals(attrName)) { |
| 3064 | resolvedType = attrValue; |
| 3065 | } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) { |
Tobias Thierer | b0800dc | 2016-04-21 17:51:41 +0100 | [diff] [blame] | 3066 | componentSpecified = Boolean.parseBoolean(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3067 | } else if (ATTR_USERID.equals(attrName)) { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 3068 | userId = Integer.parseInt(attrValue); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3069 | } else if (attrName.startsWith(ATTR_TASKDESCRIPTION_PREFIX)) { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 3070 | taskDescription.restoreFromXml(attrName, attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3071 | } else { |
| 3072 | Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName); |
| 3073 | } |
| 3074 | } |
| 3075 | |
| 3076 | int event; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3077 | while (((event = in.next()) != END_DOCUMENT) && |
| 3078 | (event != END_TAG || in.getDepth() >= outerDepth)) { |
| 3079 | if (event == START_TAG) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3080 | final String name = in.getName(); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3081 | if (DEBUG) |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 3082 | Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3083 | if (TAG_INTENT.equals(name)) { |
| 3084 | intent = Intent.restoreFromXml(in); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3085 | if (DEBUG) |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 3086 | Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3087 | } else if (TAG_PERSISTABLEBUNDLE.equals(name)) { |
| 3088 | persistentState = PersistableBundle.restoreFromXml(in); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3089 | if (DEBUG) Slog.d(TaskPersister.TAG, |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3090 | "ActivityRecord: persistentState=" + persistentState); |
| 3091 | } else { |
| 3092 | Slog.w(TAG, "restoreActivity: unexpected name=" + name); |
| 3093 | XmlUtils.skipCurrentTag(in); |
| 3094 | } |
| 3095 | } |
| 3096 | } |
| 3097 | |
| 3098 | if (intent == null) { |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 3099 | throw new XmlPullParserException("restoreActivity error intent=" + intent); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3100 | } |
| 3101 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 3102 | final ActivityTaskManagerService service = stackSupervisor.mService; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3103 | final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null, |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 3104 | userId, Binder.getCallingUid()); |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 3105 | if (aInfo == null) { |
Craig Mautner | 77b0426 | 2014-06-27 15:22:12 -0700 | [diff] [blame] | 3106 | throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent + |
| 3107 | " resolvedType=" + resolvedType); |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 3108 | } |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 3109 | final ActivityRecord r = new ActivityRecord(service, null /* caller */, |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 3110 | 0 /* launchedFromPid */, launchedFromUid, launchedFromPackage, intent, resolvedType, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3111 | aInfo, service.getConfiguration(), null /* resultTo */, null /* resultWho */, |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 3112 | 0 /* reqCode */, componentSpecified, false /* rootVoiceInteraction */, |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 3113 | stackSupervisor, null /* options */, null /* sourceRecord */); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3114 | |
| 3115 | r.persistentState = persistentState; |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 3116 | r.taskDescription = taskDescription; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3117 | r.createTime = createTime; |
| 3118 | |
| 3119 | return r; |
| 3120 | } |
| 3121 | |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 3122 | private static boolean isInVrUiMode(Configuration config) { |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3123 | return (config.uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_VR_HEADSET; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 3124 | } |
| 3125 | |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 3126 | int getUid() { |
| 3127 | return info.applicationInfo.uid; |
| 3128 | } |
| 3129 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3130 | void setShowWhenLocked(boolean showWhenLocked) { |
| 3131 | mShowWhenLocked = showWhenLocked; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3132 | mRootActivityContainer.ensureActivitiesVisible(null, 0 /* configChanges */, |
Kevin Chyn | 4463948 | 2017-10-09 18:34:41 -0700 | [diff] [blame] | 3133 | false /* preserveWindows */); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3134 | } |
| 3135 | |
| 3136 | /** |
chaviw | 2c50098 | 2018-01-04 17:05:05 -0800 | [diff] [blame] | 3137 | * @return true if the activity windowing mode is not |
| 3138 | * {@link android.app.WindowConfiguration#WINDOWING_MODE_PINNED} and activity contains |
| 3139 | * windows that have {@link LayoutParams#FLAG_SHOW_WHEN_LOCKED} set or if the activity |
| 3140 | * has set {@link #mShowWhenLocked}. |
| 3141 | * Multi-windowing mode will be exited if true is returned. |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3142 | */ |
| 3143 | boolean canShowWhenLocked() { |
chaviw | 2c50098 | 2018-01-04 17:05:05 -0800 | [diff] [blame] | 3144 | return !inPinnedWindowingMode() && (mShowWhenLocked |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3145 | || mAtmService.mWindowManager.containsShowWhenLockedWindow(appToken)); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3146 | } |
| 3147 | |
| 3148 | void setTurnScreenOn(boolean turnScreenOn) { |
| 3149 | mTurnScreenOn = turnScreenOn; |
| 3150 | } |
| 3151 | |
| 3152 | /** |
| 3153 | * Determines whether this ActivityRecord can turn the screen on. It checks whether the flag |
| 3154 | * {@link #mTurnScreenOn} is set and checks whether the ActivityRecord should be visible |
| 3155 | * depending on Keyguard state |
| 3156 | * |
| 3157 | * @return true if the screen can be turned on, false otherwise. |
| 3158 | */ |
| 3159 | boolean canTurnScreenOn() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3160 | final ActivityStack stack = getActivityStack(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3161 | return mTurnScreenOn && stack != null && |
| 3162 | stack.checkKeyguardVisibility(this, true /* shouldBeVisible */, true /* isTop */); |
| 3163 | } |
| 3164 | |
| 3165 | boolean getTurnScreenOnFlag() { |
| 3166 | return mTurnScreenOn; |
| 3167 | } |
| 3168 | |
| 3169 | boolean isTopRunningActivity() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3170 | return mRootActivityContainer.topRunningActivity() == this; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3171 | } |
| 3172 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 3173 | /** |
| 3174 | * @return {@code true} if this is the resumed activity on its current display, {@code false} |
| 3175 | * otherwise. |
| 3176 | */ |
| 3177 | boolean isResumedActivityOnDisplay() { |
| 3178 | final ActivityDisplay display = getDisplay(); |
| 3179 | return display != null && this == display.getResumedActivity(); |
| 3180 | } |
| 3181 | |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 3182 | void registerRemoteAnimations(RemoteAnimationDefinition definition) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3183 | if (mAppWindowToken == null) { |
| 3184 | Slog.w(TAG_WM, "Attempted to register remote animations with non-existing app" |
| 3185 | + " token: " + appToken); |
| 3186 | return; |
| 3187 | } |
| 3188 | mAppWindowToken.registerRemoteAnimations(definition); |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 3189 | } |
| 3190 | |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3191 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3192 | public String toString() { |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 3193 | if (stringName != null) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 3194 | return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) + |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3195 | (finishing ? " f}" : "}"); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 3196 | } |
| 3197 | StringBuilder sb = new StringBuilder(128); |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 3198 | sb.append("ActivityRecord{"); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 3199 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3200 | sb.append(" u"); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3201 | sb.append(mUserId); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 3202 | sb.append(' '); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3203 | sb.append(intent.getComponent().flattenToShortString()); |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3204 | stringName = sb.toString(); |
| 3205 | return toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3206 | } |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3207 | |
| 3208 | void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) { |
| 3209 | final long token = proto.start(fieldId); |
| 3210 | proto.write(HASH_CODE, System.identityHashCode(this)); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3211 | proto.write(USER_ID, mUserId); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3212 | proto.write(TITLE, intent.getComponent().flattenToShortString()); |
| 3213 | proto.end(token); |
| 3214 | } |
| 3215 | |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 3216 | /** |
| 3217 | * Write all fields to an {@code ActivityRecordProto}. This assumes the |
| 3218 | * {@code ActivityRecordProto} is the outer-most proto data. |
| 3219 | */ |
| 3220 | void writeToProto(ProtoOutputStream proto) { |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 3221 | super.writeToProto(proto, CONFIGURATION_CONTAINER, false /* trim */); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3222 | writeIdentifierToProto(proto, IDENTIFIER); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3223 | proto.write(STATE, mState.toString()); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3224 | proto.write(VISIBLE, visible); |
| 3225 | proto.write(FRONT_OF_TASK, frontOfTask); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3226 | if (hasProcess()) { |
| 3227 | proto.write(PROC_ID, app.getPid()); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3228 | } |
Wale Ogunwale | 30eab1f | 2018-05-24 18:25:25 -0700 | [diff] [blame] | 3229 | proto.write(TRANSLUCENT, !fullscreen); |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 3233 | final long token = proto.start(fieldId); |
| 3234 | writeToProto(proto); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3235 | proto.end(token); |
| 3236 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3237 | } |