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 | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 247 | final ActivityTaskManagerService service; // 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. |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 258 | final int userId; // 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 |
| 260 | final ComponentName realActivity; // the intent component, or target of an alias. |
| 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); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 410 | pw.print(" userId="); pw.println(userId); |
| 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); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 416 | pw.print(prefix); pw.print("realActivity="); |
| 417 | pw.println(realActivity.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 | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 647 | service.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 | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 665 | service.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 | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 692 | service.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 | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 723 | service.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() { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 744 | return getTask(); |
| 745 | } |
| 746 | |
| 747 | TaskRecord getTask() { |
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) { |
| 768 | // Do nothing if the {@link TaskRecord} is the same as the current {@link getTask}. |
| 769 | if (task != null && task == getTask()) { |
| 770 | return; |
| 771 | } |
| 772 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 773 | final ActivityStack oldStack = getStack(); |
| 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(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 822 | if (r == null || r.getStack() == 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() { |
| 855 | return ResolverActivity.class.getName().equals(realActivity.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( |
| 864 | Object.class.getClassLoader().loadClass(realActivity.getClassName())); |
| 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) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 876 | service = _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; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 883 | userId = 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))) { |
| 920 | realActivity = _intent.getComponent(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | } else { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 922 | realActivity = 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 | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 961 | realTheme, com.android.internal.R.styleable.Window, userId); |
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 |
| 1041 | mAppWindowToken = service.mWindowManager.mRoot.getAppWindowToken(appToken.asBinder()); |
| 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 | } |
| 1051 | mAppWindowToken = createAppWindow(service.mWindowManager, appToken, |
| 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) { |
| 1101 | return new AppWindowToken(service, token, realActivity, voiceInteraction, dc, |
| 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() { |
Yunfan Chen | d4ef301 | 2018-11-28 21:14:32 -0800 | [diff] [blame] | 1108 | if (service.mWindowManager.mRoot == null) return; |
| 1109 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1110 | final DisplayContent dc = service.mWindowManager.mRoot.getDisplayContent( |
| 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 = |
| 1196 | service.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 | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 1216 | } else if (realActivity.getClassName().contains(LEGACY_RECENTS_PACKAGE_NAME) |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 1217 | || service.getRecentTasks().isRecentsComponent(realActivity, 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 | */ |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 1235 | <T extends ActivityStack> T getStack() { |
| 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() { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 1240 | return getStack() != null ? getStack().mStackId : INVALID_STACK_ID; |
| 1241 | } |
| 1242 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1243 | ActivityDisplay getDisplay() { |
| 1244 | final ActivityStack stack = getStack(); |
| 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() { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1275 | final ActivityStack stack = getStack(); |
| 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 | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1305 | return service.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 | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1318 | && service.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 | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1326 | return service.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 | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1333 | return service.mSupportsMultiWindow && !isActivityTypeHome() |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1334 | && (ActivityInfo.isResizeableMode(info.resizeMode) |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1335 | || service.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) { |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 1346 | return service.mStackSupervisor.canPlaceEntityOnDisplay(displayId, launchedFromPid, |
| 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 |
| 1367 | if (service.shouldDisableNonVrUiLocked()) { |
| 1368 | return false; |
| 1369 | } |
| 1370 | |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 1371 | boolean isKeyguardLocked = service.isKeyguardLocked(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 1372 | boolean isCurrentAppLocked = |
| 1373 | service.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 | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1414 | return service.getAppOpsService().checkOperation( |
| 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 | |
| 1431 | final TaskRecord task = getTask(); |
| 1432 | final ActivityStack stack = getStack(); |
| 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 |
| 1454 | service.setResumedActivityUncheckLocked(this, reason); |
| 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() { |
| 1464 | return service.mWindowManager.containsDismissKeyguardWindow(appToken); |
| 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 | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1476 | if (service != null) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 1477 | service.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 | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 1483 | uriPermissions = new UriPermissionOwner(service.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() { |
| 1525 | final ActivityStack stack = getStack(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1526 | return stack != null ? stack.shouldSleepActivities() : service.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 | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 1535 | service.mUgmInternal.grantUriPermissionFromIntent(callingUid, packageName, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 1536 | intent, getUriPermissionsLocked(), userId); |
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 | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 1550 | service.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) { |
| 1643 | // TODO(multidisplay): Shouldn't be really used anymore from next CL. |
| 1644 | displayContent.mAppTransition.overridePendingAppTransitionMultiThumbFuture( |
| 1645 | specsFuture, pendingOptions.getOnAnimationStartListener(), |
| 1646 | animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP); |
| 1647 | } else if (animationType == ANIM_THUMBNAIL_ASPECT_SCALE_DOWN |
| 1648 | && specs != null) { |
| 1649 | displayContent.mAppTransition.overridePendingAppTransitionMultiThumb( |
| 1650 | specs, pendingOptions.getOnAnimationStartListener(), |
| 1651 | pendingOptions.getAnimationFinishedListener(), false); |
| 1652 | } else { |
| 1653 | displayContent.mAppTransition.overridePendingAppTransitionAspectScaledThumb( |
| 1654 | pendingOptions.getThumbnail(), |
| 1655 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 1656 | pendingOptions.getWidth(), pendingOptions.getHeight(), |
| 1657 | pendingOptions.getOnAnimationStartListener(), |
| 1658 | (animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP)); |
| 1659 | if (intent.getSourceBounds() == null) { |
| 1660 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 1661 | pendingOptions.getStartY(), |
| 1662 | pendingOptions.getStartX() + pendingOptions.getWidth(), |
| 1663 | pendingOptions.getStartY() + pendingOptions.getHeight())); |
| 1664 | } |
| 1665 | } |
| 1666 | break; |
| 1667 | case ANIM_OPEN_CROSS_PROFILE_APPS: |
| 1668 | displayContent.mAppTransition |
| 1669 | .overridePendingAppTransitionStartCrossProfileApps(); |
| 1670 | break; |
| 1671 | case ANIM_REMOTE_ANIMATION: |
| 1672 | // TODO(multidisplay): Will pass displayId and adjust dependencies from next CL. |
| 1673 | displayContent.mAppTransition.overridePendingAppTransitionRemote( |
| 1674 | pendingOptions.getRemoteAnimationAdapter()); |
| 1675 | break; |
| 1676 | case ANIM_NONE: |
| 1677 | break; |
| 1678 | default: |
| 1679 | Slog.e(TAG_WM, "applyOptionsLocked: Unknown animationType=" + animationType); |
| 1680 | break; |
| 1681 | } |
| 1682 | } |
| 1683 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1684 | ActivityOptions getOptionsForTargetActivityLocked() { |
| 1685 | return pendingOptions != null ? pendingOptions.forTargetActivity() : null; |
| 1686 | } |
| 1687 | |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1688 | void clearOptionsLocked() { |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 1689 | clearOptionsLocked(true /* withAbort */); |
| 1690 | } |
| 1691 | |
| 1692 | void clearOptionsLocked(boolean withAbort) { |
| 1693 | if (withAbort && pendingOptions != null) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1694 | pendingOptions.abort(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1695 | } |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 1696 | pendingOptions = null; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
Dianne Hackborn | 9622ca4 | 2012-10-23 18:56:33 -0700 | [diff] [blame] | 1699 | ActivityOptions takeOptionsLocked() { |
| 1700 | ActivityOptions opts = pendingOptions; |
| 1701 | pendingOptions = null; |
| 1702 | return opts; |
| 1703 | } |
| 1704 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1705 | void removeUriPermissionsLocked() { |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 1706 | if (uriPermissions != null) { |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 1707 | uriPermissions.removeUriPermissions(); |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 1708 | uriPermissions = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1709 | } |
| 1710 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1711 | |
| 1712 | void pauseKeyDispatchingLocked() { |
| 1713 | if (!keysPaused) { |
| 1714 | keysPaused = true; |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1715 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1716 | // TODO: remove the check after unification with AppWindowToken. The DC check is not |
| 1717 | // needed after no mock mAppWindowToken in tests. |
| 1718 | if (mAppWindowToken != null && mAppWindowToken.getDisplayContent() != null) { |
| 1719 | mAppWindowToken.getDisplayContent().getInputMonitor().pauseDispatchingLw( |
| 1720 | mAppWindowToken); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1721 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1722 | } |
| 1723 | } |
| 1724 | |
| 1725 | void resumeKeyDispatchingLocked() { |
| 1726 | if (keysPaused) { |
| 1727 | keysPaused = false; |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1728 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1729 | // TODO: remove the check after unification with AppWindowToken. The DC check is not |
| 1730 | // needed after no mock mAppWindowToken in tests. |
| 1731 | if (mAppWindowToken != null && mAppWindowToken.getDisplayContent() != null) { |
| 1732 | mAppWindowToken.getDisplayContent().getInputMonitor().resumeDispatchingLw( |
| 1733 | mAppWindowToken); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1734 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1735 | } |
| 1736 | } |
| 1737 | |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 1738 | private void updateTaskDescription(CharSequence description) { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1739 | task.lastDescription = description; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1742 | void setDeferHidingClient(boolean deferHidingClient) { |
| 1743 | if (mDeferHidingClient == deferHidingClient) { |
| 1744 | return; |
| 1745 | } |
| 1746 | mDeferHidingClient = deferHidingClient; |
| 1747 | if (!mDeferHidingClient && !visible) { |
| 1748 | // Hiding the client is no longer deferred and the app isn't visible still, go ahead and |
| 1749 | // update the visibility. |
| 1750 | setVisibility(false); |
| 1751 | } |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1754 | void setVisibility(boolean visible) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1755 | if (mAppWindowToken == null) { |
| 1756 | Slog.w(TAG_WM, "Attempted to set visibility of non-existing app token: " |
| 1757 | + appToken); |
| 1758 | return; |
| 1759 | } |
| 1760 | mAppWindowToken.setVisibility(visible, mDeferHidingClient); |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 1761 | mStackSupervisor.getActivityMetricsLogger().notifyVisibilityChanged(this); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1762 | } |
| 1763 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1764 | // TODO: Look into merging with #commitVisibility() |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1765 | void setVisible(boolean newVisible) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1766 | visible = newVisible; |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1767 | mDeferHidingClient = !visible && mDeferHidingClient; |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1768 | setVisibility(visible); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1769 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; |
| 1770 | } |
| 1771 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1772 | void setState(ActivityState state, String reason) { |
| 1773 | if (DEBUG_STATES) Slog.v(TAG_STATES, "State movement: " + this + " from:" + getState() |
| 1774 | + " to:" + state + " reason:" + reason); |
Bryce Lee | 6ff1707 | 2018-02-28 07:26:17 -0800 | [diff] [blame] | 1775 | |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 1776 | if (state == mState) { |
| 1777 | // No need to do anything if state doesn't change. |
| 1778 | if (DEBUG_STATES) Slog.v(TAG_STATES, "State unchanged from:" + state); |
| 1779 | return; |
| 1780 | } |
| 1781 | |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 1782 | mState = state; |
| 1783 | |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1784 | final TaskRecord parent = getTask(); |
| 1785 | |
| 1786 | if (parent != null) { |
| 1787 | parent.onActivityStateChanged(this, state, reason); |
| 1788 | } |
Robert Carr | 29daa92 | 2018-04-27 11:56:48 -0700 | [diff] [blame] | 1789 | |
Robert Carr | 9e1bf7c | 2018-05-31 15:39:07 -0700 | [diff] [blame] | 1790 | // The WindowManager interprets the app stopping signal as |
| 1791 | // an indication that the Surface will eventually be destroyed. |
| 1792 | // This however isn't necessarily true if we are going to sleep. |
| 1793 | if (state == STOPPING && !isSleeping()) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1794 | if (mAppWindowToken == null) { |
| 1795 | Slog.w(TAG_WM, "Attempted to notify stopping on non-existing app token: " |
| 1796 | + appToken); |
| 1797 | return; |
| 1798 | } |
| 1799 | mAppWindowToken.detachChildren(); |
Robert Carr | 29daa92 | 2018-04-27 11:56:48 -0700 | [diff] [blame] | 1800 | } |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | ActivityState getState() { |
| 1804 | return mState; |
| 1805 | } |
| 1806 | |
| 1807 | /** |
| 1808 | * Returns {@code true} if the Activity is in the specified state. |
| 1809 | */ |
| 1810 | boolean isState(ActivityState state) { |
| 1811 | return state == mState; |
| 1812 | } |
| 1813 | |
| 1814 | /** |
| 1815 | * Returns {@code true} if the Activity is in one of the specified states. |
| 1816 | */ |
| 1817 | boolean isState(ActivityState state1, ActivityState state2) { |
| 1818 | return state1 == mState || state2 == mState; |
| 1819 | } |
| 1820 | |
| 1821 | /** |
| 1822 | * Returns {@code true} if the Activity is in one of the specified states. |
| 1823 | */ |
| 1824 | boolean isState(ActivityState state1, ActivityState state2, ActivityState state3) { |
| 1825 | return state1 == mState || state2 == mState || state3 == mState; |
| 1826 | } |
| 1827 | |
| 1828 | /** |
| 1829 | * Returns {@code true} if the Activity is in one of the specified states. |
| 1830 | */ |
| 1831 | boolean isState(ActivityState state1, ActivityState state2, ActivityState state3, |
| 1832 | ActivityState state4) { |
| 1833 | return state1 == mState || state2 == mState || state3 == mState || state4 == mState; |
| 1834 | } |
| 1835 | |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 1836 | void notifyAppResumed(boolean wasStopped) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1837 | if (mAppWindowToken == null) { |
| 1838 | Slog.w(TAG_WM, "Attempted to notify resumed of non-existing app token: " |
| 1839 | + appToken); |
| 1840 | return; |
| 1841 | } |
| 1842 | mAppWindowToken.notifyAppResumed(wasStopped); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | void notifyUnknownVisibilityLaunched() { |
Jorim Jaggi | 838c245 | 2017-08-28 15:44:43 +0200 | [diff] [blame] | 1846 | |
| 1847 | // No display activities never add a window, so there is no point in waiting them for |
| 1848 | // relayout. |
| 1849 | if (!noDisplay) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1850 | if (mAppWindowToken != null) { |
| 1851 | mAppWindowToken.getDisplayContent().mUnknownAppVisibilityController |
| 1852 | .notifyLaunched(mAppWindowToken); |
| 1853 | } |
Jorim Jaggi | 838c245 | 2017-08-28 15:44:43 +0200 | [diff] [blame] | 1854 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1855 | } |
| 1856 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1857 | /** |
| 1858 | * @return true if the input activity should be made visible, ignoring any effect Keyguard |
| 1859 | * might have on the visibility |
| 1860 | * |
| 1861 | * @see {@link ActivityStack#checkKeyguardVisibility} |
| 1862 | */ |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 1863 | boolean shouldBeVisibleIgnoringKeyguard(boolean behindFullscreenActivity) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1864 | if (!okToShowLocked()) { |
| 1865 | return false; |
| 1866 | } |
| 1867 | |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 1868 | return !behindFullscreenActivity || mLaunchTaskBehind; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1869 | } |
| 1870 | |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1871 | void makeVisibleIfNeeded(ActivityRecord starting, boolean reportToClient) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1872 | // 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] | 1873 | if (mState == RESUMED || this == starting) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1874 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1875 | "Not making visible, r=" + this + " state=" + mState + " starting=" + starting); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1876 | return; |
| 1877 | } |
| 1878 | |
| 1879 | // If this activity is paused, tell it to now show its window. |
| 1880 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1881 | "Making visible and scheduling visibility: " + this); |
| 1882 | final ActivityStack stack = getStack(); |
| 1883 | try { |
| 1884 | if (stack.mTranslucentActivityWaiting != null) { |
| 1885 | updateOptionsLocked(returningOptions); |
| 1886 | stack.mUndrawnActivitiesBelowTopTranslucent.add(this); |
| 1887 | } |
| 1888 | setVisible(true); |
| 1889 | sleeping = false; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1890 | app.postPendingUiCleanMsg(true); |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1891 | if (reportToClient) { |
| 1892 | makeClientVisible(); |
| 1893 | } else { |
| 1894 | mClientVisibilityDeferred = true; |
| 1895 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1896 | // The activity may be waiting for stop, but that is no longer appropriate for it. |
| 1897 | mStackSupervisor.mStoppingActivities.remove(this); |
| 1898 | mStackSupervisor.mGoingToSleepActivities.remove(this); |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1899 | } catch (Exception e) { |
| 1900 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 1901 | Slog.w(TAG, "Exception thrown making visible: " + intent.getComponent(), e); |
| 1902 | } |
| 1903 | handleAlreadyVisible(); |
| 1904 | } |
Andrii Kulian | 0d595f3 | 2018-02-21 15:47:33 -0800 | [diff] [blame] | 1905 | |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1906 | /** Send visibility change message to the client and pause if needed. */ |
| 1907 | void makeClientVisible() { |
| 1908 | mClientVisibilityDeferred = false; |
| 1909 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1910 | service.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1911 | WindowVisibilityItem.obtain(true /* showWindow */)); |
Andrii Kulian | 09e1afa | 2018-05-16 21:29:34 -0700 | [diff] [blame] | 1912 | if (shouldPauseWhenBecomingVisible()) { |
Andrii Kulian | 0d595f3 | 2018-02-21 15:47:33 -0800 | [diff] [blame] | 1913 | // An activity must be in the {@link PAUSING} state for the system to validate |
| 1914 | // the move to {@link PAUSED}. |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1915 | setState(PAUSING, "makeVisibleIfNeeded"); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1916 | service.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Andrii Kulian | 0d595f3 | 2018-02-21 15:47:33 -0800 | [diff] [blame] | 1917 | PauseActivityItem.obtain(finishing, false /* userLeaving */, |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 1918 | configChangeFlags, false /* dontReport */)); |
Andrii Kulian | 0d595f3 | 2018-02-21 15:47:33 -0800 | [diff] [blame] | 1919 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1920 | } catch (Exception e) { |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1921 | Slog.w(TAG, "Exception thrown sending visibility update: " + intent.getComponent(), e); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1922 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
Andrii Kulian | 09e1afa | 2018-05-16 21:29:34 -0700 | [diff] [blame] | 1925 | /** Check if activity should be moved to PAUSED state when it becomes visible. */ |
| 1926 | private boolean shouldPauseWhenBecomingVisible() { |
| 1927 | // If the activity is stopped or stopping, cycle to the paused state. We avoid doing |
| 1928 | // this when there is an activity waiting to become translucent as the extra binder |
| 1929 | // calls will lead to noticeable jank. A later call to |
| 1930 | // ActivityStack#ensureActivitiesVisibleLocked will bring the activity to the proper |
| 1931 | // paused state. We also avoid doing this for the activity the stack supervisor |
| 1932 | // considers the resumed activity, as normal means will bring the activity from STOPPED |
| 1933 | // to RESUMED. Adding PAUSING in this scenario will lead to double lifecycles. |
| 1934 | if (!isState(STOPPED, STOPPING) || getStack().mTranslucentActivityWaiting != null |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1935 | || isResumedActivityOnDisplay()) { |
Andrii Kulian | 09e1afa | 2018-05-16 21:29:34 -0700 | [diff] [blame] | 1936 | return false; |
| 1937 | } |
| 1938 | |
| 1939 | // Check if position in task allows to become paused |
| 1940 | final int positionInTask = task.mActivities.indexOf(this); |
| 1941 | if (positionInTask == -1) { |
| 1942 | throw new IllegalStateException("Activity not found in its task"); |
| 1943 | } |
| 1944 | if (positionInTask == task.mActivities.size() - 1) { |
| 1945 | // It's the topmost activity in the task - should become paused now |
| 1946 | return true; |
| 1947 | } |
| 1948 | // Check if activity above is finishing now and this one becomes the topmost in task. |
| 1949 | final ActivityRecord activityAbove = task.mActivities.get(positionInTask + 1); |
| 1950 | if (activityAbove.finishing && results == null) { |
| 1951 | // We will only allow pausing if activity above wasn't launched for result. Otherwise it |
| 1952 | // will cause this activity to resume before getting result. |
| 1953 | return true; |
| 1954 | } |
| 1955 | return false; |
| 1956 | } |
| 1957 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1958 | boolean handleAlreadyVisible() { |
| 1959 | stopFreezingScreenLocked(false); |
| 1960 | try { |
| 1961 | if (returningOptions != null) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1962 | app.getThread().scheduleOnNewActivityOptions(appToken, returningOptions.toBundle()); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1963 | } |
| 1964 | } catch(RemoteException e) { |
| 1965 | } |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1966 | return mState == RESUMED; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | static void activityResumedLocked(IBinder token) { |
| 1970 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 1971 | if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r); |
| 1972 | if (r != null) { |
| 1973 | r.icicle = null; |
| 1974 | r.haveState = false; |
| 1975 | } |
| 1976 | } |
| 1977 | |
| 1978 | /** |
| 1979 | * Once we know that we have asked an application to put an activity in the resumed state |
| 1980 | * (either by launching it or explicitly telling it), this function updates the rest of our |
| 1981 | * state to match that fact. |
| 1982 | */ |
| 1983 | void completeResumeLocked() { |
| 1984 | final boolean wasVisible = visible; |
Jorim Jaggi | 8d06205 | 2017-08-22 14:55:17 +0200 | [diff] [blame] | 1985 | setVisible(true); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1986 | if (!wasVisible) { |
| 1987 | // Visibility has changed, so take a note of it so we call the TaskStackChangedListener |
| 1988 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; |
| 1989 | } |
| 1990 | idle = false; |
| 1991 | results = null; |
| 1992 | newIntents = null; |
| 1993 | stopped = false; |
| 1994 | |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1995 | if (isActivityTypeHome()) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1996 | WindowProcessController app = task.mActivities.get(0).app; |
| 1997 | if (hasProcess() && app != service.mHomeProcess) { |
| 1998 | service.mHomeProcess = app; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1999 | } |
| 2000 | } |
| 2001 | |
| 2002 | if (nowVisible) { |
| 2003 | // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now. |
| 2004 | mStackSupervisor.reportActivityVisibleLocked(this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | // Schedule an idle timeout in case the app doesn't do it for us. |
| 2008 | mStackSupervisor.scheduleIdleTimeoutLocked(this); |
| 2009 | |
| 2010 | mStackSupervisor.reportResumedActivityLocked(this); |
| 2011 | |
| 2012 | resumeKeyDispatchingLocked(); |
| 2013 | final ActivityStack stack = getStack(); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2014 | mStackSupervisor.mNoAnimActivities.clear(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2015 | |
| 2016 | // Mark the point when the activity is resuming |
| 2017 | // TODO: To be more accurate, the mark should be before the onCreate, |
| 2018 | // not after the onResume. But for subsequent starts, onResume is fine. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2019 | if (hasProcess()) { |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 2020 | cpuTimeAtResume = app.getCpuTime(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2021 | } else { |
| 2022 | cpuTimeAtResume = 0; // Couldn't get the cpu time of process |
| 2023 | } |
| 2024 | |
| 2025 | returningOptions = null; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2026 | |
| 2027 | if (canTurnScreenOn()) { |
| 2028 | mStackSupervisor.wakeUp("turnScreenOnFlag"); |
| 2029 | } else { |
| 2030 | // If the screen is going to turn on because the caller explicitly requested it and |
| 2031 | // the keyguard is not showing don't attempt to sleep. Otherwise the Activity will |
| 2032 | // 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] | 2033 | stack.checkReadyForSleep(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2034 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | final void activityStoppedLocked(Bundle newIcicle, PersistableBundle newPersistentState, |
| 2038 | CharSequence description) { |
| 2039 | final ActivityStack stack = getStack(); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2040 | if (mState != STOPPING) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2041 | Slog.i(TAG, "Activity reported stop, but no longer stopping: " + this); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2042 | stack.mHandler.removeMessages(STOP_TIMEOUT_MSG, this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2043 | return; |
| 2044 | } |
| 2045 | if (newPersistentState != null) { |
| 2046 | persistentState = newPersistentState; |
| 2047 | service.notifyTaskPersisterLocked(task, false); |
| 2048 | } |
| 2049 | 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] | 2050 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2051 | if (newIcicle != null) { |
| 2052 | // If icicle is null, this is happening due to a timeout, so we haven't really saved |
| 2053 | // the state. |
| 2054 | icicle = newIcicle; |
| 2055 | haveState = true; |
| 2056 | launchCount = 0; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 2057 | updateTaskDescription(description); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2058 | } |
| 2059 | if (!stopped) { |
| 2060 | 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] | 2061 | stack.mHandler.removeMessages(STOP_TIMEOUT_MSG, this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2062 | stopped = true; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2063 | setState(STOPPED, "activityStoppedLocked"); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2064 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2065 | if (mAppWindowToken != null) { |
| 2066 | mAppWindowToken.notifyAppStopped(); |
| 2067 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2068 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2069 | if (finishing) { |
| 2070 | clearOptionsLocked(); |
| 2071 | } else { |
| 2072 | if (deferRelaunchUntilPaused) { |
| 2073 | stack.destroyActivityLocked(this, true /* removeFromApp */, "stop-config"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2074 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2075 | } else { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2076 | mRootActivityContainer.updatePreviousProcess(this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2077 | } |
| 2078 | } |
| 2079 | } |
| 2080 | } |
| 2081 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2082 | void startLaunchTickingLocked() { |
Jeff Sharkey | 5ab0243 | 2017-06-27 11:01:36 -0600 | [diff] [blame] | 2083 | if (Build.IS_USER) { |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2084 | return; |
| 2085 | } |
| 2086 | if (launchTickTime == 0) { |
| 2087 | launchTickTime = SystemClock.uptimeMillis(); |
| 2088 | continueLaunchTickingLocked(); |
| 2089 | } |
| 2090 | } |
| 2091 | |
| 2092 | boolean continueLaunchTickingLocked() { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2093 | if (launchTickTime == 0) { |
| 2094 | return false; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2095 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2096 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2097 | final ActivityStack stack = getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2098 | if (stack == null) { |
| 2099 | return false; |
| 2100 | } |
| 2101 | |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2102 | Message msg = stack.mHandler.obtainMessage(LAUNCH_TICK_MSG, this); |
| 2103 | stack.mHandler.removeMessages(LAUNCH_TICK_MSG); |
| 2104 | stack.mHandler.sendMessageDelayed(msg, LAUNCH_TICK); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2105 | return true; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
| 2108 | void finishLaunchTickingLocked() { |
| 2109 | launchTickTime = 0; |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2110 | final ActivityStack stack = getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2111 | if (stack != null) { |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2112 | stack.mHandler.removeMessages(LAUNCH_TICK_MSG); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2113 | } |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2114 | } |
| 2115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2116 | // IApplicationToken |
| 2117 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2118 | public boolean mayFreezeScreenLocked(WindowProcessController app) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2119 | // Only freeze the screen if this activity is currently attached to |
| 2120 | // an application, and that application is not blocked or unresponding. |
| 2121 | // In any other case, we can't count on getting the screen unfrozen, |
| 2122 | // so it is best to leave as-is. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2123 | return hasProcess() && !app.isCrashing() && !app.isNotResponding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2124 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 2125 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2126 | public void startFreezingScreenLocked(WindowProcessController app, int configChanges) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2127 | if (mayFreezeScreenLocked(app)) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2128 | if (mAppWindowToken == null) { |
| 2129 | Slog.w(TAG_WM, |
| 2130 | "Attempted to freeze screen with non-existing app token: " + appToken); |
| 2131 | return; |
| 2132 | } |
| 2133 | |
| 2134 | if (configChanges == 0 && mAppWindowToken.okToDisplay()) { |
| 2135 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Skipping set freeze of " + appToken); |
| 2136 | return; |
| 2137 | } |
| 2138 | |
| 2139 | mAppWindowToken.startFreezingScreen(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2140 | } |
| 2141 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 2142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2143 | public void stopFreezingScreenLocked(boolean force) { |
| 2144 | if (force || frozenBeforeDestroy) { |
| 2145 | frozenBeforeDestroy = false; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2146 | if (mAppWindowToken == null) { |
| 2147 | return; |
| 2148 | } |
| 2149 | if (DEBUG_ORIENTATION) { |
| 2150 | Slog.v(TAG_WM, "Clear freezing of " + appToken + ": hidden=" |
| 2151 | + mAppWindowToken.isHidden() + " freezing=" |
| 2152 | + mAppWindowToken.isFreezingScreen()); |
| 2153 | } |
| 2154 | mAppWindowToken.stopFreezingScreen(true, force); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2155 | } |
| 2156 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 2157 | |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 2158 | public void reportFullyDrawnLocked(boolean restoredFromBundle) { |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 2159 | final WindowingModeTransitionInfoSnapshot info = mStackSupervisor |
| 2160 | .getActivityMetricsLogger().logAppTransitionReportedDrawn(this, restoredFromBundle); |
| 2161 | if (info != null) { |
| 2162 | mStackSupervisor.reportActivityLaunchedLocked(false /* timeout */, this, |
| 2163 | info.windowsFullyDrawnDelayMs); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 2164 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 2165 | } |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2166 | |
| 2167 | /** |
| 2168 | * Called when the starting window for this container is drawn. |
| 2169 | */ |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 2170 | public void onStartingWindowDrawn(long timestamp) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2171 | synchronized (service.mGlobalLock) { |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2172 | mStackSupervisor.getActivityMetricsLogger().notifyStartingWindowDrawn( |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 2173 | getWindowingMode(), timestamp); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 2174 | } |
| 2175 | } |
| 2176 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2177 | /** Called when the windows associated app window container are drawn. */ |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 2178 | public void onWindowsDrawn(boolean drawn, long timestamp) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2179 | synchronized (service.mGlobalLock) { |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 2180 | mDrawn = drawn; |
| 2181 | if (!drawn) { |
| 2182 | return; |
| 2183 | } |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 2184 | final WindowingModeTransitionInfoSnapshot info = mStackSupervisor |
| 2185 | .getActivityMetricsLogger().notifyWindowsDrawn(getWindowingMode(), timestamp); |
| 2186 | final int windowsDrawnDelayMs = info != null ? info.windowsDrawnDelayMs : INVALID_DELAY; |
| 2187 | mStackSupervisor.reportActivityLaunchedLocked(false /* timeout */, this, |
| 2188 | windowsDrawnDelayMs); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2189 | mStackSupervisor.sendWaitingVisibleReportLocked(this); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2190 | finishLaunchTickingLocked(); |
| 2191 | if (task != null) { |
| 2192 | task.hasBeenVisible = true; |
| 2193 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2194 | } |
| 2195 | } |
| 2196 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2197 | /** Called when the windows associated app window container are visible. */ |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2198 | public void onWindowsVisible() { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2199 | synchronized (service.mGlobalLock) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2200 | mStackSupervisor.reportActivityVisibleLocked(this); |
| 2201 | if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this); |
| 2202 | if (!nowVisible) { |
| 2203 | nowVisible = true; |
| 2204 | lastVisibleTime = SystemClock.uptimeMillis(); |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 2205 | if (idle || mStackSupervisor.isStoppingNoHistoryActivity()) { |
| 2206 | // If this activity was already idle or there is an activity that must be |
| 2207 | // 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] | 2208 | // the full stop of any activities that are waiting to do so. This is because |
| 2209 | // 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] | 2210 | final int size = mStackSupervisor.mActivitiesWaitingForVisibleActivity.size(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2211 | if (size > 0) { |
| 2212 | for (int i = 0; i < size; i++) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2213 | final ActivityRecord r = |
| 2214 | mStackSupervisor.mActivitiesWaitingForVisibleActivity.get(i); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2215 | if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "Was waiting for visible: " + r); |
| 2216 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2217 | mStackSupervisor.mActivitiesWaitingForVisibleActivity.clear(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2218 | mStackSupervisor.scheduleIdleLocked(); |
| 2219 | } |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 2220 | } else { |
| 2221 | // Instead of doing the full stop routine here, let's just hide any activities |
| 2222 | // we now can, and let them stop when the normal idle happens. |
| 2223 | mStackSupervisor.processStoppingActivitiesLocked(null /* idleActivity */, |
| 2224 | false /* remove */, true /* processPausingActivities */); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2225 | } |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 2226 | service.scheduleAppGcsLocked(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2227 | } |
| 2228 | } |
| 2229 | } |
| 2230 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2231 | /** Called when the windows associated app window container are no longer visible. */ |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2232 | public void onWindowsGone() { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2233 | synchronized (service.mGlobalLock) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2234 | if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + this); |
| 2235 | nowVisible = false; |
| 2236 | } |
| 2237 | } |
| 2238 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2239 | /** |
| 2240 | * Called when the key dispatching to a window associated with the app window container |
| 2241 | * timed-out. |
| 2242 | * |
| 2243 | * @param reason The reason for the key dispatching time out. |
| 2244 | * @param windowPid The pid of the window key dispatching timed out on. |
| 2245 | * @return True if input dispatching should be aborted. |
| 2246 | */ |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 2247 | public boolean keyDispatchingTimedOut(String reason, int windowPid) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2248 | ActivityRecord anrActivity; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2249 | WindowProcessController anrApp; |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 2250 | boolean windowFromSameProcessAsActivity; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2251 | synchronized (service.mGlobalLock) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2252 | anrActivity = getWaitingHistoryRecordLocked(); |
| 2253 | anrApp = app; |
Brian Carlstrom | 7b0f2e8 | 2017-03-31 00:24:18 -0700 | [diff] [blame] | 2254 | windowFromSameProcessAsActivity = |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2255 | !hasProcess() || app.getPid() == windowPid || windowPid == -1; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2256 | } |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 2257 | |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 2258 | if (windowFromSameProcessAsActivity) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 2259 | return service.mAmInternal.inputDispatchingTimedOut(anrApp.mOwner, |
| 2260 | anrActivity.shortComponentName, anrActivity.appInfo, shortComponentName, |
| 2261 | app, false, reason); |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 2262 | } else { |
| 2263 | // In this case another process added windows using this activity token. So, we call the |
| 2264 | // generic service input dispatch timed out method so that the right process is blamed. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 2265 | return service.mAmInternal.inputDispatchingTimedOut( |
| 2266 | windowPid, false /* aboveSystem */, reason) < 0; |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 2267 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2268 | } |
| 2269 | |
| 2270 | private ActivityRecord getWaitingHistoryRecordLocked() { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 2271 | // First find the real culprit... if this activity is waiting for |
| 2272 | // another activity to start or has stopped, then the key dispatching |
| 2273 | // timeout should not be caused by this. |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2274 | if (mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(this) || stopped) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2275 | final ActivityStack stack = mRootActivityContainer.getTopDisplayFocusedStack(); |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 2276 | // Try to use the one which is closest to top. |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2277 | ActivityRecord r = stack.getResumedActivity(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2278 | if (r == null) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2279 | r = stack.mPausingActivity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2280 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 2281 | if (r != null) { |
| 2282 | return r; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2283 | } |
| 2284 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 2285 | return this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2286 | } |
| 2287 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 2288 | /** Checks whether the activity should be shown for current user. */ |
| 2289 | public boolean okToShowLocked() { |
Bryce Lee | 8558ec7 | 2017-08-17 15:37:26 -0700 | [diff] [blame] | 2290 | // We cannot show activities when the device is locked and the application is not |
| 2291 | // encryption aware. |
| 2292 | if (!StorageManager.isUserKeyUnlocked(userId) |
| 2293 | && !info.applicationInfo.isEncryptionAware()) { |
| 2294 | return false; |
| 2295 | } |
| 2296 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 2297 | return (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0 |
| 2298 | || (mStackSupervisor.isCurrentProfileLocked(userId) |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 2299 | && service.mAmInternal.isUserRunning(userId, 0 /* flags */)); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2302 | /** |
| 2303 | * This method will return true if the activity is either visible, is becoming visible, is |
| 2304 | * currently pausing, or is resumed. |
| 2305 | */ |
| 2306 | public boolean isInterestingToUserLocked() { |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2307 | return visible || nowVisible || mState == PAUSING || mState == RESUMED; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2308 | } |
| 2309 | |
Wale Ogunwale | 3e99736 | 2016-09-06 10:37:56 -0700 | [diff] [blame] | 2310 | void setSleeping(boolean _sleeping) { |
| 2311 | setSleeping(_sleeping, false); |
| 2312 | } |
| 2313 | |
| 2314 | void setSleeping(boolean _sleeping, boolean force) { |
| 2315 | if (!force && sleeping == _sleeping) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2316 | return; |
| 2317 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2318 | if (attachedToProcess()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2319 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2320 | app.getThread().scheduleSleeping(appToken, _sleeping); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2321 | if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) { |
| 2322 | mStackSupervisor.mGoingToSleepActivities.add(this); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2323 | } |
| 2324 | sleeping = _sleeping; |
| 2325 | } catch (RemoteException e) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2326 | Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2327 | } |
| 2328 | } |
| 2329 | } |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 2330 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2331 | static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2332 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2333 | if (r == null) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 2334 | return INVALID_TASK_ID; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2335 | } |
| 2336 | final TaskRecord task = r.task; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2337 | final int activityNdx = task.mActivities.indexOf(r); |
| 2338 | if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 2339 | return INVALID_TASK_ID; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2340 | } |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2341 | return task.taskId; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | static ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2345 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2346 | return (r != null) ? r.getStack().isInStackLocked(r) : null; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2347 | } |
| 2348 | |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 2349 | static ActivityStack getStackLocked(IBinder token) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2350 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2351 | if (r != null) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2352 | return r.getStack(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2353 | } |
| 2354 | return null; |
| 2355 | } |
| 2356 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2357 | /** |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 2358 | * @return display id to which this record is attached, |
| 2359 | * {@link android.view.Display#INVALID_DISPLAY} if not attached. |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2360 | */ |
| 2361 | int getDisplayId() { |
| 2362 | final ActivityStack stack = getStack(); |
| 2363 | if (stack == null) { |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 2364 | return INVALID_DISPLAY; |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2365 | } |
| 2366 | return stack.mDisplayId; |
| 2367 | } |
| 2368 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2369 | final boolean isDestroyable() { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2370 | if (finishing || !hasProcess()) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2371 | // This would be redundant. |
| 2372 | return false; |
| 2373 | } |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2374 | final ActivityStack stack = getStack(); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2375 | if (stack == null || this == stack.getResumedActivity() || this == stack.mPausingActivity |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2376 | || !haveState || !stopped) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2377 | // We're not ready for this kind of thing. |
| 2378 | return false; |
| 2379 | } |
| 2380 | if (visible) { |
| 2381 | // The user would notice this! |
| 2382 | return false; |
| 2383 | } |
| 2384 | return true; |
| 2385 | } |
| 2386 | |
Winson Chung | 3bad5cc0 | 2014-08-19 17:44:32 -0700 | [diff] [blame] | 2387 | private static String createImageFilename(long createTime, int taskId) { |
| 2388 | return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime + |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2389 | IMAGE_EXTENSION; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 2390 | } |
| 2391 | |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 2392 | void setTaskDescription(TaskDescription _taskDescription) { |
| 2393 | Bitmap icon; |
| 2394 | if (_taskDescription.getIconFilename() == null && |
| 2395 | (icon = _taskDescription.getIcon()) != null) { |
| 2396 | final String iconFilename = createImageFilename(createTime, task.taskId); |
Winson Chung | c8408b8 | 2017-01-25 17:58:56 -0800 | [diff] [blame] | 2397 | final File iconFile = new File(TaskPersister.getUserImagesDir(task.userId), |
| 2398 | iconFilename); |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 2399 | final String iconFilePath = iconFile.getAbsolutePath(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2400 | service.getRecentTasks().saveImage(icon, iconFilePath); |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 2401 | _taskDescription.setIconFilename(iconFilePath); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 2402 | } |
| 2403 | taskDescription = _taskDescription; |
| 2404 | } |
| 2405 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 2406 | void setVoiceSessionLocked(IVoiceInteractionSession session) { |
| 2407 | voiceSession = session; |
| 2408 | pendingVoiceInteractionStart = false; |
| 2409 | } |
| 2410 | |
| 2411 | void clearVoiceSessionLocked() { |
| 2412 | voiceSession = null; |
| 2413 | pendingVoiceInteractionStart = false; |
| 2414 | } |
| 2415 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2416 | void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch) { |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 2417 | showStartingWindow(prev, newTask, taskSwitch, false /* fromRecents */); |
| 2418 | } |
| 2419 | |
| 2420 | void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch, |
| 2421 | boolean fromRecents) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2422 | if (mAppWindowToken == null) { |
Jorim Jaggi | 7017643 | 2017-01-18 12:52:13 +0100 | [diff] [blame] | 2423 | return; |
| 2424 | } |
Wale Ogunwale | 19866e2 | 2017-04-19 06:05:13 -0700 | [diff] [blame] | 2425 | if (mTaskOverlay) { |
| 2426 | // We don't show starting window for overlay activities. |
| 2427 | return; |
| 2428 | } |
Sunny Goyal | d85bed5 | 2018-09-25 12:01:01 -0700 | [diff] [blame] | 2429 | if (pendingOptions != null |
| 2430 | && pendingOptions.getAnimationType() == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 2431 | // Don't show starting window when using shared element transition. |
| 2432 | return; |
| 2433 | } |
Wale Ogunwale | 19866e2 | 2017-04-19 06:05:13 -0700 | [diff] [blame] | 2434 | |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2435 | final CompatibilityInfo compatInfo = |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 2436 | service.compatibilityInfoForPackageLocked(info.applicationInfo); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2437 | final boolean shown = addStartingWindow(packageName, theme, |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2438 | compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags, |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 2439 | prev != null ? prev.appToken : null, newTask, taskSwitch, isProcessRunning(), |
Jorim Jaggi | 70aa4d1 | 2017-05-15 00:05:54 +0200 | [diff] [blame] | 2440 | allowTaskSnapshot(), |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2441 | mState.ordinal() >= RESUMED.ordinal() && mState.ordinal() <= STOPPED.ordinal(), |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 2442 | fromRecents); |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2443 | if (shown) { |
| 2444 | mStartingWindowState = STARTING_WINDOW_SHOWN; |
| 2445 | } |
| 2446 | } |
| 2447 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2448 | void removeOrphanedStartingWindow(boolean behindFullscreenActivity) { |
Jorim Jaggi | cb95605 | 2017-05-09 16:27:24 +0200 | [diff] [blame] | 2449 | if (mStartingWindowState == STARTING_WINDOW_SHOWN && behindFullscreenActivity) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2450 | if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, "Found orphaned starting window " + this); |
| 2451 | mStartingWindowState = STARTING_WINDOW_REMOVED; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2452 | mAppWindowToken.removeStartingWindow(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2453 | } |
| 2454 | } |
| 2455 | |
| 2456 | int getRequestedOrientation() { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2457 | return getOrientation(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2458 | } |
| 2459 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2460 | void setRequestedOrientation(int requestedOrientation) { |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2461 | final int displayId = getDisplayId(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2462 | final Configuration displayConfig = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2463 | mRootActivityContainer.getDisplayOverrideConfiguration(displayId); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2464 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2465 | final Configuration config = setOrientation(requestedOrientation, |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2466 | displayId, displayConfig, mayFreezeScreenLocked(app)); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2467 | if (config != null) { |
| 2468 | frozenBeforeDestroy = true; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2469 | if (!service.updateDisplayOverrideConfigurationLocked(config, this, |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2470 | false /* deferResume */, displayId)) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2471 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2472 | } |
| 2473 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2474 | service.getTaskChangeNotificationController().notifyActivityRequestedOrientationChanged( |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 2475 | task.taskId, requestedOrientation); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2476 | } |
| 2477 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2478 | Configuration setOrientation(int requestedOrientation, int displayId, |
| 2479 | Configuration displayConfig, boolean freezeScreenIfNeeded) { |
| 2480 | if (mAppWindowToken == null) { |
| 2481 | Slog.w(TAG_WM, |
| 2482 | "Attempted to set orientation of non-existing app token: " + appToken); |
| 2483 | return null; |
| 2484 | } |
| 2485 | |
| 2486 | mAppWindowToken.setOrientation(requestedOrientation); |
| 2487 | |
| 2488 | final IBinder binder = freezeScreenIfNeeded ? appToken.asBinder() : null; |
| 2489 | return service.mWindowManager.updateOrientationFromAppTokens(displayConfig, binder, |
| 2490 | displayId); |
| 2491 | } |
| 2492 | |
| 2493 | int getOrientation() { |
| 2494 | if (mAppWindowToken == null) { |
| 2495 | return SCREEN_ORIENTATION_UNSPECIFIED; |
| 2496 | } |
| 2497 | |
| 2498 | return mAppWindowToken.getOrientationIgnoreVisibility(); |
| 2499 | } |
| 2500 | |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 2501 | void setDisablePreviewScreenshots(boolean disable) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2502 | if (mAppWindowToken == null) { |
| 2503 | Slog.w(TAG_WM, "Attempted to set disable screenshots of non-existing app" |
| 2504 | + " token: " + appToken); |
| 2505 | return; |
| 2506 | } |
| 2507 | mAppWindowToken.setDisablePreviewScreenshots(disable); |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 2508 | } |
| 2509 | |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 2510 | /** |
| 2511 | * Set the last reported global configuration to the client. Should be called whenever a new |
| 2512 | * global configuration is sent to the client for this activity. |
| 2513 | */ |
| 2514 | void setLastReportedGlobalConfiguration(@NonNull Configuration config) { |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2515 | mLastReportedConfiguration.setGlobalConfiguration(config); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2516 | } |
| 2517 | |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 2518 | /** |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2519 | * Set the last reported configuration to the client. Should be called whenever |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 2520 | * a new merged configuration is sent to the client for this activity. |
| 2521 | */ |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2522 | void setLastReportedConfiguration(@NonNull MergedConfiguration config) { |
Bryce Lee | 8104e7a | 2017-08-17 09:16:03 -0700 | [diff] [blame] | 2523 | setLastReportedConfiguration(config.getGlobalConfiguration(), |
| 2524 | config.getOverrideConfiguration()); |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 2525 | } |
| 2526 | |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2527 | private void setLastReportedConfiguration(Configuration global, Configuration override) { |
Bryce Lee | 8104e7a | 2017-08-17 09:16:03 -0700 | [diff] [blame] | 2528 | mLastReportedConfiguration.setConfiguration(global, override); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2529 | } |
| 2530 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2531 | // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer. |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2532 | private void updateOverrideConfiguration() { |
| 2533 | mTmpConfig.unset(); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2534 | computeBounds(mTmpBounds); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2535 | |
| 2536 | if (mTmpBounds.equals(getOverrideBounds())) { |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2537 | return; |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2538 | } |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2539 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2540 | setBounds(mTmpBounds); |
| 2541 | |
| 2542 | final Rect updatedBounds = getOverrideBounds(); |
| 2543 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2544 | // Bounds changed...update configuration to match. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2545 | if (!matchParentBounds()) { |
| 2546 | task.computeOverrideConfiguration(mTmpConfig, updatedBounds, null /* insetBounds */, |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2547 | false /* overrideWidth */, false /* overrideHeight */); |
| 2548 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2549 | |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2550 | onOverrideConfigurationChanged(mTmpConfig); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
Wale Ogunwale | d4b1d1e | 2017-04-10 06:35:59 -0700 | [diff] [blame] | 2553 | /** Returns true if the configuration is compatible with this activity. */ |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 2554 | boolean isConfigurationCompatible(Configuration config) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2555 | final int orientation = mAppWindowToken != null |
| 2556 | ? getOrientation() : info.screenOrientation; |
Wale Ogunwale | d4b1d1e | 2017-04-10 06:35:59 -0700 | [diff] [blame] | 2557 | if (isFixedOrientationPortrait(orientation) |
| 2558 | && config.orientation != ORIENTATION_PORTRAIT) { |
| 2559 | return false; |
| 2560 | } |
| 2561 | if (isFixedOrientationLandscape(orientation) |
| 2562 | && config.orientation != ORIENTATION_LANDSCAPE) { |
| 2563 | return false; |
| 2564 | } |
| 2565 | return true; |
| 2566 | } |
| 2567 | |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 2568 | /** |
| 2569 | * Computes the bounds to fit the Activity within the bounds of the {@link Configuration}. |
| 2570 | */ |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2571 | // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer. |
| 2572 | private void computeBounds(Rect outBounds) { |
| 2573 | outBounds.setEmpty(); |
| 2574 | final float maxAspectRatio = info.maxAspectRatio; |
| 2575 | final ActivityStack stack = getStack(); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2576 | if (task == null || stack == null || task.inMultiWindowMode() || maxAspectRatio == 0 |
Bryce Lee | e5ab450 | 2017-07-11 08:58:05 -0700 | [diff] [blame] | 2577 | || isInVrUiMode(getConfiguration())) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2578 | // We don't set override configuration if that activity task isn't fullscreen. I.e. the |
| 2579 | // 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] | 2580 | // the activity. This is indicated by an empty {@link outBounds}. We also don't set it |
| 2581 | // if we are in VR mode. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2582 | return; |
| 2583 | } |
| 2584 | |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 2585 | // We must base this on the parent configuration, because we set our override |
| 2586 | // configuration's appBounds based on the result of this method. If we used our own |
| 2587 | // configuration, it would be influenced by past invocations. |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 2588 | final Rect appBounds = getParent().getWindowConfiguration().getAppBounds(); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 2589 | final int containingAppWidth = appBounds.width(); |
| 2590 | final int containingAppHeight = appBounds.height(); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 2591 | int maxActivityWidth = containingAppWidth; |
| 2592 | int maxActivityHeight = containingAppHeight; |
| 2593 | |
| 2594 | if (containingAppWidth < containingAppHeight) { |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2595 | // Width is the shorter side, so we use that to figure-out what the max. height |
| 2596 | // should be given the aspect ratio. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2597 | maxActivityHeight = (int) ((maxActivityWidth * maxAspectRatio) + 0.5f); |
| 2598 | } else { |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2599 | // Height is the shorter side, so we use that to figure-out what the max. width |
| 2600 | // should be given the aspect ratio. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2601 | maxActivityWidth = (int) ((maxActivityHeight * maxAspectRatio) + 0.5f); |
| 2602 | } |
| 2603 | |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 2604 | if (containingAppWidth <= maxActivityWidth && containingAppHeight <= maxActivityHeight) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2605 | // 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] | 2606 | // 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] | 2607 | // {@link #getOverrideBounds()} will be empty (representing no override). If the method has run |
| 2608 | // 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] | 2609 | // value returned from {@link getConfiguration}. Refer to |
| 2610 | // {@link TaskRecord#computeOverrideConfiguration}. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2611 | outBounds.set(getOverrideBounds()); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2612 | return; |
| 2613 | } |
| 2614 | |
| 2615 | // Compute configuration based on max supported width and height. |
Adrian Roos | 24be34d | 2018-05-28 18:55:38 +0200 | [diff] [blame] | 2616 | // Also account for the left / top insets (e.g. from display cutouts), which will be clipped |
| 2617 | // away later in StackWindowController.adjustConfigurationForBounds(). Otherwise, the app |
| 2618 | // bounds would end up too small. |
| 2619 | outBounds.set(0, 0, maxActivityWidth + appBounds.left, maxActivityHeight + appBounds.top); |
| 2620 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2621 | if (service.mWindowManager.getNavBarPosition(getDisplayId()) == NAV_BAR_LEFT) { |
Adrian Roos | 24be34d | 2018-05-28 18:55:38 +0200 | [diff] [blame] | 2622 | // Position the activity frame on the opposite side of the nav bar. |
| 2623 | outBounds.left = appBounds.right - maxActivityWidth; |
| 2624 | outBounds.right = appBounds.right; |
| 2625 | } |
Andrii Kulian | 3a1619d | 2017-07-07 14:38:09 -0700 | [diff] [blame] | 2626 | } |
| 2627 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 2628 | /** |
| 2629 | * @return {@code true} if this activity was reparented to another display but |
| 2630 | * {@link #ensureActivityConfiguration} is not called. |
| 2631 | */ |
| 2632 | boolean shouldUpdateConfigForDisplayChanged() { |
| 2633 | return mLastReportedDisplayId != getDisplayId(); |
| 2634 | } |
| 2635 | |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 2636 | boolean ensureActivityConfiguration(int globalChanges, boolean preserveWindow) { |
| 2637 | return ensureActivityConfiguration(globalChanges, preserveWindow, |
| 2638 | false /* ignoreStopState */); |
| 2639 | } |
| 2640 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2641 | /** |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 2642 | * Make sure the given activity matches the current configuration. Ensures the HistoryRecord |
| 2643 | * is updated with the correct configuration and all other bookkeeping is handled. |
| 2644 | * |
| 2645 | * @param globalChanges The changes to the global configuration. |
| 2646 | * @param preserveWindow If the activity window should be preserved on screen if the activity |
| 2647 | * is relaunched. |
| 2648 | * @param ignoreStopState If we should try to relaunch the activity even if it is in the stopped |
| 2649 | * state. This is useful for the case where we know the activity will be |
| 2650 | * visible soon and we want to ensure its configuration before we make it |
| 2651 | * visible. |
| 2652 | * @return True if the activity was relaunched and false if it wasn't relaunched because we |
| 2653 | * can't or the app handles the specific configuration that is changing. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2654 | */ |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 2655 | boolean ensureActivityConfiguration(int globalChanges, boolean preserveWindow, |
| 2656 | boolean ignoreStopState) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2657 | final ActivityStack stack = getStack(); |
| 2658 | if (stack.mConfigWillChange) { |
| 2659 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2660 | "Skipping config check (will change): " + this); |
| 2661 | return true; |
| 2662 | } |
| 2663 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2664 | // We don't worry about activities that are finishing. |
| 2665 | if (finishing) { |
| 2666 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2667 | "Configuration doesn't matter in finishing " + this); |
| 2668 | stopFreezingScreenLocked(false); |
| 2669 | return true; |
| 2670 | } |
| 2671 | |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 2672 | if (!ignoreStopState && (mState == STOPPING || mState == STOPPED)) { |
Wale Ogunwale | 9b7a827 | 2017-04-10 08:05:41 -0700 | [diff] [blame] | 2673 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2674 | "Skipping config check stopped or stopping: " + this); |
| 2675 | return true; |
| 2676 | } |
| 2677 | |
Wale Ogunwale | ea3d3fd | 2017-05-01 07:41:08 -0700 | [diff] [blame] | 2678 | // TODO: We should add ActivityRecord.shouldBeVisible() that checks if the activity should |
| 2679 | // be visible based on the stack, task, and lockscreen state and use that here instead. The |
| 2680 | // method should be based on the logic in ActivityStack.ensureActivitiesVisibleLocked(). |
Wale Ogunwale | 9b7a827 | 2017-04-10 08:05:41 -0700 | [diff] [blame] | 2681 | // 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] | 2682 | if (!stack.shouldBeVisible(null /* starting */)) { |
Wale Ogunwale | 9b7a827 | 2017-04-10 08:05:41 -0700 | [diff] [blame] | 2683 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2684 | "Skipping config check invisible stack: " + this); |
| 2685 | return true; |
| 2686 | } |
| 2687 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2688 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2689 | "Ensuring correct configuration: " + this); |
| 2690 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2691 | final int newDisplayId = getDisplayId(); |
| 2692 | final boolean displayChanged = mLastReportedDisplayId != newDisplayId; |
| 2693 | if (displayChanged) { |
| 2694 | mLastReportedDisplayId = newDisplayId; |
| 2695 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2696 | // TODO(b/36505427): Is there a better place to do this? |
| 2697 | updateOverrideConfiguration(); |
| 2698 | |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 2699 | // Short circuit: if the two full configurations are equal (the common case), then there is |
| 2700 | // nothing to do. We test the full configuration instead of the global and merged override |
| 2701 | // configurations because there are cases (like moving a task to the pinned stack) where |
| 2702 | // 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] | 2703 | mTmpConfig.setTo(mLastReportedConfiguration.getMergedConfiguration()); |
| 2704 | if (getConfiguration().equals(mTmpConfig) && !forceNewConfig && !displayChanged) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2705 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2706 | "Configuration & display unchanged in " + this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2707 | return true; |
| 2708 | } |
| 2709 | |
| 2710 | // Okay we now are going to make this activity have the new config. |
| 2711 | // 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] | 2712 | |
| 2713 | // Find changes between last reported merged configuration and the current one. This is used |
| 2714 | // 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] | 2715 | final int changes = getConfigurationChanges(mTmpConfig); |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 2716 | |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 2717 | // Update last reported values. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2718 | final Configuration newMergedOverrideConfig = getMergedOverrideConfiguration(); |
Bryce Lee | 8104e7a | 2017-08-17 09:16:03 -0700 | [diff] [blame] | 2719 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 2720 | setLastReportedConfiguration(service.getGlobalConfiguration(), newMergedOverrideConfig); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2721 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2722 | if (mState == INITIALIZING) { |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 2723 | // No need to relaunch or schedule new config for activity that hasn't been launched |
| 2724 | // yet. We do, however, return after applying the config to activity record, so that |
| 2725 | // it will use it for launch transaction. |
| 2726 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2727 | "Skipping config check for initializing activity: " + this); |
| 2728 | return true; |
| 2729 | } |
| 2730 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2731 | if (changes == 0 && !forceNewConfig) { |
| 2732 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2733 | "Configuration no differences in " + this); |
| 2734 | // There are no significant differences, so we won't relaunch but should still deliver |
| 2735 | // the new configuration to the client process. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2736 | if (displayChanged) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2737 | scheduleActivityMovedToDisplay(newDisplayId, newMergedOverrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2738 | } else { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2739 | scheduleConfigurationChanged(newMergedOverrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2740 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2741 | return true; |
| 2742 | } |
| 2743 | |
| 2744 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 2745 | "Configuration changes for " + this + ", allChanges=" |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2746 | + Configuration.configurationDiffToString(changes)); |
| 2747 | |
| 2748 | // If the activity isn't currently running, just leave the new configuration and it will |
| 2749 | // pick that up next time it starts. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2750 | if (!attachedToProcess()) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2751 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2752 | "Configuration doesn't matter not running " + this); |
| 2753 | stopFreezingScreenLocked(false); |
| 2754 | forceNewConfig = false; |
| 2755 | return true; |
| 2756 | } |
| 2757 | |
| 2758 | // Figure out how to handle the changes between the configurations. |
| 2759 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2760 | "Checking to restart " + info.name + ": changed=0x" |
| 2761 | + Integer.toHexString(changes) + ", handles=0x" |
| 2762 | + Integer.toHexString(info.getRealConfigChanged()) |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2763 | + ", mLastReportedConfiguration=" + mLastReportedConfiguration); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2764 | |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2765 | if (shouldRelaunchLocked(changes, mTmpConfig) || forceNewConfig) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2766 | // Aha, the activity isn't handling the change, so DIE DIE DIE. |
| 2767 | configChangeFlags |= changes; |
| 2768 | startFreezingScreenLocked(app, globalChanges); |
| 2769 | forceNewConfig = false; |
| 2770 | preserveWindow &= isResizeOnlyChange(changes); |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 2771 | final boolean hasResizeChange = hasResizeChange(changes & ~info.getRealConfigChanged()); |
| 2772 | if (hasResizeChange) { |
| 2773 | final boolean isDragResizing = |
| 2774 | getTask().getWindowContainerController().isDragResizing(); |
| 2775 | mRelaunchReason = isDragResizing ? RELAUNCH_REASON_FREE_RESIZE |
| 2776 | : RELAUNCH_REASON_WINDOWING_MODE_RESIZE; |
| 2777 | } else { |
| 2778 | mRelaunchReason = RELAUNCH_REASON_NONE; |
| 2779 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2780 | if (!attachedToProcess()) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2781 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2782 | "Config is destroying non-running " + this); |
| 2783 | stack.destroyActivityLocked(this, true, "config"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2784 | } else if (mState == PAUSING) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2785 | // A little annoying: we are waiting for this activity to finish pausing. Let's not |
| 2786 | // do anything now, but just flag that it needs to be restarted when done pausing. |
| 2787 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2788 | "Config is skipping already pausing " + this); |
| 2789 | deferRelaunchUntilPaused = true; |
| 2790 | preserveWindowOnDeferredRelaunch = preserveWindow; |
| 2791 | return true; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2792 | } else if (mState == RESUMED) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2793 | // Try to optimize this case: the configuration is changing and we need to restart |
| 2794 | // the top, resumed activity. Instead of doing the normal handshaking, just say |
| 2795 | // "restart!". |
| 2796 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2797 | "Config is relaunching resumed " + this); |
| 2798 | |
| 2799 | if (DEBUG_STATES && !visible) { |
| 2800 | Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + this |
| 2801 | + " called by " + Debug.getCallers(4)); |
| 2802 | } |
| 2803 | |
| 2804 | relaunchActivityLocked(true /* andResume */, preserveWindow); |
| 2805 | } else { |
| 2806 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 2807 | "Config is relaunching non-resumed " + this); |
| 2808 | relaunchActivityLocked(false /* andResume */, preserveWindow); |
| 2809 | } |
| 2810 | |
| 2811 | // All done... tell the caller we weren't able to keep this activity around. |
| 2812 | return false; |
| 2813 | } |
| 2814 | |
| 2815 | // 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] | 2816 | // NOTE: We only forward the override configuration as the system level configuration |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2817 | // changes is always sent to all processes when they happen so it can just use whatever |
| 2818 | // system level configuration it last got. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2819 | if (displayChanged) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2820 | scheduleActivityMovedToDisplay(newDisplayId, newMergedOverrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2821 | } else { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2822 | scheduleConfigurationChanged(newMergedOverrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2823 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2824 | stopFreezingScreenLocked(false); |
| 2825 | |
| 2826 | return true; |
| 2827 | } |
| 2828 | |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 2829 | /** |
| 2830 | * When assessing a configuration change, decide if the changes flags and the new configurations |
| 2831 | * should cause the Activity to relaunch. |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 2832 | * |
| 2833 | * @param changes the changes due to the given configuration. |
| 2834 | * @param changesConfig the configuration that was used to calculate the given changes via a |
| 2835 | * call to getConfigurationChanges. |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 2836 | */ |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 2837 | private boolean shouldRelaunchLocked(int changes, Configuration changesConfig) { |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 2838 | int configChanged = info.getRealConfigChanged(); |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 2839 | boolean onlyVrUiModeChanged = onlyVrUiModeChanged(changes, changesConfig); |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 2840 | |
| 2841 | // Override for apps targeting pre-O sdks |
| 2842 | // If a device is in VR mode, and we're transitioning into VR ui mode, add ignore ui mode |
| 2843 | // to the config change. |
| 2844 | // For O and later, apps will be required to add configChanges="uimode" to their manifest. |
| 2845 | if (appInfo.targetSdkVersion < O |
| 2846 | && requestedVrComponent != null |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 2847 | && onlyVrUiModeChanged) { |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 2848 | configChanged |= CONFIG_UI_MODE; |
| 2849 | } |
| 2850 | |
| 2851 | return (changes&(~configChanged)) != 0; |
| 2852 | } |
| 2853 | |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 2854 | /** |
| 2855 | * Returns true if the configuration change is solely due to the UI mode switching into or out |
| 2856 | * of UI_MODE_TYPE_VR_HEADSET. |
| 2857 | */ |
| 2858 | private boolean onlyVrUiModeChanged(int changes, Configuration lastReportedConfig) { |
| 2859 | final Configuration currentConfig = getConfiguration(); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2860 | return changes == CONFIG_UI_MODE && (isInVrUiMode(currentConfig) |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 2861 | != isInVrUiMode(lastReportedConfig)); |
| 2862 | } |
| 2863 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2864 | private int getConfigurationChanges(Configuration lastReportedConfig) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2865 | // Determine what has changed. May be nothing, if this is a config that has come back from |
| 2866 | // the app after going idle. In that case we just want to leave the official config object |
| 2867 | // now in the activity and do nothing else. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2868 | final Configuration currentConfig = getConfiguration(); |
| 2869 | int changes = lastReportedConfig.diff(currentConfig); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2870 | // We don't want to use size changes if they don't cross boundaries that are important to |
| 2871 | // the app. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2872 | if ((changes & CONFIG_SCREEN_SIZE) != 0) { |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 2873 | final boolean crosses = crossesHorizontalSizeThreshold(lastReportedConfig.screenWidthDp, |
| 2874 | currentConfig.screenWidthDp) |
| 2875 | || crossesVerticalSizeThreshold(lastReportedConfig.screenHeightDp, |
| 2876 | currentConfig.screenHeightDp); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2877 | if (!crosses) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2878 | changes &= ~CONFIG_SCREEN_SIZE; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2879 | } |
| 2880 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2881 | if ((changes & CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 2882 | final int oldSmallest = lastReportedConfig.smallestScreenWidthDp; |
| 2883 | final int newSmallest = currentConfig.smallestScreenWidthDp; |
| 2884 | if (!crossesSmallestSizeThreshold(oldSmallest, newSmallest)) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2885 | changes &= ~CONFIG_SMALLEST_SCREEN_SIZE; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2886 | } |
| 2887 | } |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 2888 | // We don't want window configuration to cause relaunches. |
| 2889 | if ((changes & CONFIG_WINDOW_CONFIGURATION) != 0) { |
| 2890 | changes &= ~CONFIG_WINDOW_CONFIGURATION; |
| 2891 | } |
Bryce Lee | 600dadd | 2017-07-25 10:48:42 -0700 | [diff] [blame] | 2892 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2893 | return changes; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | private static boolean isResizeOnlyChange(int change) { |
| 2897 | return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION |
| 2898 | | CONFIG_SCREEN_LAYOUT)) == 0; |
| 2899 | } |
| 2900 | |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 2901 | private static boolean hasResizeChange(int change) { |
| 2902 | return (change & (CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION |
| 2903 | | CONFIG_SCREEN_LAYOUT)) != 0; |
| 2904 | } |
| 2905 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2906 | void relaunchActivityLocked(boolean andResume, boolean preserveWindow) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2907 | if (service.mSuppressResizeConfigChanges && preserveWindow) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2908 | configChangeFlags = 0; |
| 2909 | return; |
| 2910 | } |
| 2911 | |
| 2912 | List<ResultInfo> pendingResults = null; |
| 2913 | List<ReferrerIntent> pendingNewIntents = null; |
| 2914 | if (andResume) { |
| 2915 | pendingResults = results; |
| 2916 | pendingNewIntents = newIntents; |
| 2917 | } |
| 2918 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2919 | "Relaunching: " + this + " with results=" + pendingResults |
| 2920 | + " newIntents=" + pendingNewIntents + " andResume=" + andResume |
| 2921 | + " preserveWindow=" + preserveWindow); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2922 | EventLog.writeEvent(andResume ? AM_RELAUNCH_RESUME_ACTIVITY |
| 2923 | : AM_RELAUNCH_ACTIVITY, userId, System.identityHashCode(this), |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2924 | task.taskId, shortComponentName); |
| 2925 | |
| 2926 | startFreezingScreenLocked(app, 0); |
| 2927 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2928 | try { |
| 2929 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, |
| 2930 | "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + this |
| 2931 | + " callers=" + Debug.getCallers(6)); |
| 2932 | forceNewConfig = false; |
| 2933 | mStackSupervisor.activityRelaunchingLocked(this); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 2934 | final ClientTransactionItem callbackItem = ActivityRelaunchItem.obtain(pendingResults, |
| 2935 | pendingNewIntents, configChangeFlags, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 2936 | new MergedConfiguration(service.getGlobalConfiguration(), |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 2937 | getMergedOverrideConfiguration()), |
| 2938 | preserveWindow); |
| 2939 | final ActivityLifecycleItem lifecycleItem; |
| 2940 | if (andResume) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2941 | lifecycleItem = ResumeActivityItem.obtain( |
| 2942 | getDisplay().getWindowContainerController().isNextTransitionForward()); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 2943 | } else { |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 2944 | lifecycleItem = PauseActivityItem.obtain(); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 2945 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2946 | final ClientTransaction transaction = ClientTransaction.obtain(app.getThread(), appToken); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 2947 | transaction.addCallback(callbackItem); |
| 2948 | transaction.setLifecycleStateRequest(lifecycleItem); |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 2949 | service.getLifecycleManager().scheduleTransaction(transaction); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2950 | // 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] | 2951 | // 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] | 2952 | // sleeping. |
| 2953 | } catch (RemoteException e) { |
| 2954 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e); |
| 2955 | } |
| 2956 | |
| 2957 | if (andResume) { |
| 2958 | if (DEBUG_STATES) { |
| 2959 | Slog.d(TAG_STATES, "Resumed after relaunch " + this); |
| 2960 | } |
| 2961 | results = null; |
| 2962 | newIntents = null; |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 2963 | service.getAppWarningsLocked().onResumeActivity(this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2964 | } else { |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 2965 | final ActivityStack stack = getStack(); |
| 2966 | if (stack != null) { |
| 2967 | stack.mHandler.removeMessages(PAUSE_TIMEOUT_MSG, this); |
| 2968 | } |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2969 | setState(PAUSED, "relaunchActivityLocked"); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2970 | } |
| 2971 | |
| 2972 | configChangeFlags = 0; |
| 2973 | deferRelaunchUntilPaused = false; |
| 2974 | preserveWindowOnDeferredRelaunch = false; |
| 2975 | } |
| 2976 | |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 2977 | private boolean isProcessRunning() { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2978 | WindowProcessController proc = app; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2979 | if (proc == null) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2980 | proc = service.mProcessNames.get(processName, info.applicationInfo.uid); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2981 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2982 | return proc != null && proc.hasThread(); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2983 | } |
| 2984 | |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 2985 | /** |
| 2986 | * @return Whether a task snapshot starting window may be shown. |
| 2987 | */ |
| 2988 | private boolean allowTaskSnapshot() { |
| 2989 | if (newIntents == null) { |
| 2990 | return true; |
| 2991 | } |
| 2992 | |
| 2993 | // Restrict task snapshot starting window to launcher start, or there is no intent at all |
| 2994 | // (eg. task being brought to front). If the intent is something else, likely the app is |
| 2995 | // going to show some specific page or view, instead of what's left last time. |
| 2996 | for (int i = newIntents.size() - 1; i >= 0; i--) { |
| 2997 | final Intent intent = newIntents.get(i); |
| 2998 | if (intent != null && !ActivityRecord.isMainIntent(intent)) { |
| 2999 | return false; |
| 3000 | } |
| 3001 | } |
| 3002 | return true; |
| 3003 | } |
| 3004 | |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 3005 | /** |
| 3006 | * Returns {@code true} if the associated activity has the no history flag set on it. |
| 3007 | * {@code false} otherwise. |
| 3008 | */ |
| 3009 | boolean isNoHistory() { |
| 3010 | return (intent.getFlags() & FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 3011 | || (info.flags & FLAG_NO_HISTORY) != 0; |
| 3012 | } |
| 3013 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3014 | void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException { |
| 3015 | out.attribute(null, ATTR_ID, String.valueOf(createTime)); |
| 3016 | out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid)); |
| 3017 | if (launchedFromPackage != null) { |
| 3018 | out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage); |
| 3019 | } |
| 3020 | if (resolvedType != null) { |
| 3021 | out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType); |
| 3022 | } |
| 3023 | out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified)); |
| 3024 | out.attribute(null, ATTR_USERID, String.valueOf(userId)); |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 3025 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3026 | if (taskDescription != null) { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 3027 | taskDescription.saveToXml(out); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | out.startTag(null, TAG_INTENT); |
| 3031 | intent.saveToXml(out); |
| 3032 | out.endTag(null, TAG_INTENT); |
| 3033 | |
| 3034 | if (isPersistable() && persistentState != null) { |
| 3035 | out.startTag(null, TAG_PERSISTABLEBUNDLE); |
| 3036 | persistentState.saveToXml(out); |
| 3037 | out.endTag(null, TAG_PERSISTABLEBUNDLE); |
| 3038 | } |
| 3039 | } |
| 3040 | |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 3041 | static ActivityRecord restoreFromXml(XmlPullParser in, |
| 3042 | ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3043 | Intent intent = null; |
| 3044 | PersistableBundle persistentState = null; |
| 3045 | int launchedFromUid = 0; |
| 3046 | String launchedFromPackage = null; |
| 3047 | String resolvedType = null; |
| 3048 | boolean componentSpecified = false; |
| 3049 | int userId = 0; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3050 | long createTime = -1; |
| 3051 | final int outerDepth = in.getDepth(); |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 3052 | TaskDescription taskDescription = new TaskDescription(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3053 | |
| 3054 | for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) { |
| 3055 | final String attrName = in.getAttributeName(attrNdx); |
| 3056 | final String attrValue = in.getAttributeValue(attrNdx); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3057 | if (DEBUG) Slog.d(TaskPersister.TAG, |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 3058 | "ActivityRecord: attribute name=" + attrName + " value=" + attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3059 | if (ATTR_ID.equals(attrName)) { |
Tobias Thierer | 28532d0 | 2016-04-21 14:52:10 +0100 | [diff] [blame] | 3060 | createTime = Long.parseLong(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3061 | } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 3062 | launchedFromUid = Integer.parseInt(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3063 | } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) { |
| 3064 | launchedFromPackage = attrValue; |
| 3065 | } else if (ATTR_RESOLVEDTYPE.equals(attrName)) { |
| 3066 | resolvedType = attrValue; |
| 3067 | } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) { |
Tobias Thierer | b0800dc | 2016-04-21 17:51:41 +0100 | [diff] [blame] | 3068 | componentSpecified = Boolean.parseBoolean(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3069 | } else if (ATTR_USERID.equals(attrName)) { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 3070 | userId = Integer.parseInt(attrValue); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3071 | } else if (attrName.startsWith(ATTR_TASKDESCRIPTION_PREFIX)) { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 3072 | taskDescription.restoreFromXml(attrName, attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3073 | } else { |
| 3074 | Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName); |
| 3075 | } |
| 3076 | } |
| 3077 | |
| 3078 | int event; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3079 | while (((event = in.next()) != END_DOCUMENT) && |
| 3080 | (event != END_TAG || in.getDepth() >= outerDepth)) { |
| 3081 | if (event == START_TAG) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3082 | final String name = in.getName(); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3083 | if (DEBUG) |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 3084 | Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3085 | if (TAG_INTENT.equals(name)) { |
| 3086 | intent = Intent.restoreFromXml(in); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3087 | if (DEBUG) |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 3088 | Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3089 | } else if (TAG_PERSISTABLEBUNDLE.equals(name)) { |
| 3090 | persistentState = PersistableBundle.restoreFromXml(in); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3091 | if (DEBUG) Slog.d(TaskPersister.TAG, |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3092 | "ActivityRecord: persistentState=" + persistentState); |
| 3093 | } else { |
| 3094 | Slog.w(TAG, "restoreActivity: unexpected name=" + name); |
| 3095 | XmlUtils.skipCurrentTag(in); |
| 3096 | } |
| 3097 | } |
| 3098 | } |
| 3099 | |
| 3100 | if (intent == null) { |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 3101 | throw new XmlPullParserException("restoreActivity error intent=" + intent); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3102 | } |
| 3103 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 3104 | final ActivityTaskManagerService service = stackSupervisor.mService; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3105 | final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null, |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 3106 | userId, Binder.getCallingUid()); |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 3107 | if (aInfo == null) { |
Craig Mautner | 77b0426 | 2014-06-27 15:22:12 -0700 | [diff] [blame] | 3108 | throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent + |
| 3109 | " resolvedType=" + resolvedType); |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 3110 | } |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 3111 | final ActivityRecord r = new ActivityRecord(service, null /* caller */, |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 3112 | 0 /* launchedFromPid */, launchedFromUid, launchedFromPackage, intent, resolvedType, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3113 | aInfo, service.getConfiguration(), null /* resultTo */, null /* resultWho */, |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 3114 | 0 /* reqCode */, componentSpecified, false /* rootVoiceInteraction */, |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 3115 | stackSupervisor, null /* options */, null /* sourceRecord */); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3116 | |
| 3117 | r.persistentState = persistentState; |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 3118 | r.taskDescription = taskDescription; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3119 | r.createTime = createTime; |
| 3120 | |
| 3121 | return r; |
| 3122 | } |
| 3123 | |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 3124 | private static boolean isInVrUiMode(Configuration config) { |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3125 | return (config.uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_VR_HEADSET; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 3126 | } |
| 3127 | |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 3128 | int getUid() { |
| 3129 | return info.applicationInfo.uid; |
| 3130 | } |
| 3131 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3132 | void setShowWhenLocked(boolean showWhenLocked) { |
| 3133 | mShowWhenLocked = showWhenLocked; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3134 | mRootActivityContainer.ensureActivitiesVisible(null, 0 /* configChanges */, |
Kevin Chyn | 4463948 | 2017-10-09 18:34:41 -0700 | [diff] [blame] | 3135 | false /* preserveWindows */); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3136 | } |
| 3137 | |
| 3138 | /** |
chaviw | 2c50098 | 2018-01-04 17:05:05 -0800 | [diff] [blame] | 3139 | * @return true if the activity windowing mode is not |
| 3140 | * {@link android.app.WindowConfiguration#WINDOWING_MODE_PINNED} and activity contains |
| 3141 | * windows that have {@link LayoutParams#FLAG_SHOW_WHEN_LOCKED} set or if the activity |
| 3142 | * has set {@link #mShowWhenLocked}. |
| 3143 | * Multi-windowing mode will be exited if true is returned. |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3144 | */ |
| 3145 | boolean canShowWhenLocked() { |
chaviw | 2c50098 | 2018-01-04 17:05:05 -0800 | [diff] [blame] | 3146 | return !inPinnedWindowingMode() && (mShowWhenLocked |
Wale Ogunwale | 2cca862 | 2017-12-11 08:40:13 -0800 | [diff] [blame] | 3147 | || service.mWindowManager.containsShowWhenLockedWindow(appToken)); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3148 | } |
| 3149 | |
| 3150 | void setTurnScreenOn(boolean turnScreenOn) { |
| 3151 | mTurnScreenOn = turnScreenOn; |
| 3152 | } |
| 3153 | |
| 3154 | /** |
| 3155 | * Determines whether this ActivityRecord can turn the screen on. It checks whether the flag |
| 3156 | * {@link #mTurnScreenOn} is set and checks whether the ActivityRecord should be visible |
| 3157 | * depending on Keyguard state |
| 3158 | * |
| 3159 | * @return true if the screen can be turned on, false otherwise. |
| 3160 | */ |
| 3161 | boolean canTurnScreenOn() { |
| 3162 | final ActivityStack stack = getStack(); |
| 3163 | return mTurnScreenOn && stack != null && |
| 3164 | stack.checkKeyguardVisibility(this, true /* shouldBeVisible */, true /* isTop */); |
| 3165 | } |
| 3166 | |
| 3167 | boolean getTurnScreenOnFlag() { |
| 3168 | return mTurnScreenOn; |
| 3169 | } |
| 3170 | |
| 3171 | boolean isTopRunningActivity() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3172 | return mRootActivityContainer.topRunningActivity() == this; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3173 | } |
| 3174 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 3175 | /** |
| 3176 | * @return {@code true} if this is the resumed activity on its current display, {@code false} |
| 3177 | * otherwise. |
| 3178 | */ |
| 3179 | boolean isResumedActivityOnDisplay() { |
| 3180 | final ActivityDisplay display = getDisplay(); |
| 3181 | return display != null && this == display.getResumedActivity(); |
| 3182 | } |
| 3183 | |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 3184 | void registerRemoteAnimations(RemoteAnimationDefinition definition) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3185 | if (mAppWindowToken == null) { |
| 3186 | Slog.w(TAG_WM, "Attempted to register remote animations with non-existing app" |
| 3187 | + " token: " + appToken); |
| 3188 | return; |
| 3189 | } |
| 3190 | mAppWindowToken.registerRemoteAnimations(definition); |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 3191 | } |
| 3192 | |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3193 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3194 | public String toString() { |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 3195 | if (stringName != null) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 3196 | return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) + |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3197 | (finishing ? " f}" : "}"); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 3198 | } |
| 3199 | StringBuilder sb = new StringBuilder(128); |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 3200 | sb.append("ActivityRecord{"); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 3201 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3202 | sb.append(" u"); |
| 3203 | sb.append(userId); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 3204 | sb.append(' '); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3205 | sb.append(intent.getComponent().flattenToShortString()); |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3206 | stringName = sb.toString(); |
| 3207 | return toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3208 | } |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3209 | |
| 3210 | void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) { |
| 3211 | final long token = proto.start(fieldId); |
| 3212 | proto.write(HASH_CODE, System.identityHashCode(this)); |
| 3213 | proto.write(USER_ID, userId); |
| 3214 | proto.write(TITLE, intent.getComponent().flattenToShortString()); |
| 3215 | proto.end(token); |
| 3216 | } |
| 3217 | |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 3218 | /** |
| 3219 | * Write all fields to an {@code ActivityRecordProto}. This assumes the |
| 3220 | * {@code ActivityRecordProto} is the outer-most proto data. |
| 3221 | */ |
| 3222 | void writeToProto(ProtoOutputStream proto) { |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 3223 | super.writeToProto(proto, CONFIGURATION_CONTAINER, false /* trim */); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3224 | writeIdentifierToProto(proto, IDENTIFIER); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3225 | proto.write(STATE, mState.toString()); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3226 | proto.write(VISIBLE, visible); |
| 3227 | proto.write(FRONT_OF_TASK, frontOfTask); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3228 | if (hasProcess()) { |
| 3229 | proto.write(PROC_ID, app.getPid()); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3230 | } |
Wale Ogunwale | 30eab1f | 2018-05-24 18:25:25 -0700 | [diff] [blame] | 3231 | proto.write(TRANSLUCENT, !fullscreen); |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 3235 | final long token = proto.start(fieldId); |
| 3236 | writeToProto(proto); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3237 | proto.end(token); |
| 3238 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3239 | } |