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