1 /*
2 * Copyright (c) 2021 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 "accessibility_common_helper.h"
18 #include "iservice_registry.h"
19 #include "mock_bundle_manager.h"
20 #include "string_ex.h"
21 #include "system_ability_definition.h"
22 #include "system_ability_manager_proxy.h"
23 #include "mock_accessible_ability_manager_service_stub.h"
24
25 namespace OHOS {
26 static sptr<AppExecFwk::BundleMgrService> g_bundleMgrService = nullptr;
27 static sptr<OHOS::Accessibility::MockAccessibleAbilityManagerServiceStub> g_MgrService = nullptr;
28
GetInstance()29 SystemAbilityManagerClient& SystemAbilityManagerClient::GetInstance()
30 {
31 static auto instance = new SystemAbilityManagerClient();
32 return *instance;
33 }
34
GetSystemAbilityManager()35 sptr<ISystemAbilityManager> SystemAbilityManagerClient::GetSystemAbilityManager()
36 {
37 std::lock_guard<std::mutex> lock(systemAbilityManagerLock_);
38 if (systemAbilityManager_ != nullptr) {
39 return systemAbilityManager_;
40 }
41
42 systemAbilityManager_ = new SystemAbilityManagerProxy(nullptr);
43 return systemAbilityManager_;
44 }
45
GetSystemAbility(int32_t systemAbilityId)46 sptr<IRemoteObject> SystemAbilityManagerProxy::GetSystemAbility(int32_t systemAbilityId)
47 {
48 sptr<IRemoteObject> remote = nullptr;
49 switch (systemAbilityId) {
50 case BUNDLE_MGR_SERVICE_SYS_ABILITY_ID:
51 if (!g_bundleMgrService) {
52 g_bundleMgrService = new AppExecFwk::BundleMgrService();
53 }
54 remote = g_bundleMgrService;
55 break;
56 case ACCESSIBILITY_MANAGER_SERVICE_ID: {
57 bool notNullFlag = Accessibility::AccessibilityCommonHelper::GetInstance().GetRemoteObjectNotNullFlag();
58 if (notNullFlag) {
59 if (!g_MgrService) {
60 g_MgrService = new OHOS::Accessibility::MockAccessibleAbilityManagerServiceStub();
61 }
62 remote = g_MgrService;
63 }
64 break;
65 }
66 default:
67 GTEST_LOG_(INFO) << "This service is not dummy!!!!" << systemAbilityId;
68 break;
69 }
70 return remote;
71 }
72
GetSystemAbility(int32_t systemAbilityId,const std::string & deviceId)73 sptr<IRemoteObject> SystemAbilityManagerProxy::GetSystemAbility(int32_t systemAbilityId,
74 const std::string& deviceId)
75 {
76 return GetSystemAbility(systemAbilityId);
77 }
78
CheckSystemAbilityWrapper(int32_t code,MessageParcel & data)79 sptr<IRemoteObject> SystemAbilityManagerProxy::CheckSystemAbilityWrapper(int32_t code, MessageParcel& data)
80 {
81 return nullptr;
82 }
83
CheckSystemAbility(int32_t systemAbilityId)84 sptr<IRemoteObject> SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId)
85 {
86 return nullptr;
87 }
88
CheckSystemAbility(int32_t systemAbilityId,const std::string & deviceId)89 sptr<IRemoteObject> SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
90 {
91 return nullptr;
92 }
93
CheckSystemAbility(int32_t systemAbilityId,bool & isExist)94 sptr<IRemoteObject> SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId, bool& isExist)
95 {
96 return nullptr;
97 }
98
AddOnDemandSystemAbilityInfo(int32_t systemAbilityId,const std::u16string & localAbilityManagerName)99 int32_t SystemAbilityManagerProxy::AddOnDemandSystemAbilityInfo(int32_t systemAbilityId,
100 const std::u16string& localAbilityManagerName)
101 {
102 return -1;
103 }
104
RemoveSystemAbilityWrapper(int32_t code,MessageParcel & data)105 int32_t SystemAbilityManagerProxy::RemoveSystemAbilityWrapper(int32_t code, MessageParcel& data)
106 {
107 return -1;
108 }
109
RemoveSystemAbility(int32_t systemAbilityId)110 int32_t SystemAbilityManagerProxy::RemoveSystemAbility(int32_t systemAbilityId)
111 {
112 return -1;
113 }
114
ListSystemAbilities(unsigned int dumpFlags)115 std::vector<std::u16string> SystemAbilityManagerProxy::ListSystemAbilities(unsigned int dumpFlags)
116 {
117 std::vector<std::u16string> saNames;
118
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 return -1;
126 }
127
UnSubscribeSystemAbility(int32_t systemAbilityId,const sptr<ISystemAbilityStatusChange> & listener)128 int32_t SystemAbilityManagerProxy::UnSubscribeSystemAbility(int32_t systemAbilityId,
129 const sptr<ISystemAbilityStatusChange>& listener)
130 {
131 return -1;
132 }
133
LoadSystemAbility(int32_t systemAbilityId,const sptr<ISystemAbilityLoadCallback> & callback)134 int32_t SystemAbilityManagerProxy::LoadSystemAbility(int32_t systemAbilityId,
135 const sptr<ISystemAbilityLoadCallback>& callback)
136 {
137 return -1;
138 }
139
LoadSystemAbility(int32_t systemAbilityId,const std::string & deviceId,const sptr<ISystemAbilityLoadCallback> & callback)140 int32_t SystemAbilityManagerProxy::LoadSystemAbility(int32_t systemAbilityId, const std::string& deviceId,
141 const sptr<ISystemAbilityLoadCallback>& callback)
142 {
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 return -1;
160 }
161
AddSystemAbilityWrapper(int32_t code,MessageParcel & data)162 int32_t SystemAbilityManagerProxy::AddSystemAbilityWrapper(int32_t code, MessageParcel& data)
163 {
164 return -1;
165 }
166
AddSystemProcess(const std::u16string & procName,const sptr<IRemoteObject> & procObject)167 int32_t SystemAbilityManagerProxy::AddSystemProcess(
168 const std::u16string& procName, const sptr<IRemoteObject>& procObject)
169 {
170 return -1;
171 }
172
GetRunningSystemProcess(std::list<SystemProcessInfo> & systemProcessInfos)173 int32_t SystemAbilityManagerProxy::GetRunningSystemProcess(std::list<SystemProcessInfo>& systemProcessInfos)
174 {
175 return -1;
176 }
177
SubscribeSystemProcess(const sptr<ISystemProcessStatusChange> & listener)178 int32_t SystemAbilityManagerProxy::SubscribeSystemProcess(const sptr<ISystemProcessStatusChange>& listener)
179 {
180 return -1;
181 }
182
UnSubscribeSystemProcess(const sptr<ISystemProcessStatusChange> & listener)183 int32_t SystemAbilityManagerProxy::UnSubscribeSystemProcess(const sptr<ISystemProcessStatusChange>& listener)
184 {
185 return -1;
186 }
187
GetOnDemandReasonExtraData(int64_t extraDataId,MessageParcel & extraDataParcel)188 int32_t SystemAbilityManagerProxy::GetOnDemandReasonExtraData(int64_t extraDataId, MessageParcel& extraDataParcel)
189 {
190 return -1;
191 }
192
GetOnDemandPolicy(int32_t systemAbilityId,OnDemandPolicyType type,std::vector<SystemAbilityOnDemandEvent> & abilityOnDemandEvents)193 int32_t SystemAbilityManagerProxy::GetOnDemandPolicy(int32_t systemAbilityId, OnDemandPolicyType type,
194 std::vector<SystemAbilityOnDemandEvent>& abilityOnDemandEvents)
195 {
196 return -1;
197 }
198
UpdateOnDemandPolicy(int32_t systemAbilityId,OnDemandPolicyType type,const std::vector<SystemAbilityOnDemandEvent> & sabilityOnDemandEvents)199 int32_t SystemAbilityManagerProxy::UpdateOnDemandPolicy(int32_t systemAbilityId, OnDemandPolicyType type,
200 const std::vector<SystemAbilityOnDemandEvent>& sabilityOnDemandEvents)
201 {
202 return -1;
203 }
204 }