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