service: pctl: Implement functions used by Qlaunch

This commit is contained in:
german77 2023-08-05 02:43:43 -06:00 committed by fincs
parent af5072c096
commit e2424fd8bf
2 changed files with 93 additions and 3 deletions

View File

@ -7,8 +7,15 @@
#pragma once
#include "../types.h"
#include "../kernel/event.h"
#include "../sf/service.h"
typedef struct {
u8 rating_age;
bool sns_post_restriction;
bool free_communication_restriction;
} PctlRestrictionSettings;
/// Initialize pctl.
Result pctlInitialize(void);
@ -21,15 +28,41 @@ Service* pctlGetServiceSession(void);
/// Gets the Service object for IParentalControlService.
Service* pctlGetServiceSession_Service(void);
/// Gets whether Parental Controls restrictions are temporarily unlocked.
Result pctlIsRestrictionTemporaryUnlocked(bool *flag);
/// Confirm whether VrMode is allowed. Only available with [4.0.0+].
Result pctlConfirmStereoVisionPermission(void);
/// Gets whether Parental Controls are enabled.
Result pctlIsRestrictionEnabled(bool *flag);
/// Gets whether Parental Controls are enabled.
Result pctlGetSafetyLevel(u32 *safety_level);
/// Returns the current restrictions settings.
Result pctlGetCurrentSettings(PctlRestrictionSettings *settings);
/// Gets the count of applications that have free communication.
Result pctlGetFreeCommunicationApplicationListCount(u32 *count);
/// Reset the confirmation done by \ref pctlConfirmStereoVisionPermission. Only available with [5.0.0+].
Result pctlResetConfirmedStereoVisionPermission(void);
/// Gets whether VrMode is allowed. Only available with [5.0.0+].
Result pctlIsStereoVisionPermitted(bool *flag);
/// Confirm whether pairing is active.
Result pctlIsPairingActive(bool *flag);
/// Returns the synchronization event.
Result pctlGetSynchronizationEvent(Event* out_event);
/// Returns the supension event.
Result pctlGetPlayTimerEventToRequestSuspension(Event* out_event);
/// Confirm whether play timer alarm is disabled. Only available with [4.0.0+].
Result pctlIsPlayTimerAlarmDisabled(bool *flag);
/// Returns the unlinked event.
Result pctlGetUnlinkedEvent(Event* out_event);

View File

@ -61,6 +61,11 @@ static Result _pctlCmdNoInOutU8(u8 *out, u32 cmd_id) {
return serviceDispatchOut(&g_pctlSession, cmd_id, *out);
}
static Result _pctlCmdNoInOutU32(u32 *out, u32 cmd_id) {
serviceAssumeDomain(&g_pctlSession);
return serviceDispatchOut(&g_pctlSession, cmd_id, *out);
}
static Result _pctlCmdNoInOutBool(bool *out, u32 cmd_id) {
u8 tmp = 0;
Result rc = _pctlCmdNoInOutU8(&tmp, cmd_id);
@ -68,6 +73,23 @@ static Result _pctlCmdNoInOutBool(bool *out, u32 cmd_id) {
return rc;
}
static Result _pctlCmdGetEvent(Event* out_event, u32 cmd_id) {
Result rc;
Handle tmp_handle = INVALID_HANDLE;
serviceAssumeDomain(&g_pctlSession);
rc = serviceDispatch(&g_pctlSession, cmd_id,
.out_handle_attrs = { SfOutHandleAttr_HipcCopy },
.out_handles = &tmp_handle,
);
if (R_SUCCEEDED(rc)) eventLoadRemote(out_event, tmp_handle, true);
return rc;
}
Result pctlIsRestrictionTemporaryUnlocked(bool *flag) {
return _pctlCmdNoInOutBool(flag, 1006);
}
Result pctlConfirmStereoVisionPermission(void) {
if (hosversionBefore(4,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
@ -79,6 +101,19 @@ Result pctlIsRestrictionEnabled(bool *flag) {
return _pctlCmdNoInOutBool(flag, 1031);
}
Result pctlGetSafetyLevel(u32 *safety_level) {
return _pctlCmdNoInOutU32(safety_level, 1032);
}
Result pctlGetCurrentSettings(PctlRestrictionSettings *settings) {
serviceAssumeDomain(&g_pctlSession);
return serviceDispatchOut(&g_pctlSession, 1035, *settings);
}
Result pctlGetFreeCommunicationApplicationListCount(u32 *count) {
return _pctlCmdNoInOutU32(count, 1039);
}
Result pctlResetConfirmedStereoVisionPermission(void) {
if (hosversionBefore(5,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
@ -93,3 +128,25 @@ Result pctlIsStereoVisionPermitted(bool *flag) {
return _pctlCmdNoInOutBool(flag, 1065);
}
Result pctlIsPairingActive(bool *flag) {
return _pctlCmdNoInOutBool(flag, 1403);
}
Result pctlGetSynchronizationEvent(Event* out_event) {
return _pctlCmdGetEvent(out_event, 1432);
}
Result pctlGetPlayTimerEventToRequestSuspension(Event* out_event) {
return _pctlCmdGetEvent(out_event, 1457);
}
Result pctlIsPlayTimerAlarmDisabled(bool *flag) {
if (hosversionBefore(4,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
return _pctlCmdNoInOutBool(flag, 1458);
}
Result pctlGetUnlinkedEvent(Event* out_event) {
return _pctlCmdGetEvent(out_event, 1473);
}