am.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <array>
  5. #include <cinttypes>
  6. #include <cstring>
  7. #include <stack>
  8. #include "audio_core/audio_renderer.h"
  9. #include "core/core.h"
  10. #include "core/hle/ipc_helpers.h"
  11. #include "core/hle/kernel/event.h"
  12. #include "core/hle/kernel/process.h"
  13. #include "core/hle/kernel/shared_memory.h"
  14. #include "core/hle/service/acc/profile_manager.h"
  15. #include "core/hle/service/am/am.h"
  16. #include "core/hle/service/am/applet_ae.h"
  17. #include "core/hle/service/am/applet_oe.h"
  18. #include "core/hle/service/am/applets/applets.h"
  19. #include "core/hle/service/am/applets/software_keyboard.h"
  20. #include "core/hle/service/am/applets/stub_applet.h"
  21. #include "core/hle/service/am/idle.h"
  22. #include "core/hle/service/am/omm.h"
  23. #include "core/hle/service/am/spsm.h"
  24. #include "core/hle/service/am/tcap.h"
  25. #include "core/hle/service/apm/apm.h"
  26. #include "core/hle/service/filesystem/filesystem.h"
  27. #include "core/hle/service/nvflinger/nvflinger.h"
  28. #include "core/hle/service/pm/pm.h"
  29. #include "core/hle/service/set/set.h"
  30. #include "core/hle/service/vi/vi.h"
  31. #include "core/settings.h"
  32. namespace Service::AM {
  33. constexpr ResultCode ERR_NO_DATA_IN_CHANNEL{ErrorModule::AM, 0x2};
  34. constexpr ResultCode ERR_SIZE_OUT_OF_BOUNDS{ErrorModule::AM, 0x1F7};
  35. enum class AppletId : u32 {
  36. SoftwareKeyboard = 0x11,
  37. };
  38. constexpr u32 POP_LAUNCH_PARAMETER_MAGIC = 0xC79497CA;
  39. struct LaunchParameters {
  40. u32_le magic;
  41. u32_le is_account_selected;
  42. u128 current_user;
  43. INSERT_PADDING_BYTES(0x70);
  44. };
  45. static_assert(sizeof(LaunchParameters) == 0x88);
  46. IWindowController::IWindowController() : ServiceFramework("IWindowController") {
  47. // clang-format off
  48. static const FunctionInfo functions[] = {
  49. {0, nullptr, "CreateWindow"},
  50. {1, &IWindowController::GetAppletResourceUserId, "GetAppletResourceUserId"},
  51. {10, &IWindowController::AcquireForegroundRights, "AcquireForegroundRights"},
  52. {11, nullptr, "ReleaseForegroundRights"},
  53. {12, nullptr, "RejectToChangeIntoBackground"},
  54. {20, nullptr, "SetAppletWindowVisibility"},
  55. {21, nullptr, "SetAppletGpuTimeSlice"},
  56. };
  57. // clang-format on
  58. RegisterHandlers(functions);
  59. }
  60. IWindowController::~IWindowController() = default;
  61. void IWindowController::GetAppletResourceUserId(Kernel::HLERequestContext& ctx) {
  62. LOG_WARNING(Service_AM, "(STUBBED) called");
  63. IPC::ResponseBuilder rb{ctx, 4};
  64. rb.Push(RESULT_SUCCESS);
  65. rb.Push<u64>(0);
  66. }
  67. void IWindowController::AcquireForegroundRights(Kernel::HLERequestContext& ctx) {
  68. LOG_WARNING(Service_AM, "(STUBBED) called");
  69. IPC::ResponseBuilder rb{ctx, 2};
  70. rb.Push(RESULT_SUCCESS);
  71. }
  72. IAudioController::IAudioController() : ServiceFramework("IAudioController") {
  73. static const FunctionInfo functions[] = {
  74. {0, &IAudioController::SetExpectedMasterVolume, "SetExpectedMasterVolume"},
  75. {1, &IAudioController::GetMainAppletExpectedMasterVolume,
  76. "GetMainAppletExpectedMasterVolume"},
  77. {2, &IAudioController::GetLibraryAppletExpectedMasterVolume,
  78. "GetLibraryAppletExpectedMasterVolume"},
  79. {3, nullptr, "ChangeMainAppletMasterVolume"},
  80. {4, nullptr, "SetTransparentVolumeRate"},
  81. };
  82. RegisterHandlers(functions);
  83. }
  84. IAudioController::~IAudioController() = default;
  85. void IAudioController::SetExpectedMasterVolume(Kernel::HLERequestContext& ctx) {
  86. LOG_WARNING(Service_AM, "(STUBBED) called");
  87. IPC::ResponseBuilder rb{ctx, 2};
  88. rb.Push(RESULT_SUCCESS);
  89. }
  90. void IAudioController::GetMainAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx) {
  91. LOG_WARNING(Service_AM, "(STUBBED) called");
  92. IPC::ResponseBuilder rb{ctx, 3};
  93. rb.Push(RESULT_SUCCESS);
  94. rb.Push(volume);
  95. }
  96. void IAudioController::GetLibraryAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx) {
  97. LOG_WARNING(Service_AM, "(STUBBED) called");
  98. IPC::ResponseBuilder rb{ctx, 3};
  99. rb.Push(RESULT_SUCCESS);
  100. rb.Push(volume);
  101. }
  102. IDisplayController::IDisplayController() : ServiceFramework("IDisplayController") {
  103. // clang-format off
  104. static const FunctionInfo functions[] = {
  105. {0, nullptr, "GetLastForegroundCaptureImage"},
  106. {1, nullptr, "UpdateLastForegroundCaptureImage"},
  107. {2, nullptr, "GetLastApplicationCaptureImage"},
  108. {3, nullptr, "GetCallerAppletCaptureImage"},
  109. {4, nullptr, "UpdateCallerAppletCaptureImage"},
  110. {5, nullptr, "GetLastForegroundCaptureImageEx"},
  111. {6, nullptr, "GetLastApplicationCaptureImageEx"},
  112. {7, nullptr, "GetCallerAppletCaptureImageEx"},
  113. {8, nullptr, "TakeScreenShotOfOwnLayer"}, // 2.0.0+
  114. {9, nullptr, "CopyBetweenCaptureBuffers"}, // 5.0.0+
  115. {10, nullptr, "AcquireLastApplicationCaptureBuffer"},
  116. {11, nullptr, "ReleaseLastApplicationCaptureBuffer"},
  117. {12, nullptr, "AcquireLastForegroundCaptureBuffer"},
  118. {13, nullptr, "ReleaseLastForegroundCaptureBuffer"},
  119. {14, nullptr, "AcquireCallerAppletCaptureBuffer"},
  120. {15, nullptr, "ReleaseCallerAppletCaptureBuffer"},
  121. {16, nullptr, "AcquireLastApplicationCaptureBufferEx"},
  122. {17, nullptr, "AcquireLastForegroundCaptureBufferEx"},
  123. {18, nullptr, "AcquireCallerAppletCaptureBufferEx"},
  124. // 2.0.0+
  125. {20, nullptr, "ClearCaptureBuffer"},
  126. {21, nullptr, "ClearAppletTransitionBuffer"},
  127. // 4.0.0+
  128. {22, nullptr, "AcquireLastApplicationCaptureSharedBuffer"},
  129. {23, nullptr, "ReleaseLastApplicationCaptureSharedBuffer"},
  130. {24, nullptr, "AcquireLastForegroundCaptureSharedBuffer"},
  131. {25, nullptr, "ReleaseLastForegroundCaptureSharedBuffer"},
  132. {26, nullptr, "AcquireCallerAppletCaptureSharedBuffer"},
  133. {27, nullptr, "ReleaseCallerAppletCaptureSharedBuffer"},
  134. // 6.0.0+
  135. {28, nullptr, "TakeScreenShotOfOwnLayerEx"},
  136. };
  137. // clang-format on
  138. RegisterHandlers(functions);
  139. }
  140. IDisplayController::~IDisplayController() = default;
  141. IDebugFunctions::IDebugFunctions() : ServiceFramework("IDebugFunctions") {}
  142. IDebugFunctions::~IDebugFunctions() = default;
  143. ISelfController::ISelfController(std::shared_ptr<NVFlinger::NVFlinger> nvflinger)
  144. : ServiceFramework("ISelfController"), nvflinger(std::move(nvflinger)) {
  145. // clang-format off
  146. static const FunctionInfo functions[] = {
  147. {0, nullptr, "Exit"},
  148. {1, &ISelfController::LockExit, "LockExit"},
  149. {2, &ISelfController::UnlockExit, "UnlockExit"},
  150. {3, nullptr, "EnterFatalSection"},
  151. {4, nullptr, "LeaveFatalSection"},
  152. {9, &ISelfController::GetLibraryAppletLaunchableEvent, "GetLibraryAppletLaunchableEvent"},
  153. {10, &ISelfController::SetScreenShotPermission, "SetScreenShotPermission"},
  154. {11, &ISelfController::SetOperationModeChangedNotification, "SetOperationModeChangedNotification"},
  155. {12, &ISelfController::SetPerformanceModeChangedNotification, "SetPerformanceModeChangedNotification"},
  156. {13, &ISelfController::SetFocusHandlingMode, "SetFocusHandlingMode"},
  157. {14, &ISelfController::SetRestartMessageEnabled, "SetRestartMessageEnabled"},
  158. {15, nullptr, "SetScreenShotAppletIdentityInfo"},
  159. {16, &ISelfController::SetOutOfFocusSuspendingEnabled, "SetOutOfFocusSuspendingEnabled"},
  160. {17, nullptr, "SetControllerFirmwareUpdateSection"},
  161. {18, nullptr, "SetRequiresCaptureButtonShortPressedMessage"},
  162. {19, &ISelfController::SetScreenShotImageOrientation, "SetScreenShotImageOrientation"},
  163. {20, nullptr, "SetDesirableKeyboardLayout"},
  164. {40, &ISelfController::CreateManagedDisplayLayer, "CreateManagedDisplayLayer"},
  165. {41, nullptr, "IsSystemBufferSharingEnabled"},
  166. {42, nullptr, "GetSystemSharedLayerHandle"},
  167. {50, &ISelfController::SetHandlesRequestToDisplay, "SetHandlesRequestToDisplay"},
  168. {51, nullptr, "ApproveToDisplay"},
  169. {60, nullptr, "OverrideAutoSleepTimeAndDimmingTime"},
  170. {61, nullptr, "SetMediaPlaybackState"},
  171. {62, &ISelfController::SetIdleTimeDetectionExtension, "SetIdleTimeDetectionExtension"},
  172. {63, &ISelfController::GetIdleTimeDetectionExtension, "GetIdleTimeDetectionExtension"},
  173. {64, nullptr, "SetInputDetectionSourceSet"},
  174. {65, nullptr, "ReportUserIsActive"},
  175. {66, nullptr, "GetCurrentIlluminance"},
  176. {67, nullptr, "IsIlluminanceAvailable"},
  177. {68, nullptr, "SetAutoSleepDisabled"},
  178. {69, nullptr, "IsAutoSleepDisabled"},
  179. {70, nullptr, "ReportMultimediaError"},
  180. {80, nullptr, "SetWirelessPriorityMode"},
  181. {90, nullptr, "GetAccumulatedSuspendedTickValue"},
  182. {91, nullptr, "GetAccumulatedSuspendedTickChangedEvent"},
  183. {1000, nullptr, "GetDebugStorageChannel"},
  184. };
  185. // clang-format on
  186. RegisterHandlers(functions);
  187. auto& kernel = Core::System::GetInstance().Kernel();
  188. launchable_event =
  189. Kernel::Event::Create(kernel, Kernel::ResetType::Sticky, "ISelfController:LaunchableEvent");
  190. }
  191. ISelfController::~ISelfController() = default;
  192. void ISelfController::SetFocusHandlingMode(Kernel::HLERequestContext& ctx) {
  193. // Takes 3 input u8s with each field located immediately after the previous
  194. // u8, these are bool flags. No output.
  195. IPC::RequestParser rp{ctx};
  196. struct FocusHandlingModeParams {
  197. u8 unknown0;
  198. u8 unknown1;
  199. u8 unknown2;
  200. };
  201. auto flags = rp.PopRaw<FocusHandlingModeParams>();
  202. IPC::ResponseBuilder rb{ctx, 2};
  203. rb.Push(RESULT_SUCCESS);
  204. LOG_WARNING(Service_AM, "(STUBBED) called");
  205. }
  206. void ISelfController::SetRestartMessageEnabled(Kernel::HLERequestContext& ctx) {
  207. IPC::ResponseBuilder rb{ctx, 2};
  208. rb.Push(RESULT_SUCCESS);
  209. LOG_WARNING(Service_AM, "(STUBBED) called");
  210. }
  211. void ISelfController::SetPerformanceModeChangedNotification(Kernel::HLERequestContext& ctx) {
  212. IPC::RequestParser rp{ctx};
  213. bool flag = rp.Pop<bool>();
  214. IPC::ResponseBuilder rb{ctx, 2};
  215. rb.Push(RESULT_SUCCESS);
  216. LOG_WARNING(Service_AM, "(STUBBED) called flag={}", flag);
  217. }
  218. void ISelfController::SetScreenShotPermission(Kernel::HLERequestContext& ctx) {
  219. IPC::ResponseBuilder rb{ctx, 2};
  220. rb.Push(RESULT_SUCCESS);
  221. LOG_WARNING(Service_AM, "(STUBBED) called");
  222. }
  223. void ISelfController::SetOperationModeChangedNotification(Kernel::HLERequestContext& ctx) {
  224. IPC::RequestParser rp{ctx};
  225. bool flag = rp.Pop<bool>();
  226. IPC::ResponseBuilder rb{ctx, 2};
  227. rb.Push(RESULT_SUCCESS);
  228. LOG_WARNING(Service_AM, "(STUBBED) called flag={}", flag);
  229. }
  230. void ISelfController::SetOutOfFocusSuspendingEnabled(Kernel::HLERequestContext& ctx) {
  231. // Takes 3 input u8s with each field located immediately after the previous
  232. // u8, these are bool flags. No output.
  233. IPC::RequestParser rp{ctx};
  234. bool enabled = rp.Pop<bool>();
  235. IPC::ResponseBuilder rb{ctx, 2};
  236. rb.Push(RESULT_SUCCESS);
  237. LOG_WARNING(Service_AM, "(STUBBED) called enabled={}", enabled);
  238. }
  239. void ISelfController::LockExit(Kernel::HLERequestContext& ctx) {
  240. IPC::ResponseBuilder rb{ctx, 2};
  241. rb.Push(RESULT_SUCCESS);
  242. LOG_WARNING(Service_AM, "(STUBBED) called");
  243. }
  244. void ISelfController::UnlockExit(Kernel::HLERequestContext& ctx) {
  245. IPC::ResponseBuilder rb{ctx, 2};
  246. rb.Push(RESULT_SUCCESS);
  247. LOG_WARNING(Service_AM, "(STUBBED) called");
  248. }
  249. void ISelfController::GetLibraryAppletLaunchableEvent(Kernel::HLERequestContext& ctx) {
  250. launchable_event->Signal();
  251. IPC::ResponseBuilder rb{ctx, 2, 1};
  252. rb.Push(RESULT_SUCCESS);
  253. rb.PushCopyObjects(launchable_event);
  254. LOG_WARNING(Service_AM, "(STUBBED) called");
  255. }
  256. void ISelfController::SetScreenShotImageOrientation(Kernel::HLERequestContext& ctx) {
  257. IPC::ResponseBuilder rb{ctx, 2};
  258. rb.Push(RESULT_SUCCESS);
  259. LOG_WARNING(Service_AM, "(STUBBED) called");
  260. }
  261. void ISelfController::CreateManagedDisplayLayer(Kernel::HLERequestContext& ctx) {
  262. // TODO(Subv): Find out how AM determines the display to use, for now just
  263. // create the layer in the Default display.
  264. u64 display_id = nvflinger->OpenDisplay("Default");
  265. u64 layer_id = nvflinger->CreateLayer(display_id);
  266. IPC::ResponseBuilder rb{ctx, 4};
  267. rb.Push(RESULT_SUCCESS);
  268. rb.Push(layer_id);
  269. LOG_WARNING(Service_AM, "(STUBBED) called");
  270. }
  271. void ISelfController::SetHandlesRequestToDisplay(Kernel::HLERequestContext& ctx) {
  272. IPC::ResponseBuilder rb{ctx, 2};
  273. rb.Push(RESULT_SUCCESS);
  274. LOG_WARNING(Service_AM, "(STUBBED) called");
  275. }
  276. void ISelfController::SetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx) {
  277. IPC::RequestParser rp{ctx};
  278. idle_time_detection_extension = rp.Pop<u32>();
  279. IPC::ResponseBuilder rb{ctx, 2};
  280. rb.Push(RESULT_SUCCESS);
  281. LOG_WARNING(Service_AM, "(STUBBED) called");
  282. }
  283. void ISelfController::GetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx) {
  284. IPC::ResponseBuilder rb{ctx, 3};
  285. rb.Push(RESULT_SUCCESS);
  286. rb.Push<u32>(idle_time_detection_extension);
  287. LOG_WARNING(Service_AM, "(STUBBED) called");
  288. }
  289. AppletMessageQueue::AppletMessageQueue() {
  290. auto& kernel = Core::System::GetInstance().Kernel();
  291. on_new_message = Kernel::Event::Create(kernel, Kernel::ResetType::Sticky,
  292. "AMMessageQueue:OnMessageRecieved");
  293. on_operation_mode_changed = Kernel::Event::Create(kernel, Kernel::ResetType::OneShot,
  294. "AMMessageQueue:OperationModeChanged");
  295. }
  296. AppletMessageQueue::~AppletMessageQueue() = default;
  297. const Kernel::SharedPtr<Kernel::Event>& AppletMessageQueue::GetMesssageRecieveEvent() const {
  298. return on_new_message;
  299. }
  300. const Kernel::SharedPtr<Kernel::Event>& AppletMessageQueue::GetOperationModeChangedEvent() const {
  301. return on_operation_mode_changed;
  302. }
  303. void AppletMessageQueue::PushMessage(AppletMessage msg) {
  304. messages.push(msg);
  305. on_new_message->Signal();
  306. }
  307. AppletMessageQueue::AppletMessage AppletMessageQueue::PopMessage() {
  308. if (messages.empty()) {
  309. on_new_message->Clear();
  310. return AppletMessage::NoMessage;
  311. }
  312. auto msg = messages.front();
  313. messages.pop();
  314. if (messages.empty()) {
  315. on_new_message->Clear();
  316. }
  317. return msg;
  318. }
  319. std::size_t AppletMessageQueue::GetMessageCount() const {
  320. return messages.size();
  321. }
  322. void AppletMessageQueue::OperationModeChanged() {
  323. PushMessage(AppletMessage::OperationModeChanged);
  324. PushMessage(AppletMessage::PerformanceModeChanged);
  325. on_operation_mode_changed->Signal();
  326. }
  327. ICommonStateGetter::ICommonStateGetter(std::shared_ptr<AppletMessageQueue> msg_queue)
  328. : ServiceFramework("ICommonStateGetter"), msg_queue(std::move(msg_queue)) {
  329. // clang-format off
  330. static const FunctionInfo functions[] = {
  331. {0, &ICommonStateGetter::GetEventHandle, "GetEventHandle"},
  332. {1, &ICommonStateGetter::ReceiveMessage, "ReceiveMessage"},
  333. {2, nullptr, "GetThisAppletKind"},
  334. {3, nullptr, "AllowToEnterSleep"},
  335. {4, nullptr, "DisallowToEnterSleep"},
  336. {5, &ICommonStateGetter::GetOperationMode, "GetOperationMode"},
  337. {6, &ICommonStateGetter::GetPerformanceMode, "GetPerformanceMode"},
  338. {7, nullptr, "GetCradleStatus"},
  339. {8, &ICommonStateGetter::GetBootMode, "GetBootMode"},
  340. {9, &ICommonStateGetter::GetCurrentFocusState, "GetCurrentFocusState"},
  341. {10, nullptr, "RequestToAcquireSleepLock"},
  342. {11, nullptr, "ReleaseSleepLock"},
  343. {12, nullptr, "ReleaseSleepLockTransiently"},
  344. {13, nullptr, "GetAcquiredSleepLockEvent"},
  345. {20, nullptr, "PushToGeneralChannel"},
  346. {30, nullptr, "GetHomeButtonReaderLockAccessor"},
  347. {31, nullptr, "GetReaderLockAccessorEx"},
  348. {40, nullptr, "GetCradleFwVersion"},
  349. {50, nullptr, "IsVrModeEnabled"},
  350. {51, nullptr, "SetVrModeEnabled"},
  351. {52, nullptr, "SwitchLcdBacklight"},
  352. {55, nullptr, "IsInControllerFirmwareUpdateSection"},
  353. {60, &ICommonStateGetter::GetDefaultDisplayResolution, "GetDefaultDisplayResolution"},
  354. {61, &ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent, "GetDefaultDisplayResolutionChangeEvent"},
  355. {62, nullptr, "GetHdcpAuthenticationState"},
  356. {63, nullptr, "GetHdcpAuthenticationStateChangeEvent"},
  357. };
  358. // clang-format on
  359. RegisterHandlers(functions);
  360. auto& kernel = Core::System::GetInstance().Kernel();
  361. event = Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "ICommonStateGetter:Event");
  362. }
  363. ICommonStateGetter::~ICommonStateGetter() = default;
  364. void ICommonStateGetter::GetBootMode(Kernel::HLERequestContext& ctx) {
  365. IPC::ResponseBuilder rb{ctx, 3};
  366. rb.Push(RESULT_SUCCESS);
  367. rb.Push<u8>(static_cast<u8>(Service::PM::SystemBootMode::Normal)); // Normal boot mode
  368. LOG_DEBUG(Service_AM, "called");
  369. }
  370. void ICommonStateGetter::GetEventHandle(Kernel::HLERequestContext& ctx) {
  371. IPC::ResponseBuilder rb{ctx, 2, 1};
  372. rb.Push(RESULT_SUCCESS);
  373. rb.PushCopyObjects(msg_queue->GetMesssageRecieveEvent());
  374. LOG_DEBUG(Service_AM, "called");
  375. }
  376. void ICommonStateGetter::ReceiveMessage(Kernel::HLERequestContext& ctx) {
  377. IPC::ResponseBuilder rb{ctx, 3};
  378. rb.Push(RESULT_SUCCESS);
  379. rb.PushEnum<AppletMessageQueue::AppletMessage>(msg_queue->PopMessage());
  380. LOG_DEBUG(Service_AM, "called");
  381. }
  382. void ICommonStateGetter::GetCurrentFocusState(Kernel::HLERequestContext& ctx) {
  383. IPC::ResponseBuilder rb{ctx, 3};
  384. rb.Push(RESULT_SUCCESS);
  385. rb.Push(static_cast<u8>(FocusState::InFocus));
  386. LOG_WARNING(Service_AM, "(STUBBED) called");
  387. }
  388. void ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent(Kernel::HLERequestContext& ctx) {
  389. IPC::ResponseBuilder rb{ctx, 2, 1};
  390. rb.Push(RESULT_SUCCESS);
  391. rb.PushCopyObjects(msg_queue->GetOperationModeChangedEvent());
  392. LOG_DEBUG(Service_AM, "called");
  393. }
  394. void ICommonStateGetter::GetDefaultDisplayResolution(Kernel::HLERequestContext& ctx) {
  395. IPC::ResponseBuilder rb{ctx, 4};
  396. rb.Push(RESULT_SUCCESS);
  397. if (Settings::values.use_docked_mode) {
  398. rb.Push(static_cast<u32>(Service::VI::DisplayResolution::DockedWidth));
  399. rb.Push(static_cast<u32>(Service::VI::DisplayResolution::DockedHeight));
  400. } else {
  401. rb.Push(static_cast<u32>(Service::VI::DisplayResolution::UndockedWidth));
  402. rb.Push(static_cast<u32>(Service::VI::DisplayResolution::UndockedHeight));
  403. }
  404. LOG_DEBUG(Service_AM, "called");
  405. }
  406. IStorage::IStorage(std::vector<u8> buffer)
  407. : ServiceFramework("IStorage"), buffer(std::move(buffer)) {
  408. // clang-format off
  409. static const FunctionInfo functions[] = {
  410. {0, &IStorage::Open, "Open"},
  411. {1, nullptr, "OpenTransferStorage"},
  412. };
  413. // clang-format on
  414. RegisterHandlers(functions);
  415. }
  416. IStorage::~IStorage() = default;
  417. const std::vector<u8>& IStorage::GetData() const {
  418. return buffer;
  419. }
  420. void ICommonStateGetter::GetOperationMode(Kernel::HLERequestContext& ctx) {
  421. const bool use_docked_mode{Settings::values.use_docked_mode};
  422. IPC::ResponseBuilder rb{ctx, 3};
  423. rb.Push(RESULT_SUCCESS);
  424. rb.Push(static_cast<u8>(use_docked_mode ? OperationMode::Docked : OperationMode::Handheld));
  425. LOG_DEBUG(Service_AM, "called");
  426. }
  427. void ICommonStateGetter::GetPerformanceMode(Kernel::HLERequestContext& ctx) {
  428. const bool use_docked_mode{Settings::values.use_docked_mode};
  429. IPC::ResponseBuilder rb{ctx, 3};
  430. rb.Push(RESULT_SUCCESS);
  431. rb.Push(static_cast<u32>(use_docked_mode ? APM::PerformanceMode::Docked
  432. : APM::PerformanceMode::Handheld));
  433. LOG_DEBUG(Service_AM, "called");
  434. }
  435. class ILibraryAppletAccessor final : public ServiceFramework<ILibraryAppletAccessor> {
  436. public:
  437. explicit ILibraryAppletAccessor(std::shared_ptr<Applets::Applet> applet)
  438. : ServiceFramework("ILibraryAppletAccessor"), applet(std::move(applet)) {
  439. // clang-format off
  440. static const FunctionInfo functions[] = {
  441. {0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"},
  442. {1, &ILibraryAppletAccessor::IsCompleted, "IsCompleted"},
  443. {10, &ILibraryAppletAccessor::Start, "Start"},
  444. {20, nullptr, "RequestExit"},
  445. {25, nullptr, "Terminate"},
  446. {30, &ILibraryAppletAccessor::GetResult, "GetResult"},
  447. {50, nullptr, "SetOutOfFocusApplicationSuspendingEnabled"},
  448. {100, &ILibraryAppletAccessor::PushInData, "PushInData"},
  449. {101, &ILibraryAppletAccessor::PopOutData, "PopOutData"},
  450. {102, nullptr, "PushExtraStorage"},
  451. {103, &ILibraryAppletAccessor::PushInteractiveInData, "PushInteractiveInData"},
  452. {104, &ILibraryAppletAccessor::PopInteractiveOutData, "PopInteractiveOutData"},
  453. {105, &ILibraryAppletAccessor::GetPopOutDataEvent, "GetPopOutDataEvent"},
  454. {106, &ILibraryAppletAccessor::GetPopInteractiveOutDataEvent, "GetPopInteractiveOutDataEvent"},
  455. {110, nullptr, "NeedsToExitProcess"},
  456. {120, nullptr, "GetLibraryAppletInfo"},
  457. {150, nullptr, "RequestForAppletToGetForeground"},
  458. {160, nullptr, "GetIndirectLayerConsumerHandle"},
  459. };
  460. // clang-format on
  461. RegisterHandlers(functions);
  462. }
  463. private:
  464. void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) {
  465. const auto event = applet->GetBroker().GetStateChangedEvent();
  466. event->Signal();
  467. IPC::ResponseBuilder rb{ctx, 2, 1};
  468. rb.Push(RESULT_SUCCESS);
  469. rb.PushCopyObjects(event);
  470. LOG_DEBUG(Service_AM, "called");
  471. }
  472. void IsCompleted(Kernel::HLERequestContext& ctx) {
  473. IPC::ResponseBuilder rb{ctx, 3};
  474. rb.Push(RESULT_SUCCESS);
  475. rb.Push<u32>(applet->TransactionComplete());
  476. LOG_DEBUG(Service_AM, "called");
  477. }
  478. void GetResult(Kernel::HLERequestContext& ctx) {
  479. IPC::ResponseBuilder rb{ctx, 2};
  480. rb.Push(applet->GetStatus());
  481. LOG_DEBUG(Service_AM, "called");
  482. }
  483. void Start(Kernel::HLERequestContext& ctx) {
  484. ASSERT(applet != nullptr);
  485. applet->Initialize();
  486. applet->Execute();
  487. IPC::ResponseBuilder rb{ctx, 2};
  488. rb.Push(RESULT_SUCCESS);
  489. LOG_DEBUG(Service_AM, "called");
  490. }
  491. void PushInData(Kernel::HLERequestContext& ctx) {
  492. IPC::RequestParser rp{ctx};
  493. applet->GetBroker().PushNormalDataFromGame(*rp.PopIpcInterface<IStorage>());
  494. IPC::ResponseBuilder rb{ctx, 2};
  495. rb.Push(RESULT_SUCCESS);
  496. LOG_DEBUG(Service_AM, "called");
  497. }
  498. void PopOutData(Kernel::HLERequestContext& ctx) {
  499. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  500. const auto storage = applet->GetBroker().PopNormalDataToGame();
  501. if (storage == nullptr) {
  502. rb.Push(ERR_NO_DATA_IN_CHANNEL);
  503. return;
  504. }
  505. rb.Push(RESULT_SUCCESS);
  506. rb.PushIpcInterface<IStorage>(std::move(*storage));
  507. LOG_DEBUG(Service_AM, "called");
  508. }
  509. void PushInteractiveInData(Kernel::HLERequestContext& ctx) {
  510. IPC::RequestParser rp{ctx};
  511. applet->GetBroker().PushInteractiveDataFromGame(*rp.PopIpcInterface<IStorage>());
  512. ASSERT(applet->IsInitialized());
  513. applet->ExecuteInteractive();
  514. applet->Execute();
  515. IPC::ResponseBuilder rb{ctx, 2};
  516. rb.Push(RESULT_SUCCESS);
  517. LOG_DEBUG(Service_AM, "called");
  518. }
  519. void PopInteractiveOutData(Kernel::HLERequestContext& ctx) {
  520. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  521. const auto storage = applet->GetBroker().PopInteractiveDataToGame();
  522. if (storage == nullptr) {
  523. rb.Push(ERR_NO_DATA_IN_CHANNEL);
  524. return;
  525. }
  526. rb.Push(RESULT_SUCCESS);
  527. rb.PushIpcInterface<IStorage>(std::move(*storage));
  528. LOG_DEBUG(Service_AM, "called");
  529. }
  530. void GetPopOutDataEvent(Kernel::HLERequestContext& ctx) {
  531. IPC::ResponseBuilder rb{ctx, 2, 1};
  532. rb.Push(RESULT_SUCCESS);
  533. rb.PushCopyObjects(applet->GetBroker().GetNormalDataEvent());
  534. LOG_DEBUG(Service_AM, "called");
  535. }
  536. void GetPopInteractiveOutDataEvent(Kernel::HLERequestContext& ctx) {
  537. IPC::ResponseBuilder rb{ctx, 2, 1};
  538. rb.Push(RESULT_SUCCESS);
  539. rb.PushCopyObjects(applet->GetBroker().GetInteractiveDataEvent());
  540. LOG_DEBUG(Service_AM, "called");
  541. }
  542. std::shared_ptr<Applets::Applet> applet;
  543. };
  544. void IStorage::Open(Kernel::HLERequestContext& ctx) {
  545. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  546. rb.Push(RESULT_SUCCESS);
  547. rb.PushIpcInterface<IStorageAccessor>(*this);
  548. LOG_DEBUG(Service_AM, "called");
  549. }
  550. IStorageAccessor::IStorageAccessor(IStorage& storage)
  551. : ServiceFramework("IStorageAccessor"), backing(storage) {
  552. // clang-format off
  553. static const FunctionInfo functions[] = {
  554. {0, &IStorageAccessor::GetSize, "GetSize"},
  555. {10, &IStorageAccessor::Write, "Write"},
  556. {11, &IStorageAccessor::Read, "Read"},
  557. };
  558. // clang-format on
  559. RegisterHandlers(functions);
  560. }
  561. IStorageAccessor::~IStorageAccessor() = default;
  562. void IStorageAccessor::GetSize(Kernel::HLERequestContext& ctx) {
  563. IPC::ResponseBuilder rb{ctx, 4};
  564. rb.Push(RESULT_SUCCESS);
  565. rb.Push(static_cast<u64>(backing.buffer.size()));
  566. LOG_DEBUG(Service_AM, "called");
  567. }
  568. void IStorageAccessor::Write(Kernel::HLERequestContext& ctx) {
  569. IPC::RequestParser rp{ctx};
  570. const u64 offset{rp.Pop<u64>()};
  571. const std::vector<u8> data{ctx.ReadBuffer()};
  572. if (data.size() > backing.buffer.size() - offset) {
  573. IPC::ResponseBuilder rb{ctx, 2};
  574. rb.Push(ERR_SIZE_OUT_OF_BOUNDS);
  575. }
  576. std::memcpy(backing.buffer.data() + offset, data.data(), data.size());
  577. IPC::ResponseBuilder rb{ctx, 2};
  578. rb.Push(RESULT_SUCCESS);
  579. LOG_DEBUG(Service_AM, "called, offset={}", offset);
  580. }
  581. void IStorageAccessor::Read(Kernel::HLERequestContext& ctx) {
  582. IPC::RequestParser rp{ctx};
  583. const u64 offset{rp.Pop<u64>()};
  584. const std::size_t size{ctx.GetWriteBufferSize()};
  585. if (size > backing.buffer.size() - offset) {
  586. IPC::ResponseBuilder rb{ctx, 2};
  587. rb.Push(ERR_SIZE_OUT_OF_BOUNDS);
  588. }
  589. ctx.WriteBuffer(backing.buffer.data() + offset, size);
  590. IPC::ResponseBuilder rb{ctx, 2};
  591. rb.Push(RESULT_SUCCESS);
  592. LOG_DEBUG(Service_AM, "called, offset={}", offset);
  593. }
  594. ILibraryAppletCreator::ILibraryAppletCreator() : ServiceFramework("ILibraryAppletCreator") {
  595. static const FunctionInfo functions[] = {
  596. {0, &ILibraryAppletCreator::CreateLibraryApplet, "CreateLibraryApplet"},
  597. {1, nullptr, "TerminateAllLibraryApplets"},
  598. {2, nullptr, "AreAnyLibraryAppletsLeft"},
  599. {10, &ILibraryAppletCreator::CreateStorage, "CreateStorage"},
  600. {11, &ILibraryAppletCreator::CreateTransferMemoryStorage, "CreateTransferMemoryStorage"},
  601. {12, nullptr, "CreateHandleStorage"},
  602. };
  603. RegisterHandlers(functions);
  604. }
  605. ILibraryAppletCreator::~ILibraryAppletCreator() = default;
  606. static std::shared_ptr<Applets::Applet> GetAppletFromId(AppletId id) {
  607. switch (id) {
  608. case AppletId::SoftwareKeyboard:
  609. return std::make_shared<Applets::SoftwareKeyboard>();
  610. default:
  611. LOG_ERROR(Service_AM, "Unimplemented AppletId [{:08X}]! -- Falling back to stub!",
  612. static_cast<u32>(id));
  613. return std::make_shared<Applets::StubApplet>();
  614. }
  615. }
  616. void ILibraryAppletCreator::CreateLibraryApplet(Kernel::HLERequestContext& ctx) {
  617. IPC::RequestParser rp{ctx};
  618. const auto applet_id = rp.PopRaw<AppletId>();
  619. const auto applet_mode = rp.PopRaw<u32>();
  620. LOG_DEBUG(Service_AM, "called with applet_id={:08X}, applet_mode={:08X}",
  621. static_cast<u32>(applet_id), applet_mode);
  622. const auto applet = GetAppletFromId(applet_id);
  623. if (applet == nullptr) {
  624. IPC::ResponseBuilder rb{ctx, 2};
  625. rb.Push(ResultCode(-1));
  626. return;
  627. }
  628. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  629. rb.Push(RESULT_SUCCESS);
  630. rb.PushIpcInterface<AM::ILibraryAppletAccessor>(applet);
  631. LOG_DEBUG(Service_AM, "called");
  632. }
  633. void ILibraryAppletCreator::CreateStorage(Kernel::HLERequestContext& ctx) {
  634. IPC::RequestParser rp{ctx};
  635. const u64 size{rp.Pop<u64>()};
  636. std::vector<u8> buffer(size);
  637. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  638. rb.Push(RESULT_SUCCESS);
  639. rb.PushIpcInterface<AM::IStorage>(std::move(buffer));
  640. LOG_DEBUG(Service_AM, "called, size={}", size);
  641. }
  642. void ILibraryAppletCreator::CreateTransferMemoryStorage(Kernel::HLERequestContext& ctx) {
  643. IPC::RequestParser rp{ctx};
  644. rp.SetCurrentOffset(3);
  645. const auto handle{rp.Pop<Kernel::Handle>()};
  646. const auto shared_mem =
  647. Core::System::GetInstance().CurrentProcess()->GetHandleTable().Get<Kernel::SharedMemory>(
  648. handle);
  649. if (shared_mem == nullptr) {
  650. IPC::ResponseBuilder rb{ctx, 2};
  651. rb.Push(ResultCode(-1));
  652. return;
  653. }
  654. const u8* mem_begin = shared_mem->GetPointer();
  655. const u8* mem_end = mem_begin + shared_mem->GetSize();
  656. std::vector<u8> memory{mem_begin, mem_end};
  657. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  658. rb.Push(RESULT_SUCCESS);
  659. rb.PushIpcInterface(std::make_shared<IStorage>(std::move(memory)));
  660. }
  661. IApplicationFunctions::IApplicationFunctions() : ServiceFramework("IApplicationFunctions") {
  662. // clang-format off
  663. static const FunctionInfo functions[] = {
  664. {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"},
  665. {10, nullptr, "CreateApplicationAndPushAndRequestToStart"},
  666. {11, nullptr, "CreateApplicationAndPushAndRequestToStartForQuest"},
  667. {12, nullptr, "CreateApplicationAndRequestToStart"},
  668. {13, &IApplicationFunctions::CreateApplicationAndRequestToStartForQuest, "CreateApplicationAndRequestToStartForQuest"},
  669. {20, &IApplicationFunctions::EnsureSaveData, "EnsureSaveData"},
  670. {21, &IApplicationFunctions::GetDesiredLanguage, "GetDesiredLanguage"},
  671. {22, &IApplicationFunctions::SetTerminateResult, "SetTerminateResult"},
  672. {23, &IApplicationFunctions::GetDisplayVersion, "GetDisplayVersion"},
  673. {24, nullptr, "GetLaunchStorageInfoForDebug"},
  674. {25, nullptr, "ExtendSaveData"},
  675. {26, nullptr, "GetSaveDataSize"},
  676. {30, &IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed, "BeginBlockingHomeButtonShortAndLongPressed"},
  677. {31, &IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed, "EndBlockingHomeButtonShortAndLongPressed"},
  678. {32, &IApplicationFunctions::BeginBlockingHomeButton, "BeginBlockingHomeButton"},
  679. {33, &IApplicationFunctions::EndBlockingHomeButton, "EndBlockingHomeButton"},
  680. {40, &IApplicationFunctions::NotifyRunning, "NotifyRunning"},
  681. {50, &IApplicationFunctions::GetPseudoDeviceId, "GetPseudoDeviceId"},
  682. {60, nullptr, "SetMediaPlaybackStateForApplication"},
  683. {65, nullptr, "IsGamePlayRecordingSupported"},
  684. {66, &IApplicationFunctions::InitializeGamePlayRecording, "InitializeGamePlayRecording"},
  685. {67, &IApplicationFunctions::SetGamePlayRecordingState, "SetGamePlayRecordingState"},
  686. {68, nullptr, "RequestFlushGamePlayingMovieForDebug"},
  687. {70, nullptr, "RequestToShutdown"},
  688. {71, nullptr, "RequestToReboot"},
  689. {80, nullptr, "ExitAndRequestToShowThanksMessage"},
  690. {90, &IApplicationFunctions::EnableApplicationCrashReport, "EnableApplicationCrashReport"},
  691. {100, nullptr, "InitializeApplicationCopyrightFrameBuffer"},
  692. {101, nullptr, "SetApplicationCopyrightImage"},
  693. {102, nullptr, "SetApplicationCopyrightVisibility"},
  694. {110, nullptr, "QueryApplicationPlayStatistics"},
  695. {120, nullptr, "ExecuteProgram"},
  696. {121, nullptr, "ClearUserChannel"},
  697. {122, nullptr, "UnpopToUserChannel"},
  698. {500, nullptr, "StartContinuousRecordingFlushForDebug"},
  699. {1000, nullptr, "CreateMovieMaker"},
  700. {1001, nullptr, "PrepareForJit"},
  701. };
  702. // clang-format on
  703. RegisterHandlers(functions);
  704. }
  705. IApplicationFunctions::~IApplicationFunctions() = default;
  706. void IApplicationFunctions::EnableApplicationCrashReport(Kernel::HLERequestContext& ctx) {
  707. IPC::ResponseBuilder rb{ctx, 2};
  708. rb.Push(RESULT_SUCCESS);
  709. LOG_WARNING(Service_AM, "(STUBBED) called");
  710. }
  711. void IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed(
  712. Kernel::HLERequestContext& ctx) {
  713. IPC::ResponseBuilder rb{ctx, 2};
  714. rb.Push(RESULT_SUCCESS);
  715. LOG_WARNING(Service_AM, "(STUBBED) called");
  716. }
  717. void IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed(
  718. Kernel::HLERequestContext& ctx) {
  719. IPC::ResponseBuilder rb{ctx, 2};
  720. rb.Push(RESULT_SUCCESS);
  721. LOG_WARNING(Service_AM, "(STUBBED) called");
  722. }
  723. void IApplicationFunctions::BeginBlockingHomeButton(Kernel::HLERequestContext& ctx) {
  724. IPC::ResponseBuilder rb{ctx, 2};
  725. rb.Push(RESULT_SUCCESS);
  726. LOG_WARNING(Service_AM, "(STUBBED) called");
  727. }
  728. void IApplicationFunctions::EndBlockingHomeButton(Kernel::HLERequestContext& ctx) {
  729. IPC::ResponseBuilder rb{ctx, 2};
  730. rb.Push(RESULT_SUCCESS);
  731. LOG_WARNING(Service_AM, "(STUBBED) called");
  732. }
  733. void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) {
  734. LaunchParameters params{};
  735. params.magic = POP_LAUNCH_PARAMETER_MAGIC;
  736. params.is_account_selected = 1;
  737. Account::ProfileManager profile_manager{};
  738. const auto uuid = profile_manager.GetUser(Settings::values.current_user);
  739. ASSERT(uuid);
  740. params.current_user = uuid->uuid;
  741. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  742. rb.Push(RESULT_SUCCESS);
  743. std::vector<u8> buffer(sizeof(LaunchParameters));
  744. std::memcpy(buffer.data(), &params, buffer.size());
  745. rb.PushIpcInterface<AM::IStorage>(buffer);
  746. LOG_DEBUG(Service_AM, "called");
  747. }
  748. void IApplicationFunctions::CreateApplicationAndRequestToStartForQuest(
  749. Kernel::HLERequestContext& ctx) {
  750. IPC::ResponseBuilder rb{ctx, 2};
  751. rb.Push(RESULT_SUCCESS);
  752. LOG_WARNING(Service_AM, "(STUBBED) called");
  753. }
  754. void IApplicationFunctions::EnsureSaveData(Kernel::HLERequestContext& ctx) {
  755. IPC::RequestParser rp{ctx};
  756. u128 uid = rp.PopRaw<u128>(); // What does this do?
  757. LOG_WARNING(Service, "(STUBBED) called uid = {:016X}{:016X}", uid[1], uid[0]);
  758. IPC::ResponseBuilder rb{ctx, 4};
  759. rb.Push(RESULT_SUCCESS);
  760. rb.Push<u64>(0);
  761. } // namespace Service::AM
  762. void IApplicationFunctions::SetTerminateResult(Kernel::HLERequestContext& ctx) {
  763. // Takes an input u32 Result, no output.
  764. // For example, in some cases official apps use this with error 0x2A2 then
  765. // uses svcBreak.
  766. IPC::RequestParser rp{ctx};
  767. u32 result = rp.Pop<u32>();
  768. IPC::ResponseBuilder rb{ctx, 2};
  769. rb.Push(RESULT_SUCCESS);
  770. LOG_WARNING(Service_AM, "(STUBBED) called, result=0x{:08X}", result);
  771. }
  772. void IApplicationFunctions::GetDisplayVersion(Kernel::HLERequestContext& ctx) {
  773. IPC::ResponseBuilder rb{ctx, 6};
  774. rb.Push(RESULT_SUCCESS);
  775. rb.Push<u64>(1);
  776. rb.Push<u64>(0);
  777. LOG_WARNING(Service_AM, "(STUBBED) called");
  778. }
  779. void IApplicationFunctions::GetDesiredLanguage(Kernel::HLERequestContext& ctx) {
  780. // TODO(bunnei): This should be configurable
  781. IPC::ResponseBuilder rb{ctx, 4};
  782. rb.Push(RESULT_SUCCESS);
  783. rb.Push(
  784. static_cast<u64>(Service::Set::GetLanguageCodeFromIndex(Settings::values.language_index)));
  785. LOG_DEBUG(Service_AM, "called");
  786. }
  787. void IApplicationFunctions::InitializeGamePlayRecording(Kernel::HLERequestContext& ctx) {
  788. IPC::ResponseBuilder rb{ctx, 2};
  789. rb.Push(RESULT_SUCCESS);
  790. LOG_WARNING(Service_AM, "(STUBBED) called");
  791. }
  792. void IApplicationFunctions::SetGamePlayRecordingState(Kernel::HLERequestContext& ctx) {
  793. IPC::ResponseBuilder rb{ctx, 2};
  794. rb.Push(RESULT_SUCCESS);
  795. LOG_WARNING(Service_AM, "(STUBBED) called");
  796. }
  797. void IApplicationFunctions::NotifyRunning(Kernel::HLERequestContext& ctx) {
  798. IPC::ResponseBuilder rb{ctx, 3};
  799. rb.Push(RESULT_SUCCESS);
  800. rb.Push<u8>(0); // Unknown, seems to be ignored by official processes
  801. LOG_WARNING(Service_AM, "(STUBBED) called");
  802. }
  803. void IApplicationFunctions::GetPseudoDeviceId(Kernel::HLERequestContext& ctx) {
  804. IPC::ResponseBuilder rb{ctx, 6};
  805. rb.Push(RESULT_SUCCESS);
  806. // Returns a 128-bit UUID
  807. rb.Push<u64>(0);
  808. rb.Push<u64>(0);
  809. LOG_WARNING(Service_AM, "(STUBBED) called");
  810. }
  811. void InstallInterfaces(SM::ServiceManager& service_manager,
  812. std::shared_ptr<NVFlinger::NVFlinger> nvflinger) {
  813. auto message_queue = std::make_shared<AppletMessageQueue>();
  814. message_queue->PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged); // Needed on
  815. // game boot
  816. std::make_shared<AppletAE>(nvflinger, message_queue)->InstallAsService(service_manager);
  817. std::make_shared<AppletOE>(nvflinger, message_queue)->InstallAsService(service_manager);
  818. std::make_shared<IdleSys>()->InstallAsService(service_manager);
  819. std::make_shared<OMM>()->InstallAsService(service_manager);
  820. std::make_shared<SPSM>()->InstallAsService(service_manager);
  821. std::make_shared<TCAP>()->InstallAsService(service_manager);
  822. }
  823. IHomeMenuFunctions::IHomeMenuFunctions() : ServiceFramework("IHomeMenuFunctions") {
  824. // clang-format off
  825. static const FunctionInfo functions[] = {
  826. {10, &IHomeMenuFunctions::RequestToGetForeground, "RequestToGetForeground"},
  827. {11, nullptr, "LockForeground"},
  828. {12, nullptr, "UnlockForeground"},
  829. {20, nullptr, "PopFromGeneralChannel"},
  830. {21, nullptr, "GetPopFromGeneralChannelEvent"},
  831. {30, nullptr, "GetHomeButtonWriterLockAccessor"},
  832. {31, nullptr, "GetWriterLockAccessorEx"},
  833. {100, nullptr, "PopRequestLaunchApplicationForDebug"},
  834. };
  835. // clang-format on
  836. RegisterHandlers(functions);
  837. }
  838. IHomeMenuFunctions::~IHomeMenuFunctions() = default;
  839. void IHomeMenuFunctions::RequestToGetForeground(Kernel::HLERequestContext& ctx) {
  840. IPC::ResponseBuilder rb{ctx, 2};
  841. rb.Push(RESULT_SUCCESS);
  842. LOG_WARNING(Service_AM, "(STUBBED) called");
  843. }
  844. IGlobalStateController::IGlobalStateController() : ServiceFramework("IGlobalStateController") {
  845. // clang-format off
  846. static const FunctionInfo functions[] = {
  847. {0, nullptr, "RequestToEnterSleep"},
  848. {1, nullptr, "EnterSleep"},
  849. {2, nullptr, "StartSleepSequence"},
  850. {3, nullptr, "StartShutdownSequence"},
  851. {4, nullptr, "StartRebootSequence"},
  852. {10, nullptr, "LoadAndApplyIdlePolicySettings"},
  853. {11, nullptr, "NotifyCecSettingsChanged"},
  854. {12, nullptr, "SetDefaultHomeButtonLongPressTime"},
  855. {13, nullptr, "UpdateDefaultDisplayResolution"},
  856. {14, nullptr, "ShouldSleepOnBoot"},
  857. {15, nullptr, "GetHdcpAuthenticationFailedEvent"},
  858. };
  859. // clang-format on
  860. RegisterHandlers(functions);
  861. }
  862. IGlobalStateController::~IGlobalStateController() = default;
  863. IApplicationCreator::IApplicationCreator() : ServiceFramework("IApplicationCreator") {
  864. // clang-format off
  865. static const FunctionInfo functions[] = {
  866. {0, nullptr, "CreateApplication"},
  867. {1, nullptr, "PopLaunchRequestedApplication"},
  868. {10, nullptr, "CreateSystemApplication"},
  869. {100, nullptr, "PopFloatingApplicationForDevelopment"},
  870. };
  871. // clang-format on
  872. RegisterHandlers(functions);
  873. }
  874. IApplicationCreator::~IApplicationCreator() = default;
  875. IProcessWindingController::IProcessWindingController()
  876. : ServiceFramework("IProcessWindingController") {
  877. // clang-format off
  878. static const FunctionInfo functions[] = {
  879. {0, nullptr, "GetLaunchReason"},
  880. {11, nullptr, "OpenCallingLibraryApplet"},
  881. {21, nullptr, "PushContext"},
  882. {22, nullptr, "PopContext"},
  883. {23, nullptr, "CancelWindingReservation"},
  884. {30, nullptr, "WindAndDoReserved"},
  885. {40, nullptr, "ReserveToStartAndWaitAndUnwindThis"},
  886. {41, nullptr, "ReserveToStartAndWait"},
  887. };
  888. // clang-format on
  889. RegisterHandlers(functions);
  890. }
  891. IProcessWindingController::~IProcessWindingController() = default;
  892. } // namespace Service::AM