IApplicationFunctions.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. using LibHac;
  2. using LibHac.Account;
  3. using LibHac.Common;
  4. using LibHac.Fs;
  5. using LibHac.Ns;
  6. using Ryujinx.Common;
  7. using Ryujinx.Common.Logging;
  8. using Ryujinx.HLE.HOS.Ipc;
  9. using Ryujinx.HLE.HOS.Kernel.Common;
  10. using Ryujinx.HLE.HOS.Kernel.Memory;
  11. using Ryujinx.HLE.HOS.Kernel.Threading;
  12. using Ryujinx.HLE.HOS.Services.Am.AppletAE.Storage;
  13. using Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.ApplicationProxy.Types;
  14. using Ryujinx.HLE.HOS.Services.Sdb.Pdm.QueryService;
  15. using Ryujinx.HLE.HOS.SystemState;
  16. using System;
  17. using System.Numerics;
  18. using static LibHac.Fs.ApplicationSaveDataManagement;
  19. using AccountUid = Ryujinx.HLE.HOS.Services.Account.Acc.UserId;
  20. using ApplicationId = LibHac.Ncm.ApplicationId;
  21. namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.ApplicationProxy
  22. {
  23. class IApplicationFunctions : IpcService
  24. {
  25. private ulong _defaultSaveDataSize = 200000000;
  26. private ulong _defaultJournalSaveDataSize = 200000000;
  27. private KEvent _gpuErrorDetectedSystemEvent;
  28. private KEvent _friendInvitationStorageChannelEvent;
  29. private KEvent _notificationStorageChannelEvent;
  30. private KEvent _healthWarningDisappearedSystemEvent;
  31. private int _gpuErrorDetectedSystemEventHandle;
  32. private int _friendInvitationStorageChannelEventHandle;
  33. private int _notificationStorageChannelEventHandle;
  34. private int _healthWarningDisappearedSystemEventHandle;
  35. public IApplicationFunctions(Horizon system)
  36. {
  37. // TODO: Find where they are signaled.
  38. _gpuErrorDetectedSystemEvent = new KEvent(system.KernelContext);
  39. _friendInvitationStorageChannelEvent = new KEvent(system.KernelContext);
  40. _notificationStorageChannelEvent = new KEvent(system.KernelContext);
  41. _healthWarningDisappearedSystemEvent = new KEvent(system.KernelContext);
  42. }
  43. [CommandHipc(1)]
  44. // PopLaunchParameter(LaunchParameterKind kind) -> object<nn::am::service::IStorage>
  45. public ResultCode PopLaunchParameter(ServiceCtx context)
  46. {
  47. LaunchParameterKind kind = (LaunchParameterKind)context.RequestData.ReadUInt32();
  48. byte[] storageData;
  49. switch (kind)
  50. {
  51. case LaunchParameterKind.UserChannel:
  52. storageData = context.Device.Configuration.UserChannelPersistence.Pop();
  53. break;
  54. case LaunchParameterKind.PreselectedUser:
  55. // Only the first 0x18 bytes of the Data seems to be actually used.
  56. storageData = StorageHelper.MakeLaunchParams(context.Device.System.AccountManager.LastOpenedUser);
  57. break;
  58. case LaunchParameterKind.Unknown:
  59. throw new NotImplementedException("Unknown LaunchParameterKind.");
  60. default:
  61. return ResultCode.ObjectInvalid;
  62. }
  63. if (storageData == null)
  64. {
  65. return ResultCode.NotAvailable;
  66. }
  67. MakeObject(context, new AppletAE.IStorage(storageData));
  68. return ResultCode.Success;
  69. }
  70. [CommandHipc(12)] // 4.0.0+
  71. // CreateApplicationAndRequestToStart(u64 title_id)
  72. public ResultCode CreateApplicationAndRequestToStart(ServiceCtx context)
  73. {
  74. ulong titleId = context.RequestData.ReadUInt64();
  75. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { titleId });
  76. if (titleId == 0)
  77. {
  78. context.Device.UiHandler.ExecuteProgram(context.Device, ProgramSpecifyKind.RestartProgram, titleId);
  79. }
  80. else
  81. {
  82. throw new NotImplementedException();
  83. }
  84. return ResultCode.Success;
  85. }
  86. [CommandHipc(20)]
  87. // EnsureSaveData(nn::account::Uid) -> u64
  88. public ResultCode EnsureSaveData(ServiceCtx context)
  89. {
  90. Uid userId = context.RequestData.ReadStruct<AccountUid>().ToLibHacUid();
  91. ApplicationId applicationId = new ApplicationId(context.Process.TitleId);
  92. BlitStruct<ApplicationControlProperty> controlHolder = context.Device.Application.ControlData;
  93. ref ApplicationControlProperty control = ref controlHolder.Value;
  94. if (LibHac.Utilities.IsEmpty(controlHolder.ByteSpan))
  95. {
  96. // If the current application doesn't have a loaded control property, create a dummy one
  97. // and set the savedata sizes so a user savedata will be created.
  98. control = ref new BlitStruct<ApplicationControlProperty>(1).Value;
  99. // The set sizes don't actually matter as long as they're non-zero because we use directory savedata.
  100. control.UserAccountSaveDataSize = 0x4000;
  101. control.UserAccountSaveDataJournalSize = 0x4000;
  102. Logger.Warning?.Print(LogClass.ServiceAm,
  103. "No control file was found for this game. Using a dummy one instead. This may cause inaccuracies in some games.");
  104. }
  105. Result result = EnsureApplicationSaveData(context.Device.FileSystem.FsClient, out long requiredSize, applicationId, ref control, ref userId);
  106. context.ResponseData.Write(requiredSize);
  107. return (ResultCode)result.Value;
  108. }
  109. [CommandHipc(21)]
  110. // GetDesiredLanguage() -> nn::settings::LanguageCode
  111. public ResultCode GetDesiredLanguage(ServiceCtx context)
  112. {
  113. // This seems to be calling ns:am GetApplicationDesiredLanguage followed by ConvertApplicationLanguageToLanguageCode
  114. // Calls are from a IReadOnlyApplicationControlDataInterface object
  115. // ConvertApplicationLanguageToLanguageCode compares language code strings and returns the index
  116. // TODO: When above calls are implemented, switch to using ns:am
  117. long desiredLanguageCode = context.Device.System.State.DesiredLanguageCode;
  118. int supportedLanguages = (int)context.Device.Application.ControlData.Value.SupportedLanguages;
  119. int firstSupported = BitOperations.TrailingZeroCount(supportedLanguages);
  120. if (firstSupported > (int)SystemState.TitleLanguage.Chinese)
  121. {
  122. Logger.Warning?.Print(LogClass.ServiceAm, "Application has zero supported languages");
  123. context.ResponseData.Write(desiredLanguageCode);
  124. return ResultCode.Success;
  125. }
  126. // If desired language is not supported by application, use first supported language from TitleLanguage.
  127. // TODO: In the future, a GUI could enable user-specified search priority
  128. if (((1 << (int)context.Device.System.State.DesiredTitleLanguage) & supportedLanguages) == 0)
  129. {
  130. SystemLanguage newLanguage = Enum.Parse<SystemLanguage>(Enum.GetName(typeof(SystemState.TitleLanguage), firstSupported));
  131. desiredLanguageCode = SystemStateMgr.GetLanguageCode((int)newLanguage);
  132. Logger.Info?.Print(LogClass.ServiceAm, $"Application doesn't support configured language. Using {newLanguage}");
  133. }
  134. context.ResponseData.Write(desiredLanguageCode);
  135. return ResultCode.Success;
  136. }
  137. [CommandHipc(22)]
  138. // SetTerminateResult(u32)
  139. public ResultCode SetTerminateResult(ServiceCtx context)
  140. {
  141. Result result = new Result(context.RequestData.ReadUInt32());
  142. Logger.Info?.Print(LogClass.ServiceAm, $"Result = 0x{result.Value:x8} ({result.ToStringWithName()}).");
  143. return ResultCode.Success;
  144. }
  145. [CommandHipc(23)]
  146. // GetDisplayVersion() -> nn::oe::DisplayVersion
  147. public ResultCode GetDisplayVersion(ServiceCtx context)
  148. {
  149. // This should work as DisplayVersion U8Span always gives a 0x10 size byte array.
  150. // If an NACP isn't found, the buffer will be all '\0' which seems to be the correct implementation.
  151. context.ResponseData.Write(context.Device.Application.ControlData.Value.DisplayVersion);
  152. return ResultCode.Success;
  153. }
  154. [CommandHipc(25)] // 3.0.0+
  155. // ExtendSaveData(u8 save_data_type, nn::account::Uid, u64 save_size, u64 journal_size) -> u64 result_code
  156. public ResultCode ExtendSaveData(ServiceCtx context)
  157. {
  158. SaveDataType saveDataType = (SaveDataType)context.RequestData.ReadUInt64();
  159. Uid userId = context.RequestData.ReadStruct<AccountUid>().ToLibHacUid();
  160. ulong saveDataSize = context.RequestData.ReadUInt64();
  161. ulong journalSize = context.RequestData.ReadUInt64();
  162. // NOTE: Service calls nn::fs::ExtendApplicationSaveData.
  163. // Since LibHac currently doesn't support this method, we can stub it for now.
  164. _defaultSaveDataSize = saveDataSize;
  165. _defaultJournalSaveDataSize = journalSize;
  166. context.ResponseData.Write((uint)ResultCode.Success);
  167. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { saveDataType, userId, saveDataSize, journalSize });
  168. return ResultCode.Success;
  169. }
  170. [CommandHipc(26)] // 3.0.0+
  171. // GetSaveDataSize(u8 save_data_type, nn::account::Uid) -> (u64 save_size, u64 journal_size)
  172. public ResultCode GetSaveDataSize(ServiceCtx context)
  173. {
  174. SaveDataType saveDataType = (SaveDataType)context.RequestData.ReadUInt64();
  175. Uid userId = context.RequestData.ReadStruct<AccountUid>().ToLibHacUid();
  176. // NOTE: Service calls nn::fs::FindSaveDataWithFilter with SaveDataType = 1 hardcoded.
  177. // Then it calls nn::fs::GetSaveDataAvailableSize and nn::fs::GetSaveDataJournalSize to get the sizes.
  178. // Since LibHac currently doesn't support the 2 last methods, we can hardcode the values to 200mb.
  179. context.ResponseData.Write(_defaultSaveDataSize);
  180. context.ResponseData.Write(_defaultJournalSaveDataSize);
  181. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { saveDataType, userId });
  182. return ResultCode.Success;
  183. }
  184. [CommandHipc(30)]
  185. // BeginBlockingHomeButtonShortAndLongPressed()
  186. public ResultCode BeginBlockingHomeButtonShortAndLongPressed(ServiceCtx context)
  187. {
  188. // NOTE: This set two internal fields at offsets 0x89 and 0x8B to value 1 then it signals an internal event.
  189. Logger.Stub?.PrintStub(LogClass.ServiceAm);
  190. return ResultCode.Success;
  191. }
  192. [CommandHipc(31)]
  193. // EndBlockingHomeButtonShortAndLongPressed()
  194. public ResultCode EndBlockingHomeButtonShortAndLongPressed(ServiceCtx context)
  195. {
  196. // NOTE: This set two internal fields at offsets 0x89 and 0x8B to value 0 then it signals an internal event.
  197. Logger.Stub?.PrintStub(LogClass.ServiceAm);
  198. return ResultCode.Success;
  199. }
  200. [CommandHipc(32)] // 2.0.0+
  201. // BeginBlockingHomeButton(u64 nano_second)
  202. public ResultCode BeginBlockingHomeButton(ServiceCtx context)
  203. {
  204. ulong nanoSeconds = context.RequestData.ReadUInt64();
  205. // NOTE: This set two internal fields at offsets 0x89 to value 1 and 0x90 to value of "nanoSeconds" then it signals an internal event.
  206. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { nanoSeconds });
  207. return ResultCode.Success;
  208. }
  209. [CommandHipc(33)] // 2.0.0+
  210. // EndBlockingHomeButton()
  211. public ResultCode EndBlockingHomeButton(ServiceCtx context)
  212. {
  213. // NOTE: This set two internal fields at offsets 0x89 and 0x90 to value 0 then it signals an internal event.
  214. Logger.Stub?.PrintStub(LogClass.ServiceAm);
  215. return ResultCode.Success;
  216. }
  217. [CommandHipc(40)]
  218. // NotifyRunning() -> b8
  219. public ResultCode NotifyRunning(ServiceCtx context)
  220. {
  221. context.ResponseData.Write(true);
  222. return ResultCode.Success;
  223. }
  224. [CommandHipc(50)] // 2.0.0+
  225. // GetPseudoDeviceId() -> nn::util::Uuid
  226. public ResultCode GetPseudoDeviceId(ServiceCtx context)
  227. {
  228. context.ResponseData.Write(0L);
  229. context.ResponseData.Write(0L);
  230. Logger.Stub?.PrintStub(LogClass.ServiceAm);
  231. return ResultCode.Success;
  232. }
  233. [CommandHipc(66)] // 3.0.0+
  234. // InitializeGamePlayRecording(u64, handle<copy>)
  235. public ResultCode InitializeGamePlayRecording(ServiceCtx context)
  236. {
  237. Logger.Stub?.PrintStub(LogClass.ServiceAm);
  238. return ResultCode.Success;
  239. }
  240. [CommandHipc(67)] // 3.0.0+
  241. // SetGamePlayRecordingState(u32)
  242. public ResultCode SetGamePlayRecordingState(ServiceCtx context)
  243. {
  244. int state = context.RequestData.ReadInt32();
  245. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { state });
  246. return ResultCode.Success;
  247. }
  248. [CommandHipc(90)] // 4.0.0+
  249. // EnableApplicationCrashReport(u8)
  250. public ResultCode EnableApplicationCrashReport(ServiceCtx context)
  251. {
  252. bool applicationCrashReportEnabled = context.RequestData.ReadBoolean();
  253. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { applicationCrashReportEnabled });
  254. return ResultCode.Success;
  255. }
  256. [CommandHipc(100)] // 5.0.0+
  257. // InitializeApplicationCopyrightFrameBuffer(s32 width, s32 height, handle<copy, transfer_memory> transfer_memory, u64 transfer_memory_size)
  258. public ResultCode InitializeApplicationCopyrightFrameBuffer(ServiceCtx context)
  259. {
  260. int width = context.RequestData.ReadInt32();
  261. int height = context.RequestData.ReadInt32();
  262. ulong transferMemorySize = context.RequestData.ReadUInt64();
  263. int transferMemoryHandle = context.Request.HandleDesc.ToCopy[0];
  264. ulong transferMemoryAddress = context.Process.HandleTable.GetObject<KTransferMemory>(transferMemoryHandle).Address;
  265. ResultCode resultCode = ResultCode.InvalidParameters;
  266. if (((transferMemorySize & 0x3FFFF) == 0) && width <= 1280 && height <= 720)
  267. {
  268. resultCode = InitializeApplicationCopyrightFrameBufferImpl(transferMemoryAddress, transferMemorySize, width, height);
  269. }
  270. if (transferMemoryHandle != 0)
  271. {
  272. context.Device.System.KernelContext.Syscall.CloseHandle(transferMemoryHandle);
  273. }
  274. return resultCode;
  275. }
  276. private ResultCode InitializeApplicationCopyrightFrameBufferImpl(ulong transferMemoryAddress, ulong transferMemorySize, int width, int height)
  277. {
  278. if ((transferMemorySize & 0x3FFFF) != 0)
  279. {
  280. return ResultCode.InvalidParameters;
  281. }
  282. ResultCode resultCode;
  283. // if (_copyrightBuffer == null)
  284. {
  285. // TODO: Initialize buffer and object.
  286. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { transferMemoryAddress, transferMemorySize, width, height });
  287. resultCode = ResultCode.Success;
  288. }
  289. return resultCode;
  290. }
  291. [CommandHipc(101)] // 5.0.0+
  292. // SetApplicationCopyrightImage(buffer<bytes, 0x45> frame_buffer, s32 x, s32 y, s32 width, s32 height, s32 window_origin_mode)
  293. public ResultCode SetApplicationCopyrightImage(ServiceCtx context)
  294. {
  295. ulong frameBufferPos = context.Request.SendBuff[0].Position;
  296. ulong frameBufferSize = context.Request.SendBuff[0].Size;
  297. int x = context.RequestData.ReadInt32();
  298. int y = context.RequestData.ReadInt32();
  299. int width = context.RequestData.ReadInt32();
  300. int height = context.RequestData.ReadInt32();
  301. uint windowOriginMode = context.RequestData.ReadUInt32();
  302. ResultCode resultCode = ResultCode.InvalidParameters;
  303. if (((y | x) >= 0) && width >= 1 && height >= 1)
  304. {
  305. ResultCode result = SetApplicationCopyrightImageImpl(x, y, width, height, frameBufferPos, frameBufferSize, windowOriginMode);
  306. if (result != ResultCode.Success)
  307. {
  308. resultCode = result;
  309. }
  310. else
  311. {
  312. resultCode = ResultCode.Success;
  313. }
  314. }
  315. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { frameBufferPos, frameBufferSize, x, y, width, height, windowOriginMode });
  316. return resultCode;
  317. }
  318. private ResultCode SetApplicationCopyrightImageImpl(int x, int y, int width, int height, ulong frameBufferPos, ulong frameBufferSize, uint windowOriginMode)
  319. {
  320. /*
  321. if (_copyrightBuffer == null)
  322. {
  323. return ResultCode.NullCopyrightObject;
  324. }
  325. */
  326. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { x, y, width, height, frameBufferPos, frameBufferSize, windowOriginMode });
  327. return ResultCode.Success;
  328. }
  329. [CommandHipc(102)] // 5.0.0+
  330. // SetApplicationCopyrightVisibility(bool visible)
  331. public ResultCode SetApplicationCopyrightVisibility(ServiceCtx context)
  332. {
  333. bool visible = context.RequestData.ReadBoolean();
  334. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { visible });
  335. // NOTE: It sets an internal field and return ResultCode.Success in all case.
  336. return ResultCode.Success;
  337. }
  338. [CommandHipc(110)] // 5.0.0+
  339. // QueryApplicationPlayStatistics(buffer<bytes, 5> title_id_list) -> (buffer<bytes, 6> entries, s32 entries_count)
  340. public ResultCode QueryApplicationPlayStatistics(ServiceCtx context)
  341. {
  342. // TODO: Call pdm:qry cmd 13 when IPC call between services will be implemented.
  343. return (ResultCode)QueryPlayStatisticsManager.GetPlayStatistics(context);
  344. }
  345. [CommandHipc(111)] // 6.0.0+
  346. // QueryApplicationPlayStatisticsByUid(nn::account::Uid, buffer<bytes, 5> title_id_list) -> (buffer<bytes, 6> entries, s32 entries_count)
  347. public ResultCode QueryApplicationPlayStatisticsByUid(ServiceCtx context)
  348. {
  349. // TODO: Call pdm:qry cmd 16 when IPC call between services will be implemented.
  350. return (ResultCode)QueryPlayStatisticsManager.GetPlayStatistics(context, true);
  351. }
  352. [CommandHipc(120)] // 5.0.0+
  353. // ExecuteProgram(ProgramSpecifyKind kind, u64 value)
  354. public ResultCode ExecuteProgram(ServiceCtx context)
  355. {
  356. ProgramSpecifyKind kind = (ProgramSpecifyKind)context.RequestData.ReadUInt32();
  357. // padding
  358. context.RequestData.ReadUInt32();
  359. ulong value = context.RequestData.ReadUInt64();
  360. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { kind, value });
  361. context.Device.UiHandler.ExecuteProgram(context.Device, kind, value);
  362. return ResultCode.Success;
  363. }
  364. [CommandHipc(121)] // 5.0.0+
  365. // ClearUserChannel()
  366. public ResultCode ClearUserChannel(ServiceCtx context)
  367. {
  368. context.Device.Configuration.UserChannelPersistence.Clear();
  369. return ResultCode.Success;
  370. }
  371. [CommandHipc(122)] // 5.0.0+
  372. // UnpopToUserChannel(object<nn::am::service::IStorage> input_storage)
  373. public ResultCode UnpopToUserChannel(ServiceCtx context)
  374. {
  375. AppletAE.IStorage data = GetObject<AppletAE.IStorage>(context, 0);
  376. context.Device.Configuration.UserChannelPersistence.Push(data.Data);
  377. return ResultCode.Success;
  378. }
  379. [CommandHipc(123)] // 5.0.0+
  380. // GetPreviousProgramIndex() -> s32 program_index
  381. public ResultCode GetPreviousProgramIndex(ServiceCtx context)
  382. {
  383. int previousProgramIndex = context.Device.Configuration.UserChannelPersistence.PreviousIndex;
  384. context.ResponseData.Write(previousProgramIndex);
  385. Logger.Stub?.PrintStub(LogClass.ServiceAm, new { previousProgramIndex });
  386. return ResultCode.Success;
  387. }
  388. [CommandHipc(130)] // 8.0.0+
  389. // GetGpuErrorDetectedSystemEvent() -> handle<copy>
  390. public ResultCode GetGpuErrorDetectedSystemEvent(ServiceCtx context)
  391. {
  392. if (_gpuErrorDetectedSystemEventHandle == 0)
  393. {
  394. if (context.Process.HandleTable.GenerateHandle(_gpuErrorDetectedSystemEvent.ReadableEvent, out _gpuErrorDetectedSystemEventHandle) != KernelResult.Success)
  395. {
  396. throw new InvalidOperationException("Out of handles!");
  397. }
  398. }
  399. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_gpuErrorDetectedSystemEventHandle);
  400. // NOTE: This is used by "sdk" NSO during applet-application initialization.
  401. // A seperate thread is setup where event-waiting is handled.
  402. // When the Event is signaled, official sw will assert.
  403. return ResultCode.Success;
  404. }
  405. [CommandHipc(140)] // 9.0.0+
  406. // GetFriendInvitationStorageChannelEvent() -> handle<copy>
  407. public ResultCode GetFriendInvitationStorageChannelEvent(ServiceCtx context)
  408. {
  409. if (_friendInvitationStorageChannelEventHandle == 0)
  410. {
  411. if (context.Process.HandleTable.GenerateHandle(_friendInvitationStorageChannelEvent.ReadableEvent, out _friendInvitationStorageChannelEventHandle) != KernelResult.Success)
  412. {
  413. throw new InvalidOperationException("Out of handles!");
  414. }
  415. }
  416. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_friendInvitationStorageChannelEventHandle);
  417. return ResultCode.Success;
  418. }
  419. [CommandHipc(141)] // 9.0.0+
  420. // TryPopFromFriendInvitationStorageChannel() -> object<nn::am::service::IStorage>
  421. public ResultCode TryPopFromFriendInvitationStorageChannel(ServiceCtx context)
  422. {
  423. // NOTE: IStorage are pushed in the channel with IApplicationAccessor PushToFriendInvitationStorageChannel
  424. // If _friendInvitationStorageChannelEvent is signaled, the event is cleared.
  425. // If an IStorage is available, returns it with ResultCode.Success.
  426. // If not, just returns ResultCode.NotAvailable. Since we don't support friend feature for now, it's fine to do the same.
  427. Logger.Stub?.PrintStub(LogClass.ServiceAm);
  428. return ResultCode.NotAvailable;
  429. }
  430. [CommandHipc(150)] // 9.0.0+
  431. // GetNotificationStorageChannelEvent() -> handle<copy>
  432. public ResultCode GetNotificationStorageChannelEvent(ServiceCtx context)
  433. {
  434. if (_notificationStorageChannelEventHandle == 0)
  435. {
  436. if (context.Process.HandleTable.GenerateHandle(_notificationStorageChannelEvent.ReadableEvent, out _notificationStorageChannelEventHandle) != KernelResult.Success)
  437. {
  438. throw new InvalidOperationException("Out of handles!");
  439. }
  440. }
  441. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_notificationStorageChannelEventHandle);
  442. return ResultCode.Success;
  443. }
  444. [CommandHipc(160)] // 9.0.0+
  445. // GetHealthWarningDisappearedSystemEvent() -> handle<copy>
  446. public ResultCode GetHealthWarningDisappearedSystemEvent(ServiceCtx context)
  447. {
  448. if (_healthWarningDisappearedSystemEventHandle == 0)
  449. {
  450. if (context.Process.HandleTable.GenerateHandle(_healthWarningDisappearedSystemEvent.ReadableEvent, out _healthWarningDisappearedSystemEventHandle) != KernelResult.Success)
  451. {
  452. throw new InvalidOperationException("Out of handles!");
  453. }
  454. }
  455. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_healthWarningDisappearedSystemEventHandle);
  456. return ResultCode.Success;
  457. }
  458. }
  459. }