pax_global_header 0000666 0000000 0000000 00000000064 14460341002 0014504 g ustar 00root root 0000000 0000000 52 comment=fe8c421fd0977c21c47de2ba4630952dc47fd47b
repowerd-2023.07/ 0000775 0000000 0000000 00000000000 14460341002 0013510 5 ustar 00root root 0000000 0000000 repowerd-2023.07/AUTHORS 0000664 0000000 0000000 00000000343 14460341002 0014560 0 ustar 00root root 0000000 0000000 Alexander Martinz
Alexandros Frantzis
Alfred Neumayer
Dalton Durst
Erfan Abdi
Florian Leeber
Guido Berhoerster
Jami Kettunen
Katharine Chui
Luca Weiss
Marius Gripsgard
Michał Sawicz
Mike Gabriel
Ratchanan Srirattanamet
Rodney
repowerd-2023.07/CMakeLists.txt 0000664 0000000 0000000 00000007427 14460341002 0016262 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 "2023.07")
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)
option(REPOWERD_ENABLE_BINDER "Enable binder 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(DEVICEINFO REQUIRED deviceinfo)
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()
if (REPOWERD_ENABLE_BINDER)
pkg_check_modules(GBINDER REQUIRED libgbinder)
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-2023.07/ChangeLog 0000664 0000000 0000000 00000116432 14460341002 0015271 0 ustar 00root root 0000000 0000000 2023-07-27 Marius Gripsgard
* Release 2023.07 (HEAD -> main, tag: 2023.07)
* Add more missing headers for gcc 13 (5e125ca)
2023-06-08 Mike Gabriel
* Merge branch 'headers' into 'main' (7559c26)
2023-06-07 Luca Weiss
* Add missing headers for GCC13 (903b227)
2023-04-21 Mike Gabriel
* Merge branch 'listSysRequests' into 'main' (d4368a0)
2023-04-01 Katharine Chui
* support listing keep display on and notification requests on the
interface (13b8c49)
2023-03-31 Katharine Chui
* unity_screen_service: implement
com.lomiri.Repowerd.listSysRequests() (f76a473)
2023-04-08 Marius Gripsgard
* Merge branch 'personal/peat-psuwit/sensorfw-fixes' into 'main'
(24d9f03)
2023-03-11 Ratchanan Srirattanamet
* socketreader: correct isConnected() logic inversion (b26571b)
* socketreader: log error and handle EOF more gracefully (06067ac)
* sensorfw_common: clean up after itself if it fails to start
(16c18bf)
2023-03-10 Ratchanan Srirattanamet
* utils/socketreader: fix integer overflow in skipAll() (9a1129a)
2023-03-09 Ratchanan Srirattanamet
* sensorfw/common: don't leak pluginPath (228d66a)
2023-04-04 Ratchanan Srirattanamet
* Merge branch 'nullptr-mClient' into 'main' (8c72375)
2023-04-04 Jami Kettunen
* BinderPerformanceBooster: Guarantee mRemote init before mClient
(11a98b2)
2023-04-03 Jami Kettunen
* BinderPerformanceBooster: Initialize new private vars as nullptr
(041de9e)
2023-03-31 Marius Gripsgard
* Merge branch 'personal/fredldotme/powerhal' into 'main' (d96d1a5)
2023-03-27 Alfred Neumayer
* BinderPerformanceBooster: Set proper data parameter when calling
PowerHAL PowerHint feature (b2fbc06)
2023-03-18 Alfred Neumayer
* binder_performance_booster: Plug memory leak and nullptr check for
Halium 7.1 (1041610)
* binder_performance_booster: PowerHints & PowerScene support
(4b5e3af)
2023-02-25 Alfred Neumayer
* debian: Enable Binder-based PowerHAL booster (272bf07)
* src: Implement PowerHAL integration (2fbc1e1)
2023-03-16 Ratchanan Srirattanamet
* Merge branch 'screenBrightnessBacklight' into 'main' (062ef8e)
2023-03-13 Katharine Chui
* adapter: add comments regarding the usage of
screenBrightnessBacklight (bf8b7dc)
2022-07-01 Alfred Neumayer
* adapters: Fix Autobrightness exception logging (aebee4d)
2021-03-19 Marius Gripsgard
* Adapters: Make sure to log why we failed to create brightness
spline (68a88ad)
2020-05-28 Erfan Abdi
* [DNM] Add android 9 overlays auto brightness support (df75fe5)
2023-03-16 Mike Gabriel
* Merge branch 'personal/peat-psuwit/sensorfw-light-skip-bogus' into
'main' (63248fc)
2023-03-14 Ratchanan Srirattanamet
* SensorfwLightSensor: skip bogus value of 0 (b602097)
Fixes:
https://gitlab.com/ubports/development/core/repowerd/-/issues/38
2023-03-15 Mike Gabriel
* Merge branch 'personal/gberh/log-levels' into 'main' (9e5225a)
2023-03-14 Guido Berhoerster
* Make log level threshold configurable and set default (918f9de)
* Make use of log levels (0438fcf)
* Add log levels to logger (904f6fb)
2023-02-26 Mike Gabriel
* Merge branch 'focal-proper-backlight-ctrl' into 'main' (32605e4)
2022-03-23 Florian Leeber
* Try to improve dimming durations (90eae65)
2023-02-17 Mike Gabriel
* Merge branch 'personal/sunweaver/log-suspend-blocker-id' into
'main' (bd7a5d4)
2021-07-15 Dalton Durst
* Log the suspend blocker ID in DefaultStateMachine (e304aa8)
2023-02-15 Mike Gabriel
* Merge branch 'gmock-usage' into 'main' (d4632a3)
2022-08-02 Luca Weiss
* Fix GMock library target usage (4d1a97e)
2022-12-15 Marius Gripsgard
* Merge branch 'personal/gberh/add-envfile' into 'main' (fb27f3b)
2022-12-15 Guido Berhoerster
* Add example environment file read by the systemd service file
(b999c49)
2022-12-13 Mike Gabriel
* Merge branch 'personal/fredldotme/sargofp4brightness' into 'main'
(20d4ba9)
2022-12-13 Alfred Neumayer
* adapters: sensorfw: Adjust DBus timeouts a bit (29e7228)
2022-07-01 Alfred Neumayer
* adapters: Loosen sensorfw timeouts a bit (851ec1e)
2022-12-02 Mike Gabriel
* Merge branch 'personal/fredldotme/sargosplines' into 'main'
(14e02fb)
2021-08-12 Alfred Neumayer
* autobrightness: Fix creating spline points with 255 values
(1bbbd7d)
2022-11-22 Mike Gabriel
* Merge branch 'sunweaver/personal/system-unit-with-cmake' into
'main' (542c458)
* debian/control: Add to B-D: systemd. (aba01c6)
2020-08-14 Marius Gripsgard
* Install systemd unit with cmake not just debian pkg (5d893cb)
2022-11-16 Mike Gabriel
* Merge branch 'personal/peat-psuwit/sensorfw-proper' into 'main'
(8accb8e)
2022-11-11 Ratchanan Srirattanamet
* debian/repowerd.service: add deps on dbus.socket and sensorfwd
(882b1c8)
2020-04-04 Marius Gripsgard
* [adapters] Implement sensorfw light and proximity adapters
(18d87bb)
2022-08-15 Ratchanan Srirattanamet
* Merge branch 'systemd-migration' into 'main' (0a01a97)
2022-08-15 Guido Berhoerster
* Remove unused upstart job (656ad47)
2022-08-01 Marius Gripsgard
* Merge branch 'mr/typo-fix' into 'main' (75048fc)
2022-07-13 Marius Gripsgard
* Merge branch 'main-dt2w' into 'main' (d6dcb7e)
2022-03-15 Alexander Martinz
* Introduce support for Double Tap To Wake (DT2W) (5c1863a)
2022-05-31 Ratchanan Srirattanamet
* Merge branch 'personal/mariogrip/focal_-_deviceinfo' into 'main'
(67a5e59)
2020-01-19 Marius Gripsgard
* Replace libandroid-properties with libdeviceinfo (e963bc4)
2022-02-16 Mike Gabriel
* src/adapters/unity_screen_service.cpp: Typo fix. (5ec81f6)
2022-02-02 Mike Gabriel
* Release 2022.01 (c9637e9) (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-2023.07/cmake/ 0000775 0000000 0000000 00000000000 14460341002 0014570 5 ustar 00root root 0000000 0000000 repowerd-2023.07/cmake/FindAndroidHeaders.cmake 0000664 0000000 0000000 00000000304 14460341002 0021244 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-2023.07/data/ 0000775 0000000 0000000 00000000000 14460341002 0014421 5 ustar 00root root 0000000 0000000 repowerd-2023.07/data/CMakeLists.txt 0000664 0000000 0000000 00000002566 14460341002 0017172 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")
FILE(GLOB systemd_file "${CMAKE_CURRENT_SOURCE_DIR}/repowerd.service")
install(
FILES ${device_config_files}
DESTINATION ${REPOWERD_DEVICE_CONFIG_DIR}
)
install(
FILES ${dbus_config_files}
DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/dbus-1/system.d
)
pkg_check_modules(SYSTEMD systemd)
if (${SYSTEMD_FOUND})
pkg_get_variable(SYSTEMD_SYSTEM_DIR systemd systemdsystemunitdir)
message (STATUS "${SYSTEMD_SYSTEM_DIR} is the systemd system unit file install dir")
install (FILES "${systemd_file}" DESTINATION "${SYSTEMD_SYSTEM_DIR}")
endif()
repowerd-2023.07/data/dbus-configs/ 0000775 0000000 0000000 00000000000 14460341002 0017004 5 ustar 00root root 0000000 0000000 repowerd-2023.07/data/dbus-configs/com.canonical.Unity.Screen.conf 0000664 0000000 0000000 00000001146 14460341002 0024706 0 ustar 00root root 0000000 0000000
repowerd-2023.07/data/dbus-configs/com.lomiri.Repowerd.Settings.conf 0000664 0000000 0000000 00000001106 14460341002 0025306 0 ustar 00root root 0000000 0000000
repowerd-2023.07/data/dbus-configs/com.lomiri.Repowerd.conf 0000664 0000000 0000000 00000004577 14460341002 0023526 0 ustar 00root root 0000000 0000000
repowerd-2023.07/data/device-configs/ 0000775 0000000 0000000 00000000000 14460341002 0017306 5 ustar 00root root 0000000 0000000 repowerd-2023.07/data/device-configs/config-default.xml 0000664 0000000 0000000 00000007662 14460341002 0022732 0 ustar 00root root 0000000 0000000
false
4
680
10
255
102
10
repowerd-2023.07/data/device-configs/config-flo.xml 0000664 0000000 0000000 00000006636 14460341002 0022066 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-2023.07/data/device-configs/config-grouper.xml 0000664 0000000 0000000 00000005665 14460341002 0022772 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-2023.07/data/device-configs/config-hammerhead.xml 0000664 0000000 0000000 00000006305 14460341002 0023372 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-2023.07/data/device-configs/config-maguro.xml 0000664 0000000 0000000 00000005426 14460341002 0022574 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-2023.07/data/device-configs/config-mako.xml 0000664 0000000 0000000 00000006526 14460341002 0022233 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-2023.07/data/device-configs/config-manta.xml 0000664 0000000 0000000 00000006624 14460341002 0022403 0 ustar 00root root 0000000 0000000
true
- 10
- 30
- 90
- 15000
- 225000
- 10
- 13
- 65
- 85
- 220
- 255
2
repowerd-2023.07/data/repowerd.service 0000664 0000000 0000000 00000000501 14460341002 0017626 0 ustar 00root root 0000000 0000000 [Unit]
Description=monitor and control system power state
Wants=lxc-android-config.service dbus.socket socketfwd.service
After=lxc-android-config.service dbus.socket
[Service]
Type=dbus
BusName=com.lomiri.Repowerd
ExecStart=/usr/sbin/repowerd
EnvironmentFile=-/etc/default/repowerd
[Install]
WantedBy=multi-user.target
repowerd-2023.07/debian/ 0000775 0000000 0000000 00000000000 14460341002 0014732 5 ustar 00root root 0000000 0000000 repowerd-2023.07/debian/20-repowerd.conf 0000664 0000000 0000000 00000000120 14460341002 0017640 0 ustar 00root root 0000000 0000000 :programname,isequal,"repowerd" /var/log/repowerd.log;RSYSLOG_FileFormat
& stop
repowerd-2023.07/debian/Jenkinsfile 0000664 0000000 0000000 00000000651 14460341002 0017120 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-2023.07/debian/changelog 0000664 0000000 0000000 00000011325 14460341002 0016606 0 ustar 00root root 0000000 0000000 repowerd (2023.07) unstable; urgency=medium
* Upstream-provided Debian package for repowerd. See upstream
ChangeLog for recent changes.
-- UBports developers Thu, 27 Jul 2023 03:01:54 +0200
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-2023.07/debian/compat 0000664 0000000 0000000 00000000002 14460341002 0016130 0 ustar 00root root 0000000 0000000 9
repowerd-2023.07/debian/control 0000664 0000000 0000000 00000004173 14460341002 0016342 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,
libdeviceinfo-dev,
libgbinder-dev,
libglib2.0-dev,
libgtest-dev,
pkg-config,
systemd [linux-any],
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-2023.07/debian/copyright 0000664 0000000 0000000 00000002075 14460341002 0016671 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-2023.07/debian/powerd.maintscript 0000664 0000000 0000000 00000000157 14460341002 0020514 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-2023.07/debian/repowerd-data.install 0000664 0000000 0000000 00000000023 14460341002 0021053 0 ustar 00root root 0000000 0000000 usr/share/repowerd
repowerd-2023.07/debian/repowerd-data.links 0000664 0000000 0000000 00000000150 14460341002 0020526 0 ustar 00root root 0000000 0000000 usr/share/repowerd/device-configs/config-default.xml usr/share/powerd/device_configs/config-default.xml
repowerd-2023.07/debian/repowerd-tools.install 0000664 0000000 0000000 00000000031 14460341002 0021301 0 ustar 00root root 0000000 0000000 usr/sbin/repowerd-*-tool
repowerd-2023.07/debian/repowerd.apport 0000664 0000000 0000000 00000001154 14460341002 0020011 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-2023.07/debian/repowerd.default 0000664 0000000 0000000 00000000503 14460341002 0020125 0 ustar 00root root 0000000 0000000 # to be overlaid by ports
#
# REPOWERD_DEVICE_CONFIG_DIR=/usr/share/repowerd/device-configs
# REPOWERD_LOG=(syslog|console|null)
# REPOWERD_LOG_LEVEL=(debug|info|warning)
# REPOWERD_LOG_AUTOBRIGHTNESS=true
# REPOWERD_QUIRK_NORMAL_BEFORE_DISPLAY_ON_AUTOBRIGHTNESS=(always|never)
# SENSORFW_SOCKET_PATH=/var/run/sensord.sock
repowerd-2023.07/debian/repowerd.install 0000664 0000000 0000000 00000000216 14460341002 0020150 0 ustar 00root root 0000000 0000000 usr/sbin/repowerd
usr/sbin/repowerd-cli
etc/dbus-1/system.d/*.conf
lib/systemd/system/repowerd.service
debian/20-repowerd.conf etc/rsyslog.d/
repowerd-2023.07/debian/repowerd.links 0000664 0000000 0000000 00000000052 14460341002 0017620 0 ustar 00root root 0000000 0000000 usr/sbin/repowerd-cli usr/sbin/powerd-cli
repowerd-2023.07/debian/repowerd.logrotate 0000664 0000000 0000000 00000000311 14460341002 0020476 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-2023.07/debian/rules 0000775 0000000 0000000 00000000512 14460341002 0016010 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_ENABLE_BINDER=ON \
-DREPOWERD_DISABLE_TIME_SENSITIVE_TESTS=ON
repowerd-2023.07/debian/source/ 0000775 0000000 0000000 00000000000 14460341002 0016232 5 ustar 00root root 0000000 0000000 repowerd-2023.07/debian/source/format 0000664 0000000 0000000 00000000015 14460341002 0017441 0 ustar 00root root 0000000 0000000 3.0 (native)
repowerd-2023.07/doc/ 0000775 0000000 0000000 00000000000 14460341002 0014255 5 ustar 00root root 0000000 0000000 repowerd-2023.07/doc/repowerd-settings-api.txt 0000664 0000000 0000000 00000003206 14460341002 0021253 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-2023.07/src/ 0000775 0000000 0000000 00000000000 14460341002 0014277 5 ustar 00root root 0000000 0000000 repowerd-2023.07/src/CMakeLists.txt 0000664 0000000 0000000 00000003000 14460341002 0017030 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()
if (REPOWERD_ENABLE_BINDER)
add_definitions(-DREPOWERD_ENABLE_BINDER)
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-2023.07/src/adapters/ 0000775 0000000 0000000 00000000000 14460341002 0016102 5 ustar 00root root 0000000 0000000 repowerd-2023.07/src/adapters/CMakeLists.txt 0000664 0000000 0000000 00000005704 14460341002 0020650 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()
if (REPOWERD_ENABLE_BINDER)
set(REPOWERD_ADAPTER_BINDER_SRCS
binder_performance_booster.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
fs_double_tap_to_wake.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_device_info.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
sensorfw/sensorfw_common.cpp
sensorfw/sensorfw_light_sensor.cpp
sensorfw/sensorfw_proximity_sensor.cpp
sensorfw/socketreader.cpp
${REPOWERD_ADAPTER_HYBRIS_SRCS}
${REPOWERD_ADAPTER_BINDER_SRCS}
)
add_library(
repowerd-adapters STATIC
${REPOWERD_ADAPTER_SRCS}
)
target_link_libraries(
repowerd-adapters
suspend
${DEVICEINFO_LDFLAGS}
${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}
${GBINDER_LDFLAGS} ${GBINDER_LIBRARIES}
)
target_include_directories(
repowerd-adapters PUBLIC
${DEVICEINFO_INCLUDE_DIRS}
${GIO_INCLUDE_DIRS}
${GIO_UNIX_INCLUDE_DIRS}
${LIBHARDWARE_INCLUDE_DIRS}
${UA_INCLUDE_DIRS}
${UBUNTU_PLATFORM_HARDWARE_API_INCLUDE_DIRS}
${GBINDER_INCLUDE_DIRS}
)
repowerd-2023.07/src/adapters/android_autobrightness_algorithm.cpp 0000664 0000000 0000000 00000022031 14460341002 0025413 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, std::shared_ptr const& log)
try
{
auto const ab_light_levels_str = device_config.get("autoBrightnessLevels", "");
std::string ab_brightness_levels_str = device_config.get("autoBrightnessLcdBacklightValues", "");
if (ab_brightness_levels_str == "")
// FIXME screenBrightnessBacklight is supposed to be used with screenBrightnessNits
// https://cs.android.com/android/platform/superproject/+/android-security-11.0.0_r64:frameworks/base/core/res/res/values/config.xml;l=1363
// https://gitlab.com/ubports/development/core/repowerd/-/issues/36
ab_brightness_levels_str = device_config.get("screenBrightnessBacklight", "");
if (ab_brightness_levels_str == "")
throw std::runtime_error{"Autobrightness not supported - Missing values"};
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() < 1 || ab_brightness_levels.size() < 2 ||
ab_brightness_levels.size() <= ab_light_levels.size() ||
ab_brightness_levels.size() > 255)
{
throw std::runtime_error{"Autobrightness not supported - Values in config are not valid"};
}
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();
int brightness_levels_steps = 1;
if (ab_brightness_levels.size() > ab_light_levels.size() + 1)
brightness_levels_steps = ab_brightness_levels.size() / ab_light_levels.size();
for (;
l_iter != ab_light_levels.end() && b_iter != ab_brightness_levels.end();
++l_iter, b_iter+=brightness_levels_steps)
{
points.push_back({static_cast(*l_iter), static_cast(*b_iter)});
}
return std::make_unique(points);
}
catch (std::exception& e)
{
log->log(log_tag, "%s", e.what());
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, log)},
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->logDebug(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->logDebug(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->logDebug(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->logDebug(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->logDebug(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-2023.07/src/adapters/android_autobrightness_algorithm.h 0000664 0000000 0000000 00000003714 14460341002 0025067 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-2023.07/src/adapters/android_backlight.cpp 0000664 0000000 0000000 00000004011 14460341002 0022232 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-2023.07/src/adapters/android_backlight.h 0000664 0000000 0000000 00000002020 14460341002 0021675 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-2023.07/src/adapters/android_device_config.cpp 0000664 0000000 0000000 00000014136 14460341002 0023077 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 "device_info.h"
char const* const log_tag = "AndroidDeviceConfig";
repowerd::AndroidDeviceConfig::AndroidDeviceConfig(
std::shared_ptr const& log,
std::shared_ptr const& filesystem,
std::shared_ptr const& device_info,
std::vector const& config_dirs)
: log{log},
filesystem{filesystem}
{
for (auto const& dir : config_dirs)
log->logDebug(log_tag, "Using config directory: %s", dir.c_str());
parse_first_matching_file_in_dirs(config_dirs, "config-default.xml");
auto const device_name = device_info->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->logDebug(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->logDebug(log_tag, "Property: %s=%s",
property.first.c_str(), property.second.c_str());
}
}
repowerd-2023.07/src/adapters/android_device_config.h 0000664 0000000 0000000 00000004710 14460341002 0022541 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 DeviceInfo;
class AndroidDeviceConfig : public DeviceConfig
{
public:
AndroidDeviceConfig(
std::shared_ptr const& log,
std::shared_ptr const& filesystem,
std::shared_ptr const& device_info,
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-2023.07/src/adapters/android_device_quirks.cpp 0000664 0000000 0000000 00000010747 14460341002 0023154 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 "device_info.h"
using namespace std::chrono_literals;
namespace
{
char const* const log_tag = "AndroidDeviceQuirks";
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";
}
}
repowerd::AndroidDeviceQuirks::AndroidDeviceQuirks(
repowerd::Log& log,
std::shared_ptr const& device_info)
: device_name_{device_info->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_{!device_info->is_desktop()}
{
log.logDebug(log_tag, "DeviceName: %s", device_name_.c_str());
log.logDebug(log_tag, "Quirk: synthetic_initial_proximit_event_delay=%d",
static_cast(synthetic_initial_proximity_event_delay_.count()));
log.logDebug(log_tag, "Quirk: synthetic_initial_proximit_event_type=%s",
proximity_event_type_to_str(synthetic_initial_proximity_event_type_).c_str());
log.logDebug(log_tag, "Quirk: normal_before_display_on_autobrightness=%s",
normal_before_display_on_autobrightness_ ? "true" : "false");
log.logDebug(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-2023.07/src/adapters/android_device_quirks.h 0000664 0000000 0000000 00000003032 14460341002 0022606 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
#include
namespace repowerd
{
class Log;
class DeviceInfo;
class AndroidDeviceQuirks : public DeviceQuirks
{
public:
AndroidDeviceQuirks(Log& log, std::shared_ptr const& device_info);
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-2023.07/src/adapters/autobrightness_algorithm.h 0000664 0000000 0000000 00000002710 14460341002 0023362 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-2023.07/src/adapters/backlight.h 0000664 0000000 0000000 00000002075 14460341002 0020207 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-2023.07/src/adapters/backlight_brightness_control.cpp 0000664 0000000 0000000 00000026467 14460341002 0024545 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},
average_time_passed{0},
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->logDebug(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 target_brightness, TransitionSpeed transition_speed)
{
auto step = 0.01;
auto const backlight_brightness = get_brightness_value();
auto const starting_brightness =
backlight_brightness == Backlight::unknown_brightness ?
target_brightness - step : backlight_brightness;
auto transition_time = (transition_speed == TransitionSpeed::slow ||
starting_brightness == 0.0
|| target_brightness == 0.0) ?
250000us : 1000us;
if (starting_brightness != target_brightness)
{
log->logDebug(log_tag, "Transitioning brightness %.2f => %.2f transition time %lldus",
starting_brightness, target_brightness, (long long int)transition_time.count());
}
auto current_brightness = starting_brightness;
if (current_brightness < target_brightness)
{
while (current_brightness < target_brightness)
{
current_brightness += step;
if (current_brightness > target_brightness) current_brightness = target_brightness;
set_brightness(target_brightness, current_brightness, step, transition_time);
}
}
else if (current_brightness > target_brightness)
{
while (current_brightness > target_brightness)
{
current_brightness -= step;
if (current_brightness < target_brightness) current_brightness = target_brightness;
set_brightness(target_brightness, current_brightness, step, transition_time);
}
}
if (starting_brightness != target_brightness)
{
log->logDebug(log_tag, "Transitioning brightness %.2f => %.2f done",
starting_brightness, current_brightness);
brightness_handler(target_brightness);
}
}
void repowerd::BacklightBrightnessControl::set_brightness(double target_brightness, double current_brightness, double &step, std::chrono::microseconds &transition_time)
{
// Time passed for executing a brightness change - calculate rough average
auto time_passed = set_brightness_value(current_brightness);
if (average_time_passed.count() == 0)
{
average_time_passed = time_passed;
}
else
{
average_time_passed = (average_time_passed + time_passed) / 2;
}
// Remaining delta to target brightness - If this is zero, we are done
auto remaining_delta = std::abs(target_brightness - current_brightness);
if (remaining_delta == 0)
{
return;
}
// If the remaining transition_time is less than the time needed for a step
// set the step size to the remaining brightness delta, finishing the transition immediately
if (transition_time.count() <= average_time_passed.count())
{
step = remaining_delta;
return;
}
// Else if this is the initial step try to determine the necessary step size
// to finish the transition in the remaining time
// Update remaining transition time
transition_time -= average_time_passed;
if ((step == 0.01 && average_time_passed.count() == 0) || average_time_passed.count() > 0) {
// Number of steps allowed to not exceed the remaining transition time
auto maximum_steps = transition_time.count() / average_time_passed.count();
// New step size
step = remaining_delta / maximum_steps;
/*
log->logDebug(log_tag, "Adjusted new step size: %.2f max steps: %lld rem delta: %.2f rem time: %lld avg time: %lld",
step, (long long int)maximum_steps, remaining_delta, (long long int)transition_time.count(), (long long int)average_time_passed.count());
*/
}
}
std::chrono::microseconds repowerd::BacklightBrightnessControl::set_brightness_value(double brightness)
{
auto t1 = chrono->steady_now();
backlight->set_brightness(brightness);
return std::chrono::duration_cast(chrono->steady_now() - t1);
}
double repowerd::BacklightBrightnessControl::get_brightness_value()
{
return backlight->get_brightness();
}
repowerd-2023.07/src/adapters/backlight_brightness_control.h 0000664 0000000 0000000 00000005772 14460341002 0024206 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
#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);
std::chrono::microseconds set_brightness_value(double brightness);
void set_brightness(double target_brightness, double current_brightness, double &step, std::chrono::microseconds &transition_time);
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;
std::chrono::microseconds average_time_passed;
ActiveBrightnessType active_brightness_type;
bool ab_active;
};
}
repowerd-2023.07/src/adapters/binder_performance_booster.cpp 0000664 0000000 0000000 00000014372 14460341002 0024176 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2023 UBports Foundation
*
* 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: Alfred Neumayer
*/
#include "binder_performance_booster.h"
#include
#include "src/core/log.h"
namespace
{
char const* const log_tag = "BinderPerformanceBooster";
}
repowerd::BinderPerformanceBooster::BinderPerformanceBooster(
std::shared_ptr const& log)
: active_interface(nullptr),
log{log},
mSm(nullptr),
mRemote(nullptr),
mClient(nullptr),
mSceneRemote(nullptr),
mSceneClient(nullptr)
{
DeviceInfo device_info;
const std::vector interfaces { &sprd_interface, &fallback_interface };
mSceneOnName = device_info.get("RepowerdPowerHalSceneOnName", "");
mSceneOffName = device_info.get("RepowerdPowerHalSceneOffName", "");
for (const auto interface : interfaces) {
mSm = gbinder_servicemanager_new(interface->device.c_str());
if (!mSm) {
continue;
}
// Try device-specific HALs first
mRemote = gbinder_servicemanager_get_service_sync(mSm, interface->fqname.c_str(), NULL);
if (!mRemote) {
gbinder_servicemanager_unref(mSm);
continue;
}
mClient = gbinder_client_new(mRemote, interface->interface.c_str());
if (!mClient) {
gbinder_remote_object_unref(mRemote);
gbinder_servicemanager_unref(mSm);
continue;
}
// Initialize optional scene functionality
if (!interface->scene_interface.empty() && !interface->scene_fqname.empty()) {
// Try exercising device-specific HALs functionality
mSceneRemote = gbinder_servicemanager_get_service_sync(mSm, interface->scene_fqname.c_str(), NULL);
if (mSceneRemote) {
mSceneClient = gbinder_client_new(mSceneRemote, interface->scene_interface.c_str());
}
if (!mSceneClient) {
gbinder_remote_object_unref(mSceneRemote);
}
}
active_interface = interface;
break;
}
if (!active_interface) {
log->log(log_tag, "No PowerHAL interface found");
}
}
repowerd::BinderPerformanceBooster::~BinderPerformanceBooster()
{
if (mSceneClient) {
gbinder_client_unref(mSceneClient);
mSceneClient = nullptr;
}
if (mClient) {
gbinder_client_unref(mClient);
mClient = nullptr;
}
if (mSceneRemote) {
gbinder_remote_object_unref(mSceneRemote);
mSceneRemote = nullptr;
}
if (mRemote) {
gbinder_remote_object_unref(mRemote);
mRemote = nullptr;
}
if (mSm) {
gbinder_servicemanager_unref(mSm);
mSm = nullptr;
}
}
void repowerd::BinderPerformanceBooster::set_interactive(const bool enabled)
{
if (!mClient)
return;
int status;
GBinderLocalRequest *req = gbinder_client_new_request(mClient);
GBinderRemoteReply *reply;
GBinderWriter writer;
gbinder_local_request_init_writer(req, &writer);
gbinder_writer_append_bool(&writer, enabled);
reply = gbinder_client_transact_sync_reply(mClient,
1 /* setInteractive */, req, &status);
if (reply)
gbinder_remote_reply_unref(reply);
gbinder_local_request_unref(req);
}
void repowerd::BinderPerformanceBooster::set_scenario(const HalPowerHint hint, const bool enabled)
{
if (!mClient)
return;
int status;
GBinderLocalRequest *req = gbinder_client_new_request(mClient);
GBinderRemoteReply *reply;
GBinderWriter writer;
gbinder_local_request_init_writer(req, &writer);
gbinder_writer_append_int32(&writer, static_cast(hint));
gbinder_writer_append_int32(&writer, enabled ? 1 : 0);
reply = gbinder_client_transact_sync_reply(mClient,
2 /* powerHint */, req, &status);
if (reply)
gbinder_remote_reply_unref(reply);
gbinder_local_request_unref(req);
}
void repowerd::BinderPerformanceBooster::acquire_power_scene(const std::string& name)
{
if (!mSceneClient || name.empty())
return;
GBinderLocalRequest *req = gbinder_client_new_request(mSceneClient);
GBinderWriter writer;
gbinder_local_request_init_writer(req, &writer);
gbinder_writer_append_string8(&writer, "repowerd");
gbinder_writer_append_string8(&writer, name.c_str());
gbinder_client_transact_sync_oneway(mSceneClient,
active_interface->scene_acquire_method, req);
gbinder_local_request_unref(req);
}
void repowerd::BinderPerformanceBooster::release_power_scene(const std::string& name)
{
if (!mSceneClient || name.empty())
return;
GBinderLocalRequest *req = gbinder_client_new_request(mSceneClient);
GBinderWriter writer;
gbinder_local_request_init_writer(req, &writer);
gbinder_writer_append_string8(&writer, name.c_str());
gbinder_client_transact_sync_oneway(mSceneClient,
active_interface->scene_release_method, req);
gbinder_local_request_unref(req);
}
void repowerd::BinderPerformanceBooster::enable_interactive_mode()
{
log->log(log_tag, "enable_interactive_mode()");
set_interactive(true);
set_scenario(LOW_POWER, false);
set_scenario(SUSTAINED_PERFORMANCE, true);
release_power_scene(mSceneOffName);
acquire_power_scene(mSceneOnName);
}
void repowerd::BinderPerformanceBooster::disable_interactive_mode()
{
log->log(log_tag, "disable_interactive_mode()");
set_interactive(false);
set_scenario(SUSTAINED_PERFORMANCE, false);
set_scenario(LOW_POWER, true);
release_power_scene(mSceneOnName);
acquire_power_scene(mSceneOffName);
}
repowerd-2023.07/src/adapters/binder_performance_booster.h 0000664 0000000 0000000 00000005333 14460341002 0023640 0 ustar 00root root 0000000 0000000 /*
* Copyright © 2023 UBports Foundation
*
* 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: Alfred Neumayer
*/
#pragma once
#include "src/core/performance_booster.h"
#include
#include
#include
#include
#include
#define BINDER_UNISOC_SERVICE_IFACE "vendor.sprd.hardware.power@4.0::IPower"
#define BINDER_UNISOC_SERVICE_FQNAME BINDER_UNISOC_SERVICE_IFACE "/default"
namespace repowerd
{
class Log;
class BinderPerformanceBooster : public PerformanceBooster
{
public:
BinderPerformanceBooster(std::shared_ptr const& log);
~BinderPerformanceBooster();
void enable_interactive_mode() override;
void disable_interactive_mode() override;
private:
struct PowerHalInterface {
std::string device;
std::string interface;
std::string fqname;
std::string scene_interface;
std::string scene_fqname;
int scene_acquire_method;
int scene_release_method;
};
enum HalPowerHint {
INTERACTION = 0x00000002,
LOW_POWER = 0x00000005,
SUSTAINED_PERFORMANCE = 0x00000006
};
PowerHalInterface sprd_interface {
"/dev/hwbinder",
"android.hardware.power@1.0::IPower",
"android.hardware.power@1.0::IPower/default",
"vendor.sprd.hardware.power@4.0::IPower",
"vendor.sprd.hardware.power@4.0::IPower/default",
11,
12
};
PowerHalInterface fallback_interface {
"/dev/hwbinder",
"android.hardware.power@1.0::IPower",
"android.hardware.power@1.0::IPower/default",
"",
"",
0,
0
};
PowerHalInterface* active_interface;
void set_interactive(const bool enable);
void set_scenario(const HalPowerHint hint, const bool enable);
void acquire_power_scene(const std::string& name);
void release_power_scene(const std::string& name);
std::string mSceneOnName;
std::string mSceneOffName;
std::shared_ptr const log;
GBinderServiceManager *mSm;
GBinderRemoteObject *mRemote;
GBinderClient *mClient;
GBinderRemoteObject *mSceneRemote;
GBinderClient *mSceneClient;
};
}
repowerd-2023.07/src/adapters/brightness_notification.h 0000664 0000000 0000000 00000002361 14460341002 0023173 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-2023.07/src/adapters/brightness_params.cpp 0000664 0000000 0000000 00000003312 14460341002 0022320 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-2023.07/src/adapters/brightness_params.h 0000664 0000000 0000000 00000001722 14460341002 0021770 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-2023.07/src/adapters/chrono.h 0000664 0000000 0000000 00000002056 14460341002 0017546 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;
virtual std::chrono::steady_clock::time_point steady_now() = 0;
protected:
Chrono() = default;
Chrono(Chrono const&) = delete;
Chrono& operator=(Chrono const&) = delete;
};
}
repowerd-2023.07/src/adapters/console_log.cpp 0000664 0000000 0000000 00000003341 14460341002 0021112 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
repowerd::ConsoleLog::ConsoleLog(repowerd::LogLevel threshold) : repowerd::Log::Log(threshold)
{
}
void repowerd::ConsoleLog::logOutput(repowerd::LogLevel level, char const* tag, char const* format, va_list ap)
{
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 += ": ";
switch (level) {
case LogLevel::Warning:
format_str += "WARNING";
break;
case LogLevel::Info:
format_str += "INFO";
break;
default:
format_str += "DEBUG";
}
format_str += ": ";
format_str += format;
format_str += "\n";
vprintf(format_str.c_str(), ap);
fflush(stdout);
}
repowerd-2023.07/src/adapters/console_log.h 0000664 0000000 0000000 00000001657 14460341002 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:
ConsoleLog(LogLevel threshold);
void logOutput(LogLevel level, char const* tag, char const* format, va_list ap) override;
};
}
repowerd-2023.07/src/adapters/dbus_connection_handle.cpp 0000664 0000000 0000000 00000005450 14460341002 0023301 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
#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-2023.07/src/adapters/dbus_connection_handle.h 0000664 0000000 0000000 00000002232 14460341002 0022741 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-2023.07/src/adapters/dbus_event_loop.cpp 0000664 0000000 0000000 00000013757 14460341002 0022012 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-2023.07/src/adapters/dbus_event_loop.h 0000664 0000000 0000000 00000004023 14460341002 0021441 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-2023.07/src/adapters/dbus_message_handle.cpp 0000664 0000000 0000000 00000003027 14460341002 0022564 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-2023.07/src/adapters/dbus_message_handle.h 0000664 0000000 0000000 00000002303 14460341002 0022225 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-2023.07/src/adapters/default_state_machine_options.cpp 0000664 0000000 0000000 00000007426 14460341002 0024702 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 "device_info.h"
using namespace std::chrono_literals;
char const* const log_tag = "DefaultStateMachineOptions";
repowerd::DefaultStateMachineOptions::DefaultStateMachineOptions(
repowerd::Log& log,
std::shared_ptr const& device_info_)
: device_info(device_info_)
{
log.logDebug(log_tag, "DeviceName: %s", device_info->name().c_str());
log.logDebug(log_tag, "Option: notification_expiration_timeout=%lld",
static_cast(notification_expiration_timeout().count()));
log.logDebug(log_tag, "Option: power_button_long_press_timeout=%lld",
static_cast(power_button_long_press_timeout().count()));
log.logDebug(log_tag, "Option: treat_power_button_as_user_activity=%s",
treat_power_button_as_user_activity() ? "true" : "false");
log.logDebug(log_tag, "Option: turn_on_display_at_startup=%s",
turn_on_display_at_startup() ? "true" : "false");
log.logDebug(log_tag, "Option: user_inactivity_normal_display_dim_duration=%lld",
static_cast(user_inactivity_normal_display_dim_duration().count()));
log.logDebug(log_tag, "Option: user_inactivity_normal_display_off_timeout=%lld",
static_cast(user_inactivity_normal_display_off_timeout().count()));
log.logDebug(log_tag, "Option: user_inactivity_normal_suspend_timeout=%lld",
static_cast(user_inactivity_normal_suspend_timeout().count()));
log.logDebug(log_tag, "Option: user_inactivity_post_notification_display_off_timeout=%lld",
static_cast(user_inactivity_post_notification_display_off_timeout().count()));
log.logDebug(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 device_info->is_desktop();
}
bool repowerd::DefaultStateMachineOptions::turn_on_display_at_startup() const
{
return true;
}
repowerd-2023.07/src/adapters/default_state_machine_options.h 0000664 0000000 0000000 00000003430 14460341002 0024336 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
#include
namespace repowerd
{
class Log;
class DeviceInfo;
class DefaultStateMachineOptions : public StateMachineOptions
{
public:
DefaultStateMachineOptions(Log& log, std::shared_ptr const& deviceInfo);
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::shared_ptr device_info;
};
}
repowerd-2023.07/src/adapters/dev_alarm_wakeup_service.cpp 0000664 0000000 0000000 00000011750 14460341002 0023640 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-2023.07/src/adapters/dev_alarm_wakeup_service.h 0000664 0000000 0000000 00000003274 14460341002 0023307 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