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 <gtest/gtest.h>
17 #include "iservice_registry.h"
18 #include "mock_bundle_manager.h"
19 #include "string_ex.h"
20 #include "system_ability_definition.h"
21 #include "system_ability_manager_proxy.h"
22 #include "mock_accessible_ability_manager_service_stub.h"
23
24 namespace OHOS {
25 static sptr<OHOS::Accessibility::MockAccessibleAbilityManagerServiceStub> g_MgrService = nullptr;
26
GetInstance()27 SystemAbilityManagerClient& SystemAbilityManagerClient::GetInstance()
28 {
29 static auto instance = new SystemAbilityManagerClient();
30 return *instance;
31 }
32
GetSystemAbilityManager()33 sptr<ISystemAbilityManager> SystemAbilityManagerClient::GetSystemAbilityManager()
34 {
35 std::lock_guard<std::mutex> lock(systemAbilityManagerLock_);
36 if (systemAbilityManager_ != nullptr) {
37 return systemAbilityManager_;
38 }
39
40 systemAbilityManager_ = new SystemAbilityManagerProxy(nullptr);
41 return systemAbilityManager_;
42 }
43
GetSystemAbility(int32_t systemAbilityId)44 sptr<IRemoteObject> SystemAbilityManagerProxy::GetSystemAbility(int32_t systemAbilityId)
45 {
46 sptr<IRemoteObject> remote = nullptr;
47 switch (systemAbilityId) {
48 case ACCESSIBILITY_MANAGER_SERVICE_ID:
49 if (!g_MgrService) {
50 g_MgrService = new OHOS::Accessibility::MockAccessibleAbilityManagerServiceStub();
51 }
52 remote = g_MgrService;
53 break;
54 default:
55 GTEST_LOG_(INFO) << "This service is not dummy!!!!" << systemAbilityId;
56 break;
57 }
58 return remote;
59 }
60
GetSystemAbility(int32_t systemAbilityId,const std::string & deviceId)61 sptr<IRemoteObject> SystemAbilityManagerProxy::GetSystemAbility(int32_t systemAbilityId,
62 const std::string& deviceId)
63 {
64 (void)deviceId;
65 return GetSystemAbility(systemAbilityId);
66 }
67
CheckSystemAbilityWrapper(int32_t code,MessageParcel & data)68 sptr<IRemoteObject> SystemAbilityManagerProxy::CheckSystemAbilityWrapper(int32_t code, MessageParcel& data)
69 {
70 (void)code;
71 (void)data;
72 return nullptr;
73 }
74
CheckSystemAbility(int32_t systemAbilityId)75 sptr<IRemoteObject> SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId)
76 {
77 (void)systemAbilityId;
78 return nullptr;
79 }
80
CheckSystemAbility(int32_t systemAbilityId,const std::string & deviceId)81 sptr<IRemoteObject> SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
82 {
83 (void)systemAbilityId;
84 (void)deviceId;
85 return nullptr;
86 }
87
CheckSystemAbility(int32_t systemAbilityId,bool & isExist)88 sptr<IRemoteObject> SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId, bool& isExist)
89 {
90 (void)systemAbilityId;
91 (void)isExist;
92 return nullptr;
93 }
94
AddOnDemandSystemAbilityInfo(int32_t systemAbilityId,const std::u16string & localAbilityManagerName)95 int32_t SystemAbilityManagerProxy::AddOnDemandSystemAbilityInfo(int32_t systemAbilityId,
96 const std::u16string& localAbilityManagerName)
97 {
98 (void)systemAbilityId;
99 (void)localAbilityManagerName;
100 return -1;
101 }
102
RemoveSystemAbilityWrapper(int32_t code,MessageParcel & data)103 int32_t SystemAbilityManagerProxy::RemoveSystemAbilityWrapper(int32_t code, MessageParcel& data)
104 {
105 (void)code;
106 (void)data;
107 return -1;
108 }
109
RemoveSystemAbility(int32_t systemAbilityId)110 int32_t SystemAbilityManagerProxy::RemoveSystemAbility(int32_t systemAbilityId)
111 {
112 (void)systemAbilityId;
113 return -1;
114 }
115
ListSystemAbilities(unsigned int dumpFlags)116 std::vector<std::u16string> SystemAbilityManagerProxy::ListSystemAbilities(unsigned int dumpFlags)
117 {
118 (void)dumpFlags;
119 std::vector<std::u16string> saNames;
120 return saNames;
121 }
122
SubscribeSystemAbility(int32_t systemAbilityId,const sptr<ISystemAbilityStatusChange> & listener)123 int32_t SystemAbilityManagerProxy::SubscribeSystemAbility(int32_t systemAbilityId,
124 const sptr<ISystemAbilityStatusChange>& listener)
125 {
126 (void)systemAbilityId;
127 (void)listener;
128 return -1;
129 }
130
UnSubscribeSystemAbility(int32_t systemAbilityId,const sptr<ISystemAbilityStatusChange> & listener)131 int32_t SystemAbilityManagerProxy::UnSubscribeSystemAbility(int32_t systemAbilityId,
132 const sptr<ISystemAbilityStatusChange>& listener)
133 {
134 (void)systemAbilityId;
135 (void)listener;
136 return -1;
137 }
138
LoadSystemAbility(int32_t systemAbilityId,const sptr<ISystemAbilityLoadCallback> & callback)139 int32_t SystemAbilityManagerProxy::LoadSystemAbility(int32_t systemAbilityId,
140 const sptr<ISystemAbilityLoadCallback>& callback)
141 {
142 (void)systemAbilityId;
143 (void)callback;
144 return -1;
145 }
146
AddSystemAbility(int32_t systemAbilityId,const sptr<IRemoteObject> & ability,const SAExtraProp & extraProp)147 int32_t SystemAbilityManagerProxy::AddSystemAbility(int32_t systemAbilityId, const sptr<IRemoteObject>& ability,
148 const SAExtraProp& extraProp)
149 {
150 (void)systemAbilityId;
151 (void)ability;
152 (void)extraProp;
153 return -1;
154 }
155
AddSystemAbilityWrapper(int32_t code,MessageParcel & data)156 int32_t SystemAbilityManagerProxy::AddSystemAbilityWrapper(int32_t code, MessageParcel& data)
157 {
158 (void)code;
159 (void)data;
160 return -1;
161 }
162
AddSystemProcess(const std::u16string & procName,const sptr<IRemoteObject> & procObject)163 int32_t SystemAbilityManagerProxy::AddSystemProcess(
164 const std::u16string& procName, const sptr<IRemoteObject>& procObject)
165 {
166 (void)procName;
167 (void)procObject;
168 return -1;
169 }
170 }