am.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <chrono>
  5. #include <memory>
  6. #include <queue>
  7. #include "core/hle/service/kernel_helpers.h"
  8. #include "core/hle/service/service.h"
  9. namespace Kernel {
  10. class KernelCore;
  11. class KReadableEvent;
  12. class KTransferMemory;
  13. } // namespace Kernel
  14. namespace Service::Nvnflinger {
  15. class Nvnflinger;
  16. }
  17. namespace Service::AM {
  18. class AppletMessageQueue {
  19. public:
  20. // This is nn::am::AppletMessage
  21. enum class AppletMessage : u32 {
  22. None = 0,
  23. ChangeIntoForeground = 1,
  24. ChangeIntoBackground = 2,
  25. Exit = 4,
  26. ApplicationExited = 6,
  27. FocusStateChanged = 15,
  28. Resume = 16,
  29. DetectShortPressingHomeButton = 20,
  30. DetectLongPressingHomeButton = 21,
  31. DetectShortPressingPowerButton = 22,
  32. DetectMiddlePressingPowerButton = 23,
  33. DetectLongPressingPowerButton = 24,
  34. RequestToPrepareSleep = 25,
  35. FinishedSleepSequence = 26,
  36. SleepRequiredByHighTemperature = 27,
  37. SleepRequiredByLowBattery = 28,
  38. AutoPowerDown = 29,
  39. OperationModeChanged = 30,
  40. PerformanceModeChanged = 31,
  41. DetectReceivingCecSystemStandby = 32,
  42. SdCardRemoved = 33,
  43. LaunchApplicationRequested = 50,
  44. RequestToDisplay = 51,
  45. ShowApplicationLogo = 55,
  46. HideApplicationLogo = 56,
  47. ForceHideApplicationLogo = 57,
  48. FloatingApplicationDetected = 60,
  49. DetectShortPressingCaptureButton = 90,
  50. AlbumScreenShotTaken = 92,
  51. AlbumRecordingSaved = 93,
  52. };
  53. explicit AppletMessageQueue(Core::System& system);
  54. ~AppletMessageQueue();
  55. Kernel::KReadableEvent& GetMessageReceiveEvent();
  56. Kernel::KReadableEvent& GetOperationModeChangedEvent();
  57. void PushMessage(AppletMessage msg);
  58. AppletMessage PopMessage();
  59. std::size_t GetMessageCount() const;
  60. void RequestExit();
  61. void RequestResume();
  62. void FocusStateChanged();
  63. void OperationModeChanged();
  64. private:
  65. KernelHelpers::ServiceContext service_context;
  66. Kernel::KEvent* on_new_message;
  67. Kernel::KEvent* on_operation_mode_changed;
  68. std::queue<AppletMessage> messages;
  69. };
  70. class IWindowController final : public ServiceFramework<IWindowController> {
  71. public:
  72. explicit IWindowController(Core::System& system_);
  73. ~IWindowController() override;
  74. private:
  75. void GetAppletResourceUserId(HLERequestContext& ctx);
  76. void AcquireForegroundRights(HLERequestContext& ctx);
  77. };
  78. class IAudioController final : public ServiceFramework<IAudioController> {
  79. public:
  80. explicit IAudioController(Core::System& system_);
  81. ~IAudioController() override;
  82. private:
  83. void SetExpectedMasterVolume(HLERequestContext& ctx);
  84. void GetMainAppletExpectedMasterVolume(HLERequestContext& ctx);
  85. void GetLibraryAppletExpectedMasterVolume(HLERequestContext& ctx);
  86. void ChangeMainAppletMasterVolume(HLERequestContext& ctx);
  87. void SetTransparentAudioRate(HLERequestContext& ctx);
  88. static constexpr float min_allowed_volume = 0.0f;
  89. static constexpr float max_allowed_volume = 1.0f;
  90. float main_applet_volume{0.25f};
  91. float library_applet_volume{max_allowed_volume};
  92. float transparent_volume_rate{min_allowed_volume};
  93. // Volume transition fade time in nanoseconds.
  94. // e.g. If the main applet volume was 0% and was changed to 50%
  95. // with a fade of 50ns, then over the course of 50ns,
  96. // the volume will gradually fade up to 50%
  97. std::chrono::nanoseconds fade_time_ns{0};
  98. };
  99. class IDisplayController final : public ServiceFramework<IDisplayController> {
  100. public:
  101. explicit IDisplayController(Core::System& system_);
  102. ~IDisplayController() override;
  103. };
  104. class IDebugFunctions final : public ServiceFramework<IDebugFunctions> {
  105. public:
  106. explicit IDebugFunctions(Core::System& system_);
  107. ~IDebugFunctions() override;
  108. };
  109. class ISelfController final : public ServiceFramework<ISelfController> {
  110. public:
  111. explicit ISelfController(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger_);
  112. ~ISelfController() override;
  113. private:
  114. void Exit(HLERequestContext& ctx);
  115. void LockExit(HLERequestContext& ctx);
  116. void UnlockExit(HLERequestContext& ctx);
  117. void EnterFatalSection(HLERequestContext& ctx);
  118. void LeaveFatalSection(HLERequestContext& ctx);
  119. void GetLibraryAppletLaunchableEvent(HLERequestContext& ctx);
  120. void SetScreenShotPermission(HLERequestContext& ctx);
  121. void SetOperationModeChangedNotification(HLERequestContext& ctx);
  122. void SetPerformanceModeChangedNotification(HLERequestContext& ctx);
  123. void SetFocusHandlingMode(HLERequestContext& ctx);
  124. void SetRestartMessageEnabled(HLERequestContext& ctx);
  125. void SetOutOfFocusSuspendingEnabled(HLERequestContext& ctx);
  126. void SetAlbumImageOrientation(HLERequestContext& ctx);
  127. void CreateManagedDisplayLayer(HLERequestContext& ctx);
  128. void CreateManagedDisplaySeparableLayer(HLERequestContext& ctx);
  129. void SetHandlesRequestToDisplay(HLERequestContext& ctx);
  130. void SetIdleTimeDetectionExtension(HLERequestContext& ctx);
  131. void GetIdleTimeDetectionExtension(HLERequestContext& ctx);
  132. void ReportUserIsActive(HLERequestContext& ctx);
  133. void SetAutoSleepDisabled(HLERequestContext& ctx);
  134. void IsAutoSleepDisabled(HLERequestContext& ctx);
  135. void GetAccumulatedSuspendedTickValue(HLERequestContext& ctx);
  136. void GetAccumulatedSuspendedTickChangedEvent(HLERequestContext& ctx);
  137. void SetAlbumImageTakenNotificationEnabled(HLERequestContext& ctx);
  138. void SaveCurrentScreenshot(HLERequestContext& ctx);
  139. void SetRecordVolumeMuted(HLERequestContext& ctx);
  140. enum class ScreenshotPermission : u32 {
  141. Inherit = 0,
  142. Enable = 1,
  143. Disable = 2,
  144. };
  145. Nvnflinger::Nvnflinger& nvnflinger;
  146. KernelHelpers::ServiceContext service_context;
  147. Kernel::KEvent* launchable_event;
  148. Kernel::KEvent* accumulated_suspended_tick_changed_event;
  149. u32 idle_time_detection_extension = 0;
  150. u64 num_fatal_sections_entered = 0;
  151. bool is_auto_sleep_disabled = false;
  152. ScreenshotPermission screenshot_permission = ScreenshotPermission::Inherit;
  153. };
  154. class ICommonStateGetter final : public ServiceFramework<ICommonStateGetter> {
  155. public:
  156. explicit ICommonStateGetter(Core::System& system_,
  157. std::shared_ptr<AppletMessageQueue> msg_queue_);
  158. ~ICommonStateGetter() override;
  159. private:
  160. // This is nn::oe::FocusState
  161. enum class FocusState : u8 {
  162. InFocus = 1,
  163. NotInFocus = 2,
  164. Background = 3,
  165. };
  166. // This is nn::oe::OperationMode
  167. enum class OperationMode : u8 {
  168. Handheld = 0,
  169. Docked = 1,
  170. };
  171. // This is nn::am::service::SystemButtonType
  172. enum class SystemButtonType {
  173. None,
  174. HomeButtonShortPressing,
  175. HomeButtonLongPressing,
  176. PowerButtonShortPressing,
  177. PowerButtonLongPressing,
  178. ShutdownSystem,
  179. CaptureButtonShortPressing,
  180. CaptureButtonLongPressing,
  181. };
  182. void GetEventHandle(HLERequestContext& ctx);
  183. void ReceiveMessage(HLERequestContext& ctx);
  184. void GetCurrentFocusState(HLERequestContext& ctx);
  185. void GetDefaultDisplayResolutionChangeEvent(HLERequestContext& ctx);
  186. void GetOperationMode(HLERequestContext& ctx);
  187. void GetPerformanceMode(HLERequestContext& ctx);
  188. void GetBootMode(HLERequestContext& ctx);
  189. void IsVrModeEnabled(HLERequestContext& ctx);
  190. void SetVrModeEnabled(HLERequestContext& ctx);
  191. void SetLcdBacklighOffEnabled(HLERequestContext& ctx);
  192. void BeginVrModeEx(HLERequestContext& ctx);
  193. void EndVrModeEx(HLERequestContext& ctx);
  194. void GetDefaultDisplayResolution(HLERequestContext& ctx);
  195. void SetCpuBoostMode(HLERequestContext& ctx);
  196. void PerformSystemButtonPressingIfInFocus(HLERequestContext& ctx);
  197. void SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled(HLERequestContext& ctx);
  198. std::shared_ptr<AppletMessageQueue> msg_queue;
  199. bool vr_mode_state{};
  200. };
  201. class IStorageImpl {
  202. public:
  203. virtual ~IStorageImpl();
  204. virtual std::vector<u8>& GetData() = 0;
  205. virtual const std::vector<u8>& GetData() const = 0;
  206. virtual std::size_t GetSize() const = 0;
  207. };
  208. class IStorage final : public ServiceFramework<IStorage> {
  209. public:
  210. explicit IStorage(Core::System& system_, std::vector<u8>&& buffer);
  211. ~IStorage() override;
  212. std::vector<u8>& GetData() {
  213. return impl->GetData();
  214. }
  215. const std::vector<u8>& GetData() const {
  216. return impl->GetData();
  217. }
  218. std::size_t GetSize() const {
  219. return impl->GetSize();
  220. }
  221. private:
  222. void Register();
  223. void Open(HLERequestContext& ctx);
  224. std::shared_ptr<IStorageImpl> impl;
  225. };
  226. class IStorageAccessor final : public ServiceFramework<IStorageAccessor> {
  227. public:
  228. explicit IStorageAccessor(Core::System& system_, IStorage& backing_);
  229. ~IStorageAccessor() override;
  230. private:
  231. void GetSize(HLERequestContext& ctx);
  232. void Write(HLERequestContext& ctx);
  233. void Read(HLERequestContext& ctx);
  234. IStorage& backing;
  235. };
  236. class ILibraryAppletCreator final : public ServiceFramework<ILibraryAppletCreator> {
  237. public:
  238. explicit ILibraryAppletCreator(Core::System& system_);
  239. ~ILibraryAppletCreator() override;
  240. private:
  241. void CreateLibraryApplet(HLERequestContext& ctx);
  242. void CreateStorage(HLERequestContext& ctx);
  243. void CreateTransferMemoryStorage(HLERequestContext& ctx);
  244. void CreateHandleStorage(HLERequestContext& ctx);
  245. };
  246. class ILibraryAppletSelfAccessor final : public ServiceFramework<ILibraryAppletSelfAccessor> {
  247. public:
  248. explicit ILibraryAppletSelfAccessor(Core::System& system_);
  249. ~ILibraryAppletSelfAccessor() override;
  250. };
  251. class IApplicationFunctions final : public ServiceFramework<IApplicationFunctions> {
  252. public:
  253. explicit IApplicationFunctions(Core::System& system_);
  254. ~IApplicationFunctions() override;
  255. private:
  256. void PopLaunchParameter(HLERequestContext& ctx);
  257. void CreateApplicationAndRequestToStartForQuest(HLERequestContext& ctx);
  258. void EnsureSaveData(HLERequestContext& ctx);
  259. void SetTerminateResult(HLERequestContext& ctx);
  260. void GetDisplayVersion(HLERequestContext& ctx);
  261. void GetDesiredLanguage(HLERequestContext& ctx);
  262. void IsGamePlayRecordingSupported(HLERequestContext& ctx);
  263. void InitializeGamePlayRecording(HLERequestContext& ctx);
  264. void SetGamePlayRecordingState(HLERequestContext& ctx);
  265. void NotifyRunning(HLERequestContext& ctx);
  266. void GetPseudoDeviceId(HLERequestContext& ctx);
  267. void ExtendSaveData(HLERequestContext& ctx);
  268. void GetSaveDataSize(HLERequestContext& ctx);
  269. void CreateCacheStorage(HLERequestContext& ctx);
  270. void BeginBlockingHomeButtonShortAndLongPressed(HLERequestContext& ctx);
  271. void EndBlockingHomeButtonShortAndLongPressed(HLERequestContext& ctx);
  272. void BeginBlockingHomeButton(HLERequestContext& ctx);
  273. void EndBlockingHomeButton(HLERequestContext& ctx);
  274. void EnableApplicationCrashReport(HLERequestContext& ctx);
  275. void InitializeApplicationCopyrightFrameBuffer(HLERequestContext& ctx);
  276. void SetApplicationCopyrightImage(HLERequestContext& ctx);
  277. void SetApplicationCopyrightVisibility(HLERequestContext& ctx);
  278. void QueryApplicationPlayStatistics(HLERequestContext& ctx);
  279. void QueryApplicationPlayStatisticsByUid(HLERequestContext& ctx);
  280. void ExecuteProgram(HLERequestContext& ctx);
  281. void ClearUserChannel(HLERequestContext& ctx);
  282. void UnpopToUserChannel(HLERequestContext& ctx);
  283. void GetPreviousProgramIndex(HLERequestContext& ctx);
  284. void GetGpuErrorDetectedSystemEvent(HLERequestContext& ctx);
  285. void GetFriendInvitationStorageChannelEvent(HLERequestContext& ctx);
  286. void TryPopFromFriendInvitationStorageChannel(HLERequestContext& ctx);
  287. void GetNotificationStorageChannelEvent(HLERequestContext& ctx);
  288. void GetHealthWarningDisappearedSystemEvent(HLERequestContext& ctx);
  289. void PrepareForJit(HLERequestContext& ctx);
  290. KernelHelpers::ServiceContext service_context;
  291. bool launch_popped_account_preselect = false;
  292. s32 previous_program_index{-1};
  293. Kernel::KEvent* gpu_error_detected_event;
  294. Kernel::KEvent* friend_invitation_storage_channel_event;
  295. Kernel::KEvent* notification_storage_channel_event;
  296. Kernel::KEvent* health_warning_disappeared_system_event;
  297. };
  298. class IHomeMenuFunctions final : public ServiceFramework<IHomeMenuFunctions> {
  299. public:
  300. explicit IHomeMenuFunctions(Core::System& system_);
  301. ~IHomeMenuFunctions() override;
  302. private:
  303. void RequestToGetForeground(HLERequestContext& ctx);
  304. void GetPopFromGeneralChannelEvent(HLERequestContext& ctx);
  305. KernelHelpers::ServiceContext service_context;
  306. Kernel::KEvent* pop_from_general_channel_event;
  307. };
  308. class IGlobalStateController final : public ServiceFramework<IGlobalStateController> {
  309. public:
  310. explicit IGlobalStateController(Core::System& system_);
  311. ~IGlobalStateController() override;
  312. };
  313. class IApplicationCreator final : public ServiceFramework<IApplicationCreator> {
  314. public:
  315. explicit IApplicationCreator(Core::System& system_);
  316. ~IApplicationCreator() override;
  317. };
  318. class IProcessWindingController final : public ServiceFramework<IProcessWindingController> {
  319. public:
  320. explicit IProcessWindingController(Core::System& system_);
  321. ~IProcessWindingController() override;
  322. };
  323. void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system);
  324. } // namespace Service::AM