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