cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter (JIRA)" <>
Subject [jira] [Created] (CB-4519) "batterylow" and "batterycritical" may never happen because of exact level check
Date Wed, 07 Aug 2013 04:29:48 GMT
Peter created CB-4519:

             Summary: "batterylow" and "batterycritical" may never happen because of exact
level check
                 Key: CB-4519
             Project: Apache Cordova
          Issue Type: Bug
          Components: CordovaJS, Plugin Battery Status
    Affects Versions: 2.9.0
            Reporter: Peter
            Assignee: Filip Maj

The battery JavaScript code fires events when charge reaches some threshold percentages 20
and 5:
if (level === 20 || level === 5) {
    if (level === 20) {
        cordova.fireWindowEvent("batterylow", info);
    else {
        cordova.fireWindowEvent("batterycritical", info);

But this logic makes an assumption that the level will at some point be *exactly* 20 or 5.
It is not a valid assumption. AFAIK there is no guarantee that the device reports absolutely
every percentage point 0-100, so if by bad luck the device reports levels 25,22,19,16... then
clearly level===20 was missed so in this scenario the "batterylow" event the user was expecting
is simply not going to happen. 


IMO the code should be checking when the previous lvel versus current level has crossed over
the threshold, rather checking the current level is exactly equal to the threshold value.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message