Program: 182290
Project: 182290
Buggy source:
final void updateLocked(){
  long ident=Binder.clearCallingIdentity();
  try {
    String action=null;
    String oldAction=null;
    if (mLastBroadcastState == Intent.EXTRA_DOCK_STATE_CAR) {
      oldAction=UiModeManager.ACTION_EXIT_CAR_MODE;
    }
 else     if (mLastBroadcastState == Intent.EXTRA_DOCK_STATE_DESK) {
      oldAction=UiModeManager.ACTION_EXIT_DESK_MODE;
    }
    if (mCarModeEnabled) {
      if (mLastBroadcastState != Intent.EXTRA_DOCK_STATE_CAR) {
        adjustStatusBarCarModeLocked();
        if (oldAction != null) {
          mContext.sendBroadcast(new Intent(oldAction));
        }
        mLastBroadcastState=Intent.EXTRA_DOCK_STATE_CAR;
        action=UiModeManager.ACTION_ENTER_CAR_MODE;
      }
    }
 else     if (mDockState == Intent.EXTRA_DOCK_STATE_DESK) {
      if (mLastBroadcastState != Intent.EXTRA_DOCK_STATE_DESK) {
        if (oldAction != null) {
          mContext.sendBroadcast(new Intent(oldAction));
        }
        mLastBroadcastState=Intent.EXTRA_DOCK_STATE_DESK;
        action=UiModeManager.ACTION_ENTER_DESK_MODE;
      }
    }
 else {
      if (mLastBroadcastState == Intent.EXTRA_DOCK_STATE_CAR) {
        adjustStatusBarCarModeLocked();
      }
      mLastBroadcastState=Intent.EXTRA_DOCK_STATE_UNDOCKED;
      action=oldAction;
    }
    if (action != null) {
      mContext.sendOrderedBroadcast(new Intent(action),null,mResultReceiver,null,Activity.RESULT_OK,null,null);
      mHoldingConfiguration=true;
    }
    updateConfigurationLocked();
    boolean keepScreenOn=mCharging && ((mCarModeEnabled && mCarModeKeepsScreenOn) || (mCurUiMode == Configuration.UI_MODE_TYPE_DESK && mDeskModeKeepsScreenOn));
    if (keepScreenOn != mWakeLock.isHeld()) {
      if (keepScreenOn) {
        mWakeLock.acquire();
      }
 else {
        mWakeLock.release();
      }
    }
  }
  finally {
    Binder.restoreCallingIdentity(ident);
  }
}

Fixed version (ground truth):
final void updateLocked(){
  long ident=Binder.clearCallingIdentity();
  try {
    String action=null;
    String oldAction=null;
    if (mLastBroadcastState == Intent.EXTRA_DOCK_STATE_CAR) {
      adjustStatusBarCarModeLocked();
      oldAction=UiModeManager.ACTION_EXIT_CAR_MODE;
    }
 else     if (mLastBroadcastState == Intent.EXTRA_DOCK_STATE_DESK) {
      oldAction=UiModeManager.ACTION_EXIT_DESK_MODE;
    }
    if (mCarModeEnabled) {
      if (mLastBroadcastState != Intent.EXTRA_DOCK_STATE_CAR) {
        adjustStatusBarCarModeLocked();
        if (oldAction != null) {
          mContext.sendBroadcast(new Intent(oldAction));
        }
        mLastBroadcastState=Intent.EXTRA_DOCK_STATE_CAR;
        action=UiModeManager.ACTION_ENTER_CAR_MODE;
      }
    }
 else     if (mDockState == Intent.EXTRA_DOCK_STATE_DESK) {
      if (mLastBroadcastState != Intent.EXTRA_DOCK_STATE_DESK) {
        if (oldAction != null) {
          mContext.sendBroadcast(new Intent(oldAction));
        }
        mLastBroadcastState=Intent.EXTRA_DOCK_STATE_DESK;
        action=UiModeManager.ACTION_ENTER_DESK_MODE;
      }
    }
 else {
      mLastBroadcastState=Intent.EXTRA_DOCK_STATE_UNDOCKED;
      action=oldAction;
    }
    if (action != null) {
      mContext.sendOrderedBroadcast(new Intent(action),null,mResultReceiver,null,Activity.RESULT_OK,null,null);
      mHoldingConfiguration=true;
    }
    updateConfigurationLocked();
    boolean keepScreenOn=mCharging && ((mCarModeEnabled && mCarModeKeepsScreenOn) || (mCurUiMode == Configuration.UI_MODE_TYPE_DESK && mDeskModeKeepsScreenOn));
    if (keepScreenOn != mWakeLock.isHeld()) {
      if (keepScreenOn) {
        mWakeLock.acquire();
      }
 else {
        mWakeLock.release();
      }
    }
  }
  finally {
    Binder.restoreCallingIdentity(ident);
  }
}