Program: 196755
Project: 196755
Buggy source:
final boolean resumeTopActivityInnerLocked(ActivityRecord prev,Bundle options){
  if (ActivityManagerService.DEBUG_LOCKSCREEN)   mService.logLockScreen("String_Node_Str");
  ActivityRecord parent=mActivityContainer.mParentActivity;
  if ((parent != null && parent.state != ActivityState.RESUMED) || !mActivityContainer.isAttachedLocked()) {
    return false;
  }
  cancelInitializingActivities();
  ActivityRecord next=topRunningActivityLocked(null);
  final boolean userLeaving=mStackSupervisor.mUserLeaving;
  mStackSupervisor.mUserLeaving=false;
  final TaskRecord prevTask=prev != null ? prev.task : null;
  if (next == null) {
    ActivityOptions.abort(options);
    if (DEBUG_STATES)     Slog.d(TAG,"String_Node_Str");
    if (DEBUG_STACK)     mStackSupervisor.validateTopActivitiesLocked();
    final int returnTaskType=prevTask == null || !prevTask.isOverHomeStack() ? HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo();
    return isOnHomeDisplay() && mStackSupervisor.resumeHomeStackTask(returnTaskType,prev);
  }
  next.delayedResume=false;
  if (mResumedActivity == next && next.state == ActivityState.RESUMED && mStackSupervisor.allResumedActivitiesComplete()) {
    mWindowManager.executeAppTransition();
    mNoAnimActivities.clear();
    ActivityOptions.abort(options);
    if (DEBUG_STATES)     Slog.d(TAG,"String_Node_Str" + next);
    if (DEBUG_STACK)     mStackSupervisor.validateTopActivitiesLocked();
    mStackSupervisor.notifyActivityDrawnForKeyguard();
    return false;
  }
  final TaskRecord nextTask=next.task;
  if (prevTask != null && prevTask.stack == this && prevTask.isOverHomeStack() && prev.finishing && prev.frontOfTask) {
    if (DEBUG_STACK)     mStackSupervisor.validateTopActivitiesLocked();
    if (prevTask == nextTask) {
      prevTask.setFrontOfTask();
    }
 else     if (prevTask != topTask()) {
      final int taskNdx=mTaskHistory.indexOf(prevTask) + 1;
      mTaskHistory.get(taskNdx).setTaskToReturnTo(HOME_ACTIVITY_TYPE);
    }
 else {
      if (DEBUG_STATES && isOnHomeDisplay())       Slog.d(TAG,"String_Node_Str");
      final int returnTaskType=prevTask == null || !prevTask.isOverHomeStack() ? HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo();
      return isOnHomeDisplay() && mStackSupervisor.resumeHomeStackTask(returnTaskType,prev);
    }
  }
  if (mService.isSleepingOrShuttingDown() && mLastPausedActivity == next && mStackSupervisor.allPausedActivitiesComplete()) {
    mWindowManager.executeAppTransition();
    mNoAnimActivities.clear();
    ActivityOptions.abort(options);
    if (DEBUG_STATES)     Slog.d(TAG,"String_Node_Str");
    if (DEBUG_STACK)     mStackSupervisor.validateTopActivitiesLocked();
    return false;
  }
  if (mService.mStartedUsers.get(next.userId) == null) {
    Slog.w(TAG,"String_Node_Str" + next + "String_Node_Str"+ next.userId+ "String_Node_Str");
    if (DEBUG_STACK)     mStackSupervisor.validateTopActivitiesLocked();
    return false;
  }
  mStackSupervisor.mStoppingActivities.remove(next);
  mStackSupervisor.mGoingToSleepActivities.remove(next);
  next.sleeping=false;
  mStackSupervisor.mWaitingVisibleActivities.remove(next);
  if (DEBUG_SWITCH)   Slog.v(TAG,"String_Node_Str" + next);
  if (!mStackSupervisor.allPausedActivitiesComplete()) {
    if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES)     Slog.v(TAG,"String_Node_Str");
    if (DEBUG_STACK)     mStackSupervisor.validateTopActivitiesLocked();
    return false;
  }
  if (false) {
    if (mLastStartedActivity != null && !mLastStartedActivity.finishing) {
      long now=SystemClock.uptimeMillis();
      final boolean inTime=mLastStartedActivity.startTime != 0 && (mLastStartedActivity.startTime + START_WARN_TIME) >= now;
      final int lastUid=mLastStartedActivity.info.applicationInfo.uid;
      final int nextUid=next.info.applicationInfo.uid;
      if (inTime && lastUid != nextUid && lastUid != next.launchedFromUid && mService.checkPermission(android.Manifest.permission.STOP_APP_SWITCHES,-1,next.launchedFromUid) != PackageManager.PERMISSION_GRANTED) {
        mService.showLaunchWarningLocked(mLastStartedActivity,next);
      }
 else {
        next.startTime=now;
        mLastStartedActivity=next;
      }
    }
 else {
      next.startTime=SystemClock.uptimeMillis();
      mLastStartedActivity=next;
    }
  }
  boolean dontWaitForPause=(next.info.flags & ActivityInfo.FLAG_RESUME_WHILE_PAUSING) != 0;
  boolean pausing=mStackSupervisor.pauseBackStacks(userLeaving,true,dontWaitForPause);
  if (mResumedActivity != null) {
    pausing|=startPausingLocked(userLeaving,false,true,dontWaitForPause);
    if (DEBUG_STATES)     Slog.d(TAG,"String_Node_Str" + mResumedActivity);
  }
  if (pausing) {
    if (DEBUG_SWITCH || DEBUG_STATES)     Slog.v(TAG,"String_Node_Str");
    if (next.app != null && next.app.thread != null) {
      mService.updateLruProcessLocked(next.app,true,null);
    }
    if (DEBUG_STACK)     mStackSupervisor.validateTopActivitiesLocked();
    return true;
  }
  if (mService.isSleeping() && mLastNoHistoryActivity != null && !mLastNoHistoryActivity.finishing) {
    if (DEBUG_STATES)     Slog.d(TAG,"String_Node_Str" + mLastNoHistoryActivity + "String_Node_Str");
    requestFinishActivityLocked(mLastNoHistoryActivity.appToken,Activity.RESULT_CANCELED,null,"String_Node_Str",false);
    mLastNoHistoryActivity=null;
  }
  if (prev != null && prev != next) {
    if (!prev.waitingVisible && next != null && !next.nowVisible) {
      prev.waitingVisible=true;
      mStackSupervisor.mWaitingVisibleActivities.add(prev);
      if (DEBUG_SWITCH)       Slog.v(TAG,"String_Node_Str" + prev);
    }
 else {
      if (prev.finishing) {
        mWindowManager.setAppVisibility(prev.appToken,false);
        if (DEBUG_SWITCH)         Slog.v(TAG,"String_Node_Str" + prev + "String_Node_Str"+ (prev != null ? prev.waitingVisible : null)+ "String_Node_Str"+ next.nowVisible);
      }
 else {
        if (DEBUG_SWITCH)         Slog.v(TAG,"String_Node_Str" + prev + "String_Node_Str"+ (prev != null ? prev.waitingVisible : null)+ "String_Node_Str"+ next.nowVisible);
      }
    }
  }
  try {
    AppGlobals.getPackageManager().setPackageStoppedState(next.packageName,false,next.userId);
  }
 catch (  RemoteException e1) {
  }
