chromiumos/platform/power_manager.git
16 months agopower: Remove unneeded gmock references. 07/66207/2 master
Daniel Erat [Mon, 19 Aug 2013 15:49:47 +0000 (08:49 -0700)]
power: Remove unneeded gmock references.

BUG=none
TEST=built and ran tests

Change-Id: Ic50482a0f1f26e447c896ed112c3f9850039d668
Reviewed-on: https://gerrit.chromium.org/gerrit/66207
Commit-Queue: Daniel Erat (OOO 8/20-8/23) <derat@chromium.org>
Tested-by: Daniel Erat (OOO 8/20-8/23) <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
16 months agopower: Add support for writing eventlog entries. 20/62120/7 release-R30-4537.B
Daniel Erat [Sun, 14 Jul 2013 14:13:06 +0000 (07:13 -0700)]
power: Add support for writing eventlog entries.

This makes powerd use the "mosys eventlog add" command to
record suspend and resume events when the USE_MOSYS_EVENTLOG
environment variable (controlled by the "mosys_eventlog" USE
flag) is set.

It also removes absolute paths from the commands run by
powerd_setuid_helper.

BUG=chrome-os-partner:20852
TEST=manual

Change-Id: If4a0985d3cd5b92520b8676e4929e08b9250ba97
Reviewed-on: https://gerrit.chromium.org/gerrit/62120
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

16 months agopower: Move scripts to powerd/ and tools/ directories. 48/64648/3 stabilize-4512.B
Daniel Erat [Sat, 3 Aug 2013 01:53:38 +0000 (18:53 -0700)]
power: Move scripts to powerd/ and tools/ directories.

I think it makes more sense to group these by why they exist
than by the language that they're written in.

BUG=none
TEST=none
CQ-DEPEND=I8db791e860fd9a4ecf513f95a510bb9b7c7366e4

Change-Id: I463262c7f8bc7a8ea74157a5f253dd88967f2a17
Reviewed-on: https://gerrit.chromium.org/gerrit/64648
Reviewed-by: Chris Masone <cmasone@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

16 months agopower: Clean up PID-related stuff in powerd_suspend. 19/64419/4
Daniel Erat [Sat, 3 Aug 2013 01:49:25 +0000 (18:49 -0700)]
power: Clean up PID-related stuff in powerd_suspend.

powerd_suspend was using $PPID in its log messages, which
perhaps made sense when it was getting run directly by
powerd but no longer does now that powerd double-forks
before exec-ing powerd_setuid_helper, which then execs
powerd_suspend.

It also updates some only-working-by-accident code that I'd
written to make powerd_suspend abort when not run by
powerd_setuid_helper. The script checked that its parent
process contained powerd_setuid_helper in its name. The
helper exec()s powerd_suspend rather than running it as a
child, though; the check only succeeded because the helper
itself was run under sh by powerd, and that sh process ended
up being powerd_suspend's parent after the exec(). This
change makes the helper just set an environment variable
that the script then checks.

BUG=none
TEST=none

Change-Id: Iddf9a9732f2cbc887094fa540f411175cd0aac0f
Reviewed-on: https://gerrit.chromium.org/gerrit/64419
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
16 months agopower: Make powerd_suspend only runnable by setuid helper. 66/63266/2 factory-pit-4471.B firmware-pit-4482.B
Daniel Erat [Mon, 22 Jul 2013 19:51:26 +0000 (12:51 -0700)]
power: Make powerd_suspend only runnable by setuid helper.

This makes the powerd_suspend script exit with a friendly
error message directing the user toward powerd_dbus_suspend
when it's run by a process other than powerd_setuid_helper.

powerd_suspend is an implementation detail of powerd and
doesn't exercise the full suspend path (e.g. VT-switching
doesn't get locked and other processes aren't notified about
the impending suspend attempt).

BUG=chromium:242345
TEST=manual: see error when running powerd_suspend by hand;
     suspending by closing the lid or running
     powerd_dbus_suspend still works

Change-Id: I035efd055028d0da2f197e9d34883deaab2143a6
Reviewed-on: https://gerrit.chromium.org/gerrit/63266
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
16 months agopower: Ignore video activity while screen is dimmed or off. 85/62785/3 factory-4455.B stabilize-4443.B
Daniel Erat [Sat, 20 Jul 2013 19:37:10 +0000 (12:37 -0700)]
power: Ignore video activity while screen is dimmed or off.

This makes powerd disregard reports of video activity sent
by Chrome while the screen is dimmed or turned off. Video
activity still prevents the screen from getting dimmed in
the first place, but activity seen after the user has been
inactive for a long time is more likely to be a false
positive (e.g. animated ads) than to have been intentionally
triggered by the user.

BUG=chromium:262572
TEST=updated tests

Change-Id: Iad6da40fa05c55380ebd88460959c5bcda30fed6
Reviewed-on: https://gerrit.chromium.org/gerrit/62785
Reviewed-by: Benson Leung <bleung@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
17 months agopower: Remove shut-down-at-login-screen policy. 46/62546/2
Daniel Erat [Thu, 18 Jul 2013 17:34:44 +0000 (10:34 -0700)]
power: Remove shut-down-at-login-screen policy.

Chrome sends powerd "shut down on battery, suspend on AC"
idle policies at the login screen and "always suspend"
idle policies after the user has logged in now, so there's
no need for powerd to control this itself.

This change also removes the "suspend_at_login_screen" pref.

BUG=chromium:254404
TEST=updated unit tests; also checked that the correct
     external policies are received from chrome after
     logging in or out

Change-Id: I2d1bc7162b53ac16610dcb35e7b3389dfcdc75ad
Reviewed-on: https://gerrit.chromium.org/gerrit/62546
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Bartosz Fabianowski <bartfab@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

17 months agopower: Remove FileTagger class. 50/62550/2
Daniel Erat [Thu, 18 Jul 2013 21:24:37 +0000 (14:24 -0700)]
power: Remove FileTagger class.

This removes the FileTagger class, which touched and
unlinked files in /var/lib/power_manager to let
crash-reporter know whether unclean shutdowns occurred while
the system was suspended. It replaces it with much-simpler
code in the Daemon class.

The old code also tracked whether the system was in a
low-battery state or not, which I don't think makes sense
anymore: we shut down immediately when the battery is low.

BUG=chromium:259189
TEST=manual: cut battery power while system was suspended
     and checked that crash-reporter logged that it wasn't
     reporting the unclean shutdown; cut battery power while
     awake and checked that the unclean shutdown would've
     been reported

Change-Id: Ifdb3eb9c15a6eaaf36e1862659c55c4848b138ef
Reviewed-on: https://gerrit.chromium.org/gerrit/62550
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
17 months agopower: Set default powerd_dbus_suspend delay to 1 second. 52/62352/5
Daniel Erat [Wed, 10 Jul 2013 16:19:56 +0000 (09:19 -0700)]
power: Set default powerd_dbus_suspend delay to 1 second.

This command doesn't work reliably when run by hand on a
device without a delay. It can be run by scripts with
--delay 0 to get the previous behavior.

It also updates a few places where powerd_suspend was being
run directly by programs other than powerd_setuid_helper.

BUG=chromium:242345
TEST=manual: ran powerd_dbus_suspend, memory_suspend_test,
     and suspend_stress_test

Change-Id: Iaa2e4839c0a995b74b19bd5abeda49706a664333
Reviewed-on: https://gerrit.chromium.org/gerrit/62352
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
17 months agopower: Don't turn backlight on for brightness key activity. 66/61666/2
Daniel Erat [Fri, 12 Jul 2013 04:40:23 +0000 (21:40 -0700)]
power: Don't turn backlight on for brightness key activity.

If the user has set the backlight brightness to 0, powerd
automatically increases it in response to user activity.
This change makes powerd avoid the automatic increase if the
user activity was a brightness-up or brightness-down key
event, as those keys already have their own effects on the
brightness level.

BUG=chromium:254841
TEST=added unit tests; also manually tested in conjunction
     with chrome change that after manually reducing the
     brightness to 0 and waiting five seconds, a single
     brightness-up key press brings the backlight to the
     lowest non-off step rather than the step above it
CQ-DEPEND=Ie41ae7e0dfe6abcec8cf69baab702f4b23a7960e

Change-Id: I4fe72395f33fd7f3e780de4250c69fa21892e3a3
Reviewed-on: https://gerrit.chromium.org/gerrit/61666
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

17 months agopower: Add optional uint64 wakeup count to RequestSuspend. 21/61321/4 factory-pit-4390.B firmware-falco_peppy-4389.B firmware-leon-4389.26.B firmware-wolf-4389.24.B
Daniel Erat [Mon, 27 May 2013 14:06:25 +0000 (07:06 -0700)]
power: Add optional uint64 wakeup count to RequestSuspend.

This adds an optional uint64 argument to powerd's
RequestSuspend D-Bus method. A test can read
/sys/power/wakeup_count and pass the value to powerd; if the
test's count has been surpassed when powerd later reads
wakeup_count itself, the suspend attempt will be canceled.

This allows tests to exercise the actual suspend path by
making RequestSuspend calls to powerd instead of running the
powerd_suspend script directly.

I'm also adding a --delay flag to powerd_dbus_suspend that
can be used to specify a delay (in seconds) before the
request is sent to powerd. Running powerd_dbus_suspend
interactively from a terminal on a device often results in a
failed suspend attempt otherwise, since the Enter key press
is reported as user activity.

BUG=chromium:242345,chromium:221910
TEST=added unit tests; also manually tested by passing a
     stale wakeup count to powerd_dbus_suspend

Change-Id: If394b0145fc2bf470f04ab5c8616054300f9b4f6
Reviewed-on: https://gerrit.chromium.org/gerrit/61321
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

17 months agopower: Rework battery time calculations. 39/60839/5
Daniel Erat [Fri, 21 Jun 2013 00:16:42 +0000 (17:16 -0700)]
power: Rework battery time calculations.

This updates powerd to keep a rolling average of battery
current readings rather than a rolling average of
time-to-empty and time-to-full estimates.

It also makes it report time-to-full when the battery is
charging and time-to-empty when it's discharging, rather
than time-to-full whenever a charger is connected (it's
possible for the battery to discharge when using a
low-current charger). Estimates that would be extremely
large due to a low current are reported as -1.

