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