• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 
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 
MockGetSystemAbilityManager(bool mockRet)27 void MockGetSystemAbilityManager(bool mockRet)
28 {
29     g_mockGetSystemAbilityManager = mockRet;
30 }
31 
MockSendRequest(bool mockRet)32 void MockSendRequest(bool mockRet)
33 {
34     g_mockSendRequest = mockRet;
35 }
36 
37 namespace OHOS {
GetSystemAbility(int32_t systemAbilityId)38 sptr<IRemoteObject> SystemAbility::GetSystemAbility(int32_t systemAbilityId)
39 {
40     return nullptr;
41 }
42 
GetSystemAbilityManager()43 sptr<ISystemAbilityManager> SystemAbilityManagerClient::GetSystemAbilityManager()
44 {
45     if (!g_mockGetSystemAbilityManager) {
46         return nullptr;
47     }
48     sptr<IRemoteObject> registryObject = IPCSkeleton::GetContextObject();
49     return iface_cast<ISystemAbilityManager>(registryObject);
50 }
51 
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)52 int IPCObjectStub::SendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
53 {
54     reply.WriteInt32(TEST_RETVAL_ONREMOTEREQUEST);
55     if (g_mockSendRequest) {
56         return NO_ERROR;
57     }
58     return ERR_DEAD_OBJECT;
59 }
60 }  // namespace OHOS