Program: 23920
Project: 23920
Buggy source:
private synchronized final void update(){
  native_update();
  boolean logOutlier=false;
  long dischargeDuration=0;
  if (mBatteryLevel == 0 && isPowered(0xffffffff)) {
    ShutdownThread.shutdown(mContext,false);
  }
  mBatteryLevelCritical=mBatteryLevel <= CRITICAL_BATTERY_LEVEL;
  if (mAcOnline) {
    mPlugType=BatteryManager.BATTERY_PLUGGED_AC;
  }
 else   if (mUsbOnline) {
    mPlugType=BatteryManager.BATTERY_PLUGGED_USB;
  }
 else {
    mPlugType=BATTERY_PLUGGED_NONE;
  }
  if (mBatteryStatus != mLastBatteryStatus || mBatteryHealth != mLastBatteryHealth || mBatteryPresent != mLastBatteryPresent || mBatteryLevel != mLastBatteryLevel || mPlugType != mLastPlugType || mBatteryVoltage != mLastBatteryVoltage || mBatteryTemperature != mLastBatteryTemperature) {
    if (mPlugType != mLastPlugType) {
      if (mLastPlugType == BATTERY_PLUGGED_NONE) {
        if (mDischargeStartTime != 0 && mDischargeStartLevel != mBatteryLevel) {
          dischargeDuration=SystemClock.elapsedRealtime() - mDischargeStartTime;
          logOutlier=true;
          EventLog.writeEvent(LOG_BATTERY_DISCHARGE_STATUS,dischargeDuration,mDischargeStartLevel,mBatteryLevel);
          mDischargeStartTime=0;
        }
      }
 else       if (mPlugType == BATTERY_PLUGGED_NONE) {
        mDischargeStartTime=SystemClock.elapsedRealtime();
        mDischargeStartLevel=mBatteryLevel;
      }
    }
    if (mBatteryStatus != mLastBatteryStatus || mBatteryHealth != mLastBatteryHealth || mBatteryPresent != mLastBatteryPresent || mPlugType != mLastPlugType) {
      EventLog.writeEvent(LOG_BATTERY_STATUS,mBatteryStatus,mBatteryHealth,mBatteryPresent ? 1 : 0,mPlugType,mBatteryTechnology);
    }
    if (mBatteryLevel != mLastBatteryLevel || mBatteryVoltage != mLastBatteryVoltage || mBatteryTemperature != mLastBatteryTemperature) {
      EventLog.writeEvent(LOG_BATTERY_LEVEL,mBatteryLevel,mBatteryVoltage,mBatteryTemperature);
    }
    if (mBatteryLevel != mLastBatteryLevel && mPlugType == BATTERY_PLUGGED_NONE) {
      try {
        mBatteryStats.recordCurrentLevel(mBatteryLevel);
      }
 catch (      RemoteException e) {
      }
    }
    if (mBatteryLevelCritical && !mLastBatteryLevelCritical && mPlugType == BATTERY_PLUGGED_NONE) {
      dischargeDuration=SystemClock.elapsedRealtime() - mDischargeStartTime;
      logOutlier=true;
    }
    Intent statusIntent=new Intent();
    statusIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
    if (mPlugType != 0 && mLastPlugType == 0) {
      statusIntent.setAction(Intent.ACTION_POWER_CONNECTED);
      mContext.sendBroadcast(statusIntent);
    }
 else     if (mPlugType == 0 && mLastPlugType != 0) {
      statusIntent.setAction(Intent.ACTION_POWER_DISCONNECTED);
      mContext.sendBroadcast(statusIntent);
    }
    final boolean plugged=mPlugType != BATTERY_PLUGGED_NONE;
    final boolean oldPlugged=mLastPlugType != BATTERY_PLUGGED_NONE;
    final boolean sendBatteryLow=!plugged && mBatteryStatus != BatteryManager.BATTERY_STATUS_UNKNOWN && mBatteryLevel < BATTERY_LEVEL_WARNING && (oldPlugged || mLastBatteryLevel >= BATTERY_LEVEL_WARNING);
    mLastBatteryStatus=mBatteryStatus;
    mLastBatteryHealth=mBatteryHealth;
    mLastBatteryPresent=mBatteryPresent;
    mLastBatteryLevel=mBatteryLevel;
    mLastPlugType=mPlugType;
    mLastBatteryVoltage=mBatteryVoltage;
    mLastBatteryTemperature=mBatteryTemperature;
    mLastBatteryLevelCritical=mBatteryLevelCritical;
    sendIntent();
    if (sendBatteryLow) {
      mSentLowBatteryBroadcast=true;
      statusIntent.setAction(Intent.ACTION_BATTERY_LOW);
      mContext.sendBroadcast(statusIntent);
    }
 else     if (mSentLowBatteryBroadcast && mLastBatteryLevel >= BATTERY_LEVEL_CLOSE_WARNING) {
      mSentLowBatteryBroadcast=false;
      statusIntent.setAction(Intent.ACTION_BATTERY_OKAY);
      mContext.sendBroadcast(statusIntent);
    }
    if (logOutlier && dischargeDuration != 0) {
      logOutlier(dischargeDuration);
    }
  }
}

