1 /*
2 * Copyright (c) 2023-2024 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 "system_ability.h"
17 #include "iservice_registry.h"
18 #include "mock_sa_service.h"
19 #include "ipc_skeleton.h"
20
21 namespace {
22 bool g_mockGetSystemAbilityManager = true;
23 bool g_mockSendRequest = true;
24 const int32_t TEST_RETVAL_ONREMOTEREQUEST = 10000;
25 }
26
27 namespace OHOS {
GetSystemAbility(int32_t systemAbilityId)28 sptr<IRemoteObject> SystemAbility::GetSystemAbility(int32_t systemAbilityId)
29 {
30 return nullptr;
31 }
32
GetSystemAbilityManager()33 sptr<ISystemAbilityManager> SystemAbilityManagerClient::GetSystemAbilityManager()
34 {
35 if (!g_mockGetSystemAbilityManager) {
36 return nullptr;
37 }
38 sptr<IRemoteObject> registryObject = IPCSkeleton::GetContextObject();
39 return iface_cast<ISystemAbilityManager>(registryObject);
40 }
41
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)42 int IPCObjectStub::SendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
43 {
44 reply.WriteInt32(TEST_RETVAL_ONREMOTEREQUEST);
45 if (g_mockSendRequest) {
46 return NO_ERROR;
47 }
48 return ERR_DEAD_OBJECT;
49 }
50
51 namespace DevStandbyMgr {
MockGetSystemAbilityManager(bool mockRet)52 void MockSaService::MockGetSystemAbilityManager(bool mockRet)
53 {
54 g_mockGetSystemAbilityManager = mockRet;
55 }
56
MockSendRequest(bool mockRet)57 void MockSaService::MockSendRequest(bool mockRet)
58 {
59 g_mockSendRequest = mockRet;
60 }
61 }
62 } // namespace OHOS