ISelfController.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. using System.Collections.Generic;
  7. namespace Ryujinx.HLE.HOS.Services.Am
  8. {
  9. class ISelfController : IpcService
  10. {
  11. private Dictionary<int, ServiceProcessRequest> _commands;
  12. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  13. private KEvent _libraryAppletLaunchableEvent;
  14. private KEvent _accumulatedSuspendedTickChangedEvent;
  15. private int _accumulatedSuspendedTickChangedEventHandle = 0;
  16. private int _idleTimeDetectionExtension;
  17. public ISelfController(Horizon system)
  18. {
  19. _commands = new Dictionary<int, ServiceProcessRequest>
  20. {
  21. { 0, Exit },
  22. { 1, LockExit },
  23. { 2, UnlockExit },
  24. //{ 3, EnterFatalSection }, // 2.0.0+
  25. //{ 4, LeaveFatalSection }, // 2.0.0+
  26. { 9, GetLibraryAppletLaunchableEvent },
  27. { 10, SetScreenShotPermission },
  28. { 11, SetOperationModeChangedNotification },
  29. { 12, SetPerformanceModeChangedNotification },
  30. { 13, SetFocusHandlingMode },
  31. { 14, SetRestartMessageEnabled },
  32. //{ 15, SetScreenShotAppletIdentityInfo }, // 2.0.0+
  33. { 16, SetOutOfFocusSuspendingEnabled }, // 2.0.0+
  34. //{ 17, SetControllerFirmwareUpdateSection }, // 3.0.0+
  35. //{ 18, SetRequiresCaptureButtonShortPressedMessage }, // 3.0.0+
  36. { 19, SetScreenShotImageOrientation }, // 3.0.0+
  37. //{ 20, SetDesirableKeyboardLayout }, // 4.0.0+
  38. //{ 40, CreateManagedDisplayLayer },
  39. //{ 41, IsSystemBufferSharingEnabled }, // 4.0.0+
  40. //{ 42, GetSystemSharedLayerHandle }, // 4.0.0+
  41. //{ 43, GetSystemSharedBufferHandle }, // 5.0.0+
  42. { 50, SetHandlesRequestToDisplay },
  43. //{ 51, ApproveToDisplay },
  44. //{ 60, OverrideAutoSleepTimeAndDimmingTime },
  45. //{ 61, SetMediaPlaybackState },
  46. { 62, SetIdleTimeDetectionExtension },
  47. { 63, GetIdleTimeDetectionExtension },
  48. //{ 64, SetInputDetectionSourceSet },
  49. //{ 65, ReportUserIsActive }, // 2.0.0+
  50. //{ 66, GetCurrentIlluminance }, // 3.0.0+
  51. //{ 67, IsIlluminanceAvailable }, // 3.0.0+
  52. //{ 68, SetAutoSleepDisabled }, // 5.0.0+
  53. //{ 69, IsAutoSleepDisabled }, // 5.0.0+
  54. //{ 70, ReportMultimediaError }, // 4.0.0+
  55. //{ 71, GetCurrentIlluminanceEx }, // 5.0.0+
  56. //{ 80, SetWirelessPriorityMode }, // 4.0.0+
  57. //{ 90, GetAccumulatedSuspendedTickValue }, // 6.0.0+
  58. { 91, GetAccumulatedSuspendedTickChangedEvent }, // 6.0.0+
  59. //{ 100, SetAlbumImageTakenNotificationEnabled }, // 7.0.0+
  60. //{ 110, SetApplicationAlbumUserData }, // 8.0.0+
  61. //{ 1000, GetDebugStorageChannel }, // 7.0.0+
  62. };
  63. _libraryAppletLaunchableEvent = new KEvent(system);
  64. }
  65. public long Exit(ServiceCtx context)
  66. {
  67. Logger.PrintStub(LogClass.ServiceAm);
  68. return 0;
  69. }
  70. public long LockExit(ServiceCtx context)
  71. {
  72. Logger.PrintStub(LogClass.ServiceAm);
  73. return 0;
  74. }
  75. public long UnlockExit(ServiceCtx context)
  76. {
  77. Logger.PrintStub(LogClass.ServiceAm);
  78. return 0;
  79. }
  80. public long GetLibraryAppletLaunchableEvent(ServiceCtx context)
  81. {
  82. _libraryAppletLaunchableEvent.ReadableEvent.Signal();
  83. if (context.Process.HandleTable.GenerateHandle(_libraryAppletLaunchableEvent.ReadableEvent, out int handle) != KernelResult.Success)
  84. {
  85. throw new InvalidOperationException("Out of handles!");
  86. }
  87. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
  88. Logger.PrintStub(LogClass.ServiceAm);
  89. return 0;
  90. }
  91. public long SetScreenShotPermission(ServiceCtx context)
  92. {
  93. bool enable = context.RequestData.ReadByte() != 0;
  94. Logger.PrintStub(LogClass.ServiceAm);
  95. return 0;
  96. }
  97. public long SetOperationModeChangedNotification(ServiceCtx context)
  98. {
  99. bool enable = context.RequestData.ReadByte() != 0;
  100. Logger.PrintStub(LogClass.ServiceAm);
  101. return 0;
  102. }
  103. public long SetPerformanceModeChangedNotification(ServiceCtx context)
  104. {
  105. bool enable = context.RequestData.ReadByte() != 0;
  106. Logger.PrintStub(LogClass.ServiceAm);
  107. return 0;
  108. }
  109. public long SetFocusHandlingMode(ServiceCtx context)
  110. {
  111. bool flag1 = context.RequestData.ReadByte() != 0;
  112. bool flag2 = context.RequestData.ReadByte() != 0;
  113. bool flag3 = context.RequestData.ReadByte() != 0;
  114. Logger.PrintStub(LogClass.ServiceAm);
  115. return 0;
  116. }
  117. public long SetRestartMessageEnabled(ServiceCtx context)
  118. {
  119. bool enable = context.RequestData.ReadByte() != 0;
  120. Logger.PrintStub(LogClass.ServiceAm);
  121. return 0;
  122. }
  123. public long SetOutOfFocusSuspendingEnabled(ServiceCtx context)
  124. {
  125. bool enable = context.RequestData.ReadByte() != 0;
  126. Logger.PrintStub(LogClass.ServiceAm);
  127. return 0;
  128. }
  129. public long SetScreenShotImageOrientation(ServiceCtx context)
  130. {
  131. int orientation = context.RequestData.ReadInt32();
  132. Logger.PrintStub(LogClass.ServiceAm);
  133. return 0;
  134. }
  135. public long SetHandlesRequestToDisplay(ServiceCtx context)
  136. {
  137. bool enable = context.RequestData.ReadByte() != 0;
  138. Logger.PrintStub(LogClass.ServiceAm);
  139. return 0;
  140. }
  141. // SetIdleTimeDetectionExtension(u32)
  142. public long SetIdleTimeDetectionExtension(ServiceCtx context)
  143. {
  144. _idleTimeDetectionExtension = context.RequestData.ReadInt32();
  145. Logger.PrintStub(LogClass.ServiceAm, new { _idleTimeDetectionExtension });
  146. return 0;
  147. }
  148. // GetIdleTimeDetectionExtension() -> u32
  149. public long GetIdleTimeDetectionExtension(ServiceCtx context)
  150. {
  151. context.ResponseData.Write(_idleTimeDetectionExtension);
  152. Logger.PrintStub(LogClass.ServiceAm, new { _idleTimeDetectionExtension });
  153. return 0;
  154. }
  155. // GetAccumulatedSuspendedTickChangedEvent() -> handle<copy>
  156. public long GetAccumulatedSuspendedTickChangedEvent(ServiceCtx context)
  157. {
  158. if (_accumulatedSuspendedTickChangedEventHandle == 0)
  159. {
  160. _accumulatedSuspendedTickChangedEvent = new KEvent(context.Device.System);
  161. _accumulatedSuspendedTickChangedEvent.ReadableEvent.Signal();
  162. if (context.Process.HandleTable.GenerateHandle(_accumulatedSuspendedTickChangedEvent.ReadableEvent, out _accumulatedSuspendedTickChangedEventHandle) != KernelResult.Success)
  163. {
  164. throw new InvalidOperationException("Out of handles!");
  165. }
  166. }
  167. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_accumulatedSuspendedTickChangedEventHandle);
  168. return 0;
  169. }
  170. }
  171. }