From f5b24bd2443bba10a75c3afef0aba6f9b41bd3c4 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Thu, 8 Aug 2019 11:32:27 -0400 Subject: [PATCH] Added appletStartSleepSequence, appletStartShutdownSequence, appletStartRebootSequence, appletIsAutoPowerDownRequested, appletLoadAndApplyIdlePolicySettings, appletNotifyCecSettingsChanged, appletSetDefaultHomeButtonLongPressTime, appletUpdateDefaultDisplayResolution, appletShouldSleepOnBoot, and appletGetHdcpAuthenticationFailedEvent. --- nx/include/switch/services/applet.h | 68 ++++++++++++++++++++++++ nx/source/services/applet.c | 82 +++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index 62a0a63c..419edf7c 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -1262,6 +1262,74 @@ Result appletGetPopFromGeneralChannelEvent(Event *out_event); */ Result appletGetHomeButtonWriterLockAccessor(AppletLockAccessor *a); +// IGlobalStateController + +/** + * @brief Start the sequence for entering sleep-mode. + * @note Only available with AppletType_SystemApplet. + * @param[in] flag Flag, official sw uses hard-coded value = true. + */ +Result appletStartSleepSequence(bool flag); + +/** + * @brief Start the system-shutdown sequence. + * @note Only available with AppletType_SystemApplet. + */ +Result appletStartShutdownSequence(void); + +/** + * @brief Start the system-reboot sequence. + * @note Only available with AppletType_SystemApplet. + */ +Result appletStartRebootSequence(void); + +/** + * @brief IsAutoPowerDownRequested. Uses an idle:sys cmd internally. + * @note Only available with AppletType_SystemApplet on [7.0.0+]. + * @param[out] out Output flag. + */ +Result appletIsAutoPowerDownRequested(bool *out); + +/** + * @brief LoadAndApplyIdlePolicySettings. Uses an idle:sys cmd internally. + * @note Only available with AppletType_SystemApplet. + */ +Result appletLoadAndApplyIdlePolicySettings(void); + +/** + * @brief NotifyCecSettingsChanged. Uses an omm cmd internally. + * @note Only available with AppletType_SystemApplet on [2.0.0+]. + */ +Result appletNotifyCecSettingsChanged(void); + +/** + * @brief Sets the DefaultHomeButtonLongPressTime. + * @note Only available with AppletType_SystemApplet on [3.0.0+]. + * @param[in] val Input value. + */ +Result appletSetDefaultHomeButtonLongPressTime(s64 val); + +/** + * @brief UpdateDefaultDisplayResolution. Uses an omm cmd internally. + * @note Only available with AppletType_SystemApplet on [3.0.0+]. + */ +Result appletUpdateDefaultDisplayResolution(void); + +/** + * @brief ShouldSleepOnBoot. Uses an omm cmd internally. + * @note Only available with AppletType_SystemApplet on [3.0.0+]. + * @param[out] out Output flag. + */ +Result appletShouldSleepOnBoot(bool *out); + +/** + * @brief Gets an Event which is signaled for HdcpAuthenticationFailed. + * @note Only available with AppletType_SystemApplet on [4.0.0+]. + * @note The Event must be closed by the user once finished with it. + * @param[out] out_event Output Event with autoclear=false. + */ +Result appletGetHdcpAuthenticationFailedEvent(Event *out_event); + // ILibraryAppletSelfAccessor /** diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index acae6fe3..ba7e93c7 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -3974,6 +3974,88 @@ Result appletGetHomeButtonWriterLockAccessor(AppletLockAccessor *a) { return _appletGetHomeButtonRwLockAccessor(&g_appletIFunctions, a, 30); } +// IGlobalStateController + +Result appletStartSleepSequence(bool flag) { + if (__nx_applet_type != AppletType_SystemApplet) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return _appletCmdInBool(&g_appletIGlobalStateController, flag, 2); +} + +Result appletStartShutdownSequence(void) { + if (__nx_applet_type != AppletType_SystemApplet) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return _appletCmdNoIO(&g_appletIGlobalStateController, 3); +} + +Result appletStartRebootSequence(void) { + if (__nx_applet_type != AppletType_SystemApplet) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return _appletCmdNoIO(&g_appletIGlobalStateController, 4); +} + +Result appletIsAutoPowerDownRequested(bool *out) { + if (__nx_applet_type != AppletType_SystemApplet) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + if (hosversionBefore(7,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletCmdNoInOutBool(&g_appletIGlobalStateController, out, 9); +} + +Result appletLoadAndApplyIdlePolicySettings(void) { + if (__nx_applet_type != AppletType_SystemApplet) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return _appletCmdNoIO(&g_appletIGlobalStateController, 10); +} + +Result appletNotifyCecSettingsChanged(void) { + if (__nx_applet_type != AppletType_SystemApplet) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + if (hosversionBefore(2,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletCmdNoIO(&g_appletIGlobalStateController, 11); +} + +Result appletSetDefaultHomeButtonLongPressTime(s64 val) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletCmdInU64(&g_appletIGlobalStateController, val, 12); +} + +Result appletUpdateDefaultDisplayResolution(void) { + if (__nx_applet_type != AppletType_SystemApplet) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletCmdNoIO(&g_appletIGlobalStateController, 13); +} + +Result appletShouldSleepOnBoot(bool *out) { + if (__nx_applet_type != AppletType_SystemApplet) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletCmdNoInOutBool(&g_appletIGlobalStateController, out, 14); +} + +Result appletGetHdcpAuthenticationFailedEvent(Event *out_event) { + if (__nx_applet_type != AppletType_SystemApplet) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletGetEvent(&g_appletIGlobalStateController, out_event, 15, false); +} + // ILibraryAppletSelfAccessor static Result _appletExitProcessAndReturn(void) {