The default bug view has changed. See this FAQ.

Not getting Battery API charging events when plugging device into mains power

RESOLVED FIXED in mozilla13

Status

()

Core
DOM
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: benfrancis, Assigned: benfrancis)

Tracking

Trunk
mozilla13
ARM
Gonk (Firefox OS)
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [mentor=mounir][lang=c++])

Attachments

(1 attachment, 2 obsolete attachments)

(Assignee)

Description

5 years ago
STR:

1. Plug Samsung Galaxy SII flashed with latest B2G & Gaia into wall charger (not USB charger)

Expected: Charging indicator changes to charging state

Actual: No change

Works fine when charging via USB.

See https://github.com/andreasgal/gaia/issues/393 for original bug report.
Interesting!  The driver probably reports a state we don't understand.
Whiteboard: [good first bug]

Comment 2

5 years ago
Feel free to redirect mentorship to someone else, Mounir.
Whiteboard: [good first bug] → [mentor=mounir][lang=c++]
Ben, by any chance, can you tell me what's in this file when your phone is plugged into a wall charger:
/sys/class/power_supply/battery/charging_source
Also, on an akami device, we don't have battery/charging_source at all.

ls /sys/class/power_supply/battery :
uevent
subsystem
device
status
health
present
technology
voltage_max_design
voltage_min_design
voltage_now
capacity
type
power
(Assignee)

Comment 5

5 years ago
On Mon, Feb 13, 2012 at 9:57 PM, <bugzilla-daemon@mozilla.org> wrote:
--- Comment #3 from Mounir Lamouri (:volkmar) (:mounir) <mounir@lamouri.fr> 2012-02-13 13:57:07 PST ---
> Ben, by any chance, can you tell me what's in this file when your phone is
> plugged into a wall charger:
> /sys/class/power_supply/battery/charging_source

OK, dumb question. How can I look inside that file while the device is plugged into the mains, and not USB?
(In reply to Ben Francis from comment #5)
> On Mon, Feb 13, 2012 at 9:57 PM, <bugzilla-daemon@mozilla.org> wrote:
> --- Comment #3 from Mounir Lamouri (:volkmar) (:mounir) <mounir@lamouri.fr>
> 2012-02-13 13:57:07 PST ---
> > Ben, by any chance, can you tell me what's in this file when your phone is
> > plugged into a wall charger:
> > /sys/class/power_supply/battery/charging_source
> 
> OK, dumb question. How can I look inside that file while the device is
> plugged into the mains, and not USB?

Oh indeed, there is no way to do that on B2G... Can you try to plug it to your wall and to USB and see if the bug happens?
Oups, forget that last comment...
(Assignee)

Comment 8

5 years ago
OK, I added a line of C++ to log the contents of charging_source (go me!) and it appears when you plug the device into the mains, you get 2 instead of 1 which is what you get when charging via USB, the event only fires for 1.
(Assignee)

Comment 9

5 years ago
Created attachment 596982 [details] [diff] [review]
Charging source can be anything greater than zero to indicate charging, not just 1
Assignee: nobody → ben
Status: NEW → ASSIGNED
Comment on attachment 596982 [details] [diff] [review]
Charging source can be anything greater than zero to indicate charging, not just 1

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

I don't like that solution. I would prefer if you could create three constants:
static const int BATTERY_NOT_CHARGING = 0;
static const int BATTERY_CHARGING_USB = 1;
static const int BATTERY_CHARGING_AC  = 2;

Then, you could do:
  aBatteryInfo->charging() = (chargingSrc == BATTERY_CHARGING_USB || chargingSrc == BATTERY_CHARGING_AC);

And you could add a check when in DEBUG that would verify if chargingSrc is equal to one of those three values. If not, it will print the value in the logs.
Attachment #596982 - Flags: review-
adb will talk TCP.  You can connect to the phone through wifi.  (If you have wifi working ...)
(Assignee)

Comment 12

5 years ago
Created attachment 597029 [details] [diff] [review]
Charging when charging source is 1 or 2, not charging when 0. Log anything else when in DEBUG.

Changes to address Mounir's review. Feel free to re-write this if there are further changes you'd like, C++ is not my lingua franca :)
Attachment #596982 - Attachment is obsolete: true
Comment on attachment 597029 [details] [diff] [review]
Charging when charging source is 1 or 2, not charging when 0. Log anything else when in DEBUG.

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

r=me with the nits fixed

::: hal/gonk/GonkHal.cpp
@@ +284,5 @@
>  
> +  #ifdef DEBUG
> +  if (!(chargingSrc == BATTERY_NOT_CHARGING ||
> +    chargingSrc == BATTERY_CHARGING_USB || 
> +    chargingSrc == BATTERY_CHARGING_AC)) {

I would prefer if (foo != a && foo != b [...]) {
But you can disagree.

Though, you should fix the indentation to:
if (something ||
    somethingElse) {

@@ +293,3 @@
>    aBatteryInfo->level() = capacity / 100;
> +  aBatteryInfo->charging() = (chargingSrc == BATTERY_CHARGING_USB ||
> +    chargingSrc == BATTERY_CHARGING_AC);

ditto for the indentation:
aBatteryInfo->charging() = (chargingSrc == BATTERY_CHARGING_USB ||
	                    chargingSrc == BATTERY_CHARGING_AC);
Attachment #597029 - Flags: review+
(In reply to Fabrice Desré [:fabrice] from comment #4)
> Also, on an akami device, we don't have battery/charging_source at all.

Could you open a bug for that and CC me?
(Assignee)

Comment 15

5 years ago
Created attachment 597433 [details] [diff] [review]
Charging when charging source is 1 or 2, not charging when 0. Log anything else when in DEBUG.

Fixed indentation and boolean logic readability.
Attachment #597029 - Attachment is obsolete: true
Attachment #597433 - Flags: checkin+
https://hg.mozilla.org/mozilla-central/rev/ebcae0510986
Status: ASSIGNED → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla13
You need to log in before you can comment on or make changes to this bug.