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