!853 【3.1Release】修改crash

Merge pull request !853 from mashaoyin/OpenHarmony-3.1-Release
This commit is contained in:
openharmony_ci 2023-08-23 10:22:35 +00:00 committed by Gitee
commit b9a10e76cc
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -28,24 +28,29 @@
namespace OHOS {
namespace MiscServices {
class Utils {
public:
static std::string to_utf8(std::u16string str16)
{
return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> {}.to_bytes(str16);
constexpr int32_t MAIN_USER_ID = 100;
class Utils {
public:
static std::string to_utf8(std::u16string str16)
{
return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.to_bytes(str16);
}
static std::u16string to_utf16(std::string str)
{
return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes(str);
}
static int32_t GetUserId()
{
std::vector<int32_t> userIds;
auto ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(userIds);
if (ret != ErrorCode::NO_ERROR || userIds.empty()) {
IMSA_HILOGE("query active os account id failed");
return MAIN_USER_ID;
}
static std::u16string to_utf16(std::string str)
{
return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> {}.from_bytes(str);
}
static int32_t GetUserId()
{
std::vector<int32_t> userIds;
AccountSA::OsAccountManager::QueryActiveOsAccountIds(userIds);
return userIds[0];
}
};
}
}
return userIds[0];
}
};
} // namespace MiscServices
} // namespace OHOS
#endif