BUG=chromium:252948,chromium:233348,chrome-os-partner:20343
TEST=updated existing unit tests; lots of manual testing on
     different devices

Change-Id: Ic43efe9bc31832d3b6323f619a14f410d5642a0e
Reviewed-on: https://gerrit.chromium.org/gerrit/60839
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

17 months agopower: Log additional info about line power. 43/60943/2
Daniel Erat [Wed, 3 Jul 2013 23:04:36 +0000 (16:04 -0700)]
power: Log additional info about line power.

This makes powerd log the charger's current and voltage when
available.

BUG=chrome-os-partner:19442
TEST=ran power_supply_info and looked at logs with various
     chargers connected

Change-Id: I1199b975e137e8701361761268296b620c393ad5
Reviewed-on: https://gerrit.chromium.org/gerrit/60943
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

17 months agopower: Interpret powerd_suspend's exit code. 55/61055/2
Daniel Erat [Wed, 29 May 2013 22:02:13 +0000 (15:02 -0700)]
power: Interpret powerd_suspend's exit code.

This makes powerd examine powerd_suspend's exit code,
allowing it to distinguish between transient failures and
cancellations caused by wakeup events. Both cases are
currently treated the same as before (i.e. the suspend
attempt is retried with the system shutting down
eventually); the behavior will be changed in a later CL.

BUG=chromium:221910,chromium:242345
TEST=updated existing unit tests

Change-Id: I6289b30257d90d69db4caa8228ba4f51bee83834
Reviewed-on: https://gerrit.chromium.org/gerrit/61055
Reviewed-by: Julius Werner <jwerner@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
17 months agopower: Remove VideoActivityUpdate protocol buffer. 29/60929/2
Daniel Erat [Wed, 3 Jul 2013 17:44:10 +0000 (10:44 -0700)]
power: Remove VideoActivityUpdate protocol buffer.

Chrome doesn't send these anymore.

BUG=none
TEST=manual: did a build
CQ-DEPEND=I669da8f8244e43bdae3126d995d1f94e929aca21

Change-Id: I31f42ebeb44118120cc3e2e4a1fef483036dfb0b
Reviewed-on: https://gerrit.chromium.org/gerrit/60929
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
17 months agopower: Use native D-Bus arg for HandleVideoActivity. 79/60679/2
Daniel Erat [Mon, 1 Jul 2013 17:08:16 +0000 (10:08 -0700)]
power: Use native D-Bus arg for HandleVideoActivity.

This updates powerd to accept a single boolean
"is_fullscreen" argument with HandleVideoActivity D-Bus
method calls in addition to the heavier-weight
VideoActivityUpdate protocol buffers. A later change will
remove the protocol buffer code after Chrome has been
updated.

