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