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