IParentalControlService.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.HLE.HOS.Services.Arp;
  3. using System;
  4. namespace Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory
  5. {
  6. class IParentalControlService : IpcService
  7. {
  8. private int _permissionFlag;
  9. private ulong _titleId;
  10. private bool _freeCommunicationEnabled;
  11. private int[] _ratingAge;
  12. private bool _featuresRestriction = false;
  13. private bool _stereoVisionRestrictionConfigurable = true;
  14. private bool _stereoVisionRestriction = false;
  15. public IParentalControlService(ServiceCtx context, bool withInitialize, int permissionFlag)
  16. {
  17. _permissionFlag = permissionFlag;
  18. if (withInitialize)
  19. {
  20. Initialize(context);
  21. }
  22. }
  23. [Command(1)] // 4.0.0+
  24. // Initialize()
  25. public ResultCode Initialize(ServiceCtx context)
  26. {
  27. if ((_permissionFlag & 0x8001) == 0)
  28. {
  29. return ResultCode.PermissionDenied;
  30. }
  31. ResultCode resultCode = ResultCode.InvalidPid;
  32. if (context.Process.Pid != 0)
  33. {
  34. if ((_permissionFlag & 0x40) == 0)
  35. {
  36. ulong titleId = ApplicationLaunchProperty.GetByPid(context).TitleId;
  37. if (titleId != 0)
  38. {
  39. _titleId = titleId;
  40. // TODO: Call nn::arp::GetApplicationControlProperty here when implemented, if it return ResultCode.Success we assign fields.
  41. _ratingAge = Array.ConvertAll(context.Device.Application.ControlData.Value.RatingAge.ToArray(), Convert.ToInt32);
  42. _freeCommunicationEnabled = context.Device.Application.ControlData.Value.ParentalControl == LibHac.Ns.ParentalControlFlagValue.FreeCommunication;
  43. }
  44. }
  45. if (_titleId != 0)
  46. {
  47. // TODO: Service store some private fields in another static object.
  48. if ((_permissionFlag & 0x8040) == 0)
  49. {
  50. // TODO: Service store TitleId and FreeCommunicationEnabled in another static object.
  51. // When it's done it signal an event in this static object.
  52. Logger.Stub?.PrintStub(LogClass.ServicePctl);
  53. }
  54. }
  55. resultCode = ResultCode.Success;
  56. }
  57. return resultCode;
  58. }
  59. [Command(1001)]
  60. // CheckFreeCommunicationPermission()
  61. public ResultCode CheckFreeCommunicationPermission(ServiceCtx context)
  62. {
  63. Logger.Stub?.PrintStub(LogClass.ServicePctl);
  64. if (!_freeCommunicationEnabled)
  65. {
  66. return ResultCode.FreeCommunicationDisabled;
  67. }
  68. return ResultCode.Success;
  69. }
  70. [Command(1013)] // 4.0.0+
  71. // ConfirmStereoVisionPermission()
  72. public ResultCode ConfirmStereoVisionPermission(ServiceCtx context)
  73. {
  74. return IsStereoVisionPermittedImpl();
  75. }
  76. [Command(1061)] // 4.0.0+
  77. // ConfirmStereoVisionRestrictionConfigurable()
  78. public ResultCode ConfirmStereoVisionRestrictionConfigurable(ServiceCtx context)
  79. {
  80. if ((_permissionFlag & 2) == 0)
  81. {
  82. return ResultCode.PermissionDenied;
  83. }
  84. if (_stereoVisionRestrictionConfigurable)
  85. {
  86. return ResultCode.Success;
  87. }
  88. else
  89. {
  90. return ResultCode.StereoVisionRestrictionConfigurableDisabled;
  91. }
  92. }
  93. [Command(1062)] // 4.0.0+
  94. // GetStereoVisionRestriction() -> bool
  95. public ResultCode GetStereoVisionRestriction(ServiceCtx context)
  96. {
  97. if ((_permissionFlag & 0x200) == 0)
  98. {
  99. return ResultCode.PermissionDenied;
  100. }
  101. bool stereoVisionRestriction = false;
  102. if (_stereoVisionRestrictionConfigurable)
  103. {
  104. stereoVisionRestriction = _stereoVisionRestriction;
  105. }
  106. context.ResponseData.Write(stereoVisionRestriction);
  107. return ResultCode.Success;
  108. }
  109. [Command(1063)] // 4.0.0+
  110. // SetStereoVisionRestriction(bool)
  111. public ResultCode SetStereoVisionRestriction(ServiceCtx context)
  112. {
  113. if ((_permissionFlag & 0x200) == 0)
  114. {
  115. return ResultCode.PermissionDenied;
  116. }
  117. bool stereoVisionRestriction = context.RequestData.ReadBoolean();
  118. if (!_featuresRestriction)
  119. {
  120. if (_stereoVisionRestrictionConfigurable)
  121. {
  122. _stereoVisionRestriction = stereoVisionRestriction;
  123. // TODO: It signals an internal event of service. We have to determine where this event is used.
  124. }
  125. }
  126. return ResultCode.Success;
  127. }
  128. [Command(1064)] // 5.0.0+
  129. // ResetConfirmedStereoVisionPermission()
  130. public ResultCode ResetConfirmedStereoVisionPermission(ServiceCtx context)
  131. {
  132. return ResultCode.Success;
  133. }
  134. [Command(1065)] // 5.0.0+
  135. // IsStereoVisionPermitted() -> bool
  136. public ResultCode IsStereoVisionPermitted(ServiceCtx context)
  137. {
  138. bool isStereoVisionPermitted = false;
  139. ResultCode resultCode = IsStereoVisionPermittedImpl();
  140. if (resultCode == ResultCode.Success)
  141. {
  142. isStereoVisionPermitted = true;
  143. }
  144. context.ResponseData.Write(isStereoVisionPermitted);
  145. return resultCode;
  146. }
  147. private ResultCode IsStereoVisionPermittedImpl()
  148. {
  149. /*
  150. // TODO: Application Exemptions are readed from file "appExemptions.dat" in the service savedata.
  151. // Since we don't support the pctl savedata for now, this can be implemented later.
  152. if (appExemption)
  153. {
  154. return ResultCode.Success;
  155. }
  156. */
  157. if (_stereoVisionRestrictionConfigurable && _stereoVisionRestriction)
  158. {
  159. return ResultCode.StereoVisionDenied;
  160. }
  161. else
  162. {
  163. return ResultCode.Success;
  164. }
  165. }
  166. }
  167. }