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