ISelfController.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using Ryujinx.HLE.HOS.Kernel.Common;
  4. using Ryujinx.HLE.HOS.Kernel.Threading;
  5. using System;
  6. namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.SystemAppletProxy
  7. {
  8. class ISelfController : IpcService
  9. {
  10. private KEvent _libraryAppletLaunchableEvent;
  11. private KEvent _accumulatedSuspendedTickChangedEvent;
  12. private int _accumulatedSuspendedTickChangedEventHandle = 0;
  13. private object _fatalSectionLock = new object();
  14. private int _fatalSectionCount;
  15. // TODO: Set this when the game goes in suspension (go back to home menu ect), we currently don't support that so we can keep it set to 0.
  16. private ulong _accumulatedSuspendedTickValue = 0;
  17. // TODO: Determine where those fields are used.
  18. private bool _screenShotPermission = false;
  19. private bool _operationModeChangedNotification = false;
  20. private bool _performanceModeChangedNotification = false;
  21. private bool _restartMessageEnabled = false;
  22. private bool _outOfFocusSuspendingEnabled = false;
  23. private bool _handlesRequestToDisplay = false;
  24. private bool _autoSleepDisabled = false;
  25. private bool _albumImageTakenNotificationEnabled = false;
  26. private uint _screenShotImageOrientation = 0;
  27. private uint _idleTimeDetectionExtension = 0;
  28. public ISelfController(Horizon system)
  29. {
  30. _libraryAppletLaunchableEvent = new KEvent(system.KernelContext);
  31. }
  32. [Command(0)]
  33. // Exit()
  34. public ResultCode Exit(ServiceCtx context)
  35. {
  36. Logger.Stub?.PrintStub(LogClass.ServiceAm);
  37. return ResultCode.Success;
  38. }
  39. [Command(1)]
  40. // LockExit()
  41. public ResultCode LockExit(ServiceCtx context)
  42. {
  43. Logger.Stub?.PrintStub(LogClass.ServiceAm);
  44. return ResultCode.Success;
  45. }
  46. [Command(2)]
  47. // UnlockExit()
  48. public ResultCode UnlockExit(ServiceCtx context)
  49. {
  50. Logger.Stub?.PrintStub(LogClass.ServiceAm);
  51. return ResultCode.Success;
  52. }
  53. [Command(3)] // 2.0.0+
  54. // EnterFatalSection()
  55. public ResultCode EnterFatalSection(ServiceCtx context)
  56. {
  57. lock (_fatalSectionLock)
  58. {
  59. _fatalSectionCount++;
  60. }
  61. return ResultCode.Success;
  62. }
  63. [Command(4)] // 2.0.0+
  64. // LeaveFatalSection()
  65. public ResultCode LeaveFatalSection(ServiceCtx context)
  66. {
  67. ResultCode result = ResultCode.Success;
  68. lock (_fatalSectionLock)
  69. {
  70. if (_fatalSectionCount != 0)
  71. {
  72. _fatalSectionCount--;
  73. }
  74. else
  75. {
  76. result = ResultCode.UnbalancedFatalSection;
  77. }
  78. }
  79. return result;
  80. }
  81. [Command(9)]
  82. // GetLibraryAppletLaunchableEvent() -> handle<copy>
  83. public ResultCode GetLibraryAppletLaunchableEvent(ServiceCtx context)
  84. {
  85. _libraryAppletLaunchableEvent.ReadableEvent.Signal();
  86. if (context.Process.HandleTable.GenerateHandle(_libraryAppletLaunchableEvent.ReadableEvent, out int handle) != KernelResult.Success)
  87. {
  88. throw new InvalidOperationException("Out of handles!");
  89. }
  90. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
  91. Logger.Stub?.PrintStub(LogClass.ServiceAm);
  92. return ResultCode.Success;
  93. }
  94. [Command(10)]
  95. // SetScreenShotPermission(u32)
  96. public ResultCode SetScreenShotPermission(ServiceCtx context)
  97. {
  98. bool screenShotPermission = context.RequestData.ReadBoolean();
  99. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { screenShotPermission });
  100. _screenShotPermission = screenShotPermission;
  101. return ResultCode.Success;
  102. }
  103. [Command(11)]
  104. // SetOperationModeChangedNotification(b8)
  105. public ResultCode SetOperationModeChangedNotification(ServiceCtx context)
  106. {
  107. bool operationModeChangedNotification = context.RequestData.ReadBoolean();
  108. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { operationModeChangedNotification });
  109. _operationModeChangedNotification = operationModeChangedNotification;
  110. return ResultCode.Success;
  111. }
  112. [Command(12)]
  113. // SetPerformanceModeChangedNotification(b8)
  114. public ResultCode SetPerformanceModeChangedNotification(ServiceCtx context)
  115. {
  116. bool performanceModeChangedNotification = context.RequestData.ReadBoolean();
  117. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { performanceModeChangedNotification });
  118. _performanceModeChangedNotification = performanceModeChangedNotification;
  119. return ResultCode.Success;
  120. }
  121. [Command(13)]
  122. // SetFocusHandlingMode(b8, b8, b8)
  123. public ResultCode SetFocusHandlingMode(ServiceCtx context)
  124. {
  125. bool unknownFlag1 = context.RequestData.ReadBoolean();
  126. bool unknownFlag2 = context.RequestData.ReadBoolean();
  127. bool unknownFlag3 = context.RequestData.ReadBoolean();
  128. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { unknownFlag1, unknownFlag2, unknownFlag3 });
  129. return ResultCode.Success;
  130. }
  131. [Command(14)]
  132. // SetRestartMessageEnabled(b8)
  133. public ResultCode SetRestartMessageEnabled(ServiceCtx context)
  134. {
  135. bool restartMessageEnabled = context.RequestData.ReadBoolean();
  136. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { restartMessageEnabled });
  137. _restartMessageEnabled = restartMessageEnabled;
  138. return ResultCode.Success;
  139. }
  140. [Command(16)] // 2.0.0+
  141. // SetOutOfFocusSuspendingEnabled(b8)
  142. public ResultCode SetOutOfFocusSuspendingEnabled(ServiceCtx context)
  143. {
  144. bool outOfFocusSuspendingEnabled = context.RequestData.ReadBoolean();
  145. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { outOfFocusSuspendingEnabled });
  146. _outOfFocusSuspendingEnabled = outOfFocusSuspendingEnabled;
  147. return ResultCode.Success;
  148. }
  149. [Command(19)] // 3.0.0+
  150. // SetScreenShotImageOrientation(u32)
  151. public ResultCode SetScreenShotImageOrientation(ServiceCtx context)
  152. {
  153. uint screenShotImageOrientation = context.RequestData.ReadUInt32();
  154. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { screenShotImageOrientation });
  155. _screenShotImageOrientation = screenShotImageOrientation;
  156. return ResultCode.Success;
  157. }
  158. [Command(50)]
  159. // SetHandlesRequestToDisplay(b8)
  160. public ResultCode SetHandlesRequestToDisplay(ServiceCtx context)
  161. {
  162. bool handlesRequestToDisplay = context.RequestData.ReadBoolean();
  163. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { handlesRequestToDisplay });
  164. _handlesRequestToDisplay = handlesRequestToDisplay;
  165. return ResultCode.Success;
  166. }
  167. [Command(62)]
  168. // SetIdleTimeDetectionExtension(u32)
  169. public ResultCode SetIdleTimeDetectionExtension(ServiceCtx context)
  170. {
  171. uint idleTimeDetectionExtension = context.RequestData.ReadUInt32();
  172. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { idleTimeDetectionExtension });
  173. _idleTimeDetectionExtension = idleTimeDetectionExtension;
  174. return ResultCode.Success;
  175. }
  176. [Command(63)]
  177. // GetIdleTimeDetectionExtension() -> u32
  178. public ResultCode GetIdleTimeDetectionExtension(ServiceCtx context)
  179. {
  180. context.ResponseData.Write(_idleTimeDetectionExtension);
  181. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { _idleTimeDetectionExtension });
  182. return ResultCode.Success;
  183. }
  184. [Command(68)]
  185. // SetAutoSleepDisabled(u8)
  186. public ResultCode SetAutoSleepDisabled(ServiceCtx context)
  187. {
  188. bool autoSleepDisabled = context.RequestData.ReadBoolean();
  189. _autoSleepDisabled = autoSleepDisabled;
  190. return ResultCode.Success;
  191. }
  192. [Command(69)]
  193. // IsAutoSleepDisabled() -> u8
  194. public ResultCode IsAutoSleepDisabled(ServiceCtx context)
  195. {
  196. context.ResponseData.Write(_autoSleepDisabled);
  197. return ResultCode.Success;
  198. }
  199. [Command(90)] // 6.0.0+
  200. // GetAccumulatedSuspendedTickValue() -> u64
  201. public ResultCode GetAccumulatedSuspendedTickValue(ServiceCtx context)
  202. {
  203. context.ResponseData.Write(_accumulatedSuspendedTickValue);
  204. return ResultCode.Success;
  205. }
  206. [Command(91)] // 6.0.0+
  207. // GetAccumulatedSuspendedTickChangedEvent() -> handle<copy>
  208. public ResultCode GetAccumulatedSuspendedTickChangedEvent(ServiceCtx context)
  209. {
  210. if (_accumulatedSuspendedTickChangedEventHandle == 0)
  211. {
  212. _accumulatedSuspendedTickChangedEvent = new KEvent(context.Device.System.KernelContext);
  213. _accumulatedSuspendedTickChangedEvent.ReadableEvent.Signal();
  214. if (context.Process.HandleTable.GenerateHandle(_accumulatedSuspendedTickChangedEvent.ReadableEvent, out _accumulatedSuspendedTickChangedEventHandle) != KernelResult.Success)
  215. {
  216. throw new InvalidOperationException("Out of handles!");
  217. }
  218. }
  219. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_accumulatedSuspendedTickChangedEventHandle);
  220. return ResultCode.Success;
  221. }
  222. [Command(100)] // 7.0.0+
  223. // SetAlbumImageTakenNotificationEnabled(u8)
  224. public ResultCode SetAlbumImageTakenNotificationEnabled(ServiceCtx context)
  225. {
  226. bool albumImageTakenNotificationEnabled = context.RequestData.ReadBoolean();
  227. _albumImageTakenNotificationEnabled = albumImageTakenNotificationEnabled;
  228. return ResultCode.Success;
  229. }
  230. }
  231. }