am.cpp 40 KB

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