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