!782 完善获取用户id逻辑,user0使用当前用户空间获取用户id

Merge pull request !782 from 侯志雄/master
This commit is contained in:
openharmony_ci 2024-11-19 11:41:09 +00:00 committed by Gitee
commit ed7f6eaab7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 36 additions and 6 deletions

View File

@ -181,8 +181,13 @@ napi_value napi_get_uri_sync(napi_env env, napi_callback_info info)
int currentUserId = -1;
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(currentUserId);
std::string tmpIdStr = "100";
if (currentUserId >= 0) {
if (currentUserId > 0) {
tmpIdStr = std::to_string(currentUserId);
SETTING_LOG_INFO("userId is %{public}s", tmpIdStr.c_str());
} else if (currentUserId == 0) {
OHOS::AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(currentUserId);
tmpIdStr = std::to_string(currentUserId);
SETTING_LOG_INFO("user0 userId is %{public}s", tmpIdStr.c_str());
} else {
SETTING_LOG_ERROR("userid is invalid, use id 100 instead");
}
@ -263,8 +268,13 @@ napi_value napi_get_uri(napi_env env, napi_callback_info info)
int currentUserId = -1;
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(currentUserId);
std::string tmpIdStr = "100";
if (currentUserId >= 0) {
if (currentUserId > 0) {
tmpIdStr = std::to_string(currentUserId);
SETTING_LOG_INFO("userId is %{public}s", tmpIdStr.c_str());
} else if (currentUserId == 0) {
OHOS::AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(currentUserId);
tmpIdStr = std::to_string(currentUserId);
SETTING_LOG_INFO("user0 userId is %{public}s", tmpIdStr.c_str());
} else {
SETTING_LOG_ERROR("userid is invalid, use id 100 instead");
}
@ -416,8 +426,13 @@ std::shared_ptr<DataShareHelper> getDataShareHelper(
int currentUserId = -1;
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(currentUserId);
std::string tmpIdStr = "100";
if (currentUserId >= 0) {
if (currentUserId > 0) {
tmpIdStr = std::to_string(currentUserId);
SETTING_LOG_INFO("userId is %{public}s", tmpIdStr.c_str());
} else if (currentUserId == 0) {
OHOS::AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(currentUserId);
tmpIdStr = std::to_string(currentUserId);
SETTING_LOG_INFO("user0 userId is %{public}s", tmpIdStr.c_str());
} else {
SETTING_LOG_ERROR("userid is invalid, use id 100 instead");
}
@ -501,8 +516,13 @@ void GetValueExecuteExt(napi_env env, void *data)
int currentUserId = -1;
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(currentUserId);
std::string tmpIdStr = "100";
if (currentUserId >= 0) {
if (currentUserId > 0) {
tmpIdStr = std::to_string(currentUserId);
SETTING_LOG_INFO("userId is %{public}s", tmpIdStr.c_str());
} else if (currentUserId == 0) {
OHOS::AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(currentUserId);
tmpIdStr = std::to_string(currentUserId);
SETTING_LOG_INFO("user0 userId is %{public}s", tmpIdStr.c_str());
} else {
SETTING_LOG_ERROR("userid is invalid, use id 100 instead");
}
@ -582,8 +602,13 @@ void SetValueExecuteExt(napi_env env, void *data, const std::string setValue)
int currentUserId = -1;
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(currentUserId);
std::string tmpIdStr = "100";
if (currentUserId >= 0) {
if (currentUserId > 0) {
tmpIdStr = std::to_string(currentUserId);
SETTING_LOG_INFO("userId is %{public}s", tmpIdStr.c_str());
} else if (currentUserId == 0) {
OHOS::AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(currentUserId);
tmpIdStr = std::to_string(currentUserId);
SETTING_LOG_INFO("user0 userId is %{public}s", tmpIdStr.c_str());
} else {
SETTING_LOG_ERROR("userid is invalid, use id 100 instead");
}

View File

@ -130,8 +130,13 @@ namespace Settings {
int currentUserId = -1;
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(currentUserId);
std::string tmpIdStr = "100";
if (currentUserId >= 0) {
if (currentUserId > 0) {
tmpIdStr = std::to_string(currentUserId);
SETTING_LOG_INFO("userId is %{public}s", tmpIdStr.c_str());
} else if (currentUserId == 0) {
OHOS::AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(currentUserId);
tmpIdStr = std::to_string(currentUserId);
SETTING_LOG_INFO("user0 userId is %{public}s", tmpIdStr.c_str());
} else {
SETTING_LOG_INFO("%{public}s, user id 100.", __func__);
}