1 /*
2 * Copyright (c) 2021-2024 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 "installd_client.h"
17
18 #include "installd/installd_load_callback.h"
19 #include "installd_death_recipient.h"
20 #include "iservice_registry.h"
21 #include "system_ability_definition.h"
22 #include "system_ability_helper.h"
23
24 namespace OHOS {
25 namespace AppExecFwk {
26 namespace {
27 constexpr int16_t LOAD_SA_TIMEOUT_MS = 4 * 1000;
28 } // namespace
29
CreateBundleDir(const std::string &bundleDir)30 ErrCode InstalldClient::CreateBundleDir(const std::string &bundleDir)
31 {
32 if (bundleDir.empty()) {
33 APP_LOGE("bundle dir is empty");
34 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
35 }
36
37 return CallService(&IInstalld::CreateBundleDir, bundleDir);
38 }
39
ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath, const std::string &targetSoPath, const std::string &cpuAbi)40 ErrCode InstalldClient::ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath,
41 const std::string &targetSoPath, const std::string &cpuAbi)
42 {
43 if (srcModulePath.empty() || targetPath.empty()) {
44 APP_LOGE("src module path or target path is empty");
45 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
46 }
47
48 return CallService(&IInstalld::ExtractModuleFiles, srcModulePath, targetPath, targetSoPath, cpuAbi);
49 }
50
ExtractFiles(const ExtractParam &extractParam)51 ErrCode InstalldClient::ExtractFiles(const ExtractParam &extractParam)
52 {
53 if (extractParam.srcPath.empty() || extractParam.targetPath.empty()) {
54 APP_LOGE("src path or target path is empty");
55 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
56 }
57 return CallService(&IInstalld::ExtractFiles, extractParam);
58 }
59
ExtractHnpFiles(const std::string &hnpPackageInfo, const ExtractParam &extractParam)60 ErrCode InstalldClient::ExtractHnpFiles(const std::string &hnpPackageInfo, const ExtractParam &extractParam)
61 {
62 if (extractParam.srcPath.empty() || extractParam.targetPath.empty() || hnpPackageInfo.empty()) {
63 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
64 }
65 return CallService(&IInstalld::ExtractHnpFiles, hnpPackageInfo, extractParam);
66 }
67
ProcessBundleInstallNative(const std::string &userId, const std::string &hnpRootPath, const std::string &hapPath, const std::string &cpuAbi, const std::string &packageName)68 ErrCode InstalldClient::ProcessBundleInstallNative(const std::string &userId, const std::string &hnpRootPath,
69 const std::string &hapPath, const std::string &cpuAbi, const std::string &packageName)
70 {
71 return CallService(&IInstalld::ProcessBundleInstallNative, userId, hnpRootPath,
72 hapPath, cpuAbi, packageName);
73 }
74
ProcessBundleUnInstallNative(const std::string &userId, const std::string &packageName)75 ErrCode InstalldClient::ProcessBundleUnInstallNative(const std::string &userId, const std::string &packageName)
76 {
77 return CallService(&IInstalld::ProcessBundleUnInstallNative, userId, packageName);
78 }
79
ExecuteAOT(const AOTArgs &aotArgs, std::vector<uint8_t> &pendSignData)80 ErrCode InstalldClient::ExecuteAOT(const AOTArgs &aotArgs, std::vector<uint8_t> &pendSignData)
81 {
82 return CallService(&IInstalld::ExecuteAOT, aotArgs, pendSignData);
83 }
84
PendSignAOT(const std::string &anFileName, const std::vector<uint8_t> &signData)85 ErrCode InstalldClient::PendSignAOT(const std::string &anFileName, const std::vector<uint8_t> &signData)
86 {
87 return CallService(&IInstalld::PendSignAOT, anFileName, signData);
88 }
89
StopAOT()90 ErrCode InstalldClient::StopAOT()
91 {
92 return CallService(&IInstalld::StopAOT);
93 }
94
RenameModuleDir(const std::string &oldPath, const std::string &newPath)95 ErrCode InstalldClient::RenameModuleDir(const std::string &oldPath, const std::string &newPath)
96 {
97 if (oldPath.empty() || newPath.empty()) {
98 APP_LOGE("rename path is empty");
99 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
100 }
101
102 return CallService(&IInstalld::RenameModuleDir, oldPath, newPath);
103 }
104
CreateBundleDataDir(const CreateDirParam &createDirParam)105 ErrCode InstalldClient::CreateBundleDataDir(const CreateDirParam &createDirParam)
106 {
107 if (createDirParam.bundleName.empty() || createDirParam.userId < 0
108 || createDirParam.uid < 0 || createDirParam.gid < 0) {
109 APP_LOGE("params are invalid");
110 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
111 }
112
113 return CallService(&IInstalld::CreateBundleDataDir, createDirParam);
114 }
115
CreateBundleDataDirWithVector(const std::vector<CreateDirParam> &createDirParams)116 ErrCode InstalldClient::CreateBundleDataDirWithVector(const std::vector<CreateDirParam> &createDirParams)
117 {
118 return CallService(&IInstalld::CreateBundleDataDirWithVector, createDirParams);
119 }
120
RemoveBundleDataDir( const std::string &bundleName, const int32_t userId, bool isAtomicService)121 ErrCode InstalldClient::RemoveBundleDataDir(
122 const std::string &bundleName, const int32_t userId, bool isAtomicService)
123 {
124 if (bundleName.empty() || userId < 0) {
125 APP_LOGE("params are invalid");
126 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
127 }
128
129 return CallService(&IInstalld::RemoveBundleDataDir, bundleName, userId, isAtomicService);
130 }
131
RemoveModuleDataDir(const std::string &ModuleName, const int userid)132 ErrCode InstalldClient::RemoveModuleDataDir(const std::string &ModuleName, const int userid)
133 {
134 if (ModuleName.empty() || userid < 0) {
135 APP_LOGE("params are invalid");
136 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
137 }
138
139 return CallService(&IInstalld::RemoveModuleDataDir, ModuleName, userid);
140 }
141
RemoveDir(const std::string &dir)142 ErrCode InstalldClient::RemoveDir(const std::string &dir)
143 {
144 if (dir.empty()) {
145 APP_LOGE("dir removed is empty");
146 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
147 }
148
149 return CallService(&IInstalld::RemoveDir, dir);
150 }
151
GetDiskUsage(const std::string &dir, bool isRealPath)152 int64_t InstalldClient::GetDiskUsage(const std::string &dir, bool isRealPath)
153 {
154 if (dir.empty()) {
155 APP_LOGE("bundle dir is empty");
156 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
157 }
158
159 return CallService(&IInstalld::GetDiskUsage, dir, isRealPath);
160 }
161
CleanBundleDataDir(const std::string &bundleDir)162 ErrCode InstalldClient::CleanBundleDataDir(const std::string &bundleDir)
163 {
164 if (bundleDir.empty()) {
165 APP_LOGE("bundle dir is empty");
166 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
167 }
168
169 return CallService(&IInstalld::CleanBundleDataDir, bundleDir);
170 }
171
CleanBundleDataDirByName(const std::string &bundleName, const int userid, const int appIndex)172 ErrCode InstalldClient::CleanBundleDataDirByName(const std::string &bundleName, const int userid, const int appIndex)
173 {
174 if (bundleName.empty() || userid < 0 || appIndex < 0 || appIndex > Constants::INITIAL_SANDBOX_APP_INDEX) {
175 APP_LOGE("params are invalid");
176 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
177 }
178
179 return CallService(&IInstalld::CleanBundleDataDirByName, bundleName, userid, appIndex);
180 }
181
GetBundleStats(const std::string &bundleName, const int32_t userId, std::vector<int64_t> &bundleStats, const int32_t uid, const int32_t appIndex)182 ErrCode InstalldClient::GetBundleStats(const std::string &bundleName, const int32_t userId,
183 std::vector<int64_t> &bundleStats, const int32_t uid, const int32_t appIndex)
184 {
185 if (bundleName.empty()) {
186 APP_LOGE("bundleName is empty");
187 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
188 }
189
190 return CallService(&IInstalld::GetBundleStats, bundleName, userId, bundleStats, uid, appIndex);
191 }
192
GetAllBundleStats(const int32_t userId, std::vector<int64_t> &bundleStats, const std::vector<int32_t> &uids)193 ErrCode InstalldClient::GetAllBundleStats(const int32_t userId,
194 std::vector<int64_t> &bundleStats, const std::vector<int32_t> &uids)
195 {
196 if (uids.empty()) {
197 APP_LOGE("uids is empty");
198 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
199 }
200
201 return CallService(&IInstalld::GetAllBundleStats, userId, bundleStats, uids);
202 }
203
SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl, bool isPreInstallApp, bool debug)204 ErrCode InstalldClient::SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl,
205 bool isPreInstallApp, bool debug)
206 {
207 if (dir.empty() || bundleName.empty() || apl.empty()) {
208 APP_LOGE("params are invalid");
209 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
210 }
211
212 return CallService(&IInstalld::SetDirApl, dir, bundleName, apl, isPreInstallApp, debug);
213 }
214
GetBundleCachePath(const std::string &dir, std::vector<std::string> &cachePath)215 ErrCode InstalldClient::GetBundleCachePath(const std::string &dir, std::vector<std::string> &cachePath)
216 {
217 if (dir.empty()) {
218 APP_LOGE("params are invalid");
219 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
220 }
221
222 return CallService(&IInstalld::GetBundleCachePath, dir, cachePath);
223 }
224
ResetInstalldProxy()225 void InstalldClient::ResetInstalldProxy()
226 {
227 std::lock_guard<std::mutex> lock(mutex_);
228 if ((installdProxy_ != nullptr) && (installdProxy_->AsObject() != nullptr)) {
229 installdProxy_->AsObject()->RemoveDeathRecipient(recipient_);
230 }
231 SystemAbilityHelper::UnloadSystemAbility(INSTALLD_SERVICE_ID);
232 installdProxy_ = nullptr;
233 }
234
LoadInstalldService()235 bool InstalldClient::LoadInstalldService()
236 {
237 {
238 std::unique_lock<std::mutex> lock(loadSaMutex_);
239 loadSaFinished_ = false;
240 }
241 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
242 if (systemAbilityMgr == nullptr) {
243 APP_LOGE("Failed to get SystemAbilityManager");
244 return false;
245 }
246 sptr<InstalldLoadCallback> loadCallback = new (std::nothrow) InstalldLoadCallback();
247 if (loadCallback == nullptr) {
248 APP_LOGE("Create load callback failed");
249 return false;
250 }
251 auto ret = systemAbilityMgr->LoadSystemAbility(INSTALLD_SERVICE_ID, loadCallback);
252 if (ret != 0) {
253 APP_LOGE("Load system ability %{public}d failed with %{public}d", INSTALLD_SERVICE_ID, ret);
254 return false;
255 }
256
257 {
258 std::unique_lock<std::mutex> lock(loadSaMutex_);
259 auto waitStatus = loadSaCondition_.wait_for(lock, std::chrono::milliseconds(LOAD_SA_TIMEOUT_MS),
260 [this]() {
261 return loadSaFinished_;
262 });
263 if (!waitStatus) {
264 APP_LOGE("Wait for load sa timeout");
265 return false;
266 }
267 }
268 return true;
269 }
270
GetInstalldProxy()271 sptr<IInstalld> InstalldClient::GetInstalldProxy()
272 {
273 std::lock_guard<std::mutex> lock(getProxyMutex_);
274 if (installdProxy_ != nullptr) {
275 APP_LOGD("installd ready");
276 return installdProxy_;
277 }
278
279 APP_LOGI("try to get installd proxy");
280 if (!LoadInstalldService()) {
281 APP_LOGE("load installd service failed");
282 return nullptr;
283 }
284 if ((installdProxy_ == nullptr) || (installdProxy_->AsObject() == nullptr)) {
285 APP_LOGE("the installd proxy or remote object is null");
286 return nullptr;
287 }
288
289 recipient_ = new (std::nothrow) InstalldDeathRecipient();
290 if (recipient_ == nullptr) {
291 APP_LOGE("the death recipient is nullptr");
292 return nullptr;
293 }
294 installdProxy_->AsObject()->AddDeathRecipient(recipient_);
295 return installdProxy_;
296 }
297
ScanDir( const std::string &dir, ScanMode scanMode, ResultMode resultMode, std::vector<std::string> &paths)298 ErrCode InstalldClient::ScanDir(
299 const std::string &dir, ScanMode scanMode, ResultMode resultMode, std::vector<std::string> &paths)
300 {
301 if (dir.empty()) {
302 APP_LOGE("params are invalid");
303 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
304 }
305
306 return CallService(&IInstalld::ScanDir, dir, scanMode, resultMode, paths);
307 }
308
MoveFile(const std::string &oldPath, const std::string &newPath)309 ErrCode InstalldClient::MoveFile(const std::string &oldPath, const std::string &newPath)
310 {
311 if (oldPath.empty() || newPath.empty()) {
312 APP_LOGE("params are invalid");
313 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
314 }
315
316 return CallService(&IInstalld::MoveFile, oldPath, newPath);
317 }
318
CopyFile(const std::string &oldPath, const std::string &newPath, const std::string &signatureFilePath)319 ErrCode InstalldClient::CopyFile(const std::string &oldPath, const std::string &newPath,
320 const std::string &signatureFilePath)
321 {
322 if (oldPath.empty() || newPath.empty()) {
323 APP_LOGE("params are invalid");
324 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
325 }
326
327 return CallService(&IInstalld::CopyFile, oldPath, newPath, signatureFilePath);
328 }
329
Mkdir( const std::string &dir, const int32_t mode, const int32_t uid, const int32_t gid)330 ErrCode InstalldClient::Mkdir(
331 const std::string &dir, const int32_t mode, const int32_t uid, const int32_t gid)
332 {
333 if (dir.empty()) {
334 APP_LOGE("params are invalid");
335 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
336 }
337
338 return CallService(&IInstalld::Mkdir, dir, mode, uid, gid);
339 }
340
GetFileStat(const std::string &file, FileStat &fileStat)341 ErrCode InstalldClient::GetFileStat(const std::string &file, FileStat &fileStat)
342 {
343 if (file.empty()) {
344 APP_LOGE("params are invalid");
345 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
346 }
347
348 return CallService(&IInstalld::GetFileStat, file, fileStat);
349 }
350
ExtractDiffFiles(const std::string &filePath, const std::string &targetPath, const std::string &cpuAbi)351 ErrCode InstalldClient::ExtractDiffFiles(const std::string &filePath, const std::string &targetPath,
352 const std::string &cpuAbi)
353 {
354 if (filePath.empty() || targetPath.empty() || cpuAbi.empty()) {
355 APP_LOGE("file path or target path or cpuAbi is empty");
356 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
357 }
358 return CallService(&IInstalld::ExtractDiffFiles, filePath, targetPath, cpuAbi);
359 }
360
ApplyDiffPatch(const std::string &oldSoPath, const std::string &diffFilePath, const std::string &newSoPath, int32_t uid)361 ErrCode InstalldClient::ApplyDiffPatch(const std::string &oldSoPath, const std::string &diffFilePath,
362 const std::string &newSoPath, int32_t uid)
363 {
364 if (oldSoPath.empty() || diffFilePath.empty() || newSoPath.empty()) {
365 APP_LOGE("old path or diff file path or new so path is empty");
366 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
367 }
368 return CallService(&IInstalld::ApplyDiffPatch, oldSoPath, diffFilePath, newSoPath, uid);
369 }
370
IsExistDir(const std::string &dir, bool &isExist)371 ErrCode InstalldClient::IsExistDir(const std::string &dir, bool &isExist)
372 {
373 return CallService(&IInstalld::IsExistDir, dir, isExist);
374 }
375
IsExistFile(const std::string &path, bool &isExist)376 ErrCode InstalldClient::IsExistFile(const std::string &path, bool &isExist)
377 {
378 return CallService(&IInstalld::IsExistFile, path, isExist);
379 }
380
IsExistApFile(const std::string &path, bool &isExist)381 ErrCode InstalldClient::IsExistApFile(const std::string &path, bool &isExist)
382 {
383 return CallService(&IInstalld::IsExistApFile, path, isExist);
384 }
385
IsDirEmpty(const std::string &dir, bool &isDirEmpty)386 ErrCode InstalldClient::IsDirEmpty(const std::string &dir, bool &isDirEmpty)
387 {
388 return CallService(&IInstalld::IsDirEmpty, dir, isDirEmpty);
389 }
390
ObtainQuickFixFileDir(const std::string &dir, std::vector<std::string> &dirVec)391 ErrCode InstalldClient::ObtainQuickFixFileDir(const std::string &dir, std::vector<std::string> &dirVec)
392 {
393 return CallService(&IInstalld::ObtainQuickFixFileDir, dir, dirVec);
394 }
395
CopyFiles(const std::string &sourceDir, const std::string &destinationDir)396 ErrCode InstalldClient::CopyFiles(const std::string &sourceDir, const std::string &destinationDir)
397 {
398 return CallService(&IInstalld::CopyFiles, sourceDir, destinationDir);
399 }
400
GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi, std::vector<std::string> &fileNames)401 ErrCode InstalldClient::GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi,
402 std::vector<std::string> &fileNames)
403 {
404 return CallService(&IInstalld::GetNativeLibraryFileNames, filePath, cpuAbi, fileNames);
405 }
406
VerifyCodeSignature(const CodeSignatureParam &codeSignatureParam)407 ErrCode InstalldClient::VerifyCodeSignature(const CodeSignatureParam &codeSignatureParam)
408 {
409 if (codeSignatureParam.modulePath.empty()) {
410 APP_LOGE("module path is empty");
411 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
412 }
413 return CallService(&IInstalld::VerifyCodeSignature, codeSignatureParam);
414 }
415
CheckEncryption(const CheckEncryptionParam &checkEncryptionParam, bool &isEncryption)416 ErrCode InstalldClient::CheckEncryption(const CheckEncryptionParam &checkEncryptionParam, bool &isEncryption)
417 {
418 if (checkEncryptionParam.modulePath.empty()) {
419 APP_LOGE("module path is empty");
420 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
421 }
422 return CallService(&IInstalld::CheckEncryption, checkEncryptionParam, isEncryption);
423 }
424
MoveFiles(const std::string &srcDir, const std::string &desDir)425 ErrCode InstalldClient::MoveFiles(const std::string &srcDir, const std::string &desDir)
426 {
427 if (srcDir.empty() || desDir.empty()) {
428 APP_LOGE("src dir or des dir is empty");
429 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
430 }
431 return CallService(&IInstalld::MoveFiles, srcDir, desDir);
432 }
433
434
ExtractDriverSoFiles(const std::string &srcPath, const std::unordered_multimap<std::string, std::string> &dirMap)435 ErrCode InstalldClient::ExtractDriverSoFiles(const std::string &srcPath,
436 const std::unordered_multimap<std::string, std::string> &dirMap)
437 {
438 if (srcPath.empty() || dirMap.empty()) {
439 APP_LOGE("src path or dir map is empty");
440 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
441 }
442 return CallService(&IInstalld::ExtractDriverSoFiles, srcPath, dirMap);
443 }
444
VerifyCodeSignatureForHap(const CodeSignatureParam &codeSignatureParam)445 ErrCode InstalldClient::VerifyCodeSignatureForHap(const CodeSignatureParam &codeSignatureParam)
446 {
447 if (codeSignatureParam.modulePath.empty()) {
448 APP_LOGE("module path is empty");
449 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
450 }
451 return CallService(&IInstalld::VerifyCodeSignatureForHap, codeSignatureParam);
452 }
453
DeliverySignProfile(const std::string &bundleName, int32_t profileBlockLength, const unsigned char *profileBlock)454 ErrCode InstalldClient::DeliverySignProfile(const std::string &bundleName, int32_t profileBlockLength,
455 const unsigned char *profileBlock)
456 {
457 if (bundleName.empty() || profileBlock == nullptr) {
458 APP_LOGE("bundle name or profile block is empty");
459 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
460 }
461 return CallService(&IInstalld::DeliverySignProfile, bundleName, profileBlockLength, profileBlock);
462 }
463
RemoveSignProfile(const std::string &bundleName)464 ErrCode InstalldClient::RemoveSignProfile(const std::string &bundleName)
465 {
466 if (bundleName.empty()) {
467 APP_LOGE("bundle name is empty");
468 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
469 }
470 return CallService(&IInstalld::RemoveSignProfile, bundleName);
471 }
472
OnLoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject)473 void InstalldClient::OnLoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject)
474 {
475 {
476 std::lock_guard<std::mutex> lock(mutex_);
477 installdProxy_ = iface_cast<IInstalld>(remoteObject);
478 }
479
480 {
481 std::lock_guard<std::mutex> lock(loadSaMutex_);
482 loadSaFinished_ = true;
483 loadSaCondition_.notify_one();
484 }
485 }
486
OnLoadSystemAbilityFail()487 void InstalldClient::OnLoadSystemAbilityFail()
488 {
489 {
490 std::lock_guard<std::mutex> lock(mutex_);
491 installdProxy_ = nullptr;
492 }
493
494 {
495 std::lock_guard<std::mutex> lock(loadSaMutex_);
496 loadSaFinished_ = true;
497 loadSaCondition_.notify_one();
498 }
499 }
500
StartInstalldService()501 bool InstalldClient::StartInstalldService()
502 {
503 return GetInstalldProxy() != nullptr;
504 }
505
ExtractEncryptedSoFiles(const std::string &hapPath, const std::string &realSoFilesPath, const std::string &cpuAbi, const std::string &tmpSoPath, int32_t uid)506 ErrCode InstalldClient::ExtractEncryptedSoFiles(const std::string &hapPath, const std::string &realSoFilesPath,
507 const std::string &cpuAbi, const std::string &tmpSoPath, int32_t uid)
508 {
509 if (hapPath.empty() || tmpSoPath.empty() || cpuAbi.empty()) {
510 APP_LOGE("params are invalid");
511 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
512 }
513 return CallService(&IInstalld::ExtractEncryptedSoFiles, hapPath, realSoFilesPath, cpuAbi, tmpSoPath, uid);
514 }
515
SetEncryptionPolicy(int32_t uid, const std::string &bundleName, const int32_t userId, std::string &keyId)516 ErrCode InstalldClient::SetEncryptionPolicy(int32_t uid, const std::string &bundleName,
517 const int32_t userId, std::string &keyId)
518 {
519 if (bundleName.empty()) {
520 APP_LOGE("bundleName is empty");
521 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
522 }
523 return CallService(&IInstalld::SetEncryptionPolicy, uid, bundleName, userId, keyId);
524 }
525
DeleteEncryptionKeyId(const std::string &bundleName, const int32_t userId)526 ErrCode InstalldClient::DeleteEncryptionKeyId(const std::string &bundleName, const int32_t userId)
527 {
528 if (bundleName.empty()) {
529 APP_LOGE("bundleName is empty");
530 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
531 }
532 return CallService(&IInstalld::DeleteEncryptionKeyId, bundleName, userId);
533 }
534
RemoveExtensionDir(int32_t userId, const std::vector<std::string> &extensionBundleDirs)535 ErrCode InstalldClient::RemoveExtensionDir(int32_t userId, const std::vector<std::string> &extensionBundleDirs)
536 {
537 if (extensionBundleDirs.empty() || userId < 0) {
538 APP_LOGI("extensionBundleDirs empty or userId invalid");
539 return ERR_OK;
540 }
541 return CallService(&IInstalld::RemoveExtensionDir, userId, extensionBundleDirs);
542 }
543
IsExistExtensionDir(int32_t userId, const std::string &extensionBundleDir, bool &isExist)544 ErrCode InstalldClient::IsExistExtensionDir(int32_t userId, const std::string &extensionBundleDir, bool &isExist)
545 {
546 if (extensionBundleDir.empty() || userId < 0) {
547 APP_LOGE("extensionBundleDir is empty or userId is invalid");
548 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
549 }
550 return CallService(&IInstalld::IsExistExtensionDir, userId, extensionBundleDir, isExist);
551 }
552
CreateExtensionDataDir(const CreateDirParam &createDirParam)553 ErrCode InstalldClient::CreateExtensionDataDir(const CreateDirParam &createDirParam)
554 {
555 if (createDirParam.bundleName.empty() || createDirParam.userId < 0
556 || createDirParam.uid < 0 || createDirParam.gid < 0 || createDirParam.extensionDirs.empty()) {
557 APP_LOGE("params are invalid");
558 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
559 }
560
561 return CallService(&IInstalld::CreateExtensionDataDir, createDirParam);
562 }
563
GetExtensionSandboxTypeList(std::vector<std::string> &typeList)564 ErrCode InstalldClient::GetExtensionSandboxTypeList(std::vector<std::string> &typeList)
565 {
566 return CallService(&IInstalld::GetExtensionSandboxTypeList, typeList);
567 }
568
AddUserDirDeleteDfx(int32_t userId)569 ErrCode InstalldClient::AddUserDirDeleteDfx(int32_t userId)
570 {
571 return CallService(&IInstalld::AddUserDirDeleteDfx, userId);
572 }
573
MoveHapToCodeDir(const std::string &originPath, const std::string &targetPath)574 ErrCode InstalldClient::MoveHapToCodeDir(const std::string &originPath, const std::string &targetPath)
575 {
576 if (originPath.empty() || targetPath.empty()) {
577 APP_LOGE("params are invalid");
578 return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
579 }
580
581 return CallService(&IInstalld::MoveHapToCodeDir, originPath, targetPath);
582 }
583 } // namespace AppExecFwk
584 } // namespace OHOS
585