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