Bug 1163245 - [Battery][Gonk] Implementation of battery discharging remaining time. r=dhylands

This commit is contained in:
Zibi Braniecki 2015-05-13 09:35:57 -07:00
Родитель 8bf8e3dc95
Коммит c29571c802
1 изменённых файлов: 32 добавлений и 1 удалений

Просмотреть файл

@ -632,6 +632,7 @@ GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo)
if (aBatteryInfo->charging() != previousCharging){
aBatteryInfo->remainingTime() = dom::battery::kUnknownRemainingTime;
memset(&lastLevelChange, 0, sizeof(struct timespec));
remainingTime = 0.0;
}
if (aBatteryInfo->charging()) {
@ -668,7 +669,37 @@ GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo)
}
} else {
aBatteryInfo->remainingTime() = dom::battery::kUnknownRemainingTime;
if (aBatteryInfo->level() == 0.0) {
aBatteryInfo->remainingTime() = dom::battery::kDefaultRemainingTime;
} else if (aBatteryInfo->level() != previousLevel){
if (lastLevelChange.tv_sec != 0) {
clock_gettime(CLOCK_MONOTONIC, &now);
dtime = now.tv_sec - lastLevelChange.tv_sec;
dlevel = previousLevel - aBatteryInfo->level();
if (dlevel <= 0.0) {
aBatteryInfo->remainingTime() = dom::battery::kUnknownRemainingTime;
} else {
remainingTime = (double) round(dtime / dlevel * aBatteryInfo->level());
aBatteryInfo->remainingTime() = remainingTime;
}
lastLevelChange = now;
} else { // lastLevelChange.tv_sec == 0
clock_gettime(CLOCK_MONOTONIC, &lastLevelChange);
aBatteryInfo->remainingTime() = dom::battery::kUnknownRemainingTime;
}
} else {
clock_gettime(CLOCK_MONOTONIC, &now);
dtime = now.tv_sec - lastLevelChange.tv_sec;
if (dtime < remainingTime) {
aBatteryInfo->remainingTime() = round(remainingTime - dtime);
} else {
aBatteryInfo->remainingTime() = dom::battery::kUnknownRemainingTime;
}
}
}
previousCharging = aBatteryInfo->charging();