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