• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 #ifndef OHOS_DM_MULTIPLE_USER_CONNECTOR_H
17 #define OHOS_DM_MULTIPLE_USER_CONNECTOR_H
18 
19 #include <cstdint>
20 #include <map>
21 #include <mutex>
22 #include <string>
23 #include <vector>
24 namespace OHOS {
25 namespace DistributedHardware {
26 typedef struct DMAccountInfo {
27     std::string accountId;
28     std::string accountName;
29 } DMAccountInfo;
30 class MultipleUserConnector {
31 public:
32     /**
33      * @tc.name: MultipleUserConnector::GetCurrentAccountUserID
34      * @tc.desc: Get Current Account UserID of the Multiple User Connector
35      * @tc.type: FUNC
36      */
37     static int32_t GetCurrentAccountUserID(void);
38 
39     /**
40      * @tc.name: MultipleUserConnector::SetSwitchOldUserId
41      * @tc.desc: Set Switch Old UserId of the Multiple User Connector
42      * @tc.type: FUNC
43      */
44     static void SetSwitchOldUserId(int32_t userId);
45 
46     /**
47      * @tc.name: MultipleUserConnector::GetSwitchOldUserId
48      * @tc.desc: Get Switc hOld UserId of the Multiple User Connector
49      * @tc.type: FUNC
50      */
51     static int32_t GetSwitchOldUserId(void);
52 
53     /**
54      * @tc.name: MultipleUserConnector::GetOhosAccountId
55      * @tc.desc: Get Current AccountId of current user
56      * @tc.type: FUNC
57      */
58     static std::string GetOhosAccountId(void);
59 
60     /**
61      * @brief Get the Ohos Account Id By Userid
62      *
63      * @param userId the user id in which account login
64      * @return std::string the account id
65      */
66     static std::string GetOhosAccountIdByUserId(int32_t userId);
67 
68     /**
69      * @tc.name: MultipleUserConnector::SetSwitchOldAccountId
70      * @tc.desc: Set Switch Old UserId of the Multiple User Connector
71      * @tc.type: FUNC
72      */
73     static void SetSwitchOldAccountId(std::string accountId);
74 
75     /**
76      * @tc.name: MultipleUserConnector::GetSwitchOldAccountId
77      * @tc.desc: Get Switc hOld UserId of the Multiple User Connector
78      * @tc.type: FUNC
79      */
80     static std::string GetSwitchOldAccountId(void);
81 
82     /**
83      * @tc.name: MultipleUserConnector::SetSwitchOldAccountName
84      * @tc.desc: Set Switch Old AccountName of the Multiple User Connector
85      * @tc.type: FUNC
86      */
87     static void SetSwitchOldAccountName(std::string accountName);
88 
89     /**
90      * @tc.name: MultipleUserConnector::GetOhosAccountName
91      * @tc.desc: Get Current AccountName of the Multiple User Connector
92      * @tc.type: FUNC
93      */
94     static std::string GetOhosAccountName(void);
95 
96     /**
97      * @tc.name: MultipleUserConnector::GetSwitchOldAccountName
98      * @tc.desc: Get Switc Old AccountName of the Multiple User Connector
99      * @tc.type: FUNC
100      */
101     static std::string GetSwitchOldAccountName(void);
102 
103     static void SetAccountInfo(int32_t userId, DMAccountInfo dmAccountInfo);
104     static DMAccountInfo GetAccountInfoByUserId(int32_t userId);
105     static void DeleteAccountInfoByUserId(int32_t userId);
106     static void GetTokenIdAndForegroundUserId(uint32_t &tokenId, int32_t &userId);
107     static void GetCallerUserId(int32_t &userId);
108     static int32_t GetForegroundUserIds(std::vector<int32_t> &userVec);
109     static int32_t GetFirstForegroundUserId(void);
110     static int32_t GetBackgroundUserIds(std::vector<int32_t> &userIdVec);
111     static int32_t GetAllUserIds(std::vector<int32_t> &userIdVec);
112     static std::string GetAccountNickName(int32_t userId);
113     static bool IsUserUnlocked(int32_t userId);
114     static void ClearLockedUser(std::vector<int32_t> &foregroundUserVec);
115     static void ClearLockedUser(std::vector<int32_t> &foregroundUserVec, std::vector<int32_t> &backgroundUserVec);
116     static DMAccountInfo GetCurrentDMAccountInfo();
117 private:
118     static int32_t oldUserId_;
119     static std::string accountId_;
120     static std::string accountName_;
121     static std::mutex lock_;
122     static std::map<int32_t, DMAccountInfo> dmAccountInfoMap_;
123     static std::mutex dmAccountInfoMaplock_;
124 };
125 } // namespace DistributedHardware
126 } // namespace OHOS
127 #endif // OHOS_DM_MULTIPLE_USER_CONNECTOR_H
128