2018-10-17 17:15:50 +00:00
|
|
|
using Ryujinx.Common.Logging;
|
2020-05-15 01:14:38 +00:00
|
|
|
using Ryujinx.HLE.HOS.Services.Arp;
|
|
|
|
using System;
|
2018-02-10 00:14:55 +00:00
|
|
|
|
2019-09-19 00:45:11 +00: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 01:14:38 +00:00
|
|
|
private int _permissionFlag;
|
|
|
|
private ulong _titleId;
|
|
|
|
private bool _freeCommunicationEnabled;
|
|
|
|
private int[] _ratingAge;
|
2018-06-12 18:28:45 +00:00
|
|
|
|
2020-05-15 01:14:38 +00:00
|
|
|
public IParentalControlService(ServiceCtx context, bool withInitialize, int permissionFlag)
|
2018-02-10 00:14:55 +00:00
|
|
|
{
|
2020-05-15 01:14:38 +00:00
|
|
|
_permissionFlag = permissionFlag;
|
|
|
|
|
|
|
|
if (withInitialize)
|
|
|
|
{
|
|
|
|
Initialize(context);
|
|
|
|
}
|
2018-02-10 00:14:55 +00:00
|
|
|
}
|
2018-06-12 18:28:45 +00:00
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(1)] // 4.0.0+
|
|
|
|
// Initialize()
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode Initialize(ServiceCtx context)
|
2018-06-12 18:28:45 +00:00
|
|
|
{
|
2020-05-15 01:14:38 +00:00
|
|
|
if ((_permissionFlag & 0x8001) == 0)
|
2018-06-13 00:51:59 +00:00
|
|
|
{
|
2020-05-15 01:14:38 +00:00
|
|
|
return ResultCode.PermissionDenied;
|
2018-06-13 00:51:59 +00:00
|
|
|
}
|
2020-05-15 01:14:38 +00:00
|
|
|
|
|
|
|
ResultCode resultCode = ResultCode.InvalidPid;
|
|
|
|
|
|
|
|
if (context.Process.Pid != 0)
|
2018-06-13 00:51:59 +00:00
|
|
|
{
|
2020-05-15 01:14:38 +00: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 06:16:46 +00: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 01:14:38 +00: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-03 23:32:53 +00:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServicePctl);
|
2020-05-15 01:14:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resultCode = ResultCode.Success;
|
2018-06-13 00:51:59 +00:00
|
|
|
}
|
2018-06-12 18:28:45 +00:00
|
|
|
|
2020-05-15 01:14:38 +00:00
|
|
|
return resultCode;
|
2018-06-12 18:28:45 +00:00
|
|
|
}
|
2019-04-22 06:54:47 +00:00
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(1001)]
|
|
|
|
// CheckFreeCommunicationPermission()
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode CheckFreeCommunicationPermission(ServiceCtx context)
|
2019-04-22 06:54:47 +00:00
|
|
|
{
|
2020-08-03 23:32:53 +00:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServicePctl);
|
2019-04-22 06:54:47 +00:00
|
|
|
|
2020-05-15 01:14:38 +00:00
|
|
|
if (!_freeCommunicationEnabled)
|
|
|
|
{
|
|
|
|
return ResultCode.FreeCommunicationDisabled;
|
|
|
|
}
|
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.Success;
|
2019-04-22 06:54:47 +00:00
|
|
|
}
|
2018-02-10 00:14:55 +00:00
|
|
|
}
|
|
|
|
}
|