• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /*! \file utils.h */
17 
18 #ifndef FM_IMMS_PROJECT_UTILS_H
19 #define FM_IMMS_PROJECT_UTILS_H
20 
21 #include <codecvt>
22 #include <iostream>
23 #include <locale>
24 #include <string>
25 #include <vector>
26 
27 #include "os_account_manager.h"
28 
29 namespace OHOS {
30 namespace MiscServices {
31     class Utils {
32     public:
to_utf8(std::u16string str16)33         static std::string to_utf8(std::u16string str16)
34         {
35             return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> {}.to_bytes(str16);
36         }
to_utf16(std::string str)37         static std::u16string to_utf16(std::string str)
38         {
39             return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> {}.from_bytes(str);
40         }
GetUserId()41         static int32_t GetUserId()
42         {
43             std::vector<int32_t> userIds;
44             AccountSA::OsAccountManager::QueryActiveOsAccountIds(userIds);
45             return userIds[0];
46         }
47     };
48 }
49 }
50 
51 #endif