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