It also fixes a bug where the Daemon class didn't notify
KeyboardBacklightController about the session state at
startup (this is only an issue if powerd is restarted after
the user has logged in, which isn't expected to happen).

BUG=none
TEST=manual: fullscreen video is still reported

Change-Id: I448b939632abd53c809dc5a7b61e71fb2f1f9c57
Reviewed-on: https://gerrit.chromium.org/gerrit/60679
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

17 months agopower: Turn keyboard backlight off with panel backlight. 01/60701/2
Daniel Erat [Mon, 1 Jul 2013 22:07:55 +0000 (15:07 -0700)]
power: Turn keyboard backlight off with panel backlight.

When the user manually sets the display backlight brightness
to 0% (or if it gets turned off for any other reason), turn
the keyboard backlight off automatically.

Also prevent the keyboard backlight from being turned off
due to fullscreen video after the user has manually adjusted
the keyboard brightness level.

Finally, delete some syslog code that was being used to log
the revision number and instead use Chrome's logging code.

BUG=chromium:246886
TEST=added new tests; also did manual testing

Change-Id: I83911b33e51db0137f8f53831f2d829b0a16f25e
Reviewed-on: https://gerrit.chromium.org/gerrit/60701
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

17 months agopower: Log more info about battery status. 64/60264/2
Daniel Erat [Wed, 26 Jun 2013 00:04:52 +0000 (17:04 -0700)]
power: Log more info about battery status.

This makes powerd's periodic battery status messages include
the battery's charge, full charge, and current. A later
change will add more charger-specific information when it's
provided by the kernel.

BUG=chrome-os-partner:19442
TEST=manual: looked at /var/log/power_manager/powerd.LATEST

Change-Id: Icd42b220eec42dd47e233d222fb35fb8e294e570
Reviewed-on: https://gerrit.chromium.org/gerrit/60264
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

17 months agopower: Separate idle delays for AC and battery power. 26/60126/4
Daniel Erat [Wed, 26 Jun 2013 15:24:31 +0000 (08:24 -0700)]
power: Separate idle delays for AC and battery power.

This updates powerd to support |ac_idle_action| and
|battery_idle_action| fields in PowerManagementPolicy
protocol buffers instead of the old |idle_action| field.

BUG=chromium:254404
TEST=added a test
CQ-DEPEND=I89034188a1c8baee2e508372560187fb9e4a42f6

Change-Id: Ife6da36b23f83273277033b3d71f85c62c42f4c1
Reviewed-on: https://gerrit.chromium.org/gerrit/60126
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
17 months agoRemove a couple of stale entries from OWNERS 27/59927/2
Ryan Harrison [Tue, 25 Jun 2013 17:19:51 +0000 (13:19 -0400)]
Remove a couple of stale entries from OWNERS

kliegs@ no longer works on chromiumos. rharrison@ no longer works on this part of
the code base.

BUG=none
TEST=none, this is a non-functional change

Change-Id: I57cba6094fe8f226dc34df456e8c7a6f699722f3
Reviewed-on: https://gerrit.chromium.org/gerrit/59927
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Tested-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Jon Kliegman <kliegs@chromium.org>
17 months agopower: Add a bunch of missing DISALLOW_COPY_AND_ASSIGN()s. 85/59785/2
Daniel Erat [Mon, 24 Jun 2013 14:25:50 +0000 (07:25 -0700)]
power: Add a bunch of missing DISALLOW_COPY_AND_ASSIGN()s.

BUG=none
TEST=built it

Change-Id: Ifb81822fbb875c3b241eb2cdf92c872e07f23b37
Reviewed-on: https://gerrit.chromium.org/gerrit/59785
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
17 months agopower: Clean up thermal metrics and dark resume logging. 28/59628/3
Daniel Erat [Fri, 21 Jun 2013 21:42:19 +0000 (14:42 -0700)]
power: Clean up thermal metrics and dark resume logging.

Remove code for reporting thermal/fan-related metrics. There
aren't any plans to forward-port the kernel patches required
by this code to 3.8, so all it does right now is spam the
logs with errors.

Also make DarkResumePolicy avoid logging errors when its
prefs are missing, since they're only set for a few boards.

BUG=chromium:220522
TEST=ran it on lumpy and looked at log

Change-Id: I74b585c08db1aef33695969b1505e88601bd58b9
Reviewed-on: https://gerrit.chromium.org/gerrit/59628
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Sameer Nanda <snanda@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

17 months agopower: Move TimeDeltaToString() to utility library. 92/59592/2
Daniel Erat [Fri, 21 Jun 2013 19:23:39 +0000 (12:23 -0700)]
power: Move TimeDeltaToString() to utility library.

I plan to use StateController's TimeDeltaToString() in some
new code I'm writing, so this change moves it to the util
library and makes it include hours in its output so it can
deal with larger values.

BUG=none
TEST=added unit test

Change-Id: I045fddef60875e2ec797a0d7aad5d47a24e94d7e
Reviewed-on: https://gerrit.chromium.org/gerrit/59592
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

18 months agopower: Avoid shutting down due to low battery on AC. 01/59301/2
Daniel Erat [Wed, 19 Jun 2013 16:53:37 +0000 (09:53 -0700)]
power: Avoid shutting down due to low battery on AC.

This fixes a regression introduced by ab36fba1. powerd could
shut down due to low battery even when an AC power supply
was connected.

BUG=chromium:219706
TEST=added tests

Change-Id: I420338eb80de03195f15142faf673f0a7e4d2eee
Reviewed-on: https://gerrit.chromium.org/gerrit/59301
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
18 months agopower: Simplify shutdown code. 45/57545/2
Daniel Erat [Mon, 3 Jun 2013 17:29:18 +0000 (10:29 -0700)]
power: Simplify shutdown code.

This gets rid of the "clean shutdown" step, where powerd
ran the clean-shutdown Upstart job, which stopped cromo and
then emitted a CleanShutdown D-Bus signal telling powerd to
actually change the init level.

It also corrects some method and variable names ("shut down"
is a verb; "shutdown" is a noun).

BUG=chromium:246313
TEST=manual: system shuts down when requested
CQ-DEPEND=Id6949b90111f1aed5196a07566611c7fe58d36f0

Change-Id: Iaabd3219313cf5d2490141e2abefa74cc5384fc2
Reviewed-on: https://gerrit.chromium.org/gerrit/57545
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Sameer Nanda <snanda@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

18 months agopower: Update a few references to deprecated proto field. 39/58539/2 factory-4290.B stabilize-4287.B
Daniel Erat [Thu, 13 Jun 2013 15:27:40 +0000 (08:27 -0700)]
power: Update a few references to deprecated proto field.

This removes a few references to the PowerManagementPolicy
protocol buffer's deprecated presentation_idle_delay_factor
field that should've been removed in 25c0299a.

BUG=chromium:248276
TEST=built in conjunction with system_api change to remove
     the deprecated field

Change-Id: Ia2676294d443488447bbb32e059f04765f8daca2
Reviewed-on: https://gerrit.chromium.org/gerrit/58539
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Bartosz Fabianowski <bartfab@chromium.org>
18 months agopower: Add prefs for non-ambient-light backlight brightness. 16/58716/2 factory-pit-4280.B
Daniel Erat [Fri, 14 Jun 2013 21:20:14 +0000 (14:20 -0700)]
power: Add prefs for non-ambient-light backlight brightness.

This adds internal_backlight_no_als_ac_brightness and
internal_backlight_no_als_battery_brightness prefs that
control the default panel backlight brightness levels on
devices that lack ambient light sensors.

BUG=chrome-os-partner:19348
TEST=added unit tests; also manually checked that expected
     brightnesses were used on ac/battery power on a device
     that doesn't have an ambient light sensor

Change-Id: If5b511d5bd77830f975fc4b03a727e89ca4502eb
Reviewed-on: https://gerrit.chromium.org/gerrit/58716
Reviewed-by: Dave Moore <davemoore@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
18 months agoRevert "powerd_suspend: Keep RTC used for tests in sync with autotest code" 09/58709/3
Julius Werner [Fri, 14 Jun 2013 21:10:39 +0000 (14:10 -0700)]
Revert "powerd_suspend: Keep RTC used for tests in sync with autotest code"

This reverts commit 46309cd0f510d0eb682fa8c949f6770c514dc010.

This ends up causing more problems than it solves. The
second RTC is just too screwed up to get working reliably,
we should rather not use it at all.

CQ-DEPEND=CL:58710
BUG=chromium:221857
TEST=power_Resume on daisy

Change-Id: I2527190fe7b4be9852d49329386b1e19a8e955e5
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/58709
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
18 months agopower_manager: metrics: Add search keyword for CPU ready time 84/58184/2
Penny Chiu [Tue, 11 Jun 2013 09:03:38 +0000 (17:03 +0800)]
power_manager: metrics: Add search keyword for CPU ready time

In NVIDIA T114 Puppy, if CPU1~CPU3 are turned off by CPUQuiet before
system enters to suspend, they will be not turned on during system
resume, so the get_cpu_ready_time() cannot find "CPU is up" message.
This will cause some autotest tests are failed.

This patch adds "Booted secondary processor" as another keyword for
cpu_ready_time field.

BUG=chrome-os-partner:20025
TEST=script can get the timestamp for cpu_ready_time

Change-Id: Ibb930632a82a39f0983ed8ad1604e00249ee6065
Signed-off-by: Penny Chiu <pchiu@nvidia.com>
Reviewed-on: https://gerrit.chromium.org/gerrit/58184
Reviewed-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Bernie Thompson <bhthompson@chromium.org>
18 months agopower: Scale dim, rather than idle, delays while presenting. 94/58194/3 factory-spring-4262.B
Daniel Erat [Mon, 10 Jun 2013 21:58:24 +0000 (14:58 -0700)]
power: Scale dim, rather than idle, delays while presenting.

This makes powerd ignore PowerManagementPolicy's
presentation_idle_delay_factor field and instead honor
presentation_screen_dim_delay_factor.

BUG=chromium:248276
TEST=updated unit tests; manually tested that delays are
     updated as expected when entering or leaving
     presentation mode
CQ-DEPEND=I0bac41b585231fde1d5236ec1599c9756fe7aba2

Change-Id: I025a9c1cb9d7af1ae1e1c028744318295b1e85e5
Reviewed-on: https://gerrit.chromium.org/gerrit/58194
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
18 months agopowerd_suspend: Keep RTC used for tests in sync with autotest code 66/56666/5 stabilize-4255.B
Julius Werner [Fri, 24 May 2013 23:39:39 +0000 (16:39 -0700)]
powerd_suspend: Keep RTC used for tests in sync with autotest code

We are switching Autotest to use rtc1 for suspend tests on Exynos5
devices, so we need to do the same in powerd_suspend. See CL:56667

CQ-DEPEND=CL:56667
BUG=chromium:221857
TEST=power_Resume

Change-Id: I5cddbbb36627114bd8d20ce908b5efa45382971d
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/56666

18 months agopower: Update battery-full logic and lower threshold to 97%. 98/57998/5
Daniel Erat [Thu, 6 Jun 2013 15:08:47 +0000 (08:08 -0700)]
power: Update battery-full logic and lower threshold to 97%.

This updates powerd to report a battery as full if its
charge is greater than or equal to 97% of the
kernel-reported full charge, regardless of the current.
Previously, batteries were considered full if their charge
matched the full charge or if they were greater than or
equal to 98% with a zero current.

It also removes tricky code that pinned the battery level at
100% for a minute if the charger was removed while the
battery was reported as full.

BUG=chromium:247355
TEST=updated unit tests; also manually tested that battery
     percentages displayed in UI are continuous when
     plugging and unplugging charger while nearly full

Change-Id: Ia0d902125c9342c9069e726784ac9018f593bddc
Reviewed-on: https://gerrit.chromium.org/gerrit/57998
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
18 months agopower: Give up on broken ambient light sensors after 10 sec. 90/57790/2
Daniel Erat [Wed, 5 Jun 2013 00:52:41 +0000 (17:52 -0700)]
power: Give up on broken ambient light sensors after 10 sec.

This makes the InternalBacklightController class stop
waiting for the ambient light sensor if the sensor still
hasn't supplied a reading after ten seconds. Otherwise, if
the ALS driver is broken (which has happened several times),
powerd is left in a state where it refuses to change the
backlight level in response to user inactivity.

It also adds a new Clock class that can be used to mock out
the current time. This replaces a bunch of similar code that
was spread across the power manager.

BUG=chromium:243904
TEST=added a new unittest; also manually checked that state
     changes (e.g. dimming) take effect on a device with a
     broken ambient light sensor driver

Change-Id: I818ffb74ac1839fb6689c2d943d504327f499717
Reviewed-on: https://gerrit.chromium.org/gerrit/57790
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Sameer Nanda <snanda@chromium.org>
18 months agopower: Add proto to poll signal; remove deprecated fields. 69/57669/3
Daniel Erat [Wed, 5 Jun 2013 15:30:43 +0000 (08:30 -0700)]
power: Add proto to poll signal; remove deprecated fields.

This makes powerd include a PowerSupplyProperties protocol
buffer in the PowerSupplyPoll D-Bus signal that it emits so
that Chrome won't need to make an additional
GetPowerSupplyProperties method call.

It also makes powerd stop setting the |old_battery_state|
and |battery_is_present| fields.

Finally, it removes weird Chrome-initiated refreshes of the
power supply status. powerd already refreshes the status at
startup, just after resuming, when the external power source
changes, and every thirty seconds (or even more frequently
when it isn't able to compute accurate battery time
estimates), so there doesn't seem to be any reason to do an
additional refresh when Chrome asks for the status instead
of just returning the last-computed status.

BUG=chromium:234671,chromium:245108
TEST=tests pass; manually confirmed that chrome displays the
     power status as before
CQ-DEPEND=I4b0fb044ada49cbac2744045bee0ec7a7392ffbf

Change-Id: Ibd62f7193e7c32f05003958c5b53a31511a1d248
Reviewed-on: https://gerrit.chromium.org/gerrit/57669
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: James Cook <jamescook@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

18 months agopower: Turn all displays on at startup. 54/57554/2
Daniel Erat [Tue, 4 Jun 2013 17:44:59 +0000 (10:44 -0700)]
power: Turn all displays on at startup.

This fixes an issue where the displays could be stuck in the
off state if powerd was restarted after it had turned the
displays off due to inactivity.  InternalBacklightController
attempted to turn the displays on in its Init() method but
avoided sending the request due to a member variable being
previously initialized to the all-on state in the
constructor.

BUG=chromium:245083
TEST=added a unit test; also manually tested by waiting for
     displays to get turned off and then restarting powerd

Change-Id: I07fb798c7cc173b098ea2d63d1fabaf320ff7a52
Reviewed-on: https://gerrit.chromium.org/gerrit/57554
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: St├ęphane Marchesin <marcheu@chromium.org>
18 months agopower: Set ExternalPower enum. 98/57398/3
Daniel Erat [Sat, 1 Jun 2013 14:04:19 +0000 (07:04 -0700)]
power: Set ExternalPower enum.

This makes powerd set separate ExternalPower and
BatteryStatus enum values in PowerSupplyProperties protocol
buffers sent to Chrome.

It also refactors some PowerSupply code to remove
duplication.

BUG=chromium:245108
TEST=updated unit tests; also manually checked that chrome
     still displays power status correctly and
     power_supply_info prints correct info
CQ-DEPEND=Ib3c53286e72750a98b4ad862a5d55007c60e571e

Change-Id: If3ac3135f8e259981c4b9ed5641b7fb3c0123c8e
Reviewed-on: https://gerrit.chromium.org/gerrit/57398
Reviewed-by: James Cook <jamescook@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

18 months agopower: Clean up input logging. 44/57044/3
Daniel Erat [Wed, 29 May 2013 23:01:48 +0000 (16:01 -0700)]
power: Clean up input logging.

This cleans up the logging code in the Input class:

- Change some LOG(INFO)s to VLOG(1)s to cut down on
  spamminess at startup.
- Use PLOG(ERROR) to get better error reporting.
- Clean up strange punctuation (remove periods at the ends
  of non-sentences, spaces before colons, and exclamation
  points).
- Don't log warnings about expected files (".", "..", and
  "by-path").

BUG=chromium:220522
TEST=manual: logs are cleaner

Change-Id: I98b95d5ecfb5bad00b82f3d106a766ee369a38dc
Reviewed-on: https://gerrit.chromium.org/gerrit/57044
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

18 months agopower: Avoid suspending while shutting down. 02/57302/2
Daniel Erat [Sat, 1 Jun 2013 14:38:31 +0000 (07:38 -0700)]
power: Avoid suspending while shutting down.

This fixes an issue where closing the lid after the "clean
shutdown" interval (where other processes are given a chance
to clean up) completes but before the system powers off
results in the system suspending (only to resume and shut
down immediately when the lid is opened later).

The root cause is that the Daemon class checks its
clean_shutdown_initiated_ member to see if it's safe to
suspend, but the member was getting unset when other
processes reported readiness or the interval timed out. This
change makes Daemon's tracking of its shutdown progress
clearer and adds an additional check to the Suspender class.

BUG=chromium:245983
TEST=added unittest for Suspender change

Change-Id: I7d855c15eef04461f16cf87850199827660d4dfa
Reviewed-on: https://gerrit.chromium.org/gerrit/57302
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
Reviewed-by: Sameer Nanda <snanda@chromium.org>
18 months agopower: Improve powerd_suspend's reporting of wakeup events. 24/57024/3
Daniel Erat [Wed, 29 May 2013 16:19:27 +0000 (09:19 -0700)]
power: Improve powerd_suspend's reporting of wakeup events.

