зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1163245 - [Battery][Gonk] Implementation of battery discharging remaining time. r=dhylands
This commit is contained in:
Родитель
8bf8e3dc95
Коммит
c29571c802
|
@ -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();
|
||||
|
|
Загрузка…
Ссылка в новой задаче