Align code style with project

* Return correct error code for invalid user
* Always return first icon color
This commit is contained in:
Willi Ye 2020-07-20 22:16:11 +02:00 committed by ◱ PixelyIon
parent ffb9e743dd
commit 93da9f2826
6 changed files with 30 additions and 35 deletions

View File

@ -54,7 +54,6 @@ namespace skyline {
constexpr u32 MaxHandles = 0xEE01; //!< "Too many handles"
constexpr u32 NotFound = 0xF201; //!< "Not found"
constexpr u32 Unimpl = 0x177202; //!< "Unimplemented behaviour"
constexpr u32 InvArg = 0x2c7c; //!< "Argument is invalid"
}
};

View File

@ -2,8 +2,8 @@
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
#include "IManagerForApplication.h"
#include "IAccountServiceForApplication.h"
#include "IProfile.h"
#include "IAccountServiceForApplication.h"
namespace skyline::service::account {
IAccountServiceForApplication::IAccountServiceForApplication(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::account_IAccountServiceForApplication, "account:IAccountServiceForApplication", {
@ -29,7 +29,7 @@ namespace skyline::service::account {
void IAccountServiceForApplication::GetProfile(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
auto id = request.Pop<UserId>();
if (id != constant::DefaultUserId) {
response.errorCode = constant::status::InvArg;
response.errorCode = constant::InvUser;
return;
}

View File

@ -15,10 +15,6 @@ namespace skyline {
u64 upper; //!< The upper 64 bits of the user ID
u64 lower; //!< The lower 64 bits of the user ID
/**
* @param userId The user ID to compare with
* @return Whether this user ID matches the one given as a parameter
*/
inline constexpr bool operator==(const UserId &userId) {
return upper == userId.upper && lower == userId.lower;
}
@ -63,5 +59,7 @@ namespace skyline {
namespace constant {
constexpr service::account::UserId DefaultUserId = {0x0000000000000001, 0x0000000000000000}; //!< The default user ID
constexpr u32 InvUser = 0xC87C; //!< Invalid user
}
}

View File

@ -5,20 +5,33 @@
#include "IProfile.h"
namespace skyline::service::account {
IProfile::IProfile(const DeviceState &state, ServiceManager &manager, const UserId &userId) : BaseService(state, manager, Service::account_IProfile, "account:IProfile", {
IProfile::IProfile(const DeviceState &state, ServiceManager &manager, const UserId &userId) : userId(userId), BaseService(state, manager, Service::account_IProfile, "account:IProfile", {
{0x0, SFUNC(IProfile::Get)}
}) {}
void IProfile::Get(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
AccountUserData userData{};
AccountProfileBase profileBase{};
struct AccountUserData {
u32 _unk0_; //!< Unknown.
u32 iconID; //!< Icon ID (0 = Mii, the rest are character icon IDs).
u8 iconBackgroundColorID; //!< Profile icon background color ID
std::array<u8, 0x7> _unk1_; //!< Unknown.
std::array<u8, 0x10> miiID; //!< Some ID related to the Mii? All zeros when a character icon is used.
std::array<u8, 0x60> _unk2_; //!< Unknown.
};
struct {
UserId uid; //!< The UID of the corresponding account
u64 lastEditTimestamp; //!< A POSIX UTC timestamp denoting the last account edit.
std::array<char, 0x20> nickname; //!< UTF-8 Nickname.
} accountProfileBase = {.uid = userId};
std::string username = state.settings->GetString("username_value");
size_t usernameSize = std::min(sizeof(profileBase), username.size());
std::memcpy(profileBase.nickname, username.c_str(), usernameSize);
profileBase.nickname[usernameSize] = '\0';
size_t usernameSize = std::min(accountProfileBase.nickname.size(), username.size());
std::memcpy(accountProfileBase.nickname.data(), username.c_str(), usernameSize);
state.process->WriteMemory(userData, request.outputBuf.at(0).address);
response.Push(profileBase);
AccountUserData *userData = state.process->GetPointer<AccountUserData>(request.outputBuf.at(0).address);
userData->iconBackgroundColorID = 0x1; // Color indexing starts at 0x1
response.Push(accountProfileBase);
}
}

View File

@ -8,23 +8,6 @@
namespace skyline::service::account {
/// UserData
typedef struct {
u32 unk_x0; ///< Unknown.
u32 iconID; ///< Icon ID. 0 = Mii, the rest are character icon IDs.
u8 iconBackgroundColorID; ///< Profile icon background color ID
u8 unk_x9[0x7]; ///< Unknown.
u8 miiID[0x10]; ///< Some ID related to the Mii? All zeros when a character icon is used.
u8 unk_x20[0x60]; ///< Usually zeros?
} AccountUserData;
/// ProfileBase
typedef struct {
UserId uid; ///< \ref AccountUid
u64 lastEditTimestamp; ///< POSIX UTC timestamp, for the last account edit.
char nickname[0x20]; ///< UTF-8 Nickname.
} AccountProfileBase;
/**
* @brief IProfile provides functions for reading user profile (https://switchbrew.org/wiki/Account_services#IProfile)
*/
@ -33,8 +16,11 @@ namespace skyline::service::account {
IProfile(const DeviceState &state, ServiceManager &manager, const UserId &userId);
private:
UserId userId;
/**
* @brief This returns AccountUserData (optional) and AccountProfileBase
* @brief This returns AccountUserData and AccountProfileBase objects that describe the user's information
*/
void Get(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response);
};

View File

@ -13,8 +13,7 @@ import androidx.preference.EditTextPreference
import emu.skyline.R
/**
* [EditTextPreference] lacks the feature to set the automatically value as summary.
* This class adds this missing thing. Also added useful attributes.
* This class adapts [EditTextPreference] so that it supports setting the value as the summary automatically. Also added useful attributes.
*/
class CustomEditTextPreference : EditTextPreference {