This makes powerd_suspend exit with 2 when a write to
/sys/power/state fails with EBUSY, indicating that the
suspend attempt was aborted due to a wakeup event having
been seen. Previously, only earlier wakeup events that
resulted in the write to /sys/power/wakeup_count failing
were reported in this manner. A later change will modify
powerd's handling of this exit code.

It also makes some miscellaneous cleanups to the script,
creating constants for the different suspend statuses and
updating constant capitalization to match the style guide.

BUG=chromium:221910,chromium:242345
TEST=manual: powerd_suspend exits with 2 and the
     a sample of 2 is reported for the Power.SuspendStatus
     histogram on link both when closing and opening the lid
     quickly (so that the wakeup_count write fails) and
     doing it slightly more slowly (so that the state write
     fails). appropriate messages are logged to
     /var/log/messages.

Change-Id: I594a7335c09ff57caf4d907aa5e04d79a6ab3df5
Reviewed-on: https://gerrit.chromium.org/gerrit/57024
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

18 months agopower: Report unchanged ambient light levels. 72/56672/3
Daniel Erat [Fri, 24 May 2013 22:43:40 +0000 (15:43 -0700)]
power: Report unchanged ambient light levels.

Fix a long-standing bug in the power manager: the
AmbientLightSensor class only notified observers when the
ambient light level changed from its previously-measured
level. The code to update the backlight brightness in
response to the ambient light level (now living in
AmbientLightHandler) doesn't respond to changes until it
sees a few readings at brighter or dimmer levels than the
level that induced the last backlight change.

As a result, a sequence of ambient light readings like
[15, 0, 0, 0, etc.] (quite achievable in a dark room) would
result in the backlight brightness *never* being changed. In
contrast, a sequence like [15, 0, 1, 2, 1] would. Whoops.

BUG=chromium:242275
TEST=updated unit tests

Change-Id: Ib46428949d164af934c717c3553e5b67a23d73dd
Reviewed-on: https://gerrit.chromium.org/gerrit/56672
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

18 months agopower: Ignore user activity while lid is closed. 41/56341/3
Daniel Erat [Thu, 23 May 2013 01:18:35 +0000 (18:18 -0700)]
power: Ignore user activity while lid is closed.

This updates the StateController class to ignore user
activity for the purposes of idle detection while the lid is
closed (unless the system is in docked mode).  Spurious
events can be generated while closing the lid; these events
were already ignored by the Suspender class.

BUG=chromium:221228
TEST=added unit tests

Change-Id: I5a70e136d8879ede79a3b9c11572719b8a72093a
Reviewed-on: https://gerrit.chromium.org/gerrit/56341
Reviewed-by: Benson Leung <bleung@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
18 months agopower: Add Power.KeyboardBacklightLevel metric. 37/56337/3
Daniel Erat [Wed, 22 May 2013 23:21:35 +0000 (16:21 -0700)]
power: Add Power.KeyboardBacklightLevel metric.

This adds a Power.KeyboardBacklightLevel metric that reports
the keyboard backlight brightness every thirty seconds.

It also removes the existing Power.BrightnessAdjust*
metrics. These were enum histograms tracking the number of
times that the panel brightness had been manually adjusted
by the user, but they didn't make much sense: User actions
are the right approach for tracking this, and in fact,
Chrome already reports user action metrics for the panel and
keyboard brightness accelerators. powerd was also recording
the number of SetScreenBrightness D-Bus calls, but these are
received continuously when the user drags the brightness
slider -- a single drag could generate hundreds of these,
each of which would be reported as a separate histogram
sample.

BUG=chromium:220993
TEST=added unit test; also did manual testing via
     chrome://histograms

Change-Id: Iad45310fce9e3a8e69a2727a1f6dff9d3e315aa3
Reviewed-on: https://gerrit.chromium.org/gerrit/56337
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
18 months agopower: Add Power.BatteryDischargeRateWhileSuspended metric. 31/56331/3
Daniel Erat [Wed, 22 May 2013 22:59:59 +0000 (15:59 -0700)]
power: Add Power.BatteryDischargeRateWhileSuspended metric.

This adds a new metric that records the rate at which the
battery energy decreased (in mW) while the system was
suspended.

BUG=chromium:218397
TEST=added unit tests; also did manual testing via
     chrome://histograms

Change-Id: I8714c35f871541a1327b15b6d96fe1b71ed63ce9
Reviewed-on: https://gerrit.chromium.org/gerrit/56331
Reviewed-by: Sameer Nanda <snanda@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
19 months agopower: Move metrics code into separate class. 63/56063/4
Daniel Erat [Mon, 20 May 2013 18:49:41 +0000 (11:49 -0700)]
power: Move metrics code into separate class.

This moves metrics-related code out of Daemon and into a new
MetricsReporter class to make it easier to test.

BUG=chromium:236839
TEST=updated existing unit tests

Change-Id: Ie25f5fa3976ec54ed2ada7b9360c51cb4bd3529d
Reviewed-on: https://gerrit.chromium.org/gerrit/56063
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
19 months agopower: Improve AmbientLightHandler logging. 66/56266/2
Daniel Erat [Wed, 22 May 2013 17:28:03 +0000 (10:28 -0700)]
power: Improve AmbientLightHandler logging.

There are multiple AmbientLightHandler instances on systems
with both panel and keyboard backlights; this adds a short
description to log messages make it possible to distinguish
between the instances.

BUG=chromium:242275
TEST=manual: log messages include "panel" or "keyboard"

Change-Id: I71068665eb272974170cdd070170f926e7bf1b1e
Reviewed-on: https://gerrit.chromium.org/gerrit/56266
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
19 months agopower: Rename powerd-related files. 97/55597/2
Daniel Erat [Fri, 17 May 2013 23:13:56 +0000 (16:13 -0700)]
power: Rename powerd-related files.

This renames some files to match their classes: powerd.*
becomes daemon.*, powerd_metrics.cc becomes
daemon_metrics.cc, and powerd_main.cc becomes main.cc.

BUG=none
TEST=built it

Change-Id: I8760c76cf2f5a9f55d1f32dfea70ef74e6c2511d
Reviewed-on: https://gerrit.chromium.org/gerrit/55597
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

19 months agopower: Clean up powerd_suspend's exit codes. 85/55585/3
Daniel Erat [Wed, 1 May 2013 13:05:14 +0000 (06:05 -0700)]
power: Clean up powerd_suspend's exit codes.

This fixes a case where powerd_suspend would try to return
exit code -1 -- exit codes must be zero or positive.  I'm
also cleaning up some comments.

BUG=chromium:236270
TEST=manual: hit a key mid-suspend and checked that
     powerd_suspend returned 2 and didn't log a message to
     /var/log/messages about an invalid return value

Change-Id: Idcec15f3feb631304a66332c4e417dd18dd81ae1
Reviewed-on: https://gerrit.chromium.org/gerrit/55585
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Sameer Nanda <snanda@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

19 months agopower: Allow shutdown on AC. 25/50925/4 factory-spring-4131.B
Todd Broch [Fri, 26 Apr 2013 23:11:49 +0000 (16:11 -0700)]
power: Allow shutdown on AC.

Some DUTs have alternative AC supplies which may not provide
sufficient power to charge or even maintain current battery levels.

In that case, we may still need to shutdown in the event that battery
drains below low_battery_shutdown level.

BUG=chrome-os-partner:18927
TEST=manual,

On spring,
1. Boot plugged with provided DUT AC charger.
2. Attach compatible non-Mains charger.
3. Run script below to fake low battery condition - 1%
  stop powerd
  percent=`power-supply-info | grep percent | awk {'print $2-1'}`
  prw='/var/lib/power_manager'
  echo ${percent} > ${prw}/low_battery_shutdown_percent
  start powerd
4. see shutdown occur on AC (non-Mains) supply
  tail -f /var/log/power_manager/powerd.LATEST | grep -i 'On AC'
  [0429/173022:INFO:powerd.cc(630)] On AC (USB) with battery at 73% (displayed as 3%); 3943 sec until full
5. Re-attach provided DUT AC charger
6. cleanup
   rm ${prw}/low_battery_shutdown_percent
   restart powerd

Change-Id: Ibae80c8ff3b0a33b4d7e47f454ddc53108478acf
Reviewed-on: https://gerrit.chromium.org/gerrit/50925
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Sameer Nanda <snanda@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
19 months agopower : Add allow_docked_mode preference 17/50917/3 factory-4128.B
Benson Leung [Fri, 10 May 2013 23:12:41 +0000 (16:12 -0700)]
power : Add allow_docked_mode preference

Add this preference so we have a way to restore the old
behavior that suspended every time the lid is closed.

Signed-off-by: Benson Leung <bleung@chromium.org>
BUG=chromium:239523
TEST=Added a unit test DisallowDockedMode.
Tested this on Lumpy and Parrot. Set the allow_docked_mode
config to 0, and plug in an external display. Notice that the
system suspends instead of going to docked mode.

Change-Id: I3ab5eaf7e48b988fc9ac752d87d34743c47d6124
Reviewed-on: https://gerrit.chromium.org/gerrit/50917
Commit-Queue: Benson Leung <bleung@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Tested-by: Benson Leung <bleung@chromium.org>
19 months agopower: add in low battery time and percent threshold values to the log 17/49917/4
Bernie Thompson [Thu, 2 May 2013 18:10:59 +0000 (11:10 -0700)]
power: add in low battery time and percent threshold values to the log

Some testing scripts such as power_LoadTest need to read values that powerd
is using, this adds the necessary values into the log which were removed by
https://gerrit.chromium.org/gerrit/#/c/48457/

BUG=chromium:237565
TEST=Manual, run new power_manager on DUT and verify powerd.LATEST log has
a reasonable message.

Change-Id: I1821bde2222a93682a39afe34731a579b35ffa27
Reviewed-on: https://gerrit.chromium.org/gerrit/49917
Reviewed-by: Todd Broch <tbroch@chromium.org>
Commit-Queue: Bernie Thompson <bhthompson@chromium.org>
Tested-by: Bernie Thompson <bhthompson@chromium.org>
19 months agopower: Use nominal voltage for battery energy. 50/49650/3
Daniel Erat [Tue, 30 Apr 2013 18:41:14 +0000 (11:41 -0700)]
power: Use nominal voltage for battery energy.

