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