• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 "ipc/installd_proxy.h"
17 
18 #include "ipc_types.h"
19 
20 #include "app_log_wrapper.h"
21 #include "bundle_constants.h"
22 #include "parcel_macro.h"
23 #include "string_ex.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 namespace {
28 constexpr int32_t WAIT_TIME = 3000;
29 }
30 
InstalldProxy(const sptr<IRemoteObject> & object)31 InstalldProxy::InstalldProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IInstalld>(object)
32 {
33     APP_LOGI("installd proxy instance is created");
34 }
35 
~InstalldProxy()36 InstalldProxy::~InstalldProxy()
37 {
38     APP_LOGI("installd proxy instance is destroyed");
39 }
40 
CreateBundleDir(const std::string & bundleDir)41 ErrCode InstalldProxy::CreateBundleDir(const std::string &bundleDir)
42 {
43     MessageParcel data;
44     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
45     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleDir));
46 
47     MessageParcel reply;
48     MessageOption option;
49     return TransactInstalldCmd(InstalldInterfaceCode::CREATE_BUNDLE_DIR, data, reply, option);
50 }
51 
ExtractModuleFiles(const std::string & srcModulePath,const std::string & targetPath,const std::string & targetSoPath,const std::string & cpuAbi)52 ErrCode InstalldProxy::ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath,
53     const std::string &targetSoPath, const std::string &cpuAbi)
54 {
55     MessageParcel data;
56     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
57     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(srcModulePath));
58     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(targetPath));
59     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(targetSoPath));
60     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi));
61 
62     MessageParcel reply;
63     MessageOption option;
64     return TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_MODULE_FILES, data, reply, option);
65 }
66 
ExtractFiles(const ExtractParam & extractParam)67 ErrCode InstalldProxy::ExtractFiles(const ExtractParam &extractParam)
68 {
69     MessageParcel data;
70     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
71     if (!data.WriteParcelable(&extractParam)) {
72         APP_LOGE("WriteParcelable extractParam failed.");
73         return ERR_APPEXECFWK_PARCEL_ERROR;
74     }
75 
76     MessageParcel reply;
77     MessageOption option;
78     return TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_FILES, data, reply, option);
79 }
80 
ExecuteAOT(const AOTArgs & aotArgs)81 ErrCode InstalldProxy::ExecuteAOT(const AOTArgs &aotArgs)
82 {
83     MessageParcel data;
84     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
85     if (!data.WriteParcelable(&aotArgs)) {
86         APP_LOGE("WriteParcelable aotArgs failed");
87         return ERR_APPEXECFWK_PARCEL_ERROR;
88     }
89 
90     MessageParcel reply;
91     MessageOption option;
92     return TransactInstalldCmd(InstalldInterfaceCode::EXECUTE_AOT, data, reply, option);
93 }
94 
RenameModuleDir(const std::string & oldPath,const std::string & newPath)95 ErrCode InstalldProxy::RenameModuleDir(const std::string &oldPath, const std::string &newPath)
96 {
97     MessageParcel data;
98     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
99     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(oldPath));
100     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(newPath));
101 
102     MessageParcel reply;
103     MessageOption option;
104     return TransactInstalldCmd(InstalldInterfaceCode::RENAME_MODULE_DIR, data, reply, option);
105 }
106 
CreateBundleDataDir(const CreateDirParam & createDirParam)107 ErrCode InstalldProxy::CreateBundleDataDir(const CreateDirParam &createDirParam)
108 {
109     MessageParcel data;
110     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
111     if (!data.WriteParcelable(&createDirParam)) {
112         APP_LOGE("WriteParcelable createDirParam failed.");
113         return ERR_APPEXECFWK_PARCEL_ERROR;
114     }
115 
116     MessageParcel reply;
117     MessageOption option;
118     return TransactInstalldCmd(InstalldInterfaceCode::CREATE_BUNDLE_DATA_DIR, data, reply, option);
119 }
120 
CreateBundleDataDirWithVector(const std::vector<CreateDirParam> & createDirParams)121 ErrCode InstalldProxy::CreateBundleDataDirWithVector(const std::vector<CreateDirParam> &createDirParams)
122 {
123     MessageParcel data;
124     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
125     if (createDirParams.empty()) {
126         APP_LOGE("createDirParams size is empty.");
127         return ERR_BUNDLE_MANAGER_INVALID_PARAMETER;
128     }
129     INSTALLD_PARCEL_WRITE(data, Uint32, createDirParams.size());
130     for (const auto &createDirParam : createDirParams) {
131         if (!data.WriteParcelable(&createDirParam)) {
132             APP_LOGE("WriteParcelable createDirParam failed.");
133             return ERR_APPEXECFWK_PARCEL_ERROR;
134         }
135     }
136 
137     MessageParcel reply;
138     MessageOption option;
139     return TransactInstalldCmd(InstalldInterfaceCode::CREATE_BUNDLE_DATA_DIR_WITH_VECTOR, data, reply, option);
140 }
141 
RemoveBundleDataDir(const std::string & bundleName,const int userid)142 ErrCode InstalldProxy::RemoveBundleDataDir(const std::string &bundleName, const int userid)
143 {
144     MessageParcel data;
145     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
146     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
147     INSTALLD_PARCEL_WRITE(data, Int32, userid);
148 
149     MessageParcel reply;
150     MessageOption option;
151     return TransactInstalldCmd(InstalldInterfaceCode::REMOVE_BUNDLE_DATA_DIR, data, reply, option);
152 }
153 
RemoveModuleDataDir(const std::string & ModuleName,const int userid)154 ErrCode InstalldProxy::RemoveModuleDataDir(const std::string &ModuleName, const int userid)
155 {
156     MessageParcel data;
157     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
158     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(ModuleName));
159     INSTALLD_PARCEL_WRITE(data, Int32, userid);
160 
161     MessageParcel reply;
162     MessageOption option;
163     return TransactInstalldCmd(InstalldInterfaceCode::REMOVE_MODULE_DATA_DIR, data, reply, option);
164 }
165 
RemoveDir(const std::string & dir)166 ErrCode InstalldProxy::RemoveDir(const std::string &dir)
167 {
168     MessageParcel data;
169     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
170     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
171 
172     MessageParcel reply;
173     MessageOption option(MessageOption::TF_SYNC);
174     return TransactInstalldCmd(InstalldInterfaceCode::REMOVE_DIR, data, reply, option);
175 }
176 
CleanBundleDataDir(const std::string & bundleDir)177 ErrCode InstalldProxy::CleanBundleDataDir(const std::string &bundleDir)
178 {
179     MessageParcel data;
180     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
181     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleDir));
182 
183     MessageParcel reply;
184     MessageOption option(MessageOption::TF_SYNC, WAIT_TIME);
185     return TransactInstalldCmd(InstalldInterfaceCode::CLEAN_BUNDLE_DATA_DIR, data, reply, option);
186 }
187 
CleanBundleDataDirByName(const std::string & bundleName,const int userid)188 ErrCode InstalldProxy::CleanBundleDataDirByName(const std::string &bundleName, const int userid)
189 {
190     MessageParcel data;
191     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
192     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
193     INSTALLD_PARCEL_WRITE(data, Int32, userid);
194     MessageParcel reply;
195     MessageOption option;
196     return TransactInstalldCmd(InstalldInterfaceCode::CLEAN_BUNDLE_DATA_DIR_BY_NAME, data, reply, option);
197 }
198 
GetBundleStats(const std::string & bundleName,const int32_t userId,std::vector<int64_t> & bundleStats,const int32_t uid)199 ErrCode InstalldProxy::GetBundleStats(
200     const std::string &bundleName, const int32_t userId, std::vector<int64_t> &bundleStats, const int32_t uid)
201 {
202     MessageParcel data;
203     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
204     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
205     INSTALLD_PARCEL_WRITE(data, Int32, userId);
206     INSTALLD_PARCEL_WRITE(data, Int32, uid);
207     MessageParcel reply;
208     MessageOption option(MessageOption::TF_SYNC);
209     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_BUNDLE_STATS, data, reply, option);
210     if (ret == ERR_OK) {
211         if (reply.ReadInt64Vector(&bundleStats)) {
212             return ERR_OK;
213         } else {
214             return ERR_APPEXECFWK_PARCEL_ERROR;
215         }
216     }
217     return ret;
218 }
219 
GetAllBundleStats(const std::vector<std::string> & bundleNames,const int32_t userId,std::vector<int64_t> & bundleStats,const std::vector<int32_t> & uids)220 ErrCode InstalldProxy::GetAllBundleStats(const std::vector<std::string> &bundleNames, const int32_t userId,
221     std::vector<int64_t> &bundleStats, const std::vector<int32_t> &uids)
222 {
223     uint32_t bundleNamesSize = bundleNames.size();
224     MessageParcel data;
225     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
226     INSTALLD_PARCEL_WRITE(data, Uint32, bundleNamesSize);
227     for (const auto &bundleName : bundleNames) {
228         INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
229     }
230     INSTALLD_PARCEL_WRITE(data, Int32, userId);
231     for (const auto &uid : uids) {
232         INSTALLD_PARCEL_WRITE(data, Int32, uid);
233     }
234     MessageParcel reply;
235     MessageOption option(MessageOption::TF_SYNC);
236     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_ALL_BUNDLE_STATS, data, reply, option);
237     if (ret == ERR_OK) {
238         if (reply.ReadInt64Vector(&bundleStats)) {
239             return ERR_OK;
240         } else {
241             return ERR_APPEXECFWK_PARCEL_ERROR;
242         }
243     }
244     return ret;
245 }
246 
SetDirApl(const std::string & dir,const std::string & bundleName,const std::string & apl,bool isPreInstallApp,bool debug)247 ErrCode InstalldProxy::SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl,
248     bool isPreInstallApp, bool debug)
249 {
250     MessageParcel data;
251     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
252     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
253     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
254     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(apl));
255     INSTALLD_PARCEL_WRITE(data, Bool, isPreInstallApp);
256     INSTALLD_PARCEL_WRITE(data, Bool, debug);
257 
258     MessageParcel reply;
259     MessageOption option(MessageOption::TF_SYNC);
260     return TransactInstalldCmd(InstalldInterfaceCode::SET_DIR_APL, data, reply, option);
261 }
262 
GetBundleCachePath(const std::string & dir,std::vector<std::string> & cachePath)263 ErrCode InstalldProxy::GetBundleCachePath(const std::string &dir, std::vector<std::string> &cachePath)
264 {
265     MessageParcel data;
266     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
267     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
268     MessageParcel reply;
269     MessageOption option(MessageOption::TF_SYNC);
270     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_BUNDLE_CACHE_PATH, data, reply, option);
271     if (ret == ERR_OK) {
272         if (reply.ReadStringVector(&cachePath)) {
273             return ERR_OK;
274         } else {
275             return ERR_APPEXECFWK_PARCEL_ERROR;
276         }
277     }
278     return ret;
279 }
280 
ScanDir(const std::string & dir,ScanMode scanMode,ResultMode resultMode,std::vector<std::string> & paths)281 ErrCode InstalldProxy::ScanDir(
282     const std::string &dir, ScanMode scanMode, ResultMode resultMode, std::vector<std::string> &paths)
283 {
284     MessageParcel data;
285     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
286     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
287     INSTALLD_PARCEL_WRITE(data, Int32, static_cast<int32_t>(scanMode));
288     INSTALLD_PARCEL_WRITE(data, Int32, static_cast<int32_t>(resultMode));
289 
290     MessageParcel reply;
291     MessageOption option(MessageOption::TF_SYNC);
292     auto ret = TransactInstalldCmd(InstalldInterfaceCode::SCAN_DIR, data, reply, option);
293     if (ret != ERR_OK) {
294         return ret;
295     }
296 
297     if (!reply.ReadStringVector(&paths)) {
298         return ERR_APPEXECFWK_PARCEL_ERROR;
299     }
300 
301     return ERR_OK;
302 }
303 
MoveFile(const std::string & oldPath,const std::string & newPath)304 ErrCode InstalldProxy::MoveFile(const std::string &oldPath, const std::string &newPath)
305 {
306     MessageParcel data;
307     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
308     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(oldPath));
309     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(newPath));
310 
311     MessageParcel reply;
312     MessageOption option(MessageOption::TF_SYNC);
313     return TransactInstalldCmd(InstalldInterfaceCode::MOVE_FILE, data, reply, option);
314 }
315 
CopyFile(const std::string & oldPath,const std::string & newPath,const std::string & signatureFilePath)316 ErrCode InstalldProxy::CopyFile(const std::string &oldPath, const std::string &newPath,
317     const std::string &signatureFilePath)
318 {
319     MessageParcel data;
320     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
321     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(oldPath));
322     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(newPath));
323     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(signatureFilePath));
324 
325     MessageParcel reply;
326     MessageOption option(MessageOption::TF_SYNC);
327     return TransactInstalldCmd(InstalldInterfaceCode::COPY_FILE, data, reply, option);
328 }
329 
Mkdir(const std::string & dir,const int32_t mode,const int32_t uid,const int32_t gid)330 ErrCode InstalldProxy::Mkdir(
331     const std::string &dir, const int32_t mode, const int32_t uid, const int32_t gid)
332 {
333     MessageParcel data;
334     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
335     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
336     INSTALLD_PARCEL_WRITE(data, Int32, mode);
337     INSTALLD_PARCEL_WRITE(data, Int32, uid);
338     INSTALLD_PARCEL_WRITE(data, Int32, gid);
339 
340     MessageParcel reply;
341     MessageOption option(MessageOption::TF_SYNC);
342     return TransactInstalldCmd(InstalldInterfaceCode::MKDIR, data, reply, option);
343 }
344 
GetFileStat(const std::string & file,FileStat & fileStat)345 ErrCode InstalldProxy::GetFileStat(const std::string &file, FileStat &fileStat)
346 {
347     MessageParcel data;
348     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
349     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(file));
350 
351     MessageParcel reply;
352     MessageOption option(MessageOption::TF_SYNC);
353     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_FILE_STAT, data, reply, option);
354     if (ret != ERR_OK) {
355         APP_LOGE("TransactInstalldCmd failed");
356         return ret;
357     }
358 
359     std::unique_ptr<FileStat> info(reply.ReadParcelable<FileStat>());
360     if (info == nullptr) {
361         APP_LOGE("readParcelableInfo failed");
362         return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
363     }
364 
365     fileStat = *info;
366     return ERR_OK;
367 }
368 
ExtractDiffFiles(const std::string & filePath,const std::string & targetPath,const std::string & cpuAbi)369 ErrCode InstalldProxy::ExtractDiffFiles(const std::string &filePath, const std::string &targetPath,
370     const std::string &cpuAbi)
371 {
372     MessageParcel data;
373     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
374     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(filePath));
375     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(targetPath));
376     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi));
377 
378     MessageParcel reply;
379     MessageOption option(MessageOption::TF_SYNC);
380     return TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_DIFF_FILES, data, reply, option);
381 }
382 
ApplyDiffPatch(const std::string & oldSoPath,const std::string & diffFilePath,const std::string & newSoPath,int32_t uid)383 ErrCode InstalldProxy::ApplyDiffPatch(const std::string &oldSoPath, const std::string &diffFilePath,
384     const std::string &newSoPath, int32_t uid)
385 {
386     MessageParcel data;
387     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
388     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(oldSoPath));
389     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(diffFilePath));
390     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(newSoPath));
391     INSTALLD_PARCEL_WRITE(data, Int32, uid);
392 
393     MessageParcel reply;
394     MessageOption option(MessageOption::TF_SYNC);
395     return TransactInstalldCmd(InstalldInterfaceCode::APPLY_DIFF_PATCH, data, reply, option);
396 }
397 
IsExistDir(const std::string & dir,bool & isExist)398 ErrCode InstalldProxy::IsExistDir(const std::string &dir, bool &isExist)
399 {
400     MessageParcel data;
401     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
402     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
403 
404     MessageParcel reply;
405     MessageOption option(MessageOption::TF_SYNC);
406     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_EXIST_DIR, data, reply, option);
407     if (ret != ERR_OK) {
408         APP_LOGE("TransactInstalldCmd failed");
409         return ret;
410     }
411     isExist = reply.ReadBool();
412     return ERR_OK;
413 }
414 
IsExistFile(const std::string & path,bool & isExist)415 ErrCode InstalldProxy::IsExistFile(const std::string &path, bool &isExist)
416 {
417     MessageParcel data;
418     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
419     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(path));
420 
421     MessageParcel reply;
422     MessageOption option(MessageOption::TF_SYNC);
423     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_EXIST_FILE, data, reply, option);
424     if (ret != ERR_OK) {
425         APP_LOGE("TransactInstalldCmd failed");
426         return ret;
427     }
428     isExist = reply.ReadBool();
429     return ERR_OK;
430 }
431 
IsExistApFile(const std::string & path,bool & isExist)432 ErrCode InstalldProxy::IsExistApFile(const std::string &path, bool &isExist)
433 {
434     MessageParcel data;
435     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
436     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(path));
437 
438     MessageParcel reply;
439     MessageOption option(MessageOption::TF_SYNC);
440     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_EXIST_AP_FILE, data, reply, option);
441     if (ret != ERR_OK) {
442         APP_LOGE("TransactInstalldCmd failed");
443         return ret;
444     }
445     isExist = reply.ReadBool();
446     return ERR_OK;
447 }
448 
IsDirEmpty(const std::string & dir,bool & isDirEmpty)449 ErrCode InstalldProxy::IsDirEmpty(const std::string &dir, bool &isDirEmpty)
450 {
451     MessageParcel data;
452     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
453     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
454 
455     MessageParcel reply;
456     MessageOption option(MessageOption::TF_SYNC);
457     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_DIR_EMPTY, data, reply, option);
458     if (ret != ERR_OK) {
459         APP_LOGE("TransactInstalldCmd failed");
460         return ret;
461     }
462     isDirEmpty = reply.ReadBool();
463     return ERR_OK;
464 }
465 
ObtainQuickFixFileDir(const std::string & dir,std::vector<std::string> & dirVec)466 ErrCode InstalldProxy::ObtainQuickFixFileDir(const std::string &dir, std::vector<std::string> &dirVec)
467 {
468     MessageParcel data;
469     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
470     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
471 
472     MessageParcel reply;
473     MessageOption option(MessageOption::TF_SYNC);
474     auto ret = TransactInstalldCmd(InstalldInterfaceCode::OBTAIN_QUICK_FIX_DIR, data, reply, option);
475     if (ret != ERR_OK) {
476         APP_LOGE("TransactInstalldCmd failed");
477         return ret;
478     }
479     if (!reply.ReadStringVector(&dirVec)) {
480         return ERR_APPEXECFWK_PARCEL_ERROR;
481     }
482     return ERR_OK;
483 }
484 
CopyFiles(const std::string & sourceDir,const std::string & destinationDir)485 ErrCode InstalldProxy::CopyFiles(const std::string &sourceDir, const std::string &destinationDir)
486 {
487     MessageParcel data;
488     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
489     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(sourceDir));
490     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(destinationDir));
491 
492     MessageParcel reply;
493     MessageOption option(MessageOption::TF_SYNC);
494     auto ret = TransactInstalldCmd(InstalldInterfaceCode::COPY_FILES, data, reply, option);
495     if (ret != ERR_OK) {
496         APP_LOGE("TransactInstalldCmd failed");
497         return ret;
498     }
499     return ERR_OK;
500 }
501 
GetNativeLibraryFileNames(const std::string & filePath,const std::string & cpuAbi,std::vector<std::string> & fileNames)502 ErrCode InstalldProxy::GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi,
503     std::vector<std::string> &fileNames)
504 {
505     MessageParcel data;
506     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
507     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(filePath));
508     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi));
509 
510     MessageParcel reply;
511     MessageOption option(MessageOption::TF_SYNC);
512     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_NATIVE_LIBRARY_FILE_NAMES, data, reply, option);
513     if (ret != ERR_OK) {
514         APP_LOGE("TransactInstalldCmd failed");
515         return ret;
516     }
517     if (!reply.ReadStringVector(&fileNames)) {
518         APP_LOGE("ReadStringVector failed");
519         return ERR_APPEXECFWK_PARCEL_ERROR;
520     }
521     return ERR_OK;
522 }
523 
VerifyCodeSignature(const CodeSignatureParam & codeSignatureParam)524 ErrCode InstalldProxy::VerifyCodeSignature(const CodeSignatureParam &codeSignatureParam)
525 {
526     MessageParcel data;
527     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
528     if (!data.WriteParcelable(&codeSignatureParam)) {
529         APP_LOGE("WriteParcelable codeSignatureParam failed.");
530         return ERR_APPEXECFWK_PARCEL_ERROR;
531     }
532 
533     MessageParcel reply;
534     MessageOption option(MessageOption::TF_SYNC);
535     auto ret = TransactInstalldCmd(InstalldInterfaceCode::VERIFY_CODE_SIGNATURE, data, reply, option);
536     if (ret != ERR_OK) {
537         APP_LOGE("TransactInstalldCmd failed");
538         return ret;
539     }
540     return ERR_OK;
541 }
542 
CheckEncryption(const CheckEncryptionParam & checkEncryptionParam,bool & isEncryption)543 ErrCode InstalldProxy::CheckEncryption(const CheckEncryptionParam &checkEncryptionParam, bool &isEncryption)
544 {
545     MessageParcel data;
546     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
547     if (!data.WriteParcelable(&checkEncryptionParam)) {
548         APP_LOGE("WriteParcelable checkEncryptionParam failed.");
549         return ERR_APPEXECFWK_PARCEL_ERROR;
550     }
551     MessageParcel reply;
552     MessageOption option(MessageOption::TF_SYNC);
553     auto ret = TransactInstalldCmd(InstalldInterfaceCode::CHECK_ENCRYPTION, data, reply, option);
554     if (ret != ERR_OK) {
555         APP_LOGE("TransactInstalldCmd failed");
556         return ret;
557     }
558     isEncryption = reply.ReadBool();
559     return ERR_OK;
560 }
561 
MoveFiles(const std::string & srcDir,const std::string & desDir)562 ErrCode InstalldProxy::MoveFiles(const std::string &srcDir, const std::string &desDir)
563 {
564     MessageParcel data;
565     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
566     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(srcDir));
567     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(desDir));
568 
569     MessageParcel reply;
570     MessageOption option(MessageOption::TF_SYNC);
571     auto ret = TransactInstalldCmd(InstalldInterfaceCode::MOVE_FILES, data, reply, option);
572     if (ret != ERR_OK) {
573         APP_LOGE("TransactInstalldCmd failed");
574         return ret;
575     }
576     return ERR_OK;
577 }
578 
ExtractDriverSoFiles(const std::string & srcPath,const std::unordered_multimap<std::string,std::string> & dirMap)579 ErrCode InstalldProxy::ExtractDriverSoFiles(const std::string &srcPath,
580     const std::unordered_multimap<std::string, std::string> &dirMap)
581 {
582     MessageParcel data;
583     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
584     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(srcPath));
585     INSTALLD_PARCEL_WRITE(data, Int32, static_cast<int32_t>(dirMap.size()));
586     for (auto &[orignialDir, destinedDir] : dirMap) {
587         INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(orignialDir));
588         INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(destinedDir));
589     }
590     MessageParcel reply;
591     MessageOption option(MessageOption::TF_SYNC);
592     auto ret = TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_DRIVER_SO_FILE, data, reply, option);
593     if (ret != ERR_OK) {
594         APP_LOGE("TransactInstalldCmd failed");
595         return ret;
596     }
597     return ERR_OK;
598 }
599 
ExtractEncryptedSoFiles(const std::string & hapPath,const std::string & realSoFilesPath,const std::string & cpuAbi,const std::string & tmpSoPath,int32_t uid)600 ErrCode InstalldProxy::ExtractEncryptedSoFiles(const std::string &hapPath, const std::string &realSoFilesPath,
601     const std::string &cpuAbi, const std::string &tmpSoPath, int32_t uid)
602 {
603     MessageParcel data;
604     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
605     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(hapPath));
606     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(realSoFilesPath));
607     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi));
608     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(tmpSoPath));
609     INSTALLD_PARCEL_WRITE(data, Int32, uid);
610 
611     MessageParcel reply;
612     MessageOption option(MessageOption::TF_SYNC);
613     auto ret = TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_CODED_SO_FILE, data, reply, option);
614     if (ret != ERR_OK) {
615         APP_LOGE("TransactInstalldCmd failed");
616         return ret;
617     }
618     return ERR_OK;
619 }
620 
VerifyCodeSignatureForHap(const CodeSignatureParam & codeSignatureParam)621 ErrCode InstalldProxy::VerifyCodeSignatureForHap(const CodeSignatureParam &codeSignatureParam)
622 {
623     MessageParcel data;
624     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
625     if (!data.WriteParcelable(&codeSignatureParam)) {
626         APP_LOGE("WriteParcelable codeSignatureParam failed.");
627         return ERR_APPEXECFWK_PARCEL_ERROR;
628     }
629 
630     MessageParcel reply;
631     MessageOption option(MessageOption::TF_SYNC);
632     auto ret = TransactInstalldCmd(InstalldInterfaceCode::VERIFY_CODE_SIGNATURE_FOR_HAP, data, reply, option);
633     if (ret != ERR_OK) {
634         APP_LOGE("TransactInstalldCmd failed");
635         return ret;
636     }
637     return ERR_OK;
638 }
639 
DeliverySignProfile(const std::string & bundleName,int32_t profileBlockLength,const unsigned char * profileBlock)640 ErrCode InstalldProxy::DeliverySignProfile(const std::string &bundleName, int32_t profileBlockLength,
641     const unsigned char *profileBlock)
642 {
643     if (profileBlockLength == 0 || profileBlockLength > Constants::MAX_PARCEL_CAPACITY || profileBlock == nullptr) {
644         APP_LOGE("invalid params");
645         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
646     }
647     MessageParcel data;
648     (void)data.SetMaxCapacity(Constants::MAX_PARCEL_CAPACITY);
649     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
650     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
651     INSTALLD_PARCEL_WRITE(data, Int32, profileBlockLength);
652     if (!data.WriteRawData(profileBlock, profileBlockLength)) {
653         APP_LOGE("Failed to write raw data");
654         return ERR_APPEXECFWK_PARCEL_ERROR;
655     }
656 
657     MessageParcel reply;
658     MessageOption option(MessageOption::TF_SYNC);
659     auto ret = TransactInstalldCmd(InstalldInterfaceCode::DELIVERY_SIGN_PROFILE, data, reply, option);
660     if (ret != ERR_OK) {
661         APP_LOGE("TransactInstalldCmd failed");
662         return ret;
663     }
664     return ERR_OK;
665 }
666 
RemoveSignProfile(const std::string & bundleName)667 ErrCode InstalldProxy::RemoveSignProfile(const std::string &bundleName)
668 {
669     MessageParcel data;
670     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
671     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
672 
673     MessageParcel reply;
674     MessageOption option(MessageOption::TF_SYNC);
675     auto ret = TransactInstalldCmd(InstalldInterfaceCode::REMOVE_SIGN_PROFILE, data, reply, option);
676     if (ret != ERR_OK) {
677         APP_LOGE("TransactInstalldCmd failed");
678         return ret;
679     }
680     return ERR_OK;
681 }
682 
TransactInstalldCmd(InstalldInterfaceCode code,MessageParcel & data,MessageParcel & reply,MessageOption & option)683 ErrCode InstalldProxy::TransactInstalldCmd(InstalldInterfaceCode code, MessageParcel &data, MessageParcel &reply,
684     MessageOption &option)
685 {
686     sptr<IRemoteObject> remote = Remote();
687     if (remote == nullptr) {
688         APP_LOGE("fail to send %{public}u cmd to service due to remote object is null", code);
689         return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
690     }
691 
692     if (remote->SendRequest(static_cast<uint32_t>(code), data, reply, option) != OHOS::NO_ERROR) {
693         APP_LOGE("fail to send %{public}u request to service due to transact error", code);
694         return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
695     }
696     return reply.ReadInt32();
697 }
698 }  // namespace AppExecFwk
699 }  // namespace OHOS