1 /*
2 * Copyright (c) 2024-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 #include "lnn_ohos_account_adapter_mock.h"
17
GetInstance()18 OHOS::AccountSA::OhosAccountKits &OHOS::AccountSA::OhosAccountKits::GetInstance()
19 {
20 static OhosAccountKits ohosAccountKits;
21 return ohosAccountKits;
22 }
23
QueryOhosAccountInfo()24 std::pair<bool, OHOS::AccountSA::OhosAccountInfo> OHOS::AccountSA::OhosAccountKits::QueryOhosAccountInfo()
25 {
26 auto mock = OHOS::AccountSA::OhosAccountKitsMock::GetMock();
27 if (mock == nullptr) {
28 std::pair<bool, OHOS::AccountSA::OhosAccountInfo> account_info = {};
29 return account_info;
30 }
31 return mock->QueryOhosAccountInfo();
32 }
33
QueryOsAccountDistributedInfo(std::int32_t id)34 std::pair<bool, OHOS::AccountSA::OhosAccountInfo> OHOS::AccountSA::OhosAccountKits::QueryOsAccountDistributedInfo(
35 std::int32_t id)
36 {
37 auto mock = OHOS::AccountSA::OhosAccountKitsMock::GetMock();
38 if (mock == nullptr) {
39 std::pair<bool, OHOS::AccountSA::OhosAccountInfo> account_info = {};
40 return account_info;
41 }
42 return mock->QueryOsAccountDistributedInfo(id);
43 }
44
GetOsAccountDistributedInfo(int32_t localId,OHOS::AccountSA::OhosAccountInfo & accountInfo)45 int32_t OHOS::AccountSA::OhosAccountKits::GetOsAccountDistributedInfo(int32_t localId,
46 OHOS::AccountSA::OhosAccountInfo &accountInfo)
47 {
48 auto mock = OHOS::AccountSA::OhosAccountKitsMock::GetMock();
49 if (mock == nullptr) {
50 return -1;
51 }
52 return mock->GetOsAccountDistributedInfo(localId, accountInfo);
53 }
54
IsSameAccountGroupDevice()55 bool OHOS::AccountSA::OhosAccountKits::IsSameAccountGroupDevice()
56 {
57 auto mock = OHOS::AccountSA::OhosAccountKitsMock::GetMock();
58 if (mock == nullptr) {
59 return false;
60 }
61 return mock->IsSameAccountGroupDevice();
62 }
63
64 namespace OHOS::AccountSA {
OhosAccountKitsMock()65 OhosAccountKitsMock::OhosAccountKitsMock()
66 {
67 mock.store(this);
68 }
69
~OhosAccountKitsMock()70 OhosAccountKitsMock::~OhosAccountKitsMock()
71 {
72 mock.store(nullptr);
73 }
74
75 extern "C" {
IsSameAccountGroupDevice(void)76 bool IsSameAccountGroupDevice(void)
77 {
78 auto mock = OHOS::AccountSA::OhosAccountKitsMock::GetMock();
79 if (mock == nullptr) {
80 return false;
81 }
82 return mock->IsSameAccountGroupDevice();
83 }
84 }
85
86 } // namespace OHOS::AccountSA
87
QueryActiveOsAccountIds(std::vector<int32_t> & ids)88 OHOS::ErrCode OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(std::vector<int32_t> &ids)
89 {
90 auto mock = OHOS::AccountSA::OsAccountManagerMock::GetMock();
91 if (mock == nullptr) {
92 return -1;
93 }
94 return mock->QueryActiveOsAccountIds(ids);
95 }
96
IsOsAccountVerified(const int32_t id,bool & isVerified)97 OHOS::ErrCode OHOS::AccountSA::OsAccountManager::IsOsAccountVerified(const int32_t id, bool &isVerified)
98 {
99 auto mock = OHOS::AccountSA::OsAccountManagerMock::GetMock();
100 if (mock == nullptr) {
101 return -1;
102 }
103 return mock->IsOsAccountVerified(id, isVerified);
104 }
105
106 namespace OHOS::AccountSA {
OsAccountManagerMock()107 OsAccountManagerMock::OsAccountManagerMock()
108 {
109 mock.store(this);
110 }
111
~OsAccountManagerMock()112 OsAccountManagerMock::~OsAccountManagerMock()
113 {
114 mock.store(nullptr);
115 }
116 } // namespace OHOS::AccountSA