livedisplay: Fix endless loop for devices that don't support outdoor

mode.

There was a logic mistake that caused _all_ modes to be skipped if
outdoor mode isn't supported. In order to avoid such mistakes in the
future, also simplify the logic and make it more easily understandable.

Change-Id: I5fe8edbb3c4d2dd05fc4b4a7f94ca05d4ecd408b
This commit is contained in:
Danny Baumann 2016-04-15 11:58:59 +02:00
parent 7cd7f79c75
commit 842344a358
1 changed files with 18 additions and 11 deletions

View File

@ -235,24 +235,31 @@ public class LiveDisplayService extends SystemService {
next = 0;
}
int nextMode = 0;
int nextMode;
while (true) {
nextMode = Integer.valueOf(mTileValues[next]);
// Skip outdoor mode if it's unsupported, and skip the day setting
// if it's the same as the off setting
if (((!mConfig.hasFeature(MODE_OUTDOOR) ||
mConfig.hasFeature(FEATURE_MANAGED_OUTDOOR_MODE)
&& nextMode == MODE_OUTDOOR)) ||
(mCTC.getDayColorTemperature() == mConfig.getDefaultDayTemperature()
&& nextMode == MODE_DAY)) {
next++;
if (next >= mTileValues.length) {
next = 0;
if (nextMode == MODE_OUTDOOR) {
// Only accept outdoor mode if it's supported by the hardware
if (mConfig.hasFeature(MODE_OUTDOOR)
&& !mConfig.hasFeature(FEATURE_MANAGED_OUTDOOR_MODE)) {
break;
}
} else if (nextMode == MODE_DAY) {
// Skip the day setting if it's the same as the off setting
if (mCTC.getDayColorTemperature() != mConfig.getDefaultDayTemperature()) {
break;
}
} else {
// every other mode doesn't have any preconstraints
break;
}
// If we come here, we decided to skip the mode
next++;
if (next >= mTileValues.length) {
next = 0;
}
}
return nextMode;