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