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