!776 根据线程获取用户id

Merge pull request !776 from 侯志雄/master
This commit is contained in:
openharmony_ci 2024-11-01 02:46:17 +00:00 committed by Gitee
commit 74aefd6312
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 24 additions and 18 deletions

View File

@ -178,10 +178,11 @@ napi_value napi_get_uri_sync(napi_env env, napi_callback_info info)
std::string keyStr = unwrap_string_from_js(env, args[PARAM0]);
// get userId string
std::vector<int> tmpId;
OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(tmpId);
int currentUserId = -1;
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(currentUserId);
std::string tmpIdStr = "100";
if (tmpId.size() > 0) {
tmpIdStr = std::to_string(tmpId[0]);
if (currentUserId >= 0) {
tmpIdStr = std::to_string(currentUserId);
} else {
SETTING_LOG_ERROR("userid is invalid, use id 100 instead");
}
@ -259,10 +260,11 @@ napi_value napi_get_uri(napi_env env, napi_callback_info info)
std::string keyStr = unwrap_string_from_js(env, args[PARAM0]);
// get userId string
std::vector<int> tmpId;
OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(tmpId);
int currentUserId = -1;
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(currentUserId);
std::string tmpIdStr = "100";
if (tmpId.size() > 0) {
tmpIdStr = std::to_string(tmpId[0]);
if (currentUserId >= 0) {
tmpIdStr = std::to_string(currentUserId);
} else {
SETTING_LOG_ERROR("userid is invalid, use id 100 instead");
}
@ -411,10 +413,11 @@ std::shared_ptr<DataShareHelper> getDataShareHelper(
{
std::shared_ptr<OHOS::DataShare::DataShareHelper> dataShareHelper = nullptr;
std::vector<int> tmpId;
OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(tmpId);
int currentUserId = -1;
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(currentUserId);
std::string tmpIdStr = "100";
if (tmpId.size() > 0) {
tmpIdStr = std::to_string(tmpId[0]);
if (currentUserId >= 0) {
tmpIdStr = std::to_string(currentUserId);
} else {
SETTING_LOG_ERROR("userid is invalid, use id 100 instead");
}
@ -495,10 +498,11 @@ void GetValueExecuteExt(napi_env env, void *data)
}
std::vector<int> tmpId;
OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(tmpId);
int currentUserId = -1;
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(currentUserId);
std::string tmpIdStr = "100";
if (tmpId.size() > 0) {
tmpIdStr = std::to_string(tmpId[0]);
if (currentUserId >= 0) {
tmpIdStr = std::to_string(currentUserId);
} else {
SETTING_LOG_ERROR("userid is invalid, use id 100 instead");
}
@ -575,10 +579,11 @@ void SetValueExecuteExt(napi_env env, void *data, const std::string setValue)
val.Put(SETTINGS_DATA_FIELD_VALUE, setValue);
std::vector<int> tmpId;
OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(tmpId);
int currentUserId = -1;
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(currentUserId);
std::string tmpIdStr = "100";
if (tmpId.size() > 0) {
tmpIdStr = std::to_string(tmpId[0]);
if (currentUserId >= 0) {
tmpIdStr = std::to_string(currentUserId);
} else {
SETTING_LOG_ERROR("userid is invalid, use id 100 instead");
}

View File

@ -117,10 +117,11 @@ namespace Settings {
std::string GetObserverIdStr()
{
std::vector<int> tmpId;
OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(tmpId);
int currentUserId = -1;
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(currentUserId);
std::string tmpIdStr = "100";
if (tmpId.size() > 0) {
tmpIdStr = std::to_string(tmpId[0]);
if (currentUserId >= 0) {
tmpIdStr = std::to_string(currentUserId);
} else {
SETTING_LOG_INFO("%{public}s, user id 100.", __func__);
}