catch (  IllegalArgumentException e) {
    Slog.w(TAG,"String_Node_Str" + next.packageName + "String_Node_Str"+ e);
  }
  boolean anim=true;
  if (prev != null) {
    if (prev.finishing) {
      if (DEBUG_TRANSITION)       Slog.v(TAG,"String_Node_Str" + prev);
      if (mNoAnimActivities.contains(prev)) {
        anim=false;
        mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE,false);
      }
 else {
        mWindowManager.prepareAppTransition(prev.task == next.task ? AppTransition.TRANSIT_ACTIVITY_CLOSE : AppTransition.TRANSIT_TASK_CLOSE,false);
      }
      mWindowManager.setAppWillBeHidden(prev.appToken);
      mWindowManager.setAppVisibility(prev.appToken,false);
    }
 else {
      if (DEBUG_TRANSITION)       Slog.v(TAG,"String_Node_Str" + prev);
      if (mNoAnimActivities.contains(next)) {
        anim=false;
        mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE,false);
      }
 else {
        mWindowManager.prepareAppTransition(prev.task == next.task ? AppTransition.TRANSIT_ACTIVITY_OPEN : next.mLaunchTaskBehind ? AppTransition.TRANSIT_TASK_OPEN_BEHIND : AppTransition.TRANSIT_TASK_OPEN,false);
      }
    }
    if (false) {
      mWindowManager.setAppWillBeHidden(prev.appToken);
      mWindowManager.setAppVisibility(prev.appToken,false);
    }
  }
 else {
    if (DEBUG_TRANSITION)     Slog.v(TAG,"String_Node_Str");
    if (mNoAnimActivities.contains(next)) {
      anim=false;
      mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE,false);
    }
 else {
      mWindowManager.prepareAppTransition(AppTransition.TRANSIT_ACTIVITY_OPEN,false);
    }
  }
  Bundle resumeAnimOptions=null;
  if (anim) {
    ActivityOptions opts=next.getOptionsForTargetActivityLocked();
    if (opts != null) {
      resumeAnimOptions=opts.toBundle();
    }
    next.applyOptionsLocked();
  }
 else {
    next.clearOptionsLocked();
  }
  ActivityStack lastStack=mStackSupervisor.getLastStack();
  if (next.app != null && next.app.thread != null) {
    if (DEBUG_SWITCH)     Slog.v(TAG,"String_Node_Str" + next);
    mWindowManager.setAppVisibility(next.appToken,true);
    next.startLaunchTickingLocked();
    ActivityRecord lastResumedActivity=lastStack == null ? null : lastStack.mResumedActivity;
    ActivityState lastState=next.state;
    mService.updateCpuStats();
    if (DEBUG_STATES)     Slog.v(TAG,"String_Node_Str" + next + "String_Node_Str");
    next.state=ActivityState.RESUMED;
    mResumedActivity=next;
    next.task.touchActiveTime();
    mService.addRecentTaskLocked(next.task);
    mService.updateLruProcessLocked(next.app,true,null);
    updateLRUListLocked(next);
    mService.updateOomAdjLocked();
    boolean notUpdated=true;
    if (mStackSupervisor.isFrontStack(this)) {
      Configuration config=mWindowManager.updateOrientationFromAppTokens(mService.mConfiguration,next.mayFreezeScreenLocked(next.app) ? next.appToken : null);
      if (config != null) {
        next.frozenBeforeDestroy=true;
      }
      notUpdated=!mService.updateConfigurationLocked(config,next,false,false);
    }
    if (notUpdated) {
      ActivityRecord nextNext=topRunningActivityLocked(null);
      if (DEBUG_SWITCH || DEBUG_STATES)       Slog.i(TAG,"String_Node_Str" + next + "String_Node_Str"+ nextNext);
      if (nextNext != next) {
        mStackSupervisor.scheduleResumeTopActivities();
      }
      if (mStackSupervisor.reportResumedActivityLocked(next)) {
        mNoAnimActivities.clear();
        if (DEBUG_STACK)         mStackSupervisor.validateTopActivitiesLocked();
        return true;
      }
      if (DEBUG_STACK)       mStackSupervisor.validateTopActivitiesLocked();
      return false;
    }
    try {
      ArrayList<ResultInfo> a=next.results;
      if (a != null) {
        final int N=a.size();
        if (!next.finishing && N > 0) {
          if (DEBUG_RESULTS)           Slog.v(TAG,"String_Node_Str" + next + "String_Node_Str"+ a);
          next.app.thread.scheduleSendResult(next.appToken,a);
        }
      }
      if (next.newIntents != null) {
        next.app.thread.scheduleNewIntent(next.newIntents,next.appToken);
      }
      EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY,next.userId,System.identityHashCode(next),next.task.taskId,next.shortComponentName);
      next.sleeping=false;
      mService.showAskCompatModeDialogLocked(next);
      next.app.pendingUiClean=true;
      next.app.forceProcessStateUpTo(ActivityManager.PROCESS_STATE_TOP);
      next.clearOptionsLocked();
      next.app.thread.scheduleResumeActivity(next.appToken,next.app.repProcState,mService.isNextTransitionForward(),resumeAnimOptions);
      mStackSupervisor.checkReadyForSleepLocked();
      if (DEBUG_STATES)       Slog.d(TAG,"String_Node_Str" + next);
    }
 catch (    Exception e) {
      if (DEBUG_STATES)       Slog.v(TAG,"String_Node_Str" + lastState + "String_Node_Str"+ next);
      next.state=lastState;
      if (lastStack != null) {
        lastStack.mResumedActivity=lastResumedActivity;
      }
      Slog.i(TAG,"String_Node_Str" + next);
      if (!next.hasBeenLaunched) {
        next.hasBeenLaunched=true;
      }
 else       if (SHOW_APP_STARTING_PREVIEW && lastStack != null && mStackSupervisor.isFrontStack(lastStack)) {
        mWindowManager.setAppStartingWindow(next.appToken,next.packageName,next.theme,mService.compatibilityInfoForPackageLocked(next.info.applicationInfo),next.nonLocalizedLabel,next.labelRes,next.icon,next.logo,next.windowFlags,null,true);
      }
      mStackSupervisor.startSpecificActivityLocked(next,true,false);
      if (DEBUG_STACK)       mStackSupervisor.validateTopActivitiesLocked();
      return true;
    }
    try {
      next.visible=true;
      completeResumeLocked(next);
    }
 catch (    Exception e) {
      Slog.w(TAG,"String_Node_Str" + next,e);
      requestFinishActivityLocked(next.appToken,Activity.RESULT_CANCELED,null,"String_Node_Str",true);
      if (DEBUG_STACK)       mStackSupervisor.validateTopActivitiesLocked();
      return true;
    }
    next.stopped=false;
  }
 else {
    if (!next.hasBeenLaunched) {
      next.hasBeenLaunched=true;
    }
 else {
      if (SHOW_APP_STARTING_PREVIEW) {
        mWindowManager.setAppStartingWindow(next.appToken,next.packageName,next.theme,mService.compatibilityInfoForPackageLocked(next.info.applicationInfo),next.nonLocalizedLabel,next.labelRes,next.icon,next.logo,next.windowFlags,null,true);
      }
      if (DEBUG_SWITCH)       Slog.v(TAG,"String_Node_Str" + next);
    }
    if (DEBUG_STATES)     Slog.d(TAG,"String_Node_Str" + next);
    mStackSupervisor.startSpecificActivityLocked(next,true,true);
  }
  if (DEBUG_STACK)   mStackSupervisor.validateTopActivitiesLocked();
  return true;
}

