2018-10-17 18:15:50 +01:00
|
|
|
using Ryujinx.Common.Logging;
|
2020-05-15 02:14:38 +01:00
|
|
|
using Ryujinx.HLE.HOS.Services.Arp;
|
|
|
|
using System;
|
2018-02-10 00:14:55 +00:00
|
|
|
|
2019-09-19 01:45:11 +01:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory
|
2018-02-10 00:14:55 +00:00
|
|
|
{
|
2018-03-19 18:58:46 +00:00
|
|
|
class IParentalControlService : IpcService
|
2018-02-10 00:14:55 +00:00
|
|
|
{
|
2020-05-15 02:14:38 +01:00
|
|
|
private int _permissionFlag;
|
|
|
|
private ulong _titleId;
|
|
|
|
private bool _freeCommunicationEnabled;
|
|
|
|
private int[] _ratingAge;
|
2018-06-12 19:28:45 +01:00
|
|
|
|
2020-05-15 02:14:38 +01:00
|
|
|
public IParentalControlService(ServiceCtx context, bool withInitialize, int permissionFlag)
|
2018-02-10 00:14:55 +00:00
|
|
|
{
|
2020-05-15 02:14:38 +01:00
|
|
|
_permissionFlag = permissionFlag;
|
|
|
|
|
|
|
|
if (withInitialize)
|
|
|
|
{
|
|
|
|
Initialize(context);
|
|
|
|
}
|
2018-02-10 00:14:55 +00:00
|
|
|
}
|
2018-06-12 19:28:45 +01:00
|
|
|
|
2019-07-12 02:13:43 +01:00
|
|
|
[Command(1)] // 4.0.0+
|
|
|
|
// Initialize()
|
2019-07-14 20:04:38 +01:00
|
|
|
public ResultCode Initialize(ServiceCtx context)
|
2018-06-12 19:28:45 +01:00
|
|
|
{
|
2020-05-15 02:14:38 +01:00
|
|
|
if ((_permissionFlag & 0x8001) == 0)
|
2018-06-13 01:51:59 +01:00
|
|
|
{
|
2020-05-15 02:14:38 +01:00
|
|
|
return ResultCode.PermissionDenied;
|
2018-06-13 01:51:59 +01:00
|
|
|
}
|
2020-05-15 02:14:38 +01:00
|
|
|
|
|
|
|
ResultCode resultCode = ResultCode.InvalidPid;
|
|
|
|
|
|
|
|
if (context.Process.Pid != 0)
|
2018-06-13 01:51:59 +01:00
|
|
|
{
|
2020-05-15 02:14:38 +01:00
|
|
|
if ((_permissionFlag & 0x40) == 0)
|
|
|
|
{
|
|
|
|
ulong titleId = ApplicationLaunchProperty.GetByPid(context).TitleId;
|
|
|
|
|
|
|
|
if (titleId != 0)
|
|
|
|
{
|
|
|
|
_titleId = titleId;
|
|
|
|
|
|
|
|
// TODO: Call nn::arp::GetApplicationControlProperty here when implemented, if it return ResultCode.Success we assign fields.
|
2020-05-15 07:16:46 +01:00
|
|
|
_ratingAge = Array.ConvertAll(context.Device.Application.ControlData.Value.RatingAge.ToArray(), Convert.ToInt32);
|
|
|
|
_freeCommunicationEnabled = context.Device.Application.ControlData.Value.ParentalControl == LibHac.Ns.ParentalControlFlagValue.FreeCommunication;
|
2020-05-15 02:14:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_titleId != 0)
|
|
|
|
{
|
|
|
|
// TODO: Service store some private fields in another static object.
|
|
|
|
|
|
|
|
if ((_permissionFlag & 0x8040) == 0)
|
|
|
|
{
|
|
|
|
// TODO: Service store TitleId and FreeCommunicationEnabled in another static object.
|
|
|
|
// When it's done it signal an event in this static object.
|
2020-08-04 00:32:53 +01:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServicePctl);
|
2020-05-15 02:14:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resultCode = ResultCode.Success;
|
2018-06-13 01:51:59 +01:00
|
|
|
}
|
2018-06-12 19:28:45 +01:00
|
|
|
|
2020-05-15 02:14:38 +01:00
|
|
|
return resultCode;
|
2018-06-12 19:28:45 +01:00
|
|
|
}
|
2019-04-22 07:54:47 +01:00
|
|
|
|
2019-07-12 02:13:43 +01:00
|
|
|
[Command(1001)]
|
|
|
|
// CheckFreeCommunicationPermission()
|
2019-07-14 20:04:38 +01:00
|
|
|
public ResultCode CheckFreeCommunicationPermission(ServiceCtx context)
|
2019-04-22 07:54:47 +01:00
|
|
|
{
|
2020-08-04 00:32:53 +01:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServicePctl);
|
2019-04-22 07:54:47 +01:00
|
|
|
|
2020-05-15 02:14:38 +01:00
|
|
|
if (!_freeCommunicationEnabled)
|
|
|
|
{
|
|
|
|
return ResultCode.FreeCommunicationDisabled;
|
|
|
|
}
|
|
|
|
|
2019-07-14 20:04:38 +01:00
|
|
|
return ResultCode.Success;
|
2019-04-22 07:54:47 +01:00
|
|
|
}
|
2018-02-10 00:14:55 +00:00
|
|
|
}
|
|
|
|
}
|