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