Merge "Improve the logic to determine the idle mode"