pax_global_header 0000666 0000000 0000000 00000000064 14176470112 0014515 g ustar 00root root 0000000 0000000 52 comment=c9637e902631b5755119e82cb04de95b3851b970
repowerd-2022.01/ 0000775 0000000 0000000 00000000000 14176470112 0013512 5 ustar 00root root 0000000 0000000 repowerd-2022.01/AUTHORS 0000664 0000000 0000000 00000000177 14176470112 0014567 0 ustar 00root root 0000000 0000000 Alexandros Frantzis
Alfred Neumayer
Dalton Durst
Florian Leeber
Marius Gripsgard
Michał Sawicz
Ratchanan Srirattanamet
Rodney
repowerd-2022.01/CMakeLists.txt 0000664 0000000 0000000 00000007231 14176470112 0016255 0 ustar 00root root 0000000 0000000 # Copyright © 2016 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
# Authored by: Alexandros Frantzis
project(repowerd)
set(REPOWERD_VERSION "2022.01")
cmake_minimum_required(VERSION 3.0)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
option(REPOWERD_BUILD_TESTS "Build tests" ON)
option(REPOWERD_DISABLE_TIME_SENSITIVE_TESTS "Don't run time-sensitive tests" OFF)
option(REPOWERD_ENABLE_HYBRIS "Enable hybris support" ON)
# Work around cmake setting conf dir to "/usr/etc" instead of "/etc"
# when prefix is "/usr"
if (NOT DEFINED CMAKE_INSTALL_SYSCONFDIR AND CMAKE_INSTALL_PREFIX STREQUAL "/usr")
set(CMAKE_INSTALL_SYSCONFDIR "/etc")
endif()
enable_testing()
include(GNUInstallDirs)
find_package(Threads REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(ANDROID_PROPERTIES REQUIRED libandroid-properties)
pkg_check_modules(GIO REQUIRED gio-2.0)
pkg_check_modules(GIO_UNIX REQUIRED gio-unix-2.0)
if (REPOWERD_ENABLE_HYBRIS)
pkg_check_modules(UA REQUIRED ubuntu-platform-api)
pkg_check_modules(LIBHARDWARE REQUIRED libhardware)
pkg_check_modules(UBUNTU_PLATFORM_HARDWARE_API REQUIRED ubuntu-platform-hardware-api)
find_package(AndroidHeaders REQUIRED)
endif()
set(build_types "None;Debug;Release;RelWithDebInfo;MinSizeRel;AddressSanitizer;ThreadSanitizer")
# Change informational string for CMAKE_BUILD_TYPE
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "${build_types}" FORCE)
# Enable cmake-gui to display a drop down list for CMAKE_BUILD_TYPE
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${build_types}")
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -pthread -std=c11 -Werror -Wall -Wextra -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -pthread -std=c++14 -Werror -Wall -Wnon-virtual-dtor -Wextra -pedantic")
string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lower)
if(cmake_build_type_lower MATCHES "addresssanitizer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
elseif(cmake_build_type_lower MATCHES "threadsanitizer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread -fno-omit-frame-pointer")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=thread")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=thread")
link_libraries(tsan) # Workaround for LP:1413474
endif()
set(POWERD_DEVICE_CONFIG_DIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/powerd/device_configs")
set(REPOWERD_DEVICE_CONFIG_DIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/repowerd/device-configs")
add_definitions(-DREPOWERD_VERSION="${REPOWERD_VERSION}")
add_subdirectory(src/)
add_subdirectory(data/)
if(REPOWERD_BUILD_TESTS)
find_package(GMock REQUIRED)
add_subdirectory(tests/)
endif()
repowerd-2022.01/ChangeLog 0000664 0000000 0000000 00000102407 14176470112 0015270 0 ustar 00root root 0000000 0000000 2022-02-02 Mike Gabriel
* Release 2022.01 (HEAD -> main, tag: 2022.01)
2021-12-01 Marius Gripsgard
* Merge branch 'personal/peat-psuwit/merge-xenial-2021Nov' into
'main' (810c7d1)
2021-11-29 Ratchanan Srirattanamet
* Merge remote-tracking branch 'gitlab_ubports/ubports/xenial' into
personal/peat-psuwit/merge-xenial-2021Nov (097638b)
2021-08-12 Florian Leeber
* Merge branch 'personal/usb/suspend-delay-3' into 'ubports/xenial'
(69e3ead)
2021-08-11 Dalton Durst
* default_state_machine: 4 second delay before suspend (7ce336d)
2021-07-20 Dalton Durst
* Merge branch 'personal/peat-psuwit/rename-to-lomiri' into 'main'
(481457c)
2021-06-30 Dalton Durst
* Merge branch 'personal/peat-psuwit/fix-gh-ut-1747' into
'ubports/xenial' (a566d2c)
2021-06-30 Ratchanan Srirattanamet
* default_daemon_config: actually return created UbuntuLightSensor
(ee41141)
Fixes:
https://github.com/ubports/ubuntu-touch/issues/1747
2021-06-04 Ratchanan Srirattanamet
* CMakeLists: bump version to match d/changelog (dbf8e0c)
* d/{control,rules}: accommodate cmake-extras migration & no
platform-api (650abde)
* d/repowerd.service: update bus name (81e84e9)
* Rename com.canonical.powerd to com.lomiri.Repowerd (8a6500d)
* Rename com.canonical.repowerd to com.lomiri.Repowerd.Settings
(d87b9a0)
2021-05-29 Ratchanan Srirattanamet
* src, tests: rename interfaces to lomiri-system-compositor (f453e89)
2021-05-28 Ratchanan Srirattanamet
* event_loop: ignore function casting -Werror (ff24112)
* tests: make sure we don't include gtest_main needlessly (f606f47)
* CMakeLists: migrate to FindGMock from cmake-extras (36af0bf)
2021-06-10 Dalton Durst
* Merge branch 'xenial_-_build-without-hybris' into 'ubports/xenial'
(5b22003)
2021-06-04 Ratchanan Srirattanamet
* Move Jenkinsfile to debian/ per the new guideline (c4dd9f0)
* Update Jenkinsfile to use shared library (6b9d4fc)
2021-05-28 Ratchanan Srirattanamet
* tests/adapter-tests: fix building without hybris/platform-api
(6a10bc4)
* default_daemon_config: add missing includes for non-hybris case
(ea86e35)
2021-03-25 Marius Gripsgard
* Merge pull request #17 from ubports/xenial_-_wayland-session
(1375dd3)
2021-03-24 Marius Gripsgard
* Merge pull request #20 from ubports/xenial_-_clock-alarm (0424d9b)
2021-03-15 Rodney
* Merge pull request #16 from ubports/xenial_-_missing-header
(1f5a30e)
2020-05-27 Marius Gripsgard
* adapters: timerfd: Implement CLOCK_REALTIME_ALARM (1576f3c)
2020-08-14 Marius Gripsgard
* adapters: logind: Make wayland session a compatable repowerd
session (5b3b74b)
2021-01-14 Marius Gripsgard
* Allow to be built without hybris/android/papi support (fc4bc9b)
* core: Add missing header (025e510)
2020-09-08 Ratchanan Srirattanamet
* core: do disallow automatic suspend on client request (5c9e029)
2020-08-12 Marius Gripsgard
* Merge pull request #10 from ubports/xenial_-_fix-proximity-hiccup
(2a0e480)
2020-07-18 Florian Leeber
* The Oneplus One also needs to have the initial fake event reversed
(08419b8)
2020-06-24 Ratchanan Srirattanamet
* core: actually uses suspend inhibitions in automatic suspend
decision (946c666)
2020-05-05 Ratchanan Srirattanamet
* debian: uses a link instead of a file copy for powerd compat config
(04dce2e)
2020-05-04 Ratchanan Srirattanamet
* Revert "core: Suspend inhibitions should affect automatic suspend
only when display turns off due to inactivity" (cfb1cec)
* Update Jenkinsfile as of ubports/build-tools@10c0987 (955732c)
2020-04-08 Marius Gripsgard
* Update changelog (36c10ca)
2020-01-22 Florian Leeber
* Use default config from other directory (#7) (ec4223e)
2018-10-25 Alfred Neumayer
* adapters: Fix crash in UPowerPowerSource's critical temperature
assignment Using std::stod when parsing UPower's
shutdownBatteryTemperature setting causes repowerd to
crash on Sony Xperia X (arm64 kernel). Use std::stoi
instead as the setting itself is backed by an integer type
in UPower itself. (4d3f54c)
2018-01-15 Marius Gripsgard
* Import to ubp (a6362f4)
2017-12-17 Marius Gripsgard
* Always set brightness before first autobrightness setting fixes
https://github.com/ubports/ubuntu-touch/issues/305
(cd09c43)
2018-01-15 Marius Gripsgard
* Add Jenkinsfile (ad3225c)
2017-04-03 Bileto Bot
* Releasing 2017.03+17.04.20170403-0ubuntu1 (9d02adb)
2017-04-03 Alexandros Frantzis
* 2017.03 release - Fix "Closing the lid does not suspend the
device" (LP: #1668596) - Fix "messages are logged on
every input event" (LP: #1674736) - Fix brightness
issues when turning on the screen on Fairphone 2 - Add
apport hook (69cb91e)
* adapters: Fix UnityDisplay::turn_on memory leak (f498d04)
2017-03-29 Alexandros Frantzis
* Prepare files for 2017.03 release (69d9e6a)
2017-03-28 Alexandros Frantzis
* debian: Add apport hook (36fabb4)
* adapters: Ensure dimming a lit display will not increase its
brightness (56c2aa8)
* adapters: Fix application of user-set normal brightness value
(d433783)
* tests: Make rt::FakeTimer thread-safe to avoid races in tests
(230ccf5)
2017-03-27 Alexandros Frantzis
* adapters: Implement system suspend block notifications for
LogindSystemPowerControl (140ec67)
* core: Introduce system suspend block infrastructure and core logic
(e438a1b)
* core: Suspend inhibitions should affect automatic suspend only when
display turns off due to inactivity (8fd9f6b)
2017-03-23 Alexandros Frantzis
* core: Ensure we don't suspend the system when session is inactive
(b565779)
* core,adapters: Refactor SystemPowerControl::(dis)allow_suspend()
methods (87db540)
* core,adapters: Remove obsolete SystemPowerControl methods (deb4948)
* core: Implement suspend disallowance logic in DefaultStateMachine
(2575366)
* core,adapters: Move suspend dis/allowance handling to the
per-session state machine (05976cf)
* adapters: Don't inhibit logind suspends for suspend block requests
sent to repowerd (7379903)
* core: Suspend action when closing lid should not respect suspend
inhibitions (2b15a62)
* tests: Add test for UnityDisplay::turn_on() maximum wait (2081084)
2017-03-18 Ratchanan Srirattanamet
* adapters: make the screen-on call to u-s-c synchronous (49761c8)
2017-03-22 Alexandros Frantzis
* tests: Deduplicate duration_of() helper function (4bda546)
* debian: Don't log to /var/log/syslog (de8282f)
2017-02-21 Bileto Bot
* Releasing 2017.02+17.04.20170221-0ubuntu1 (f7263a9)
2017-02-21 Alexandros Frantzis
* Prepare files for 2017.02 release (83ac5f3)
* adapters: Generate random cookies for wakeup requests (3510a46)
2017-02-20 Alexandros Frantzis
* tests: Fix destruction order of test object members (0a94520)
2017-02-17 Alexandros Frantzis
* adapters: Add missing signal from Unity.Screen introspection
(926f1ed)
* doc: Add com.canonical.repowerd DBus API documentation (4be1095)
2017-02-15 Alexandros Frantzis
* tests: Add REPOWERD_TEST_LOG environment variable (00ce88f)
* adapters: Improve critical battery behavior (e978612)
2017-02-14 Alexandros Frantzis
* adapters: Refactor upower based power source to use DisplayDevice
(db0b761)
* tools: Add settings support to repowerd-cli (a5b6ab7)
2017-02-13 Alexandros Frantzis
* adapters: Implement dbus based client settings (4cfb8f7)
2017-02-14 Alexandros Frantzis
* core: Apply changes to inactivity timeouts when the power source
changes (b55da16)
* core: Don't accept the display-off action for the lid behavior
setting (a2e2693)
2017-02-09 Alexandros Frantzis
* core: Add core logic for critical power behavior setting (ac81a3a)
* core: Add critical power behavior support in ClientSettings and
hook it up in the daemon (22637fd)
2017-02-08 Alexandros Frantzis
* core: Add core logic for lid behavior settings (188dba8)
* core: Add lid behavior support in ClientSettings and hook it up in
the daemon (6a1205f)
* adapters: Implement logind based system resume notification
(8a9410d)
* core: Add system resume handling (d897dfe)
2017-01-31 Alexandros Frantzis
* core: Add basic inactivity suspend timeout support (756e2fd)
* tests: Update suspend expectation methods (cf3167f)
2017-01-30 Alexandros Frantzis
* core,adapters: Add support for battery vs line-power client
settings (8dcfd6b)
2017-01-27 Alexandros Frantzis
* core: Introduce ClientSettings (5407b28)
2017-01-26 Alexandros Frantzis
* core: Introduce StateMachine::handle_set_inactivity_behavior()
(137b47f)
2017-02-01 Alexandros Frantzis
* adapters: Implement and use TimerfdWakeupService (ebbff23)
2017-01-17 Alexandros Frantzis
* core: Improve display handling during lid manipulation (2e9ada7)
2017-01-13 Alexandros Frantzis
* core,adapters: Update DisplayPowerControl interface to support
filters (ef55d92)
* adapters: Rename UnityDisplayPowerControl to UnityDisplay (15346a2)
* adapters: Implement DisplayConfiguration with
UnityDisplayPowerControl (0d43e06)
2017-01-12 Alexandros Frantzis
* core: Add DisplayInformation interface and core logic (433f06d)
2017-01-05 Alexandros Frantzis
* adapters: Set the names of all event loop threads (956b449)
2017-01-04 Alexandros Frantzis
* core,adapters: Suspend when allowed with lid closed (8f901e8)
2016-12-12 Bileto Bot
* Releasing 2016.12+17.04.20161212.1-0ubuntu1 (28c65b0)
2016-12-12 Alexandros Frantzis
* Prepare files for 2016.12 release (4ed91aa)
2016-12-07 Alexandros Frantzis
* adapters: Temporarily disallow suspend after a power source change
(56e524b)
* adapters: Temporarily inhibit suspend after a hardware alarm is
triggered (62ea426)
* adapters: Introduce TemporarySuspendInhibition and implementation
(2cb7454)
* adapters: Increase synthetic proximity event delay for mako
(c879a68)
2016-12-06 Alexandros Frantzis
* adapters: Use a sensible time value in the future when not needing
/dev/alarm (537ea5c)
2016-12-07 Alexandros Frantzis
* adapters: Notify about power source changes involving the "pending
charge" battery state (638bc74)
2016-12-12 Alexandros Frantzis
* repowerd: Add REPOWERD_DEVICE_CONFIG_DIR environment variable
(1c39d81)
2016-12-09 Alexandros Frantzis
* adapters: Use proper DBus path for dbus manager (91513a1)
2016-12-05 Alexandros Frantzis
* tests: Fix build with clang (a9c0985)
2016-12-02 Alexandros Frantzis
* adapters: Inhibit lid handling when disallowing default logind
system handlers (ef10585)
2016-11-23 Alexandros Frantzis
* adapters: Rename UPowerPowerSource to UPowerPowerSourceAndLid
(0640162)
* adapters: Implement and use upower-based Lid (d93f52e)
2016-12-02 Alexandros Frantzis
* adapters: Implement LogindSystemPowerControl::suspend_if_allowed()
(153811b)
2016-11-22 Alexandros Frantzis
* core: Add lid state machine logic (0686f6f)
2016-11-21 Alexandros Frantzis
* core: Add Lid interface and hook it up in the daemon (95717ce)
2016-12-02 Alexandros Frantzis
* core: Fix HandlerRegistration move semantics (c1d81fa)
2016-11-30 Alexandros Frantzis
* adapters: Log DefaultStateMachine options (0b0a86c)
* core,adapters: Add treat_power_button_as_user_activity option
(3af72b2)
* tests: Refactor ATurnOnDisplayAtStartupOption test (0fda3aa)
* core,adapters: Move turn_on_display_at_startup option into
StateMachineOptions (b8a0707)
* core,adapters: Move state machine timeout options to
StateMachineOptions (c78dfd6)
2016-12-01 Alexandros Frantzis
* tests: Fix race in BacklightBrightnessControl tests (4883dca)
* tests: Fix race in LogindSystemPowerControl tests (88e57ba)
2016-11-30 Alexandros Frantzis
* adapters: Fix build with g++-4.9 and clang (48d7a81)
2016-11-29 Alexandros Frantzis
* adapters: Implement
LogindSystemPowerControl::(dis)allow_default_system_handlers
(388e916)
2016-11-28 Alexandros Frantzis
* core: Add SystemPowerControl::(dis)allow_default_system_handlers()
(77dd443)
* core: Add StateMachine::start() method (e1f2019)
2016-11-29 Alexandros Frantzis
* core,adapters: Distinguish different suspend types and deal with
them accordingly (99f74bc)
2016-11-25 Alexandros Frantzis
* adapters: Add and use LogindSystemPowerControl (f78f76c)
* adapters: Add repowerd::Fd move semantics support (0396aa3)
* core,adapters: Merge ShutdownControl into SystemPowerControl
(b1447d5)
* core: Rename SuspendControl to SystemPowerControl (df83d92)
2016-11-29 Alexandros Frantzis
* core: Pause active session before removing it (0d52e08)
2016-11-24 Bileto Bot
* Releasing 2016.11+17.04.20161124-0ubuntu1 (9334bde)
2016-11-24 Alexandros Frantzis
* tests: Add repowerd::Daemon tests for pause and resume (874bf2f)
* cmake: Update FindGtestGmock.cmake for gtest/gmock 1.8.0
compatibility (ce97efd)
2016-11-16 Alexandros Frantzis
* Prepare files for 2016.11 release (5e4cf24)
* debian: Start by default on desktop systemd-based systems (5658501)
* adapters: Accept requests without a matching session that originate
from root or the active session user (3f8dab8)
2016-11-15 Alexandros Frantzis
* adapters: Add ignore_session_deactivation quirk (bd445ad)
2016-11-10 Alexandros Frantzis
* core: Support pausing and resuming state machines during session
switches (0b6b3ec)
2016-11-11 Alexandros Frantzis
* core: Update the active session when the active session is removed
(97bb2d3)
2016-11-10 Alexandros Frantzis
* core: Add override to NullStateMachine (7ab0b57)
* tests: Use namespace testing globally in Daemon tests (efc4a07)
* core: Start processing session tracking events before any
per-session events (051ed29)
2016-11-09 Alexandros Frantzis
* adapters: Use the logind session id (instead of the logind path)
for the repowerd session id (1134a79)
* core: Give each state machine a name and log it (ca1a15c)
2016-11-08 Alexandros Frantzis
* core,adapters: Dispatch client requests to sessions that own them
(a2b88ff)
* core: Move brightness handling into state machine (ed5f6c8)
* core: Daemon enqueue_action_to_active_session (1fe931c)
2016-11-03 Alexandros Frantzis
* core,adapters: Introduce and use repowerd::invalid_session_id
(225ff26)
* core: Introduce session handling (432ea06)
2016-11-02 Alexandros Frantzis
* core: Add and use StateMachineFactory (38230c4)
* tools: Add repowerd-session-tool (48abb04)
2016-11-01 Alexandros Frantzis
* core: Add DaemonConfig::the_session_tracker() and default
implementation (805c80d)
* core,adapters: Add logind-based session tracker (9814d67)
2016-10-27 Alexandros Frantzis
* core,adapters: Move handling of multiple notifications from
adapters to core (11fa44f)
2016-10-26 Alexandros Frantzis
* core: Use a state event adapter instead of changing the state
machine interface (6d588c6)
* core,adapters: Move handling of multiple inactivity requests from
adapters to core (913ca3f)
2016-10-25 Alexandros Frantzis
* core: Don't expose underlying AlarmId type (04a0019)
2016-10-07 Bileto Bot
* Releasing 2016.10+16.10.20161007-0ubuntu1 (768279e)
2016-10-07 Alexandros Frantzis
* 2016.10 release (93f7646)
* Prepare files for 2016.10 release (55341f9)
* debian: Sync with released package (dee78d6)
2016-10-06 Alexandros Frantzis
* debian: Wait for the repowerd DBus API to be accessible before
declaring the upstart job as started (9096f69)
* tools: Handle SIGTERM gracefully in repowerd-cli (061d484)
* tools: Update repowerd-cli help text (fff9535)
2016-09-22 Alexandros Frantzis
* adapters: Fix typo in brightness config value (1e8d162)
2016-08-30 Alexandros Frantzis
* Prepare for 2016.08.3 release (b9fa947)
* core: Enforce an upper limit to the amount of time notifications
can keep the display on (c259fa7)
* tools: Support the "active" command in repowerd-cli (450c1d0)
2016-08-24 Alexandros Frantzis
* Sync with released version (d5020cc)
2016-08-23 Alexandros Frantzis
* adapters: Log quirks (82d03bd)
* adapters: Add autobrightness quirk for Nexus 4 (e9fb49a)
2016-08-22 Alexandros Frantzis
* Prepare for 2016.08.2 release (9e4a848)
2016-08-20 Alexandros Frantzis
* adapters: Fix autobrightness behavior (LP: #1613871) (051515d)
2016-08-17 Alexandros Frantzis
* debian: Update changelog for new fix (04120eb)
* repowerd: Change reduced (AKA short) timeout to 10s (f7cb388)
* Fix "The call screen still turns off after rejecting the call on
the remote end without answering." (LP: #1613506)
(49b0ee4)
2016-08-16 Alexandros Frantzis
* Prepare for 2016.08.1 release (25ffea5)
2016-08-12 Alexandros Frantzis
* Don't turn off the screen immediately after a keep on request is
cancelled and timeouts have expired (6b1f405)
2016-08-11 Alexandros Frantzis
* Prepare files for 2016.08 release (5224039)
2016-08-09 Alexandros Frantzis
* Fix suspending during video playback when USB gets unplugged (LP
#1602933) (011b5f1)
2016-08-08 Alexandros Frantzis
* debian: Silently fail if lxc-android-config.service is missing
(33fd6fc)
2016-08-05 Alexandros Frantzis
* Fix build with g++-6 (b046a41)
2016-07-25 Alexandros Frantzis
* debian: Update changelog (115d87c)
2016-07-13 Michał Sawicz
* Wants, not Requires lxc-android-config (LP: #1602597) (452cc65)
2016-07-06 Alexandros Frantzis
* debian: More packaging improvements (b19a738)
* debian: Update Vcs-Git field (279f26e)
2016-07-05 Alexandros Frantzis
* debian: Update changelog with needs-packaging LP bug (dd5494c)
* debian: Format is 3.0 (native) (3b9966d)
2016-06-13 Alexandros Frantzis
* adapters: Ignore stray proximity events when the proximity sensor
is disabled (4a6508d)
2016-06-10 Alexandros Frantzis
* tests: Change how we split tests into executables (32810a3)
* Abstract time-related operations and use fake time in tests
(b0a123d)
* Abstract filesystem access and remove FUSE test dependency
(8db2296)
* tools: Use DefaultDaemonConfig to create components in tools
(0cf8a8e)
2016-06-09 Alexandros Frantzis
* debian: Update changelog (72ec03e)
* repowerd: Log repowerd version (7829fb2)
2016-06-08 Alexandros Frantzis
* Fix clang build (a3e716a)
2016-06-07 Alexandros Frantzis
* adapters: Choose sysfs backlight based on type (d5a7dd6)
* adapters: Log used sysfs backlight path (32dddcb)
* repowerd: The proximity state of NullProximitySensor is always far
(ebe9905)
* adapters: Remove printf messages from mocksuspend backend (7290b72)
* repowerd: Log fallbacks to null components implementations
(5067905)
* repowerd: Allow running without brightness control (7ddb93d)
* tests: Update filters for tests that need FUSE or are
time-sensitive (e0ae829)
* adapters: Fix SysfsBacklight::get_brightness() to return the last
set brightness value, unless brightness was changed
externally (e7ca8e6)
2016-06-06 Alexandros Frantzis
* adapters: Refactor path handling (db1f78a)
* tests: Support symlinks in VirtualFilesystem (9c6b490)
2016-06-03 Alexandros Frantzis
* tools: Informational message improvements (ebc3837)
* Support disabling time-sensitive integration tests (90c2ba5)
2016-06-01 Alexandros Frantzis
* tests: Include forgotten header (a7565bc)
* Round brightness calculations for better accuracy (29461c8)
* Misc fixes (c5daeb6)
* debian: Explicitly state arch-unqualified package name in powerd
maintscript to allow proper conf file removal (ad44678)
2016-05-31 Alexandros Frantzis
* debian: Build depend on libubuntu-platform-hardware-api-dev instead
of -headers (eda9bfd)
* adapters: Log android properties (d5c6805)
* adapters: Properly read device-specific config file (5c23f44)
* adapters: Add logging to AndroidDeviceConfig (10f7c30)
2016-05-30 Alexandros Frantzis
* debian: Use an init system neutral postrotation command for
logrotate (aa9275e)
* adapters: Transition directly to new brightness value if current
value is unknown (06ae913)
* Use double instead of float where possible (4cf5cb9)
* debian: Make repowerd packages depend on specific versions of other
repowerd packages (50039b5)
* tools: Add and ship (re)powerd-cli utility (700f4ae)
* tests: Keep trying to unmount fuse filesystems on tear down
(7661853)
* core: Change disable_inactivity_timeouts to brighten/turn on the
display (d6d0c08)
* debian: Remove powerd conf files (a178495)
* debian: Update package version (a575824)
2016-05-27 Alexandros Frantzis
* adapters: Implement and use UPower based power source (1bc6ea7)
* adapters: Implement and use system shutdown control (a370dbf)
* core: Add handling of critical power source state (8f0d300)
2016-05-26 Alexandros Frantzis
* core: Add PowerSource and core logic (235a857)
* repowerd: Properly shutdown on SIGINT and SIGTERM signals (8ade3f7)
* core: Change internal daemon loop terminology (Event->Action)
(b32c3ff)
* repowerd: Read first from powerd device config directory for
compatibility reasons (3dcbe44)
2016-05-25 Alexandros Frantzis
* debian: Add logrotate configuration (1b6e9ef)
* debian: Add rsyslog configuration (1fc7669)
* data,debian: Install dbus conf files (12c4472)
* debian: Add repowerd init system startup files (643e567)
* debian: Update packaging (4cfdcde)
* build: Install repowerd and tools to sbin (e7f72ad)
* data: Add device config files (2b486d6)
2016-05-24 Alexandros Frantzis
* tests: Fix build errors with stricter debian flags (fd252bc)
* adapters: Log brightness transitions (43e9cb5)
* adapters: Add a quirk for the type (near/far) of the synthetic
initial proximity event (86153b7)
2016-05-23 Alexandros Frantzis
* adapters: Implement Ubuntu platform API based performance booster
(d0e3c02)
* core,tests: Add performance booster and logic (8dd2c3e)
* adapters: Print timestamp of each log entry in ConsoleLog (d2d61dc)
2016-05-20 Alexandros Frantzis
* adapters: Add libsuspend based suspend control (08eea7e)
* core,adapters: Add SuspendControl and logic (a43fc34)
2016-05-23 Alexandros Frantzis
* adapters: Make all public BacklightBrightnessControl methods
synchronous (a2384d9)
2016-05-19 Alexandros Frantzis
* adapters: Add logging to OfonoVoiceCallService (36da37f)
* repowerd: Use the ofono based modem power control by default
(be2de2d)
* adapters: Implement ofono based modem power control (64e78c5)
2016-05-18 Alexandros Frantzis
* tests: Use a variable of the correct type uint64_t when creating a
GVariant containing a time value (a6ecd8b)
* core: Add ModemPowerControl and logic (5ca84af)
* core: Don't store shared_ptr to unused object (6604dec)
2016-05-13 Alexandros Frantzis
* core,adapters: Add logging (30125fc)
2016-05-18 Alexandros Frantzis
* core: Initialize forgotten DefaultStateMachine instance variable
(b95675e)
2016-05-17 Alexandros Frantzis
* tests: Add some tests for AndroidAutobrightnessAlgorithm (3c1e788)
* adapters: Improve robustness against crashes of clients emitting
notifications (49e340a)
* adapters: Don't emit brightness notification if brightness hasn't
changed (13284c5)
2016-05-16 Alexandros Frantzis
* tests: Add tests for AndroidBacklight (712ec75)
2016-05-12 Alexandros Frantzis
* adapters: Introduce and use an Android libhardware based backlight
(a332076)
* repowerd: Fall back to a null light sensor if a real one is not
available (123a93c)
* repowerd: Use separate backlight and light sensor creation methods
in DefaultDaemonConfig (392fef0)
* adapters: Fix off-by-one error in MonotoneSpline (0b27334)
* adapters: Implement brightness change notification over DBus
(eebc906)
2016-05-10 Alexandros Frantzis
* adapters: Implement autobrightness (736c165)
2016-05-12 Alexandros Frantzis
* adapters: Use g_variant_iter_next() to avoid memory errors
(4ec2fa1)
2016-05-11 Alexandros Frantzis
* debian,build: Build depend on android-headers (73a601c)
* adapters: Don't allow MonotoneSplines with fewer than two points
(a1a2869)
2016-05-10 Alexandros Frantzis
* adapters: Ensure registering an object or signal handlers are
synchronous (711c6b2)
2016-05-09 Alexandros Frantzis
* core: Remove ProximitySensor::start_processing() (a6e76c1)
* adapters,tool: Implement UbuntuLightSensor and related light tool
(eaee111)
* tests: Extract TemporaryEnvironmentValue and TemporaryFile classes
(8079eb8)
* adapters: Implement monotone spline class (78f856e)
* Use static libraries with transitive usage requirements instead of
object libraries (fc78512)
2016-05-05 Alexandros Frantzis
* adapters: Refactor BacklightBrightnessControl (previously
SysfsBrightnessControl) to not depend on a specific
backlight control technology (4dd45d2)
2016-05-04 Alexandros Frantzis
* adapters: Translate DBus setInactivityTimeouts request infinite
timeout value to repowerd infinite timeout value (cee3aba)
* core: Ignore invalid values for inactivity timeouts (0a62fb1)
* core: Properly handle requests to disable inactivity timeouts
(4054d80)
2016-04-27 Alexandros Frantzis
* adapters: Add ofono based voice call service (08c78da)
* adapters: Powerd DBus API sys state should only affect system
suspend, not display power (05d722e)
* tests: Fix race in test expectations (2d4bec1)
2016-04-26 Alexandros Frantzis
* adapters: Introduce mechanism to unregister dbus object and signal
handlers (226f492)
2016-04-25 Alexandros Frantzis
* adapters: Transition smoothly between brightness values (69d24f5)
2016-04-22 Alexandros Frantzis
* tools: Add wakeup tool (3585617)
* adapters: Add /dev/alarm based wakeup service (12ecb2e)
2016-04-25 Alexandros Frantzis
* adapters: Support Powerd DBus API wakeup requests (d6b12db)
2016-04-21 Alexandros Frantzis
* adapters: Calculate default brightness values based on device
config (1a25677)
* adapters: Merge PowerdService into UnityScreenService (c1d6b68)
* core,adapters: Ensure we start processing requests after all
handlers have been registered (08e1427)
2016-04-20 Alexandros Frantzis
* adapters: Add forgotten "#pragma once" (597c96f)
* core: Small DefaultStateMachine refactoring (ab16485)
* adapters: Scale brightness values requested by users using the
device config brightness values (61baad1)
* adapters: Implement part of the com.canonical.powerd dbus API
(cc9f99d)
2016-04-15 Alexandros Frantzis
* core: Improve notification handling (c9a28fa)
* tests: Fix initialization of fuse_ops struct to support gcc-4.9
(91943d8)
* repowerd: Turn on display at startup (5b96d0b)
2016-04-14 Alexandros Frantzis
* tests: Check for existence of fuse only when building the tests
(ba9a071)
* debian: Build depend on 'fuse' package (f848e0f)
* repowerd: Use production components instead of null implementation
where possible (8e4d663)
* adapters: First cut at SysfsBrightnessControl (900f44b)
2016-04-13 Alexandros Frantzis
* tests: Add virtual filesystem infrastructure (e8a1169)
2016-04-12 Alexandros Frantzis
* adapters: Implement an event loop based timer (e986d86)
* core: Add Timer::cancel_alarm() (52cbb0b)
2016-04-11 Alexandros Frantzis
* adapters: Implement DBus based user activity (f35cb84)
* adapters: Implement a DBus based power button event sink (b7b93bd)
* adapters: Implement DBus based power button (e8fc886)
* adapters: Fix UnityDisplayPowerControl header (66cd5b7)
2016-04-08 Alexandros Frantzis
* adapters: Implement DBus based display power control (2e84337)
* adapters: Improve UbuntuProximitySensor concurrency correctness
(e1cddb2)
* adapters: Introduce device quirks support (77043ff)
2016-04-07 Alexandros Frantzis
* tools: Add proximity tool (d92851a)
* Update debian/control build-deps (09d59dd)
* adapters: Implement proximity sensor based on
ubuntu-application-api (993536b)
2016-04-05 Alexandros Frantzis
* adapters: Implement display power event notification in
UnityScreenService (bd33a07)
2016-04-04 Alexandros Frantzis
* core: Implement display power event notification logic (19c8157)
2016-04-01 Alexandros Frantzis
* adapters: Properly register and unregister handlers in
UnityScreenService (ff7092e)
* adapters: Add notification support to UnityScreenService (044b05f)
2016-03-31 Alexandros Frantzis
* tests,adapters: First cut at DBus infrastructure and
UnityScreenService (74ec4ff)
2016-03-29 Alexandros Frantzis
* core: Move core code into core/ directory (26f4ad6)
* tests: Fix race in acceptance tests (57eba3e)
* daemon,tests: Implement 'set_inactivity_timeout' client request
(81c11e8)
2016-03-28 Alexandros Frantzis
* daemon,tests: Implement 'enable/disable_autobrightness' client
requests (3b29dcc)
* daemon,tests: Implement 'set_normal_brightness_value' client
request (0e9e52a)
2016-03-23 Alexandros Frantzis
* daemon,tests: Support voice call use cases (c8294a6)
2016-03-24 Alexandros Frantzis
* tests: Deduplicate timeout variables (793f95c)
2016-03-23 Alexandros Frantzis
* daemon,tests: Support more notification use cases (c390c3e)
2016-03-21 Alexandros Frantzis
* daemon,tests: Support inactivity timeout dispaly dimming (7bb1bc0)
2016-03-18 Alexandros Frantzis
* daemon,tests: Support notification use cases (2a0eb40)
2016-03-17 Alexandros Frantzis
* daemon,tests: Support "enable/disable_inactivity_timeout" client
request and remove "turn_on_display" request (dbf4738)
* Refactor handler registration and unregistration (8489673)
2016-03-11 Alexandros Frantzis
* daemon,tests: Support "turn_on_display" client request (29cb01c)
2016-03-10 Alexandros Frantzis
* daemon,tests: Fix power button long press behavior (8e60c78)
* daemon,tests: Support proximity use cases (d300ca0)
2016-03-09 Alexandros Frantzis
* tests: Improve test names (964f422)
* daemon,tests: Implement user activity use cases (a742b9f)
* Introduce DaemonConfig methods for timeouts (a9d3a28)
* tests: Deduplicate common acceptance test code (e1755f0)
* daemon,tests: Added basic user inactivity display blanking logic
(108011d)
2016-03-08 Alexandros Frantzis
* Be consistent about using "power button" vs "power key" (648ddb4)
* tests: Add unit tests for repowerd::Daemon (e6c730c)
* tests: Add power button long press acceptance tests (1f4c4b6)
2016-03-03 Alexandros Frantzis
* More power button tests and logic (422ad61)
* Remove redundant curly braces (09f2e18)
2016-03-02 Alexandros Frantzis
* Add a simple event loop and StateMachine abstraction (dd45f05)
* Walking skeleton (1ad0bdb)
repowerd-2022.01/cmake/ 0000775 0000000 0000000 00000000000 14176470112 0014572 5 ustar 00root root 0000000 0000000 repowerd-2022.01/cmake/FindAndroidHeaders.cmake 0000664 0000000 0000000 00000000304 14176470112 0021246 0 ustar 00root root 0000000 0000000 include(CheckIncludeFiles)
check_include_files(android/linux/android_alarm.h HAVE_ANDROID_HEADERS)
if(NOT HAVE_ANDROID_HEADERS)
message(FATAL_ERROR "Could not find android headers")
endif()
repowerd-2022.01/data/ 0000775 0000000 0000000 00000000000 14176470112 0014423 5 ustar 00root root 0000000 0000000 repowerd-2022.01/data/CMakeLists.txt 0000664 0000000 0000000 00000002011 14176470112 0017155 0 ustar 00root root 0000000 0000000 # Copyright © 2016 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
# Authored by: Alexandros Frantzis
FILE(GLOB device_config_files "${CMAKE_CURRENT_SOURCE_DIR}/device-configs/*.xml")
FILE(GLOB dbus_config_files "${CMAKE_CURRENT_SOURCE_DIR}/dbus-configs/*.conf")
install(
FILES ${device_config_files}
DESTINATION ${REPOWERD_DEVICE_CONFIG_DIR}
)
install(
FILES ${dbus_config_files}
DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/dbus-1/system.d
)
repowerd-2022.01/data/dbus-configs/ 0000775 0000000 0000000 00000000000 14176470112 0017006 5 ustar 00root root 0000000 0000000 repowerd-2022.01/data/dbus-configs/com.canonical.Unity.Screen.conf 0000664 0000000 0000000 00000001146 14176470112 0024710 0 ustar 00root root 0000000 0000000
repowerd-2022.01/data/dbus-configs/com.lomiri.Repowerd.Settings.conf 0000664 0000000 0000000 00000001106 14176470112 0025310 0 ustar 00root root 0000000 0000000
repowerd-2022.01/data/dbus-configs/com.lomiri.Repowerd.conf 0000664 0000000 0000000 00000004577 14176470112 0023530 0 ustar 00root root 0000000 0000000
repowerd-2022.01/data/device-configs/ 0000775 0000000 0000000 00000000000 14176470112 0017310 5 ustar 00root root 0000000 0000000 repowerd-2022.01/data/device-configs/config-default.xml 0000664 0000000 0000000 00000007662 14176470112 0022734 0 ustar 00root root 0000000 0000000
false
4
680
10
255
102
10
repowerd-2022.01/data/device-configs/config-flo.xml 0000664 0000000 0000000 00000006636 14176470112 0022070 0 ustar 00root root 0000000 0000000
true
- 5
- 15
- 50
- 100
- 200
- 400
- 1000
- 2000
- 3000
- 5000
- 10000
- 30000
- 11
- 18
- 27
- 38
- 48
- 55
- 64
- 74
- 120
- 164
- 225
- 255
- 255
5
87
5
600
repowerd-2022.01/data/device-configs/config-grouper.xml 0000664 0000000 0000000 00000005665 14176470112 0022774 0 ustar 00root root 0000000 0000000
true
- 5
- 15
- 50
- 100
- 200
- 400
- 1000
- 2000
- 3000
- 5000
- 10000
- 30000
- 5
- 20
- 30
- 40
- 50
- 60
- 70
- 80
- 130
- 180
- 255
- 255
- 255
5
repowerd-2022.01/data/device-configs/config-hammerhead.xml 0000664 0000000 0000000 00000006305 14176470112 0023374 0 ustar 00root root 0000000 0000000
true
- 1
- 4
- 40
- 350
- 600
- 1000
- 1600
- 3000
- 10000
- 13
- 26
- 73
- 88
- 130
- 167
- 204
- 240
- 254
- 255
1
82
1
600
repowerd-2022.01/data/device-configs/config-maguro.xml 0000664 0000000 0000000 00000005426 14176470112 0022576 0 ustar 00root root 0000000 0000000
true
- 6
- 9
- 14
- 20
- 30
- 46
- 68
- 103
- 154
- 231
- 346
- 519
- 778
- 1168
- 1752
- 2627
- 3941
- 5912
- 8867
- 19
- 23
- 26
- 30
- 34
- 39
- 45
- 51
- 59
- 67
- 77
- 88
- 101
- 116
- 133
- 152
- 174
- 199
- 228
- 250
10
repowerd-2022.01/data/device-configs/config-mako.xml 0000664 0000000 0000000 00000006526 14176470112 0022235 0 ustar 00root root 0000000 0000000
true
- 10
- 50
- 100
- 200
- 400
- 500
- 800
- 1000
- 1600
- 3000
- 10000
- 14
- 28
- 37
- 51
- 71
- 80
- 96
- 108
- 144
- 181
- 254
- 255
1
87
1
600
repowerd-2022.01/data/device-configs/config-manta.xml 0000664 0000000 0000000 00000006624 14176470112 0022405 0 ustar 00root root 0000000 0000000
true
- 10
- 30
- 90
- 15000
- 225000
- 10
- 13
- 65
- 85
- 220
- 255
2
repowerd-2022.01/debian/ 0000775 0000000 0000000 00000000000 14176470112 0014734 5 ustar 00root root 0000000 0000000 repowerd-2022.01/debian/20-repowerd.conf 0000664 0000000 0000000 00000000120 14176470112 0017642 0 ustar 00root root 0000000 0000000 :programname,isequal,"repowerd" /var/log/repowerd.log;RSYSLOG_FileFormat
& stop
repowerd-2022.01/debian/Jenkinsfile 0000664 0000000 0000000 00000000651 14176470112 0017122 0 ustar 00root root 0000000 0000000 @Library('ubports-build-tools') _
buildAndProvideDebianPackage()
// Or if the package consists entirely of arch-independent packages:
// (optional optimization, will confuse BlueOcean's live view at build stage)
// buildAndProvideDebianPackage(/* isArchIndependent */ true)
// Optionally, to skip building on some architectures (amd64 is always built):
// buildAndProvideDebianPackage(false, /* ignoredArchs */ ['arm64'])
repowerd-2022.01/debian/changelog 0000664 0000000 0000000 00000010763 14176470112 0016615 0 ustar 00root root 0000000 0000000 repowerd (2022.01) unstable; urgency=medium
* Upstream-provided Debian package for repowerd. See upstream
ChangeLog for recent changes.
-- UBports developers Wed, 02 Feb 2022 12:51:38 +0100
repowerd (2018.04+ubports) xenial; urgency=medium
* Import to UBports
* Always set brightness before first autobrightness setting
-- Marius Gripsgard Mon, 15 Jan 2018 15:45:57 +0100
repowerd (2017.03+17.04.20170403-0ubuntu1) zesty; urgency=medium
* 2017.03 release
- Fix "Closing the lid does not suspend the device" (LP: #1668596)
- Fix "messages are logged on every input event" (LP: #1674736)
- Fix brightness issues when turning on the screen on Fairphone 2
- Add apport hook
-- Alexandros Frantzis Mon, 03 Apr 2017 14:19:32 +0000
repowerd (2017.02+17.04.20170221-0ubuntu1) zesty; urgency=medium
* 2017.02 release
- Improve lid handling
- Add timerfd based wakeup service for desktop
- Support new power settings, exposed through com.canonical.repowerd
- Improve handling of critically low power scenarios
- Generate random cookies for wakeup requests
* 2017.02 release
-- Alexandros Frantzis Tue, 21 Feb 2017 11:41:12 +0000
repowerd (2016.12+17.04.20161212.1-0ubuntu1) zesty; urgency=medium
* New 2016.12 release
- Support suspending with logind
- Implement basic lid handling
- Don't change the display power mode when pressing the power
button on non-phablet devices.
- Various snap-related improvements
- Fix "[mako] Alarm doesn't ring when screen locked" (LP: #1588526)
- Fix "[mako] Awful life battery since OTA 13" (LP: #1630382)
-- Alexandros Frantzis Mon, 12 Dec 2016 19:02:03 +0000
repowerd (2016.11+17.04.20161124-0ubuntu1) zesty; urgency=medium
* New 2016.11 release
- Support multiple user sessions
- Don't interfere with the power state of non-mir sessions
- Start repowerd at boot on desktop systems
-- Alexandros Frantzis Thu, 24 Nov 2016 12:55:52 +0000
repowerd (2016.10+16.10.20161007-0ubuntu1) yakkety; urgency=medium
* New 2016.10 release
- Fix typo in brightness config value (LP: #1618391)
- Update repowerd-cli help text
- Handle SIGTERM gracefully in repowerd-cli
- Wait for the repowerd DBus API to be accessible before marking
the upstart job as started (LP: #1623853)
* 2016.10 release
-- Alexandros Frantzis Fri, 07 Oct 2016 11:50:44 +0000
repowerd (2016.08.3+16.10.20160830.1-0ubuntu1) yakkety; urgency=medium
* New 2016.08.3 release
- Fix "Low battery notification turns screen on and never turns
it off again." (LP: #1618417)
- Fix "lock display when idle timeout not honoured" (LP: #1615001)
- Fix "Missing powerd-cli active" (LP: #1618072)
-- Alexandros Frantzis Tue, 30 Aug 2016 16:36:58 +0000
repowerd (2016.08.2+16.10.20160823.1-0ubuntu1) yakkety; urgency=medium
* New 2016.08.2 release
- Fix "Regression: In dark conditions autobrightness does not
adapt" (LP: #1613871)
-- Alexandros Frantzis Tue, 23 Aug 2016 14:22:58 +0000
repowerd (2016.08.1+16.10.20160817.1-0ubuntu1) yakkety; urgency=medium
* New 2016.08.1 release
- Fix "Display turns off right after playing back a long video"
(LP: #1602739)
- Fix "call screen still turns off after rejecting the call on
the remote end without answering." (LP: #1613506)
-- Alexandros Frantzis Wed, 17 Aug 2016 17:48:35 +0000
repowerd (2016.08+16.10.20160811-0ubuntu1) yakkety; urgency=medium
* New 2016.08 release
- Fix "suspends during video playback when USB gets unplugged"
(LP: #1602933)
-- Alexandros Frantzis Thu, 11 Aug 2016 14:17:03 +0000
repowerd (2016.06+16.10.20160808-0ubuntu1) yakkety; urgency=medium
* debian/repowerd.service:
- Make service dependency on lxc-android-config.service optional
('Wants' instead of 'Requires')
- Silently fail if lxc-android-config.service is missing
-- Alexandros Frantzis Mon, 08 Aug 2016 08:59:28 +0000
repowerd (2016.06+16.10.20160706.1-0ubuntu1) yakkety; urgency=medium
* Initial release (LP: #1599271)
-- Alexandros Frantzis Wed, 06 Jul 2016 14:24:10 +0000
repowerd-2022.01/debian/compat 0000664 0000000 0000000 00000000002 14176470112 0016132 0 ustar 00root root 0000000 0000000 9
repowerd-2022.01/debian/control 0000664 0000000 0000000 00000004077 14176470112 0016347 0 ustar 00root root 0000000 0000000 Source: repowerd
Priority: optional
Section: admin
Maintainer: Ubuntu Developers
Build-Depends: debhelper (>= 9),
dh-apport,
dh-systemd,
android-headers,
cmake,
cmake-extras,
dbus,
googletest | google-mock,
libandroid-properties-dev,
libglib2.0-dev,
libgtest-dev,
pkg-config
Standards-Version: 3.9.7
Homepage: https://launchpad.net/repowerd
Vcs-Git: https://git.launchpad.net/repowerd
Package: repowerd
Architecture: any
Depends: ${misc:Depends},
${shlibs:Depends},
repowerd-data (= ${source:Version})
Replaces: powerd (<< 2016.05~)
Breaks: powerd (<< 2016.05~)
Provides: powerd
Description: Power daemon to monitor and control system power state
This daemon monitors and controls system power states for Ubuntu
phone and tablet.
.
This package contains repowerd daemon itself.
Package: repowerd-data
Architecture: all
Depends: ${misc:Depends}
Conflicts: powerd (<< 2016.05~)
Description: Power daemon to monitor and control system power state
This daemon monitors and controls system power states for Ubuntu
phone and tablet.
.
This package contains data files needed by repowerd.
Package: repowerd-tools
Architecture: any
Depends: ${misc:Depends},
${shlibs:Depends},
repowerd-data (= ${source:Version})
Description: Power daemon to monitor and control system power state
This daemon monitors and controls system power states for Ubuntu
phone and tablet. It provides a dbus interface for system services to request
a power state, essentially allowing services to block suspend.
.
This package contains tools that use the repowerd infrastructure to interact
with various hardware components. These tools are mainly useful for manual
integration testing.
Package: powerd
Architecture: all
Depends: ${misc:Depends},
repowerd (>= ${source:Version})
Section: oldlibs
Description: Transitional dummy package
This is a transitional dummy package.
repowerd-2022.01/debian/copyright 0000664 0000000 0000000 00000002075 14176470112 0016673 0 ustar 00root root 0000000 0000000 Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Power daemon to monitor power button events
Upstream-Contact: Alexandros Frantzis
Source: https://launchpad.net/repowerd
Files: *
Copyright: Copyright (C) 2016, Canonical Ltd
License: GPL-3
License: GPL-3
This program is free software: you can redistribute it and/or modify it
under the terms of the the GNU General Public License version 3, as
published by the Free Software Foundation.
.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranties of
MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
PURPOSE. See the applicable version of the GNU Lesser General Public
License for more details.
.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
.
On Debian systems, the complete text of the GNU General Public License
can be found in `/usr/share/common-licenses/GPL-3'
repowerd-2022.01/debian/powerd.maintscript 0000664 0000000 0000000 00000000157 14176470112 0020516 0 ustar 00root root 0000000 0000000 rm_conffile /etc/dbus-1/system.d/powerd.conf 2016.06~ powerd
rm_conffile /etc/init/powerd.conf 2016.06~ powerd
repowerd-2022.01/debian/repowerd-data.install 0000664 0000000 0000000 00000000023 14176470112 0021055 0 ustar 00root root 0000000 0000000 usr/share/repowerd
repowerd-2022.01/debian/repowerd-data.links 0000664 0000000 0000000 00000000150 14176470112 0020530 0 ustar 00root root 0000000 0000000 usr/share/repowerd/device-configs/config-default.xml usr/share/powerd/device_configs/config-default.xml
repowerd-2022.01/debian/repowerd-tools.install 0000664 0000000 0000000 00000000031 14176470112 0021303 0 ustar 00root root 0000000 0000000 usr/sbin/repowerd-*-tool
repowerd-2022.01/debian/repowerd.apport 0000664 0000000 0000000 00000001154 14176470112 0020013 0 ustar 00root root 0000000 0000000 '''apport package hook for repowerd
Copyright (c) 2017 Canonical Ltd.
Author: Alexandros Frantzis
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License version 3, as published by the Free
Software Foundation. See http://www.gnu.org/copyleft/gpl.html for the full text
of the license.
'''
from apport.hookutils import *
def add_info(report, ui=None):
attach_file_if_exists(report, '/var/log/repowerd.log', key='repowerd.log')
attach_file_if_exists(report, '/var/log/repowerd.log.1', key='repowerd.log.1')
repowerd-2022.01/debian/repowerd.install 0000664 0000000 0000000 00000000152 14176470112 0020151 0 ustar 00root root 0000000 0000000 usr/sbin/repowerd
usr/sbin/repowerd-cli
etc/dbus-1/system.d/*.conf
debian/20-repowerd.conf etc/rsyslog.d/
repowerd-2022.01/debian/repowerd.links 0000664 0000000 0000000 00000000052 14176470112 0017622 0 ustar 00root root 0000000 0000000 usr/sbin/repowerd-cli usr/sbin/powerd-cli
repowerd-2022.01/debian/repowerd.logrotate 0000664 0000000 0000000 00000000311 14176470112 0020500 0 ustar 00root root 0000000 0000000 /var/log/repowerd.log {
daily
missingok
rotate 4
compress
notifempty
delaycompress
maxsize 10M
postrotate
kill -HUP $(cat /var/run/rsyslogd.pid)
endscript
}
repowerd-2022.01/debian/repowerd.service 0000664 0000000 0000000 00000000360 14176470112 0020144 0 ustar 00root root 0000000 0000000 [Unit]
Description=monitor and control system power state
Wants=lxc-android-config.service
After=lxc-android-config.service
[Service]
Type=dbus
BusName=com.lomiri.Repowerd
ExecStart=/usr/sbin/repowerd
[Install]
WantedBy=multi-user.target
repowerd-2022.01/debian/repowerd.upstart 0000664 0000000 0000000 00000001160 14176470112 0020205 0 ustar 00root root 0000000 0000000 author "Alexandros Frantzis "
start on started dbus and android
respawn
post-start script
# Wait for repowerd to really start.
# Time out after a sensible amount of time to avoid looping forever
# and consuming power if something fails.
num_tries=0
while ! dbus-send --print-reply --system --dest=com.canonical.powerd /com/canonical/powerd com.canonical.powerd.getBrightnessParams;
do
sleep 0.5;
num_tries=$((num_tries+1));
if [ $num_tries -eq 60 ];
then
break;
fi
done
end script
exec /usr/sbin/repowerd
repowerd-2022.01/debian/rules 0000775 0000000 0000000 00000000447 14176470112 0016021 0 ustar 00root root 0000000 0000000 #!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
%:
dh $@ --parallel --fail-missing --with apport,systemd
override_dh_auto_configure:
dh_auto_configure -- \
-DREPOWERD_ENABLE_HYBRIS=OFF \
-DREPOWERD_DISABLE_TIME_SENSITIVE_TESTS=ON
repowerd-2022.01/debian/source/ 0000775 0000000 0000000 00000000000 14176470112 0016234 5 ustar 00root root 0000000 0000000 repowerd-2022.01/debian/source/format 0000664 0000000 0000000 00000000015 14176470112 0017443 0 ustar 00root root 0000000 0000000 3.0 (native)
repowerd-2022.01/doc/ 0000775 0000000 0000000 00000000000 14176470112 0014257 5 ustar 00root root 0000000 0000000 repowerd-2022.01/doc/repowerd-settings-api.txt 0000664 0000000 0000000 00000003206 14176470112 0021255 0 ustar 00root root 0000000 0000000 Service : com.lomiri.Repowerd.Settings
Interface : com.lomiri.Repowerd.Settings
ObjectPath: /com/lomiri/Repowerd/Settings
Methods
-------
void SetInactivityBehavior(string power_action,
string power_source,
int timeout_sec)
: "display-off", "suspend"
: "battery", "line-power"
: positive timeout in seconds, non-positive to disable
Sets the inactivity behavior to while on
after seconds.
Examples:
While on battery turn off display after 30 seconds of inactivity:
SetInactivityBehavior("display-off", "battery", 30)
While plugged in never turn off display due to inactivity:
SetInactivityBehavior("display-off", "line-power", -1)
While on battery suspend after 10 minutes of inactivity:
SetInactivityBehavior("suspend", "battery", 600)
void SetLidBehavior(string power_action,
string power_source)
: "none", "suspend"
: "battery", "line-power"
Sets the lid behavior to while on .
Examples:
While on battery suspend when closing the lid:
SetLidBehavior("suspend", "battery")
While plugged in do nothing when closing the lid:
SetLidBehavior("none", "line-power")
void SetCriticalPowerBehavior(string power_action)
: "suspend", "power-off"
Sets the critical power behavior to .
Examples:
Power off the device when power is critically low:
SetCriticalPowerBehavior("power-off")
repowerd-2022.01/src/ 0000775 0000000 0000000 00000000000 14176470112 0014301 5 ustar 00root root 0000000 0000000 repowerd-2022.01/src/CMakeLists.txt 0000664 0000000 0000000 00000002656 14176470112 0017052 0 ustar 00root root 0000000 0000000 # Copyright © 2016 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
# Authored by: Alexandros Frantzis
add_definitions(-DPOWERD_DEVICE_CONFIG_DIR=\"${POWERD_DEVICE_CONFIG_DIR}\")
add_definitions(-DREPOWERD_DEVICE_CONFIG_DIR=\"${REPOWERD_DEVICE_CONFIG_DIR}\")
include_directories(
${CMAKE_SOURCE_DIR}
)
if (REPOWERD_ENABLE_HYBRIS)
add_definitions(-DREPOWERD_ENABLE_HYBRIS)
endif()
add_subdirectory(core)
add_subdirectory(adapters)
add_subdirectory(tools)
add_library(
repowerd-default-daemon-config STATIC
default_daemon_config.cpp
)
target_link_libraries(
repowerd-default-daemon-config
repowerd-core
repowerd-adapters
)
add_executable(
repowerd
main.cpp
)
target_link_libraries(
repowerd
repowerd-core
repowerd-adapters
repowerd-default-daemon-config
)
install(
TARGETS repowerd
RUNTIME DESTINATION sbin
)
repowerd-2022.01/src/adapters/ 0000775 0000000 0000000 00000000000 14176470112 0016104 5 ustar 00root root 0000000 0000000 repowerd-2022.01/src/adapters/CMakeLists.txt 0000664 0000000 0000000 00000005110 14176470112 0020641 0 ustar 00root root 0000000 0000000 # Copyright © 2016 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
# Authored by: Alexandros Frantzis
add_subdirectory(libsuspend)
if (REPOWERD_ENABLE_HYBRIS)
set(REPOWERD_ADAPTER_HYBRIS_SRCS
android_backlight.cpp
dev_alarm_wakeup_service.cpp
ubuntu_light_sensor.cpp
ubuntu_performance_booster.cpp
ubuntu_proximity_sensor.cpp
)
endif()
set(
REPOWERD_ADAPTER_SRCS
android_autobrightness_algorithm.cpp
android_device_config.cpp
android_device_quirks.cpp
backlight_brightness_control.cpp
brightness_params.cpp
console_log.cpp
dbus_connection_handle.cpp
dbus_event_loop.cpp
dbus_message_handle.cpp
default_state_machine_options.cpp
event_loop.cpp
event_loop_timer.cpp
fd.cpp
libsuspend_system_power_control.cpp
logind_session_tracker.cpp
logind_system_power_control.cpp
lsc_display.cpp
lsc_power_button.cpp
lsc_user_activity.cpp
monotone_spline.cpp
null_log.cpp
ofono_voice_call_service.cpp
path.cpp
real_chrono.cpp
real_filesystem.cpp
real_temporary_suspend_inhibition.cpp
repowerd_settings_service.cpp
syslog_log.cpp
sysfs_backlight.cpp
timerfd_wakeup_service.cpp
unity_screen_service.cpp
upower_power_source_and_lid.cpp
${REPOWERD_ADAPTER_HYBRIS_SRCS}
)
add_library(
repowerd-adapters STATIC
${REPOWERD_ADAPTER_SRCS}
)
target_link_libraries(
repowerd-adapters
suspend
${ANDROID_PROPERTIES_LDFLAGS} ${ANDROID_PROPERTIES_LIBRARIES}
${GIO_LDFLAGS} ${GIO_LIBRARIES}
${GIO_UNIX_LDFLAGS} ${GIO_UNIX_LIBRARIES}
${LIBHARDWARE_LDFLAGS} ${LIBHARDWARE_LIBRARIES}
${UA_LDFLAGS} ${UA_LIBRARIES}
${UBUNTU_PLATFORM_HARDWARE_API_LDFLAGS} ${UBUNTU_PLATFORM_HARDWARE_API_LIBRARIES}
)
target_include_directories(
repowerd-adapters PUBLIC
${ANDROID_PROPERTIES_INCLUDE_DIRS}
${GIO_INCLUDE_DIRS}
${GIO_UNIX_INCLUDE_DIRS}
${LIBHARDWARE_INCLUDE_DIRS}
${UA_INCLUDE_DIRS}
${UBUNTU_PLATFORM_HARDWARE_API_INCLUDE_DIRS}
)
repowerd-2022.01/src/adapters/android_autobrightness_algorithm.cpp 0000664 0000000 0000000 00000020106 14176470112 0025416 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "android_autobrightness_algorithm.h"
#include "brightness_params.h"
#include "device_config.h"
#include "event_loop.h"
#include "event_loop_handler_registration.h"
#include "src/core/log.h"
#include "monotone_spline.h"
#include
#include
#include
#include
#include
namespace
{
char const* const log_tag = "AndroidAutobrightnessAlgorithm";
auto const null_handler = [](auto){};
auto constexpr smoothing_factor_slow = 2000.0;
auto constexpr smoothing_factor_fast = 200.0;
auto constexpr hysteresis_factor = 0.1;
auto constexpr debounce_delay = std::chrono::seconds{4};
std::vector parse_int_array(std::string const& str)
{
std::vector elems;
std::stringstream ss{str};
std::string item;
while (std::getline(ss, item, ','))
elems.push_back(std::stoi(item));
return elems;
}
std::unique_ptr
create_brightness_spline(repowerd::DeviceConfig const& device_config)
try
{
auto const ab_light_levels_str = device_config.get("autoBrightnessLevels", "");
auto const ab_brightness_levels_str = device_config.get("autoBrightnessLcdBacklightValues", "");
auto ab_light_levels = parse_int_array(ab_light_levels_str);
auto const ab_brightness_levels = parse_int_array(ab_brightness_levels_str);
if (ab_light_levels.size() == 0 || ab_brightness_levels.size() == 0 ||
ab_brightness_levels.size() != ab_light_levels.size() + 1)
{
throw std::runtime_error{"Autobrightness not supported"};
}
ab_light_levels.insert(ab_light_levels.begin(), 0);
std::vector points;
auto l_iter = ab_light_levels.begin();
auto b_iter = ab_brightness_levels.begin();
for (;
l_iter != ab_light_levels.end() && b_iter != ab_brightness_levels.end();
++l_iter, ++b_iter)
{
points.push_back({static_cast(*l_iter), static_cast(*b_iter)});
}
return std::make_unique(points);
}
catch (...)
{
return {};
}
double get_max_brightness(repowerd::DeviceConfig const& device_config)
{
auto const brightness_params = repowerd::BrightnessParams::from_device_config(device_config);
return brightness_params.max_value;
}
double exponential_smoothing(
double old_average, double new_value, double smoothing_factor)
{
return old_average + smoothing_factor * (new_value - old_average);
}
}
repowerd::AndroidAutobrightnessAlgorithm::AndroidAutobrightnessAlgorithm(
DeviceConfig const& device_config,
std::shared_ptr const& log)
: brightness_spline{create_brightness_spline(device_config)},
max_brightness{get_max_brightness(device_config)},
log{log},
started{false},
debouncing_seqnum{0}
{
reset();
}
repowerd::AndroidAutobrightnessAlgorithm::~AndroidAutobrightnessAlgorithm() = default;
bool repowerd::AndroidAutobrightnessAlgorithm::init(EventLoop& event_loop)
{
if (!brightness_spline) return false;
this->event_loop = &event_loop;
return true;
}
void repowerd::AndroidAutobrightnessAlgorithm::new_light_value(double light)
{
if (!started)
return;
auto const is_first_light_value = !have_previous_light_values();
log->log(log_tag, "process_new_light_value(%.2f), is_first_light_value=%d",
light, is_first_light_value);
update_averages(light);
if (is_first_light_value)
{
notify_brightness(brightness_spline->interpolate(fast_average));
applied_light = fast_average;
}
else
{
schedule_debounce();
}
}
void repowerd::AndroidAutobrightnessAlgorithm::start()
{
if (!started)
{
reset();
started = true;
}
}
void repowerd::AndroidAutobrightnessAlgorithm::stop()
{
if (started)
{
reset();
started = false;
}
}
repowerd::HandlerRegistration repowerd::AndroidAutobrightnessAlgorithm::register_autobrightness_handler(
AutobrightnessHandler const& handler)
{
return EventLoopHandlerRegistration{
*event_loop,
[this, &handler]{ this->autobrightness_handler = handler; },
[this]{ this->autobrightness_handler = null_handler; }};
}
void repowerd::AndroidAutobrightnessAlgorithm::reset()
{
last_light = 0.0;
last_light_tp = {};
applied_light = 0.0;
fast_average = 0.0;
slow_average = 0.0;
debouncing = false;
++debouncing_seqnum;
}
bool repowerd::AndroidAutobrightnessAlgorithm::have_previous_light_values()
{
return last_light_tp != std::chrono::steady_clock::time_point{};
}
void repowerd::AndroidAutobrightnessAlgorithm::update_averages(double light)
{
auto const now = std::chrono::steady_clock::now();
if (!have_previous_light_values())
{
fast_average = light;
slow_average = light;
}
else
{
auto const dt = now - last_light_tp;
double const dt_ms =
std::chrono::duration_cast(dt).count();
auto const fast_factor = dt_ms / (dt_ms + smoothing_factor_fast);
auto const slow_factor = dt_ms / (dt_ms + smoothing_factor_slow);
fast_average = exponential_smoothing(fast_average, light, fast_factor);
slow_average = exponential_smoothing(slow_average, light, slow_factor);
}
last_light_tp = now;
last_light = light;
}
void repowerd::AndroidAutobrightnessAlgorithm::schedule_debounce()
{
if (debouncing)
return;
debouncing = true;
++debouncing_seqnum;
log->log(log_tag, "schedule_debounce(), seqnum=%d", debouncing_seqnum);
event_loop->schedule_in(
debounce_delay,
[this, expected_debouncing_seqnum=debouncing_seqnum]
{
if (debouncing_seqnum != expected_debouncing_seqnum)
{
log->log(log_tag, "debounce() ignored, expected_seqnum=%d, actual_seqnum=%d",
expected_debouncing_seqnum, debouncing_seqnum);
return;
}
auto constexpr min_hysteresis = 2.0;
debouncing = false;
update_averages(last_light);
auto const hysteresis = std::max(applied_light * hysteresis_factor, min_hysteresis);
auto const slow_delta = slow_average - applied_light;
auto const fast_delta = fast_average - applied_light;
log->log(log_tag,
"debounce(), seqnum=%d, applied_light=%.2f, hysteresis=%.2f, "
"slow_average=%.2f, fast_average=%.2f, slow_delta=%.2f, "
"fast_delta=%.2f",
expected_debouncing_seqnum, applied_light, hysteresis, slow_average,
fast_average, slow_delta, fast_delta);
if ((slow_delta >= hysteresis && fast_delta >= hysteresis) ||
(-slow_delta >= hysteresis && -fast_delta >= hysteresis))
{
log->log(log_tag, "debounce(), apply light %.2f", fast_average);
notify_brightness(brightness_spline->interpolate(fast_average));
applied_light = fast_average;
}
auto const hysteresis_last_light =
std::max(last_light * hysteresis_factor, min_hysteresis);
if (fabs(fast_average - last_light) >= hysteresis_last_light)
schedule_debounce();
});
}
void repowerd::AndroidAutobrightnessAlgorithm::notify_brightness(double brightness)
{
return autobrightness_handler(brightness / max_brightness);
}
repowerd-2022.01/src/adapters/android_autobrightness_algorithm.h 0000664 0000000 0000000 00000003714 14176470112 0025071 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#pragma once
#include "autobrightness_algorithm.h"
#include
#include
namespace repowerd
{
class DeviceConfig;
class Log;
class MonotoneSpline;
class AndroidAutobrightnessAlgorithm : public AutobrightnessAlgorithm
{
public:
AndroidAutobrightnessAlgorithm(
DeviceConfig const& device_config,
std::shared_ptr const& log);
~AndroidAutobrightnessAlgorithm();
bool init(EventLoop& event_loop) override;
void new_light_value(double light) override;
void start() override;
void stop() override;
HandlerRegistration register_autobrightness_handler(
AutobrightnessHandler const& handler) override;
private:
void reset();
bool have_previous_light_values();
void update_averages(double light);
void schedule_debounce();
void notify_brightness(double brightness);
EventLoop* event_loop;
std::unique_ptr const brightness_spline;
double const max_brightness;
std::shared_ptr const log;
AutobrightnessHandler autobrightness_handler;
bool started;
std::chrono::steady_clock::time_point last_light_tp;
double last_light;
double applied_light;
double fast_average;
double slow_average;
bool debouncing;
int debouncing_seqnum;
};
}
repowerd-2022.01/src/adapters/android_backlight.cpp 0000664 0000000 0000000 00000004011 14176470112 0022234 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "android_backlight.h"
#include
#include
#include
#include
repowerd::AndroidBacklight::AndroidBacklight()
: brightness{Backlight::unknown_brightness}
{
hw_module_t const* hwmod;
auto error = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, &hwmod);
if (error || hwmod == nullptr)
throw std::runtime_error("Failed to open Android lights module");
error = hwmod->methods->open(hwmod, LIGHT_ID_BACKLIGHT,
reinterpret_cast(&light_dev));
if (error || light_dev == nullptr)
throw std::runtime_error("Failed to open Android backlight device");
}
repowerd::AndroidBacklight::~AndroidBacklight()
{
light_dev->common.close(reinterpret_cast(light_dev));
}
void repowerd::AndroidBacklight::set_brightness(double value)
{
int const value_abs = round(value * 255);
light_state_t state;
memset(&state, 0, sizeof(light_state_t));
state.flashMode = LIGHT_FLASH_NONE;
state.brightnessMode = BRIGHTNESS_MODE_USER;
state.color = ((0xffU << 24) | (value_abs << 16) | (value_abs << 8) | value_abs);
auto const err = light_dev->set_light(light_dev, &state);
if (!err) brightness = value;
}
double repowerd::AndroidBacklight::get_brightness()
{
return brightness;
}
repowerd-2022.01/src/adapters/android_backlight.h 0000664 0000000 0000000 00000002020 14176470112 0021677 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#pragma once
#include "backlight.h"
struct light_device_t;
namespace repowerd
{
class AndroidBacklight : public Backlight
{
public:
AndroidBacklight();
~AndroidBacklight();
void set_brightness(double) override;
double get_brightness() override;
private:
light_device_t* light_dev;
double brightness;
};
}
repowerd-2022.01/src/adapters/android_device_config.cpp 0000664 0000000 0000000 00000014317 14176470112 0023102 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "android_device_config.h"
#include "path.h"
#include "src/core/log.h"
#include
#include
#include
#include
#include
#include
#include
namespace
{
char const* const log_tag = "AndroidDeviceConfig";
std::string determine_device_name()
{
char name[PROP_VALUE_MAX] = "";
property_get("ro.product.device", name, "");
return name;
}
}
repowerd::AndroidDeviceConfig::AndroidDeviceConfig(
std::shared_ptr const& log,
std::shared_ptr const& filesystem,
std::vector const& config_dirs)
: log{log},
filesystem{filesystem}
{
for (auto const& dir : config_dirs)
log->log(log_tag, "Using config directory: %s", dir.c_str());
parse_first_matching_file_in_dirs(config_dirs, "config-default.xml");
auto const device_name = determine_device_name();
if (device_name != "")
parse_first_matching_file_in_dirs(config_dirs, "config-" + device_name + ".xml");
log_properties();
}
std::string repowerd::AndroidDeviceConfig::get(
std::string const& name, std::string const& default_value) const
{
auto const iter = config.find(name);
if (iter != config.end())
return iter->second;
else
return default_value;
}
void repowerd::AndroidDeviceConfig::parse_first_matching_file_in_dirs(
std::vector const& config_dirs, std::string const& filename)
{
for (auto const& config_dir : config_dirs)
{
auto const full_file_path = Path{config_dir}/filename;
if (filesystem->is_regular_file(full_file_path))
{
parse_file(full_file_path);
break;
}
}
}
void repowerd::AndroidDeviceConfig::parse_file(std::string const& file)
{
log->log(log_tag, "parse_file(%s)", file.c_str());
GMarkupParser parser;
parser.start_element = static_xml_start_element;
parser.end_element = static_xml_end_element;
parser.text = static_xml_text;
parser.passthrough = nullptr;
parser.error = nullptr;
auto const ctx = std::unique_ptr{
g_markup_parse_context_new(
&parser,
static_cast(0),
this,
nullptr),
g_markup_parse_context_free};
auto const ifs_ptr = filesystem->istream(file);
auto& ifs = *ifs_ptr;
std::array text;
while (ifs)
{
ifs.read(text.data(), text.size());
auto text_len = ifs.gcount();
g_markup_parse_context_parse(
ctx.get(),
text.data(),
text_len,
nullptr);
}
}
void repowerd::AndroidDeviceConfig::static_xml_start_element(
GMarkupParseContext* /*context*/,
char const* element_name,
char const** attribute_names,
char const** attribute_values,
gpointer user_data,
GError** /*error*/)
{
auto const device_config = static_cast(user_data);
std::unordered_map attribs;
auto current_attrib = attribute_names;
auto current_value = attribute_values;
while (*current_attrib != nullptr)
{
attribs.emplace(*current_attrib, *current_value);
++current_attrib;
++current_value;
}
device_config->xml_start_element(element_name, attribs);
}
void repowerd::AndroidDeviceConfig::static_xml_end_element(
GMarkupParseContext* /*context*/,
char const* element_name,
void* user_data,
GError** /*error*/)
{
auto const device_config = static_cast(user_data);
device_config->xml_end_element(element_name);
}
void repowerd::AndroidDeviceConfig::static_xml_text(
GMarkupParseContext* /*context*/,
char const* text,
gsize text_len,
gpointer user_data,
GError** /*error*/)
{
auto const device_config = static_cast(user_data);
if (text && text_len > 0)
device_config->xml_text(std::string{text, text_len});
else
device_config->xml_text("");
}
void repowerd::AndroidDeviceConfig::xml_start_element(
std::string const& element_name,
std::unordered_map const& attribs)
{
if (element_name != "integer" && element_name != "integer-array" && element_name != "bool")
return;
auto iter = attribs.find("name");
if (iter == attribs.end())
return;
auto config_name = iter->second;
if (config_name.find("config_") == 0)
config_name = config_name.substr(strlen("config_"));
last_config_name = config_name;
config.erase(last_config_name);
}
void repowerd::AndroidDeviceConfig::xml_end_element(
std::string const& element_name)
{
if (element_name != "integer" && element_name != "integer-array" && element_name != "bool")
return;
last_config_name = "";
}
void repowerd::AndroidDeviceConfig::xml_text(std::string const& text)
{
auto clean_text = text;
clean_text.erase(
std::remove_if(clean_text.begin(), clean_text.end(), [](int c) { return isspace(c); }),
clean_text.end());
if (last_config_name == "" || clean_text == "")
return;
auto iter = config.find(last_config_name);
if (iter != config.end())
iter->second += "," + clean_text;
else
config[last_config_name] = clean_text;
}
void repowerd::AndroidDeviceConfig::log_properties()
{
for (auto const& property : config)
{
log->log(log_tag, "Property: %s=%s",
property.first.c_str(), property.second.c_str());
}
}
repowerd-2022.01/src/adapters/android_device_config.h 0000664 0000000 0000000 00000004576 14176470112 0022555 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#pragma once
#include "device_config.h"
#include "filesystem.h"
#include
#include
#include
#include
namespace repowerd
{
class Log;
class AndroidDeviceConfig : public DeviceConfig
{
public:
AndroidDeviceConfig(
std::shared_ptr const& log,
std::shared_ptr const& filesystem,
std::vector const& config_dirs);
std::string get(
std::string const& name, std::string const& default_value) const override;
private:
static void static_xml_start_element(
GMarkupParseContext* context,
char const* element_name,
char const** attribute_names,
char const** attribute_values,
gpointer user_data,
GError** error);
static void static_xml_end_element(
GMarkupParseContext* context,
char const* element_name,
void* user_data,
GError** error);
static void static_xml_text(
GMarkupParseContext* context,
char const* text,
gsize text_len,
gpointer user_data,
GError** error);
void parse_first_matching_file_in_dirs(
std::vector const& dirs, std::string const& filename);
void parse_file(std::string const& file);
void xml_start_element(
std::string const& element_name,
std::unordered_map const& attribs);
void xml_end_element(std::string const& element_name);
void xml_text(std::string const& text);
void log_properties();
std::shared_ptr const log;
std::shared_ptr const filesystem;
std::string last_config_name;
std::unordered_map config;
};
}
repowerd-2022.01/src/adapters/android_device_quirks.cpp 0000664 0000000 0000000 00000011400 14176470112 0023141 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "android_device_quirks.h"
#include "src/core/log.h"
#include
using namespace std::chrono_literals;
namespace
{
char const* const log_tag = "AndroidDeviceQuirks";
std::string determine_device_name()
{
char name[PROP_VALUE_MAX] = "";
property_get("ro.product.device", name, "");
return name;
}
std::chrono::milliseconds synthetic_initial_proximity_event_delay_for(std::string const& device_name)
{
// Mako can be a bit slow to report proximity when waking from suspend
if (device_name == "mako")
return 700ms;
else
return 500ms;
}
repowerd::AndroidDeviceQuirks::ProximityEventType
synthetic_initial_proximity_event_type_for(std::string device_name)
{
// In general we assume a "near" state if we don't get an initial event.
// However, arale and bacon do not emit an initial event when in the "far" state
// in particular, so we assume a "far" state for arale.
if (device_name == "arale" || device_name == "bacon" || device_name == "A0001" || device_name == "a0001")
return repowerd::AndroidDeviceQuirks::ProximityEventType::far;
else
return repowerd::AndroidDeviceQuirks::ProximityEventType::near;
}
bool normal_before_display_on_autobrightness_for(std::string const& device_name)
{
auto const quirk_cstr = getenv("REPOWERD_QUIRK_NORMAL_BEFORE_DISPLAY_ON_AUTOBRIGHTNESS");
std::string const quirk{quirk_cstr ? quirk_cstr : "always"};
// Mako needs us to manually set the brightness before the first
// autobrightness setting after turning on the screen. Otherwise, it
// doesn't update screen brightness to the proper level until the next
// screen content refresh.
return (device_name == "mako" || quirk == "always") && quirk != "never";
}
std::string proximity_event_type_to_str(
repowerd::AndroidDeviceQuirks::ProximityEventType const type)
{
switch (type)
{
case repowerd::AndroidDeviceQuirks::ProximityEventType::near: return "near";
case repowerd::AndroidDeviceQuirks::ProximityEventType::far: return "far";
default: return "unknown";
};
return "unknown";
}
bool ignore_session_deactivation_for(std::string const& device_name)
{
// ignore session deactivation for all android devices
return !device_name.empty();
}
}
repowerd::AndroidDeviceQuirks::AndroidDeviceQuirks(
repowerd::Log& log)
: device_name_{determine_device_name()},
synthetic_initial_proximity_event_delay_{
synthetic_initial_proximity_event_delay_for(device_name_)},
synthetic_initial_proximity_event_type_{
synthetic_initial_proximity_event_type_for(device_name_)},
normal_before_display_on_autobrightness_{
normal_before_display_on_autobrightness_for(device_name_)},
ignore_session_deactivation_{
ignore_session_deactivation_for(device_name_)}
{
log.log(log_tag, "DeviceName: %s", device_name_.c_str());
log.log(log_tag, "Quirk: synthetic_initial_proximit_event_delay=%d",
static_cast(synthetic_initial_proximity_event_delay_.count()));
log.log(log_tag, "Quirk: synthetic_initial_proximit_event_type=%s",
proximity_event_type_to_str(synthetic_initial_proximity_event_type_).c_str());
log.log(log_tag, "Quirk: normal_before_display_on_autobrightness=%s",
normal_before_display_on_autobrightness_ ? "true" : "false");
log.log(log_tag, "Quirk: ignore_session_deactivation=%s",
ignore_session_deactivation_ ? "true" : "false");
}
std::chrono::milliseconds
repowerd::AndroidDeviceQuirks::synthetic_initial_proximity_event_delay() const
{
return synthetic_initial_proximity_event_delay_;
}
repowerd::AndroidDeviceQuirks::ProximityEventType
repowerd::AndroidDeviceQuirks::synthetic_initial_proximity_event_type() const
{
return synthetic_initial_proximity_event_type_;
}
bool repowerd::AndroidDeviceQuirks::normal_before_display_on_autobrightness() const
{
return normal_before_display_on_autobrightness_;
}
bool repowerd::AndroidDeviceQuirks::ignore_session_deactivation() const
{
return ignore_session_deactivation_;
}
repowerd-2022.01/src/adapters/android_device_quirks.h 0000664 0000000 0000000 00000002706 14176470112 0022617 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#pragma once
#include "device_quirks.h"
#include
namespace repowerd
{
class Log;
class AndroidDeviceQuirks : public DeviceQuirks
{
public:
AndroidDeviceQuirks(Log& log);
std::chrono::milliseconds synthetic_initial_proximity_event_delay() const override;
ProximityEventType synthetic_initial_proximity_event_type() const override;
bool normal_before_display_on_autobrightness() const override;
bool ignore_session_deactivation() const override;
private:
std::string const device_name_;
std::chrono::milliseconds const synthetic_initial_proximity_event_delay_;
ProximityEventType const synthetic_initial_proximity_event_type_;
bool normal_before_display_on_autobrightness_;
bool const ignore_session_deactivation_;
};
}
repowerd-2022.01/src/adapters/autobrightness_algorithm.h 0000664 0000000 0000000 00000002710 14176470112 0023364 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#pragma once
#include "src/core/handler_registration.h"
#include
namespace repowerd
{
using AutobrightnessHandler = std::function;
class EventLoop;
class AutobrightnessAlgorithm
{
public:
virtual ~AutobrightnessAlgorithm() = default;
virtual bool init(EventLoop& event_loop) = 0;
virtual void new_light_value(double light) = 0;
virtual void start() = 0;
virtual void stop() = 0;
virtual HandlerRegistration register_autobrightness_handler(
AutobrightnessHandler const& handler) = 0;
protected:
AutobrightnessAlgorithm() = default;
AutobrightnessAlgorithm(AutobrightnessAlgorithm const&) = delete;
AutobrightnessAlgorithm& operator=(AutobrightnessAlgorithm const&) = delete;
};
}
repowerd-2022.01/src/adapters/backlight.h 0000664 0000000 0000000 00000002075 14176470112 0020211 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#pragma once
namespace repowerd
{
class Backlight
{
public:
virtual ~Backlight() = default;
virtual void set_brightness(double) = 0;
virtual double get_brightness() = 0;
static double constexpr unknown_brightness = -1.0;
protected:
Backlight() = default;
Backlight(Backlight const&) = delete;
Backlight& operator=(Backlight const&) = delete;
};
}
repowerd-2022.01/src/adapters/backlight_brightness_control.cpp 0000664 0000000 0000000 00000022661 14176470112 0024537 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "autobrightness_algorithm.h"
#include "backlight_brightness_control.h"
#include "backlight.h"
#include "brightness_params.h"
#include "chrono.h"
#include "device_quirks.h"
#include "event_loop_handler_registration.h"
#include "light_sensor.h"
#include "src/core/log.h"
#include
#include
#include
#include
#include
using namespace std::chrono_literals;
namespace
{
char const* const log_tag = "BacklightBrightnessControl";
auto const null_handler = [](double){};
double normal_brightness_percent(repowerd::DeviceConfig const& device_config)
{
auto brightness_params = repowerd::BrightnessParams::from_device_config(device_config);
return static_cast(brightness_params.default_value) / brightness_params.max_value;
}
double dim_brightness_percent(repowerd::DeviceConfig const& device_config)
{
auto const brightness_params = repowerd::BrightnessParams::from_device_config(device_config);
return static_cast(brightness_params.dim_value) / brightness_params.max_value;
}
}
repowerd::BacklightBrightnessControl::BacklightBrightnessControl(
std::shared_ptr const& backlight,
std::shared_ptr const& light_sensor,
std::shared_ptr const& autobrightness_algorithm,
std::shared_ptr const& chrono,
std::shared_ptr const& log,
DeviceConfig const& device_config,
DeviceQuirks const& quirks)
: backlight{backlight},
light_sensor{light_sensor},
autobrightness_algorithm{autobrightness_algorithm},
chrono{chrono},
log{log},
normal_before_display_on_autobrightness{
quirks.normal_before_display_on_autobrightness()},
ab_supported{autobrightness_algorithm->init(event_loop)},
event_loop{"Backlight"},
brightness_handler{null_handler},
dim_brightness{dim_brightness_percent(device_config)},
normal_brightness{normal_brightness_percent(device_config)},
user_normal_brightness{normal_brightness},
active_brightness_type{ActiveBrightnessType::off},
ab_active{false}
{
if (ab_supported)
{
ab_handler_registration = autobrightness_algorithm->register_autobrightness_handler(
[this] (double brightness)
{
if (ab_active)
{
this->log->log(log_tag, "new_autobrightness_value(%.2f)", brightness);
normal_brightness = brightness;
if (active_brightness_type == ActiveBrightnessType::normal)
{
transition_to_brightness_value(normal_brightness, TransitionSpeed::slow);
}
}
});
light_handler_registration = light_sensor->register_light_handler(
[this] (double light)
{
event_loop.enqueue(
[this, light]
{
this->autobrightness_algorithm->new_light_value(light);
});
});
}
}
void repowerd::BacklightBrightnessControl::disable_autobrightness()
{
if (!ab_supported) return;
event_loop.enqueue(
[this]
{
if (ab_active)
{
autobrightness_algorithm->stop();
light_sensor->disable_light_events();
normal_brightness = user_normal_brightness;
ab_active = false;
if (active_brightness_type == ActiveBrightnessType::normal)
transition_to_brightness_value(normal_brightness, TransitionSpeed::slow);
}
}).get();
}
void repowerd::BacklightBrightnessControl::enable_autobrightness()
{
if (!ab_supported) return;
event_loop.enqueue(
[this]
{
if (!ab_active)
{
if (active_brightness_type == ActiveBrightnessType::normal)
{
autobrightness_algorithm->start();
light_sensor->enable_light_events();
}
ab_active = true;
}
}).get();
}
void repowerd::BacklightBrightnessControl::set_dim_brightness()
{
event_loop.enqueue(
[this]
{
bool should_transition = true;
auto const backlight_brightness = get_brightness_value();
if (backlight_brightness > 0.0 &&
backlight_brightness < dim_brightness)
{
should_transition = false;
}
if (should_transition)
transition_to_brightness_value(dim_brightness, TransitionSpeed::normal);
active_brightness_type = ActiveBrightnessType::dim;
}).get();
}
void repowerd::BacklightBrightnessControl::set_normal_brightness()
{
event_loop.enqueue(
[this]
{
if (ab_active && active_brightness_type == ActiveBrightnessType::off)
{
if (normal_before_display_on_autobrightness)
transition_to_brightness_value(normal_brightness, TransitionSpeed::normal);
autobrightness_algorithm->start();
light_sensor->enable_light_events();
}
else
{
transition_to_brightness_value(normal_brightness, TransitionSpeed::normal);
}
active_brightness_type = ActiveBrightnessType::normal;
}).get();
}
void repowerd::BacklightBrightnessControl::set_normal_brightness_value(double v)
{
event_loop.enqueue(
[this,v]
{
user_normal_brightness = v;
if (!ab_active)
normal_brightness = user_normal_brightness;
if (active_brightness_type == ActiveBrightnessType::normal && !ab_active)
transition_to_brightness_value(normal_brightness, TransitionSpeed::normal);
}).get();
}
void repowerd::BacklightBrightnessControl::set_off_brightness()
{
event_loop.enqueue(
[this]
{
transition_to_brightness_value(0, TransitionSpeed::normal);
active_brightness_type = ActiveBrightnessType::off;
autobrightness_algorithm->stop();
light_sensor->disable_light_events();
}).get();
}
repowerd::HandlerRegistration
repowerd::BacklightBrightnessControl::register_brightness_handler(
BrightnessHandler const& handler)
{
return EventLoopHandlerRegistration(
event_loop,
[this,&handler] { brightness_handler = handler; },
[this] { brightness_handler = null_handler; });
}
void repowerd::BacklightBrightnessControl::transition_to_brightness_value(
double brightness, TransitionSpeed transition_speed)
{
auto const step = 0.01;
auto const backlight_brightness = get_brightness_value();
auto const starting_brightness =
backlight_brightness == Backlight::unknown_brightness ?
brightness - step : backlight_brightness;
auto const num_steps = std::ceil(std::fabs(starting_brightness - brightness) / step);
auto const step_time = (transition_speed == TransitionSpeed::slow ||
starting_brightness == 0.0
|| brightness == 0.0) ?
100000us / num_steps : 1000us;
if (starting_brightness != brightness)
{
log->log(log_tag, "Transitioning brightness %.2f => %.2f in %.2f steps %.2fus each",
starting_brightness, brightness, num_steps, step_time.count());
}
auto current_brightness = starting_brightness;
if (current_brightness < brightness)
{
while (current_brightness < brightness)
{
current_brightness += step;
if (current_brightness > brightness) current_brightness = brightness;
set_brightness_value(current_brightness);
chrono->sleep_for(std::chrono::duration_cast(step_time));
}
}
else if (current_brightness > brightness)
{
while (current_brightness > brightness)
{
current_brightness -= step;
if (current_brightness < brightness) current_brightness = brightness;
set_brightness_value(current_brightness);
chrono->sleep_for(std::chrono::duration_cast(step_time));
}
}
if (starting_brightness != brightness)
{
log->log(log_tag, "Transitioning brightness %.2f => %.2f done",
starting_brightness, current_brightness);
}
if (starting_brightness != brightness)
brightness_handler(brightness);
}
void repowerd::BacklightBrightnessControl::set_brightness_value(double brightness)
{
backlight->set_brightness(brightness);
}
double repowerd::BacklightBrightnessControl::get_brightness_value()
{
return backlight->get_brightness();
}
repowerd-2022.01/src/adapters/backlight_brightness_control.h 0000664 0000000 0000000 00000005430 14176470112 0024177 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#pragma once
#include "src/core/brightness_control.h"
#include "brightness_notification.h"
#include "event_loop.h"
#include
namespace repowerd
{
class AutobrightnessAlgorithm;
class Backlight;
class Chrono;
class DeviceConfig;
class DeviceQuirks;
class LightSensor;
class Log;
class BacklightBrightnessControl : public BrightnessControl, public BrightnessNotification
{
public:
BacklightBrightnessControl(
std::shared_ptr const& backlight,
std::shared_ptr const& light_sensor,
std::shared_ptr const& autobrightness_algorithm,
std::shared_ptr const& chrono,
std::shared_ptr const& log,
DeviceConfig const& device_config,
DeviceQuirks const& device_quirks);
void disable_autobrightness() override;
void enable_autobrightness() override;
void set_dim_brightness() override;
void set_normal_brightness() override;
void set_normal_brightness_value(double) override;
void set_off_brightness() override;
HandlerRegistration register_brightness_handler(
BrightnessHandler const& handler) override;
private:
enum class ActiveBrightnessType {normal, dim, off};
enum class TransitionSpeed {normal, slow};
void transition_to_brightness_value(double brightness, TransitionSpeed transition_speed);
void set_brightness_value(double brightness);
double get_brightness_value();
std::shared_ptr const backlight;
std::shared_ptr const light_sensor;
std::shared_ptr const autobrightness_algorithm;
std::shared_ptr const chrono;
std::shared_ptr const log;
bool const normal_before_display_on_autobrightness;
bool const ab_supported;
EventLoop event_loop;
HandlerRegistration light_handler_registration;
HandlerRegistration ab_handler_registration;
BrightnessHandler brightness_handler;
double dim_brightness;
double normal_brightness;
double user_normal_brightness;
ActiveBrightnessType active_brightness_type;
bool ab_active;
};
}
repowerd-2022.01/src/adapters/brightness_notification.h 0000664 0000000 0000000 00000002361 14176470112 0023175 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#pragma once
#include "src/core/handler_registration.h"
#include
namespace repowerd
{
using BrightnessHandler = std::function;
class BrightnessNotification
{
public:
virtual ~BrightnessNotification() = default;
virtual HandlerRegistration register_brightness_handler(
BrightnessHandler const& handler) = 0;
protected:
BrightnessNotification() = default;
BrightnessNotification(BrightnessNotification const&) = delete;
BrightnessNotification& operator=(BrightnessNotification const&) = delete;
};
}
repowerd-2022.01/src/adapters/brightness_params.cpp 0000664 0000000 0000000 00000003312 14176470112 0022322 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "brightness_params.h"
#include "device_config.h"
int string_to_int(std::string const& value, int default_value)
{
try { return std::stoi(value); }
catch (...) { return default_value; }
}
repowerd::BrightnessParams repowerd::BrightnessParams::from_device_config(
DeviceConfig const& device_config)
{
auto dim_str = device_config.get("screenBrightnessDim", "10");
auto min_str = device_config.get("screenBrightnessSettingMinimum", "10");
auto max_str = device_config.get("screenBrightnessSettingMaximum", "255");
auto default_str = device_config.get("screenBrightnessSettingDefault", "102");
auto ab_str = device_config.get("automatic_brightness_available", "false");
BrightnessParams params;
params.dim_value = string_to_int(dim_str, 10);
params.min_value = string_to_int(min_str, 10);
params.max_value = string_to_int(max_str, 255);
params.default_value = string_to_int(default_str, 102);
params.autobrightness_supported = (ab_str == "true");
return params;
}
repowerd-2022.01/src/adapters/brightness_params.h 0000664 0000000 0000000 00000001722 14176470112 0021772 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#pragma once
namespace repowerd
{
class DeviceConfig;
struct BrightnessParams
{
static BrightnessParams from_device_config(DeviceConfig const&);
int dim_value;
int min_value;
int max_value;
int default_value;
bool autobrightness_supported;
};
}
repowerd-2022.01/src/adapters/chrono.h 0000664 0000000 0000000 00000001751 14176470112 0017551 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#pragma once
#include
namespace repowerd
{
class Chrono
{
public:
virtual ~Chrono() = default;
virtual void sleep_for(std::chrono::nanoseconds t) = 0;
protected:
Chrono() = default;
Chrono(Chrono const&) = delete;
Chrono& operator=(Chrono const&) = delete;
};
}
repowerd-2022.01/src/adapters/console_log.cpp 0000664 0000000 0000000 00000002641 14176470112 0021116 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "console_log.h"
#include
#include
#include
#include
void repowerd::ConsoleLog::log(char const* tag, char const* format, ...)
{
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
char now[32];
auto const offset = strftime(now, sizeof(now), "%F %T", localtime(&ts.tv_sec));
snprintf(now + offset, sizeof(now) - offset, ".%06ld", ts.tv_nsec / 1000);
std::string format_str;
format_str += "[";
format_str += now;
format_str += "] ";
format_str += tag;
format_str += ": ";
format_str += format;
format_str += "\n";
va_list ap;
va_start(ap, format);
vprintf(format_str.c_str(), ap);
va_end(ap);
fflush(stdout);
}
repowerd-2022.01/src/adapters/console_log.h 0000664 0000000 0000000 00000001556 14176470112 0020567 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#pragma once
#include "src/core/log.h"
namespace repowerd
{
class ConsoleLog : public Log
{
public:
void log(char const* tag, char const* format, ...) override;
};
}
repowerd-2022.01/src/adapters/dbus_connection_handle.cpp 0000664 0000000 0000000 00000005425 14176470112 0023305 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "dbus_connection_handle.h"
#include "scoped_g_error.h"
#include
repowerd::DBusConnectionHandle::DBusConnectionHandle(std::string const& address)
{
repowerd::ScopedGError error;
connection = g_dbus_connection_new_for_address_sync(
address.c_str(),
GDBusConnectionFlags(
G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION |
G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT),
nullptr,
nullptr,
error);
if (!connection)
{
throw std::runtime_error(
"Failed to connect to DBus bus with address '" +
address + "': " + error.message_str());
}
}
repowerd::DBusConnectionHandle::~DBusConnectionHandle()
{
g_dbus_connection_close_sync(connection, nullptr, nullptr);
}
void repowerd::DBusConnectionHandle::request_name(char const* name) const
{
static constexpr uint32_t DBUS_NAME_FLAG_DO_NOT_QUEUE = 0x4;
static constexpr uint32_t DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER = 0x1;
repowerd::ScopedGError error;
int const timeout_default = -1;
auto const null_cancellable = nullptr;
auto result = g_dbus_connection_call_sync(
connection,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
"RequestName",
g_variant_new("(su)", name, DBUS_NAME_FLAG_DO_NOT_QUEUE),
G_VARIANT_TYPE("(u)"),
G_DBUS_CALL_FLAGS_NONE,
timeout_default,
null_cancellable,
error);
if (!result)
{
throw std::runtime_error(
"Failed to request DBus name '" +
std::string{name} + "': " + error.message_str());
}
uint32_t request_name_reply{0};
g_variant_get(result, "(u)", &request_name_reply);
g_variant_unref(result);
if (request_name_reply != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
{
throw std::runtime_error(
"Failed to become the primary owner of DBus name '" +
std::string{name} + "'");
}
}
repowerd::DBusConnectionHandle::operator GDBusConnection*() const
{
return connection;
}
repowerd-2022.01/src/adapters/dbus_connection_handle.h 0000664 0000000 0000000 00000002232 14176470112 0022743 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#pragma once
#include
#include
namespace repowerd
{
class DBusConnectionHandle
{
public:
DBusConnectionHandle(std::string const& address);
~DBusConnectionHandle();
void request_name(char const* name) const;
operator GDBusConnection*() const;
private:
DBusConnectionHandle(DBusConnectionHandle const&) = delete;
DBusConnectionHandle& operator=(DBusConnectionHandle const&) = delete;
GDBusConnection* connection;
};
}
repowerd-2022.01/src/adapters/dbus_event_loop.cpp 0000664 0000000 0000000 00000013757 14176470112 0022014 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "dbus_event_loop.h"
#include "event_loop_handler_registration.h"
#include "scoped_g_error.h"
namespace
{
// Send a synchronous request to ensure all previous requests have
// reached the dbus daemon
void repowerd_g_dbus_connection_wait_for_requests(GDBusConnection* connection)
{
int const timeout_default = -1;
auto const null_cancellable = nullptr;
auto const null_args = nullptr;
auto const null_return_args_types = nullptr;
auto const null_error = nullptr;
auto result = g_dbus_connection_call_sync(
connection,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
"GetId",
null_args,
null_return_args_types,
G_DBUS_CALL_FLAGS_NONE,
timeout_default,
null_cancellable,
null_error);
g_variant_unref(result);
}
}
repowerd::HandlerRegistration repowerd::DBusEventLoop::register_object_handler(
GDBusConnection* dbus_connection,
char const* dbus_path,
char const* introspection_xml,
DBusEventLoopMethodCallHandler const& handler)
{
struct ObjectContext
{
static void static_call(
GDBusConnection* connection,
char const* sender,
char const* object_path,
char const* interface_name,
char const* method_name,
GVariant* parameters,
GDBusMethodInvocation* invocation,
ObjectContext* ctx)
{
ctx->handler(
connection, sender, object_path, interface_name,
method_name, parameters, invocation);
}
static void static_destroy(ObjectContext* ctx) { delete ctx; }
DBusEventLoopMethodCallHandler const handler;
};
unsigned int registration_id = 0;
auto done = enqueue(
[&]
{
auto const introspection_data = g_dbus_node_info_new_for_xml(
introspection_xml, NULL);
GDBusInterfaceVTable interface_vtable;
interface_vtable.method_call =
reinterpret_cast(&ObjectContext::static_call);
interface_vtable.get_property = nullptr;
interface_vtable.set_property = nullptr;
ScopedGError error;
registration_id = g_dbus_connection_register_object(
dbus_connection,
dbus_path,
introspection_data->interfaces[0],
&interface_vtable,
new ObjectContext{handler},
reinterpret_cast(&ObjectContext::static_destroy),
error);
g_dbus_node_info_unref(introspection_data);
if (error.is_set())
{
throw std::runtime_error{
"Failed to register DBus object '" + std::string{dbus_path} + "': " +
error.message_str()};
}
});
done.wait();
// g_dbus_connection_register_object() is not synchronous, so wait for
// the registration (really a DBus AddMatch request) to be processed
// by the server
repowerd_g_dbus_connection_wait_for_requests(dbus_connection);
return EventLoopHandlerRegistration(
*this,
[dbus_connection,registration_id]
{
g_dbus_connection_unregister_object(
dbus_connection,
registration_id);
});
}
repowerd::HandlerRegistration repowerd::DBusEventLoop::register_signal_handler(
GDBusConnection* dbus_connection,
char const* dbus_sender,
char const* dbus_interface,
char const* dbus_member,
char const* dbus_path,
DBusEventLoopSignalHandler const& handler)
{
struct SignalContext
{
static void static_call(
GDBusConnection* connection,
char const* sender,
char const* object_path,
char const* interface_name,
char const* signal_name,
GVariant* parameters,
SignalContext* ctx)
{
ctx->handler(
connection, sender, object_path, interface_name,
signal_name, parameters);
}
static void static_destroy(SignalContext* ctx) { delete ctx; }
DBusEventLoopSignalHandler const handler;
};
unsigned int registration_id = 0;
auto done = enqueue(
[&]
{
registration_id = g_dbus_connection_signal_subscribe(
dbus_connection,
dbus_sender,
dbus_interface,
dbus_member,
dbus_path,
nullptr,
G_DBUS_SIGNAL_FLAGS_NONE,
reinterpret_cast(&SignalContext::static_call),
new SignalContext{handler},
reinterpret_cast(&SignalContext::static_destroy));
});
done.wait();
// g_dbus_connection_signal_subscribe() is not synchronous, so wait for
// the subscription (really a DBus AddMatch request) to be processed
// by the server
repowerd_g_dbus_connection_wait_for_requests(dbus_connection);
return EventLoopHandlerRegistration(
*this,
[dbus_connection,registration_id]
{
g_dbus_connection_signal_unsubscribe(
dbus_connection,
registration_id);
});
}
repowerd-2022.01/src/adapters/dbus_event_loop.h 0000664 0000000 0000000 00000004023 14176470112 0021443 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#pragma once
#include "event_loop.h"
#include "src/core/handler_registration.h"
#include
namespace repowerd
{
using DBusEventLoopMethodCallHandler =
std::function<
void(
GDBusConnection* connection,
char const* sender,
char const* object_path,
char const* interface_name,
char const* method_name,
GVariant* parameters,
GDBusMethodInvocation* invocation)>;
using DBusEventLoopSignalHandler =
std::function<
void(
GDBusConnection* connection,
char const* sender,
char const* object_path,
char const* interface_name,
char const* signal_name,
GVariant* parameters)>;
class DBusEventLoop : public EventLoop
{
public:
using EventLoop::EventLoop;
repowerd::HandlerRegistration register_object_handler(
GDBusConnection* dbus_connection,
char const* dbus_path,
char const* introspection_xml,
DBusEventLoopMethodCallHandler const& handler);
repowerd::HandlerRegistration register_signal_handler(
GDBusConnection* dbus_connection,
char const* dbus_sender,
char const* dbus_interface,
char const* dbus_member,
char const* dbus_path,
DBusEventLoopSignalHandler const& handler);
};
}
repowerd-2022.01/src/adapters/dbus_message_handle.cpp 0000664 0000000 0000000 00000003027 14176470112 0022566 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "dbus_message_handle.h"
#include
repowerd::DBusMessageHandle::DBusMessageHandle(GDBusMessage* message)
: message{message}
{
}
repowerd::DBusMessageHandle::DBusMessageHandle(GDBusMessage* message, GVariant* params)
: message{message}
{
if (!message)
throw std::runtime_error("Failed to create DBusMessageHandle with invalid dbus message");
g_dbus_message_set_body(message, params);
}
repowerd::DBusMessageHandle::DBusMessageHandle(DBusMessageHandle&& other) noexcept
: message{other.message}
{
other.message = nullptr;
}
repowerd::DBusMessageHandle::~DBusMessageHandle()
{
if (message)
g_object_unref(message);
}
repowerd::DBusMessageHandle::operator GDBusMessage*() const
{
return message;
}
repowerd::DBusMessageHandle::operator bool() const
{
return message != nullptr;
}
repowerd-2022.01/src/adapters/dbus_message_handle.h 0000664 0000000 0000000 00000002303 14176470112 0022227 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#pragma once
#include
namespace repowerd
{
class DBusMessageHandle
{
public:
DBusMessageHandle(GDBusMessage* message);
DBusMessageHandle(GDBusMessage* message, GVariant* params);
DBusMessageHandle(DBusMessageHandle&&) noexcept;
~DBusMessageHandle();
operator GDBusMessage*() const;
operator bool() const;
private:
DBusMessageHandle(DBusMessageHandle const&) = delete;
DBusMessageHandle& operator=(DBusMessageHandle const&) = delete;
GDBusMessage* message;
};
}
repowerd-2022.01/src/adapters/default_state_machine_options.cpp 0000664 0000000 0000000 00000010426 14176470112 0024676 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "default_state_machine_options.h"
#include "src/core/log.h"
#include "src/core/infinite_timeout.h"
#include
using namespace std::chrono_literals;
namespace
{
char const* const log_tag = "DefaultStateMachineOptions";
std::string determine_device_name()
{
char name[PROP_VALUE_MAX] = "";
property_get("ro.product.device", name, "");
return name;
}
bool treat_power_button_as_user_activity_for(
std::string const& device_name)
{
// On non-phablet/non-android devices the power button
// is treated as a generic power-state-changing user activity, i.e.,
// it can turn on the screen but not turn it off
return device_name.empty();
}
}
repowerd::DefaultStateMachineOptions::DefaultStateMachineOptions(
repowerd::Log& log)
: device_name_{determine_device_name()},
treat_power_button_as_user_activity_{
treat_power_button_as_user_activity_for(determine_device_name())}
{
log.log(log_tag, "DeviceName: %s", device_name_.c_str());
log.log(log_tag, "Option: notification_expiration_timeout=%lld",
static_cast(notification_expiration_timeout().count()));
log.log(log_tag, "Option: power_button_long_press_timeout=%lld",
static_cast(power_button_long_press_timeout().count()));
log.log(log_tag, "Option: treat_power_button_as_user_activity=%s",
treat_power_button_as_user_activity() ? "true" : "false");
log.log(log_tag, "Option: turn_on_display_at_startup=%s",
turn_on_display_at_startup() ? "true" : "false");
log.log(log_tag, "Option: user_inactivity_normal_display_dim_duration=%lld",
static_cast(user_inactivity_normal_display_dim_duration().count()));
log.log(log_tag, "Option: user_inactivity_normal_display_off_timeout=%lld",
static_cast(user_inactivity_normal_display_off_timeout().count()));
log.log(log_tag, "Option: user_inactivity_normal_suspend_timeout=%lld",
static_cast(user_inactivity_normal_suspend_timeout().count()));
log.log(log_tag, "Option: user_inactivity_post_notification_display_off_timeout=%lld",
static_cast(user_inactivity_post_notification_display_off_timeout().count()));
log.log(log_tag, "Option: user_inactivity_reduced_display_off_timeout=%lld",
static_cast(user_inactivity_reduced_display_off_timeout().count()));
}
std::chrono::milliseconds
repowerd::DefaultStateMachineOptions::notification_expiration_timeout() const
{
return 60s;
}
std::chrono::milliseconds
repowerd::DefaultStateMachineOptions::power_button_long_press_timeout() const
{
return 2s;
}
std::chrono::milliseconds
repowerd::DefaultStateMachineOptions::user_inactivity_normal_display_dim_duration() const
{
return 10s;
}
std::chrono::milliseconds
repowerd::DefaultStateMachineOptions::user_inactivity_normal_display_off_timeout() const
{
return 60s;
}
std::chrono::milliseconds
repowerd::DefaultStateMachineOptions::user_inactivity_normal_suspend_timeout() const
{
return repowerd::infinite_timeout;
}
std::chrono::milliseconds
repowerd::DefaultStateMachineOptions::user_inactivity_post_notification_display_off_timeout() const
{
return 5s;
}
std::chrono::milliseconds
repowerd::DefaultStateMachineOptions::user_inactivity_reduced_display_off_timeout() const
{
return 10s;
}
bool repowerd::DefaultStateMachineOptions::treat_power_button_as_user_activity() const
{
return treat_power_button_as_user_activity_;
}
bool repowerd::DefaultStateMachineOptions::turn_on_display_at_startup() const
{
return true;
}
repowerd-2022.01/src/adapters/default_state_machine_options.h 0000664 0000000 0000000 00000003361 14176470112 0024343 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#pragma once
#include "src/core/state_machine_options.h"
#include
namespace repowerd
{
class Log;
class DefaultStateMachineOptions : public StateMachineOptions
{
public:
DefaultStateMachineOptions(Log& log);
std::chrono::milliseconds notification_expiration_timeout() const override;
std::chrono::milliseconds power_button_long_press_timeout() const override;
std::chrono::milliseconds user_inactivity_normal_display_dim_duration() const override;
std::chrono::milliseconds user_inactivity_normal_display_off_timeout() const override;
std::chrono::milliseconds user_inactivity_normal_suspend_timeout() const override;
std::chrono::milliseconds user_inactivity_post_notification_display_off_timeout() const override;
std::chrono::milliseconds user_inactivity_reduced_display_off_timeout() const override;
bool treat_power_button_as_user_activity() const override;
bool turn_on_display_at_startup() const override;
private:
std::string const device_name_;
bool const treat_power_button_as_user_activity_;
};
}
repowerd-2022.01/src/adapters/dev_alarm_wakeup_service.cpp 0000664 0000000 0000000 00000011750 14176470112 0023642 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "dev_alarm_wakeup_service.h"
#include "filesystem.h"
#include
#include
#include
#include
#include
namespace
{
auto null_handler = [](auto){};
void ioctl_or_throw(
repowerd::Filesystem& fs,
int fd, unsigned long request, void* args,
char const* error_msg)
{
int retval;
do
{
retval = fs.ioctl(fd, request, args);
}
while (retval < 0 && errno == EINTR);
if (retval < 0)
throw std::system_error{errno, std::system_category(), error_msg};
}
timespec to_timespec(std::chrono::system_clock::time_point const& tp)
{
auto d = tp.time_since_epoch();
auto const sec = std::chrono::duration_cast(d);
timespec ts;
ts.tv_sec = sec.count();
ts.tv_nsec = std::chrono::duration_cast(d - sec).count();
return ts;
}
}
repowerd::DevAlarmWakeupService::DevAlarmWakeupService(
std::shared_ptr const& filesystem)
: filesystem{filesystem},
dev_alarm_fd{filesystem->open("/dev/alarm", O_RDWR)},
running{true},
cookie_pool{1},
wakeup_handler{null_handler}
{
if (dev_alarm_fd == -1)
throw std::system_error{errno, std::system_category(), "Failed to open /dev/alarm"};
reset_hardware_alarm();
wakeup_thread = std::thread(
[this]
{
std::unique_lock lock{wakeup_mutex};
while (running)
{
lock.unlock();
ioctl_or_throw(
*this->filesystem, dev_alarm_fd, ANDROID_ALARM_WAIT, nullptr,
"Failed to wait for alarm on /dev/alarm");
lock.lock();
if (running && !wakeups.empty())
{
auto const wakeup = *wakeups.begin();
cookie_pool.remove(std::stoull(wakeup.second));
wakeups.erase(wakeups.begin());
auto const handler = wakeup_handler;
lock.unlock();
handler(wakeup.second);
lock.lock();
}
reset_hardware_alarm();
}
});
}
repowerd::DevAlarmWakeupService::~DevAlarmWakeupService()
{
{
std::lock_guard lock{wakeup_mutex};
running = false;
reset_hardware_alarm();
}
wakeup_thread.join();
}
std::string repowerd::DevAlarmWakeupService::schedule_wakeup_at(
std::chrono::system_clock::time_point tp)
{
std::lock_guard lock{wakeup_mutex};
auto const cookie = std::to_string(cookie_pool.generate());
wakeups.insert({tp, cookie});
reset_hardware_alarm();
return cookie;
}
void repowerd::DevAlarmWakeupService::cancel_wakeup(std::string const& cookie)
{
std::lock_guard lock{wakeup_mutex};
for (auto iter = wakeups.begin(); iter != wakeups.end(); ++iter)
{
if (iter->second == cookie)
{
cookie_pool.remove(std::stoull(cookie));
wakeups.erase(iter);
break;
}
}
reset_hardware_alarm();
}
repowerd::HandlerRegistration repowerd::DevAlarmWakeupService::register_wakeup_handler(
WakeupHandler const& handler)
{
std::lock_guard lock{wakeup_mutex};
wakeup_handler = handler;
return repowerd::HandlerRegistration{
[this]
{
std::lock_guard lock{wakeup_mutex};
wakeup_handler = null_handler;
}};
}
unsigned int repowerd::DevAlarmWakeupService::num_stored_elements()
{
std::lock_guard lock{wakeup_mutex};
return cookie_pool.size() + wakeups.size();
}
void repowerd::DevAlarmWakeupService::reset_hardware_alarm()
{
using std::chrono::system_clock;
timespec next_wakeup;
if (running)
{
if (wakeups.empty())
{
next_wakeup = to_timespec(system_clock::now() + std::chrono::hours(24 * 30));
}
else
{
next_wakeup = to_timespec(wakeups.begin()->first);
}
}
else
{
next_wakeup = to_timespec(system_clock::time_point{});
}
ioctl_or_throw(
*filesystem, dev_alarm_fd, ANDROID_ALARM_SET(ANDROID_ALARM_RTC_WAKEUP), &next_wakeup,
"Failed to set alarm on /dev/alarm");
}
repowerd-2022.01/src/adapters/dev_alarm_wakeup_service.h 0000664 0000000 0000000 00000003274 14176470112 0023311 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#pragma once
#include "wakeup_service.h"
#include "fd.h"
#include "unique_random_pool.h"
#include