account: Services Refactoring (#1833)
* account: Services Refactoring * Remove extra empty space * Fix IProfile::Get * address gdkchan feedback
This commit is contained in:
parent
4f01c13f50
commit
b001040c2f
17 changed files with 844 additions and 317 deletions
|
@ -1,188 +1,106 @@
|
|||
using Ryujinx.Common;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Services.Account.Acc.AccountService;
|
||||
using Ryujinx.HLE.HOS.Services.Arp;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Account.Acc
|
||||
{
|
||||
[Service("acc:u0")]
|
||||
[Service("acc:u0", AccountServiceFlag.Application)] // Max Sessions: 4
|
||||
class IAccountServiceForApplication : IpcService
|
||||
{
|
||||
private bool _userRegistrationRequestPermitted = false;
|
||||
private ApplicationServiceServer _applicationServiceServer;
|
||||
|
||||
private ApplicationLaunchProperty _applicationLaunchProperty;
|
||||
|
||||
public IAccountServiceForApplication(ServiceCtx context) { }
|
||||
public IAccountServiceForApplication(ServiceCtx context, AccountServiceFlag serviceFlag)
|
||||
{
|
||||
_applicationServiceServer = new ApplicationServiceServer(serviceFlag);
|
||||
}
|
||||
|
||||
[Command(0)]
|
||||
// GetUserCount() -> i32
|
||||
public ResultCode GetUserCount(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(context.Device.System.State.Account.GetUserCount());
|
||||
|
||||
return ResultCode.Success;
|
||||
return _applicationServiceServer.GetUserCountImpl(context);
|
||||
}
|
||||
|
||||
[Command(1)]
|
||||
// GetUserExistence(nn::account::Uid) -> bool
|
||||
public ResultCode GetUserExistence(ServiceCtx context)
|
||||
{
|
||||
UserId userId = context.RequestData.ReadStruct<UserId>();
|
||||
|
||||
if (userId.IsNull)
|
||||
{
|
||||
return ResultCode.NullArgument;
|
||||
}
|
||||
|
||||
context.ResponseData.Write(context.Device.System.State.Account.TryGetUser(userId, out _));
|
||||
|
||||
return ResultCode.Success;
|
||||
return _applicationServiceServer.GetUserExistenceImpl(context);
|
||||
}
|
||||
|
||||
[Command(2)]
|
||||
// ListAllUsers() -> array<nn::account::Uid, 0xa>
|
||||
public ResultCode ListAllUsers(ServiceCtx context)
|
||||
{
|
||||
return WriteUserList(context, context.Device.System.State.Account.GetAllUsers());
|
||||
return _applicationServiceServer.ListAllUsers(context);
|
||||
}
|
||||
|
||||
[Command(3)]
|
||||
// ListOpenUsers() -> array<nn::account::Uid, 0xa>
|
||||
public ResultCode ListOpenUsers(ServiceCtx context)
|
||||
{
|
||||
return WriteUserList(context, context.Device.System.State.Account.GetOpenedUsers());
|
||||
}
|
||||
|
||||
private ResultCode WriteUserList(ServiceCtx context, IEnumerable<UserProfile> profiles)
|
||||
{
|
||||
if (context.Request.RecvListBuff.Count == 0)
|
||||
{
|
||||
return ResultCode.InvalidInputBuffer;
|
||||
}
|
||||
|
||||
long outputPosition = context.Request.RecvListBuff[0].Position;
|
||||
long outputSize = context.Request.RecvListBuff[0].Size;
|
||||
|
||||
MemoryHelper.FillWithZeros(context.Memory, outputPosition, (int)outputSize);
|
||||
|
||||
ulong offset = 0;
|
||||
|
||||
foreach (UserProfile userProfile in profiles)
|
||||
{
|
||||
if (offset + 0x10 > (ulong)outputSize)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
context.Memory.Write((ulong)outputPosition + offset, userProfile.UserId.High);
|
||||
context.Memory.Write((ulong)outputPosition + offset + 8, userProfile.UserId.Low);
|
||||
|
||||
offset += 0x10;
|
||||
}
|
||||
|
||||
return ResultCode.Success;
|
||||
return _applicationServiceServer.ListOpenUsers(context);
|
||||
}
|
||||
|
||||
[Command(4)]
|
||||
// GetLastOpenedUser() -> nn::account::Uid
|
||||
public ResultCode GetLastOpenedUser(ServiceCtx context)
|
||||
{
|
||||
context.Device.System.State.Account.LastOpenedUser.UserId.Write(context.ResponseData);
|
||||
|
||||
return ResultCode.Success;
|
||||
return _applicationServiceServer.GetLastOpenedUser(context);
|
||||
}
|
||||
|
||||
[Command(5)]
|
||||
// GetProfile(nn::account::Uid) -> object<nn::account::profile::IProfile>
|
||||
public ResultCode GetProfile(ServiceCtx context)
|
||||
{
|
||||
UserId userId = context.RequestData.ReadStruct<UserId>();
|
||||
ResultCode resultCode = _applicationServiceServer.GetProfile(context, out IProfile iProfile);
|
||||
|
||||
if (!context.Device.System.State.Account.TryGetUser(userId, out UserProfile userProfile))
|
||||
if (resultCode == ResultCode.Success)
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.ServiceAcc, $"User 0x{userId} not found!");
|
||||
|
||||
return ResultCode.UserNotFound;
|
||||
MakeObject(context, iProfile);
|
||||
}
|
||||
|
||||
MakeObject(context, new IProfile(userProfile));
|
||||
|
||||
// Doesn't occur in our case.
|
||||
// return ResultCode.NullObject;
|
||||
|
||||
return ResultCode.Success;
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
[Command(50)]
|
||||
// IsUserRegistrationRequestPermitted(u64, pid) -> bool
|
||||
// IsUserRegistrationRequestPermitted(pid) -> bool
|
||||
public ResultCode IsUserRegistrationRequestPermitted(ServiceCtx context)
|
||||
{
|
||||
// The u64 argument seems to be unused by account.
|
||||
context.ResponseData.Write(_userRegistrationRequestPermitted);
|
||||
|
||||
return ResultCode.Success;
|
||||
// NOTE: pid is unused.
|
||||
return _applicationServiceServer.IsUserRegistrationRequestPermitted(context);
|
||||
}
|
||||
|
||||
[Command(51)]
|
||||
// TrySelectUserWithoutInteraction(bool) -> nn::account::Uid
|
||||
public ResultCode TrySelectUserWithoutInteraction(ServiceCtx context)
|
||||
{
|
||||
if (context.Device.System.State.Account.GetUserCount() != 1)
|
||||
{
|
||||
// Invalid UserId.
|
||||
new UserId(0, 0).Write(context.ResponseData);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool baasCheck = context.RequestData.ReadBoolean();
|
||||
|
||||
if (baasCheck)
|
||||
{
|
||||
// This checks something related to baas (online), and then return an invalid UserId if the check in baas returns an error code.
|
||||
// In our case, we can just log it for now.
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { baasCheck });
|
||||
}
|
||||
|
||||
// As we returned an invalid UserId if there is more than one user earlier, now we can return only the first one.
|
||||
context.Device.System.State.Account.GetFirst().UserId.Write(context.ResponseData);
|
||||
|
||||
return ResultCode.Success;
|
||||
return _applicationServiceServer.TrySelectUserWithoutInteraction(context);
|
||||
}
|
||||
|
||||
[Command(100)]
|
||||
[Command(140)] // 6.0.0+
|
||||
// InitializeApplicationInfo(u64, pid)
|
||||
// Both calls (100, 140) use the same submethod, maybe there's something different further along when arp:r is called?
|
||||
// InitializeApplicationInfo(u64 pid_placeholder, pid)
|
||||
public ResultCode InitializeApplicationInfo(ServiceCtx context)
|
||||
{
|
||||
if (_applicationLaunchProperty != null)
|
||||
{
|
||||
return ResultCode.Unknown41;
|
||||
}
|
||||
// NOTE: In call 100, account service use the pid_placeholder instead of the real pid, which is wrong, call 140 fix that.
|
||||
|
||||
// The u64 argument seems to be unused by account.
|
||||
long unknown = context.RequestData.ReadInt64();
|
||||
/*
|
||||
|
||||
// TODO: Account actually calls nn::arp::detail::IReader::GetApplicationLaunchProperty() with the current PID and store the result (ApplicationLaunchProperty) internally.
|
||||
// For now we can hardcode values, and fix it after GetApplicationLaunchProperty is implemented.
|
||||
|
||||
/*
|
||||
if (nn::arp::detail::IReader::GetApplicationLaunchProperty() == 0xCC9D) // InvalidProcessId
|
||||
if (nn::arp::detail::IReader::GetApplicationLaunchProperty() == 0xCC9D) // ResultCode.InvalidProcessId
|
||||
{
|
||||
_applicationLaunchProperty = ApplicationLaunchProperty.Default;
|
||||
|
||||
return ResultCode.InvalidArgument;
|
||||
}
|
||||
else
|
||||
*/
|
||||
{
|
||||
_applicationLaunchProperty = ApplicationLaunchProperty.GetByPid(context);
|
||||
}
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { unknown });
|
||||
*/
|
||||
|
||||
// TODO: Determine where ApplicationLaunchProperty is used.
|
||||
ApplicationLaunchProperty applicationLaunchProperty = ApplicationLaunchProperty.GetByPid(context);
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { applicationLaunchProperty.TitleId });
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
@ -191,19 +109,14 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
|
|||
// GetBaasAccountManagerForApplication(nn::account::Uid) -> object<nn::account::baas::IManagerForApplication>
|
||||
public ResultCode GetBaasAccountManagerForApplication(ServiceCtx context)
|
||||
{
|
||||
UserId userId = context.RequestData.ReadStruct<UserId>();
|
||||
ResultCode resultCode = _applicationServiceServer.CheckUserId(context, out UserId userId);
|
||||
|
||||
if (userId.IsNull)
|
||||
if (resultCode != ResultCode.Success)
|
||||
{
|
||||
return ResultCode.NullArgument;
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
if (_applicationLaunchProperty == null)
|
||||
{
|
||||
return ResultCode.InvalidArgument;
|
||||
}
|
||||
|
||||
MakeObject(context, new IManagerForApplication(userId, _applicationLaunchProperty));
|
||||
MakeObject(context, new IManagerForApplication(userId));
|
||||
|
||||
// Doesn't occur in our case.
|
||||
// return ResultCode.NullObject;
|
||||
|
@ -215,63 +128,14 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
|
|||
// StoreSaveDataThumbnail(nn::account::Uid, buffer<bytes, 5>)
|
||||
public ResultCode StoreSaveDataThumbnail(ServiceCtx context)
|
||||
{
|
||||
if (_applicationLaunchProperty == null)
|
||||
{
|
||||
return ResultCode.InvalidArgument;
|
||||
}
|
||||
|
||||
UserId userId = context.RequestData.ReadStruct<UserId>();
|
||||
|
||||
if (userId.IsNull)
|
||||
{
|
||||
return ResultCode.NullArgument;
|
||||
}
|
||||
|
||||
if (context.Request.SendBuff.Count == 0)
|
||||
{
|
||||
return ResultCode.InvalidInputBuffer;
|
||||
}
|
||||
|
||||
long inputPosition = context.Request.SendBuff[0].Position;
|
||||
long inputSize = context.Request.SendBuff[0].Size;
|
||||
|
||||
if (inputSize != 0x24000)
|
||||
{
|
||||
return ResultCode.InvalidInputBufferSize;
|
||||
}
|
||||
|
||||
byte[] thumbnailBuffer = new byte[inputSize];
|
||||
|
||||
context.Memory.Read((ulong)inputPosition, thumbnailBuffer);
|
||||
|
||||
// TODO: Store thumbnailBuffer somewhere, in save data 0x8000000000000010 ?
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceAcc);
|
||||
|
||||
return ResultCode.Success;
|
||||
return _applicationServiceServer.StoreSaveDataThumbnail(context);
|
||||
}
|
||||
|
||||
[Command(111)]
|
||||
// ClearSaveDataThumbnail(nn::account::Uid)
|
||||
public ResultCode ClearSaveDataThumbnail(ServiceCtx context)
|
||||
{
|
||||
if (_applicationLaunchProperty == null)
|
||||
{
|
||||
return ResultCode.InvalidArgument;
|
||||
}
|
||||
|
||||
UserId userId = context.RequestData.ReadStruct<UserId>();
|
||||
|
||||
if (userId.IsNull)
|
||||
{
|
||||
return ResultCode.NullArgument;
|
||||
}
|
||||
|
||||
// TODO: Clear the Thumbnail somewhere, in save data 0x8000000000000010 ?
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceAcc);
|
||||
|
||||
return ResultCode.Success;
|
||||
return _applicationServiceServer.ClearSaveDataThumbnail(context);
|
||||
}
|
||||
|
||||
[Command(131)] // 6.0.0+
|
||||
|
@ -294,25 +158,15 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
|
|||
// ListQualifiedUsers() -> array<nn::account::Uid, 0xa>
|
||||
public ResultCode ListQualifiedUsers(ServiceCtx context)
|
||||
{
|
||||
// TODO: Determine how users are "qualified". We assume all users are "qualified" for now.
|
||||
|
||||
return WriteUserList(context, context.Device.System.State.Account.GetAllUsers());
|
||||
return _applicationServiceServer.ListQualifiedUsers(context);
|
||||
}
|
||||
|
||||
[Command(150)] // 6.0.0+
|
||||
// IsUserAccountSwitchLocked() -> bool
|
||||
public ResultCode IsUserAccountSwitchLocked(ServiceCtx context)
|
||||
{
|
||||
// TODO : Validate the following check.
|
||||
/*
|
||||
if (_applicationLaunchProperty != null)
|
||||
{
|
||||
return ResultCode.Unknown41;
|
||||
}
|
||||
*/
|
||||
|
||||
// Account actually calls nn::arp::detail::IReader::GetApplicationControlProperty() with the current PID and store the result (NACP File) internally.
|
||||
// But since we use LibHac and we load one Application at a time, it's not necessary.
|
||||
// TODO: Account actually calls nn::arp::detail::IReader::GetApplicationControlProperty() with the current Pid and store the result (NACP file) internally.
|
||||
// But since we use LibHac and we load one Application at a time, it's not necessary.
|
||||
|
||||
context.ResponseData.Write(context.Device.Application.ControlData.Value.UserAccountSwitchLock);
|
||||
|
||||
|
@ -321,4 +175,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
|
|||
return ResultCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue