Program: 192428
Project: 192428
Buggy source:
public void noteDeviceIdleModeLocked(int mode,String activeReason,int activeUid){
  final long elapsedRealtime=mClocks.elapsedRealtime();
  final long uptime=mClocks.uptimeMillis();
  boolean nowIdling=mode == DEVICE_IDLE_MODE_FULL;
  if (mDeviceIdling && !nowIdling && activeReason == null) {
    nowIdling=true;
  }
  boolean nowLightIdling=mode == DEVICE_IDLE_MODE_LIGHT;
  if (mDeviceLightIdling && !nowLightIdling && !nowIdling&& activeReason == null) {
    nowLightIdling=true;
  }
  if (activeReason != null && (mDeviceIdling || mDeviceLightIdling)) {
    addHistoryEventLocked(elapsedRealtime,uptime,HistoryItem.EVENT_ACTIVE,activeReason,activeUid);
  }
  if (mDeviceIdling != nowIdling) {
    mDeviceIdling=nowIdling;
    int stepState=nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0;
    mModStepMode|=(mCurStepMode & STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState;
    mCurStepMode=(mCurStepMode & ~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState;
    if (nowIdling) {
      mDeviceIdlingTimer.startRunningLocked(elapsedRealtime);
    }
 else {
      mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime);
    }
  }
  if (mDeviceLightIdling != nowLightIdling) {
    mDeviceLightIdling=nowLightIdling;
    if (nowLightIdling) {
      mDeviceLightIdlingTimer.startRunningLocked(elapsedRealtime);
    }
 else {
      mDeviceLightIdlingTimer.stopRunningLocked(elapsedRealtime);
    }
  }
  if (mDeviceIdleMode != mode) {
    mHistoryCur.states2=(mHistoryCur.states2 & ~HistoryItem.STATE2_DEVICE_IDLE_MASK) | (mode << HistoryItem.STATE2_DEVICE_IDLE_SHIFT);
    if (DEBUG_HISTORY)     Slog.v(TAG,"String_Node_Str" + Integer.toHexString(mHistoryCur.states2));
    addHistoryRecordLocked(elapsedRealtime,uptime);
    long lastDuration=elapsedRealtime - mLastIdleTimeStart;
    mLastIdleTimeStart=elapsedRealtime;
    if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) {
      if (lastDuration > mLongestLightIdleTime) {
        mLongestLightIdleTime=lastDuration;
      }
      mDeviceIdleModeLightTimer.stopRunningLocked(elapsedRealtime);
    }
 else     if (mDeviceIdleMode == DEVICE_IDLE_MODE_FULL) {
      if (lastDuration > mLongestFullIdleTime) {
        mLongestFullIdleTime=lastDuration;
      }
      mDeviceIdleModeFullTimer.stopRunningLocked(elapsedRealtime);
    }
    if (mode == DEVICE_IDLE_MODE_LIGHT) {
      mDeviceIdleModeLightTimer.startRunningLocked(elapsedRealtime);
    }
 else     if (mode == DEVICE_IDLE_MODE_FULL) {
      mDeviceIdleModeFullTimer.startRunningLocked(elapsedRealtime);
    }
    mDeviceIdleMode=mode;
  }
}

Fixed version (ground truth):
public void noteDeviceIdleModeLocked(int mode,String activeReason,int activeUid){
  final long elapsedRealtime=mClocks.elapsedRealtime();
  final long uptime=mClocks.uptimeMillis();
  boolean nowIdling=mode == DEVICE_IDLE_MODE_DEEP;
  if (mDeviceIdling && !nowIdling && activeReason == null) {
    nowIdling=true;
  }
  boolean nowLightIdling=mode == DEVICE_IDLE_MODE_LIGHT;
  if (mDeviceLightIdling && !nowLightIdling && !nowIdling&& activeReason == null) {
    nowLightIdling=true;
  }
  if (activeReason != null && (mDeviceIdling || mDeviceLightIdling)) {
    addHistoryEventLocked(elapsedRealtime,uptime,HistoryItem.EVENT_ACTIVE,activeReason,activeUid);
  }
  if (mDeviceIdling != nowIdling) {
    mDeviceIdling=nowIdling;
    int stepState=nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0;
    mModStepMode|=(mCurStepMode & STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState;
    mCurStepMode=(mCurStepMode & ~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState;
    if (nowIdling) {
      mDeviceIdlingTimer.startRunningLocked(elapsedRealtime);
    }
 else {
      mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime);
    }
  }
  if (mDeviceLightIdling != nowLightIdling) {
    mDeviceLightIdling=nowLightIdling;
    if (nowLightIdling) {
      mDeviceLightIdlingTimer.startRunningLocked(elapsedRealtime);
    }
 else {
      mDeviceLightIdlingTimer.stopRunningLocked(elapsedRealtime);
    }
  }
  if (mDeviceIdleMode != mode) {
    mHistoryCur.states2=(mHistoryCur.states2 & ~HistoryItem.STATE2_DEVICE_IDLE_MASK) | (mode << HistoryItem.STATE2_DEVICE_IDLE_SHIFT);
    if (DEBUG_HISTORY)     Slog.v(TAG,"String_Node_Str" + Integer.toHexString(mHistoryCur.states2));
    addHistoryRecordLocked(elapsedRealtime,uptime);
    long lastDuration=elapsedRealtime - mLastIdleTimeStart;
    mLastIdleTimeStart=elapsedRealtime;
    if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) {
      if (lastDuration > mLongestLightIdleTime) {
        mLongestLightIdleTime=lastDuration;
      }
      mDeviceIdleModeLightTimer.stopRunningLocked(elapsedRealtime);
    }
 else     if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) {
      if (lastDuration > mLongestFullIdleTime) {
        mLongestFullIdleTime=lastDuration;
      }
      mDeviceIdleModeFullTimer.stopRunningLocked(elapsedRealtime);
    }
    if (mode == DEVICE_IDLE_MODE_LIGHT) {
      mDeviceIdleModeLightTimer.startRunningLocked(elapsedRealtime);
    }
 else     if (mode == DEVICE_IDLE_MODE_DEEP) {
      mDeviceIdleModeFullTimer.startRunningLocked(elapsedRealtime);
    }
    mDeviceIdleMode=mode;
  }
}