This changes the "battery energy" calculation to use the
nominal voltage rather than the instantaneous voltage.

BUG=chromium:224841
TEST=manual: ran power_supply_info

Change-Id: I6aa1a9450bbb2c53ff43a150c9bb39496dfd0fcb
Reviewed-on: https://gerrit.chromium.org/gerrit/49650
Reviewed-by: Sameer Nanda <snanda@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
19 months agopower: Use underscores instead of hyphens in binary names. 96/49596/3
Daniel Erat [Mon, 29 Apr 2013 20:59:55 +0000 (13:59 -0700)]
power: Use underscores instead of hyphens in binary names.

This renames backlight-tool to backlight_tool and
power-supply-info to power_supply_info -- all other power
manager binaries and scripts use underscores.

BUG=none
TEST=built it
CQ-DEPEND=I263d2c9027b6c61f47ebafebd52692f6d0a37e3e

Change-Id: Id17a1b8472238b2283629d8b24efaf9aea82bd4a
Reviewed-on: https://gerrit.chromium.org/gerrit/49596
Reviewed-by: Chris Masone <cmasone@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

19 months agopower: Add test for suspend-if-lid-closed-at-startup. 38/49538/2
Daniel Erat [Mon, 29 Apr 2013 22:29:05 +0000 (15:29 -0700)]
power: Add test for suspend-if-lid-closed-at-startup.

This adds a test to make sure that powerd will try to
suspend immediately if it's restarted while the lid is
closed.

BUG=none
TEST=new test passes

Change-Id: I22831d384a1db9d45366fc7d32136cbadfd03978
Reviewed-on: https://gerrit.chromium.org/gerrit/49538
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

19 months agopower: Remove ExternalBacklight class. 29/49529/3
Daniel Erat [Mon, 29 Apr 2013 17:22:01 +0000 (10:22 -0700)]
power: Remove ExternalBacklight class.

This removes the ExternalBacklight class, which is broken
and won't be used in the foreseeable future.  It also avoids
using BacklightController objects that fail initialization.

Finally, it adds a #error for the currently-unsupported
HAS_KEYBOARD_BACKLIGHT && !HAS_ALS combination and removes
some stale method declarations from powerd.h.

BUG=chromium:207899,chromium:221900,chromium:235640
TEST=updated tests; manually tested on stumpy and lumpy;
     forced InternalBacklight and
     InternalBacklightController initialization to fail and
     checked that powerd still mostly works

Change-Id: I4840f5adbfdd9a05758f99d00f51dfa31b900d47
Reviewed-on: https://gerrit.chromium.org/gerrit/49529
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
19 months agopower: Report USB power sources. 71/49471/2 stabilize-4068.0.B
Daniel Erat [Sat, 27 Apr 2013 20:27:58 +0000 (13:27 -0700)]
power: Report USB power sources.

This updates powerd to report the battery state as
CONNECTED_TO_USB when a USB power source is connected.

BUG=chromium:172894
TEST=added tests
CQ-DEPEND=Iae3cd53325998bdb882b00273a990ff216556e58

Change-Id: I875148cb64c782240fcbf08d0fc4b112b5523fe6
Reviewed-on: https://gerrit.chromium.org/gerrit/49471
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Jenny Zhang <jennyz@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

19 months agopower: Expose line power type. 18/49318/4
Todd Broch [Thu, 25 Apr 2013 18:16:05 +0000 (11:16 -0700)]
power: Expose line power type.

Previously line power type was fixed to 'Mains'.  Moving forward it
can change depending upon the charging capabilities of the supply.

This CL adds string field in power status to maintain the value and
publishes it in the powerd log and in power-supply-info output.
Additionally CL adds check in unit test for the new variable.

BUG=chrome-os-partner:18939
TEST=manual,
run power-supply-info on two devices and see:

Spring:
-------
Device: Line Power
  path:             /sys/class/power_supply/cros_ec-charger
  online:           yes
  type:             Mains

Lumpy:
------
Device: Line Power
  path:             /sys/class/power_supply/AC
  online:           no
  type:             Mains

See messaging in powerd log:
On AC (Mains) with battery at 99% (displayed as 100%); 0 sec until full

Also unittest stills.

Change-Id: I5b2c4ba022569324d6f78b842aa4c4fda0373783
Reviewed-on: https://gerrit.chromium.org/gerrit/49318
Tested-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Sameer Nanda <snanda@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>

19 months agopower: Remove MetricsStore. 64/49264/3
Daniel Erat [Thu, 25 Apr 2013 21:26:59 +0000 (14:26 -0700)]
power: Remove MetricsStore.

This makes the num-sessions-on-current-charge metrics code
use a pref to persist its count across reboots.

BUG=chromium:235579
TEST=updated existing tests; manually tested that the count
     is incremented as a result of logging in while AC is
     unconnected and that the metric is sent after
     connecting AC

Change-Id: Ia16185e6a32d8c4af296d4eb330ba78b0f959dfd
Reviewed-on: https://gerrit.chromium.org/gerrit/49264
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

19 months agopower: Remove bogus AmbientLightSensor instantiations. 34/49234/2
Daniel Erat [Thu, 25 Apr 2013 22:08:55 +0000 (15:08 -0700)]
power: Remove bogus AmbientLightSensor instantiations.

powerd_main.cc was creating AmbientLightSensor objects for
all non-desktop machines without checking whether they
actually had the required hardware or not.  This would
result in InternalBacklightController deferring state
changes (like screen dimming) indefinitely; it waits for the
initial ambient light reading to avoid unnecessary changes
soon after boot.

BUG=chromium:235548
TEST=manual: did a build with the als USE flag forced off
     and a bogus ALS device path and checked that the screen
     is dimmed due to inactivity

Change-Id: I46c1f269149dc758cef2e6532e6421d38571494f
Reviewed-on: https://gerrit.chromium.org/gerrit/49234
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Dave Moore <davemoore@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
19 months agopower: Increase delays for user activity after screen dim. 35/49135/5
Daniel Erat [Wed, 24 Apr 2013 22:48:34 +0000 (15:48 -0700)]
power: Increase delays for user activity after screen dim.

This adds support to powerd for increasing the screen dim,
off, etc. delays if user activity is reported while the
screen is dimmed or soon after it's been turned off.  The
default scale factor in powerd is currently 1.0; Chrome
needs to send PowerManagementPolicy protobufs containing
larger factors before this will take effect.

BUG=chromium:212394
TEST=added unit tests; also did manual testing using
     set_power_policy
CQ-DEPEND=I4a773c4cc8e5f4427a21eadde127e00d537656a2

Change-Id: Ief6f91f5c216467208367d4a5e39dbfe53a7d536
Reviewed-on: https://gerrit.chromium.org/gerrit/49135
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
19 months agopower: Stop setting deprecated PowerSupplyProperties fields. 75/49175/2
Daniel Erat [Wed, 24 Apr 2013 23:03:35 +0000 (16:03 -0700)]
power: Stop setting deprecated PowerSupplyProperties fields.

Chrome no longer reads some of the fields in these protocol
buffers.  Make powerd stop writing them so they can be
removed.

BUG=chromium:234786
TEST=built it and checked that chrome still displays power
     status correctly

Change-Id: I0d2a8661e48ef7cbaf953f29f51a09d0228f6f41
Reviewed-on: https://gerrit.chromium.org/gerrit/49175
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Jenny Zhang <jennyz@chromium.org>
19 months agopower: AC line power supply type should be less rigid. 53/49053/5
Todd Broch [Tue, 23 Apr 2013 23:54:10 +0000 (16:54 -0700)]
power: AC line power supply type should be less rigid.

From drivers/power/power_supply_sysfs.c
     static char *type_text[] = {
                "Unknown", "Battery", "UPS", "Mains", "USB",
                   "USB_DCP", "USB_CDP", "USB_ACA"
                   };

Presumably all strings except "Battery" could be a charger and
therefore powerd should interrogate the "online" variable for any
power supply type not just "Mains".

BUG=chrome-os-partner:18562
TEST=manual, On Spring

1. emerge-daisy_spring power_manager and install on Spring

2. Unplug device from AC supply & restart powerd

3. See in powerd log:
  power_supply.cc(469)] Line power path found: /sys/class/power_supply/cros_ec-charger
  powerd.cc(630)] On battery at 87% (displayed as 86%); 24023 sec until empty

4. Plug device into AC supply or alternative charger & restart powerd
  power_supply.cc(469)] Line power path found: /sys/class/power_supply/cros_ec-charger
  powerd.cc(627)] On AC with battery at 87% (displayed as 86%); 2398 sec until full

5. Also try plug/unplug without restart of powerd to see status changes.

6. power-supply-info correctly indentifies line-power on Spring

  # power-supply-info
  Device: Line Power
    path:             /sys/class/power_supply/cros_ec-charger
    online:           yes

7. test new unit test
  FEATURES=test emerge-lumpy power_manager
  [ RUN      ] PowerSupplyTest.TestNonMainsLinePower
  [       OK ] PowerSupplyTest.TestNonMainsLinePower (6 ms)
Change-Id: I454c5010ee71ed794644b9036b261d071f75137d
Reviewed-on: https://gerrit.chromium.org/gerrit/49053
Reviewed-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
19 months agopower: Use updated PowerSupplyProperties protocol buffer. 09/49009/4
Daniel Erat [Wed, 24 Apr 2013 00:17:13 +0000 (17:17 -0700)]
power: Use updated PowerSupplyProperties protocol buffer.

This updates powerd to use the new location of the
power_supply_properties.proto file and to fill its
battery_state field.

It also gets rid of powerd's old, barely-used BatteryState
enum and makes powerd fill the battery-time fields with the
averaged times (which are all that Chrome uses, anyway).

BUG=chromium:196402
TEST=updated and added tests; manually confirmed that things
     work as before
CQ-DEPEND=Ia98bdce63e4368f6bf6b6d241c7d6a69b1a427ad

Change-Id: I622b811ab392cf8e9db1d89d014ffea2d209e866
Reviewed-on: https://gerrit.chromium.org/gerrit/49009
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Jenny Zhang <jennyz@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

