• 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 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
20 #ifdef OS_ACCOUNT_PART_EXISTS
21 #include "os_account_manager.h"
22 using namespace OHOS::AccountSA;
23 #endif // OS_ACCOUNT_PART_EXISTS
24 #endif
25 
26 namespace OHOS {
27 namespace DistributedHardware {
28 int32_t MultipleUserConnector::oldUserId_ = -1;
29 #ifndef OS_ACCOUNT_PART_EXISTS
30 const int32_t DEFAULT_OS_ACCOUNT_ID = 0; // 0 is the default id when there is no os_account part
31 #endif // OS_ACCOUNT_PART_EXISTS
32 
GetCurrentAccountUserID(void)33 int32_t MultipleUserConnector::GetCurrentAccountUserID(void)
34 {
35 #if (defined(__LITEOS_M__) || defined(LITE_DEVICE))
36     return 0;
37 #else
38 #ifdef OS_ACCOUNT_PART_EXISTS
39     std::vector<int> ids;
40     ErrCode ret = OsAccountManager::QueryActiveOsAccountIds(ids);
41     if (ret != 0 || ids.empty()) {
42         return -1;
43     }
44     return ids[0];
45 #else // OS_ACCOUNT_PART_EXISTS
46     return DEFAULT_OS_ACCOUNT_ID;
47 #endif // OS_ACCOUNT_PART_EXISTS
48 #endif
49 }
50 
SetSwitchOldUserId(int32_t userId)51 void MultipleUserConnector::SetSwitchOldUserId(int32_t userId)
52 {
53     oldUserId_ = userId;
54 }
55 
GetSwitchOldUserId(void)56 int32_t MultipleUserConnector::GetSwitchOldUserId(void)
57 {
58     return oldUserId_;
59 }
60 } // namespace DistributedHardware
61 } // namespace OHOS
62