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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Derek Basehore [Sat, 23 Feb 2013 02:25:59 +0000 (18:25 -0800)]
Use dark resume and move parts of powerd_suspend
This makes the suspender class use dark resume to resuspend or shutdown if we
perform a dark resume. It also moves muting the system and sending out the
PowerStateChanged signal through the dbus to powerd. This allows the suspender
class to call powerd_suspend again after waking up from a dark resume without
messing with other programs through the PowerStateChanged signal. It also lets
us not store state in some file for whether the system was muted for when we
call powerd_suspend again.
This also modifies suspender_unittest.cc to take into account the changes to
suspender.cc
BUG=chromium-os:39284
TEST=Suspend system
Change-Id: I4d5ff09c277c22c2324f59e8e9b7bb0cc7c54ce7
Reviewed-on: https://gerrit.chromium.org/gerrit/43876
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
Commit-Queue: Derek Basehore <dbasehore@chromium.org>
Derek Basehore [Sat, 23 Feb 2013 00:52:44 +0000 (16:52 -0800)]
Rename and add muting functions to audio_detector
Rename audio_detector to audio_client. This is because adding muting
functionality to the class makes detector a bad descriptor of what the class can
do. The muting functions are added so we can mute the system in powerd instead
of powerd_suspend.
BUG=chromium-os:39284
TEST=Suspend system
Change-Id: Ic511268e4a850196a2ebea37a0c0730073a5f3c3
Reviewed-on: https://gerrit.chromium.org/gerrit/43875
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
Commit-Queue: Derek Basehore <dbasehore@chromium.org>
Derek Basehore [Sat, 23 Feb 2013 00:57:10 +0000 (16:57 -0800)]
Add DarkPolicy class and unittests
This class contains all of the functionality to keep track of preferences for
and determine how long the system suspends for. It also determines when we
should shutdown based on battery state. With the exception of the constructor,
the interface is designed so the caller does not know what other classes may be
used to determine these things.
BUG=chromium-os:39284
TEST=Suspend system
Change-Id: Ifaa4187d838bb89c0525900534761e3120bc9778
Reviewed-on: https://gerrit.chromium.org/gerrit/43874
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
Commit-Queue: Derek Basehore <dbasehore@chromium.org>
Yufeng Shen [Mon, 4 Mar 2013 22:50:06 +0000 (17:50 -0500)]
power: Polling battery info from exteranl HID devices
Some external HID devices, e.g. Apple Magic Mouse, expose battery
information under sysfs /sys/class/power_supply. This patch adds
a DeviceBattery class to poll those battery level information into
powerd.
BUG=chromium-os:39317
TEST=Connect CrOS device with Apple Magic Mouse & Trackpad, check msgs
in powerd.LATEST like:
"
Got battery update from /sys/class/power_supply/hid-B8:17:C2:9C:74:77-battery:Apple Magic Mouse with battery level 89
Got battery update from /sys/class/power_supply/hid-7C:C3:A1:47:1E:8B-battery:miletus’s Trackpad with battery level 50
"
TEST=Turn off the Apple Magic Mouse, check msgs like
"
Error during read of file /sys/class/power_supply/hid-B8:17:C2:9C:74:77-battery/capacity, status=5
Got error on reading battery level for /sys/class/power_supply/hid-B8:17:C2:9C:74:77-battery:Apple Magic Mouse
"
Change-Id: If1722f050d6603f6e235a6ef133c48642a400f71
Reviewed-on: https://gerrit.chromium.org/gerrit/44879
Commit-Queue: Yufeng Shen <miletus@chromium.org>
Reviewed-by: Yufeng Shen <miletus@chromium.org>
Tested-by: Yufeng Shen <miletus@chromium.org>
Yufeng Shen [Fri, 8 Mar 2013 20:45:50 +0000 (15:45 -0500)]
power: fix timeout leak in internal_backlight_unittest
In unittest InternalBacklightTest::Transitions we call the
transition timeout callback explicitly using
TriggerTransitionTimeoutForTesting(). In that case, the return
value from the callback HandleTransitionTimeout() is not actually
returned to the glib mainloop, so we may not cancel the timeout
while we finish the test. And the callback can be executed while
following tests are running which will cause very confusing failure
in the following tests. This might also contribute to
http://crosbug.com/38732
BUG=chromium-os:38732
TEST=unittests don't crash.
Change-Id: I9c753db619375f4badb85e02826fa3d80673f6b7
Reviewed-on: https://gerrit.chromium.org/gerrit/44962
Reviewed-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Yufeng Shen <miletus@chromium.org>
Tested-by: Yufeng Shen <miletus@chromium.org>
Daniel Erat [Fri, 8 Mar 2013 15:07:27 +0000 (07:07 -0800)]
power: AmbientLightSensor refactoring.
This adds an AmbientLightSensorStub class to remove some
more repetitive GMock calls. It also moves
AmbientLightSensor and AsyncFileReader to the system/
subdirectory, makes BacklightController implementations
inherit from AmbientLightObserver instead of having
BacklightController itself inheriting from it, and removes a
few obsolete VideoDetector-related headers.
BUG=chromium-os:38922
TEST=unit tests pass
Change-Id: I9ba7b1f720b2473ddb49b97f0ccdade64f6a0d63
Reviewed-on: https://gerrit.chromium.org/gerrit/45023
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Chris Masone [Sat, 9 Mar 2013 00:56:57 +0000 (16:56 -0800)]
libpowerd needs librt; specify this dependency
aio_* is part of librt, and libpowerd uses this functionality directly.
As such, it should specify this in powerd/module.mk instead of
inheriting the dependency from dbus-glib as it was before.
BUG=chromium-os:39738
TEST=emerge-amd64-generic power_manager with dbus-glib roll CLs patched in.
Change-Id: I5e107d366a491b57d01e325ed7d85d3048a291ac
Reviewed-on: https://gerrit.chromium.org/gerrit/44998
Tested-by: Chris Masone <cmasone@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Chris Masone <cmasone@chromium.org>
Daniel Erat [Thu, 7 Mar 2013 21:19:07 +0000 (13:19 -0800)]
power: Avoid suspending while the system is being updated.
This makes powerd listen for StatusUpdate D-Bus signals
emitted by the update engine so it can avoid suspending the
system while an update is being downloaded or applied (only
on AC power).
It also adds a helper method for some delay-triggered code
that was copied-and-pasted across a bunch of tests.
BUG=chromium-os:20502,chromium-os:39706,chromium-os:39700
TEST=added a unit test; also manually checked that idle
action went to no-op while downloading and applying an
update and returned to suspend after it was applied,
and also returned to suspend eventually after pulling
the network connection mid-download
Change-Id: I5b045ab7ccfef99f425b50d96438b44d0f1277c2
Reviewed-on: https://gerrit.chromium.org/gerrit/44873
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Daniel Erat [Thu, 28 Feb 2013 04:41:32 +0000 (20:41 -0800)]
power: Rename MonitorReconfigure to DisplayPowerSetter.
This renames the MonitorReconfigure class to
DisplayPowerSetter and makes it take a single enum value
describing the desired state (e.g. "all displays on",
"internal display off and external displays on", etc.)
instead of its previous all-displays vs. internal-only and
on vs. off parameters.
It also moves InternalBacklightController's display-state
timeout code into DisplayPowerSetter and adds a
DisplayPowerSetterStub implementation for unit tests.
BUG=chromium-os:39289
TEST=updated unit tests and did manual testing
Change-Id: I70ae4e7bd2021ca71ecf8e35987a660f30c49543
Reviewed-on: https://gerrit.chromium.org/gerrit/44341
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Daniel Erat [Wed, 6 Mar 2013 23:49:01 +0000 (15:49 -0800)]
power: Don't pin or taper battery percentage after resuming.
powerd pins the battery percentage at 100% when AC is
disconnected while the battery is full and then gradually
interpolates to the level being reported by the battery.
When the system is suspended while on battery power, the
level will decrease further, however. This change makes
powerd exit the pinned and intepolating/tapered states after
resuming so accurate levels will be reported.
BUG=chromium-os:38834
TEST=manual: disconnected AC at 100% on pixel, closed lid,
resumed a bit later, and observed that status area
updated to lower percentage immediately instead of
staying at 100%
Change-Id: Ica4dec69d69c0d1e63588b37565b6be96ef1fa16
Reviewed-on: https://gerrit.chromium.org/gerrit/44775
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Ryan Harrison [Tue, 5 Mar 2013 15:58:37 +0000 (10:58 -0500)]
power_manager: Reset all of ALS state when becoming active & initialized
This changes the name of the reset method from ResetHysteresis ->
ResetAls. Additionally this function now sest the ALS level to the current level
of the device and adjusts related variables.
This is needed, because when we become active the system is going to apply the
current ALS level. Currently the code just reapplies the old value, but if light
was on before, but should no longer be on, then the light will go
dim->on->off. By setting the ALS level to the dim level we are effectively
transitioning dim->dim->off in this case. There is also an issue with the
backlight being sticky in this situation that this fix resolves.
BUG=chrome-os-partner:17935
TEST=On a link device let device idle in a dark enough room for the backlight to
be on. Take into a bright environment, then interact with the device so it
comes out of idle. The expected behaviour is the backlight should make a
single transition from the dim state to off if it isn't already off. Repeat
starting bright and going to dark. There should be a single transition from
dim/off to on.
Change-Id: I84541b12834f4381ec7ed228049c3cea04cb2c18
Reviewed-on: https://gerrit.chromium.org/gerrit/44655
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Tested-by: Ryan Harrison <rharrison@chromium.org>
Daniel Erat [Mon, 4 Mar 2013 22:58:42 +0000 (14:58 -0800)]
power: Remove harmless typo from 2010.
This fixes some code that's attempting to check the return
value from a call to file_util::WriteFile(). Without this,
builds using CFLAGS="-clang" CXXFLAGS="-clang" fail.
BUG=none
TEST=manual: builds and tests pass
TBR=tbroch@chromium.org
Change-Id: I9384fc448d9dc4205899e721f6336a24c469290f
Reviewed-on: https://gerrit.chromium.org/gerrit/44571
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Daniel Erat [Mon, 4 Mar 2013 17:10:35 +0000 (09:10 -0800)]
power: Remove deprecated prefs.
This removes several screen-lock and idle-timeout prefs that
are no longer used by powerd.
BUG=chromium-os:38281,chromium-os:38732
TEST=unit tests pass
Change-Id: If3349d093762a499b503a5d01ae720332af92add
Reviewed-on: https://gerrit.chromium.org/gerrit/44527
Reviewed-by: Benson Leung <bleung@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Daniel Erat [Mon, 4 Mar 2013 18:13:14 +0000 (10:13 -0800)]
power: Make RequestSuspend be a method instead of a signal.
This updates powerd's RequestSuspend signal (currently only
emitted by the powerd_dbus_suspend tool) to instead be a
method.
It also fixes a bug in powerd_dbus_suspend where --timeout=0
would always result in a LOG(FATAL) rather than the
(presumably) intended wait-indefinitely behavior -- calling
'continue' in a do-while results in the while condition
being evaluated.
BUG=chromium:179713
TEST=powerd_dbus_suspend works with various timeout values
CQ-DEPEND=Ib7e15923355e499346029d4f9d3e59c52848d2ce
Change-Id: I0bb7c80073b4fe437f08c75370744c436fefa96e
Reviewed-on: https://gerrit.chromium.org/gerrit/44530
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Sameer Nanda <snanda@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Yufeng Shen [Thu, 28 Feb 2013 23:01:44 +0000 (18:01 -0500)]
power: A fix for power supply of external device
This kernel patch
http://git.kernel.org/?p=linux/kernel/git/stable/linux-stable.git;a=commit;h=
25a0bc2dfc2ea732f40af2dae52426ead66ae76e
adds a way to tell a system battery from a device battery through a
"scope" attribute.
Currently GetPowerSupplyPaths() is only meant to find the path for
system battery. So to avoid accidentally identifying battery of
external device as system battery, skip the power supply which has
"scope" attribute with value "Device".
BUG=chromium-os:39317
TEST=connet Apple Magic Trackpad/Mouse, restart powerd, see logs
in powerd.LATEST like
Power supply /sys/class/power_supply/hid-7C:C3:A1:47:1E:8B-battery found with scope: Device
Power supply /sys/class/power_supply/hid-B8:17:C2:9C:74:77-battery found with scope: Device
Change-Id: I529c1ecb40bfd2ff1cc56835e007838e33f9e66f
Reviewed-on: https://gerrit.chromium.org/gerrit/44327
Commit-Queue: Yufeng Shen <miletus@chromium.org>
Reviewed-by: Yufeng Shen <miletus@chromium.org>
Tested-by: Yufeng Shen <miletus@chromium.org>
Ryan Harrison [Wed, 27 Feb 2013 20:43:03 +0000 (15:43 -0500)]
power_manager: Reset hysteresis state when returning to active state.
Since ALS based transitions are supressed while we are in a non-active state
like idle some of the transitions maybe missed. This leads to cases where if the
ambient light levels change while we are non-active the backlight might not do
what the user expects when becoming active. The solution for this is reset the
state of the hysetersis, so that we can run what ever transition is approriate
now.
BUG=chrome-os-partner:17935
TEST=On link device let device idle in bright room, so the backlight is
off. Cover the ALS sensor, then interact witht eh device so it comes out of
idle. The expected behaviour is the backlight should turn on again.
Change-Id: Ib3f45442b016ffec283226be78777d742b4716c4
Reviewed-on: https://gerrit.chromium.org/gerrit/44206
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Daniel Erat [Wed, 27 Feb 2013 01:41:19 +0000 (17:41 -0800)]
power: Replace MockBacklight with BacklightStub.
This moves ExternalBacklightControllerTest's TestBacklight
class to a separate file and renames it to
system::BacklightStub. It updates existing tests to use
this class instead of MockBacklight, which cuts down on a
bunch of gMock boilerplate.
It also moves plug_dimmer_unittest.cc and
idle_dimmer_unittest.cc's tests into
internal_backlight_controller_unittest.cc, with a few minor
changes to remove redundancy and improve coverage.
BUG=chromium-os:38922
TEST=unit tests pass
Change-Id: Ie74281d34213e4d20a4f8fc353af1591ed3154bc
Reviewed-on: https://gerrit.chromium.org/gerrit/44183
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Daniel Erat [Wed, 27 Feb 2013 01:26:26 +0000 (17:26 -0800)]
power: Make BacklightInterface support multiple observers.
This replaces BacklightInterface's set_observer() method
with the standard AddObserver/RemoveObserver() pattern using
ObserverList.
BUG=chromium-os:38922
TEST=unit tests pass
Change-Id: I51d76a0ed813e5e5799825bffeccd85e3e16d82f
Reviewed-on: https://gerrit.chromium.org/gerrit/44130
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Daniel Erat [Tue, 26 Feb 2013 21:52:04 +0000 (13:52 -0800)]
power: Update to libchrome-180609.
BUG=chromium-os:38944
TEST=unit tests pass; powerd seems to work as before
CQ-DEPEND=I816825055aa646e226c9004864605e95aab704c1
Change-Id: I9204f2a8812942aa89e409ece7d4d78733734ac7
Reviewed-on: https://gerrit.chromium.org/gerrit/44088
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Daniel Erat [Sat, 23 Feb 2013 20:59:36 +0000 (12:59 -0800)]
power: Remove BacklightController::SetMonitorReconfigure().
This removes BacklightController::SetMonitorReconfigure() in
favor of just passing a MonitorReconfigure object to the
constructor of each BacklightController implementation that
needs it. Doing so removes unneccesary and
inconsistently-done NULL checks and removes no-op
SetMonitorReconfigure() implementations for e.g.
KeyboardBacklightController.
BUG=none
TEST=unit tests pass
Change-Id: I7181bce1fcd72f3c8ff259d7704721caef1d6c49
Reviewed-on: https://gerrit.chromium.org/gerrit/43868
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Shawn Nematbakhsh [Mon, 25 Feb 2013 19:53:05 +0000 (11:53 -0800)]
power: Update suspend_stress_test to ignore a specific firmware error.
suspend_stress_test greps the firmware log for the string "ERROR".
Unfortunately, we have a print in Coreboot that contains the string
"ERROR", yet is not a fatal error or an error at all. It causes
suspend_stress_test to prematurely abort on certain platforms.
Fix this by ignoring this one specific error string. We are also
changing the string in Coreboot for future firmware builds.
TEST=Manual. Verify suspend_stress_test doesn't abort on Stout.
BUG=chrome-os-partner:17973.
Change-Id: I982f965b9e8513071276008c7e0f69f07d381360
Reviewed-on: https://gerrit.chromium.org/gerrit/43920
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Shawn Nematbakhsh <shawnn@chromium.org>
Tested-by: Shawn Nematbakhsh <shawnn@chromium.org>
Daniel Erat [Wed, 20 Feb 2013 15:40:05 +0000 (07:40 -0800)]
power: Ignore lock_on_idle_suspend and lock_ms prefs.
This removes a couple of screen-locking-related preferences.
Chrome currently writes its "Require password to wake from
sleep" setting to the power manager's prefs dir, but this is
no longer needed; Chrome now initiates screen-locking itself
when the system is about to suspend, and the
lock-long-before-suspending behavior that could be achieved
with lock_ms apparently isn't needed by default (and can now
be explicitly set by Chrome via an enterprise policy).
BUG=chromium-os:38732
TEST=updated unit tests. manually tested that chrome's
setting works as before and that the screen is locked
after 15 seconds when a policy is set with
"set_power_policy --ac_screen_dim_delay=10
--ac_screen_lock_delay=15 --ac_screen_off_delay=0"
Change-Id: I1d83eedfe490a9610e65cd48fa47d1d921fe779b
Reviewed-on: https://gerrit.chromium.org/gerrit/43728
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Daniel Erat [Wed, 20 Feb 2013 17:22:35 +0000 (09:22 -0800)]
power: Increase logging during AmbientLightSensorTest.
This makes AsyncFileReader log more details during
AmbientLightSensorTest, with the hope that it'll make it
easier to track down the cause of "corrupted double-linked
list" crashes in glibc that occasionally show up on the
builders.
I'm also fixing a (probably harmless)
use-before-initialization in AmbientLightSensor.
BUG=chromium-os:38609
TEST=ran tests
Change-Id: Ie860b0137e52c71da31138ca50c7fe9a675c5288
Reviewed-on: https://gerrit.chromium.org/gerrit/43613
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Daniel Erat [Thu, 21 Feb 2013 02:10:16 +0000 (18:10 -0800)]
power: Don't shut down for reports of 0% battery.
This changes powerd's low-battery shutdown method to ignore
battery levels that are very close to zero in an attempt to
work around spurious low-battery reports at boot.
In the normal case, when the battery level is falling on an
already-running system, we should still shut down long
before we approach 0%.
BUG=chromium-os:38912
TEST=manual: powerd shuts down as before after draining the
battery, and the device shuts down at boot (or soon
after) when powered on after that
Change-Id: I89c174b6296bc679fd01c36c73bb65aa5fb5e573
Reviewed-on: https://gerrit.chromium.org/gerrit/43686
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Daniel Erat [Fri, 15 Feb 2013 01:12:54 +0000 (17:12 -0800)]
power: Share StateController constants.
This promotes some commonly-used constants (e.g. lid state,
button state, session state, display presentation mode,
etc.) to power_constants.h. Sharing these among classes
prevents implementation details from leaking out across the
code (for example, the Input class was returning raw
integers that it got back from an ioctl).
It also separates InputObserver::OnInputEvent() into
separate OnLidEvent() and on OnPowerButtonEvent() methods,
which removes some ugliness where the same enum was being
used to report lid states and button states.
BUG=none
TEST=builds and tests pass; behaves as before with manual
testing
Change-Id: Ib716836c55319042cd6d4492ea7c775d600f3234
Reviewed-on: https://gerrit.chromium.org/gerrit/43602
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Daniel Erat [Mon, 11 Feb 2013 21:03:58 +0000 (13:03 -0800)]
power: Change suspend retry delay to 10 seconds.
This decreases the retry interval after a failed suspend
attempt from sixty seconds to ten seconds.
BUG=chromium-os:38907,chrome-os-partner:17533
TEST=manual: made powerd_suspend always fail and check that
idle-suspend is retried after 10 seconds (lid-closed
suspend is retried immediately now because of a
separate change to work around missing lid-open events)
Change-Id: Iba5940962a196cf16c3bfdb5dc992d31eb7cb0d0
Reviewed-on: https://gerrit.chromium.org/gerrit/43587
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Sameer Nanda <snanda@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Daniel Erat [Tue, 19 Feb 2013 17:30:44 +0000 (09:30 -0800)]
power: Watch disable_idle_suspend pref for changes.
This makes powerd watch the disable_idle_suspend pref for
changes at runtime to make manual testing a bit easier.
BUG=chromium-os:32240
TEST=added a unit test and manually tested that changes are
applied
Change-Id: I5c0d32a1bc81ce63ecde6c371fd01a93d0913be1
Reviewed-on: https://gerrit.chromium.org/gerrit/43575
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Daniel Erat [Fri, 15 Feb 2013 02:41:32 +0000 (18:41 -0800)]
powerd: Delete old code replaced by StateController.
This deletes the IdleDetector, ScreenLocker, and
VideoDetector classes and removes a bunch of code in
powerd's Daemon class that has been replaced by the
StateController class.
BUG=chromium-os:38281
TEST=unit tests pass; manually confirmed that keyboard
backlight turns off for fullscreen video as before
Change-Id: I907961a647aabf99d8d07793469cf07abf51362e
Reviewed-on: https://gerrit.chromium.org/gerrit/43471
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Sameer Nanda [Thu, 14 Feb 2013 21:07:11 +0000 (13:07 -0800)]
power: Refresh mosys eventlog upon resuming
Refresh the mosys eventlog on resuming. This helps get the latest
snapshot of mosys eventlog included in feedback reports.
BUG=chromium-os:38734
TEST=do a suspend-resume cycle. Then open up "eventlog" under
chrome://system. The last entry in eventlog should correspond to the
resume that just happened.
Change-Id: I26c70c7c58ce11bc69082c73aee12742821bd675
Reviewed-on: https://gerrit.chromium.org/gerrit/43302
Reviewed-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Sameer Nanda <snanda@chromium.org>
Tested-by: Sameer Nanda <snanda@chromium.org>
Daniel Erat [Thu, 7 Feb 2013 03:18:54 +0000 (19:18 -0800)]
power: Make suspend code work around strange lid events.
This makes powerd handle two edge cases:
- If the lid is quickly opened and closed, the device may
resume without any lid-open and lid-closed events being
received by powerd. This change makes powerd immediately
re-suspend on resume if it suspended due to the lid being
closed and sees the lid as still being closed.
- Snow devices are awoken from suspend on lid-close. If a
device suspends due to user inactivity and then resumes
due to lid-close, this change makes the system re-suspend
immediately (i.e. the system resuming is only counted as
user activity if the lid is open).
BUG=chromium-os:38011,chrome-os-partner:17499
TEST=added unit tests and did manual testing
Change-Id: Iec985891eaac10903509a3ab34fdee65156a377b
Reviewed-on: https://gerrit.chromium.org/gerrit/43335
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Daniel Erat [Thu, 14 Feb 2013 03:23:42 +0000 (19:23 -0800)]
power: Put backlight into suspended state earlier.
This ensures that powerd puts the backlight into the
"suspended" state (i.e. original level saved to resume level
and current level set to 0) before announcing to Chrome that
the system is going to suspend (which causes Chrome to turn
the display on so it will be turned on immediately upon
resuming).
BUG=chromium-os:38869
TEST=updated unit tests
Change-Id: I96b310f6c03fed1b3e42c9578605ce14d3214d45
Reviewed-on: https://gerrit.chromium.org/gerrit/43257
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Daniel Erat [Tue, 12 Feb 2013 18:36:48 +0000 (10:36 -0800)]
power: Run powerd_suspend synchronously.
This makes powerd run the powerd_suspend script
synchronously rather than asynchronously. It receives the
suspend status via the script's exit code instead of via
a PowerStateChanged D-Bus signal. This prevents races where
additional events are received before before the signal and
powerd doesn't know whether the system has suspended and
resumed yet or not.
It also fixes an issue where powerd could announce a
suspend attempt and wait for suspend delays, try to suspend
and fail, emit a PowerStateChanged "on" signal (telling
clients to undo the preparation that they did via their
suspend delay), and then retry the suspend attempt
immediately without waiting for suspned delays again. This
change makes powerd instead wait for suspend delays again
before retries.
Finally, it moves all of the pre-suspend and post-resume
work into Daemon::PrepareForSuspend() and
Daemon::HandleResume() methods. Before, some of the
pre-suspend setup was done before even requesting suspend;
if the request was canceled early, it was possible for the
corresponding post-resume tasks to not be executed.
BUG=chromium-os:38869
TEST=updated existing unit tests; also manual testing on
assorted hardware
Change-Id: I88963d4f393c8c71782606b17e910b566c4e90ef
Reviewed-on: https://gerrit.chromium.org/gerrit/43171
Reviewed-by: Dave Moore <davemoore@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Daniel Erat [Tue, 12 Feb 2013 23:18:47 +0000 (15:18 -0800)]
power: Re-add support for avoid-suspend-for-headphones.
I missed implementing this in the new StateController class.
BUG=chromium-os:38861,chromium-os:38803
TEST=added unit test; also did manual testing on stumpy:
device avoids suspending post-login when headphones
are connected but still shuts down at the login screen
Change-Id: Iadb47125b67415a4849b0e5439d8f54582010382
Reviewed-on: https://gerrit.chromium.org/gerrit/43148
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Daniel Erat [Tue, 12 Feb 2013 00:10:28 +0000 (16:10 -0800)]
power: Don't let user activity cancel suspend w/ closed lid.
Chrome sometimes reports bogus fling-cancel scroll events to
powerd as user activity as the lid is closed. This can
cancel the in-progress suspend attempt. This change makes
the Suspender class disregard user activity when the lid is
closed.
BUG=chromium-os:38819
TEST=added unit test; also manually tested that lid-close
suspend works on snow
Change-Id: I2f9b4d74c6f2214b44fb7a24c15860fb1ee0caca
Reviewed-on: https://gerrit.chromium.org/gerrit/43069
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Dave Moore <davemoore@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Daniel Erat [Sat, 9 Feb 2013 06:41:00 +0000 (22:41 -0800)]
power: Fix cancel-suspend code and make it testable.
This moves the Suspender class's code for doing things like
running the powerd_suspend script or getting the wakeup
count into a Delegate class and adds unit tests for
Suspender.
It also moves all of the deciding-to-cancel-suspend
responsibility out of the (non-unit-testable) Daemon class
and into Suspender; now Daemon only tells Suspender about
generic things like user activity or lid-open events.
It also passes the suspend ID to powerd_suspend so it can be
included in the PowerStateChanged signal that's emitted on
resume; this allows Suspender to ignore resumes from
previous suspends if it's already dealing with a subsequent
suspend request.
Finally, it merges the lid_open and user_active files that
powerd previously touched to tell powerd_suspend to cancel
suspending into a single cancel_suspend file. This removes
complexity from powerd_suspend (e.g. should the lid being
open abort suspend?) and keeps it in Suspender, where it can
be tested.
BUG=chromium-os:38782
TEST=added unit tests, confirmed that power_Resume from
BVT passes, and did manual testing:
- suspend-from-idle is canceled on user activity both
before and after powerd_suspend has been run
- suspend-on-lid-closed is canceled on lid-opened both
before and after powerd_suspend has been run
- system resuspends if lid is closed and then opened
and closed quickly
Change-Id: Ia26551e2133f90ed925b85d734231a50afc074ad
Reviewed-on: https://gerrit.chromium.org/gerrit/42984
Tested-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Dave Moore <davemoore@chromium.org>
Daniel Erat [Sat, 9 Feb 2013 00:23:19 +0000 (16:23 -0800)]
power: Fix StopSession D-Bus method call.
This fixes powerd's StopSession call to the session manager,
which requires an (unused) string parameter.
BUG=chromium-os:38281
TEST=manual: user is logged out after timeout after setting
idle action to stop_session
Change-Id: Ib4efdb7e9922689796f31a4d97e0c425d00afdc2
Reviewed-on: https://gerrit.chromium.org/gerrit/42969
Reviewed-by: Simon Que <sque@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Daniel Erat [Wed, 6 Feb 2013 23:53:06 +0000 (15:53 -0800)]
power: Brighten backlight if off on session state change.
This increases the backlight to the minimum-visible level on
login or logout if it was manually set to 0.
BUG=chromium-os:25082
TEST=manual
TBR=davemoore@chromium.org
Change-Id: If1d48e4d832826446dd66eb468aa3ff0332dbed4
Reviewed-on: https://gerrit.chromium.org/gerrit/42808
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Ryan Harrison [Thu, 7 Feb 2013 18:37:58 +0000 (13:37 -0500)]
Pull in bug fix for common.mk
This bug does not appear to have affected the builds of this package, but it
should be fixed incase it causes failures in the future.
BUG=chromium-os:37854
TEST=Emerged locally with USE=profiling
Send CL through try bots
Change-Id: I56bf3d7a169d4362e56267a9f733ac79daf0d4b8
Reviewed-on: https://gerrit.chromium.org/gerrit/42872
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Tested-by: Ryan Harrison <rharrison@chromium.org>
Daniel Erat [Wed, 6 Feb 2013 21:09:28 +0000 (13:09 -0800)]
power: Improve StateController's logging.
This makes powerd log full details about external policies
from Chrome and makes StateController's "Updated settings"
message a bit more concise.
BUG=chromium-os:38379
TEST=manual: inspected logs
Change-Id: I08feaeca99b0ca2626ae881b4d77dfd93c8cbf08
Reviewed-on: https://gerrit.chromium.org/gerrit/42766
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Dave Moore <davemoore@chromium.org>
Ryan Harrison [Wed, 30 Jan 2013 16:43:55 +0000 (11:43 -0500)]
power_manager: Update local common.mk
The base version of common.mk in common-mk has been updated to include support
for MODE=profiling. This has already been enabled in the power_manager
ebuild. This CL updates the local common.mk so that this option can be used by
developers.
BUG=chromium-os:37854
TEST=Tried the various build methods:
`MODE=profiling cros_workon_make --board=link power_manger`
`MODE=profiling cros_workon_make --board=link power_manger --test`
`cros_workon_make --board=link power_manger`
`cros_workon_make --board=link power_manger --test`
Repeated these with emerge-link power_manager and FEATURES=test as needed
Change-Id: I195c2b24e31b2788a485e5d2852d561176b5992b
Reviewed-on: https://gerrit.chromium.org/gerrit/42645
Tested-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Daniel Erat [Tue, 5 Feb 2013 18:11:55 +0000 (10:11 -0800)]
power: Make StateController support idle metrics.
This makes the StateController class notify its delegate in
response to user activity so idle-time-related metrics can
be reported.
BUG=chromium-os:38281
TEST=added a unit test; also manually tested via
chrome://histograms
Change-Id: I0ad6526915d4a6f16182b484a3323bf8e716b2c8
Reviewed-on: https://gerrit.chromium.org/gerrit/42637
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Daniel Erat [Tue, 5 Feb 2013 15:10:09 +0000 (07:10 -0800)]
power: Make IdleController support for idle notifications.
This adds support to IdleController for externally-requested
idle notifications (created via RequestIdleNotification
D-Bus method calls and responsible for emitting IdleNotify
signals).
It also makes StateController get used for GetIdleTime
requests when --use_state_controller is set.
BUG=chromium-os:38281
TEST=added unit tests; also did manual testing:
dbus-send --system --dest=org.chromium.PowerManager \
--print-reply --type=method_call \
/org/chromium/PowerManager \
org.chromium.PowerManager.GetIdleTime
dbus-send --system --dest=org.chromium.PowerManager \
--print-reply --type=method_call \
/org/chromium/PowerManager \
org.chromium.PowerManager.RequestIdleNotification \
int64:10000
Change-Id: Iac905c7c45e4507d7cf1c66f0b43cba93b5b59f4
Reviewed-on: https://gerrit.chromium.org/gerrit/42615
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Dave Moore <davemoore@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Daniel Erat [Mon, 4 Feb 2013 23:11:08 +0000 (15:11 -0800)]
power: Make logging a bit less noisy.
This combines some frequently-occurring log messages into
single lines and switches others to VLOG(1).
BUG=chromium-os:38379
TEST=manual: looked at log
Change-Id: I78f6932034edc0e29eb7a89cd54ab2d292b9d35e
Reviewed-on: https://gerrit.chromium.org/gerrit/42578
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Daniel Erat [Mon, 4 Feb 2013 21:49:10 +0000 (13:49 -0800)]
power: Update paths for state files further.
83c1a3e6 was overly ambitious in moving files from
/var/run/power_manager/root to
/var/spool/power_manager/root; most of the moved files don't
need to persist across reboot (and the power_Resume autotest
was dependent on last_resume_timings getting written to the
old location). This moves several of the files back.
BUG=chromium-os:38484
TEST=manual: checked that TimeInSuspendAtResume and
TimeInSuspendAtBoot are both written as expected
Change-Id: Id3e8cb5f12d386214f9acc0e58e618bd0e35d5ee
Reviewed-on: https://gerrit.chromium.org/gerrit/42558
Tested-by: Daniel Erat <derat@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Reviewed-by: Doug Anderson <dianders@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Daniel Erat [Mon, 4 Feb 2013 18:10:02 +0000 (10:10 -0800)]
power: Make disable_idle_suspend pref avoid idle shutdown.
This broadens StateController's interpretation of the
disable_idle_suspend pref to additionally block other
idle-triggered actions, like shutdown. This matches
powerd's previous behavior (e.g. the system doesn't shut
down when idle on the login screen).
BUG=chromium-os:38281
TEST=added a unit test; also manually checked that the idle
action is "do nothing" instead of "shut down" at the
login screen when disable_idle_suspend is set
Change-Id: I3048d43e4e77863927f66771f3a9de72344b2ccb
Reviewed-on: https://gerrit.chromium.org/gerrit/42552
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>