Program: 24253
Project: 24253
Buggy source:
/** 
 * Ensure that the top activity in the stack is resumed.
 * @param prev The previously resumed activity, for when in the processof pausing; can be null to call from elsewhere.
 * @return Returns true if something is being resumed, or false ifnothing happened.
 */
private final boolean resumeTopActivityLocked(HistoryRecord prev){
  HistoryRecord next=topRunningActivityLocked(null);
  final boolean userLeaving=mUserLeaving;
  mUserLeaving=false;
  if (next == null) {
    if (mFactoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL && mTopAction == null) {
      return false;
    }
    Intent intent=new Intent(mTopAction,mTopData != null ? Uri.parse(mTopData) : null);
    intent.setComponent(mTopComponent);
    if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
      intent.addCategory(Intent.CATEGORY_HOME);
    }
    ActivityInfo aInfo=intent.resolveActivityInfo(mContext.getPackageManager(),PackageManager.GET_SHARED_LIBRARY_FILES);
    if (aInfo != null) {
      intent.setComponent(new ComponentName(aInfo.applicationInfo.packageName,aInfo.name));
      ProcessRecord app=getProcessRecordLocked(aInfo.processName,aInfo.applicationInfo.uid);
      if (app == null || app.instrumentationClass == null) {
        intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivityLocked(null,intent,null,null,0,aInfo,null,null,0,0,0,false,false);
      }
    }
    return true;
  }
  if (mResumedActivity == next && next.state == ActivityState.RESUMED) {
    mWindowManager.executeAppTransition();
    return false;
  }
  if ((mSleeping || mShuttingDown) && mLastPausedActivity == next && next.state == ActivityState.PAUSED) {
    mWindowManager.executeAppTransition();
    return false;
  }
  mStoppingActivities.remove(next);
  mWaitingVisibleActivities.remove(next);
  if (DEBUG_SWITCH)   Log.v(TAG,"String_Node_Str" + next);
  if (mPausingActivity != null) {
    if (DEBUG_SWITCH)     Log.v(TAG,"String_Node_Str" + mPausingActivity);
    return false;
  }
  if (mResumedActivity != null) {
    if (DEBUG_SWITCH)     Log.v(TAG,"String_Node_Str");
    startPausingLocked(userLeaving,false);
    return true;
  }
  if (prev != null && prev != next) {
    if (!prev.waitingVisible && next != null && !next.nowVisible) {
      prev.waitingVisible=true;
      mWaitingVisibleActivities.add(prev);
      if (DEBUG_SWITCH)       Log.v(TAG,"String_Node_Str" + prev);
    }
 else {
      if (prev.finishing) {
        mWindowManager.setAppVisibility(prev,false);
        if (DEBUG_SWITCH)         Log.v(TAG,"String_Node_Str" + prev + "String_Node_Str"+ (prev != null ? prev.waitingVisible : null)+ "String_Node_Str"+ next.nowVisible);
      }
 else {
        if (DEBUG_SWITCH)         Log.v(TAG,"String_Node_Str" + prev + "String_Node_Str"+ (prev != null ? prev.waitingVisible : null)+ "String_Node_Str"+ next.nowVisible);
      }
    }
  }
  if (prev != null) {
    if (prev.finishing) {
      if (DEBUG_TRANSITION)       Log.v(TAG,"String_Node_Str" + prev);
      mWindowManager.prepareAppTransition(prev.task == next.task ? WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE : WindowManagerPolicy.TRANSIT_TASK_CLOSE);
      mWindowManager.setAppWillBeHidden(prev);
      mWindowManager.setAppVisibility(prev,false);
    }
 else {
      if (DEBUG_TRANSITION)       Log.v(TAG,"String_Node_Str" + prev);
      mWindowManager.prepareAppTransition(prev.task == next.task ? WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN : WindowManagerPolicy.TRANSIT_TASK_OPEN);
    }
    if (false) {
      mWindowManager.setAppWillBeHidden(prev);
      mWindowManager.setAppVisibility(prev,false);
    }
  }
 else   if (mHistory.size() > 1) {
    if (DEBUG_TRANSITION)     Log.v(TAG,"String_Node_Str");
    mWindowManager.prepareAppTransition(WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN);
  }
  if (next.app != null && next.app.thread != null) {
    if (DEBUG_SWITCH)     Log.v(TAG,"String_Node_Str" + next);
    mWindowManager.setAppVisibility(next,true);
    HistoryRecord lastResumedActivity=mResumedActivity;
    ActivityState lastState=next.state;
    updateCpuStats();
    next.state=ActivityState.RESUMED;
    mResumedActivity=next;
    next.task.touchActiveTime();
    updateLRUListLocked(next.app,true);
    updateLRUListLocked(next);
    Configuration config=mWindowManager.updateOrientationFromAppTokens(mConfiguration,next.mayFreezeScreenLocked(next.app) ? next : null);
    if (config != null) {
      next.frozenBeforeDestroy=true;
    }
    if (!updateConfigurationLocked(config,next)) {
      HistoryRecord nextNext=topRunningActivityLocked(null);
      if (DEBUG_SWITCH)       Log.i(TAG,"String_Node_Str" + next + "String_Node_Str"+ nextNext);
      if (nextNext != next) {
        mHandler.sendEmptyMessage(RESUME_TOP_ACTIVITY_MSG);
      }
      mWindowManager.executeAppTransition();
      return true;
    }
    try {
      ArrayList a=next.results;
      if (a != null) {
        final int N=a.size();
        if (!next.finishing && N > 0) {
          if (DEBUG_RESULTS)           Log.v(TAG,"String_Node_Str" + next + "String_Node_Str"+ a);
          next.app.thread.scheduleSendResult(next,a);
        }
      }
      if (next.newIntents != null) {
        next.app.thread.scheduleNewIntent(next.newIntents,next);
      }
      EventLog.writeEvent(LOG_AM_RESUME_ACTIVITY,System.identityHashCode(next),next.task.taskId,next.shortComponentName);
      updateUsageStats(next,true);
      next.app.thread.scheduleResumeActivity(next,isNextTransitionForward());
      pauseIfSleepingLocked();
    }
 catch (    Exception e) {
      next.state=lastState;
      mResumedActivity=lastResumedActivity;
      if (Config.LOGD)       Log.d(TAG,"String_Node_Str" + next);
      if (!next.hasBeenLaunched) {
        next.hasBeenLaunched=true;
      }
 else {
        if (SHOW_APP_STARTING_ICON) {
          mWindowManager.setAppStartingWindow(next,next.packageName,next.theme,next.nonLocalizedLabel,next.labelRes,next.icon,null,true);
        }
      }
      startSpecificActivityLocked(next,true,false);
      return true;
    }
    try {
      next.visible=true;
      completeResumeLocked(next);
    }
 catch (    Exception e) {
      Log.w(TAG,"String_Node_Str" + next,e);
      requestFinishActivityLocked(next,Activity.RESULT_CANCELED,null,"String_Node_Str");
      return true;
    }
    next.icicle=null;
    next.haveState=false;
    next.stopped=false;
  }
 else {
    if (!next.hasBeenLaunched) {
      next.hasBeenLaunched=true;
    }
 else {
      if (SHOW_APP_STARTING_ICON) {
        mWindowManager.setAppStartingWindow(next,next.packageName,next.theme,next.nonLocalizedLabel,next.labelRes,next.icon,null,true);
      }
      if (DEBUG_SWITCH)       Log.v(TAG,"String_Node_Str" + next);
    }
    startSpecificActivityLocked(next,true,true);
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Ensure that the top activity in the stack is resumed.
 * @param prev The previously resumed activity, for when in the processof pausing; can be null to call from elsewhere.
 * @return Returns true if something is being resumed, or false ifnothing happened.
 */
private final boolean resumeTopActivityLocked(HistoryRecord prev){
  HistoryRecord next=topRunningActivityLocked(null);
  final boolean userLeaving=mUserLeaving;
  mUserLeaving=false;
  if (next == null) {
    if (mFactoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL && mTopAction == null) {
      return false;
    }
    Intent intent=new Intent(mTopAction,mTopData != null ? Uri.parse(mTopData) : null);
    intent.setComponent(mTopComponent);
    if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
      intent.addCategory(Intent.CATEGORY_HOME);
    }
    ActivityInfo aInfo=intent.resolveActivityInfo(mContext.getPackageManager(),STOCK_PM_FLAGS);
    if (aInfo != null) {
      intent.setComponent(new ComponentName(aInfo.applicationInfo.packageName,aInfo.name));
      ProcessRecord app=getProcessRecordLocked(aInfo.processName,aInfo.applicationInfo.uid);
      if (app == null || app.instrumentationClass == null) {
        intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivityLocked(null,intent,null,null,0,aInfo,null,null,0,0,0,false,false);
      }
    }
    return true;
  }
  if (mResumedActivity == next && next.state == ActivityState.RESUMED) {
    mWindowManager.executeAppTransition();
    return false;
  }
  if ((mSleeping || mShuttingDown) && mLastPausedActivity == next && next.state == ActivityState.PAUSED) {
    mWindowManager.executeAppTransition();
    return false;
  }
  mStoppingActivities.remove(next);
  mWaitingVisibleActivities.remove(next);
  if (DEBUG_SWITCH)   Log.v(TAG,"String_Node_Str" + next);
  if (mPausingActivity != null) {
    if (DEBUG_SWITCH)     Log.v(TAG,"String_Node_Str" + mPausingActivity);
    return false;
  }
  if (mResumedActivity != null) {
    if (DEBUG_SWITCH)     Log.v(TAG,"String_Node_Str");
    startPausingLocked(userLeaving,false);
    return true;
  }
  if (prev != null && prev != next) {
    if (!prev.waitingVisible && next != null && !next.nowVisible) {
      prev.waitingVisible=true;
      mWaitingVisibleActivities.add(prev);
      if (DEBUG_SWITCH)       Log.v(TAG,"String_Node_Str" + prev);
    }
 else {
      if (prev.finishing) {
        mWindowManager.setAppVisibility(prev,false);
        if (DEBUG_SWITCH)         Log.v(TAG,"String_Node_Str" + prev + "String_Node_Str"+ (prev != null ? prev.waitingVisible : null)+ "String_Node_Str"+ next.nowVisible);
      }
 else {
        if (DEBUG_SWITCH)         Log.v(TAG,"String_Node_Str" + prev + "String_Node_Str"+ (prev != null ? prev.waitingVisible : null)+ "String_Node_Str"+ next.nowVisible);
      }
    }
  }
  if (prev != null) {
    if (prev.finishing) {
      if (DEBUG_TRANSITION)       Log.v(TAG,"String_Node_Str" + prev);
      mWindowManager.prepareAppTransition(prev.task == next.task ? WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE : WindowManagerPolicy.TRANSIT_TASK_CLOSE);
      mWindowManager.setAppWillBeHidden(prev);
      mWindowManager.setAppVisibility(prev,false);
    }
 else {
      if (DEBUG_TRANSITION)       Log.v(TAG,"String_Node_Str" + prev);
      mWindowManager.prepareAppTransition(prev.task == next.task ? WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN : WindowManagerPolicy.TRANSIT_TASK_OPEN);
    }
    if (false) {
      mWindowManager.setAppWillBeHidden(prev);
      mWindowManager.setAppVisibility(prev,false);
    }
  }
 else   if (mHistory.size() > 1) {
    if (DEBUG_TRANSITION)     Log.v(TAG,"String_Node_Str");
    mWindowManager.prepareAppTransition(WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN);
  }
  if (next.app != null && next.app.thread != null) {
    if (DEBUG_SWITCH)     Log.v(TAG,"String_Node_Str" + next);
    mWindowManager.setAppVisibility(next,true);
    HistoryRecord lastResumedActivity=mResumedActivity;
    ActivityState lastState=next.state;
    updateCpuStats();
    next.state=ActivityState.RESUMED;
    mResumedActivity=next;
    next.task.touchActiveTime();
    updateLRUListLocked(next.app,true);
    updateLRUListLocked(next);
    Configuration config=mWindowManager.updateOrientationFromAppTokens(mConfiguration,next.mayFreezeScreenLocked(next.app) ? next : null);
    if (config != null) {
      next.frozenBeforeDestroy=true;
    }
    if (!updateConfigurationLocked(config,next)) {
      HistoryRecord nextNext=topRunningActivityLocked(null);
      if (DEBUG_SWITCH)       Log.i(TAG,"String_Node_Str" + next + "String_Node_Str"+ nextNext);
      if (nextNext != next) {
        mHandler.sendEmptyMessage(RESUME_TOP_ACTIVITY_MSG);
      }
      mWindowManager.executeAppTransition();
      return true;
    }
    try {
      ArrayList a=next.results;
      if (a != null) {
        final int N=a.size();
        if (!next.finishing && N > 0) {
          if (DEBUG_RESULTS)           Log.v(TAG,"String_Node_Str" + next + "String_Node_Str"+ a);
          next.app.thread.scheduleSendResult(next,a);
        }
      }
      if (next.newIntents != null) {
        next.app.thread.scheduleNewIntent(next.newIntents,next);
      }
      EventLog.writeEvent(LOG_AM_RESUME_ACTIVITY,System.identityHashCode(next),next.task.taskId,next.shortComponentName);
      updateUsageStats(next,true);
      next.app.thread.scheduleResumeActivity(next,isNextTransitionForward());
      pauseIfSleepingLocked();
    }
 catch (    Exception e) {
      next.state=lastState;
      mResumedActivity=lastResumedActivity;
      if (Config.LOGD)       Log.d(TAG,"String_Node_Str" + next);
      if (!next.hasBeenLaunched) {
        next.hasBeenLaunched=true;
      }
 else {
        if (SHOW_APP_STARTING_ICON) {
          mWindowManager.setAppStartingWindow(next,next.packageName,next.theme,next.nonLocalizedLabel,next.labelRes,next.icon,null,true);
        }
      }
      startSpecificActivityLocked(next,true,false);
      return true;
    }
    try {
      next.visible=true;
      completeResumeLocked(next);
    }
 catch (    Exception e) {
      Log.w(TAG,"String_Node_Str" + next,e);
      requestFinishActivityLocked(next,Activity.RESULT_CANCELED,null,"String_Node_Str");
      return true;
    }
    next.icicle=null;
    next.haveState=false;
    next.stopped=false;
  }
 else {
    if (!next.hasBeenLaunched) {
      next.hasBeenLaunched=true;
    }
 else {
      if (SHOW_APP_STARTING_ICON) {
        mWindowManager.setAppStartingWindow(next,next.packageName,next.theme,next.nonLocalizedLabel,next.labelRes,next.icon,null,true);
      }
      if (DEBUG_SWITCH)       Log.v(TAG,"String_Node_Str" + next);
    }
    startSpecificActivityLocked(next,true,true);
  }
  return true;
}