Fixed version (ground truth):
final boolean resumeTopActivityInnerLocked(ActivityRecord prev,Bundle options){
  if (ActivityManagerService.DEBUG_LOCKSCREEN)   mService.logLockScreen("String_Node_Str");
  if (!mService.mBooting && !mService.mBooted) {
    return false;
  }
  ActivityRecord parent=mActivityContainer.mParentActivity;
  if ((parent != null && parent.state != ActivityState.RESUMED) || !mActivityContainer.isAttachedLocked()) {
    return false;
  }
  cancelInitializingActivities();
  ActivityRecord next=topRunningActivityLocked(null);
  final boolean userLeaving=mStackSupervisor.mUserLeaving;
  mStackSupervisor.mUserLeaving=false;
  final TaskRecord prevTask=prev != null ? prev.task : null;
  if (next == null) {
    ActivityOptions.abort(options);
    if (DEBUG_STATES)     Slog.d(TAG,"String_Node_Str");
    if (DEBUG_STACK)     mStackSupervisor.validateTopActivitiesLocked();
    final int returnTaskType=prevTask == null || !prevTask.isOverHomeStack() ? HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo();
    return isOnHomeDisplay() && mStackSupervisor.resumeHomeStackTask(returnTaskType,prev);
  }
  next.delayedResume=false;
  if (mResumedActivity == next && next.state == ActivityState.RESUMED && mStackSupervisor.allResumedActivitiesComplete()) {
    mWindowManager.executeAppTransition();
    mNoAnimActivities.clear();
    ActivityOptions.abort(options);
    if (DEBUG_STATES)     Slog.d(TAG,"String_Node_Str" + next);
    if (DEBUG_STACK)     mStackSupervisor.validateTopActivitiesLocked();
    mStackSupervisor.notifyActivityDrawnForKeyguard();
    return false;
  }
  final TaskRecord nextTask=next.task;
  if (prevTask != null && prevTask.stack == this && prevTask.isOverHomeStack() && prev.finishing && prev.frontOfTask) {
    if (DEBUG_STACK)     mStackSupervisor.validateTopActivitiesLocked();
    if (prevTask == nextTask) {
      prevTask.setFrontOfTask();
    }
 else     if (prevTask != topTask()) {
      final int taskNdx=mTaskHistory.indexOf(prevTask) + 1;
      mTaskHistory.get(taskNdx).setTaskToReturnTo(HOME_ACTIVITY_TYPE);
    }
 else {
      if (DEBUG_STATES && isOnHomeDisplay())       Slog.d(TAG,"String_Node_Str");
      final int returnTaskType=prevTask == null || !prevTask.isOverHomeStack() ? HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo();
      return isOnHomeDisplay() && mStackSupervisor.resumeHomeStackTask(returnTaskType,prev);
    }
  }
  if (mService.isSleepingOrShuttingDown() && mLastPausedActivity == next && mStackSupervisor.allPausedActivitiesComplete()) {
    mWindowManager.executeAppTransition();
    mNoAnimActivities.clear();
    ActivityOptions.abort(options);
    if (DEBUG_STATES)     Slog.d(TAG,"String_Node_Str");
    if (DEBUG_STACK)     mStackSupervisor.validateTopActivitiesLocked();
    return false;
  }
  if (mService.mStartedUsers.get(next.userId) == null) {
    Slog.w(TAG,"String_Node_Str" + next + "String_Node_Str"+ next.userId+ "String_Node_Str");
    if (DEBUG_STACK)     mStackSupervisor.validateTopActivitiesLocked();
    return false;
  }
  mStackSupervisor.mStoppingActivities.remove(next);
  mStackSupervisor.mGoingToSleepActivities.remove(next);
  next.sleeping=false;
  mStackSupervisor.mWaitingVisibleActivities.remove(next);
  if (DEBUG_SWITCH)   Slog.v(TAG,"String_Node_Str" + next);
  if (!mStackSupervisor.allPausedActivitiesComplete()) {
    if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES)     Slog.v(TAG,"String_Node_Str");
    if (DEBUG_STACK)     mStackSupervisor.validateTopActivitiesLocked();
    return false;
  }
  if (false) {
    if (mLastStartedActivity != null && !mLastStartedActivity.finishing) {
      long now=SystemClock.uptimeMillis();
      final boolean inTime=mLastStartedActivity.startTime != 0 && (mLastStartedActivity.startTime + START_WARN_TIME) >= now;
      final int lastUid=mLastStartedActivity.info.applicationInfo.uid;
      final int nextUid=next.info.applicationInfo.uid;
      if (inTime && lastUid != nextUid && lastUid != next.launchedFromUid && mService.checkPermission(android.Manifest.permission.STOP_APP_SWITCHES,-1,next.launchedFromUid) != PackageManager.PERMISSION_GRANTED) {
        mService.showLaunchWarningLocked(mLastStartedActivity,next);
      }
 else {
        next.startTime=now;
        mLastStartedActivity=next;
      }
    }
 else {
      next.startTime=SystemClock.uptimeMillis();
      mLastStartedActivity=next;
    }
  }
  boolean dontWaitForPause=(next.info.flags & ActivityInfo.FLAG_RESUME_WHILE_PAUSING) != 0;
  boolean pausing=mStackSupervisor.pauseBackStacks(userLeaving,true,dontWaitForPause);
  if (mResumedActivity != null) {
    pausing|=startPausingLocked(userLeaving,false,true,dontWaitForPause);
    if (DEBUG_STATES)     Slog.d(TAG,"String_Node_Str" + mResumedActivity);
  }
  if (pausing) {
    if (DEBUG_SWITCH || DEBUG_STATES)     Slog.v(TAG,"String_Node_Str");
    if (next.app != null && next.app.thread != null) {
      mService.updateLruProcessLocked(next.app,true,null);
    }
    if (DEBUG_STACK)     mStackSupervisor.validateTopActivitiesLocked();
    return true;
  }
  if (mService.isSleeping() && mLastNoHistoryActivity != null && !mLastNoHistoryActivity.finishing) {
    if (DEBUG_STATES)     Slog.d(TAG,"String_Node_Str" + mLastNoHistoryActivity + "String_Node_Str");
    requestFinishActivityLocked(mLastNoHistoryActivity.appToken,Activity.RESULT_CANCELED,null,"String_Node_Str",false);
    mLastNoHistoryActivity=null;
  }
  if (prev != null && prev != next) {
    if (!prev.waitingVisible && next != null && !next.nowVisible) {
      prev.waitingVisible=true;
      mStackSupervisor.mWaitingVisibleActivities.add(prev);
      if (DEBUG_SWITCH)       Slog.v(TAG,"String_Node_Str" + prev);
    }
 else {
      if (prev.finishing) {
        mWindowManager.setAppVisibility(prev.appToken,false);
        if (DEBUG_SWITCH)         Slog.v(TAG,"String_Node_Str" + prev + "String_Node_Str"+ (prev != null ? prev.waitingVisible : null)+ "String_Node_Str"+ next.nowVisible);
      }
 else {
        if (DEBUG_SWITCH)         Slog.v(TAG,"String_Node_Str" + prev + "String_Node_Str"+ (prev != null ? prev.waitingVisible : null)+ "String_Node_Str"+ next.nowVisible);
      }
    }
  }
  try {
    AppGlobals.getPackageManager().setPackageStoppedState(next.packageName,false,next.userId);
  }
 catch (  RemoteException e1) {
  }
