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