• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "multiple_user_connector.h"
17 
18 #include "dm_log.h"
19 
20 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
21 #include "account_info.h"
22 #include "ohos_account_kits.h"
23 #ifdef OS_ACCOUNT_PART_EXISTS
24 #include "os_account_manager.h"
25 using namespace OHOS::AccountSA;
26 #endif // OS_ACCOUNT_PART_EXISTS
27 #endif
28 
29 namespace OHOS {
30 namespace DistributedHardware {
31 int32_t MultipleUserConnector::oldUserId_ = -1;
32 std::string MultipleUserConnector::accountId_ = "";
33 
34 #ifndef OS_ACCOUNT_PART_EXISTS
35 const int32_t DEFAULT_OS_ACCOUNT_ID = 0; // 0 is the default id when there is no os_account part
36 #endif // OS_ACCOUNT_PART_EXISTS
37 
GetCurrentAccountUserID(void)38 int32_t MultipleUserConnector::GetCurrentAccountUserID(void)
39 {
40 #if (defined(__LITEOS_M__) || defined(LITE_DEVICE))
41     return 0;
42 #else
43 #ifdef OS_ACCOUNT_PART_EXISTS
44     std::vector<int> ids;
45     ErrCode ret = OsAccountManager::QueryActiveOsAccountIds(ids);
46     if (ret != 0 || ids.empty()) {
47         return -1;
48     }
49     return ids[0];
50 #else // OS_ACCOUNT_PART_EXISTS
51     return DEFAULT_OS_ACCOUNT_ID;
52 #endif // OS_ACCOUNT_PART_EXISTS
53 #endif
54 }
55 
GetOhosAccountId(void)56 std::string MultipleUserConnector::GetOhosAccountId(void)
57 {
58 #if (defined(__LITEOS_M__) || defined(LITE_DEVICE))
59     return "";
60 #else
61 #ifdef OS_ACCOUNT_PART_EXISTS
62     OhosAccountInfo accountInfo;
63     ErrCode ret = OhosAccountKits::GetInstance().GetOhosAccountInfo(accountInfo);
64     if (ret != 0 || accountInfo.uid_ == "") {
65         return "";
66     }
67     return accountInfo.uid_;
68 #else // OS_ACCOUNT_PART_EXISTS
69     return "";
70 #endif // OS_ACCOUNT_PART_EXISTS
71 #endif
72 }
73 
SetSwitchOldUserId(int32_t userId)74 void MultipleUserConnector::SetSwitchOldUserId(int32_t userId)
75 {
76     oldUserId_ = userId;
77 }
78 
GetSwitchOldUserId(void)79 int32_t MultipleUserConnector::GetSwitchOldUserId(void)
80 {
81     return oldUserId_;
82 }
83 
SetSwitchOldAccountId(std::string accountId)84 void MultipleUserConnector::SetSwitchOldAccountId(std::string accountId)
85 {
86     accountId_ = accountId;
87 }
88 
GetSwitchOldAccountId(void)89 std::string MultipleUserConnector::GetSwitchOldAccountId(void)
90 {
91     return accountId_;
92 }
93 } // namespace DistributedHardware
94 } // namespace OHOS
95