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