bug fix: get accountUid

Signed-off-by: y30033032 <yuanmeng36@huawei.com>
This commit is contained in:
y30033032 2024-09-14 17:48:22 +08:00
parent b8ecc06964
commit 0a943a8897
4 changed files with 46 additions and 1 deletions

View File

@ -26,6 +26,7 @@ int32_t GetOsAccountId(char *id, uint32_t idLen, uint32_t *len);
int32_t GetCurrentAccount(int64_t *account);
int32_t GetActiveOsAccountIds(void);
bool IsActiveOsAccountUnlocked(void);
int32_t GetOsAccountUid(char *id, uint32_t idLen, uint32_t *len);
#ifdef __cplusplus
}

View File

@ -26,6 +26,7 @@
static const int32_t ACCOUNT_STRTOLL_BASE = 10;
#define DEFAULT_ACCOUNT_NAME "ohosAnonymousName"
#define DEFAULT_ACCOUNT_UID "ohosAnonymousUid"
int32_t GetOsAccountId(char *id, uint32_t idLen, uint32_t *len)
{
@ -133,4 +134,39 @@ bool IsActiveOsAccountUnlocked(void)
}
LNN_LOGI(LNN_STATE, "account verified status=%{public}d, accountId=%{public}d", isUnlocked, osAccountId);
return isUnlocked;
}
int32_t GetOsAccountUid(char *id, uint32_t idLen, uint32_t *len)
{
if (id == nullptr || len == nullptr || idLen == 0) {
LNN_LOGE(LNN_STATE, "invalid parameter");
return SOFTBUS_INVALID_PARAM;
}
auto accountInfo = OHOS::AccountSA::OhosAccountKits::GetInstance().QueryOhosAccountInfo();
if (!accountInfo.first) {
LNN_LOGE(LNN_STATE, "QueryOhosAccountInfo failed");
return SOFTBUS_NETWORK_GET_ACCOUNT_INFO_FAILED;
}
if (accountInfo.second.uid_.empty()) {
LNN_LOGE(LNN_STATE, "accountInfo uid is empty");
return SOFTBUS_NETWORK_GET_ACCOUNT_INFO_FAILED;
}
*len = accountInfo.second.uid_.length();
char *anonyUid = nullptr;
Anonymize(accountInfo.second.uid_.c_str(), &anonyUid);
LNN_LOGI(LNN_STATE, "uid=%{public}s, len=%{public}d", AnonymizeWrapper(anonyUid), *len);
AnonymizeFree(anonyUid);
if (memcmp(DEFAULT_ACCOUNT_UID, accountInfo.second.uid_.c_str(), *len) == 0) {
LNN_LOGE(LNN_STATE, "not login account");
return SOFTBUS_NOT_LOGIN;
}
if (memcpy_s(id, idLen, accountInfo.second.uid_.c_str(), *len) != EOK) {
LNN_LOGE(LNN_STATE, "memcpy_s uid failed, idLen=%{public}d, len=%{public}d", idLen, *len);
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}

View File

@ -39,4 +39,12 @@ int32_t GetActiveOsAccountIds(void)
bool IsActiveOsAccountUnlocked(void)
{
return true;
}
int32_t GetOsAccountUid(char *id, uint32_t idLen, uint32_t *len)
{
(void)id;
(void)idLen;
(void)len;
return SOFTBUS_NOT_IMPLEMENT;
}

View File

@ -539,7 +539,7 @@ enum SoftBusErrNo {
SOFTBUS_NETWORK_WRITERAWDATA_FAILED,
SOFTBUS_NETWORK_PROXY_READINT_FAILED,
SOFTBUS_NETWORK_READRAWDATA_FAILED,
SOFTBUS_NETWORK_GET_ACCOUNT_INFO_FAILED,
/* errno begin: -((203 << 21) | (4 << 16) | (1 << 12) | 0x0FFF) */
SOFTBUS_LANE_ERR_BASE = SOFTBUS_SUB_ERRNO(LNN_SUB_MODULE_CODE, LNN_LANE_MODULE_CODE),
SOFTBUS_LANE_SELECT_FAIL,