You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "ASF subversion and git services (JIRA)" <ji...@apache.org> on 2014/05/15 02:13:22 UTC
[jira] [Commented] (CB-4519) "batterylow" and "batterycritical" may
never happen because of exact level check
[ https://issues.apache.org/jira/browse/CB-4519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13998299#comment-13998299 ]
ASF subversion and git services commented on CB-4519:
-----------------------------------------------------
Commit 9821813a4ed4d1cc9af1341763e0adc9d8a0a12d in cordova-plugin-battery-status's branch refs/heads/master from [~purplecabbage]
[ https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-battery-status.git;h=9821813 ]
CB-4519, CB-4520 low+critical weren't firing when level went from 21->19, and were when level went 19->20
> "batterylow" and "batterycritical" may never happen because of exact level check
> --------------------------------------------------------------------------------
>
> Key: CB-4519
> URL: https://issues.apache.org/jira/browse/CB-4519
> Project: Apache Cordova
> Issue Type: Bug
> Components: CordovaJS, Plugin Battery Status
> Affects Versions: 2.9.0
> Reporter: Peter
> Assignee: Jesse MacFadyen
>
> The battery JavaScript code fires events when charge reaches some threshold percentages 20 and 5:
> {code}
> if (level === 20 || level === 5) {
> if (level === 20) {
> cordova.fireWindowEvent("batterylow", info);
> }
> else {
> cordova.fireWindowEvent("batterycritical", info);
> }
> }
> {code}
> 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.
> Ref http://stackoverflow.com/questions/10189218/detect-changing-battery-state-at-every-percentage-in-android
> 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 was sent by Atlassian JIRA
(v6.2#6252)