From 9a19aac39c2178c4dbd0e146b1d5bedf6e2caf55 Mon Sep 17 00:00:00 2001 From: tangjie02 Date: Wed, 10 May 2023 18:00:41 +0800 Subject: [PATCH] feature(power): Delete LockScreenWhenHibernate and LockScreenWhenSuspend functions and replace suspend/hibernate/shutdown api with SessionManager. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除当计算机休眠/待机时是否锁屏功能,将该功能移动到会话管理实现 Relates #68459 Signed-off-by: tangjie02 --- ...lete-LockScreenWhenHibernate-and-Loc.patch | 427 ++++++++++++++++++ kiran-cc-daemon.spec | 6 +- 2 files changed, 432 insertions(+), 1 deletion(-) create mode 100644 0001-feature-power-Delete-LockScreenWhenHibernate-and-Loc.patch diff --git a/0001-feature-power-Delete-LockScreenWhenHibernate-and-Loc.patch b/0001-feature-power-Delete-LockScreenWhenHibernate-and-Loc.patch new file mode 100644 index 0000000..db59f36 --- /dev/null +++ b/0001-feature-power-Delete-LockScreenWhenHibernate-and-Loc.patch @@ -0,0 +1,427 @@ +From be5fbd89a3bb0611e117c71325a34f417c19287a Mon Sep 17 00:00:00 2001 +From: tangjie02 +Date: Tue, 9 May 2023 16:59:23 +0800 +Subject: [PATCH] feature(power): Delete LockScreenWhenHibernate and + LockScreenWhenSuspend functions and replace suspend/hibernate/shutdown api + with SessionManager. +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +- 删除当计算机休眠/待机时是否锁屏功能,将该功能移动到会话管理实现 + +Relates #68459 + +Signed-off-by: tangjie02 +--- + .../com.kylinsec.kiran.power.gschema.xml.in | 10 -- + include/power-i.h | 4 - + ...com.kylinsec.Kiran.SessionDaemon.Power.xml | 24 ---- + plugins/power/power-manager.cpp | 34 ------ + plugins/power/power-manager.h | 8 -- + plugins/power/save/power-save-computer.cpp | 40 +------ + plugins/power/save/power-save-computer.h | 4 +- + plugins/power/wrapper/power-session.cpp | 111 ++++++++++++++++++ + plugins/power/wrapper/power-session.h | 10 ++ + 9 files changed, 126 insertions(+), 119 deletions(-) + +diff --git a/data/schemas/com.kylinsec.kiran.power.gschema.xml.in b/data/schemas/com.kylinsec.kiran.power.gschema.xml.in +index ab51e40..094ea2f 100644 +--- a/data/schemas/com.kylinsec.kiran.power.gschema.xml.in ++++ b/data/schemas/com.kylinsec.kiran.power.gschema.xml.in +@@ -97,16 +97,6 @@ + Whether does the cpu save energy when the ups or battery power is low. + + +- +- true +- Whether lock screen when the computer is suspend. +- +- +- +- true +- Whether lock screen when the computer is hibernate. +- +- + + 'suspend' + The action to take when the system suspend button is pressed. +diff --git a/include/power-i.h b/include/power-i.h +index 2aba2fc..8d33a91 100644 +--- a/include/power-i.h ++++ b/include/power-i.h +@@ -141,10 +141,6 @@ extern "C" + #define POWER_SCHEMA_ENABLE_CHARGE_LOW_DIMMED "enable-charge-low-dimmed" + // 电量过低时计算机是否进入节能模式 + #define POWER_SCHEMA_ENABLE_CHARGE_LOW_SAVER "enable-charge-low-saver" +-// 待机时是否锁定屏幕 +-#define POWER_SCHEMA_SCREEN_LOCKED_WHEN_SUSPEND "screen-locked-when-suspend" +-// 休眠时是否锁定屏幕 +-#define POWER_SCHEMA_SCREEN_LOCKED_WHEN_HIBERNATE "screen-locked-when-hibernate" + // 按下挂起键触发的节能行为 + #define POWER_SCHEMA_BUTTON_SUSPEND_ACTION "button-suspend-action" + // 按下休眠键触发的节能行为 +diff --git a/plugins/power/com.kylinsec.Kiran.SessionDaemon.Power.xml b/plugins/power/com.kylinsec.Kiran.SessionDaemon.Power.xml +index 29444f4..fe2f35e 100644 +--- a/plugins/power/com.kylinsec.Kiran.SessionDaemon.Power.xml ++++ b/plugins/power/com.kylinsec.Kiran.SessionDaemon.Power.xml +@@ -81,20 +81,6 @@ + Enable cpu save energy when the ups or battery power is low. + + +- +- +- Whether lock screen when the computer is suspend. +- +- Lock screen when the computer is suspend. +- +- +- +- +- Whether lock screen when the computer is hibernate. +- +- Lock screen when the computer is hibernate. +- +- + + + Indicates whether the system is running on battery power. +@@ -120,16 +106,6 @@ + Whether does the cpu save energy when the ups or battery power is low. + + +- +- +- Whether lock screen when the computer is suspend. +- +- +- +- +- Whether lock screen when the computer is hibernate. +- +- + + + +diff --git a/plugins/power/power-manager.cpp b/plugins/power/power-manager.cpp +index 8438b3f..9282b85 100644 +--- a/plugins/power/power-manager.cpp ++++ b/plugins/power/power-manager.cpp +@@ -329,18 +329,6 @@ void PowerManager::EnableChargeLowSaver(bool enabled, MethodInvocation& invocati + invocation.ret(); + } + +-void PowerManager::LockScreenWhenSuspend(bool enabled, MethodInvocation& invocation) +-{ +- this->ScreenLockedWhenSuspend_set(enabled); +- invocation.ret(); +-} +- +-void PowerManager::LockScreenWhenHibernate(bool enabled, MethodInvocation& invocation) +-{ +- this->ScreenLockedWhenHibernate_set(enabled); +- invocation.ret(); +-} +- + bool PowerManager::DisplayIdleDimmedEnabled_setHandler(bool value) + { + this->power_settings_->set_boolean(POWER_SCHEMA_ENABLE_DISPLAY_IDLE_DIMMED, value); +@@ -359,18 +347,6 @@ bool PowerManager::ChargeLowSaverEnabled_setHandler(bool value) + return true; + } + +-bool PowerManager::ScreenLockedWhenSuspend_setHandler(bool value) +-{ +- this->power_settings_->set_boolean(POWER_SCHEMA_SCREEN_LOCKED_WHEN_SUSPEND, value); +- return true; +-} +- +-bool PowerManager::ScreenLockedWhenHibernate_setHandler(bool value) +-{ +- this->power_settings_->set_boolean(POWER_SCHEMA_SCREEN_LOCKED_WHEN_HIBERNATE, value); +- return true; +-} +- + bool PowerManager::OnBattery_get() + { + return this->upower_client_->get_on_battery(); +@@ -396,16 +372,6 @@ bool PowerManager::ChargeLowSaverEnabled_get() + return this->power_settings_->get_boolean(POWER_SCHEMA_ENABLE_CHARGE_LOW_SAVER); + } + +-bool PowerManager::ScreenLockedWhenSuspend_get() +-{ +- return this->power_settings_->get_boolean(POWER_SCHEMA_SCREEN_LOCKED_WHEN_SUSPEND); +-} +- +-bool PowerManager::ScreenLockedWhenHibernate_get() +-{ +- return this->power_settings_->get_boolean(POWER_SCHEMA_SCREEN_LOCKED_WHEN_HIBERNATE); +-} +- + void PowerManager::on_battery_changed(bool on_battery) + { + this->OnBattery_set(on_battery); +diff --git a/plugins/power/power-manager.h b/plugins/power/power-manager.h +index 0f799ee..674de4d 100644 +--- a/plugins/power/power-manager.h ++++ b/plugins/power/power-manager.h +@@ -88,18 +88,12 @@ protected: + virtual void EnableChargeLowDimmed(bool enabled, MethodInvocation &invocation); + // 电量过低时是否进入节能模式 + virtual void EnableChargeLowSaver(bool enabled, MethodInvocation &invocation); +- // 待机时是否锁定屏幕 +- virtual void LockScreenWhenSuspend(bool enabled, MethodInvocation &invocation); +- // 休眠时是否锁定屏幕 +- virtual void LockScreenWhenHibernate(bool enabled, MethodInvocation &invocation); + + virtual bool OnBattery_setHandler(bool value) { return true; } + virtual bool LidIsPresent_setHandler(bool value) { return true; } + virtual bool DisplayIdleDimmedEnabled_setHandler(bool value); + virtual bool ChargeLowDimmedEnabled_setHandler(bool value); + virtual bool ChargeLowSaverEnabled_setHandler(bool value); +- virtual bool ScreenLockedWhenSuspend_setHandler(bool value); +- virtual bool ScreenLockedWhenHibernate_setHandler(bool value); + + // 系统是否在使用电池供电 + virtual bool OnBattery_get(); +@@ -108,8 +102,6 @@ protected: + virtual bool DisplayIdleDimmedEnabled_get(); + virtual bool ChargeLowDimmedEnabled_get(); + virtual bool ChargeLowSaverEnabled_get(); +- virtual bool ScreenLockedWhenSuspend_get(); +- virtual bool ScreenLockedWhenHibernate_get(); + + private: + void init(); +diff --git a/plugins/power/save/power-save-computer.cpp b/plugins/power/save/power-save-computer.cpp +index cc62fbd..fdf7743 100644 +--- a/plugins/power/save/power-save-computer.cpp ++++ b/plugins/power/save/power-save-computer.cpp +@@ -18,9 +18,7 @@ namespace Kiran + { + PowerSaveComputer::PowerSaveComputer() + { +- this->power_settings_ = Gio::Settings::create(POWER_SCHEMA_ID); +- this->login1_ = PowerWrapperManager::get_instance()->get_default_login1(); +- this->screensaver_ = PowerWrapperManager::get_instance()->get_default_screensaver(); ++ this->session_ = PowerWrapperManager::get_instance()->get_default_session(); + } + + void PowerSaveComputer::init() +@@ -29,51 +27,21 @@ void PowerSaveComputer::init() + + void PowerSaveComputer::suspend() + { +- uint32_t throttle = 0; +- +- auto lockscreen = this->power_settings_->get_boolean(POWER_SCHEMA_SCREEN_LOCKED_WHEN_SUSPEND); +- // 挂起之前锁定屏幕 +- if (lockscreen) +- { +- throttle = this->screensaver_->lock_and_throttle("suspend"); +- } +- + this->save_changed_.emit(ComputerSaveState::COMPUTER_SAVE_STATE_SLEEP, PowerAction::POWER_ACTION_COMPUTER_SUSPEND); +- this->login1_->suspend(); ++ this->session_->suspend(); + this->save_changed_.emit(ComputerSaveState::COMPUTER_SAVE_STATE_RESUME, PowerAction::POWER_ACTION_COMPUTER_SUSPEND); +- +- this->screensaver_->poke(); +- if (throttle) +- { +- this->screensaver_->remove_throttle(throttle); +- } + } + + void PowerSaveComputer::hibernate() + { +- uint32_t throttle = 0; +- +- auto lockscreen = this->power_settings_->get_boolean(POWER_SCHEMA_SCREEN_LOCKED_WHEN_HIBERNATE); +- // 休眠之前锁定屏幕 +- if (lockscreen) +- { +- throttle = this->screensaver_->lock_and_throttle("hibernate"); +- } +- + this->save_changed_.emit(ComputerSaveState::COMPUTER_SAVE_STATE_SLEEP, PowerAction::POWER_ACTION_COMPUTER_HIBERNATE); +- this->login1_->hibernate(); ++ this->session_->hibernate(); + this->save_changed_.emit(ComputerSaveState::COMPUTER_SAVE_STATE_RESUME, PowerAction::POWER_ACTION_COMPUTER_HIBERNATE); +- +- this->screensaver_->poke(); +- if (throttle) +- { +- this->screensaver_->remove_throttle(throttle); +- } + } + + void PowerSaveComputer::shutdown() + { +- this->login1_->shutdown(); ++ this->session_->shutdown(); + } + + } // namespace Kiran +diff --git a/plugins/power/save/power-save-computer.h b/plugins/power/save/power-save-computer.h +index eb8f7c3..f516cbf 100644 +--- a/plugins/power/save/power-save-computer.h ++++ b/plugins/power/save/power-save-computer.h +@@ -49,9 +49,7 @@ private: + private: + static PowerSaveComputer* instance_; + +- Glib::RefPtr power_settings_; +- std::shared_ptr login1_; +- std::shared_ptr screensaver_; ++ std::shared_ptr session_; + + sigc::signal save_changed_; + }; +diff --git a/plugins/power/wrapper/power-session.cpp b/plugins/power/wrapper/power-session.cpp +index 1a613c1..d87e38b 100644 +--- a/plugins/power/wrapper/power-session.cpp ++++ b/plugins/power/wrapper/power-session.cpp +@@ -73,6 +73,117 @@ void PowerSession::init() + this->sm_presence_proxy_->signal_signal().connect(sigc::mem_fun(this, &PowerSession::on_sm_presence_signal)); + } + ++bool PowerSession::can_suspend() ++{ ++ try ++ { ++ auto retval = this->sm_proxy_->call_sync("CanSuspend", Glib::VariantContainerBase()); ++ auto v1 = retval.get_child(0); ++ return Glib::VariantBase::cast_dynamic>(v1).get(); ++ } ++ catch (const Glib::Error& e) ++ { ++ KLOG_WARNING("Failed to call CanSuspend: %s", e.what().c_str()); ++ } ++ catch (const std::exception& e) ++ { ++ KLOG_WARNING("Failed to get the retval of function CanSuspend: %s", e.what()); ++ } ++ return false; ++} ++ ++void PowerSession::suspend() ++{ ++ if (!this->can_suspend()) ++ { ++ KLOG_WARNING("The session manager doesn't allow suspend."); ++ return; ++ } ++ ++ try ++ { ++ this->sm_proxy_->call_sync("Suspend", Glib::VariantContainerBase()); ++ } ++ catch (const Glib::Error& e) ++ { ++ KLOG_WARNING("Failed to call Suspend: %s", e.what().c_str()); ++ } ++} ++ ++bool PowerSession::can_hibernate() ++{ ++ try ++ { ++ auto retval = this->sm_proxy_->call_sync("CanHibernate", Glib::VariantContainerBase()); ++ auto v1 = retval.get_child(0); ++ return Glib::VariantBase::cast_dynamic>(v1).get(); ++ } ++ catch (const Glib::Error& e) ++ { ++ KLOG_WARNING("Failed to call CanHibernate: %s", e.what().c_str()); ++ } ++ catch (const std::exception& e) ++ { ++ KLOG_WARNING("Failed to get the retval of function CanHibernate: %s", e.what()); ++ } ++ return false; ++} ++ ++void PowerSession::hibernate() ++{ ++ if (!this->can_hibernate()) ++ { ++ KLOG_WARNING("The session manager doesn't allow hibernate."); ++ return; ++ } ++ ++ try ++ { ++ this->sm_proxy_->call_sync("Hibernate", Glib::VariantContainerBase()); ++ } ++ catch (const Glib::Error& e) ++ { ++ KLOG_WARNING("Failed to call Hibernate: %s", e.what().c_str()); ++ } ++} ++ ++bool PowerSession::can_shutdown() ++{ ++ try ++ { ++ auto retval = this->sm_proxy_->call_sync("CanShutdown", Glib::VariantContainerBase()); ++ auto v1 = retval.get_child(0); ++ return Glib::VariantBase::cast_dynamic>(v1).get(); ++ } ++ catch (const Glib::Error& e) ++ { ++ KLOG_WARNING("Failed to call CanShutdown: %s", e.what().c_str()); ++ } ++ catch (const std::exception& e) ++ { ++ KLOG_WARNING("Failed to get the retval of function CanShutdown: %s", e.what()); ++ } ++ return false; ++} ++ ++void PowerSession::shutdown() ++{ ++ if (!this->can_shutdown()) ++ { ++ KLOG_WARNING("The session manager doesn't allow shutdown."); ++ return; ++ } ++ ++ try ++ { ++ this->sm_proxy_->call_sync("Shutdown", Glib::VariantContainerBase()); ++ } ++ catch (const Glib::Error& e) ++ { ++ KLOG_WARNING("Failed to call shutdown: %s", e.what().c_str()); ++ } ++} ++ + uint32_t PowerSession::get_status() + { + KLOG_PROFILE(""); +diff --git a/plugins/power/wrapper/power-session.h b/plugins/power/wrapper/power-session.h +index a2e26c9..6b0e770 100644 +--- a/plugins/power/wrapper/power-session.h ++++ b/plugins/power/wrapper/power-session.h +@@ -39,6 +39,16 @@ public: + // 挂起状态是否禁用 + bool get_suspend_inhibited() { return this->is_suspend_inhibited_; }; + ++ // 挂机 ++ bool can_suspend(); ++ void suspend(); ++ // 休眠 ++ bool can_hibernate(); ++ void hibernate(); ++ // 关机 ++ bool can_shutdown(); ++ void shutdown(); ++ + private: + // 获取空闲状态 + uint32_t get_status(); +-- +2.36.1 + diff --git a/kiran-cc-daemon.spec b/kiran-cc-daemon.spec index a431a63..b783b5b 100644 --- a/kiran-cc-daemon.spec +++ b/kiran-cc-daemon.spec @@ -1,6 +1,6 @@ Name: kiran-cc-daemon Version: 2.5.1 -Release: 7 +Release: 8 Summary: DBus daemon for Kiran Desktop License: MulanPSL-2.0 @@ -10,6 +10,7 @@ Patch0001: 0001-fix-keyboard-Add-modifier-lock-window-tips-enable-ke.patch Patch0002: 0001-fix-audio-Fix-coredump-problem-caused-by-nullpointer.patch Patch0003: 0001-fix-audio-Fix-the-type-of-return-value-in-template.patch Patch0004: 0001-feature-timedate-Prior-to-select-last-ntp-service-in.patch +Patch0005: 0001-feature-power-Delete-LockScreenWhenHibernate-and-Loc.patch BuildRequires: cmake >= 3.2 @@ -174,6 +175,9 @@ glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/nulls || : %{_libdir}/pkgconfig/kiran-cc-daemon.pc %changelog +* Wed May 10 2023 tangjie02 - 2.5.1-8 +- KYOS-F: Delete LockScreenWhenHibernate and LockScreenWhenSuspend functions and replace suspend/hibernate/shutdown api with SessionManager. + * Thu Apr 27 2023 tangjie02 - 2.5.1-7 - KYOS-F: Prior to select last ntp service in ntp-utils.d directory. -- Gitee