Last Comment Bug 710178 - "ASSERTION: Battery API: When charging and level at 1.0, remaining time should be 0. Please fix your backend!"
: "ASSERTION: Battery API: When charging and level at 1.0, remaining time shoul...
Status: RESOLVED FIXED
: assertion
Product: Core
Classification: Components
Component: DOM (show other bugs)
: Trunk
: All All
: -- normal (vote)
: mozilla11
Assigned To: Makoto Kato [:m_kato]
:
: Andrew Overholt [:overholt]
Mentors:
Depends on:
Blocks: 707085
  Show dependency treegraph
 
Reported: 2011-12-13 04:28 PST by neil@parkwaycc.co.uk
Modified: 2011-12-19 05:44 PST (History)
5 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
fix (1.35 KB, patch)
2011-12-16 03:36 PST, Makoto Kato [:m_kato]
mounir: review+
Details | Diff | Splinter Review

Description neil@parkwaycc.co.uk 2011-12-13 04:28:06 PST
+++ This bug was initially created as a clone of Bug #707085 +++

Calling navigator.mozBattery triggers:

###!!! ASSERTION: Battery API: When charging and level at 1.0, remaining time should be 0. Please fix your backend!: 'Error', file dom/battery/BatteryManager.cpp, line 200

My Windows XP desktop has no battery.
Comment 1 Mounir Lamouri (:mounir) 2011-12-13 08:25:54 PST
Makoto, it seems that your code doesn't take into account situations were there is no battery. Can you check if there actually is a battery with the Windows API? In that case, you should file the structure with the default values like you do when there is no status.

I should have catch that in the review of the initial patch, I'm sorry :(

If you don't have time to work on that soon let me know, I will try to have a look.
Comment 2 Makoto Kato [:m_kato] 2011-12-13 20:22:57 PST
maybe, some environment always returns unknown (-1) for remain time.  We should check whether level is 1.0.
Comment 3 Mounir Lamouri (:mounir) 2011-12-14 02:09:09 PST
(In reply to Makoto Kato from comment #2)
> maybe, some environment always returns unknown (-1) for remain time.  We
> should check whether level is 1.0.

We could do that but I think the best solution would be to check if there is a battery in the device. On Linux, that information is easily available. Can't we get it on Windows?
Comment 4 Makoto Kato [:m_kato] 2011-12-16 03:35:40 PST
(In reply to Mounir Lamouri (:volkmar) (:mounir) from comment #3)
> (In reply to Makoto Kato from comment #2)
> > maybe, some environment always returns unknown (-1) for remain time.  We
> > should check whether level is 1.0.
> 
> We could do that but I think the best solution would be to check if there is
> a battery in the device. On Linux, that information is easily available.
> Can't we get it on Windows?

If no battery, we can check other member of SYSTEM_POWER_STATUS.  But it can return unknown, so we should check whether level is 1.0.   If API cannot return unknown, I think it is better.
Comment 5 Makoto Kato [:m_kato] 2011-12-16 03:36:32 PST
Created attachment 582233 [details] [diff] [review]
fix
Comment 6 Mounir Lamouri (:mounir) 2011-12-16 08:17:33 PST
Comment on attachment 582233 [details] [diff] [review]
fix

Review of attachment 582233 [details] [diff] [review]:
-----------------------------------------------------------------

r=me with the change.

Thank you for the quick fix :)

::: hal/windows/WindowsBattery.cpp
@@ +224,5 @@
>    if (status.ACLineStatus != 0) {
> +    if (aBattryInfo->level() == 1.0) {
> +      // GetSystemPowerStatus API may returns -1 for BatteryFullLifeTime.
> +      // So, if battery is 100%, set 0 at force.
> +      aBatteryInfo->remainingTime() = 0;

Please use kDefaultRemainingTime instead of 0.
Comment 8 Marco Bonardo [::mak] 2011-12-19 05:44:16 PST
https://hg.mozilla.org/mozilla-central/rev/5efce975a9e7

Note You need to log in before you can comment on or make changes to this bug.