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