19 months agoRemove USB persist settings from powerd_suspend 18/49018/3
Julius Werner [Wed, 24 Apr 2013 01:12:57 +0000 (18:12 -0700)]
Remove USB persist settings from powerd_suspend

USB persist is now globally disabled by default in the kernel. We no
longer need to explicitly deactivate it on every suspend.

Also threw in some leftover comment cleanup on derat's request.

CQ-DEPEND=CL:49016
BUG=None
TEST=None

Change-Id: I04cd3e69c74ffea343e595a6893a85ca98ebac53
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/49018
Reviewed-by: Sameer Nanda <snanda@chromium.org>
19 months agopower: Ignore user in SessionStateChanged signal. 58/48958/3
Daniel Erat [Tue, 23 Apr 2013 21:18:02 +0000 (14:18 -0700)]
power: Ignore user in SessionStateChanged signal.

This makes powerd ignore the username argument in
SessionStateChanged D-Bus signals and RetrieveSessionState
responses.  It wasn't doing anything with them.

CQ-DEPEND=CL:48972
BUG=chromium:234763
TEST=manual: powerd's logs show changes to the session state
     after logging in or out

Change-Id: Iee2d9bb804348df5195246658f40c62bacee27ba
Reviewed-on: https://gerrit.chromium.org/gerrit/48958
Reviewed-by: Chris Masone <cmasone@chromium.org>
Tested-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Chris Masone <cmasone@chromium.org>

19 months agopower: Update displayed battery percentages. 14/48914/3
Daniel Erat [Tue, 16 Apr 2013 22:03:38 +0000 (15:03 -0700)]
power: Update displayed battery percentages.

This simplifies the previous "pin to 100% for three minutes,
then taper down to the actual percentage over seven minutes"
behavior when going from AC to battery with a full charge.
Instead, the charge at the point when the battery was
considered full is used as the high-water mark for the
entirety of the discharge cycle.  This avoids
discontinuities in the displayed percentage when connecting
and disconnecting AC power.

It also makes an improvement to a logging message that I
intended to include in a previous patch. :-/

I'm also sneaking in a small check to avoid negative
time-to-full durations if the battery reports a higher
charge than its supposedly maximum charge, which I appear to
have just seen on a Pixel PVT device.

BUG=chromium:230112
TEST=updated tests; manually tested that levels are
     continuous when switching between AC and battery power
     near 100%

Change-Id: Ic06e6aea4eaf5a80df43aef527e3139601914eaf
Reviewed-on: https://gerrit.chromium.org/gerrit/48914
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
19 months agoAdd script to help testing dark resume: 35/48835/2
Derek Basehore [Mon, 22 Apr 2013 22:45:04 +0000 (15:45 -0700)]
Add script to help testing dark resume:

This script functions like the set_short_powerd_timeouts script. It can be used
to quickly activate or deactivate dark resume with a short suspend duration on a
dev or test image.

BUG=None
TEST=run script then suspend

Change-Id: I735e6dff129125cde950c756b823b7d5c90bf1c6
Reviewed-on: https://gerrit.chromium.org/gerrit/48835
Reviewed-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
19 months agopower: Use different backlight levels for AC and battery. 48/48648/2
Daniel Erat [Thu, 18 Apr 2013 02:31:28 +0000 (19:31 -0700)]
power: Use different backlight levels for AC and battery.

This updates the ambient-light-derived brightness levels to
be 80% and 100% while on AC and 63% and 80% while on
battery.  (The 63% value is chosen to roughly correspond
with the 40%-computed-linearly of the maximum brightness
that the backlight is set to while the boot splash screen is
displayed -- the actual number varies depending on the
minimum-visible-level.)

BUG=chromium:188826
TEST=manual: ambient-light-derived level changes when
     connecting and disconnect AC adapter

Change-Id: I265d68bbbaad2a35310aea7a6e4d0a5119fc5fd6
Reviewed-on: https://gerrit.chromium.org/gerrit/48648
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
19 months agopower: Move more battery code out of powerd.cc. 57/48457/3
Daniel Erat [Tue, 16 Apr 2013 22:03:38 +0000 (15:03 -0700)]
power: Move more battery code out of powerd.cc.

This moves the rest of the power-status-related code
(specifically, time-averaging, percent-pinning/tapering, and
low-battery-detection) out of powerd.cc and into the
PowerSupply class.

It also refactors some redundant testing code.

BUG=chromium:221746,chromium:231731,chromium:220522
TEST=added unit tests

Change-Id: I1045d4549522a455934830463b5f32830103f621
Reviewed-on: https://gerrit.chromium.org/gerrit/48457
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
20 months agopower: Add ignore_external_policy pref. 25/48225/2 stabilize-4035.0.B
Daniel Erat [Mon, 15 Apr 2013 23:03:16 +0000 (16:03 -0700)]
power: Add ignore_external_policy pref.

This adds a pref to make powerd ignore PowerManagementPolicy
protobufs that are sent by Chrome.  Many autotests currently
write powerd prefs and depend on Chrome not having sent a
policy that overrides them; this would be problematic once
Chrome starts always sending policies.

BUG=chromium:225730
TEST=added a test

Change-Id: I8a54f3550555ce0e7ff2c3dd66b58b213285b26c
Reviewed-on: https://gerrit.chromium.org/gerrit/48225
Reviewed-by: Bartosz Fabianowski <bartfab@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
20 months agopower: Make AmbientLightHandler power-source aware. 84/48084/2 stabilize-4008.0.B
Daniel Erat [Sat, 13 Apr 2013 20:59:11 +0000 (13:59 -0700)]
power: Make AmbientLightHandler power-source aware.

This updates the AmbientLightHandler class to support
returning different brightness levels when on AC power vs.
battery power.  It's likely that we need this for the
internal panel's backlight.

A separate target percentage for battery power can be
specified in the second field of a line in the
internal_backlight_als_steps or keyboard_backlight_als_steps
prefs.  If only three fields are supplied, the percentage in
the first field is used for both AC and battery.

