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; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 20 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 21 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 22 | import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS; |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 23 | import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE; |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 24 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 25 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION; |
| 26 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE; |
| 27 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH; |
| 28 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_THUMBNAILS; |
| 29 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES; |
| 30 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH; |
| 31 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_THUMBNAILS; |
| 32 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 33 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 34 | import static com.android.server.am.TaskRecord.INVALID_TASK_ID; |
| 35 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 36 | import android.app.ActivityManager.TaskDescription; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 37 | import android.app.ActivityOptions; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 38 | import android.app.PendingIntent; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 39 | import android.app.ResultInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.content.ComponentName; |
| 41 | import android.content.Intent; |
| 42 | import android.content.pm.ActivityInfo; |
| 43 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 44 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.content.res.Configuration; |
| 46 | import android.graphics.Bitmap; |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 47 | import android.graphics.Rect; |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 48 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.os.Bundle; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 50 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.os.Message; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 52 | import android.os.PersistableBundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.os.Process; |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 54 | import android.os.RemoteException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.os.SystemClock; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 56 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 57 | import android.os.UserHandle; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 58 | import android.service.voice.IVoiceInteractionSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.util.EventLog; |
| 60 | import android.util.Log; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 61 | import android.util.Slog; |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 62 | import android.util.TimeUtils; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 63 | import android.view.AppTransitionAnimationSpec; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.view.IApplicationToken; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 65 | import android.view.WindowManager; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 66 | |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 67 | import com.android.internal.app.ResolverActivity; |
| 68 | import com.android.internal.content.ReferrerIntent; |
| 69 | import com.android.internal.util.XmlUtils; |
| 70 | import com.android.server.AttributeCache; |
| 71 | import com.android.server.am.ActivityStack.ActivityState; |
| 72 | import com.android.server.am.ActivityStackSupervisor.ActivityContainer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 74 | import java.io.File; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 75 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | import java.io.PrintWriter; |
| 77 | import java.lang.ref.WeakReference; |
| 78 | import java.util.ArrayList; |
| 79 | import java.util.HashSet; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 80 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 82 | import org.xmlpull.v1.XmlPullParser; |
| 83 | import org.xmlpull.v1.XmlPullParserException; |
| 84 | import org.xmlpull.v1.XmlSerializer; |
| 85 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | /** |
| 87 | * An entry in the history stack, representing an activity. |
| 88 | */ |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 89 | final class ActivityRecord { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 90 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityRecord" : TAG_AM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 91 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 92 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 93 | private static final String TAG_THUMBNAILS = TAG + POSTFIX_THUMBNAILS; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 94 | |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 95 | private static final boolean SHOW_ACTIVITY_START_TIME = true; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 96 | final public static String RECENTS_PACKAGE_NAME = "com.android.systemui.recents"; |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 97 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 98 | private static final String ATTR_ID = "id"; |
| 99 | private static final String TAG_INTENT = "intent"; |
| 100 | private static final String ATTR_USERID = "user_id"; |
| 101 | private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle"; |
| 102 | private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid"; |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 103 | private static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 104 | private static final String ATTR_RESOLVEDTYPE = "resolved_type"; |
| 105 | private static final String ATTR_COMPONENTSPECIFIED = "component_specified"; |
Dianne Hackborn | 337abb3 | 2014-09-24 12:44:29 -0700 | [diff] [blame] | 106 | static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 107 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | final ActivityManagerService service; // owner |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 109 | final IApplicationToken.Stub appToken; // window manager token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | final ActivityInfo info; // all about me |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 111 | final ApplicationInfo appInfo; // information about activity's app |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 112 | final int launchedFromUid; // always the uid who started the activity. |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 113 | final String launchedFromPackage; // always the package who started the activity. |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 114 | final int userId; // Which user is this running for? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | final Intent intent; // the original intent that generated us |
| 116 | final ComponentName realActivity; // the intent component, or target of an alias. |
| 117 | final String shortComponentName; // the short component name of the intent |
| 118 | final String resolvedType; // as per original caller; |
| 119 | final String packageName; // the package implementing intent's component |
| 120 | final String processName; // process where this component wants to run |
| 121 | final String taskAffinity; // as per ActivityInfo.taskAffinity |
| 122 | final boolean stateNotNeeded; // As per ActivityInfo.flags |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 123 | boolean fullscreen; // covers the full screen? |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 124 | final boolean noDisplay; // activity is not displayed? |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 125 | final boolean componentSpecified; // did caller specifiy an explicit component? |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 126 | final boolean rootVoiceInteraction; // was this the root activity of a voice interaction? |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 127 | |
| 128 | static final int APPLICATION_ACTIVITY_TYPE = 0; |
| 129 | static final int HOME_ACTIVITY_TYPE = 1; |
| 130 | static final int RECENTS_ACTIVITY_TYPE = 2; |
Craig Mautner | 2c1faed | 2013-07-23 12:56:02 -0700 | [diff] [blame] | 131 | int mActivityType; |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | CharSequence nonLocalizedLabel; // the label information from the package mgr. |
| 134 | int labelRes; // the label information from the package mgr. |
| 135 | int icon; // resource identifier of activity's icon. |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 136 | int logo; // resource identifier of activity's logo. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | int theme; // resource identifier of activity's theme. |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 138 | int realTheme; // actual theme resource we will use, never 0. |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 139 | int windowFlags; // custom window flags for preview window. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | TaskRecord task; // the task this is in. |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 141 | long createTime = System.currentTimeMillis(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 142 | long displayStartTime; // when we started launching this activity |
| 143 | long fullyDrawnStartTime; // when we started launching this activity |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 144 | long startTime; // last time this activity was started |
Dianne Hackborn | 5068560 | 2011-12-01 12:23:37 -0800 | [diff] [blame] | 145 | long lastVisibleTime; // last time this activity became visible |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 146 | 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] | 147 | long pauseTime; // last time we started pausing the activity |
| 148 | long launchTickTime; // base time for launch tick messages |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | Configuration configuration; // configuration activity was last running in |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 150 | // Overridden configuration by the activity task |
| 151 | // WARNING: Reference points to {@link TaskRecord#mOverrideConfig}, so its internal state |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 152 | // should never be altered directly. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 153 | Configuration taskConfigOverride; |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 154 | CompatibilityInfo compat;// last used compatibility mode |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 155 | 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] | 156 | final String resultWho; // additional identifier for use by resultTo. |
| 157 | final int requestCode; // code given by requester (resultTo) |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 158 | ArrayList<ResultInfo> results; // pending ActivityResult objs we have received |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 160 | ArrayList<ReferrerIntent> newIntents; // any pending new intents for single-top mode |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 161 | ActivityOptions pendingOptions; // most recently given options |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 162 | ActivityOptions returningOptions; // options that are coming back via convertToTranslucent |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 163 | 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] | 164 | HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 165 | UriPermissionOwner uriPermissions; // current special URI access perms. |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 166 | ProcessRecord app; // if non-null, hosting application |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 167 | ActivityState state; // current state we are in |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | Bundle icicle; // last saved activity state |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 169 | PersistableBundle persistentState; // last persistently saved activity state |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | boolean frontOfTask; // is this the root activity of its task? |
| 171 | boolean launchFailed; // set if a launched failed, to abort on 2nd try |
| 172 | boolean haveState; // have we gotten the last activity state? |
| 173 | boolean stopped; // is activity pause finished? |
Dianne Hackborn | 95fc68f | 2009-05-19 18:37:45 -0700 | [diff] [blame] | 174 | 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] | 175 | boolean finishing; // activity in pending finish list? |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 176 | boolean deferRelaunchUntilPaused; // relaunch of activity is being deferred until pause is |
| 177 | // completed |
| 178 | boolean preserveWindowOnDeferredRelaunch; // activity windows are preserved on deferred relaunch |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | int configChangeFlags; // which config values have changed |
| 180 | boolean keysPaused; // has key dispatching been paused for it? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | int launchMode; // the launch mode activity attribute. |
| 182 | boolean visible; // does this activity's window need to be shown? |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 183 | boolean sleeping; // have we told the activity to sleep? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | boolean nowVisible; // is this activity's window visible? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | boolean idle; // has the activity gone idle? |
| 186 | boolean hasBeenLaunched;// has this activity ever been launched? |
| 187 | boolean frozenBeforeDestroy;// has been frozen but not yet destroyed. |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 188 | boolean immersive; // immersive mode (don't interrupt if possible) |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 189 | boolean forceNewConfig; // force re-create with new config next time |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 190 | int launchCount; // count of launches since last state |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 191 | long lastLaunchTime; // time of last launch of this activity |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 192 | boolean isVrActivity; // is the activity running in VR mode? |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 193 | ArrayList<ActivityContainer> mChildContainers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 195 | String stringName; // for caching of toString(). |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 196 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 197 | private boolean inHistory; // are we in the history stack? |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 198 | final ActivityStackSupervisor mStackSupervisor; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 199 | boolean mStartingWindowShown = false; |
Jorim Jaggi | c2f262b | 2015-12-07 16:59:10 -0800 | [diff] [blame] | 200 | boolean mUpdateTaskThumbnailWhenHidden; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 201 | ActivityContainer mInitialActivityContainer; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 202 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 203 | TaskDescription taskDescription; // the recents information for this activity |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 204 | boolean mLaunchTaskBehind; // this activity is actively being launched with |
| 205 | // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed. |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 206 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 207 | // These configurations are collected from application's resources based on size-sensitive |
| 208 | // qualifiers. For example, layout-w800dp will be added to mHorizontalSizeConfigurations as 800 |
| 209 | // and drawable-sw400dp will be added to both as 400. |
| 210 | private int[] mVerticalSizeConfigurations; |
| 211 | private int[] mHorizontalSizeConfigurations; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 212 | private int[] mSmallestSizeConfigurations; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 213 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 214 | boolean pendingVoiceInteractionStart; // Waiting for activity-invoked voice session |
| 215 | IVoiceInteractionSession voiceSession; // Voice interaction session for this activity |
| 216 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 218 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 219 | pw.print(prefix); pw.print("packageName="); pw.print(packageName); |
| 220 | pw.print(" processName="); pw.println(processName); |
| 221 | pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid); |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 222 | pw.print(" launchedFromPackage="); pw.print(launchedFromPackage); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 223 | pw.print(" userId="); pw.println(userId); |
| 224 | pw.print(prefix); pw.print("app="); pw.println(app); |
| 225 | pw.print(prefix); pw.println(intent.toInsecureStringWithClip()); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 226 | pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask); |
| 227 | pw.print(" task="); pw.println(task); |
| 228 | pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 229 | pw.print(prefix); pw.print("realActivity="); |
| 230 | pw.println(realActivity.flattenToShortString()); |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 231 | if (appInfo != null) { |
| 232 | pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir); |
| 233 | if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) { |
| 234 | pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir); |
| 235 | } |
| 236 | pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 237 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 238 | pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded); |
| 239 | pw.print(" componentSpecified="); pw.print(componentSpecified); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 240 | pw.print(" mActivityType="); pw.println(mActivityType); |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 241 | if (rootVoiceInteraction) { |
| 242 | pw.print(prefix); pw.print("rootVoiceInteraction="); pw.println(rootVoiceInteraction); |
| 243 | } |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 244 | pw.print(prefix); pw.print("compat="); pw.print(compat); |
| 245 | pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes)); |
| 246 | pw.print(" icon=0x"); pw.print(Integer.toHexString(icon)); |
| 247 | pw.print(" theme=0x"); pw.println(Integer.toHexString(theme)); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 248 | pw.print(prefix); pw.print("config="); pw.println(configuration); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 249 | pw.print(prefix); pw.print("taskConfigOverride="); pw.println(taskConfigOverride); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 250 | if (resultTo != null || resultWho != null) { |
| 251 | pw.print(prefix); pw.print("resultTo="); pw.print(resultTo); |
| 252 | pw.print(" resultWho="); pw.print(resultWho); |
| 253 | pw.print(" resultCode="); pw.println(requestCode); |
| 254 | } |
Craig Mautner | 29c58ca | 2014-10-14 16:17:06 -0700 | [diff] [blame] | 255 | if (taskDescription != null) { |
| 256 | final String iconFilename = taskDescription.getIconFilename(); |
| 257 | if (iconFilename != null || taskDescription.getLabel() != null || |
| 258 | taskDescription.getPrimaryColor() != 0) { |
| 259 | pw.print(prefix); pw.print("taskDescription:"); |
| 260 | pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename()); |
| 261 | pw.print(" label=\""); pw.print(taskDescription.getLabel()); |
| 262 | pw.print("\""); |
| 263 | pw.print(" color="); |
| 264 | pw.println(Integer.toHexString(taskDescription.getPrimaryColor())); |
| 265 | } |
| 266 | if (iconFilename == null && taskDescription.getIcon() != null) { |
| 267 | pw.print(prefix); pw.println("taskDescription contains Bitmap"); |
| 268 | } |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 269 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 270 | if (results != null) { |
| 271 | pw.print(prefix); pw.print("results="); pw.println(results); |
| 272 | } |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 273 | if (pendingResults != null && pendingResults.size() > 0) { |
| 274 | pw.print(prefix); pw.println("Pending Results:"); |
| 275 | for (WeakReference<PendingIntentRecord> wpir : pendingResults) { |
| 276 | PendingIntentRecord pir = wpir != null ? wpir.get() : null; |
| 277 | pw.print(prefix); pw.print(" - "); |
| 278 | if (pir == null) { |
| 279 | pw.println("null"); |
| 280 | } else { |
| 281 | pw.println(pir); |
| 282 | pir.dump(pw, prefix + " "); |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | if (newIntents != null && newIntents.size() > 0) { |
| 287 | pw.print(prefix); pw.println("Pending New Intents:"); |
| 288 | for (int i=0; i<newIntents.size(); i++) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 289 | Intent intent = newIntents.get(i); |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 290 | pw.print(prefix); pw.print(" - "); |
| 291 | if (intent == null) { |
| 292 | pw.println("null"); |
| 293 | } else { |
| 294 | pw.println(intent.toShortString(false, true, false, true)); |
| 295 | } |
| 296 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 297 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 298 | if (pendingOptions != null) { |
| 299 | pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions); |
| 300 | } |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 301 | if (appTimeTracker != null) { |
| 302 | appTimeTracker.dumpWithHeader(pw, prefix, false); |
| 303 | } |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 304 | if (uriPermissions != null) { |
Jeff Sharkey | 846318a | 2014-04-04 12:12:41 -0700 | [diff] [blame] | 305 | uriPermissions.dump(pw, prefix); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 306 | } |
| 307 | pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed); |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 308 | pw.print(" launchCount="); pw.print(launchCount); |
| 309 | pw.print(" lastLaunchTime="); |
| 310 | if (lastLaunchTime == 0) pw.print("0"); |
| 311 | else TimeUtils.formatDuration(lastLaunchTime, now, pw); |
| 312 | pw.println(); |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 313 | pw.print(prefix); pw.print("haveState="); pw.print(haveState); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 314 | pw.print(" icicle="); pw.println(icicle); |
| 315 | pw.print(prefix); pw.print("state="); pw.print(state); |
| 316 | pw.print(" stopped="); pw.print(stopped); |
Dianne Hackborn | 95fc68f | 2009-05-19 18:37:45 -0700 | [diff] [blame] | 317 | pw.print(" delayedResume="); pw.print(delayedResume); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 318 | pw.print(" finishing="); pw.println(finishing); |
| 319 | pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused); |
| 320 | pw.print(" inHistory="); pw.print(inHistory); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 321 | pw.print(" visible="); pw.print(visible); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 322 | pw.print(" sleeping="); pw.print(sleeping); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 323 | pw.print(" idle="); pw.println(idle); |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 324 | pw.print(" mStartingWindowShown="); pw.println(mStartingWindowShown); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 325 | pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen); |
| 326 | pw.print(" noDisplay="); pw.print(noDisplay); |
| 327 | pw.print(" immersive="); pw.print(immersive); |
| 328 | pw.print(" launchMode="); pw.println(launchMode); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 329 | pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 330 | pw.print(" forceNewConfig="); pw.println(forceNewConfig); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 331 | pw.print(prefix); pw.print("mActivityType="); |
| 332 | pw.println(activityTypeToString(mActivityType)); |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 333 | pw.print(prefix); pw.print("vrMode="); pw.println(isVrActivity); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 334 | if (displayStartTime != 0 || startTime != 0) { |
| 335 | pw.print(prefix); pw.print("displayStartTime="); |
| 336 | if (displayStartTime == 0) pw.print("0"); |
| 337 | else TimeUtils.formatDuration(displayStartTime, now, pw); |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 338 | pw.print(" startTime="); |
| 339 | if (startTime == 0) pw.print("0"); |
| 340 | else TimeUtils.formatDuration(startTime, now, pw); |
| 341 | pw.println(); |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 342 | } |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 343 | final boolean waitingVisible = mStackSupervisor.mWaitingVisibleActivities.contains(this); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 344 | if (lastVisibleTime != 0 || waitingVisible || nowVisible) { |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 345 | pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 346 | pw.print(" nowVisible="); pw.print(nowVisible); |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 347 | pw.print(" lastVisibleTime="); |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 348 | if (lastVisibleTime == 0) pw.print("0"); |
| 349 | else TimeUtils.formatDuration(lastVisibleTime, now, pw); |
| 350 | pw.println(); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 351 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 352 | if (deferRelaunchUntilPaused || configChangeFlags != 0) { |
| 353 | pw.print(prefix); pw.print("deferRelaunchUntilPaused="); pw.print(deferRelaunchUntilPaused); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 354 | pw.print(" configChangeFlags="); |
| 355 | pw.println(Integer.toHexString(configChangeFlags)); |
| 356 | } |
| 357 | if (connections != null) { |
| 358 | pw.print(prefix); pw.print("connections="); pw.println(connections); |
| 359 | } |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 360 | if (info != null) { |
| 361 | pw.println(prefix + "resizeMode=" + ActivityInfo.resizeModeToString(info.resizeMode)); |
| 362 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | } |
| 364 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 365 | public boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) { |
| 366 | return crossesSizeThreshold(mHorizontalSizeConfigurations, firstDp, secondDp); |
| 367 | } |
| 368 | |
| 369 | public boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) { |
| 370 | return crossesSizeThreshold(mVerticalSizeConfigurations, firstDp, secondDp); |
| 371 | } |
| 372 | |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 373 | public boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) { |
| 374 | return crossesSizeThreshold(mSmallestSizeConfigurations, firstDp, secondDp); |
| 375 | } |
| 376 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 377 | /** |
| 378 | * The purpose of this method is to decide whether the activity needs to be relaunched upon |
| 379 | * changing its size. In most cases the activities don't need to be relaunched, if the resize |
| 380 | * is small, all the activity content has to do is relayout itself within new bounds. There are |
| 381 | * cases however, where the activity's content would be completely changed in the new size and |
| 382 | * the full relaunch is required. |
| 383 | * |
| 384 | * The activity will report to us vertical and horizontal thresholds after which a relaunch is |
| 385 | * required. These thresholds are collected from the application resource qualifiers. For |
| 386 | * example, if application has layout-w600dp resource directory, then it needs a relaunch when |
| 387 | * we resize from width of 650dp to 550dp, as it crosses the 600dp threshold. However, if |
| 388 | * it resizes width from 620dp to 700dp, it won't be relaunched as it stays on the same side |
| 389 | * of the threshold. |
| 390 | */ |
| 391 | private static boolean crossesSizeThreshold(int[] thresholds, int firstDp, |
| 392 | int secondDp) { |
| 393 | if (thresholds == null) { |
| 394 | return false; |
| 395 | } |
| 396 | for (int i = thresholds.length - 1; i >= 0; i--) { |
| 397 | final int threshold = thresholds[i]; |
| 398 | if ((firstDp < threshold && secondDp >= threshold) |
| 399 | || (firstDp >= threshold && secondDp < threshold)) { |
| 400 | return true; |
| 401 | } |
| 402 | } |
| 403 | return false; |
| 404 | } |
| 405 | |
| 406 | public void setSizeConfigurations(int[] horizontalSizeConfiguration, |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 407 | int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 408 | mHorizontalSizeConfigurations = horizontalSizeConfiguration; |
| 409 | mVerticalSizeConfigurations = verticalSizeConfigurations; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 410 | mSmallestSizeConfigurations = smallestSizeConfigurations; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 413 | void scheduleConfigurationChanged(Configuration config, boolean reportToActivity) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 414 | if (app == null || app.thread == null) { |
| 415 | return; |
| 416 | } |
| 417 | try { |
| 418 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + this + " " + |
| 419 | "reportToActivity=" + reportToActivity + " and config: " + config); |
| 420 | app.thread.scheduleActivityConfigurationChanged( |
| 421 | appToken, new Configuration(config), reportToActivity); |
| 422 | } catch (RemoteException e) { |
| 423 | // If process died, whatever. |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | void scheduleMultiWindowChanged() { |
| 428 | if (task == null || task.stack == null || app == null || app.thread == null) { |
| 429 | return; |
| 430 | } |
| 431 | try { |
| 432 | // An activity is considered to be in multi-window mode if its task isn't fullscreen. |
| 433 | app.thread.scheduleMultiWindowChanged(appToken, !task.mFullscreen); |
| 434 | } catch (Exception e) { |
| 435 | // If process died, I don't care. |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | void schedulePictureInPictureChanged() { |
| 440 | if (task == null || task.stack == null || app == null || app.thread == null) { |
| 441 | return; |
| 442 | } |
| 443 | try { |
| 444 | app.thread.schedulePictureInPictureChanged( |
| 445 | appToken, task.stack.mStackId == PINNED_STACK_ID); |
| 446 | } catch (Exception e) { |
| 447 | // If process died, no one cares. |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 451 | boolean isFreeform() { |
| 452 | return task != null && task.stack != null |
| 453 | && task.stack.mStackId == FREEFORM_WORKSPACE_STACK_ID; |
| 454 | } |
| 455 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 456 | static class Token extends IApplicationToken.Stub { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 457 | private final WeakReference<ActivityRecord> weakActivity; |
| 458 | private final ActivityManagerService mService; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 459 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 460 | Token(ActivityRecord activity, ActivityManagerService service) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 461 | weakActivity = new WeakReference<>(activity); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 462 | mService = service; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 463 | } |
| 464 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 465 | @Override |
| 466 | public void windowsDrawn() { |
| 467 | synchronized (mService) { |
| 468 | ActivityRecord r = tokenToActivityRecordLocked(this); |
| 469 | if (r != null) { |
| 470 | r.windowsDrawnLocked(); |
| 471 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 472 | } |
| 473 | } |
| 474 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 475 | @Override |
| 476 | public void windowsVisible() { |
| 477 | synchronized (mService) { |
| 478 | ActivityRecord r = tokenToActivityRecordLocked(this); |
| 479 | if (r != null) { |
| 480 | r.windowsVisibleLocked(); |
| 481 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 482 | } |
| 483 | } |
| 484 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 485 | @Override |
| 486 | public void windowsGone() { |
| 487 | synchronized (mService) { |
| 488 | ActivityRecord r = tokenToActivityRecordLocked(this); |
| 489 | if (r != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 490 | if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + r); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 491 | r.nowVisible = false; |
| 492 | return; |
| 493 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 497 | @Override |
| 498 | public boolean keyDispatchingTimedOut(String reason) { |
| 499 | ActivityRecord r; |
| 500 | ActivityRecord anrActivity; |
| 501 | ProcessRecord anrApp; |
| 502 | synchronized (mService) { |
| 503 | r = tokenToActivityRecordLocked(this); |
| 504 | if (r == null) { |
| 505 | return false; |
| 506 | } |
| 507 | anrActivity = r.getWaitingHistoryRecordLocked(); |
| 508 | anrApp = r != null ? r.app : null; |
| 509 | } |
| 510 | return mService.inputDispatchingTimedOut(anrApp, anrActivity, r, false, reason); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 511 | } |
| 512 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 513 | @Override |
| 514 | public long getKeyDispatchingTimeout() { |
| 515 | synchronized (mService) { |
| 516 | ActivityRecord r = tokenToActivityRecordLocked(this); |
| 517 | if (r == null) { |
| 518 | return 0; |
| 519 | } |
| 520 | r = r.getWaitingHistoryRecordLocked(); |
| 521 | return ActivityManagerService.getInputDispatchingTimeoutLocked(r); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 522 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | private static final ActivityRecord tokenToActivityRecordLocked(Token token) { |
| 526 | if (token == null) { |
| 527 | return null; |
| 528 | } |
| 529 | ActivityRecord r = token.weakActivity.get(); |
| 530 | if (r == null || r.task == null || r.task.stack == null) { |
| 531 | return null; |
| 532 | } |
| 533 | return r; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 534 | } |
| 535 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 536 | @Override |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 537 | public String toString() { |
| 538 | StringBuilder sb = new StringBuilder(128); |
| 539 | sb.append("Token{"); |
| 540 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 541 | sb.append(' '); |
| 542 | sb.append(weakActivity.get()); |
| 543 | sb.append('}'); |
| 544 | return sb.toString(); |
| 545 | } |
| 546 | } |
| 547 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 548 | static ActivityRecord forTokenLocked(IBinder token) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 549 | try { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 550 | return Token.tokenToActivityRecordLocked((Token)token); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 551 | } catch (ClassCastException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 552 | Slog.w(TAG, "Bad activity token: " + token, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 553 | return null; |
| 554 | } |
| 555 | } |
| 556 | |
Chong Zhang | 85ee654 | 2015-10-02 13:36:38 -0700 | [diff] [blame] | 557 | boolean isResolverActivity() { |
| 558 | return ResolverActivity.class.getName().equals(realActivity.getClassName()); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 561 | ActivityRecord(ActivityManagerService _service, ProcessRecord _caller, |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 562 | int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | ActivityInfo aInfo, Configuration _configuration, |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 564 | ActivityRecord _resultTo, String _resultWho, int _reqCode, |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 565 | boolean _componentSpecified, boolean _rootVoiceInteraction, |
| 566 | ActivityStackSupervisor supervisor, |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 567 | ActivityContainer container, ActivityOptions options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | service = _service; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 569 | appToken = new Token(this, service); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | info = aInfo; |
| 571 | launchedFromUid = _launchedFromUid; |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 572 | launchedFromPackage = _launchedFromPackage; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 573 | userId = UserHandle.getUserId(aInfo.applicationInfo.uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | intent = _intent; |
| 575 | shortComponentName = _intent.getComponent().flattenToShortString(); |
| 576 | resolvedType = _resolvedType; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 577 | componentSpecified = _componentSpecified; |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 578 | rootVoiceInteraction = _rootVoiceInteraction; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | configuration = _configuration; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 580 | taskConfigOverride = Configuration.EMPTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | resultTo = _resultTo; |
| 582 | resultWho = _resultWho; |
| 583 | requestCode = _reqCode; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 584 | state = ActivityState.INITIALIZING; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | frontOfTask = false; |
| 586 | launchFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | stopped = false; |
Dianne Hackborn | 95fc68f | 2009-05-19 18:37:45 -0700 | [diff] [blame] | 588 | delayedResume = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 589 | finishing = false; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 590 | deferRelaunchUntilPaused = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 591 | keysPaused = false; |
| 592 | inHistory = false; |
Chong Zhang | a48ef66 | 2015-08-18 19:21:47 -0700 | [diff] [blame] | 593 | visible = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | nowVisible = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 595 | idle = false; |
| 596 | hasBeenLaunched = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 597 | mStackSupervisor = supervisor; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 598 | mInitialActivityContainer = container; |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 599 | if (options != null) { |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 600 | pendingOptions = options; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 601 | mLaunchTaskBehind = pendingOptions.getLaunchTaskBehind(); |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 602 | PendingIntent usageReport = pendingOptions.getUsageTimeReport(); |
| 603 | if (usageReport != null) { |
| 604 | appTimeTracker = new AppTimeTracker(usageReport); |
| 605 | } |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 606 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 607 | |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 608 | // This starts out true, since the initial state of an activity |
| 609 | // is that we have everything, and we shouldn't never consider it |
| 610 | // lacking in state to be removed if it dies. |
| 611 | haveState = true; |
| 612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 613 | if (aInfo != null) { |
Chong Zhang | 6bdc7e1 | 2016-02-01 14:33:53 -0800 | [diff] [blame] | 614 | // If the class name in the intent doesn't match that of the target, this is |
| 615 | // probably an alias. We have to create a new ComponentName object to keep track |
| 616 | // 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] | 617 | if (aInfo.targetActivity == null |
Chong Zhang | 6bdc7e1 | 2016-02-01 14:33:53 -0800 | [diff] [blame] | 618 | || (aInfo.targetActivity.equals(_intent.getComponent().getClassName()) |
| 619 | && (aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE |
| 620 | || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP))) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | realActivity = _intent.getComponent(); |
| 622 | } else { |
Chong Zhang | 6bdc7e1 | 2016-02-01 14:33:53 -0800 | [diff] [blame] | 623 | realActivity = new ComponentName(aInfo.packageName, aInfo.targetActivity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | } |
| 625 | taskAffinity = aInfo.taskAffinity; |
| 626 | stateNotNeeded = (aInfo.flags& |
| 627 | ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 628 | appInfo = aInfo.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | nonLocalizedLabel = aInfo.nonLocalizedLabel; |
| 630 | labelRes = aInfo.labelRes; |
| 631 | if (nonLocalizedLabel == null && labelRes == 0) { |
| 632 | ApplicationInfo app = aInfo.applicationInfo; |
| 633 | nonLocalizedLabel = app.nonLocalizedLabel; |
| 634 | labelRes = app.labelRes; |
| 635 | } |
| 636 | icon = aInfo.getIconResource(); |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 637 | logo = aInfo.getLogoResource(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 638 | theme = aInfo.getThemeResource(); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 639 | realTheme = theme; |
| 640 | if (realTheme == 0) { |
| 641 | realTheme = aInfo.applicationInfo.targetSdkVersion |
| 642 | < Build.VERSION_CODES.HONEYCOMB |
| 643 | ? android.R.style.Theme |
| 644 | : android.R.style.Theme_Holo; |
| 645 | } |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 646 | if ((aInfo.flags&ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) { |
| 647 | windowFlags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 648 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 649 | if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0 |
| 650 | && _caller != null |
| 651 | && (aInfo.applicationInfo.uid == Process.SYSTEM_UID |
| 652 | || aInfo.applicationInfo.uid == _caller.info.uid)) { |
| 653 | processName = _caller.processName; |
| 654 | } else { |
| 655 | processName = aInfo.processName; |
| 656 | } |
| 657 | |
| 658 | if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) { |
| 659 | intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 660 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 661 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 662 | packageName = aInfo.applicationInfo.packageName; |
| 663 | launchMode = aInfo.launchMode; |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 665 | AttributeCache.Entry ent = AttributeCache.instance().get(packageName, |
Amith Yamasani | 4befbec | 2013-07-10 16:18:01 -0700 | [diff] [blame] | 666 | realTheme, com.android.internal.R.styleable.Window, userId); |
Dianne Hackborn | b795d7c | 2015-07-28 17:40:06 -0700 | [diff] [blame] | 667 | final boolean translucent = ent != null && (ent.array.getBoolean( |
Filip Gruszczynski | 23958c6 | 2015-02-23 18:05:27 -0800 | [diff] [blame] | 668 | com.android.internal.R.styleable.Window_windowIsTranslucent, false) |
| 669 | || (!ent.array.hasValue( |
| 670 | com.android.internal.R.styleable.Window_windowIsTranslucent) |
| 671 | && ent.array.getBoolean( |
| 672 | com.android.internal.R.styleable.Window_windowSwipeToDismiss, |
Dianne Hackborn | b795d7c | 2015-07-28 17:40:06 -0700 | [diff] [blame] | 673 | false))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | fullscreen = ent != null && !ent.array.getBoolean( |
| 675 | com.android.internal.R.styleable.Window_windowIsFloating, false) |
Filip Gruszczynski | 23958c6 | 2015-02-23 18:05:27 -0800 | [diff] [blame] | 676 | && !translucent; |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 677 | noDisplay = ent != null && ent.array.getBoolean( |
| 678 | com.android.internal.R.styleable.Window_windowNoDisplay, false); |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 679 | |
Craig Mautner | 8025935 | 2013-09-28 12:35:25 -0700 | [diff] [blame] | 680 | if ((!_componentSpecified || _launchedFromUid == Process.myUid() |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 681 | || _launchedFromUid == 0) && |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 682 | Intent.ACTION_MAIN.equals(_intent.getAction()) && |
| 683 | _intent.hasCategory(Intent.CATEGORY_HOME) && |
| 684 | _intent.getCategories().size() == 1 && |
| 685 | _intent.getData() == null && |
| 686 | _intent.getType() == null && |
Chong Zhang | 85ee654 | 2015-10-02 13:36:38 -0700 | [diff] [blame] | 687 | !isResolverActivity()) { |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 688 | // This sure looks like a home activity! |
| 689 | mActivityType = HOME_ACTIVITY_TYPE; |
Craig Mautner | 8025935 | 2013-09-28 12:35:25 -0700 | [diff] [blame] | 690 | } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) { |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 691 | mActivityType = RECENTS_ACTIVITY_TYPE; |
| 692 | } else { |
| 693 | mActivityType = APPLICATION_ACTIVITY_TYPE; |
| 694 | } |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 695 | |
| 696 | immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0; |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 697 | isVrActivity = (aInfo.flags & ActivityInfo.FLAG_ENABLE_VR_MODE) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 698 | } else { |
| 699 | realActivity = null; |
| 700 | taskAffinity = null; |
| 701 | stateNotNeeded = false; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 702 | appInfo = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | processName = null; |
| 704 | packageName = null; |
| 705 | fullscreen = true; |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 706 | noDisplay = false; |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 707 | mActivityType = APPLICATION_ACTIVITY_TYPE; |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 708 | immersive = false; |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 709 | isVrActivity = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 713 | void setTask(TaskRecord newTask, TaskRecord taskToAffiliateWith) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 714 | if (task != null && task.removeActivity(this) && task != newTask && task.stack != null) { |
| 715 | task.stack.removeTask(task, "setTask"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 716 | } |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 717 | task = newTask; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 718 | setTaskToAffiliateWith(taskToAffiliateWith); |
| 719 | } |
| 720 | |
| 721 | void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) { |
| 722 | if (taskToAffiliateWith != null && |
| 723 | launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE && |
| 724 | launchMode != ActivityInfo.LAUNCH_SINGLE_TASK) { |
| 725 | task.setTaskToAffiliateWith(taskToAffiliateWith); |
| 726 | } |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 729 | boolean changeWindowTranslucency(boolean toOpaque) { |
| 730 | if (fullscreen == toOpaque) { |
| 731 | return false; |
| 732 | } |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 733 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 734 | // Keep track of the number of fullscreen activities in this task. |
| 735 | task.numFullscreen += toOpaque ? +1 : -1; |
| 736 | |
| 737 | fullscreen = toOpaque; |
| 738 | return true; |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 739 | } |
| 740 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 741 | void putInHistory() { |
| 742 | if (!inHistory) { |
| 743 | inHistory = true; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | |
| 747 | void takeFromHistory() { |
| 748 | if (inHistory) { |
| 749 | inHistory = false; |
| 750 | if (task != null && !finishing) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 751 | task = null; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 752 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 753 | clearOptionsLocked(); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 754 | } |
| 755 | } |
| 756 | |
| 757 | boolean isInHistory() { |
| 758 | return inHistory; |
| 759 | } |
| 760 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 761 | boolean isInStackLocked() { |
| 762 | return task != null && task.stack != null && task.stack.isInStackLocked(this) != null; |
| 763 | } |
| 764 | |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 765 | boolean isHomeActivity() { |
| 766 | return mActivityType == HOME_ACTIVITY_TYPE; |
| 767 | } |
| 768 | |
| 769 | boolean isRecentsActivity() { |
| 770 | return mActivityType == RECENTS_ACTIVITY_TYPE; |
| 771 | } |
| 772 | |
| 773 | boolean isApplicationActivity() { |
| 774 | return mActivityType == APPLICATION_ACTIVITY_TYPE; |
| 775 | } |
| 776 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 777 | boolean isPersistable() { |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 778 | return (info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || |
| 779 | info.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS) && |
| 780 | (intent == null || |
| 781 | (intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 784 | boolean isFocusable() { |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 785 | return StackId.canReceiveKeys(task.stack.mStackId) || isAlwaysFocusable(); |
| 786 | } |
| 787 | |
| 788 | boolean isResizeable() { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 789 | return !isHomeActivity() && ActivityInfo.isResizeableMode(info.resizeMode); |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 790 | } |
| 791 | |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 792 | boolean isResizeableOrForced() { |
| 793 | return !isHomeActivity() && (isResizeable() || service.mForceResizableActivities); |
| 794 | } |
| 795 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 796 | boolean supportsPictureInPicture() { |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 797 | return !isHomeActivity() && info.resizeMode == RESIZE_MODE_RESIZEABLE_AND_PIPABLE; |
| 798 | } |
| 799 | |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 800 | boolean canGoInDockedStack() { |
| 801 | return !isHomeActivity() |
| 802 | && (isResizeableOrForced() || info.resizeMode == RESIZE_MODE_CROP_WINDOWS); |
| 803 | } |
| 804 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 805 | boolean isAlwaysFocusable() { |
| 806 | return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 807 | } |
| 808 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 809 | void makeFinishingLocked() { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 810 | if (!finishing) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 811 | if (task != null && task.stack != null |
| 812 | && this == task.stack.getVisibleBehindActivity()) { |
Jose Lima | 34ff492 | 2014-08-18 15:19:41 -0700 | [diff] [blame] | 813 | // A finishing activity should not remain as visible in the background |
| 814 | mStackSupervisor.requestVisibleBehindLocked(this, false); |
| 815 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 816 | finishing = true; |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 817 | if (stopped) { |
| 818 | clearOptionsLocked(); |
| 819 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 823 | UriPermissionOwner getUriPermissionsLocked() { |
| 824 | if (uriPermissions == null) { |
| 825 | uriPermissions = new UriPermissionOwner(service, this); |
| 826 | } |
| 827 | return uriPermissions; |
| 828 | } |
| 829 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 830 | void addResultLocked(ActivityRecord from, String resultWho, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | int requestCode, int resultCode, |
| 832 | Intent resultData) { |
| 833 | ActivityResult r = new ActivityResult(from, resultWho, |
John Spurlock | 8a985d2 | 2014-02-25 09:40:05 -0500 | [diff] [blame] | 834 | requestCode, resultCode, resultData); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 835 | if (results == null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 836 | results = new ArrayList<ResultInfo>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | } |
| 838 | results.add(r); |
| 839 | } |
| 840 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 841 | void removeResultsLocked(ActivityRecord from, String resultWho, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 | int requestCode) { |
| 843 | if (results != null) { |
| 844 | for (int i=results.size()-1; i>=0; i--) { |
| 845 | ActivityResult r = (ActivityResult)results.get(i); |
| 846 | if (r.mFrom != from) continue; |
| 847 | if (r.mResultWho == null) { |
| 848 | if (resultWho != null) continue; |
| 849 | } else { |
| 850 | if (!r.mResultWho.equals(resultWho)) continue; |
| 851 | } |
| 852 | if (r.mRequestCode != requestCode) continue; |
| 853 | |
| 854 | results.remove(i); |
| 855 | } |
| 856 | } |
| 857 | } |
| 858 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 859 | void addNewIntentLocked(ReferrerIntent intent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 860 | if (newIntents == null) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 861 | newIntents = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 862 | } |
| 863 | newIntents.add(intent); |
| 864 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 865 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 866 | /** |
| 867 | * Deliver a new Intent to an existing activity, so that its onNewIntent() |
| 868 | * method will be called at the proper time. |
| 869 | */ |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 870 | final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) { |
Dianne Hackborn | 514074f | 2013-02-11 10:52:46 -0800 | [diff] [blame] | 871 | // The activity now gets access to the data associated with this Intent. |
| 872 | service.grantUriPermissionFromIntentLocked(callingUid, packageName, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 873 | intent, getUriPermissionsLocked(), userId); |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 874 | // We want to immediately deliver the intent to the activity if |
| 875 | // it is currently the top resumed activity... however, if the |
| 876 | // device is sleeping, then all activities are stopped, so in that |
| 877 | // case we will deliver it if this is the current top activity on its |
| 878 | // stack. |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 879 | final ReferrerIntent rintent = new ReferrerIntent(intent, referrer); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 880 | boolean unsent = true; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 881 | if ((state == ActivityState.RESUMED |
| 882 | || (service.isSleeping() && task.stack != null |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 883 | && task.stack.topRunningActivityLocked() == this)) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 884 | && app != null && app.thread != null) { |
| 885 | try { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 886 | ArrayList<ReferrerIntent> ar = new ArrayList<>(1); |
| 887 | ar.add(rintent); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 888 | app.thread.scheduleNewIntent(ar, appToken); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 889 | unsent = false; |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 890 | } catch (RemoteException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 891 | Slog.w(TAG, "Exception thrown sending new intent to " + this, e); |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 892 | } catch (NullPointerException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 893 | Slog.w(TAG, "Exception thrown sending new intent to " + this, e); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 894 | } |
| 895 | } |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 896 | if (unsent) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 897 | addNewIntentLocked(rintent); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | |
Dianne Hackborn | 9622ca4 | 2012-10-23 18:56:33 -0700 | [diff] [blame] | 901 | void updateOptionsLocked(ActivityOptions options) { |
| 902 | if (options != null) { |
| 903 | if (pendingOptions != null) { |
| 904 | pendingOptions.abort(); |
| 905 | } |
| 906 | pendingOptions = options; |
| 907 | } |
| 908 | } |
| 909 | |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 910 | void applyOptionsLocked() { |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 911 | if (pendingOptions != null |
| 912 | && pendingOptions.getAnimationType() != ActivityOptions.ANIM_SCENE_TRANSITION) { |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 913 | final int animationType = pendingOptions.getAnimationType(); |
| 914 | switch (animationType) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 915 | case ActivityOptions.ANIM_CUSTOM: |
| 916 | service.mWindowManager.overridePendingAppTransition( |
| 917 | pendingOptions.getPackageName(), |
| 918 | pendingOptions.getCustomEnterResId(), |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 919 | pendingOptions.getCustomExitResId(), |
| 920 | pendingOptions.getOnAnimationStartListener()); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 921 | break; |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 922 | case ActivityOptions.ANIM_CLIP_REVEAL: |
| 923 | service.mWindowManager.overridePendingAppTransitionClipReveal( |
| 924 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 925 | pendingOptions.getWidth(), pendingOptions.getHeight()); |
| 926 | if (intent.getSourceBounds() == null) { |
| 927 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 928 | pendingOptions.getStartY(), |
| 929 | pendingOptions.getStartX()+pendingOptions.getWidth(), |
| 930 | pendingOptions.getStartY()+pendingOptions.getHeight())); |
| 931 | } |
| 932 | break; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 933 | case ActivityOptions.ANIM_SCALE_UP: |
| 934 | service.mWindowManager.overridePendingAppTransitionScaleUp( |
| 935 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 936 | pendingOptions.getWidth(), pendingOptions.getHeight()); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 937 | if (intent.getSourceBounds() == null) { |
| 938 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 939 | pendingOptions.getStartY(), |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 940 | pendingOptions.getStartX()+pendingOptions.getWidth(), |
| 941 | pendingOptions.getStartY()+pendingOptions.getHeight())); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 942 | } |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 943 | break; |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 944 | case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP: |
| 945 | case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN: |
| 946 | boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 947 | service.mWindowManager.overridePendingAppTransitionThumb( |
| 948 | pendingOptions.getThumbnail(), |
| 949 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 950 | pendingOptions.getOnAnimationStartListener(), |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 951 | scaleUp); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 952 | if (intent.getSourceBounds() == null) { |
| 953 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 954 | pendingOptions.getStartY(), |
| 955 | pendingOptions.getStartX() |
| 956 | + pendingOptions.getThumbnail().getWidth(), |
| 957 | pendingOptions.getStartY() |
| 958 | + pendingOptions.getThumbnail().getHeight())); |
| 959 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 960 | break; |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 961 | case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP: |
| 962 | case ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN: |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 963 | final AppTransitionAnimationSpec[] specs = pendingOptions.getAnimSpecs(); |
| 964 | if (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN |
| 965 | && specs != null) { |
| 966 | service.mWindowManager.overridePendingAppTransitionMultiThumb( |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 967 | specs, pendingOptions.getOnAnimationStartListener(), |
| 968 | pendingOptions.getAnimationFinishedListener(), false); |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 969 | } else { |
| 970 | service.mWindowManager.overridePendingAppTransitionAspectScaledThumb( |
| 971 | pendingOptions.getThumbnail(), |
| 972 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 973 | pendingOptions.getWidth(), pendingOptions.getHeight(), |
| 974 | pendingOptions.getOnAnimationStartListener(), |
| 975 | (animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP)); |
| 976 | if (intent.getSourceBounds() == null) { |
| 977 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 978 | pendingOptions.getStartY(), |
| 979 | pendingOptions.getStartX() + pendingOptions.getWidth(), |
| 980 | pendingOptions.getStartY() + pendingOptions.getHeight())); |
| 981 | } |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 982 | } |
| 983 | break; |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 984 | default: |
| 985 | Slog.e(TAG, "applyOptionsLocked: Unknown animationType=" + animationType); |
| 986 | break; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 987 | } |
| 988 | pendingOptions = null; |
| 989 | } |
| 990 | } |
| 991 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 992 | ActivityOptions getOptionsForTargetActivityLocked() { |
| 993 | return pendingOptions != null ? pendingOptions.forTargetActivity() : null; |
| 994 | } |
| 995 | |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 996 | void clearOptionsLocked() { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 997 | if (pendingOptions != null) { |
| 998 | pendingOptions.abort(); |
| 999 | pendingOptions = null; |
| 1000 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Dianne Hackborn | 9622ca4 | 2012-10-23 18:56:33 -0700 | [diff] [blame] | 1003 | ActivityOptions takeOptionsLocked() { |
| 1004 | ActivityOptions opts = pendingOptions; |
| 1005 | pendingOptions = null; |
| 1006 | return opts; |
| 1007 | } |
| 1008 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1009 | void removeUriPermissionsLocked() { |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 1010 | if (uriPermissions != null) { |
| 1011 | uriPermissions.removeUriPermissionsLocked(); |
| 1012 | uriPermissions = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1013 | } |
| 1014 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | |
| 1016 | void pauseKeyDispatchingLocked() { |
| 1017 | if (!keysPaused) { |
| 1018 | keysPaused = true; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1019 | service.mWindowManager.pauseKeyDispatching(appToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | void resumeKeyDispatchingLocked() { |
| 1024 | if (keysPaused) { |
| 1025 | keysPaused = false; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1026 | service.mWindowManager.resumeKeyDispatching(appToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1030 | void updateThumbnailLocked(Bitmap newThumbnail, CharSequence description) { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1031 | if (newThumbnail != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1032 | if (DEBUG_THUMBNAILS) Slog.i(TAG_THUMBNAILS, |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1033 | "Setting thumbnail of " + this + " to " + newThumbnail); |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 1034 | boolean thumbnailUpdated = task.setLastThumbnailLocked(newThumbnail); |
Winson Chung | 096f36b | 2014-08-20 15:39:01 -0700 | [diff] [blame] | 1035 | if (thumbnailUpdated && isPersistable()) { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1036 | mStackSupervisor.mService.notifyTaskPersisterLocked(task, false); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1037 | } |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1038 | } |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1039 | task.lastDescription = description; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 1042 | void startLaunchTickingLocked() { |
| 1043 | if (ActivityManagerService.IS_USER_BUILD) { |
| 1044 | return; |
| 1045 | } |
| 1046 | if (launchTickTime == 0) { |
| 1047 | launchTickTime = SystemClock.uptimeMillis(); |
| 1048 | continueLaunchTickingLocked(); |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | boolean continueLaunchTickingLocked() { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1053 | if (launchTickTime == 0) { |
| 1054 | return false; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 1055 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1056 | |
| 1057 | final ActivityStack stack = task.stack; |
| 1058 | if (stack == null) { |
| 1059 | return false; |
| 1060 | } |
| 1061 | |
| 1062 | Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG, this); |
| 1063 | stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG); |
| 1064 | stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK); |
| 1065 | return true; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | void finishLaunchTickingLocked() { |
| 1069 | launchTickTime = 0; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1070 | final ActivityStack stack = task.stack; |
| 1071 | if (stack != null) { |
| 1072 | stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG); |
| 1073 | } |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 1074 | } |
| 1075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | // IApplicationToken |
| 1077 | |
| 1078 | public boolean mayFreezeScreenLocked(ProcessRecord app) { |
| 1079 | // Only freeze the screen if this activity is currently attached to |
| 1080 | // an application, and that application is not blocked or unresponding. |
| 1081 | // In any other case, we can't count on getting the screen unfrozen, |
| 1082 | // so it is best to leave as-is. |
Dianne Hackborn | 5f4d643 | 2010-12-21 20:40:11 -0800 | [diff] [blame] | 1083 | return app != null && !app.crashing && !app.notResponding; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1085 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1086 | public void startFreezingScreenLocked(ProcessRecord app, int configChanges) { |
| 1087 | if (mayFreezeScreenLocked(app)) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1088 | service.mWindowManager.startAppFreezingScreen(appToken, configChanges); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1089 | } |
| 1090 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1091 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | public void stopFreezingScreenLocked(boolean force) { |
| 1093 | if (force || frozenBeforeDestroy) { |
| 1094 | frozenBeforeDestroy = false; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1095 | service.mWindowManager.stopAppFreezingScreen(appToken, force); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1096 | } |
| 1097 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1098 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1099 | public void reportFullyDrawnLocked() { |
| 1100 | final long curTime = SystemClock.uptimeMillis(); |
| 1101 | if (displayStartTime != 0) { |
| 1102 | reportLaunchTimeLocked(curTime); |
| 1103 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1104 | final ActivityStack stack = task.stack; |
| 1105 | if (fullyDrawnStartTime != 0 && stack != null) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1106 | final long thisTime = curTime - fullyDrawnStartTime; |
| 1107 | final long totalTime = stack.mFullyDrawnStartTime != 0 |
| 1108 | ? (curTime - stack.mFullyDrawnStartTime) : thisTime; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 1109 | if (SHOW_ACTIVITY_START_TIME) { |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 1110 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1111 | EventLog.writeEvent(EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME, |
| 1112 | userId, System.identityHashCode(this), shortComponentName, |
| 1113 | thisTime, totalTime); |
| 1114 | StringBuilder sb = service.mStringBuilder; |
| 1115 | sb.setLength(0); |
| 1116 | sb.append("Fully drawn "); |
| 1117 | sb.append(shortComponentName); |
| 1118 | sb.append(": "); |
| 1119 | TimeUtils.formatDuration(thisTime, sb); |
| 1120 | if (thisTime != totalTime) { |
| 1121 | sb.append(" (total "); |
| 1122 | TimeUtils.formatDuration(totalTime, sb); |
| 1123 | sb.append(")"); |
| 1124 | } |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1125 | Log.i(TAG, sb.toString()); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1126 | } |
| 1127 | if (totalTime > 0) { |
Adam Lesinski | 0debc9a | 2014-07-16 19:09:13 -0700 | [diff] [blame] | 1128 | //service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1129 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1130 | stack.mFullyDrawnStartTime = 0; |
| 1131 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1132 | fullyDrawnStartTime = 0; |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | private void reportLaunchTimeLocked(final long curTime) { |
| 1136 | final ActivityStack stack = task.stack; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1137 | if (stack == null) { |
| 1138 | return; |
| 1139 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1140 | final long thisTime = curTime - displayStartTime; |
| 1141 | final long totalTime = stack.mLaunchStartTime != 0 |
| 1142 | ? (curTime - stack.mLaunchStartTime) : thisTime; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 1143 | if (SHOW_ACTIVITY_START_TIME) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 1144 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1145 | EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME, |
| 1146 | userId, System.identityHashCode(this), shortComponentName, |
| 1147 | thisTime, totalTime); |
| 1148 | StringBuilder sb = service.mStringBuilder; |
| 1149 | sb.setLength(0); |
| 1150 | sb.append("Displayed "); |
| 1151 | sb.append(shortComponentName); |
| 1152 | sb.append(": "); |
| 1153 | TimeUtils.formatDuration(thisTime, sb); |
| 1154 | if (thisTime != totalTime) { |
| 1155 | sb.append(" (total "); |
| 1156 | TimeUtils.formatDuration(totalTime, sb); |
| 1157 | sb.append(")"); |
| 1158 | } |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1159 | Log.i(TAG, sb.toString()); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1160 | } |
| 1161 | mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime); |
| 1162 | if (totalTime > 0) { |
Adam Lesinski | 0debc9a | 2014-07-16 19:09:13 -0700 | [diff] [blame] | 1163 | //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1164 | } |
| 1165 | displayStartTime = 0; |
| 1166 | stack.mLaunchStartTime = 0; |
| 1167 | } |
| 1168 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1169 | void windowsDrawnLocked() { |
| 1170 | if (displayStartTime != 0) { |
| 1171 | reportLaunchTimeLocked(SystemClock.uptimeMillis()); |
| 1172 | } |
| 1173 | mStackSupervisor.sendWaitingVisibleReportLocked(this); |
| 1174 | startTime = 0; |
| 1175 | finishLaunchTickingLocked(); |
| 1176 | if (task != null) { |
| 1177 | task.hasBeenVisible = true; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 1178 | } |
| 1179 | } |
| 1180 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1181 | void windowsVisibleLocked() { |
| 1182 | mStackSupervisor.reportActivityVisibleLocked(this); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1183 | if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1184 | if (!nowVisible) { |
| 1185 | nowVisible = true; |
| 1186 | lastVisibleTime = SystemClock.uptimeMillis(); |
| 1187 | if (!idle) { |
| 1188 | // Instead of doing the full stop routine here, let's just hide any activities |
| 1189 | // we now can, and let them stop when the normal idle happens. |
| 1190 | mStackSupervisor.processStoppingActivitiesLocked(false); |
| 1191 | } else { |
| 1192 | // If this activity was already idle, then we now need to make sure we perform |
| 1193 | // the full stop of any activities that are waiting to do so. This is because |
| 1194 | // we won't do that while they are still waiting for this one to become visible. |
| 1195 | final int size = mStackSupervisor.mWaitingVisibleActivities.size(); |
| 1196 | if (size > 0) { |
| 1197 | for (int i = 0; i < size; i++) { |
| 1198 | ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1199 | 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] | 1200 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1201 | mStackSupervisor.mWaitingVisibleActivities.clear(); |
| 1202 | mStackSupervisor.scheduleIdleLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1203 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1204 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1205 | service.scheduleAppGcsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1206 | } |
| 1207 | } |
| 1208 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1209 | ActivityRecord getWaitingHistoryRecordLocked() { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1210 | // First find the real culprit... if this activity is waiting for |
| 1211 | // another activity to start or has stopped, then the key dispatching |
| 1212 | // timeout should not be caused by this. |
Wale Ogunwale | 16a6279 | 2015-04-01 11:50:31 -0700 | [diff] [blame] | 1213 | if (mStackSupervisor.mWaitingVisibleActivities.contains(this) || stopped) { |
Craig Mautner | 8f2adcb | 2014-04-07 22:21:33 +0000 | [diff] [blame] | 1214 | final ActivityStack stack = mStackSupervisor.getFocusedStack(); |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1215 | // Try to use the one which is closest to top. |
| 1216 | ActivityRecord r = stack.mResumedActivity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1217 | if (r == null) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1218 | r = stack.mPausingActivity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1219 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1220 | if (r != null) { |
| 1221 | return r; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1222 | } |
| 1223 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1224 | return this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1225 | } |
| 1226 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1227 | /** |
| 1228 | * This method will return true if the activity is either visible, is becoming visible, is |
| 1229 | * currently pausing, or is resumed. |
| 1230 | */ |
| 1231 | public boolean isInterestingToUserLocked() { |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1232 | return visible || nowVisible || state == ActivityState.PAUSING || |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1233 | state == ActivityState.RESUMED; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | public void setSleeping(boolean _sleeping) { |
| 1237 | if (sleeping == _sleeping) { |
| 1238 | return; |
| 1239 | } |
| 1240 | if (app != null && app.thread != null) { |
| 1241 | try { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1242 | app.thread.scheduleSleeping(appToken, _sleeping); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1243 | if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) { |
| 1244 | mStackSupervisor.mGoingToSleepActivities.add(this); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1245 | } |
| 1246 | sleeping = _sleeping; |
| 1247 | } catch (RemoteException e) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1248 | Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1249 | } |
| 1250 | } |
| 1251 | } |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 1252 | |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1253 | static void activityResumedLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1254 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1255 | if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r); |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1256 | r.icicle = null; |
| 1257 | r.haveState = false; |
| 1258 | } |
| 1259 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1260 | static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1261 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1262 | if (r == null) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 1263 | return INVALID_TASK_ID; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1264 | } |
| 1265 | final TaskRecord task = r.task; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1266 | final int activityNdx = task.mActivities.indexOf(r); |
| 1267 | if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 1268 | return INVALID_TASK_ID; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1269 | } |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1270 | return task.taskId; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | static ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1274 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 1275 | return (r != null) ? r.task.stack.isInStackLocked(r) : null; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1276 | } |
| 1277 | |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1278 | static ActivityStack getStackLocked(IBinder token) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1279 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1280 | if (r != null) { |
| 1281 | return r.task.stack; |
| 1282 | } |
| 1283 | return null; |
| 1284 | } |
| 1285 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 1286 | final boolean isDestroyable() { |
| 1287 | if (finishing || app == null || state == ActivityState.DESTROYING |
| 1288 | || state == ActivityState.DESTROYED) { |
| 1289 | // This would be redundant. |
| 1290 | return false; |
| 1291 | } |
| 1292 | if (task == null || task.stack == null || this == task.stack.mResumedActivity |
| 1293 | || this == task.stack.mPausingActivity || !haveState || !stopped) { |
| 1294 | // We're not ready for this kind of thing. |
| 1295 | return false; |
| 1296 | } |
| 1297 | if (visible) { |
| 1298 | // The user would notice this! |
| 1299 | return false; |
| 1300 | } |
| 1301 | return true; |
| 1302 | } |
| 1303 | |
Winson Chung | 3bad5cc0 | 2014-08-19 17:44:32 -0700 | [diff] [blame] | 1304 | private static String createImageFilename(long createTime, int taskId) { |
| 1305 | return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime + |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1306 | TaskPersister.IMAGE_EXTENSION; |
| 1307 | } |
| 1308 | |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1309 | void setTaskDescription(TaskDescription _taskDescription) { |
| 1310 | Bitmap icon; |
| 1311 | if (_taskDescription.getIconFilename() == null && |
| 1312 | (icon = _taskDescription.getIcon()) != null) { |
| 1313 | final String iconFilename = createImageFilename(createTime, task.taskId); |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 1314 | final File iconFile = new File(TaskPersister.getUserImagesDir(userId), iconFilename); |
| 1315 | final String iconFilePath = iconFile.getAbsolutePath(); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 1316 | service.mRecentTasks.saveImage(icon, iconFilePath); |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 1317 | _taskDescription.setIconFilename(iconFilePath); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1318 | } |
| 1319 | taskDescription = _taskDescription; |
| 1320 | } |
| 1321 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1322 | void setVoiceSessionLocked(IVoiceInteractionSession session) { |
| 1323 | voiceSession = session; |
| 1324 | pendingVoiceInteractionStart = false; |
| 1325 | } |
| 1326 | |
| 1327 | void clearVoiceSessionLocked() { |
| 1328 | voiceSession = null; |
| 1329 | pendingVoiceInteractionStart = false; |
| 1330 | } |
| 1331 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1332 | void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException { |
| 1333 | out.attribute(null, ATTR_ID, String.valueOf(createTime)); |
| 1334 | out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid)); |
| 1335 | if (launchedFromPackage != null) { |
| 1336 | out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage); |
| 1337 | } |
| 1338 | if (resolvedType != null) { |
| 1339 | out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType); |
| 1340 | } |
| 1341 | out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified)); |
| 1342 | out.attribute(null, ATTR_USERID, String.valueOf(userId)); |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 1343 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1344 | if (taskDescription != null) { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1345 | taskDescription.saveToXml(out); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | out.startTag(null, TAG_INTENT); |
| 1349 | intent.saveToXml(out); |
| 1350 | out.endTag(null, TAG_INTENT); |
| 1351 | |
| 1352 | if (isPersistable() && persistentState != null) { |
| 1353 | out.startTag(null, TAG_PERSISTABLEBUNDLE); |
| 1354 | persistentState.saveToXml(out); |
| 1355 | out.endTag(null, TAG_PERSISTABLEBUNDLE); |
| 1356 | } |
| 1357 | } |
| 1358 | |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 1359 | static ActivityRecord restoreFromXml(XmlPullParser in, |
| 1360 | ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1361 | Intent intent = null; |
| 1362 | PersistableBundle persistentState = null; |
| 1363 | int launchedFromUid = 0; |
| 1364 | String launchedFromPackage = null; |
| 1365 | String resolvedType = null; |
| 1366 | boolean componentSpecified = false; |
| 1367 | int userId = 0; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1368 | long createTime = -1; |
| 1369 | final int outerDepth = in.getDepth(); |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 1370 | TaskDescription taskDescription = new TaskDescription(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1371 | |
| 1372 | for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) { |
| 1373 | final String attrName = in.getAttributeName(attrNdx); |
| 1374 | final String attrValue = in.getAttributeValue(attrNdx); |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 1375 | if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 1376 | "ActivityRecord: attribute name=" + attrName + " value=" + attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1377 | if (ATTR_ID.equals(attrName)) { |
| 1378 | createTime = Long.valueOf(attrValue); |
| 1379 | } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) { |
| 1380 | launchedFromUid = Integer.valueOf(attrValue); |
| 1381 | } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) { |
| 1382 | launchedFromPackage = attrValue; |
| 1383 | } else if (ATTR_RESOLVEDTYPE.equals(attrName)) { |
| 1384 | resolvedType = attrValue; |
| 1385 | } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) { |
| 1386 | componentSpecified = Boolean.valueOf(attrValue); |
| 1387 | } else if (ATTR_USERID.equals(attrName)) { |
| 1388 | userId = Integer.valueOf(attrValue); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1389 | } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) { |
| 1390 | taskDescription.restoreFromXml(attrName, attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1391 | } else { |
| 1392 | Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName); |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | int event; |
| 1397 | while (((event = in.next()) != XmlPullParser.END_DOCUMENT) && |
Ben Kwa | 8814cf4 | 2015-07-08 10:54:56 -0700 | [diff] [blame] | 1398 | (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1399 | if (event == XmlPullParser.START_TAG) { |
| 1400 | final String name = in.getName(); |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 1401 | if (TaskPersister.DEBUG) |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 1402 | Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1403 | if (TAG_INTENT.equals(name)) { |
| 1404 | intent = Intent.restoreFromXml(in); |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 1405 | if (TaskPersister.DEBUG) |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 1406 | Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1407 | } else if (TAG_PERSISTABLEBUNDLE.equals(name)) { |
| 1408 | persistentState = PersistableBundle.restoreFromXml(in); |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 1409 | if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1410 | "ActivityRecord: persistentState=" + persistentState); |
| 1411 | } else { |
| 1412 | Slog.w(TAG, "restoreActivity: unexpected name=" + name); |
| 1413 | XmlUtils.skipCurrentTag(in); |
| 1414 | } |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | if (intent == null) { |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 1419 | throw new XmlPullParserException("restoreActivity error intent=" + intent); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | final ActivityManagerService service = stackSupervisor.mService; |
| 1423 | final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1424 | userId); |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 1425 | if (aInfo == null) { |
Craig Mautner | 77b0426 | 2014-06-27 15:22:12 -0700 | [diff] [blame] | 1426 | throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent + |
| 1427 | " resolvedType=" + resolvedType); |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 1428 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1429 | final ActivityRecord r = new ActivityRecord(service, /*caller*/null, launchedFromUid, |
| 1430 | launchedFromPackage, intent, resolvedType, aInfo, service.getConfiguration(), |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 1431 | null, null, 0, componentSpecified, false, stackSupervisor, null, null); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1432 | |
| 1433 | r.persistentState = persistentState; |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 1434 | r.taskDescription = taskDescription; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1435 | r.createTime = createTime; |
| 1436 | |
| 1437 | return r; |
| 1438 | } |
| 1439 | |
| 1440 | private static String activityTypeToString(int type) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 1441 | switch (type) { |
| 1442 | case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE"; |
| 1443 | case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE"; |
| 1444 | case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE"; |
| 1445 | default: return Integer.toString(type); |
| 1446 | } |
| 1447 | } |
| 1448 | |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 1449 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1450 | public String toString() { |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 1451 | if (stringName != null) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 1452 | return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) + |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1453 | (finishing ? " f}" : "}"); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 1454 | } |
| 1455 | StringBuilder sb = new StringBuilder(128); |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 1456 | sb.append("ActivityRecord{"); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 1457 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 1458 | sb.append(" u"); |
| 1459 | sb.append(userId); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 1460 | sb.append(' '); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1461 | sb.append(intent.getComponent().flattenToShortString()); |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 1462 | stringName = sb.toString(); |
| 1463 | return toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1464 | } |
| 1465 | } |