From bbb1ff6574b2e4e13b3aec68c20e62c622845859 Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 11 Feb 2024 20:45:40 -0500 Subject: [PATCH] am: add IApplicationAccessor --- src/core/CMakeLists.txt | 2 + .../am/service/application_accessor.cpp | 138 ++++++++++++++++++ .../service/am/service/application_accessor.h | 40 +++++ 3 files changed, 180 insertions(+) create mode 100644 src/core/hle/service/am/service/application_accessor.cpp create mode 100644 src/core/hle/service/am/service/application_accessor.h diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 073e42e00..db27e0f3e 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -441,6 +441,8 @@ add_library(core STATIC hle/service/am/service/all_system_applet_proxies_service.h hle/service/am/service/applet_common_functions.cpp hle/service/am/service/applet_common_functions.h + hle/service/am/service/application_accessor.cpp + hle/service/am/service/application_accessor.h hle/service/am/service/application_functions.cpp hle/service/am/service/application_functions.h hle/service/am/service/application_proxy_service.cpp diff --git a/src/core/hle/service/am/service/application_accessor.cpp b/src/core/hle/service/am/service/application_accessor.cpp new file mode 100644 index 000000000..6e7d110e8 --- /dev/null +++ b/src/core/hle/service/am/service/application_accessor.cpp @@ -0,0 +1,138 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/hle/result.h" +#include "core/hle/service/am/am_types.h" +#include "core/hle/service/am/applet.h" +#include "core/hle/service/am/applet_data_broker.h" +#include "core/hle/service/am/applet_manager.h" +#include "core/hle/service/am/service/application_accessor.h" +#include "core/hle/service/am/service/library_applet_accessor.h" +#include "core/hle/service/am/service/storage.h" +#include "core/hle/service/cmif_serialization.h" + +namespace Service::AM { + +IApplicationAccessor::IApplicationAccessor(Core::System& system_, std::shared_ptr applet) + : ServiceFramework{system_, "IApplicationAccessor"}, m_applet(std::move(applet)) { + // clang-format off + static const FunctionInfo functions[] = { + {0, D<&IApplicationAccessor::GetAppletStateChangedEvent>, "GetAppletStateChangedEvent"}, + {1, nullptr, "IsCompleted"}, + {10, D<&IApplicationAccessor::Start>, "Start"}, + {20, D<&IApplicationAccessor::RequestExit>, "RequestExit"}, + {25, D<&IApplicationAccessor::Terminate>, "Terminate"}, + {30, D<&IApplicationAccessor::GetResult>, "GetResult"}, + {101, D<&IApplicationAccessor::RequestForApplicationToGetForeground>, "RequestForApplicationToGetForeground"}, + {110, nullptr, "TerminateAllLibraryApplets"}, + {111, nullptr, "AreAnyLibraryAppletsLeft"}, + {112, D<&IApplicationAccessor::GetCurrentLibraryApplet>, "GetCurrentLibraryApplet"}, + {120, nullptr, "GetApplicationId"}, + {121, D<&IApplicationAccessor::PushLaunchParameter>, "PushLaunchParameter"}, + {122, D<&IApplicationAccessor::GetApplicationControlProperty>, "GetApplicationControlProperty"}, + {123, nullptr, "GetApplicationLaunchProperty"}, + {124, nullptr, "GetApplicationLaunchRequestInfo"}, + {130, D<&IApplicationAccessor::SetUsers>, "SetUsers"}, + {131, D<&IApplicationAccessor::CheckRightsEnvironmentAvailable>, "CheckRightsEnvironmentAvailable"}, + {132, D<&IApplicationAccessor::GetNsRightsEnvironmentHandle>, "GetNsRightsEnvironmentHandle"}, + {140, nullptr, "GetDesirableUids"}, + {150, D<&IApplicationAccessor::ReportApplicationExitTimeout>, "ReportApplicationExitTimeout"}, + {160, nullptr, "SetApplicationAttribute"}, + {170, nullptr, "HasSaveDataAccessPermission"}, + {180, nullptr, "PushToFriendInvitationStorageChannel"}, + {190, nullptr, "PushToNotificationStorageChannel"}, + {200, nullptr, "RequestApplicationSoftReset"}, + {201, nullptr, "RestartApplicationTimer"}, + }; + // clang-format on + + RegisterHandlers(functions); +} + +IApplicationAccessor::~IApplicationAccessor() = default; + +Result IApplicationAccessor::Start() { + LOG_INFO(Service_AM, "called"); + m_applet->process->Run(); + R_SUCCEED(); +} + +Result IApplicationAccessor::RequestExit() { + LOG_INFO(Service_AM, "called"); + m_applet->message_queue.RequestExit(); + R_SUCCEED(); +} + +Result IApplicationAccessor::Terminate() { + LOG_INFO(Service_AM, "called"); + m_applet->process->Terminate(); + R_SUCCEED(); +} + +Result IApplicationAccessor::GetResult() { + LOG_INFO(Service_AM, "called"); + R_SUCCEED(); +} + +Result IApplicationAccessor::GetAppletStateChangedEvent( + OutCopyHandle out_event) { + LOG_INFO(Service_AM, "called"); + *out_event = m_applet->caller_applet_broker->GetStateChangedEvent().GetHandle(); + R_SUCCEED(); +} + +Result IApplicationAccessor::PushLaunchParameter(LaunchParameterKind kind, + SharedPointer storage) { + LOG_INFO(Service_AM, "called, kind={}", kind); + + switch (kind) { + case LaunchParameterKind::AccountPreselectedUser: + m_applet->preselected_user_launch_parameter.push_back(storage->GetData()); + R_SUCCEED(); + default: + R_THROW(ResultUnknown); + } +} + +Result IApplicationAccessor::GetApplicationControlProperty( + OutBuffer out_control_property) { + LOG_WARNING(Service_AM, "(STUBBED) called"); + R_THROW(ResultUnknown); +} + +Result IApplicationAccessor::SetUsers(bool enable, + InArray user_ids) { + LOG_INFO(Service_AM, "called, enable={} user_id_count={}", enable, user_ids.size()); + R_SUCCEED(); +} + +Result IApplicationAccessor::GetCurrentLibraryApplet( + Out> out_accessor) { + LOG_INFO(Service_AM, "(STUBBED) called"); + *out_accessor = nullptr; + R_SUCCEED(); +} + +Result IApplicationAccessor::RequestForApplicationToGetForeground() { + LOG_WARNING(Service_AM, "(STUBBED) called"); + R_THROW(ResultUnknown); +} + +Result IApplicationAccessor::CheckRightsEnvironmentAvailable(Out out_is_available) { + LOG_WARNING(Service_AM, "(STUBBED) called"); + *out_is_available = true; + R_SUCCEED(); +} + +Result IApplicationAccessor::GetNsRightsEnvironmentHandle(Out out_handle) { + LOG_WARNING(Service_AM, "(STUBBED) called"); + *out_handle = 0xdeadbeef; + R_SUCCEED(); +} + +Result IApplicationAccessor::ReportApplicationExitTimeout() { + LOG_ERROR(Service_AM, "called"); + R_SUCCEED(); +} + +} // namespace Service::AM diff --git a/src/core/hle/service/am/service/application_accessor.h b/src/core/hle/service/am/service/application_accessor.h new file mode 100644 index 000000000..39a9b2153 --- /dev/null +++ b/src/core/hle/service/am/service/application_accessor.h @@ -0,0 +1,40 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "common/uuid.h" +#include "core/hle/service/am/am_types.h" +#include "core/hle/service/cmif_types.h" +#include "core/hle/service/service.h" + +namespace Service::AM { + +struct Applet; +class ILibraryAppletAccessor; +class IStorage; + +class IApplicationAccessor final : public ServiceFramework { +public: + explicit IApplicationAccessor(Core::System& system_, std::shared_ptr applet); + ~IApplicationAccessor() override; + +private: + Result Start(); + Result RequestExit(); + Result Terminate(); + Result GetResult(); + Result GetAppletStateChangedEvent(OutCopyHandle out_event); + Result PushLaunchParameter(LaunchParameterKind kind, SharedPointer storage); + Result GetApplicationControlProperty(OutBuffer out_control_property); + Result SetUsers(bool enable, InArray user_ids); + Result GetCurrentLibraryApplet(Out> out_accessor); + Result RequestForApplicationToGetForeground(); + Result CheckRightsEnvironmentAvailable(Out out_is_available); + Result GetNsRightsEnvironmentHandle(Out out_handle); + Result ReportApplicationExitTimeout(); + + const std::shared_ptr m_applet; +}; + +} // namespace Service::AM