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     if (systemAbilityManager_ != nullptr) {
36         return systemAbilityManager_;
37     }
38 
39     systemAbilityManager_ = new SystemAbilityManagerProxy(nullptr);
40     return systemAbilityManager_;
41 }
42 
GetSystemAbility(int32_t systemAbilityId,const std::string & deviceId)43 sptr<IRemoteObject> SystemAbilityManagerProxy::GetSystemAbility(int32_t systemAbilityId,
44     const std::string& deviceId)
45 {
46     (void)deviceId;
47     return GetSystemAbility(systemAbilityId);
48 }
49 
GetSystemAbility(int32_t systemAbilityId)50 sptr<IRemoteObject> SystemAbilityManagerProxy::GetSystemAbility(int32_t systemAbilityId)
51 {
52     sptr<IRemoteObject> remote = nullptr;
53     switch (systemAbilityId) {
54         case ACCESSIBILITY_MANAGER_SERVICE_ID:
55             if (!g_MgrService) {
56                 g_MgrService = new OHOS::Accessibility::MockAccessibleAbilityManagerServiceStub();
57             }
58             remote = g_MgrService;
59             break;
60         default:
61             GTEST_LOG_(INFO) << "This service is not dummy!!!!" << systemAbilityId;
62             break;
63     }
64     return remote;
65 }
66 
CheckSystemAbilityWrapper(int32_t code,MessageParcel & data)67 sptr<IRemoteObject> SystemAbilityManagerProxy::CheckSystemAbilityWrapper(int32_t code, MessageParcel& data)
68 {
69     (void)code;
70     (void)data;
71     return nullptr;
72 }
73 
CheckSystemAbility(int32_t systemAbilityId)74 sptr<IRemoteObject> SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId)
75 {
76     (void)systemAbilityId;
77     return nullptr;
78 }
79 
CheckSystemAbility(int32_t systemAbilityId,const std::string & deviceId)80 sptr<IRemoteObject> SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
81 {
82     (void)systemAbilityId;
83     (void)deviceId;
84     return nullptr;
85 }
86 
CheckSystemAbility(int32_t systemAbilityId,bool & isExist)87 sptr<IRemoteObject> SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId, bool& isExist)
88 {
89     (void)systemAbilityId;
90     (void)isExist;
91     return nullptr;
92 }
93 
AddOnDemandSystemAbilityInfo(int32_t systemAbilityId,const std::u16string & localAbilityManagerName)94 int32_t SystemAbilityManagerProxy::AddOnDemandSystemAbilityInfo(int32_t systemAbilityId,
95     const std::u16string& localAbilityManagerName)
96 {
97     (void)systemAbilityId;
98     (void)localAbilityManagerName;
99     return -1;
100 }
101 
RemoveSystemAbilityWrapper(int32_t code,MessageParcel & data)102 int32_t SystemAbilityManagerProxy::RemoveSystemAbilityWrapper(int32_t code, MessageParcel& data)
103 {
104     (void)code;
105     (void)data;
106     return -1;
107 }
108 
RemoveSystemAbility(int32_t systemAbilityId)109 int32_t SystemAbilityManagerProxy::RemoveSystemAbility(int32_t systemAbilityId)
110 {
111     (void)systemAbilityId;
112     return -1;
113 }
114 
ListSystemAbilities(unsigned int dumpFlags)115 std::vector<std::u16string> SystemAbilityManagerProxy::ListSystemAbilities(unsigned int dumpFlags)
116 {
117     (void)dumpFlags;
118     std::vector<std::u16string> saNames;
119     return saNames;
120 }
121 
SubscribeSystemAbility(int32_t systemAbilityId,const sptr<ISystemAbilityStatusChange> & listener)122 int32_t SystemAbilityManagerProxy::SubscribeSystemAbility(int32_t systemAbilityId,
123     const sptr<ISystemAbilityStatusChange>& listener)
124 {
125     (void)systemAbilityId;
126     (void)listener;
127     return -1;
128 }
129 
UnSubscribeSystemAbility(int32_t systemAbilityId,const sptr<ISystemAbilityStatusChange> & listener)130 int32_t SystemAbilityManagerProxy::UnSubscribeSystemAbility(int32_t systemAbilityId,
131     const sptr<ISystemAbilityStatusChange>& listener)
132 {
133     (void)systemAbilityId;
134     (void)listener;
135     return -1;
136 }
137 
LoadSystemAbility(int32_t systemAbilityId,const sptr<ISystemAbilityLoadCallback> & callback)138 int32_t SystemAbilityManagerProxy::LoadSystemAbility(int32_t systemAbilityId,
139     const sptr<ISystemAbilityLoadCallback>& callback)
140 {
141     (void)systemAbilityId;
142     (void)callback;
143     return -1;
144 }
145 
UnloadSystemAbility(int32_t systemAbilityId)146 int32_t SystemAbilityManagerProxy::UnloadSystemAbility(int32_t systemAbilityId)
147 {
148     return -1;
149 }
150 
CancelUnloadSystemAbility(int32_t systemAbilityId)151 int32_t SystemAbilityManagerProxy::CancelUnloadSystemAbility(int32_t systemAbilityId)
152 {
153     return -1;
154 }
155 
AddSystemAbility(int32_t systemAbilityId,const sptr<IRemoteObject> & ability,const SAExtraProp & extraProp)156 int32_t SystemAbilityManagerProxy::AddSystemAbility(int32_t systemAbilityId, const sptr<IRemoteObject>& ability,
157     const SAExtraProp& extraProp)
158 {
159     (void)systemAbilityId;
160     (void)ability;
161     (void)extraProp;
162     return -1;
163 }
164 
AddSystemAbilityWrapper(int32_t code,MessageParcel & data)165 int32_t SystemAbilityManagerProxy::AddSystemAbilityWrapper(int32_t code, MessageParcel& data)
166 {
167     (void)code;
168     (void)data;
169     return -1;
170 }
171 
AddSystemProcess(const std::u16string & procName,const sptr<IRemoteObject> & procObject)172 int32_t SystemAbilityManagerProxy::AddSystemProcess(
173     const std::u16string& procName, const sptr<IRemoteObject>& procObject)
174 {
175     (void)procName;
176     (void)procObject;
177     return -1;
178 }
179 
GetRunningSystemProcess(std::list<SystemProcessInfo> & systemProcessInfos)180 int32_t SystemAbilityManagerProxy::GetRunningSystemProcess(std::list<SystemProcessInfo>& systemProcessInfos)
181 {
182     return -1;
183 }
184 
SubscribeSystemProcess(const sptr<ISystemProcessStatusChange> & listener)185 int32_t SystemAbilityManagerProxy::SubscribeSystemProcess(const sptr<ISystemProcessStatusChange>& listener)
186 {
187     return -1;
188 }
189 
UnSubscribeSystemProcess(const sptr<ISystemProcessStatusChange> & listener)190 int32_t SystemAbilityManagerProxy::UnSubscribeSystemProcess(const sptr<ISystemProcessStatusChange>& listener)
191 {
192     return -1;
193 }
194 
GetOnDemandSystemAbilityIds(std::vector<int32_t> & systemAbilityIds)195 int32_t SystemAbilityManagerProxy::GetOnDemandSystemAbilityIds(std::vector<int32_t>& systemAbilityIds)
196 {
197     return -1;
198 }
199 
Recompute(int32_t systemAbilityId,int32_t code)200 sptr<IRemoteObject> SystemAbilityManagerProxy::Recompute(int32_t systemAbilityId, int32_t code)
201 {
202     return nullptr;
203 }
204 }