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,const std::string & deviceId)44 sptr<IRemoteObject> SystemAbilityManagerProxy::GetSystemAbility(int32_t systemAbilityId,
45 const std::string& deviceId)
46 {
47 (void)deviceId;
48 return GetSystemAbility(systemAbilityId);
49 }
50
GetSystemAbility(int32_t systemAbilityId)51 sptr<IRemoteObject> SystemAbilityManagerProxy::GetSystemAbility(int32_t systemAbilityId)
52 {
53 sptr<IRemoteObject> remote = nullptr;
54 switch (systemAbilityId) {
55 case ACCESSIBILITY_MANAGER_SERVICE_ID:
56 if (!g_MgrService) {
57 g_MgrService = new OHOS::Accessibility::MockAccessibleAbilityManagerServiceStub();
58 }
59 remote = g_MgrService;
60 break;
61 default:
62 GTEST_LOG_(INFO) << "This service is not dummy!!!!" << systemAbilityId;
63 break;
64 }
65 return remote;
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
UnloadSystemAbility(int32_t systemAbilityId)147 int32_t SystemAbilityManagerProxy::UnloadSystemAbility(int32_t systemAbilityId)
148 {
149 return -1;
150 }
151
CancelUnloadSystemAbility(int32_t systemAbilityId)152 int32_t SystemAbilityManagerProxy::CancelUnloadSystemAbility(int32_t systemAbilityId)
153 {
154 return -1;
155 }
156
AddSystemAbility(int32_t systemAbilityId,const sptr<IRemoteObject> & ability,const SAExtraProp & extraProp)157 int32_t SystemAbilityManagerProxy::AddSystemAbility(int32_t systemAbilityId, const sptr<IRemoteObject>& ability,
158 const SAExtraProp& extraProp)
159 {
160 (void)systemAbilityId;
161 (void)ability;
162 (void)extraProp;
163 return -1;
164 }
165
AddSystemAbilityWrapper(int32_t code,MessageParcel & data)166 int32_t SystemAbilityManagerProxy::AddSystemAbilityWrapper(int32_t code, MessageParcel& data)
167 {
168 (void)code;
169 (void)data;
170 return -1;
171 }
172
AddSystemProcess(const std::u16string & procName,const sptr<IRemoteObject> & procObject)173 int32_t SystemAbilityManagerProxy::AddSystemProcess(
174 const std::u16string& procName, const sptr<IRemoteObject>& procObject)
175 {
176 (void)procName;
177 (void)procObject;
178 return -1;
179 }
180
GetRunningSystemProcess(std::list<SystemProcessInfo> & systemProcessInfos)181 int32_t SystemAbilityManagerProxy::GetRunningSystemProcess(std::list<SystemProcessInfo>& systemProcessInfos)
182 {
183 return -1;
184 }
185
SubscribeSystemProcess(const sptr<ISystemProcessStatusChange> & listener)186 int32_t SystemAbilityManagerProxy::SubscribeSystemProcess(const sptr<ISystemProcessStatusChange>& listener)
187 {
188 return -1;
189 }
190
UnSubscribeSystemProcess(const sptr<ISystemProcessStatusChange> & listener)191 int32_t SystemAbilityManagerProxy::UnSubscribeSystemProcess(const sptr<ISystemProcessStatusChange>& listener)
192 {
193 return -1;
194 }
195
GetOnDemandSystemAbilityIds(std::vector<int32_t> & systemAbilityIds)196 int32_t SystemAbilityManagerProxy::GetOnDemandSystemAbilityIds(std::vector<int32_t>& systemAbilityIds)
197 {
198 return -1;
199 }
200
Recompute(int32_t systemAbilityId,int32_t code)201 sptr<IRemoteObject> SystemAbilityManagerProxy::Recompute(int32_t systemAbilityId, int32_t code)
202 {
203 return nullptr;
204 }
205 }