• 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 
DeleteUninstallTmpDirs(const std::vector<std::string> & dirs)170 ErrCode InstalldProxy::DeleteUninstallTmpDirs(const std::vector<std::string> &dirs)
171 {
172     MessageParcel data;
173     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
174     INSTALLD_PARCEL_WRITE(data, Uint32, dirs.size());
175     for (const std::string &dir : dirs) {
176         INSTALLD_PARCEL_WRITE(data, String, dir);
177     }
178 
179     MessageParcel reply;
180     MessageOption option;
181     return TransactInstalldCmd(InstalldInterfaceCode::DELETE_UNINSTALL_TMP_DIRS, data, reply, option);
182 }
183 
RenameModuleDir(const std::string & oldPath,const std::string & newPath)184 ErrCode InstalldProxy::RenameModuleDir(const std::string &oldPath, const std::string &newPath)
185 {
186     MessageParcel data;
187     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
188     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(oldPath));
189     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(newPath));
190 
191     MessageParcel reply;
192     MessageOption option;
193     return TransactInstalldCmd(InstalldInterfaceCode::RENAME_MODULE_DIR, data, reply, option);
194 }
195 
CreateBundleDataDir(const CreateDirParam & createDirParam)196 ErrCode InstalldProxy::CreateBundleDataDir(const CreateDirParam &createDirParam)
197 {
198     MessageParcel data;
199     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
200     if (!data.WriteParcelable(&createDirParam)) {
201         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable createDirParam failed");
202         return ERR_APPEXECFWK_PARCEL_ERROR;
203     }
204 
205     MessageParcel reply;
206     MessageOption option;
207     return TransactInstalldCmd(InstalldInterfaceCode::CREATE_BUNDLE_DATA_DIR, data, reply, option);
208 }
209 
CreateBundleDataDirWithVector(const std::vector<CreateDirParam> & createDirParams)210 ErrCode InstalldProxy::CreateBundleDataDirWithVector(const std::vector<CreateDirParam> &createDirParams)
211 {
212     MessageParcel data;
213     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
214     if (createDirParams.empty()) {
215         LOG_E(BMS_TAG_INSTALLD, "createDirParams size is empty");
216         return ERR_BUNDLE_MANAGER_INVALID_PARAMETER;
217     }
218     INSTALLD_PARCEL_WRITE(data, Uint32, createDirParams.size());
219     for (const auto &createDirParam : createDirParams) {
220         if (!data.WriteParcelable(&createDirParam)) {
221             LOG_E(BMS_TAG_INSTALLD, "WriteParcelable createDirParam failed");
222             return ERR_APPEXECFWK_PARCEL_ERROR;
223         }
224     }
225 
226     MessageParcel reply;
227     MessageOption option;
228     return TransactInstalldCmd(InstalldInterfaceCode::CREATE_BUNDLE_DATA_DIR_WITH_VECTOR, data, reply, option);
229 }
230 
RemoveBundleDataDir(const std::string & bundleName,const int userId,bool isAtomicService,const bool async)231 ErrCode InstalldProxy::RemoveBundleDataDir(
232     const std::string &bundleName, const int userId, bool isAtomicService, const bool async)
233 {
234     MessageParcel data;
235     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
236     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
237     INSTALLD_PARCEL_WRITE(data, Int32, userId);
238     INSTALLD_PARCEL_WRITE(data, Bool, isAtomicService);
239     INSTALLD_PARCEL_WRITE(data, Bool, async);
240 
241     MessageParcel reply;
242     MessageOption option;
243     return TransactInstalldCmd(InstalldInterfaceCode::REMOVE_BUNDLE_DATA_DIR, data, reply, option);
244 }
245 
RemoveModuleDataDir(const std::string & ModuleName,const int userid)246 ErrCode InstalldProxy::RemoveModuleDataDir(const std::string &ModuleName, const int userid)
247 {
248     MessageParcel data;
249     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
250     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(ModuleName));
251     INSTALLD_PARCEL_WRITE(data, Int32, userid);
252 
253     MessageParcel reply;
254     MessageOption option;
255     return TransactInstalldCmd(InstalldInterfaceCode::REMOVE_MODULE_DATA_DIR, data, reply, option);
256 }
257 
RemoveDir(const std::string & dir)258 ErrCode InstalldProxy::RemoveDir(const std::string &dir)
259 {
260     MessageParcel data;
261     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
262     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
263 
264     MessageParcel reply;
265     MessageOption option(MessageOption::TF_SYNC);
266     return TransactInstalldCmd(InstalldInterfaceCode::REMOVE_DIR, data, reply, option);
267 }
268 
GetDiskUsage(const std::string & dir,bool isRealPath)269 int64_t InstalldProxy::GetDiskUsage(const std::string &dir, bool isRealPath)
270 {
271     MessageParcel data;
272     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
273     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
274     INSTALLD_PARCEL_WRITE(data, Bool, isRealPath);
275 
276     MessageParcel reply;
277     MessageOption option(MessageOption::TF_SYNC, WAIT_TIME);
278     return TransactInstalldCmd(InstalldInterfaceCode::GET_DISK_USAGE, data, reply, option);
279 }
280 
GetDiskUsageFromPath(const std::vector<std::string> & path,int64_t & statSize)281 ErrCode InstalldProxy::GetDiskUsageFromPath(const std::vector<std::string> &path, int64_t &statSize)
282 {
283     MessageParcel data;
284     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
285     if (path.size() > Constants::MAX_CACHE_DIR_SIZE) {
286         LOG_E(BMS_TAG_INSTALLD, "cache path size invalid");
287         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
288     }
289     if (!data.WriteUint32(path.size())) {
290         LOG_E(BMS_TAG_INSTALLD, "failed: write path count fail");
291         return ERR_APPEXECFWK_PARCEL_ERROR;
292     }
293 
294     if (!data.WriteStringVector(path)) {
295         LOG_E(BMS_TAG_INSTALLD, "fail to WriteStringVector for path");
296         return false;
297     }
298 
299     MessageParcel reply;
300     MessageOption option(MessageOption::TF_SYNC, WAIT_TIME);
301     ErrCode ret = TransactInstalldCmd(InstalldInterfaceCode::GET_DISK_USAGE_FROM_PATH, data, reply, option);
302     if (ret == ERR_OK) {
303         statSize = reply.ReadInt64();
304     }
305     return ret;
306 }
307 
CleanBundleDataDir(const std::string & bundleDir)308 ErrCode InstalldProxy::CleanBundleDataDir(const std::string &bundleDir)
309 {
310     MessageParcel data;
311     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
312     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleDir));
313 
314     MessageParcel reply;
315     MessageOption option(MessageOption::TF_SYNC, WAIT_TIME);
316     return TransactInstalldCmd(InstalldInterfaceCode::CLEAN_BUNDLE_DATA_DIR, data, reply, option);
317 }
318 
CleanBundleDataDirByName(const std::string & bundleName,const int userid,const int appIndex)319 ErrCode InstalldProxy::CleanBundleDataDirByName(const std::string &bundleName, const int userid, const int appIndex)
320 {
321     MessageParcel data;
322     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
323     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
324     INSTALLD_PARCEL_WRITE(data, Int32, userid);
325     INSTALLD_PARCEL_WRITE(data, Int32, appIndex);
326     MessageParcel reply;
327     MessageOption option;
328     return TransactInstalldCmd(InstalldInterfaceCode::CLEAN_BUNDLE_DATA_DIR_BY_NAME, data, reply, option);
329 }
330 
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)331 ErrCode InstalldProxy::GetBundleStats(const std::string &bundleName, const int32_t userId,
332     std::vector<int64_t> &bundleStats, const int32_t uid, const int32_t appIndex,
333     const uint32_t statFlag, const std::vector<std::string> &moduleNameList)
334 {
335     MessageParcel data;
336     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
337     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
338     INSTALLD_PARCEL_WRITE(data, Int32, userId);
339     INSTALLD_PARCEL_WRITE(data, Int32, uid);
340     INSTALLD_PARCEL_WRITE(data, Int32, appIndex);
341     INSTALLD_PARCEL_WRITE(data, Uint32, statFlag);
342     if (!data.WriteInt32(moduleNameList.size())) {
343         LOG_E(BMS_TAG_INSTALLD, "GetBundleStats failed: write module name count fail");
344         return ERR_APPEXECFWK_PARCEL_ERROR;
345     }
346     for (size_t i = 0; i < moduleNameList.size(); i++) {
347         if (!data.WriteString(moduleNameList[i])) {
348             LOG_E(BMS_TAG_INSTALLD, "WriteParcelable moduleNames:[%{public}s] failed",
349                 moduleNameList[i].c_str());
350             return ERR_APPEXECFWK_PARCEL_ERROR;
351         }
352     }
353     MessageParcel reply;
354     MessageOption option(MessageOption::TF_SYNC);
355     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_BUNDLE_STATS, data, reply, option);
356     if (ret == ERR_OK) {
357         if (reply.ReadInt64Vector(&bundleStats)) {
358             return ERR_OK;
359         } else {
360             return ERR_APPEXECFWK_PARCEL_ERROR;
361         }
362     }
363     return ret;
364 }
365 
GetAllBundleStats(const int32_t userId,std::vector<int64_t> & bundleStats,const std::vector<int32_t> & uids)366 ErrCode InstalldProxy::GetAllBundleStats(const int32_t userId,
367     std::vector<int64_t> &bundleStats, const std::vector<int32_t> &uids)
368 {
369     MessageParcel data;
370     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
371     INSTALLD_PARCEL_WRITE(data, Int32, userId);
372     uint32_t uidSize = uids.size();
373     INSTALLD_PARCEL_WRITE(data, Uint32, uidSize);
374     for (const auto &uid : uids) {
375         INSTALLD_PARCEL_WRITE(data, Int32, uid);
376     }
377     MessageParcel reply;
378     MessageOption option(MessageOption::TF_SYNC);
379     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_ALL_BUNDLE_STATS, data, reply, option);
380     if (ret == ERR_OK) {
381         if (!reply.ReadInt64Vector(&bundleStats)) {
382             return ERR_APPEXECFWK_PARCEL_ERROR;
383         }
384         return ERR_OK;
385     }
386     return ret;
387 }
388 
SetDirApl(const std::string & dir,const std::string & bundleName,const std::string & apl,bool isPreInstallApp,bool debug)389 ErrCode InstalldProxy::SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl,
390     bool isPreInstallApp, bool debug)
391 {
392     MessageParcel data;
393     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
394     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
395     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
396     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(apl));
397     INSTALLD_PARCEL_WRITE(data, Bool, isPreInstallApp);
398     INSTALLD_PARCEL_WRITE(data, Bool, debug);
399 
400     MessageParcel reply;
401     MessageOption option(MessageOption::TF_SYNC);
402     return TransactInstalldCmd(InstalldInterfaceCode::SET_DIR_APL, data, reply, option);
403 }
404 
GetBundleCachePath(const std::string & dir,std::vector<std::string> & cachePath)405 ErrCode InstalldProxy::GetBundleCachePath(const std::string &dir, std::vector<std::string> &cachePath)
406 {
407     MessageParcel data;
408     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
409     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
410     MessageParcel reply;
411     MessageOption option(MessageOption::TF_SYNC);
412     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_BUNDLE_CACHE_PATH, data, reply, option);
413     if (ret == ERR_OK) {
414         if (reply.ReadStringVector(&cachePath)) {
415             return ERR_OK;
416         } else {
417             return ERR_APPEXECFWK_PARCEL_ERROR;
418         }
419     }
420     return ret;
421 }
422 
ScanDir(const std::string & dir,ScanMode scanMode,ResultMode resultMode,std::vector<std::string> & paths)423 ErrCode InstalldProxy::ScanDir(
424     const std::string &dir, ScanMode scanMode, ResultMode resultMode, std::vector<std::string> &paths)
425 {
426     MessageParcel data;
427     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
428     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
429     INSTALLD_PARCEL_WRITE(data, Int32, static_cast<int32_t>(scanMode));
430     INSTALLD_PARCEL_WRITE(data, Int32, static_cast<int32_t>(resultMode));
431 
432     MessageParcel reply;
433     MessageOption option(MessageOption::TF_SYNC);
434     auto ret = TransactInstalldCmd(InstalldInterfaceCode::SCAN_DIR, data, reply, option);
435     if (ret != ERR_OK) {
436         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
437         return ret;
438     }
439 
440     if (!reply.ReadStringVector(&paths)) {
441         return ERR_APPEXECFWK_PARCEL_ERROR;
442     }
443 
444     return ERR_OK;
445 }
446 
MoveFile(const std::string & oldPath,const std::string & newPath)447 ErrCode InstalldProxy::MoveFile(const std::string &oldPath, const std::string &newPath)
448 {
449     MessageParcel data;
450     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
451     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(oldPath));
452     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(newPath));
453 
454     MessageParcel reply;
455     MessageOption option(MessageOption::TF_SYNC);
456     return TransactInstalldCmd(InstalldInterfaceCode::MOVE_FILE, data, reply, option);
457 }
458 
CopyFile(const std::string & oldPath,const std::string & newPath,const std::string & signatureFilePath)459 ErrCode InstalldProxy::CopyFile(const std::string &oldPath, const std::string &newPath,
460     const std::string &signatureFilePath)
461 {
462     MessageParcel data;
463     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
464     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(oldPath));
465     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(newPath));
466     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(signatureFilePath));
467 
468     MessageParcel reply;
469     MessageOption option(MessageOption::TF_SYNC);
470     return TransactInstalldCmd(InstalldInterfaceCode::COPY_FILE, data, reply, option);
471 }
472 
Mkdir(const std::string & dir,const int32_t mode,const int32_t uid,const int32_t gid)473 ErrCode InstalldProxy::Mkdir(
474     const std::string &dir, const int32_t mode, const int32_t uid, const int32_t gid)
475 {
476     MessageParcel data;
477     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
478     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
479     INSTALLD_PARCEL_WRITE(data, Int32, mode);
480     INSTALLD_PARCEL_WRITE(data, Int32, uid);
481     INSTALLD_PARCEL_WRITE(data, Int32, gid);
482 
483     MessageParcel reply;
484     MessageOption option(MessageOption::TF_SYNC);
485     return TransactInstalldCmd(InstalldInterfaceCode::MKDIR, data, reply, option);
486 }
487 
GetFileStat(const std::string & file,FileStat & fileStat)488 ErrCode InstalldProxy::GetFileStat(const std::string &file, FileStat &fileStat)
489 {
490     MessageParcel data;
491     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
492     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(file));
493 
494     MessageParcel reply;
495     MessageOption option(MessageOption::TF_SYNC);
496     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_FILE_STAT, data, reply, option);
497     if (ret != ERR_OK) {
498         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
499         return ret;
500     }
501 
502     std::unique_ptr<FileStat> info(reply.ReadParcelable<FileStat>());
503     if (info == nullptr) {
504         LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
505         return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
506     }
507 
508     fileStat = *info;
509     return ERR_OK;
510 }
511 
ExtractDiffFiles(const std::string & filePath,const std::string & targetPath,const std::string & cpuAbi)512 ErrCode InstalldProxy::ExtractDiffFiles(const std::string &filePath, const std::string &targetPath,
513     const std::string &cpuAbi)
514 {
515     MessageParcel data;
516     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
517     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(filePath));
518     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(targetPath));
519     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi));
520 
521     MessageParcel reply;
522     MessageOption option(MessageOption::TF_SYNC);
523     return TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_DIFF_FILES, data, reply, option);
524 }
525 
ApplyDiffPatch(const std::string & oldSoPath,const std::string & diffFilePath,const std::string & newSoPath,int32_t uid)526 ErrCode InstalldProxy::ApplyDiffPatch(const std::string &oldSoPath, const std::string &diffFilePath,
527     const std::string &newSoPath, int32_t uid)
528 {
529     MessageParcel data;
530     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
531     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(oldSoPath));
532     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(diffFilePath));
533     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(newSoPath));
534     INSTALLD_PARCEL_WRITE(data, Int32, uid);
535 
536     MessageParcel reply;
537     MessageOption option(MessageOption::TF_SYNC);
538     return TransactInstalldCmd(InstalldInterfaceCode::APPLY_DIFF_PATCH, data, reply, option);
539 }
540 
IsExistDir(const std::string & dir,bool & isExist)541 ErrCode InstalldProxy::IsExistDir(const std::string &dir, bool &isExist)
542 {
543     MessageParcel data;
544     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
545     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
546 
547     MessageParcel reply;
548     MessageOption option(MessageOption::TF_SYNC);
549     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_EXIST_DIR, data, reply, option);
550     if (ret != ERR_OK) {
551         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
552         return ret;
553     }
554     isExist = reply.ReadBool();
555     return ERR_OK;
556 }
557 
IsExistFile(const std::string & path,bool & isExist)558 ErrCode InstalldProxy::IsExistFile(const std::string &path, bool &isExist)
559 {
560     MessageParcel data;
561     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
562     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(path));
563 
564     MessageParcel reply;
565     MessageOption option(MessageOption::TF_SYNC);
566     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_EXIST_FILE, data, reply, option);
567     if (ret != ERR_OK) {
568         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
569         return ret;
570     }
571     isExist = reply.ReadBool();
572     return ERR_OK;
573 }
574 
IsExistApFile(const std::string & path,bool & isExist)575 ErrCode InstalldProxy::IsExistApFile(const std::string &path, bool &isExist)
576 {
577     MessageParcel data;
578     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
579     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(path));
580 
581     MessageParcel reply;
582     MessageOption option(MessageOption::TF_SYNC);
583     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_EXIST_AP_FILE, data, reply, option);
584     if (ret != ERR_OK) {
585         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
586         return ret;
587     }
588     isExist = reply.ReadBool();
589     return ERR_OK;
590 }
591 
IsDirEmpty(const std::string & dir,bool & isDirEmpty)592 ErrCode InstalldProxy::IsDirEmpty(const std::string &dir, bool &isDirEmpty)
593 {
594     MessageParcel data;
595     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
596     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
597 
598     MessageParcel reply;
599     MessageOption option(MessageOption::TF_SYNC);
600     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_DIR_EMPTY, data, reply, option);
601     if (ret != ERR_OK) {
602         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
603         return ret;
604     }
605     isDirEmpty = reply.ReadBool();
606     return ERR_OK;
607 }
608 
ObtainQuickFixFileDir(const std::string & dir,std::vector<std::string> & dirVec)609 ErrCode InstalldProxy::ObtainQuickFixFileDir(const std::string &dir, std::vector<std::string> &dirVec)
610 {
611     MessageParcel data;
612     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
613     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
614 
615     MessageParcel reply;
616     MessageOption option(MessageOption::TF_SYNC);
617     auto ret = TransactInstalldCmd(InstalldInterfaceCode::OBTAIN_QUICK_FIX_DIR, data, reply, option);
618     if (ret != ERR_OK) {
619         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
620         return ret;
621     }
622     if (!reply.ReadStringVector(&dirVec)) {
623         return ERR_APPEXECFWK_PARCEL_ERROR;
624     }
625     return ERR_OK;
626 }
627 
CopyFiles(const std::string & sourceDir,const std::string & destinationDir)628 ErrCode InstalldProxy::CopyFiles(const std::string &sourceDir, const std::string &destinationDir)
629 {
630     MessageParcel data;
631     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
632     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(sourceDir));
633     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(destinationDir));
634 
635     MessageParcel reply;
636     MessageOption option(MessageOption::TF_SYNC);
637     auto ret = TransactInstalldCmd(InstalldInterfaceCode::COPY_FILES, data, reply, option);
638     if (ret != ERR_OK) {
639         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
640         return ret;
641     }
642     return ERR_OK;
643 }
644 
GetNativeLibraryFileNames(const std::string & filePath,const std::string & cpuAbi,std::vector<std::string> & fileNames)645 ErrCode InstalldProxy::GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi,
646     std::vector<std::string> &fileNames)
647 {
648     MessageParcel data;
649     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
650     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(filePath));
651     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi));
652 
653     MessageParcel reply;
654     MessageOption option(MessageOption::TF_SYNC);
655     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_NATIVE_LIBRARY_FILE_NAMES, data, reply, option);
656     if (ret != ERR_OK) {
657         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
658         return ret;
659     }
660     if (!reply.ReadStringVector(&fileNames)) {
661         LOG_E(BMS_TAG_INSTALLD, "ReadStringVector failed");
662         return ERR_APPEXECFWK_PARCEL_ERROR;
663     }
664     return ERR_OK;
665 }
666 
VerifyCodeSignature(const CodeSignatureParam & codeSignatureParam)667 ErrCode InstalldProxy::VerifyCodeSignature(const CodeSignatureParam &codeSignatureParam)
668 {
669     MessageParcel data;
670     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
671     if (!data.WriteParcelable(&codeSignatureParam)) {
672         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable codeSignatureParam failed");
673         return ERR_APPEXECFWK_PARCEL_ERROR;
674     }
675 
676     MessageParcel reply;
677     MessageOption option(MessageOption::TF_SYNC);
678     auto ret = TransactInstalldCmd(InstalldInterfaceCode::VERIFY_CODE_SIGNATURE, data, reply, option);
679     if (ret != ERR_OK) {
680         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
681         return ret;
682     }
683     return ERR_OK;
684 }
685 
CheckEncryption(const CheckEncryptionParam & checkEncryptionParam,bool & isEncryption)686 ErrCode InstalldProxy::CheckEncryption(const CheckEncryptionParam &checkEncryptionParam, bool &isEncryption)
687 {
688     MessageParcel data;
689     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
690     if (!data.WriteParcelable(&checkEncryptionParam)) {
691         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable checkEncryptionParam failed");
692         return ERR_APPEXECFWK_PARCEL_ERROR;
693     }
694     MessageParcel reply;
695     MessageOption option(MessageOption::TF_SYNC);
696     auto ret = TransactInstalldCmd(InstalldInterfaceCode::CHECK_ENCRYPTION, data, reply, option);
697     if (ret != ERR_OK) {
698         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
699         return ret;
700     }
701     isEncryption = reply.ReadBool();
702     return ERR_OK;
703 }
704 
MoveFiles(const std::string & srcDir,const std::string & desDir)705 ErrCode InstalldProxy::MoveFiles(const std::string &srcDir, const std::string &desDir)
706 {
707     MessageParcel data;
708     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
709     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(srcDir));
710     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(desDir));
711 
712     MessageParcel reply;
713     MessageOption option(MessageOption::TF_SYNC);
714     auto ret = TransactInstalldCmd(InstalldInterfaceCode::MOVE_FILES, data, reply, option);
715     if (ret != ERR_OK) {
716         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
717         return ret;
718     }
719     return ERR_OK;
720 }
721 
ExtractDriverSoFiles(const std::string & srcPath,const std::unordered_multimap<std::string,std::string> & dirMap)722 ErrCode InstalldProxy::ExtractDriverSoFiles(const std::string &srcPath,
723     const std::unordered_multimap<std::string, std::string> &dirMap)
724 {
725     MessageParcel data;
726     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
727     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(srcPath));
728     INSTALLD_PARCEL_WRITE(data, Int32, static_cast<int32_t>(dirMap.size()));
729     for (auto &[orignialDir, destinedDir] : dirMap) {
730         INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(orignialDir));
731         INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(destinedDir));
732     }
733     MessageParcel reply;
734     MessageOption option(MessageOption::TF_SYNC);
735     auto ret = TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_DRIVER_SO_FILE, data, reply, option);
736     if (ret != ERR_OK) {
737         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
738         return ret;
739     }
740     return ERR_OK;
741 }
742 
ExtractEncryptedSoFiles(const std::string & hapPath,const std::string & realSoFilesPath,const std::string & cpuAbi,const std::string & tmpSoPath,int32_t uid)743 ErrCode InstalldProxy::ExtractEncryptedSoFiles(const std::string &hapPath, const std::string &realSoFilesPath,
744     const std::string &cpuAbi, const std::string &tmpSoPath, int32_t uid)
745 {
746     MessageParcel data;
747     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
748     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(hapPath));
749     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(realSoFilesPath));
750     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi));
751     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(tmpSoPath));
752     INSTALLD_PARCEL_WRITE(data, Int32, uid);
753 
754     MessageParcel reply;
755     MessageOption option(MessageOption::TF_SYNC);
756     auto ret = TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_CODED_SO_FILE, data, reply, option);
757     if (ret != ERR_OK) {
758         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
759         return ret;
760     }
761     return ERR_OK;
762 }
763 
VerifyCodeSignatureForHap(const CodeSignatureParam & codeSignatureParam)764 ErrCode InstalldProxy::VerifyCodeSignatureForHap(const CodeSignatureParam &codeSignatureParam)
765 {
766     MessageParcel data;
767     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
768     if (!data.WriteParcelable(&codeSignatureParam)) {
769         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable codeSignatureParam failed");
770         return ERR_APPEXECFWK_PARCEL_ERROR;
771     }
772 
773     MessageParcel reply;
774     MessageOption option(MessageOption::TF_SYNC);
775     auto ret = TransactInstalldCmd(InstalldInterfaceCode::VERIFY_CODE_SIGNATURE_FOR_HAP, 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 
DeliverySignProfile(const std::string & bundleName,int32_t profileBlockLength,const unsigned char * profileBlock)783 ErrCode InstalldProxy::DeliverySignProfile(const std::string &bundleName, int32_t profileBlockLength,
784     const unsigned char *profileBlock)
785 {
786     if (profileBlockLength == 0 || profileBlockLength > Constants::MAX_PARCEL_CAPACITY || profileBlock == nullptr) {
787         LOG_E(BMS_TAG_INSTALLD, "invalid params");
788         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
789     }
790     MessageParcel data;
791     (void)data.SetMaxCapacity(Constants::MAX_PARCEL_CAPACITY);
792     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
793     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
794     INSTALLD_PARCEL_WRITE(data, Int32, profileBlockLength);
795     if (!data.WriteRawData(profileBlock, profileBlockLength)) {
796         LOG_E(BMS_TAG_INSTALLD, "Failed to write raw data");
797         return ERR_APPEXECFWK_PARCEL_ERROR;
798     }
799 
800     MessageParcel reply;
801     MessageOption option(MessageOption::TF_SYNC);
802     auto ret = TransactInstalldCmd(InstalldInterfaceCode::DELIVERY_SIGN_PROFILE, data, reply, option);
803     if (ret != ERR_OK) {
804         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
805         return ret;
806     }
807     return ERR_OK;
808 }
809 
RemoveSignProfile(const std::string & bundleName)810 ErrCode InstalldProxy::RemoveSignProfile(const std::string &bundleName)
811 {
812     MessageParcel data;
813     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
814     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
815 
816     MessageParcel reply;
817     MessageOption option(MessageOption::TF_SYNC);
818     auto ret = TransactInstalldCmd(InstalldInterfaceCode::REMOVE_SIGN_PROFILE, data, reply, option);
819     if (ret != ERR_OK) {
820         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
821         return ret;
822     }
823     return ERR_OK;
824 }
825 
SetEncryptionPolicy(int32_t uid,const std::string & bundleName,const int32_t userId,std::string & keyId)826 ErrCode InstalldProxy::SetEncryptionPolicy(int32_t uid, const std::string &bundleName,
827     const int32_t userId, std::string &keyId)
828 {
829     MessageParcel data;
830     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
831     INSTALLD_PARCEL_WRITE(data, Int32, uid);
832     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
833     INSTALLD_PARCEL_WRITE(data, Int32, userId);
834 
835     MessageParcel reply;
836     MessageOption option(MessageOption::TF_SYNC);
837     auto ret = TransactInstalldCmd(InstalldInterfaceCode::SET_ENCRYPTION_DIR, data, reply, option);
838     if (ret != ERR_OK) {
839         APP_LOGE("TransactInstalldCmd failed");
840         return ret;
841     }
842     keyId = reply.ReadString();
843     return ERR_OK;
844 }
845 
DeleteEncryptionKeyId(const std::string & bundleName,const int32_t userId)846 ErrCode InstalldProxy::DeleteEncryptionKeyId(const std::string &bundleName, const int32_t userId)
847 {
848     MessageParcel data;
849     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
850     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
851     INSTALLD_PARCEL_WRITE(data, Int32, userId);
852 
853     MessageParcel reply;
854     MessageOption option(MessageOption::TF_SYNC);
855     auto ret = TransactInstalldCmd(InstalldInterfaceCode::DELETE_ENCRYPTION_KEY_ID, data, reply, option);
856     if (ret != ERR_OK) {
857         APP_LOGE("TransactInstalldCmd failed");
858         return ret;
859     }
860     return ERR_OK;
861 }
862 
RemoveExtensionDir(int32_t userId,const std::vector<std::string> & extensionBundleDirs)863 ErrCode InstalldProxy::RemoveExtensionDir(int32_t userId, const std::vector<std::string> &extensionBundleDirs)
864 {
865     MessageParcel data;
866     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
867     INSTALLD_PARCEL_WRITE(data, Int32, userId);
868     const auto size = extensionBundleDirs.size();
869     if (size > MAX_VEC_SIZE) {
870         APP_LOGE("fail to RemoveExtensionDir due to extensionBundleDirs size %{public}zu is too big", size);
871         return ERR_APPEXECFWK_PARCEL_ERROR;
872     }
873     INSTALLD_PARCEL_WRITE(data, Int32, size);
874     for (size_t i = 0; i < size; i++) {
875         if (extensionBundleDirs[i].size() > MAX_STRING_SIZE) {
876             APP_LOGE("extensionBundleDirs %{public}zu is too long", i);
877             return ERR_APPEXECFWK_PARCEL_ERROR;
878         }
879         if (!data.WriteString(extensionBundleDirs[i])) {
880             APP_LOGE("fail to RemoveExtensionDir due to write extensionBundleDirs %{public}zu fail", i);
881             return ERR_APPEXECFWK_PARCEL_ERROR;
882         }
883     }
884 
885     MessageParcel reply;
886     MessageOption option(MessageOption::TF_SYNC);
887     auto ret = TransactInstalldCmd(InstalldInterfaceCode::REMOVE_EXTENSION_DIR, data, reply, option);
888     if (ret != ERR_OK) {
889         APP_LOGE("TransactInstalldCmd failed");
890         return ret;
891     }
892     return ERR_OK;
893 }
894 
IsExistExtensionDir(int32_t userId,const std::string & extensionBundleDir,bool & isExist)895 ErrCode InstalldProxy::IsExistExtensionDir(int32_t userId, const std::string &extensionBundleDir, bool &isExist)
896 {
897     MessageParcel data;
898     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
899     INSTALLD_PARCEL_WRITE(data, Int32, userId);
900     if (extensionBundleDir.size() > MAX_STRING_SIZE) {
901         APP_LOGE("extensionBundleDir is too long");
902         return ERR_APPEXECFWK_PARCEL_ERROR;
903     }
904     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(extensionBundleDir));
905 
906     MessageParcel reply;
907     MessageOption option(MessageOption::TF_SYNC);
908     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_EXIST_EXTENSION_DIR, data, reply, option);
909     if (ret != ERR_OK) {
910         APP_LOGE("TransactInstalldCmd failed");
911         return ret;
912     }
913     isExist = reply.ReadBool();
914     return ERR_OK;
915 }
916 
GetExtensionSandboxTypeList(std::vector<std::string> & typeList)917 ErrCode InstalldProxy::GetExtensionSandboxTypeList(std::vector<std::string> &typeList)
918 {
919     MessageParcel data;
920     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
921     MessageParcel reply;
922     MessageOption option(MessageOption::TF_SYNC);
923     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_EXTENSION_SANDBOX_TYPE_LIST, data, reply, option);
924     if (ret != ERR_OK) {
925         APP_LOGE("TransactInstalldCmd failed");
926         return ret;
927     }
928     if (!reply.ReadStringVector(&typeList)) {
929         APP_LOGE("fail to GetExtensionSandboxTypeList from reply");
930         return ERR_APPEXECFWK_PARCEL_ERROR;
931     }
932     return ERR_OK;
933 }
934 
CreateExtensionDataDir(const CreateDirParam & createDirParam)935 ErrCode InstalldProxy::CreateExtensionDataDir(const CreateDirParam &createDirParam)
936 {
937     MessageParcel data;
938     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
939     if (!data.WriteParcelable(&createDirParam)) {
940         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable createDirParam failed");
941         return ERR_APPEXECFWK_PARCEL_ERROR;
942     }
943 
944     MessageParcel reply;
945     MessageOption option;
946     return TransactInstalldCmd(InstalldInterfaceCode::CREATE_EXTENSION_DATA_DIR, data, reply, option);
947 }
948 
MoveHapToCodeDir(const std::string & originPath,const std::string & targetPath)949 ErrCode InstalldProxy::MoveHapToCodeDir(const std::string &originPath, const std::string &targetPath)
950 {
951     MessageParcel data;
952     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
953     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(originPath));
954     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(targetPath));
955 
956     MessageParcel reply;
957     MessageOption option(MessageOption::TF_SYNC);
958     return TransactInstalldCmd(InstalldInterfaceCode::MOVE_HAP_TO_CODE_DIR, data, reply, option);
959 }
960 
TransactInstalldCmd(InstalldInterfaceCode code,MessageParcel & data,MessageParcel & reply,MessageOption & option)961 ErrCode InstalldProxy::TransactInstalldCmd(InstalldInterfaceCode code, MessageParcel &data, MessageParcel &reply,
962     MessageOption &option)
963 {
964     sptr<IRemoteObject> remote = Remote();
965     if (remote == nullptr) {
966         LOG_E(BMS_TAG_INSTALLD, "fail to send %{public}u cmd to service due to remote object is null", code);
967         return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
968     }
969 
970     if (remote->SendRequest(static_cast<uint32_t>(code), data, reply, option) != OHOS::NO_ERROR) {
971         LOG_E(BMS_TAG_INSTALLD, "fail to send %{public}u request to service due to transact error", code);
972         return ERR_APPEXECFWK_INSTALLD_SERVICE_DIED;
973     }
974     return reply.ReadInt32();
975 }
976 }  // namespace AppExecFwk
977 }  // namespace OHOS