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