• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_app_mgr_service.h"
19 #include "string_ex.h"
20 #include "system_ability_definition.h"
21 #include "system_ability_manager_proxy.h"
22 #include "mock_test.h"
23 
24 namespace OHOS {
25 static uint32_t g_mockFlag = 0;
26 static sptr<AppExecFwk::MockAppMgrService> g_appMgrService = nullptr;
27 
SetAppProxyFlag(uint32_t flag)28 void SetAppProxyFlag(uint32_t flag)
29 {
30     g_mockFlag = flag;
31 }
32 
SwitchForeOrBackGround(uint32_t tokenId,int32_t flag)33 void SwitchForeOrBackGround(uint32_t tokenId, int32_t flag)
34 {
35     if (g_appMgrService == nullptr) {
36         return;
37     }
38     g_appMgrService->SwitchForeOrBackGround(tokenId, flag);
39 }
40 
GetInstance()41 SystemAbilityManagerClient& SystemAbilityManagerClient::GetInstance()
42 {
43     static auto instance = new SystemAbilityManagerClient();
44     return *instance;
45 }
46 
GetSystemAbilityManager()47 sptr<ISystemAbilityManager> SystemAbilityManagerClient::GetSystemAbilityManager()
48 {
49     if (g_mockFlag == 0) {
50         GTEST_LOG_(INFO) << "GetSystemAbilityManager: return nullptr";
51         return nullptr;
52     }
53     std::lock_guard<std::mutex> lock(systemAbilityManagerLock_);
54     if (systemAbilityManager_ != nullptr) {
55         return systemAbilityManager_;
56     }
57 
58     systemAbilityManager_ = new SystemAbilityManagerProxy(nullptr);
59     return systemAbilityManager_;
60 }
61 
GetSystemAbility(int32_t systemAbilityId)62 sptr<IRemoteObject> SystemAbilityManagerProxy::GetSystemAbility(int32_t systemAbilityId)
63 {
64     if (g_mockFlag == 1) {
65         GTEST_LOG_(INFO) << "GetSystemAbility(" << systemAbilityId << "): return nullptr";
66         return nullptr;
67     }
68     sptr<IRemoteObject> remote = nullptr;
69     switch (systemAbilityId) {
70         case APP_MGR_SERVICE_ID:
71             if (!g_appMgrService) {
72                 GTEST_LOG_(INFO) << "GetSystemAbility(" << systemAbilityId << "): return MockAppMgrService";
73                 g_appMgrService = new AppExecFwk::MockAppMgrService();
74             }
75             remote = g_appMgrService;
76             break;
77         default:
78             GTEST_LOG_(INFO) << "This service is not dummy!!!!" << systemAbilityId;
79             break;
80     }
81     return remote;
82 }
83 
GetSystemAbility(int32_t systemAbilityId,const std::string & deviceId)84 sptr<IRemoteObject> SystemAbilityManagerProxy::GetSystemAbility(int32_t systemAbilityId,
85     const std::string& deviceId)
86 {
87     return GetSystemAbility(systemAbilityId);
88 }
89 
CheckSystemAbilityWrapper(int32_t code,MessageParcel & data)90 sptr<IRemoteObject> SystemAbilityManagerProxy::CheckSystemAbilityWrapper(int32_t code, MessageParcel& data)
91 {
92     return nullptr;
93 }
94 
CheckSystemAbility(int32_t systemAbilityId)95 sptr<IRemoteObject> SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId)
96 {
97     return nullptr;
98 }
99 
CheckSystemAbility(int32_t systemAbilityId,const std::string & deviceId)100 sptr<IRemoteObject> SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
101 {
102     return nullptr;
103 }
104 
CheckSystemAbility(int32_t systemAbilityId,bool & isExist)105 sptr<IRemoteObject> SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId, bool& isExist)
106 {
107     return nullptr;
108 }
109 
AddOnDemandSystemAbilityInfo(int32_t systemAbilityId,const std::u16string & localAbilityManagerName)110 int32_t SystemAbilityManagerProxy::AddOnDemandSystemAbilityInfo(int32_t systemAbilityId,
111     const std::u16string& localAbilityManagerName)
112 {
113     return -1;
114 }
115 
RemoveSystemAbilityWrapper(int32_t code,MessageParcel & data)116 int32_t SystemAbilityManagerProxy::RemoveSystemAbilityWrapper(int32_t code, MessageParcel& data)
117 {
118     return -1;
119 }
120 
RemoveSystemAbility(int32_t systemAbilityId)121 int32_t SystemAbilityManagerProxy::RemoveSystemAbility(int32_t systemAbilityId)
122 {
123     return -1;
124 }
125 
ListSystemAbilities(unsigned int dumpFlags)126 std::vector<std::u16string> SystemAbilityManagerProxy::ListSystemAbilities(unsigned int dumpFlags)
127 {
128     std::vector<std::u16string> saNames;
129 
130     return saNames;
131 }
132 
SubscribeSystemAbility(int32_t systemAbilityId,const sptr<ISystemAbilityStatusChange> & listener)133 int32_t SystemAbilityManagerProxy::SubscribeSystemAbility(int32_t systemAbilityId,
134     const sptr<ISystemAbilityStatusChange>& listener)
135 {
136     return -1;
137 }
138 
UnSubscribeSystemAbility(int32_t systemAbilityId,const sptr<ISystemAbilityStatusChange> & listener)139 int32_t SystemAbilityManagerProxy::UnSubscribeSystemAbility(int32_t systemAbilityId,
140     const sptr<ISystemAbilityStatusChange>& listener)
141 {
142     return -1;
143 }
144 
LoadSystemAbility(int32_t systemAbilityId,const sptr<ISystemAbilityLoadCallback> & callback)145 int32_t SystemAbilityManagerProxy::LoadSystemAbility(int32_t systemAbilityId,
146     const sptr<ISystemAbilityLoadCallback>& callback)
147 {
148     return -1;
149 }
150 
LoadSystemAbility(int32_t systemAbilityId,const std::string & deviceId,const sptr<ISystemAbilityLoadCallback> & callback)151 int32_t SystemAbilityManagerProxy::LoadSystemAbility(int32_t systemAbilityId, const std::string& deviceId,
152     const sptr<ISystemAbilityLoadCallback>& callback)
153 {
154     return -1;
155 }
156 
UnloadSystemAbility(int32_t systemAbilityId)157 int32_t SystemAbilityManagerProxy::UnloadSystemAbility(int32_t systemAbilityId)
158 {
159     return -1;
160 }
161 
CancelUnloadSystemAbility(int32_t systemAbilityId)162 int32_t SystemAbilityManagerProxy::CancelUnloadSystemAbility(int32_t systemAbilityId)
163 {
164     return -1;
165 }
166 
AddSystemAbility(int32_t systemAbilityId,const sptr<IRemoteObject> & ability,const SAExtraProp & extraProp)167 int32_t SystemAbilityManagerProxy::AddSystemAbility(int32_t systemAbilityId, const sptr<IRemoteObject>& ability,
168     const SAExtraProp& extraProp)
169 {
170     return -1;
171 }
172 
AddSystemAbilityWrapper(int32_t code,MessageParcel & data)173 int32_t SystemAbilityManagerProxy::AddSystemAbilityWrapper(int32_t code, MessageParcel& data)
174 {
175     return -1;
176 }
177 
AddSystemProcess(const std::u16string & procName,const sptr<IRemoteObject> & procObject)178 int32_t SystemAbilityManagerProxy::AddSystemProcess(
179     const std::u16string& procName, const sptr<IRemoteObject>& procObject)
180 {
181     return -1;
182 }
183 
GetRunningSystemProcess(std::list<SystemProcessInfo> & systemProcessInfos)184 int32_t SystemAbilityManagerProxy::GetRunningSystemProcess(std::list<SystemProcessInfo>& systemProcessInfos)
185 {
186     return -1;
187 }
SubscribeSystemProcess(const sptr<ISystemProcessStatusChange> & listener)188 int32_t SystemAbilityManagerProxy::SubscribeSystemProcess(const sptr<ISystemProcessStatusChange>& listener)
189 {
190     return -1;
191 }
UnSubscribeSystemProcess(const sptr<ISystemProcessStatusChange> & listener)192 int32_t SystemAbilityManagerProxy::UnSubscribeSystemProcess(const sptr<ISystemProcessStatusChange>& listener)
193 {
194     return -1;
195 }
196 }