Program: 193040
Project: 193040
Buggy source:
private void completePauseLocked(boolean resumeNext){
  ActivityRecord prev=mPausingActivity;
  if (DEBUG_PAUSE)   Slog.v(TAG_PAUSE,"String_Node_Str" + prev);
  if (prev != null) {
    final boolean wasStopping=prev.state == ActivityState.STOPPING;
    prev.state=ActivityState.PAUSED;
    if (prev.finishing) {
      if (DEBUG_PAUSE)       Slog.v(TAG_PAUSE,"String_Node_Str" + prev);
      prev=finishCurrentActivityLocked(prev,FINISH_AFTER_VISIBLE,false);
    }
 else     if (prev.app != null) {
      if (DEBUG_PAUSE)       Slog.v(TAG_PAUSE,"String_Node_Str" + prev);
      if (mStackSupervisor.mWaitingVisibleActivities.remove(prev)) {
        if (DEBUG_SWITCH || DEBUG_PAUSE)         Slog.v(TAG_PAUSE,"String_Node_Str" + prev);
      }
      if (prev.configDestroy) {
        if (DEBUG_PAUSE)         Slog.v(TAG_PAUSE,"String_Node_Str" + prev);
        destroyActivityLocked(prev,true,"String_Node_Str");
      }
 else       if (wasStopping) {
        prev.state=ActivityState.STOPPING;
      }
 else       if (!hasVisibleBehindActivity() || mService.isSleepingOrShuttingDown()) {
        addToStopping(prev);
      }
    }
 else {
      if (DEBUG_PAUSE)       Slog.v(TAG_PAUSE,"String_Node_Str" + prev);
      prev=null;
    }
    prev.stopFreezingScreenLocked(true);
    mPausingActivity=null;
  }
  if (resumeNext) {
    final ActivityStack topStack=mStackSupervisor.getFocusedStack();
    if (!mService.isSleepingOrShuttingDown()) {
      mStackSupervisor.resumeFocusedStackTopActivityLocked(topStack,prev,null);
    }
 else {
      mStackSupervisor.checkReadyForSleepLocked();
      ActivityRecord top=topStack.topRunningActivityLocked();
      if (top == null || (prev != null && top != prev)) {
        mStackSupervisor.resumeFocusedStackTopActivityLocked();
      }
    }
  }
  if (prev != null) {
    prev.resumeKeyDispatchingLocked();
    if (prev.app != null && prev.cpuTimeAtResume > 0 && mService.mBatteryStatsService.isOnBattery()) {
      long diff=mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid) - prev.cpuTimeAtResume;
      if (diff > 0) {
        BatteryStatsImpl bsi=mService.mBatteryStatsService.getActiveStatistics();
synchronized (bsi) {
          BatteryStatsImpl.Uid.Proc ps=bsi.getProcessStatsLocked(prev.info.applicationInfo.uid,prev.info.packageName);
          if (ps != null) {
            ps.addForegroundTimeLocked(diff);
          }
        }
      }
    }
    prev.cpuTimeAtResume=0;
  }
  mService.notifyTaskStackChangedLocked();
}

Fixed version (ground truth):
private void completePauseLocked(boolean resumeNext){
  ActivityRecord prev=mPausingActivity;
  if (DEBUG_PAUSE)   Slog.v(TAG_PAUSE,"String_Node_Str" + prev);
  if (prev != null) {
    final boolean wasStopping=prev.state == ActivityState.STOPPING;
    prev.state=ActivityState.PAUSED;
    if (prev.finishing) {
      if (DEBUG_PAUSE)       Slog.v(TAG_PAUSE,"String_Node_Str" + prev);
      prev=finishCurrentActivityLocked(prev,FINISH_AFTER_VISIBLE,false);
    }
 else     if (prev.app != null) {
      if (DEBUG_PAUSE)       Slog.v(TAG_PAUSE,"String_Node_Str" + prev);
      if (mStackSupervisor.mWaitingVisibleActivities.remove(prev)) {
        if (DEBUG_SWITCH || DEBUG_PAUSE)         Slog.v(TAG_PAUSE,"String_Node_Str" + prev);
      }
      if (prev.deferRelaunchUntilPaused) {
        if (DEBUG_PAUSE)         Slog.v(TAG_PAUSE,"String_Node_Str" + prev);
        relaunchActivityLocked(prev,prev.configChangeFlags,false,prev.preserveWindowOnDeferredRelaunch);
      }
 else       if (wasStopping) {
        prev.state=ActivityState.STOPPING;
      }
 else       if (!hasVisibleBehindActivity() || mService.isSleepingOrShuttingDown()) {
        addToStopping(prev);
      }
    }
 else {
      if (DEBUG_PAUSE)       Slog.v(TAG_PAUSE,"String_Node_Str" + prev);
      prev=null;
    }
    prev.stopFreezingScreenLocked(true);
    mPausingActivity=null;
  }
  if (resumeNext) {
    final ActivityStack topStack=mStackSupervisor.getFocusedStack();
    if (!mService.isSleepingOrShuttingDown()) {
      mStackSupervisor.resumeFocusedStackTopActivityLocked(topStack,prev,null);
    }
 else {
      mStackSupervisor.checkReadyForSleepLocked();
      ActivityRecord top=topStack.topRunningActivityLocked();
      if (top == null || (prev != null && top != prev)) {
        mStackSupervisor.resumeFocusedStackTopActivityLocked();
      }
    }
  }
  if (prev != null) {
    prev.resumeKeyDispatchingLocked();
    if (prev.app != null && prev.cpuTimeAtResume > 0 && mService.mBatteryStatsService.isOnBattery()) {
      long diff=mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid) - prev.cpuTimeAtResume;
      if (diff > 0) {
        BatteryStatsImpl bsi=mService.mBatteryStatsService.getActiveStatistics();
synchronized (bsi) {
          BatteryStatsImpl.Uid.Proc ps=bsi.getProcessStatsLocked(prev.info.applicationInfo.uid,prev.info.packageName);
          if (ps != null) {
            ps.addForegroundTimeLocked(diff);
          }
        }
      }
    }
    prev.cpuTimeAtResume=0;
  }
  mService.notifyTaskStackChangedLocked();
}