BUG=chromium:188826
TEST=added unit tests for AmbientLightHandler (it was
     previously only covered by KeyboardBacklightController
     and InternalBacklightController's tests); manually
     tested with a custom internal_backlight_als_steps pref

Change-Id: I4c2c761f70ab2b257d1491cc122ce757f88bc0a4
Reviewed-on: https://gerrit.chromium.org/gerrit/48084
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

20 months agopower: Rework ambient light handling for internal backlight. 46/47946/2
Daniel Erat [Wed, 10 Apr 2013 15:48:44 +0000 (08:48 -0700)]
power: Rework ambient light handling for internal backlight.

This updates InternalBacklightController's handling of
ambient light to be similar to that of
KeyboardBacklightController.  The AmbientLightHandler class
is used to read prefs and interpret sensor readings.  Only
two brightness steps are defined, with the upper one (100%)
intended to be used in high-ambient-light conditions (e.g.
direct sunlight).

It also prevents ambient-light-triggered adjustments from
being made after the user has used the brightness keys to
manually set the brightness.

BUG=chromium:188826,chromium:218269
TEST=updated and added unit tests.  also did manual testing:
     - when indoors, brightness level should remain constant
     - after moving outdoors, backlight should go to 100%
     - going back indoors should revert to earlier level
     - after pressing brightness keys, backlight shouldn't
       be automatically adjusted at all until reboot

Change-Id: I8fb25dfea3e44709aa90d25c818534210df4c646
Reviewed-on: https://gerrit.chromium.org/gerrit/47946
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
20 months agopower: Clean up RollingAverage. 67/47867/2
Daniel Erat [Thu, 11 Apr 2013 16:36:05 +0000 (09:36 -0700)]
power: Clean up RollingAverage.

This makes minor changes to RollingAverage (no functional
changes intended), simplifies its unit tests, and updates
powerd_unittest.cc to use real averages instead of
MockRollingAverage.

BUG=chromium:221746
TEST=updated tests

Change-Id: I47b328b2021d095438af0af4802a167b2ef6fa11
Reviewed-on: https://gerrit.chromium.org/gerrit/47867
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

20 months agopower: Fix crash in power-supply-info. 57/47857/2
Daniel Erat [Thu, 11 Apr 2013 14:42:13 +0000 (07:42 -0700)]
power: Fix crash in power-supply-info.

e8b7d447 updated the PowerSupply class to require that the
passed-in PrefsInterface be non-NULL but failed to update
the power-supply-info tool correspondingly.

BUG=chromium:230228
TEST=manual: power-supply-info doesn't crash

Change-Id: I74dfd53a9bf2ca13a7a149905607ea5eed4aa953
Reviewed-on: https://gerrit.chromium.org/gerrit/47857
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
20 months agopower: Don't dim keyboard for video on login screen. 74/47774/2
Daniel Erat [Wed, 10 Apr 2013 19:25:35 +0000 (12:25 -0700)]
power: Don't dim keyboard for video on login screen.

This updates KeyboardBacklightController to ignore reports
of fullscreen video that are received while the user isn't
logged in.  This prevents the keyboard backlight from being
turned off in response to login screen animations.

BUG=chromium:223698
TEST=added a test and confirmed that the keyboard backlight
     stays on when rapidly clicking back and forth between
     "Add user" and "Cancel" on the login screen

Change-Id: Ib54eb2b18cafb3925dad6dd2da7fc28f566d9248
Reviewed-on: https://gerrit.chromium.org/gerrit/47774
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

20 months agopower: Move polling code into PowerSupply. 89/47689/3
Daniel Erat [Wed, 3 Apr 2013 22:12:10 +0000 (15:12 -0700)]
power: Move polling code into PowerSupply.

This moves the code to poll the power status from powerd.cc
into the PowerSupply class.

BUG=chromium:221746
TEST=existing tests pass; added new tests; manually
     confirmed that power status is updated as expected

Change-Id: I800efd73de6dc2b8f6eff0e7c115191c127da01a
Reviewed-on: https://gerrit.chromium.org/gerrit/47689
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

20 months agopower: Split more powerd files between policy/ and system/. 35/47235/5
Daniel Erat [Wed, 3 Apr 2013 14:21:18 +0000 (07:21 -0700)]
power: Split more powerd files between policy/ and system/.

This moves BacklightController and its implementations,
Suspender, and SuspendDelayController to policy/ and moves
PowerSupply to system/.  It also moves the real
implementation of Suspender::Delegate from suspender.cc to
powerd.cc to break a weird dependency.

No functional changes are intended; this change only moves
files and updates namespaces and makefiles.

BUG=chromium:219551
TEST=compiles and tests pass

Change-Id: I2843b745160356e17dadb968729ac7d6a9ff733e
Reviewed-on: https://gerrit.chromium.org/gerrit/47235
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
20 months agopower: Add LID_NOT_PRESENT to LidState enum. 16/47016/3
Daniel Erat [Sun, 31 Mar 2013 14:10:28 +0000 (07:10 -0700)]
power: Add LID_NOT_PRESENT to LidState enum.

This cleans up lid-related code for systems that don't have
lids.  It adds a new enum value to represent the
lid-not-present case (LID_OPEN was inconsistently used
previously) and consolidates use of the use_lid pref.

BUG=chromium:195780
TEST=added unit test; manually verified that lumpy still
     suspends on lid closed and that docked mode works and
     that stumpy (no lid) behaves as before

Change-Id: I5ccec7aaa7e200d47245b903e920c7ce13febea6
Reviewed-on: https://gerrit.chromium.org/gerrit/47016
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

20 months agopower: Queue pref writes. 09/47009/4
Daniel Erat [Sun, 31 Mar 2013 01:20:26 +0000 (18:20 -0700)]
power: Queue pref writes.

This makes the Prefs class batch write requests so they're
done once per second.  Backlight prefs can be updated
frequently when the user drags the brightness slider.

It also changes some spammy inotify LOG(INFO)s to VLOG(1).

BUG=chromium:196308,chromium:220522
TEST=added unit tests; also manually tested that
     /var/lib/power_manager/plugged_brightness_offset is
     updated once per second while dragging the brightness
     slider

Change-Id: I007921c59fc82f5463a537a298439badf9a56112
Reviewed-on: https://gerrit.chromium.org/gerrit/47009
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

20 months agopower: Force backlight on for user activity. 69/46969/3
Daniel Erat [Sat, 30 Mar 2013 21:43:54 +0000 (14:43 -0700)]
power: Force backlight on for user activity.

This ensures that the panel backlight is turned on if the
user previously sets the brightness to zero but later begins
interacting with the computer again (but only if an external
display isn't connected).

Note that decreasing the brightness to zero and then
immediately hitting a key typically won't turn the backlight
back on; this is due to Chrome rate-limiting its reports of
user activity such that at most one is sent every five
seconds.  To avoid this, Chrome would probably need to
report every user action to powerd.

BUG=chromium:221303
TEST=added unit test; also manually tested

Change-Id: I48e2c29178edeb6b5f4af84b609edfa864f0dc35
Reviewed-on: https://gerrit.chromium.org/gerrit/46969
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

20 months agopower: Handle in-progress async I/O operations. 68/46968/2
Daniel Erat [Fri, 29 Mar 2013 00:03:56 +0000 (17:03 -0700)]
power: Handle in-progress async I/O operations.

This updates AsyncFileReader::Reset() to call aio_suspend()
to wait for the in-progress request to complete when
aio_cancel() returns AIO_NOTCANCELED to indicate that the
request was in-progress and couldn't be canceled.
Otherwise, the subsequent completion of the request can
cause a crash.

BUG=chromium:220740
TEST=powerd behaves the same as before.  also ran
     system_unittest in a loop with
     --gtest_filter='AsyncFileReaderTest.*:AmbientLightSensorTest.*'
     and observed that it didn't crash when the
     AIO_NOTCANCELED condition is hit

Change-Id: I58ba14aba87ae8af2cdafe9d964d8e33a739e376
Reviewed-on: https://gerrit.chromium.org/gerrit/46968
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

20 months agopower: Add support for docked mode. 17/46717/5
Daniel Erat [Mon, 25 Mar 2013 16:39:12 +0000 (09:39 -0700)]
power: Add support for docked mode.

This adds "docked mode", a state where the system avoids
suspending when the lid is closed while an external display
is connected.  When entering this mode, the internal panel
is also turned off while external displays are left on.

BUG=chromium:218387
TEST=added unit tests; also did manual testing using various
     hardware

Change-Id: I57ba627de1d32530efff76a24219c494bdfc3944
Reviewed-on: https://gerrit.chromium.org/gerrit/46717
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
20 months agopower: Turn backlight on when external display is unplugged. 17/46817/3
Daniel Erat [Thu, 28 Mar 2013 20:33:08 +0000 (13:33 -0700)]
power: Turn backlight on when external display is unplugged.

This ensures that the internal backlight is on after an
external display is disconnected.  It also moves the
handling of other cases where the backlight should be forced
on, such as session state change or power button being
pressed, into InternalBacklightController.

BUG=chromium:218387
TEST=added unit tests

Change-Id: I71a3ebc9c82e04c64bcc74655d5a0b4e95efd2a2
Reviewed-on: https://gerrit.chromium.org/gerrit/46817
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

20 months agopowerd: Send peripheral device battery info to Chrome through DBus 07/46707/6
Yufeng Shen [Wed, 27 Mar 2013 22:51:01 +0000 (18:51 -0400)]
powerd: Send peripheral device battery info to Chrome through DBus

Remove PeripheralBatteryWatcherObserver, instead send the peripheral
device battery status to Chrome directly from PeripheralBatteryWatcher
using DBus with protobuffer. Change the unittests accordingly.

BUG=chromium:221420
TEST=built it, and check that Chrome can receive this signal

Change-Id: Ia76e205056179549b2f6456418d02dcbab476e18
Reviewed-on: https://gerrit.chromium.org/gerrit/46707
Reviewed-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Yufeng Shen <miletus@chromium.org>
Tested-by: Yufeng Shen <miletus@chromium.org>
20 months agopower: Refactor DBusHandler class. 40/46640/6
Daniel Erat [Wed, 27 Mar 2013 00:39:00 +0000 (17:39 -0700)]
power: Refactor DBusHandler class.

This renames the class's files from util_dbus_handler.* to
dbus_handler.*, makes it use thunks instead of putting
implementation in static methods, removes a bunch of
redundant "DBus" strings from method, type, and variable
names, unifies its method call and signal handler to
eliminate some copy-and-pasted code, and makes its
name-owner-changed code take a regular callback instead of a
function pointer.

It also makes the Daemon class, rather than Suspender,
register for name-owner-changed notifications.
DisplayPowerSetter needs to receive notification when Chrome
is restarted so it can resend the desired state (this will
be done in a following change).

BUG=chromium:218387
TEST=unit tests pass; also did manual testing and verified
     that signals, method calls, and name-owner-changed
     notifications are handled as before

Change-Id: I37ee647d6bbc96b0f52d4c54f39cc26c341f7d0d
Reviewed-on: https://gerrit.chromium.org/gerrit/46640
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

20 months agopower: Avoid checking not-used battery times. 59/46559/2
Daniel Erat [Tue, 26 Mar 2013 20:50:14 +0000 (13:50 -0700)]
power: Avoid checking not-used battery times.

This makes powerd not check the time-until-empty value when
the battery is charging and not check time-until-full when
the battery is discharging.  We sometimes see garbage values
here, and they currently cause powerd to reject other valid
values.

BUG=chromium:223915
TEST=added unit test; manually tested that reasonable values
     are still displayed

Change-Id: I226ad2dac17d6cf656c7223371dd917262dcaca8
Reviewed-on: https://gerrit.chromium.org/gerrit/46559
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

20 months agopower: Use Chrome's SetDisplaySoftwareDimming method. 41/46441/3
Daniel Erat [Sat, 23 Mar 2013 20:07:16 +0000 (13:07 -0700)]
power: Use Chrome's SetDisplaySoftwareDimming method.

This makes powerd call the SetDisplaySoftwareDimming D-Bus
method exported by Chrome instead of emitting a
SoftwareScreenDimmingRequested signal.  It also cleans up
some avoiding-calling-D-Bus-functions-from-tests hackiness.

BUG=chromium:221391
TEST=manual; also updated unit tests

Change-Id: I75408326c35f2128ae0c0f5007700749594b1379
Reviewed-on: https://gerrit.chromium.org/gerrit/46441
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: St├ęphane Marchesin <marcheu@chromium.org>
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
20 months agopowerd: Calculate gmock/gtest library dependencies programatically 23/46423/4
Gaurav Shah [Sun, 24 Mar 2013 22:42:58 +0000 (15:42 -0700)]
powerd: Calculate gmock/gtest library dependencies programatically

(gmock/gtest doesn't generate pkg-config metadata, calculating lib
 dependencies this way makes it easier to upgrade gmock/gtest packages.)

BUG=chromium:211445
TEST=build tests for package using gtest 1.6

Change-Id: Ie565f1ca928e16fe5fc33a6dda3bb78c8b98948a
Reviewed-on: https://gerrit.chromium.org/gerrit/46423
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Gaurav Shah <gauravsh@chromium.org>
Commit-Queue: Gaurav Shah <gauravsh@chromium.org>

20 months agopower: Add WARN_UNUSED_RESULT to some testing code. 34/46434/4
Daniel Erat [Mon, 25 Mar 2013 21:15:05 +0000 (14:15 -0700)]
power: Add WARN_UNUSED_RESULT to some testing code.

This fixes a test in StateControllerTest that wasn't
checking the return values from some helper methods that it
called and adds the WARN_UNUSED_RESULT annotation to these
methods so the same mistake can't be made in the future.

BUG=none
TEST=ran tests

Change-Id: I611e88284f09cee8d9c86c9ef56299e60b807059
Reviewed-on: https://gerrit.chromium.org/gerrit/46434
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
20 months agopower: Add AmbientLightHandler. 71/46371/4
Daniel Erat [Sat, 23 Mar 2013 21:02:35 +0000 (14:02 -0700)]
power: Add AmbientLightHandler.

This moves KeyboardBacklightController's
ambient-light-sensor-related code into a separate
AmbientLightHandler class, with the goal of this code
eventually being shared with InternalBacklightController.
No functional changes are intended.

BUG=chromium:188826,chromium:218269
TEST=existing tests pass; manually checked that keyboard
     backlight ALS adjustments happen as before

Change-Id: I1d1e65b48f3d428c5871158730ebd34a8169e8e6
Reviewed-on: https://gerrit.chromium.org/gerrit/46371
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

20 months agopower: Avoid dimming, suspending, etc. while on VT2. 57/46357/4
Daniel Erat [Thu, 21 Mar 2013 21:43:48 +0000 (14:43 -0700)]
power: Avoid dimming, suspending, etc. while on VT2.

This makes powerd check the currently-active virtual
terminal once per minute and treat VT2 as an indication of
user activity.  It also replaces some static callbacks in
the Input class with thunks and moves a bit of code from the
still-too-big Daemon class into InputController.

Note that the terminal will still be blanked eventually if
the user is truly inactive (i.e. no keys are pressed), but
this isn't powerd's doing.

BUG=chromium:202736
TEST=manual: powerd's power management doesn't kick in while
     on VT2

Change-Id: I3fab035694b2f3ceed17c03776002dc35f04bba4
Reviewed-on: https://gerrit.chromium.org/gerrit/46357
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

20 months agopower: Remove StateControl and GetIdleTime. 61/46361/3
Daniel Erat [Thu, 21 Mar 2013 18:45:04 +0000 (11:45 -0700)]
power: Remove StateControl and GetIdleTime.

This removes the StateControl class, which used to track
overrides that used to be sent by Chrome.  Chrome just
incorporates these in the more-comprehensive power
management policy messages that it sends to powerd now.

It also removes the GetIdleTime D-Bus method.  Chrome
tracks the idle time itself now instead of asking powerd for
it.

BUG=chromium:176405,chromium:178908
TEST=did a build
TBR=cmasone@chromium.org
CQ-DEPEND=I548599d3ade6396c4e913594ad6944e65a9c85f0

Change-Id: I76373cb22a40347aa6a3f011ef250481799ddf55
Reviewed-on: https://gerrit.chromium.org/gerrit/46361
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
21 months agopower: Don't send idle warning when idle action is unset. 74/46274/2
Daniel Erat [Fri, 22 Mar 2013 14:56:25 +0000 (07:56 -0700)]
power: Don't send idle warning when idle action is unset.

This makes powerd avoid sending the idle-imminent message
when the idle action is unset, and also send the
idle-deferred message at the point of the action being
unset.

BUG=chromium:223089
TEST=added unit tests

Change-Id: Id88aef6aa61075ba263324815aaeeca942a5a00f
Reviewed-on: https://gerrit.chromium.org/gerrit/46274
Reviewed-by: Bartosz Fabianowski <bartfab@chromium.org>
Tested-by: Bartosz Fabianowski <bartfab@chromium.org>
Commit-Queue: Bartosz Fabianowski <bartfab@chromium.org>

21 months agopower: Scale idle warning delay when presenting. 31/46131/2
Daniel Erat [Thu, 21 Mar 2013 16:35:26 +0000 (09:35 -0700)]
power: Scale idle warning delay when presenting.

This makes the idle-warning delay get scaled in a manner
similar to the other delays when in presentation mode.

BUG=chromium:195560
TEST=added unit test

Change-Id: Id11a6268564fa86f3f7ff3d8a323132230a9d683
Reviewed-on: https://gerrit.chromium.org/gerrit/46131
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Bartosz Fabianowski <bartfab@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

21 months agopower: Add suspend_at_login_screen pref. 40/46040/4
Daniel Erat [Wed, 20 Mar 2013 21:36:16 +0000 (14:36 -0700)]
power: Add suspend_at_login_screen pref.

This adds a new pref that can be set to configure powerd to
suspend due to user inactivity at the login screen instead
of shutting down.

BUG=chromium:216299
TEST=added unit test

Change-Id: I508aca33f454ff780676064046f626c566727462
Reviewed-on: https://gerrit.chromium.org/gerrit/46040
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
21 months agopower: Log reasons associated with policies. 98/45998/2
Daniel Erat [Wed, 20 Mar 2013 15:41:26 +0000 (08:41 -0700)]
power: Log reasons associated with policies.

This makes powerd log the "reason" field from
PowerManagementPolicy protocol buffer messages.

BUG=chromium:176405
TEST=manual: reasons get logged when chrome sets them
CQ-DEPEND=I2b8522ea6f64bad985b6efdfbda3f74f0799ae3e
TBR=bartfab@chromium.org

Change-Id: I13598fe5b1fb012421499a121f8dd67b8074be96
Reviewed-on: https://gerrit.chromium.org/gerrit/45998
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Bartosz Fabianowski <bartfab@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

21 months agopower: Rework BacklightController interface. 72/45372/7 stabilize-3881.0.B
Daniel Erat [Fri, 15 Feb 2013 01:02:28 +0000 (17:02 -0800)]
power: Rework BacklightController interface.

This makes large changes to the BacklightController
interface and its three implementations,
InternalBacklightController, ExternalBacklightController,
and KeyboardBacklightController.  (This commit message is
correspondingly large.)

Previously, the interface declared a SetPowerState() method
that took an enum value describing various states (active,
dimmed, suspended, active-but-manually-set-to-zero, shutting
down, etc.).  This let implementation details leak into
outside classes and greatly complicated BacklightController
implementations: InternalBacklightController had nested
if-else statements to e.g. enter the suspended state
differently depending on whether it was previously in the
off-for-inactivity state vs. the active state.

This change makes BacklightController instead expose methods
such as SetDimmedForInactivity(), SetSuspended(),
SetShuttingDown(), etc.  Implementations are responsible for
handling the interactions between the various states that
are set at any given time.

Along with this comes refactoring to simplify the
implementations.  KeyboardBacklightController initially
supported arbitrary brightness levels but now just moves
between predefined steps for ambient-light-sensor- and
user-determined levels; I've changed the code to reflect
that (e.g. no need to keep a second copy of the current
brightness in |user_target_percent_dim_| and
|als_target_percent_dim_|).

InternalBacklightController similarly duplicated state
between e.g. |target_percent_| and |target_level_|.  This
change makes the distinction between the currently-used
level (which may be dictated by whether the backlight dimmed
or off for inactivity) and the user-requested and
ALS-requested levels clearer.

I've also refactored the unit tests for the implementations
to eliminate boilerplate, remove duplicate checks, and
improve coverage of untested areas.

BUG=chromium-os:38922,chromium-os:39289,chromium-os:39045
TEST=updated/rewrote unit tests; manual testing

Change-Id: Iaf3daab53749f9db13c97e2eabe71a01072a6a28
Reviewed-on: https://gerrit.chromium.org/gerrit/45372
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>

21 months agopower: Add support for emitting pre-idle warning. 04/45804/3
Daniel Erat [Mon, 18 Mar 2013 22:08:41 +0000 (15:08 -0700)]
power: Add support for emitting pre-idle warning.

This makes powerd honor |idle_warning_ms| delays in
PowerManagementPolicy messages sent by Chrome.  After the
delay, an IdleActionImminent D-Bus signal is emitted.  If
the system leaves the inactive state before the idle action
is performed, an IdleActionDeferred D-Bus signal is emitted.

BUG=chromium:195560
TEST=added unit tests; also manually tested that signals are
     sent as expected using set_power_policy and
     dbus-monitor
CQ-DEPEND=Ie7ce73c72078da3cb757879a4097324828ba4205

Change-Id: Idaceca9a910fe4e45f3c75e3ff460076ca1f0860
Reviewed-on: https://gerrit.chromium.org/gerrit/45804
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Bartosz Fabianowski <bartfab@chromium.org>
21 months agopower: Miscellaneous testing-related cleanup. 42/45342/2 factory-spring-3842.B
Daniel Erat [Wed, 13 Mar 2013 21:01:36 +0000 (14:01 -0700)]
power: Miscellaneous testing-related cleanup.

This updates common/testrunner.cc to initialize the base
library's command-line and logging code so that GTEST_ARGS
can be used to pass logging- and testing-related flags when
emerging the package with FEATURES=test (e.g. it can be set
to a string that includes --gtest_filter and --vmodule).

It also makes minor additions to several stub classes in
anticipation of a larger change:
BacklightStub::clear_resume_level() resets the
previously-set resume level, and DisplayPowerSetterStub
counts the number of times that SetDisplayPower() has been
called.

BUG=none
TEST=builds and unit tests still pass

Change-Id: I673f5f0dce67168b8d62b4d30c1237abd023f89e
Reviewed-on: https://gerrit.chromium.org/gerrit/45342
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
21 months agopower: Ignore HandleUserActivity arguments. 17/45317/3
Daniel Erat [Wed, 13 Mar 2013 04:48:25 +0000 (21:48 -0700)]
power: Ignore HandleUserActivity arguments.

This makes powerd stop checking for arguments in
HandleUserActivity D-Bus method calls.  It no longer uses
the timestamp argument, which can be onerous for clients to
create.

BUG=none
TEST=manual: user activity is still reported by chrome
TBR=dnschneid@chromium.org

Change-Id: Ide8432eae500ff8833a9fc88a0f5a8783ab21cc5
Reviewed-on: https://gerrit.chromium.org/gerrit/45317
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: David Schneider <dnschneid@chromium.org>
21 months agoAdd disabling of dark resume 96/44996/5 firmware-spring-3833.B
Derek Basehore [Fri, 8 Mar 2013 21:08:31 +0000 (13:08 -0800)]
Add disabling of dark resume

To prevent dark resume from breaking suspend autotests, this change adds a pref
that is added for test images. It disables dark resume when this pref is set to
non-zero. This also sets the values of the dark resume sysfs files to disabled
when dark resume is disabled and when DarkResumePolicy is destroyed. This
prevents stale information from restarts and crashes of powerd from persisting.

suspend_stress_test is modified to disable dark resume since it can be run on a
dev image.

dark_resume_policy_unittest is modified to test that this new functionality
works.

BUG=chromium-os:39707
TEST=suspend_stress_test, power_UiResume, power_Resume

Change-Id: I3f31086e5138d317d9293d9130fbec5a81678058
Reviewed-on: https://gerrit.chromium.org/gerrit/44996
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
Commit-Queue: Derek Basehore <dbasehore@chromium.org>