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