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