catch (  IllegalArgumentException e) {
    Slog.w(TAG,"String_Node_Str" + next.packageName + "String_Node_Str"+ e);
  }
  boolean anim=true;
  if (prev != null) {
    if (prev.finishing) {
      if (DEBUG_TRANSITION)       Slog.v(TAG,"String_Node_Str" + prev);
      if (mNoAnimActivities.contains(prev)) {
        anim=false;
        mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE,false);
      }
 else {
        mWindowManager.prepareAppTransition(prev.task == next.task ? AppTransition.TRANSIT_ACTIVITY_CLOSE : AppTransition.TRANSIT_TASK_CLOSE,false);
      }
      mWindowManager.setAppWillBeHidden(prev.appToken);
      mWindowManager.setAppVisibility(prev.appToken,false);
    }
 else {
      if (DEBUG_TRANSITION)       Slog.v(TAG,"String_Node_Str" + prev);
      if (mNoAnimActivities.contains(next)) {
        anim=false;
        mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE,false);
      }
 else {
        mWindowManager.prepareAppTransition(prev.task == next.task ? AppTransition.TRANSIT_ACTIVITY_OPEN : next.mLaunchTaskBehind ? AppTransition.TRANSIT_TASK_OPEN_BEHIND : AppTransition.TRANSIT_TASK_OPEN,false);
      }
    }
    if (false) {
      mWindowManager.setAppWillBeHidden(prev.appToken);
      mWindowManager.setAppVisibility(prev.appToken,false);
    }
  }
 else {
    if (DEBUG_TRANSITION)     Slog.v(TAG,"String_Node_Str");
    if (mNoAnimActivities.contains(next)) {
      anim=false;
      mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE,false);
    }
 else {
      mWindowManager.prepareAppTransition(AppTransition.TRANSIT_ACTIVITY_OPEN,false);
    }
  }
  Bundle resumeAnimOptions=null;
  if (anim) {
    ActivityOptions opts=next.getOptionsForTargetActivityLocked();
    if (opts != null) {
      resumeAnimOptions=opts.toBundle();
    }
    next.applyOptionsLocked();
  }
 else {
    next.clearOptionsLocked();
  }
  ActivityStack lastStack=mStackSupervisor.getLastStack();
  if (next.app != null && next.app.thread != null) {
    if (DEBUG_SWITCH)     Slog.v(TAG,"String_Node_Str" + next);
    mWindowManager.setAppVisibility(next.appToken,true);
    next.startLaunchTickingLocked();
    ActivityRecord lastResumedActivity=lastStack == null ? null : lastStack.mResumedActivity;
    ActivityState lastState=next.state;
    mService.updateCpuStats();
    if (DEBUG_STATES)     Slog.v(TAG,"String_Node_Str" + next + "String_Node_Str");
    next.state=ActivityState.RESUMED;
    mResumedActivity=next;
    next.task.touchActiveTime();
    mService.addRecentTaskLocked(next.task);
    mService.updateLruProcessLocked(next.app,true,null);
    updateLRUListLocked(next);
    mService.updateOomAdjLocked();
    boolean notUpdated=true;
    if (mStackSupervisor.isFrontStack(this)) {
      Configuration config=mWindowManager.updateOrientationFromAppTokens(mService.mConfiguration,next.mayFreezeScreenLocked(next.app) ? next.appToken : null);
      if (config != null) {
        next.frozenBeforeDestroy=true;
      }
      notUpdated=!mService.updateConfigurationLocked(config,next,false,false);
    }
    if (notUpdated) {
      ActivityRecord nextNext=topRunningActivityLocked(null);
      if (DEBUG_SWITCH || DEBUG_STATES)       Slog.i(TAG,"String_Node_Str" + next + "String_Node_Str"+ nextNext);
      if (nextNext != next) {
        mStackSupervisor.scheduleResumeTopActivities();
      }
      if (mStackSupervisor.reportResumedActivityLocked(next)) {
        mNoAnimActivities.clear();
        if (DEBUG_STACK)         mStackSupervisor.validateTopActivitiesLocked();
        return true;
      }
      if (DEBUG_STACK)       mStackSupervisor.validateTopActivitiesLocked();
      return false;
    }
    try {
      ArrayList<ResultInfo> a=next.results;
      if (a != null) {
        final int N=a.size();
        if (!next.finishing && N > 0) {
          if (DEBUG_RESULTS)           Slog.v(TAG,"String_Node_Str" + next + "String_Node_Str"+ a);
          next.app.thread.scheduleSendResult(next.appToken,a);
        }
      }
      if (next.newIntents != null) {
        next.app.thread.scheduleNewIntent(next.newIntents,next.appToken);
      }
      EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY,next.userId,System.identityHashCode(next),next.task.taskId,next.shortComponentName);
      next.sleeping=false;
      mService.showAskCompatModeDialogLocked(next);
      next.app.pendingUiClean=true;
      next.app.forceProcessStateUpTo(ActivityManager.PROCESS_STATE_TOP);
      next.clearOptionsLocked();
      next.app.thread.scheduleResumeActivity(next.appToken,next.app.repProcState,mService.isNextTransitionForward(),resumeAnimOptions);
      mStackSupervisor.checkReadyForSleepLocked();
      if (DEBUG_STATES)       Slog.d(TAG,"String_Node_Str" + next);
    }
 catch (    Exception e) {
      if (DEBUG_STATES)       Slog.v(TAG,"String_Node_Str" + lastState + "String_Node_Str"+ next);
      next.state=lastState;
      if (lastStack != null) {
        lastStack.mResumedActivity=lastResumedActivity;
      }
      Slog.i(TAG,"String_Node_Str" + next);
      if (!next.hasBeenLaunched) {
        next.hasBeenLaunched=true;
      }
 else       if (SHOW_APP_STARTING_PREVIEW && lastStack != null && mStackSupervisor.isFrontStack(lastStack)) {
        mWindowManager.setAppStartingWindow(next.appToken,next.packageName,next.theme,mService.compatibilityInfoForPackageLocked(next.info.applicationInfo),next.nonLocalizedLabel,next.labelRes,next.icon,next.logo,next.windowFlags,null,true);
      }
      mStackSupervisor.startSpecificActivityLocked(next,true,false);
      if (DEBUG_STACK)       mStackSupervisor.validateTopActivitiesLocked();
      return true;
    }
    try {
      next.visible=true;
      completeResumeLocked(next);
    }
 catch (    Exception e) {
      Slog.w(TAG,"String_Node_Str" + next,e);
      requestFinishActivityLocked(next.appToken,Activity.RESULT_CANCELED,null,"String_Node_Str",true);
      if (DEBUG_STACK)       mStackSupervisor.validateTopActivitiesLocked();
      return true;
    }
    next.stopped=false;
  }
 else {
    if (!next.hasBeenLaunched) {
      next.hasBeenLaunched=true;
    }
 else {
      if (SHOW_APP_STARTING_PREVIEW) {
        mWindowManager.setAppStartingWindow(next.appToken,next.packageName,next.theme,mService.compatibilityInfoForPackageLocked(next.info.applicationInfo),next.nonLocalizedLabel,next.labelRes,next.icon,next.logo,next.windowFlags,null,true);
      }
      if (DEBUG_SWITCH)       Slog.v(TAG,"String_Node_Str" + next);
    }
    if (DEBUG_STATES)     Slog.d(TAG,"String_Node_Str" + next);
    mStackSupervisor.startSpecificActivityLocked(next,true,true);
  }
  if (DEBUG_STACK)   mStackSupervisor.validateTopActivitiesLocked();
  return true;
}