1 /*
2 * Copyright (c) 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 "dlp_os_account_mock.h"
17
18 namespace OHOS {
19 namespace AccountSA {
20 static const int32_t MAIN_OS_ACCOUNT_ID = 100;
21 std::string g_accountId = "accountIdA";
22 std::string g_accountName = "accountIdA";
23 std::string g_parameters = R"({"parameters":{"adConfig":{"adDomain":"test"},"type":"AD"}})";
24
GetInstance()25 OhosAccountKits& OhosAccountKits::GetInstance()
26 {
27 static OhosAccountKits instance;
28 return instance;
29 }
30
QueryOhosAccountInfo()31 std::pair<bool, OhosAccountInfo> OhosAccountKits::QueryOhosAccountInfo()
32 {
33 OhosAccountInfo accountInfo;
34 accountInfo.name_ = g_accountName;
35 accountInfo.status_ = ACCOUNT_STATE_LOGIN;
36 accountInfo.SetRawUid(g_accountId);
37 return std::make_pair(false, accountInfo);
38 }
39
QueryOsAccountDistributedInfo(std::int32_t userId)40 std::pair<bool, OhosAccountInfo> OhosAccountKits::QueryOsAccountDistributedInfo(std::int32_t userId)
41 {
42 (void)userId;
43 OhosAccountInfo accountInfo;
44 accountInfo.name_ = g_accountName;
45 accountInfo.status_ = ACCOUNT_STATE_LOGIN;
46 accountInfo.SetRawUid(g_accountId);
47 return std::make_pair(true, accountInfo);
48 }
49
GetOsAccountDistributedInfo(int32_t localId,OhosAccountInfo & accountInfo)50 ErrCode OhosAccountKits::GetOsAccountDistributedInfo(int32_t localId, OhosAccountInfo &accountInfo)
51 {
52 accountInfo.name_ = g_accountName;
53 accountInfo.status_ = ACCOUNT_STATE_LOGIN;
54 accountInfo.SetRawUid(g_accountId);
55 return 0;
56 }
57
GetInstance()58 DomainAccountClient& DomainAccountClient::GetInstance()
59 {
60 static DomainAccountClient instance;
61 return instance;
62 }
63
GetDomainInfo(DomainAccountInfo & domainInfo)64 void OsAccountInfo::GetDomainInfo(DomainAccountInfo &domainInfo)
65 {
66 domainInfo.accountId_ = g_accountId;
67 domainInfo.accountName_ = g_accountName;
68 }
69
GetAccountServerConfig(const DomainAccountInfo & info,DomainServerConfig & config)70 ErrCode DomainAccountClient::GetAccountServerConfig(const DomainAccountInfo &info, DomainServerConfig &config)
71 {
72 config.parameters_ = g_parameters;
73 return 0;
74 }
75
GetForegroundOsAccountLocalId(int32_t & localId)76 int OsAccountManager::GetForegroundOsAccountLocalId(int32_t &localId)
77 {
78 localId = MAIN_OS_ACCOUNT_ID;
79 return 0;
80 }
81
QueryOsAccountById(const int id,OsAccountInfo & osAccountInfo)82 int OsAccountManager::QueryOsAccountById(const int id, OsAccountInfo &osAccountInfo)
83 {
84 return 0;
85 }
86 } // namespace AccountSA
87 } // namespace OHOS
88
89 namespace OHOS {
90 namespace Security {
91 namespace DlpPermissionUnitTest {
SetAccountServerConfigParameters(std::string & parameters)92 void SetAccountServerConfigParameters(std::string ¶meters)
93 {
94 OHOS::AccountSA::g_parameters = parameters;
95 }
96 } // namespace DlpPermission
97 } // namespace Security
98 } // namespace OHOS