• 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 "app_log_tag_wrapper.h"
19 #include "parcel_macro.h"
20 #include "string_ex.h"
21 
22 namespace OHOS {
23 namespace AppExecFwk {
24 namespace {
25 constexpr int32_t WAIT_TIME = 3000;
26 constexpr int32_t MAX_VEC_SIZE = 1000;
27 constexpr int32_t MAX_STRING_SIZE = 1024;
28 }
29 
InstalldProxy(const sptr<IRemoteObject> & object)30 InstalldProxy::InstalldProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IInstalld>(object)
31 {
32     LOG_NOFUNC_I(BMS_TAG_INSTALLD, "installd proxy instance created");
33 }
34 
~InstalldProxy()35 InstalldProxy::~InstalldProxy()
36 {
37     LOG_NOFUNC_I(BMS_TAG_INSTALLD, "installd proxy instance destroyed");
38 }
39 
CreateBundleDir(const std::string & bundleDir)40 ErrCode InstalldProxy::CreateBundleDir(const std::string &bundleDir)
41 {
42     MessageParcel data;
43     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
44     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleDir));
45 
46     MessageParcel reply;
47     MessageOption option;
48     return TransactInstalldCmd(InstalldInterfaceCode::CREATE_BUNDLE_DIR, data, reply, option);
49 }
50 
ExtractModuleFiles(const std::string & srcModulePath,const std::string & targetPath,const std::string & targetSoPath,const std::string & cpuAbi)51 ErrCode InstalldProxy::ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath,
52     const std::string &targetSoPath, const std::string &cpuAbi)
53 {
54     MessageParcel data;
55     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
56     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(srcModulePath));
57     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(targetPath));
58     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(targetSoPath));
59     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi));
60 
61     MessageParcel reply;
62     MessageOption option;
63     return TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_MODULE_FILES, data, reply, option);
64 }
65 
ExtractFiles(const ExtractParam & extractParam)66 ErrCode InstalldProxy::ExtractFiles(const ExtractParam &extractParam)
67 {
68     MessageParcel data;
69     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
70     if (!data.WriteParcelable(&extractParam)) {
71         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable extractParam failed");
72         return ERR_APPEXECFWK_PARCEL_ERROR;
73     }
74 
75     MessageParcel reply;
76     MessageOption option;
77     return TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_FILES, data, reply, option);
78 }
79 
ExtractHnpFiles(const std::string & hnpPackageInfo,const ExtractParam & extractParam)80 ErrCode InstalldProxy::ExtractHnpFiles(const std::string &hnpPackageInfo, const ExtractParam &extractParam)
81 {
82     MessageParcel data;
83     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
84     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(hnpPackageInfo));
85     if (!data.WriteParcelable(&extractParam)) {
86         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable extractParam failed");
87         return ERR_APPEXECFWK_PARCEL_ERROR;
88     }
89 
90     MessageParcel reply;
91     MessageOption option;
92     return TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_HNP_FILES, data, reply, option);
93 }
94 
ProcessBundleInstallNative(const std::string & userId,const std::string & hnpRootPath,const std::string & hapPath,const std::string & cpuAbi,const std::string & packageName)95 ErrCode InstalldProxy::ProcessBundleInstallNative(const std::string &userId, const std::string &hnpRootPath,
96     const std::string &hapPath, const std::string &cpuAbi, const std::string &packageName)
97 {
98     MessageParcel data;
99     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
100     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(userId));
101     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(hnpRootPath));
102     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(hapPath));
103     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi));
104     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(packageName));
105 
106     MessageParcel reply;
107     MessageOption option;
108     return TransactInstalldCmd(InstalldInterfaceCode::INSTALL_NATIVE, data, reply, option);
109 }
110 
ProcessBundleUnInstallNative(const std::string & userId,const std::string & packageName)111 ErrCode InstalldProxy::ProcessBundleUnInstallNative(const std::string &userId, const std::string &packageName)
112 {
113     MessageParcel data;
114     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
115     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(userId));
116     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(packageName));
117 
118     MessageParcel reply;
119     MessageOption option;
120     return TransactInstalldCmd(InstalldInterfaceCode::UNINSTALL_NATIVE, data, reply, option);
121 }
122 
ExecuteAOT(const AOTArgs & aotArgs,std::vector<uint8_t> & pendSignData)123 ErrCode InstalldProxy::ExecuteAOT(const AOTArgs &aotArgs, std::vector<uint8_t> &pendSignData)
124 {
125     MessageParcel data;
126     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
127     if (!data.WriteParcelable(&aotArgs)) {
128         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable aotArgs failed");
129         return ERR_APPEXECFWK_PARCEL_ERROR;
130     }
131 
132     MessageParcel reply;
133     MessageOption option;
134     ErrCode ret = TransactInstalldCmd(InstalldInterfaceCode::EXECUTE_AOT, data, reply, option);
135     if (ret == ERR_APPEXECFWK_INSTALLD_SIGN_AOT_DISABLE) {
136         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd ExecuteAOT failed when AOTSign disable");
137         if (!reply.ReadUInt8Vector(&pendSignData)) {
138             LOG_E(BMS_TAG_INSTALLD, "ReadUInt8Vector ExecuteAOT failed");
139             return ERR_APPEXECFWK_PARCEL_ERROR;
140         }
141     }
142     return ret;
143 }
144 
PendSignAOT(const std::string & anFileName,const std::vector<uint8_t> & signData)145 ErrCode InstalldProxy::PendSignAOT(const std::string &anFileName, const std::vector<uint8_t> &signData)
146 {
147     MessageParcel data;
148     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
149     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(anFileName));
150     if (!data.WriteUInt8Vector(signData)) {
151         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable PendSignAOT failed");
152         return ERR_APPEXECFWK_PARCEL_ERROR;
153     }
154 
155     MessageParcel reply;
156     MessageOption option;
157     return TransactInstalldCmd(InstalldInterfaceCode::PEND_SIGN_AOT, data, reply, option);
158 }
159 
StopAOT()160 ErrCode InstalldProxy::StopAOT()
161 {
162     MessageParcel data;
163     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
164 
165     MessageParcel reply;
166     MessageOption option;
167     return TransactInstalldCmd(InstalldInterfaceCode::STOP_AOT, data, reply, option);
168 }
169 
RenameModuleDir(const std::string & oldPath,const std::string & newPath)170 ErrCode InstalldProxy::RenameModuleDir(const std::string &oldPath, const std::string &newPath)
171 {
172     MessageParcel data;
173     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
174     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(oldPath));
175     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(newPath));
176 
177     MessageParcel reply;
178     MessageOption option;
179     return TransactInstalldCmd(InstalldInterfaceCode::RENAME_MODULE_DIR, data, reply, option);
180 }
181 
CreateBundleDataDir(const CreateDirParam & createDirParam)182 ErrCode InstalldProxy::CreateBundleDataDir(const CreateDirParam &createDirParam)
183 {
184     MessageParcel data;
185     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
186     if (!data.WriteParcelable(&createDirParam)) {
187         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable createDirParam failed");
188         return ERR_APPEXECFWK_PARCEL_ERROR;
189     }
190 
191     MessageParcel reply;
192     MessageOption option;
193     return TransactInstalldCmd(InstalldInterfaceCode::CREATE_BUNDLE_DATA_DIR, data, reply, option);
194 }
195 
CreateBundleDataDirWithVector(const std::vector<CreateDirParam> & createDirParams)196 ErrCode InstalldProxy::CreateBundleDataDirWithVector(const std::vector<CreateDirParam> &createDirParams)
197 {
198     MessageParcel data;
199     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
200     if (createDirParams.empty()) {
201         LOG_E(BMS_TAG_INSTALLD, "createDirParams size is empty");
202         return ERR_BUNDLE_MANAGER_INVALID_PARAMETER;
203     }
204     INSTALLD_PARCEL_WRITE(data, Uint32, createDirParams.size());
205     for (const auto &createDirParam : createDirParams) {
206         if (!data.WriteParcelable(&createDirParam)) {
207             LOG_E(BMS_TAG_INSTALLD, "WriteParcelable createDirParam failed");
208             return ERR_APPEXECFWK_PARCEL_ERROR;
209         }
210     }
211 
212     MessageParcel reply;
213     MessageOption option;
214     return TransactInstalldCmd(InstalldInterfaceCode::CREATE_BUNDLE_DATA_DIR_WITH_VECTOR, data, reply, option);
215 }
216 
RemoveBundleDataDir(const std::string & bundleName,const int userId,bool isAtomicService)217 ErrCode InstalldProxy::RemoveBundleDataDir(const std::string &bundleName, const int userId, bool isAtomicService)
218 {
219     MessageParcel data;
220     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
221     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
222     INSTALLD_PARCEL_WRITE(data, Int32, userId);
223     INSTALLD_PARCEL_WRITE(data, Bool, isAtomicService);
224 
225     MessageParcel reply;
226     MessageOption option;
227     return TransactInstalldCmd(InstalldInterfaceCode::REMOVE_BUNDLE_DATA_DIR, data, reply, option);
228 }
229 
RemoveModuleDataDir(const std::string & ModuleName,const int userid)230 ErrCode InstalldProxy::RemoveModuleDataDir(const std::string &ModuleName, const int userid)
231 {
232     MessageParcel data;
233     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
234     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(ModuleName));
235     INSTALLD_PARCEL_WRITE(data, Int32, userid);
236 
237     MessageParcel reply;
238     MessageOption option;
239     return TransactInstalldCmd(InstalldInterfaceCode::REMOVE_MODULE_DATA_DIR, data, reply, option);
240 }
241 
RemoveDir(const std::string & dir)242 ErrCode InstalldProxy::RemoveDir(const std::string &dir)
243 {
244     MessageParcel data;
245     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
246     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
247 
248     MessageParcel reply;
249     MessageOption option(MessageOption::TF_SYNC);
250     return TransactInstalldCmd(InstalldInterfaceCode::REMOVE_DIR, data, reply, option);
251 }
252 
GetDiskUsage(const std::string & dir,bool isRealPath)253 int64_t InstalldProxy::GetDiskUsage(const std::string &dir, bool isRealPath)
254 {
255     MessageParcel data;
256     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
257     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
258     INSTALLD_PARCEL_WRITE(data, Bool, isRealPath);
259 
260     MessageParcel reply;
261     MessageOption option(MessageOption::TF_SYNC, WAIT_TIME);
262     return TransactInstalldCmd(InstalldInterfaceCode::GET_DISK_USAGE, data, reply, option);
263 }
264 
CleanBundleDataDir(const std::string & bundleDir)265 ErrCode InstalldProxy::CleanBundleDataDir(const std::string &bundleDir)
266 {
267     MessageParcel data;
268     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
269     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleDir));
270 
271     MessageParcel reply;
272     MessageOption option(MessageOption::TF_SYNC, WAIT_TIME);
273     return TransactInstalldCmd(InstalldInterfaceCode::CLEAN_BUNDLE_DATA_DIR, data, reply, option);
274 }
275 
CleanBundleDataDirByName(const std::string & bundleName,const int userid,const int appIndex)276 ErrCode InstalldProxy::CleanBundleDataDirByName(const std::string &bundleName, const int userid, const int appIndex)
277 {
278     MessageParcel data;
279     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
280     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
281     INSTALLD_PARCEL_WRITE(data, Int32, userid);
282     INSTALLD_PARCEL_WRITE(data, Int32, appIndex);
283     MessageParcel reply;
284     MessageOption option;
285     return TransactInstalldCmd(InstalldInterfaceCode::CLEAN_BUNDLE_DATA_DIR_BY_NAME, data, reply, option);
286 }
287 
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)288 ErrCode InstalldProxy::GetBundleStats(const std::string &bundleName, const int32_t userId,
289     std::vector<int64_t> &bundleStats, const int32_t uid, const int32_t appIndex,
290     const uint32_t statFlag, const std::vector<std::string> &moduleNameList)
291 {
292     MessageParcel data;
293     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
294     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
295     INSTALLD_PARCEL_WRITE(data, Int32, userId);
296     INSTALLD_PARCEL_WRITE(data, Int32, uid);
297     INSTALLD_PARCEL_WRITE(data, Int32, appIndex);
298     INSTALLD_PARCEL_WRITE(data, Uint32, statFlag);
299     if (!data.WriteInt32(moduleNameList.size())) {
300         LOG_E(BMS_TAG_INSTALLD, "GetBundleStats failed: write module name count fail");
301         return ERR_APPEXECFWK_PARCEL_ERROR;
302     }
303     for (size_t i = 0; i < moduleNameList.size(); i++) {
304         if (!data.WriteString(moduleNameList[i])) {
305             LOG_E(BMS_TAG_INSTALLD, "WriteParcelable moduleNames:[%{public}s] failed",
306                 moduleNameList[i].c_str());
307             return ERR_APPEXECFWK_PARCEL_ERROR;
308         }
309     }
310     MessageParcel reply;
311     MessageOption option(MessageOption::TF_SYNC);
312     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_BUNDLE_STATS, data, reply, option);
313     if (ret == ERR_OK) {
314         if (reply.ReadInt64Vector(&bundleStats)) {
315             return ERR_OK;
316         } else {
317             return ERR_APPEXECFWK_PARCEL_ERROR;
318         }
319     }
320     return ret;
321 }
322 
GetAllBundleStats(const int32_t userId,std::vector<int64_t> & bundleStats,const std::vector<int32_t> & uids)323 ErrCode InstalldProxy::GetAllBundleStats(const int32_t userId,
324     std::vector<int64_t> &bundleStats, const std::vector<int32_t> &uids)
325 {
326     MessageParcel data;
327     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
328     INSTALLD_PARCEL_WRITE(data, Int32, userId);
329     uint32_t uidSize = uids.size();
330     INSTALLD_PARCEL_WRITE(data, Uint32, uidSize);
331     for (const auto &uid : uids) {
332         INSTALLD_PARCEL_WRITE(data, Int32, uid);
333     }
334     MessageParcel reply;
335     MessageOption option(MessageOption::TF_SYNC);
336     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_ALL_BUNDLE_STATS, data, reply, option);
337     if (ret == ERR_OK) {
338         if (!reply.ReadInt64Vector(&bundleStats)) {
339             return ERR_APPEXECFWK_PARCEL_ERROR;
340         }
341         return ERR_OK;
342     }
343     return ret;
344 }
345 
SetDirApl(const std::string & dir,const std::string & bundleName,const std::string & apl,bool isPreInstallApp,bool debug)346 ErrCode InstalldProxy::SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl,
347     bool isPreInstallApp, bool debug)
348 {
349     MessageParcel data;
350     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
351     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
352     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
353     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(apl));
354     INSTALLD_PARCEL_WRITE(data, Bool, isPreInstallApp);
355     INSTALLD_PARCEL_WRITE(data, Bool, debug);
356 
357     MessageParcel reply;
358     MessageOption option(MessageOption::TF_SYNC);
359     return TransactInstalldCmd(InstalldInterfaceCode::SET_DIR_APL, data, reply, option);
360 }
361 
GetBundleCachePath(const std::string & dir,std::vector<std::string> & cachePath)362 ErrCode InstalldProxy::GetBundleCachePath(const std::string &dir, std::vector<std::string> &cachePath)
363 {
364     MessageParcel data;
365     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
366     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
367     MessageParcel reply;
368     MessageOption option(MessageOption::TF_SYNC);
369     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_BUNDLE_CACHE_PATH, data, reply, option);
370     if (ret == ERR_OK) {
371         if (reply.ReadStringVector(&cachePath)) {
372             return ERR_OK;
373         } else {
374             return ERR_APPEXECFWK_PARCEL_ERROR;
375         }
376     }
377     return ret;
378 }
379 
ScanDir(const std::string & dir,ScanMode scanMode,ResultMode resultMode,std::vector<std::string> & paths)380 ErrCode InstalldProxy::ScanDir(
381     const std::string &dir, ScanMode scanMode, ResultMode resultMode, std::vector<std::string> &paths)
382 {
383     MessageParcel data;
384     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
385     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
386     INSTALLD_PARCEL_WRITE(data, Int32, static_cast<int32_t>(scanMode));
387     INSTALLD_PARCEL_WRITE(data, Int32, static_cast<int32_t>(resultMode));
388 
389     MessageParcel reply;
390     MessageOption option(MessageOption::TF_SYNC);
391     auto ret = TransactInstalldCmd(InstalldInterfaceCode::SCAN_DIR, data, reply, option);
392     if (ret != ERR_OK) {
393         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
394         return ret;
395     }
396 
397     if (!reply.ReadStringVector(&paths)) {
398         return ERR_APPEXECFWK_PARCEL_ERROR;
399     }
400 
401     return ERR_OK;
402 }
403 
MoveFile(const std::string & oldPath,const std::string & newPath)404 ErrCode InstalldProxy::MoveFile(const std::string &oldPath, const std::string &newPath)
405 {
406     MessageParcel data;
407     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
408     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(oldPath));
409     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(newPath));
410 
411     MessageParcel reply;
412     MessageOption option(MessageOption::TF_SYNC);
413     return TransactInstalldCmd(InstalldInterfaceCode::MOVE_FILE, data, reply, option);
414 }
415 
CopyFile(const std::string & oldPath,const std::string & newPath,const std::string & signatureFilePath)416 ErrCode InstalldProxy::CopyFile(const std::string &oldPath, const std::string &newPath,
417     const std::string &signatureFilePath)
418 {
419     MessageParcel data;
420     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
421     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(oldPath));
422     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(newPath));
423     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(signatureFilePath));
424 
425     MessageParcel reply;
426     MessageOption option(MessageOption::TF_SYNC);
427     return TransactInstalldCmd(InstalldInterfaceCode::COPY_FILE, data, reply, option);
428 }
429 
Mkdir(const std::string & dir,const int32_t mode,const int32_t uid,const int32_t gid)430 ErrCode InstalldProxy::Mkdir(
431     const std::string &dir, const int32_t mode, const int32_t uid, const int32_t gid)
432 {
433     MessageParcel data;
434     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
435     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
436     INSTALLD_PARCEL_WRITE(data, Int32, mode);
437     INSTALLD_PARCEL_WRITE(data, Int32, uid);
438     INSTALLD_PARCEL_WRITE(data, Int32, gid);
439 
440     MessageParcel reply;
441     MessageOption option(MessageOption::TF_SYNC);
442     return TransactInstalldCmd(InstalldInterfaceCode::MKDIR, data, reply, option);
443 }
444 
GetFileStat(const std::string & file,FileStat & fileStat)445 ErrCode InstalldProxy::GetFileStat(const std::string &file, FileStat &fileStat)
446 {
447     MessageParcel data;
448     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
449     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(file));
450 
451     MessageParcel reply;
452     MessageOption option(MessageOption::TF_SYNC);
453     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_FILE_STAT, data, reply, option);
454     if (ret != ERR_OK) {
455         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
456         return ret;
457     }
458 
459     std::unique_ptr<FileStat> info(reply.ReadParcelable<FileStat>());
460     if (info == nullptr) {
461         LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
462         return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
463     }
464 
465     fileStat = *info;
466     return ERR_OK;
467 }
468 
ExtractDiffFiles(const std::string & filePath,const std::string & targetPath,const std::string & cpuAbi)469 ErrCode InstalldProxy::ExtractDiffFiles(const std::string &filePath, const std::string &targetPath,
470     const std::string &cpuAbi)
471 {
472     MessageParcel data;
473     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
474     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(filePath));
475     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(targetPath));
476     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi));
477 
478     MessageParcel reply;
479     MessageOption option(MessageOption::TF_SYNC);
480     return TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_DIFF_FILES, data, reply, option);
481 }
482 
ApplyDiffPatch(const std::string & oldSoPath,const std::string & diffFilePath,const std::string & newSoPath,int32_t uid)483 ErrCode InstalldProxy::ApplyDiffPatch(const std::string &oldSoPath, const std::string &diffFilePath,
484     const std::string &newSoPath, int32_t uid)
485 {
486     MessageParcel data;
487     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
488     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(oldSoPath));
489     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(diffFilePath));
490     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(newSoPath));
491     INSTALLD_PARCEL_WRITE(data, Int32, uid);
492 
493     MessageParcel reply;
494     MessageOption option(MessageOption::TF_SYNC);
495     return TransactInstalldCmd(InstalldInterfaceCode::APPLY_DIFF_PATCH, data, reply, option);
496 }
497 
IsExistDir(const std::string & dir,bool & isExist)498 ErrCode InstalldProxy::IsExistDir(const std::string &dir, bool &isExist)
499 {
500     MessageParcel data;
501     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
502     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
503 
504     MessageParcel reply;
505     MessageOption option(MessageOption::TF_SYNC);
506     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_EXIST_DIR, data, reply, option);
507     if (ret != ERR_OK) {
508         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
509         return ret;
510     }
511     isExist = reply.ReadBool();
512     return ERR_OK;
513 }
514 
IsExistFile(const std::string & path,bool & isExist)515 ErrCode InstalldProxy::IsExistFile(const std::string &path, bool &isExist)
516 {
517     MessageParcel data;
518     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
519     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(path));
520 
521     MessageParcel reply;
522     MessageOption option(MessageOption::TF_SYNC);
523     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_EXIST_FILE, data, reply, option);
524     if (ret != ERR_OK) {
525         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
526         return ret;
527     }
528     isExist = reply.ReadBool();
529     return ERR_OK;
530 }
531 
IsExistApFile(const std::string & path,bool & isExist)532 ErrCode InstalldProxy::IsExistApFile(const std::string &path, bool &isExist)
533 {
534     MessageParcel data;
535     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
536     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(path));
537 
538     MessageParcel reply;
539     MessageOption option(MessageOption::TF_SYNC);
540     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_EXIST_AP_FILE, data, reply, option);
541     if (ret != ERR_OK) {
542         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
543         return ret;
544     }
545     isExist = reply.ReadBool();
546     return ERR_OK;
547 }
548 
IsDirEmpty(const std::string & dir,bool & isDirEmpty)549 ErrCode InstalldProxy::IsDirEmpty(const std::string &dir, bool &isDirEmpty)
550 {
551     MessageParcel data;
552     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
553     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
554 
555     MessageParcel reply;
556     MessageOption option(MessageOption::TF_SYNC);
557     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_DIR_EMPTY, data, reply, option);
558     if (ret != ERR_OK) {
559         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
560         return ret;
561     }
562     isDirEmpty = reply.ReadBool();
563     return ERR_OK;
564 }
565 
ObtainQuickFixFileDir(const std::string & dir,std::vector<std::string> & dirVec)566 ErrCode InstalldProxy::ObtainQuickFixFileDir(const std::string &dir, std::vector<std::string> &dirVec)
567 {
568     MessageParcel data;
569     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
570     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
571 
572     MessageParcel reply;
573     MessageOption option(MessageOption::TF_SYNC);
574     auto ret = TransactInstalldCmd(InstalldInterfaceCode::OBTAIN_QUICK_FIX_DIR, data, reply, option);
575     if (ret != ERR_OK) {
576         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
577         return ret;
578     }
579     if (!reply.ReadStringVector(&dirVec)) {
580         return ERR_APPEXECFWK_PARCEL_ERROR;
581     }
582     return ERR_OK;
583 }
584 
CopyFiles(const std::string & sourceDir,const std::string & destinationDir)585 ErrCode InstalldProxy::CopyFiles(const std::string &sourceDir, const std::string &destinationDir)
586 {
587     MessageParcel data;
588     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
589     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(sourceDir));
590     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(destinationDir));
591 
592     MessageParcel reply;
593     MessageOption option(MessageOption::TF_SYNC);
594     auto ret = TransactInstalldCmd(InstalldInterfaceCode::COPY_FILES, data, reply, option);
595     if (ret != ERR_OK) {
596         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
597         return ret;
598     }
599     return ERR_OK;
600 }
601 
GetNativeLibraryFileNames(const std::string & filePath,const std::string & cpuAbi,std::vector<std::string> & fileNames)602 ErrCode InstalldProxy::GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi,
603     std::vector<std::string> &fileNames)
604 {
605     MessageParcel data;
606     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
607     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(filePath));
608     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi));
609 
610     MessageParcel reply;
611     MessageOption option(MessageOption::TF_SYNC);
612     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_NATIVE_LIBRARY_FILE_NAMES, data, reply, option);
613     if (ret != ERR_OK) {
614         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
615         return ret;
616     }
617     if (!reply.ReadStringVector(&fileNames)) {
618         LOG_E(BMS_TAG_INSTALLD, "ReadStringVector failed");
619         return ERR_APPEXECFWK_PARCEL_ERROR;
620     }
621     return ERR_OK;
622 }
623 
VerifyCodeSignature(const CodeSignatureParam & codeSignatureParam)624 ErrCode InstalldProxy::VerifyCodeSignature(const CodeSignatureParam &codeSignatureParam)
625 {
626     MessageParcel data;
627     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
628     if (!data.WriteParcelable(&codeSignatureParam)) {
629         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable codeSignatureParam failed");
630         return ERR_APPEXECFWK_PARCEL_ERROR;
631     }
632 
633     MessageParcel reply;
634     MessageOption option(MessageOption::TF_SYNC);
635     auto ret = TransactInstalldCmd(InstalldInterfaceCode::VERIFY_CODE_SIGNATURE, data, reply, option);
636     if (ret != ERR_OK) {
637         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
638         return ret;
639     }
640     return ERR_OK;
641 }
642 
CheckEncryption(const CheckEncryptionParam & checkEncryptionParam,bool & isEncryption)643 ErrCode InstalldProxy::CheckEncryption(const CheckEncryptionParam &checkEncryptionParam, bool &isEncryption)
644 {
645     MessageParcel data;
646     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
647     if (!data.WriteParcelable(&checkEncryptionParam)) {
648         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable checkEncryptionParam failed");
649         return ERR_APPEXECFWK_PARCEL_ERROR;
650     }
651     MessageParcel reply;
652     MessageOption option(MessageOption::TF_SYNC);
653     auto ret = TransactInstalldCmd(InstalldInterfaceCode::CHECK_ENCRYPTION, data, reply, option);
654     if (ret != ERR_OK) {
655         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
656         return ret;
657     }
658     isEncryption = reply.ReadBool();
659     return ERR_OK;
660 }
661 
MoveFiles(const std::string & srcDir,const std::string & desDir)662 ErrCode InstalldProxy::MoveFiles(const std::string &srcDir, const std::string &desDir)
663 {
664     MessageParcel data;
665     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
666     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(srcDir));
667     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(desDir));
668 
669     MessageParcel reply;
670     MessageOption option(MessageOption::TF_SYNC);
671     auto ret = TransactInstalldCmd(InstalldInterfaceCode::MOVE_FILES, data, reply, option);
672     if (ret != ERR_OK) {
673         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
674         return ret;
675     }
676     return ERR_OK;
677 }
678 
ExtractDriverSoFiles(const std::string & srcPath,const std::unordered_multimap<std::string,std::string> & dirMap)679 ErrCode InstalldProxy::ExtractDriverSoFiles(const std::string &srcPath,
680     const std::unordered_multimap<std::string, std::string> &dirMap)
681 {
682     MessageParcel data;
683     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
684     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(srcPath));
685     INSTALLD_PARCEL_WRITE(data, Int32, static_cast<int32_t>(dirMap.size()));
686     for (auto &[orignialDir, destinedDir] : dirMap) {
687         INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(orignialDir));
688         INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(destinedDir));
689     }
690     MessageParcel reply;
691     MessageOption option(MessageOption::TF_SYNC);
692     auto ret = TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_DRIVER_SO_FILE, data, reply, option);
693     if (ret != ERR_OK) {
694         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
695         return ret;
696     }
697     return ERR_OK;
698 }
699 
ExtractEncryptedSoFiles(const std::string & hapPath,const std::string & realSoFilesPath,const std::string & cpuAbi,const std::string & tmpSoPath,int32_t uid)700 ErrCode InstalldProxy::ExtractEncryptedSoFiles(const std::string &hapPath, const std::string &realSoFilesPath,
701     const std::string &cpuAbi, const std::string &tmpSoPath, int32_t uid)
702 {
703     MessageParcel data;
704     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
705     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(hapPath));
706     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(realSoFilesPath));
707     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi));
708     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(tmpSoPath));
709     INSTALLD_PARCEL_WRITE(data, Int32, uid);
710 
711     MessageParcel reply;
712     MessageOption option(MessageOption::TF_SYNC);
713     auto ret = TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_CODED_SO_FILE, data, reply, option);
714     if (ret != ERR_OK) {
715         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
716         return ret;
717     }
718     return ERR_OK;
719 }
720 
VerifyCodeSignatureForHap(const CodeSignatureParam & codeSignatureParam)721 ErrCode InstalldProxy::VerifyCodeSignatureForHap(const CodeSignatureParam &codeSignatureParam)
722 {
723     MessageParcel data;
724     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
725     if (!data.WriteParcelable(&codeSignatureParam)) {
726         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable codeSignatureParam failed");
727         return ERR_APPEXECFWK_PARCEL_ERROR;
728     }
729 
730     MessageParcel reply;
731     MessageOption option(MessageOption::TF_SYNC);
732     auto ret = TransactInstalldCmd(InstalldInterfaceCode::VERIFY_CODE_SIGNATURE_FOR_HAP, data, reply, option);
733     if (ret != ERR_OK) {
734         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
735         return ret;
736     }
737     return ERR_OK;
738 }
739 
DeliverySignProfile(const std::string & bundleName,int32_t profileBlockLength,const unsigned char * profileBlock)740 ErrCode InstalldProxy::DeliverySignProfile(const std::string &bundleName, int32_t profileBlockLength,
741     const unsigned char *profileBlock)
742 {
743     if (profileBlockLength == 0 || profileBlockLength > Constants::MAX_PARCEL_CAPACITY || profileBlock == nullptr) {
744         LOG_E(BMS_TAG_INSTALLD, "invalid params");
745         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
746     }
747     MessageParcel data;
748     (void)data.SetMaxCapacity(Constants::MAX_PARCEL_CAPACITY);
749     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
750     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
751     INSTALLD_PARCEL_WRITE(data, Int32, profileBlockLength);
752     if (!data.WriteRawData(profileBlock, profileBlockLength)) {
753         LOG_E(BMS_TAG_INSTALLD, "Failed to write raw data");
754         return ERR_APPEXECFWK_PARCEL_ERROR;
755     }
756 
757     MessageParcel reply;
758     MessageOption option(MessageOption::TF_SYNC);
759     auto ret = TransactInstalldCmd(InstalldInterfaceCode::DELIVERY_SIGN_PROFILE, data, reply, option);
760     if (ret != ERR_OK) {
761         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
762         return ret;
763     }
764     return ERR_OK;
765 }
766 
RemoveSignProfile(const std::string & bundleName)767 ErrCode InstalldProxy::RemoveSignProfile(const std::string &bundleName)
768 {
769     MessageParcel data;
770     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
771     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
772 
773     MessageParcel reply;
774     MessageOption option(MessageOption::TF_SYNC);
775     auto ret = TransactInstalldCmd(InstalldInterfaceCode::REMOVE_SIGN_PROFILE, data, reply, option);
776     if (ret != ERR_OK) {
777         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
778         return ret;
779     }
780     return ERR_OK;
781 }
782 
SetEncryptionPolicy(int32_t uid,const std::string & bundleName,const int32_t userId,std::string & keyId)783 ErrCode InstalldProxy::SetEncryptionPolicy(int32_t uid, const std::string &bundleName,
784     const int32_t userId, std::string &keyId)
785 {
786     MessageParcel data;
787     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
788     INSTALLD_PARCEL_WRITE(data, Int32, uid);
789     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
790     INSTALLD_PARCEL_WRITE(data, Int32, userId);
791 
792     MessageParcel reply;
793     MessageOption option(MessageOption::TF_SYNC);
794     auto ret = TransactInstalldCmd(InstalldInterfaceCode::SET_ENCRYPTION_DIR, data, reply, option);
795     if (ret != ERR_OK) {
796         APP_LOGE("TransactInstalldCmd failed");
797         return ret;
798     }
799     keyId = reply.ReadString();
800     return ERR_OK;
801 }
802 
DeleteEncryptionKeyId(const std::string & bundleName,const int32_t userId)803 ErrCode InstalldProxy::DeleteEncryptionKeyId(const std::string &bundleName, const int32_t userId)
804 {
805     MessageParcel data;
806     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
807     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
808     INSTALLD_PARCEL_WRITE(data, Int32, userId);
809 
810     MessageParcel reply;
811     MessageOption option(MessageOption::TF_SYNC);
812     auto ret = TransactInstalldCmd(InstalldInterfaceCode::DELETE_ENCRYPTION_KEY_ID, data, reply, option);
813     if (ret != ERR_OK) {
814         APP_LOGE("TransactInstalldCmd failed");
815         return ret;
816     }
817     return ERR_OK;
818 }
819 
RemoveExtensionDir(int32_t userId,const std::vector<std::string> & extensionBundleDirs)820 ErrCode InstalldProxy::RemoveExtensionDir(int32_t userId, const std::vector<std::string> &extensionBundleDirs)
821 {
822     MessageParcel data;
823     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
824     INSTALLD_PARCEL_WRITE(data, Int32, userId);
825     const auto size = extensionBundleDirs.size();
826     if (size > MAX_VEC_SIZE) {
827         APP_LOGE("fail to RemoveExtensionDir due to extensionBundleDirs size %{public}zu is too big", size);
828         return ERR_APPEXECFWK_PARCEL_ERROR;
829     }
830     INSTALLD_PARCEL_WRITE(data, Int32, size);
831     for (size_t i = 0; i < size; i++) {
832         if (extensionBundleDirs[i].size() > MAX_STRING_SIZE) {
833             APP_LOGE("extensionBundleDirs %{public}zu is too long", i);
834             return ERR_APPEXECFWK_PARCEL_ERROR;
835         }
836         if (!data.WriteString(extensionBundleDirs[i])) {
837             APP_LOGE("fail to RemoveExtensionDir due to write extensionBundleDirs %{public}zu fail", i);
838             return ERR_APPEXECFWK_PARCEL_ERROR;
839         }
840     }
841 
842     MessageParcel reply;
843     MessageOption option(MessageOption::TF_SYNC);
844     auto ret = TransactInstalldCmd(InstalldInterfaceCode::REMOVE_EXTENSION_DIR, data, reply, option);
845     if (ret != ERR_OK) {
846         APP_LOGE("TransactInstalldCmd failed");
847         return ret;
848     }
849     return ERR_OK;
850 }
851 
IsExistExtensionDir(int32_t userId,const std::string & extensionBundleDir,bool & isExist)852 ErrCode InstalldProxy::IsExistExtensionDir(int32_t userId, const std::string &extensionBundleDir, bool &isExist)
853 {
854     MessageParcel data;
855     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
856     INSTALLD_PARCEL_WRITE(data, Int32, userId);
857     if (extensionBundleDir.size() > MAX_STRING_SIZE) {
858         APP_LOGE("extensionBundleDir is too long");
859         return ERR_APPEXECFWK_PARCEL_ERROR;
860     }
861     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(extensionBundleDir));
862 
863     MessageParcel reply;
864     MessageOption option(MessageOption::TF_SYNC);
865     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_EXIST_EXTENSION_DIR, data, reply, option);
866     if (ret != ERR_OK) {
867         APP_LOGE("TransactInstalldCmd failed");
868         return ret;
869     }
870     isExist = reply.ReadBool();
871     return ERR_OK;
872 }
873 
GetExtensionSandboxTypeList(std::vector<std::string> & typeList)874 ErrCode InstalldProxy::GetExtensionSandboxTypeList(std::vector<std::string> &typeList)
875 {
876     MessageParcel data;
877     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
878     MessageParcel reply;
879     MessageOption option(MessageOption::TF_SYNC);
880     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_EXTENSION_SANDBOX_TYPE_LIST, data, reply, option);
881     if (ret != ERR_OK) {
882         APP_LOGE("TransactInstalldCmd failed");
883         return ret;
884     }
885     if (!reply.ReadStringVector(&typeList)) {
886         APP_LOGE("fail to GetExtensionSandboxTypeList from reply");
887         return ERR_APPEXECFWK_PARCEL_ERROR;
888     }
889     return ERR_OK;
890 }
891 
CreateExtensionDataDir(const CreateDirParam & createDirParam)892 ErrCode InstalldProxy::CreateExtensionDataDir(const CreateDirParam &createDirParam)
893 {
894     MessageParcel data;
895     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
896     if (!data.WriteParcelable(&createDirParam)) {
897         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable createDirParam failed");
898         return ERR_APPEXECFWK_PARCEL_ERROR;
899     }
900 
901     MessageParcel reply;
902     MessageOption option;
903     return TransactInstalldCmd(InstalldInterfaceCode::CREATE_EXTENSION_DATA_DIR, data, reply, option);
904 }
905 
MoveHapToCodeDir(const std::string & originPath,const std::string & targetPath)906 ErrCode InstalldProxy::MoveHapToCodeDir(const std::string &originPath, const std::string &targetPath)
907 {
908     MessageParcel data;
909     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
910     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(originPath));
911     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(targetPath));
912 
913     MessageParcel reply;
914     MessageOption option(MessageOption::TF_SYNC);
915     return TransactInstalldCmd(InstalldInterfaceCode::MOVE_HAP_TO_CODE_DIR, data, reply, option);
916 }
917 
TransactInstalldCmd(InstalldInterfaceCode code,MessageParcel & data,MessageParcel & reply,MessageOption & option)918 ErrCode InstalldProxy::TransactInstalldCmd(InstalldInterfaceCode code, MessageParcel &data, MessageParcel &reply,
919     MessageOption &option)
920 {
921     sptr<IRemoteObject> remote = Remote();
922     if (remote == nullptr) {
923         LOG_E(BMS_TAG_INSTALLD, "fail to send %{public}u cmd to service due to remote object is null", code);
924         return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
925     }
926 
927     if (remote->SendRequest(static_cast<uint32_t>(code), data, reply, option) != OHOS::NO_ERROR) {
928         LOG_E(BMS_TAG_INSTALLD, "fail to send %{public}u request to service due to transact error", code);
929         return ERR_APPEXECFWK_INSTALLD_SERVICE_DIED;
930     }
931     return reply.ReadInt32();
932 }
933 }  // namespace AppExecFwk
934 }  // namespace OHOS