Closed
Bug 1043920
Opened 11 years ago
Closed 11 years ago
Reader mode (ambient light detection) prevents device from sleeping (holds CPU wakelock)
Categories
(Firefox for Android Graveyard :: Reader View, defect)
Tracking
(firefox32 fixed, firefox33 fixed, firefox34 verified, fennec32+)
VERIFIED
FIXED
Firefox 34
People
(Reporter: kamil.paral, Assigned: mfinkle, Mentored)
References
Details
(Whiteboard: [lang=js])
Attachments
(1 file, 1 obsolete file)
4.59 KB,
patch
|
Margaret
:
review+
Sylvestre
:
approval-mozilla-aurora+
Sylvestre
:
approval-mozilla-beta+
|
Details | Diff | Splinter Review |
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0 (Beta/Release)
Build ID: 20140611060104
Steps to reproduce:
Lately my tablet seems to have been "randomly" depleting a lot of battery during sleep (e.g. 10-15% of capacity lost during night instead of usual 3%). I don't know if it is a recent regression, but I have identified the issue to be caused by Reader Mode in Firefox.
I have spent two days carefully measuring it (using Battery Monitor Widget) and the measurements are absolutely consistent and I can reproduce them any time and every time.
Actual results:
If Firefox has at least one tab opened in Reader Mode, the device drains 4 times more energy during sleep).
It doesn't matter whether the tab is active or not. It doesn't matter whether Firefox was the currently active app before putting device to sleep, or whether it has just been in the "recently used apps" list.
If I look at integrated Battery usage dialog in Settings, I see "Android OS" to be the primary cause of energy consumption (e.g. 40%, more than Screen, which is usually the top offender). If I look into Android OS process details, I see "Keep awake: 10 hours" and similar values. Firefox process itself is not marked as using energy nor keeping the device awake. But I can consistently reproduce this behavior by opening or closing a tab in Reader Mode, letting the device sleep for a while, and then looking at the changed numbers.
I have read there there are two types of "wakelocks" - display and CPU. The display lock is clearly not held, because the device automatically turns it off and locks itself. But it seems that Reader Mode is holding the CPU lock for as long as the tab is opened, even if Firefox is not an active app.
I have seen this problem with many different web pages toggled into Reader Mode, so I don't expect to be URL-specific. But to be sure, here's an example URL that causes the problem every time I test it:
http://www.lupa.cz/clanky/p2p-pujcky-proc-se-zadluzit-bance-kdyz-vam-muze-pujcit-dav/
If I open it as a normal web page and put the device to sleep, it doesn't consume extra power and Android OS process doesn't show increasing numbers in "Keep awake" (the numbers are actually decreasing, for some reason). If I toggle that web page into Reader Mode and put the device to sleep, a lot of power is drained and Android OS process shows rapidly increasing time in Keep Awake.
Expected results:
Reader Mode should not keep the device awake. I don't know whether I'm the only one affected (due to some specific configuration), or everyone with my hardware (Nexus 7) or completely everyone. But at least for me, this bug is quite critical. If I don't pay a lot of attention and don't carefully close all Reader Mode tabs before putting the device to sleep, my battery is depleted very quickly.
If you need some specific information to help you debug the issue, please tell me. My tablet is not rooted, by I can work with adb shell. Thanks.
Assignee | ||
Comment 1•11 years ago
|
||
The Reader view using a web API to monitor the ambient lighting levels and adjust the background color from light to dark. It only does this if the "color scheme" is set to "auto", which is the default.
Can you try tapping the "Aa" button in Reader and changing the color scheme to "light" or "dark" and see if that changes the power usage?
Reporter | ||
Comment 2•11 years ago
|
||
Bingo! It's definitely caused by light conditions autodetection. When I switch the theme manually, the energy consumption is normal and the device sleeps properly. When I switch it back to autodetection, the consumption is up again and the device does not sleep. Should this get reassigned somewhere else? Do I understand correctly it might affect all websites using this API, not just the reader mode?
Updated•11 years ago
|
OS: Linux → Android
Hardware: x86_64 → ARM
Summary: Reader mode prevents device from sleeping (holds CPU wakelock) → Reader mode (ambient light detection) prevents device from sleeping (holds CPU wakelock)
Updated•11 years ago
|
Status: UNCONFIRMED → NEW
Ever confirmed: true
Assignee | ||
Comment 3•11 years ago
|
||
(In reply to Kamil Páral from comment #2)
> Bingo! It's definitely caused by light conditions autodetection. When I
> switch the theme manually, the energy consumption is normal and the device
> sleeps properly. When I switch it back to autodetection, the consumption is
> up again and the device does not sleep. Should this get reassigned somewhere
> else? Do I understand correctly it might affect all websites using this API,
> not just the reader mode?
Thank you for testing this out. Let's leave the bug here for now. We can try to fix this by listening for "application-foreground" and "application-background" notifications. We can hook and unhook the event listener as appropriate.
A larger question is whether the Gecko platform should be aware of this situation for all events and throttle them back when Fennec is not in the foreground.
Updated•11 years ago
|
Mentor: margaret.leibovic
Whiteboard: [lang=js]
Assignee | ||
Updated•11 years ago
|
Assignee: nobody → mark.finkle
Assignee | ||
Comment 4•11 years ago
|
||
This patch uses "visibilitychange" to monitor when the page goes into the background. It works when switching tabs. It also works when putting the app into the background and then back to foreground.
If using "auto", the patch will remove the "devicelight" event listener when the page is not visible. It will add the event listener back when the page becomes visible again.
Attachment #8462873 -
Flags: review?(margaret.leibovic)
Comment 5•11 years ago
|
||
Comment on attachment 8462873 [details] [diff] [review]
devicelight-pagevisible v0.1
Review of attachment 8462873 [details] [diff] [review]:
-----------------------------------------------------------------
Nice, visibilitychange is definitely what we want to use here. I'd just like to see us make this logic a bit better before landing it.
::: mobile/android/chrome/content/aboutReader.js
@@ +415,5 @@
> + if (this._doc.hidden) {
> + this._win.removeEventListener("devicelight", this, false);
> + } else {
> + this._win.addEventListener("devicelight", this, false);
> + }
I don't really like how this means we now add/remove this listener in two different places, since I'm worried we could end up accidentally adding the listener twice. Like, what happens if the user opens a reader mode tab in the background? Perhaps instead of using the color scheme pref, we could keep track of whether or not we have an active listener. And then instead of always adding this visibilitychange listener, you could only add it when we're in auto color mode.
At the very least, I think you should factor out the event listener code into a helper method like _setLightDetectionEnabled(true/false), which adds/removes the listener and also initializes/deletes _luxValues/_totalLux as appropriate. The user's ambient light situation may have changed while the reader mode tab was in the background, and resetting these values would lead to us updating the color scheme immediately, as opposed to waiting for the average to update.
Attachment #8462873 -
Flags: review?(margaret.leibovic) → feedback+
Assignee | ||
Comment 6•11 years ago
|
||
This version unifies the code to turn device light tracking. I tested with the debugger and it removes the event handler when appropriate. Light/dark transitions work correctly.
Attachment #8462873 -
Attachment is obsolete: true
Attachment #8463547 -
Flags: review?(margaret.leibovic)
Comment 7•11 years ago
|
||
Comment on attachment 8463547 [details] [diff] [review]
devicelight-pagevisible v0.2
Review of attachment 8463547 [details] [diff] [review]:
-----------------------------------------------------------------
::: mobile/android/chrome/content/aboutReader.js
@@ +411,5 @@
> + return;
> + }
> +
> + // Turn off the ambient light sensor if the page is hidden
> + this._enableAmbientLighting(!this._doc.hidden)
Nit: Add a semicolon.
Attachment #8463547 -
Flags: review?(margaret.leibovic) → review+
Assignee | ||
Comment 8•11 years ago
|
||
https://hg.mozilla.org/integration/fx-team/rev/877cd1bb9912
I think we should uplift this since it can impact battery life.
tracking-fennec: --- → 32+
status-firefox32:
--- → affected
status-firefox33:
--- → affected
status-firefox34:
--- → affected
Comment 9•11 years ago
|
||
Kamil, it would be nice to do the same comparative testing again for verification purposes when this makes it's way to Nightly.
Reporter | ||
Comment 10•11 years ago
|
||
Sure, I will. Just please tell me once it is available at http://nightly.mozilla.org/. And thanks for the quick fix.
Comment 11•11 years ago
|
||
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 34
Comment 12•11 years ago
|
||
(In reply to Kamil Páral from comment #10)
> Sure, I will. Just please tell me once it is available at
> http://nightly.mozilla.org/. And thanks for the quick fix.
This is in Nightly now as of the 30th of July.
Reporter | ||
Comment 13•11 years ago
|
||
I have downloaded today's Nightly and tested it, it seems to be fixed. I don't see any increased battery consumption even with light conditions autodetection. Great job!
Updated•11 years ago
|
Status: RESOLVED → VERIFIED
Assignee | ||
Comment 15•11 years ago
|
||
(In reply to Aaron Train [:aaronmt] from comment #14)
> re: aurora/beta
Given the verification in comment 13, yes, we should uplift as far as we can. Reducing battery consumption is a big deal.
Flags: needinfo?(mark.finkle)
Assignee | ||
Comment 16•11 years ago
|
||
Comment on attachment 8463547 [details] [diff] [review]
devicelight-pagevisible v0.2
Approval Request Comment
[Feature/regressing bug #]:
[User impact if declined]: Increased battery consumption
[Describe test coverage new/current, TBPL]: Reduced power usage was verified
[Risks and why]: Low. Functionality still seems to work fine.
[String/UUID change made/needed]: None
Attachment #8463547 -
Flags: approval-mozilla-beta?
Attachment #8463547 -
Flags: approval-mozilla-aurora?
Updated•11 years ago
|
Attachment #8463547 -
Flags: approval-mozilla-beta?
Attachment #8463547 -
Flags: approval-mozilla-beta+
Attachment #8463547 -
Flags: approval-mozilla-aurora?
Attachment #8463547 -
Flags: approval-mozilla-aurora+
Assignee | ||
Comment 17•11 years ago
|
||
Updated•5 years ago
|
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•