Fixed version (ground truth):
private synchronized final void update(){
  native_update();
  boolean logOutlier=false;
  long dischargeDuration=0;
  shutdownIfNoPower();
  mBatteryLevelCritical=mBatteryLevel <= CRITICAL_BATTERY_LEVEL;
  if (mAcOnline) {
    mPlugType=BatteryManager.BATTERY_PLUGGED_AC;
  }
 else   if (mUsbOnline) {
    mPlugType=BatteryManager.BATTERY_PLUGGED_USB;
  }
 else {
    mPlugType=BATTERY_PLUGGED_NONE;
  }
  if (mBatteryStatus != mLastBatteryStatus || mBatteryHealth != mLastBatteryHealth || mBatteryPresent != mLastBatteryPresent || mBatteryLevel != mLastBatteryLevel || mPlugType != mLastPlugType || mBatteryVoltage != mLastBatteryVoltage || mBatteryTemperature != mLastBatteryTemperature) {
    if (mPlugType != mLastPlugType) {
      if (mLastPlugType == BATTERY_PLUGGED_NONE) {
        if (mDischargeStartTime != 0 && mDischargeStartLevel != mBatteryLevel) {
          dischargeDuration=SystemClock.elapsedRealtime() - mDischargeStartTime;
          logOutlier=true;
          EventLog.writeEvent(LOG_BATTERY_DISCHARGE_STATUS,dischargeDuration,mDischargeStartLevel,mBatteryLevel);
          mDischargeStartTime=0;
        }
      }
 else       if (mPlugType == BATTERY_PLUGGED_NONE) {
        mDischargeStartTime=SystemClock.elapsedRealtime();
        mDischargeStartLevel=mBatteryLevel;
      }
    }
    if (mBatteryStatus != mLastBatteryStatus || mBatteryHealth != mLastBatteryHealth || mBatteryPresent != mLastBatteryPresent || mPlugType != mLastPlugType) {
      EventLog.writeEvent(LOG_BATTERY_STATUS,mBatteryStatus,mBatteryHealth,mBatteryPresent ? 1 : 0,mPlugType,mBatteryTechnology);
    }
    if (mBatteryLevel != mLastBatteryLevel || mBatteryVoltage != mLastBatteryVoltage || mBatteryTemperature != mLastBatteryTemperature) {
      EventLog.writeEvent(LOG_BATTERY_LEVEL,mBatteryLevel,mBatteryVoltage,mBatteryTemperature);
    }
    if (mBatteryLevel != mLastBatteryLevel && mPlugType == BATTERY_PLUGGED_NONE) {
      try {
        mBatteryStats.recordCurrentLevel(mBatteryLevel);
      }
 catch (      RemoteException e) {
      }
    }
    if (mBatteryLevelCritical && !mLastBatteryLevelCritical && mPlugType == BATTERY_PLUGGED_NONE) {
      dischargeDuration=SystemClock.elapsedRealtime() - mDischargeStartTime;
      logOutlier=true;
    }
    Intent statusIntent=new Intent();
    statusIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
    if (mPlugType != 0 && mLastPlugType == 0) {
      statusIntent.setAction(Intent.ACTION_POWER_CONNECTED);
      mContext.sendBroadcast(statusIntent);
    }
 else     if (mPlugType == 0 && mLastPlugType != 0) {
      statusIntent.setAction(Intent.ACTION_POWER_DISCONNECTED);
      mContext.sendBroadcast(statusIntent);
    }
    final boolean plugged=mPlugType != BATTERY_PLUGGED_NONE;
    final boolean oldPlugged=mLastPlugType != BATTERY_PLUGGED_NONE;
    final boolean sendBatteryLow=!plugged && mBatteryStatus != BatteryManager.BATTERY_STATUS_UNKNOWN && mBatteryLevel < BATTERY_LEVEL_WARNING && (oldPlugged || mLastBatteryLevel >= BATTERY_LEVEL_WARNING);
    mLastBatteryStatus=mBatteryStatus;
    mLastBatteryHealth=mBatteryHealth;
    mLastBatteryPresent=mBatteryPresent;
    mLastBatteryLevel=mBatteryLevel;
    mLastPlugType=mPlugType;
    mLastBatteryVoltage=mBatteryVoltage;
    mLastBatteryTemperature=mBatteryTemperature;
    mLastBatteryLevelCritical=mBatteryLevelCritical;
    sendIntent();
    if (sendBatteryLow) {
      mSentLowBatteryBroadcast=true;
      statusIntent.setAction(Intent.ACTION_BATTERY_LOW);
      mContext.sendBroadcast(statusIntent);
    }
 else     if (mSentLowBatteryBroadcast && mLastBatteryLevel >= BATTERY_LEVEL_CLOSE_WARNING) {
      mSentLowBatteryBroadcast=false;
      statusIntent.setAction(Intent.ACTION_BATTERY_OKAY);
      mContext.sendBroadcast(statusIntent);
    }
    if (logOutlier && dischargeDuration != 0) {
      logOutlier(dischargeDuration);
    }
  }
}