• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 const int 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,const uint32_t statFlag,const std::vector<std::string> & moduleNameList)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     const uint32_t statFlag, const std::vector<std::string> &moduleNameList)
185 {
186     if (bundleName.empty()) {
187         APP_LOGE("bundleName is empty");
188         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
189     }
190 
191     return CallService(&IInstalld::GetBundleStats, bundleName, userId, bundleStats,
192         uid, appIndex, statFlag, moduleNameList);
193 }
194 
GetAllBundleStats(const int32_t userId,std::vector<int64_t> & bundleStats,const std::vector<int32_t> & uids)195 ErrCode InstalldClient::GetAllBundleStats(const int32_t userId,
196     std::vector<int64_t> &bundleStats, const std::vector<int32_t> &uids)
197 {
198     if (uids.empty()) {
199         APP_LOGE("uids is empty");
200         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
201     }
202 
203     return CallService(&IInstalld::GetAllBundleStats, userId, bundleStats, uids);
204 }
205 
SetDirApl(const std::string & dir,const std::string & bundleName,const std::string & apl,bool isPreInstallApp,bool debug)206 ErrCode InstalldClient::SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl,
207     bool isPreInstallApp, bool debug)
208 {
209     if (dir.empty() || bundleName.empty() || apl.empty()) {
210         APP_LOGE("params are invalid");
211         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
212     }
213 
214     return CallService(&IInstalld::SetDirApl, dir, bundleName, apl, isPreInstallApp, debug);
215 }
216 
GetBundleCachePath(const std::string & dir,std::vector<std::string> & cachePath)217 ErrCode InstalldClient::GetBundleCachePath(const std::string &dir, std::vector<std::string> &cachePath)
218 {
219     if (dir.empty()) {
220         APP_LOGE("params are invalid");
221         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
222     }
223 
224     return CallService(&IInstalld::GetBundleCachePath, dir, cachePath);
225 }
226 
ResetInstalldProxy()227 void InstalldClient::ResetInstalldProxy()
228 {
229     std::lock_guard<std::mutex> lock(mutex_);
230     if ((installdProxy_ != nullptr) && (installdProxy_->AsObject() != nullptr)) {
231         installdProxy_->AsObject()->RemoveDeathRecipient(recipient_);
232     }
233     SystemAbilityHelper::UnloadSystemAbility(INSTALLD_SERVICE_ID);
234     installdProxy_ = nullptr;
235 }
236 
LoadInstalldService()237 bool InstalldClient::LoadInstalldService()
238 {
239     {
240         std::unique_lock<std::mutex> lock(loadSaMutex_);
241         loadSaFinished_ = false;
242     }
243     auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
244     if (systemAbilityMgr == nullptr) {
245         APP_LOGE("Failed to get SystemAbilityManager");
246         return false;
247     }
248     sptr<InstalldLoadCallback> loadCallback = new (std::nothrow) InstalldLoadCallback();
249     if (loadCallback == nullptr) {
250         APP_LOGE("Create load callback failed");
251         return false;
252     }
253     auto ret = systemAbilityMgr->LoadSystemAbility(INSTALLD_SERVICE_ID, loadCallback);
254     if (ret != 0) {
255         APP_LOGE("Load system ability %{public}d failed with %{public}d", INSTALLD_SERVICE_ID, ret);
256         return false;
257     }
258 
259     {
260         std::unique_lock<std::mutex> lock(loadSaMutex_);
261         auto waitStatus = loadSaCondition_.wait_for(lock, std::chrono::milliseconds(LOAD_SA_TIMEOUT_MS),
262             [this]() {
263                 return loadSaFinished_;
264             });
265         if (!waitStatus) {
266             APP_LOGE("Wait for load sa timeout");
267             return false;
268         }
269     }
270     return true;
271 }
272 
GetInstalldProxy()273 sptr<IInstalld> InstalldClient::GetInstalldProxy()
274 {
275     std::lock_guard<std::mutex> lock(getProxyMutex_);
276     if (installdProxy_ != nullptr) {
277         APP_LOGD("installd ready");
278         return installdProxy_;
279     }
280 
281     APP_LOGI("try to get installd proxy");
282     if (!LoadInstalldService()) {
283         APP_LOGE("load installd service failed");
284         return nullptr;
285     }
286     if ((installdProxy_ == nullptr) || (installdProxy_->AsObject() == nullptr)) {
287         APP_LOGE("the installd proxy or remote object is null");
288         return nullptr;
289     }
290 
291     recipient_ = new (std::nothrow) InstalldDeathRecipient();
292     if (recipient_ == nullptr) {
293         APP_LOGE("the death recipient is nullptr");
294         return nullptr;
295     }
296     installdProxy_->AsObject()->AddDeathRecipient(recipient_);
297     return installdProxy_;
298 }
299 
ScanDir(const std::string & dir,ScanMode scanMode,ResultMode resultMode,std::vector<std::string> & paths)300 ErrCode InstalldClient::ScanDir(
301     const std::string &dir, ScanMode scanMode, ResultMode resultMode, std::vector<std::string> &paths)
302 {
303     if (dir.empty()) {
304         APP_LOGE("params are invalid");
305         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
306     }
307 
308     return CallService(&IInstalld::ScanDir, dir, scanMode, resultMode, paths);
309 }
310 
MoveFile(const std::string & oldPath,const std::string & newPath)311 ErrCode InstalldClient::MoveFile(const std::string &oldPath, const std::string &newPath)
312 {
313     if (oldPath.empty() || newPath.empty()) {
314         APP_LOGE("params are invalid");
315         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
316     }
317 
318     return CallService(&IInstalld::MoveFile, oldPath, newPath);
319 }
320 
CopyFile(const std::string & oldPath,const std::string & newPath,const std::string & signatureFilePath)321 ErrCode InstalldClient::CopyFile(const std::string &oldPath, const std::string &newPath,
322     const std::string &signatureFilePath)
323 {
324     if (oldPath.empty() || newPath.empty()) {
325         APP_LOGE("params are invalid");
326         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
327     }
328 
329     return CallService(&IInstalld::CopyFile, oldPath, newPath, signatureFilePath);
330 }
331 
Mkdir(const std::string & dir,const int32_t mode,const int32_t uid,const int32_t gid)332 ErrCode InstalldClient::Mkdir(
333     const std::string &dir, const int32_t mode, const int32_t uid, const int32_t gid)
334 {
335     if (dir.empty()) {
336         APP_LOGE("params are invalid");
337         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
338     }
339 
340     return CallService(&IInstalld::Mkdir, dir, mode, uid, gid);
341 }
342 
GetFileStat(const std::string & file,FileStat & fileStat)343 ErrCode InstalldClient::GetFileStat(const std::string &file, FileStat &fileStat)
344 {
345     if (file.empty()) {
346         APP_LOGE("params are invalid");
347         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
348     }
349 
350     return CallService(&IInstalld::GetFileStat, file, fileStat);
351 }
352 
ExtractDiffFiles(const std::string & filePath,const std::string & targetPath,const std::string & cpuAbi)353 ErrCode InstalldClient::ExtractDiffFiles(const std::string &filePath, const std::string &targetPath,
354     const std::string &cpuAbi)
355 {
356     if (filePath.empty() || targetPath.empty() || cpuAbi.empty()) {
357         APP_LOGE("file path or target path or cpuAbi is empty");
358         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
359     }
360     return CallService(&IInstalld::ExtractDiffFiles, filePath, targetPath, cpuAbi);
361 }
362 
ApplyDiffPatch(const std::string & oldSoPath,const std::string & diffFilePath,const std::string & newSoPath,int32_t uid)363 ErrCode InstalldClient::ApplyDiffPatch(const std::string &oldSoPath, const std::string &diffFilePath,
364     const std::string &newSoPath, int32_t uid)
365 {
366     if (oldSoPath.empty() || diffFilePath.empty() || newSoPath.empty()) {
367         APP_LOGE("old path or diff file path or new so path is empty");
368         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
369     }
370     return CallService(&IInstalld::ApplyDiffPatch, oldSoPath, diffFilePath, newSoPath, uid);
371 }
372 
IsExistDir(const std::string & dir,bool & isExist)373 ErrCode InstalldClient::IsExistDir(const std::string &dir, bool &isExist)
374 {
375     return CallService(&IInstalld::IsExistDir, dir, isExist);
376 }
377 
IsExistFile(const std::string & path,bool & isExist)378 ErrCode InstalldClient::IsExistFile(const std::string &path, bool &isExist)
379 {
380     return CallService(&IInstalld::IsExistFile, path, isExist);
381 }
382 
IsExistApFile(const std::string & path,bool & isExist)383 ErrCode InstalldClient::IsExistApFile(const std::string &path, bool &isExist)
384 {
385     return CallService(&IInstalld::IsExistApFile, path, isExist);
386 }
387 
IsDirEmpty(const std::string & dir,bool & isDirEmpty)388 ErrCode InstalldClient::IsDirEmpty(const std::string &dir, bool &isDirEmpty)
389 {
390     return CallService(&IInstalld::IsDirEmpty, dir, isDirEmpty);
391 }
392 
ObtainQuickFixFileDir(const std::string & dir,std::vector<std::string> & dirVec)393 ErrCode InstalldClient::ObtainQuickFixFileDir(const std::string &dir, std::vector<std::string> &dirVec)
394 {
395     return CallService(&IInstalld::ObtainQuickFixFileDir, dir, dirVec);
396 }
397 
CopyFiles(const std::string & sourceDir,const std::string & destinationDir)398 ErrCode InstalldClient::CopyFiles(const std::string &sourceDir, const std::string &destinationDir)
399 {
400     return CallService(&IInstalld::CopyFiles, sourceDir, destinationDir);
401 }
402 
GetNativeLibraryFileNames(const std::string & filePath,const std::string & cpuAbi,std::vector<std::string> & fileNames)403 ErrCode InstalldClient::GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi,
404     std::vector<std::string> &fileNames)
405 {
406     return CallService(&IInstalld::GetNativeLibraryFileNames, filePath, cpuAbi, fileNames);
407 }
408 
VerifyCodeSignature(const CodeSignatureParam & codeSignatureParam)409 ErrCode InstalldClient::VerifyCodeSignature(const CodeSignatureParam &codeSignatureParam)
410 {
411     if (codeSignatureParam.modulePath.empty()) {
412         APP_LOGE("module path is empty");
413         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
414     }
415     return CallService(&IInstalld::VerifyCodeSignature, codeSignatureParam);
416 }
417 
CheckEncryption(const CheckEncryptionParam & checkEncryptionParam,bool & isEncryption)418 ErrCode InstalldClient::CheckEncryption(const CheckEncryptionParam &checkEncryptionParam, bool &isEncryption)
419 {
420     if (checkEncryptionParam.modulePath.empty()) {
421         APP_LOGE("module path is empty");
422         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
423     }
424     return CallService(&IInstalld::CheckEncryption, checkEncryptionParam, isEncryption);
425 }
426 
MoveFiles(const std::string & srcDir,const std::string & desDir)427 ErrCode InstalldClient::MoveFiles(const std::string &srcDir, const std::string &desDir)
428 {
429     if (srcDir.empty() || desDir.empty()) {
430         APP_LOGE("src dir or des dir is empty");
431         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
432     }
433     return CallService(&IInstalld::MoveFiles, srcDir, desDir);
434 }
435 
436 
ExtractDriverSoFiles(const std::string & srcPath,const std::unordered_multimap<std::string,std::string> & dirMap)437 ErrCode InstalldClient::ExtractDriverSoFiles(const std::string &srcPath,
438     const std::unordered_multimap<std::string, std::string> &dirMap)
439 {
440     if (srcPath.empty() || dirMap.empty()) {
441         APP_LOGE("src path or dir map is empty");
442         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
443     }
444     return CallService(&IInstalld::ExtractDriverSoFiles, srcPath, dirMap);
445 }
446 
VerifyCodeSignatureForHap(const CodeSignatureParam & codeSignatureParam)447 ErrCode InstalldClient::VerifyCodeSignatureForHap(const CodeSignatureParam &codeSignatureParam)
448 {
449     if (codeSignatureParam.modulePath.empty()) {
450         APP_LOGE("module path is empty");
451         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
452     }
453     return CallService(&IInstalld::VerifyCodeSignatureForHap, codeSignatureParam);
454 }
455 
DeliverySignProfile(const std::string & bundleName,int32_t profileBlockLength,const unsigned char * profileBlock)456 ErrCode InstalldClient::DeliverySignProfile(const std::string &bundleName, int32_t profileBlockLength,
457     const unsigned char *profileBlock)
458 {
459     if (bundleName.empty() || profileBlock == nullptr) {
460         APP_LOGE("bundle name or profile block is empty");
461         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
462     }
463     return CallService(&IInstalld::DeliverySignProfile, bundleName, profileBlockLength, profileBlock);
464 }
465 
RemoveSignProfile(const std::string & bundleName)466 ErrCode InstalldClient::RemoveSignProfile(const std::string &bundleName)
467 {
468     if (bundleName.empty()) {
469         APP_LOGE("bundle name is empty");
470         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
471     }
472     return CallService(&IInstalld::RemoveSignProfile, bundleName);
473 }
474 
OnLoadSystemAbilitySuccess(const sptr<IRemoteObject> & remoteObject)475 void InstalldClient::OnLoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject)
476 {
477     {
478         std::lock_guard<std::mutex> lock(mutex_);
479         installdProxy_ = iface_cast<IInstalld>(remoteObject);
480     }
481 
482     {
483         std::lock_guard<std::mutex> lock(loadSaMutex_);
484         loadSaFinished_ = true;
485         loadSaCondition_.notify_one();
486     }
487 }
488 
OnLoadSystemAbilityFail()489 void InstalldClient::OnLoadSystemAbilityFail()
490 {
491     {
492         std::lock_guard<std::mutex> lock(mutex_);
493         installdProxy_ = nullptr;
494     }
495 
496     {
497         std::lock_guard<std::mutex> lock(loadSaMutex_);
498         loadSaFinished_ = true;
499         loadSaCondition_.notify_one();
500     }
501 }
502 
StartInstalldService()503 bool InstalldClient::StartInstalldService()
504 {
505     return GetInstalldProxy() != nullptr;
506 }
507 
ExtractEncryptedSoFiles(const std::string & hapPath,const std::string & realSoFilesPath,const std::string & cpuAbi,const std::string & tmpSoPath,int32_t uid)508 ErrCode InstalldClient::ExtractEncryptedSoFiles(const std::string &hapPath, const std::string &realSoFilesPath,
509     const std::string &cpuAbi, const std::string &tmpSoPath, int32_t uid)
510 {
511     if (hapPath.empty() || tmpSoPath.empty() || cpuAbi.empty()) {
512         APP_LOGE("params are invalid");
513         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
514     }
515     return CallService(&IInstalld::ExtractEncryptedSoFiles, hapPath, realSoFilesPath, cpuAbi, tmpSoPath, uid);
516 }
517 
SetEncryptionPolicy(int32_t uid,const std::string & bundleName,const int32_t userId,std::string & keyId)518 ErrCode InstalldClient::SetEncryptionPolicy(int32_t uid, const std::string &bundleName,
519     const int32_t userId, std::string &keyId)
520 {
521     if (bundleName.empty()) {
522         APP_LOGE("bundleName is empty");
523         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
524     }
525     return CallService(&IInstalld::SetEncryptionPolicy, uid, bundleName, userId, keyId);
526 }
527 
DeleteEncryptionKeyId(const std::string & bundleName,const int32_t userId)528 ErrCode InstalldClient::DeleteEncryptionKeyId(const std::string &bundleName, const int32_t userId)
529 {
530     if (bundleName.empty()) {
531         APP_LOGE("bundleName is empty");
532         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
533     }
534     return CallService(&IInstalld::DeleteEncryptionKeyId, bundleName, userId);
535 }
536 
RemoveExtensionDir(int32_t userId,const std::vector<std::string> & extensionBundleDirs)537 ErrCode InstalldClient::RemoveExtensionDir(int32_t userId, const std::vector<std::string> &extensionBundleDirs)
538 {
539     if (extensionBundleDirs.empty() || userId < 0) {
540         APP_LOGI("extensionBundleDirs empty or userId invalid");
541         return ERR_OK;
542     }
543     return CallService(&IInstalld::RemoveExtensionDir, userId, extensionBundleDirs);
544 }
545 
IsExistExtensionDir(int32_t userId,const std::string & extensionBundleDir,bool & isExist)546 ErrCode InstalldClient::IsExistExtensionDir(int32_t userId, const std::string &extensionBundleDir, bool &isExist)
547 {
548     if (extensionBundleDir.empty() || userId < 0) {
549         APP_LOGE("extensionBundleDir is empty or userId is invalid");
550         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
551     }
552     return CallService(&IInstalld::IsExistExtensionDir, userId, extensionBundleDir, isExist);
553 }
554 
CreateExtensionDataDir(const CreateDirParam & createDirParam)555 ErrCode InstalldClient::CreateExtensionDataDir(const CreateDirParam &createDirParam)
556 {
557     if (createDirParam.bundleName.empty() || createDirParam.userId < 0
558         || createDirParam.uid < 0 || createDirParam.gid < 0 || createDirParam.extensionDirs.empty()) {
559         APP_LOGE("params are invalid");
560         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
561     }
562 
563     return CallService(&IInstalld::CreateExtensionDataDir, createDirParam);
564 }
565 
GetExtensionSandboxTypeList(std::vector<std::string> & typeList)566 ErrCode InstalldClient::GetExtensionSandboxTypeList(std::vector<std::string> &typeList)
567 {
568     return CallService(&IInstalld::GetExtensionSandboxTypeList, typeList);
569 }
570 
MoveHapToCodeDir(const std::string & originPath,const std::string & targetPath)571 ErrCode InstalldClient::MoveHapToCodeDir(const std::string &originPath, const std::string &targetPath)
572 {
573     if (originPath.empty() || targetPath.empty()) {
574         APP_LOGE("params are invalid");
575         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
576     }
577 
578     return CallService(&IInstalld::MoveHapToCodeDir, originPath, targetPath);
579 }
580 }  // namespace AppExecFwk
581 }  // namespace OHOS
582