• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "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 int16_t WAIT_TIME = 3000;
26 constexpr int16_t MAX_VEC_SIZE = 1000;
27 constexpr int16_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,int64_t & statSize,bool isRealPath)269 ErrCode InstalldProxy::GetDiskUsage(const std::string &dir, int64_t &statSize, 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     ErrCode ret = TransactInstalldCmd(InstalldInterfaceCode::GET_DISK_USAGE, data, reply, option);
279     if (ret == ERR_OK) {
280         statSize = reply.ReadInt64();
281     }
282     return ret;
283 }
284 
GetDiskUsageFromPath(const std::vector<std::string> & path,int64_t & statSize)285 ErrCode InstalldProxy::GetDiskUsageFromPath(const std::vector<std::string> &path, int64_t &statSize)
286 {
287     MessageParcel data;
288     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
289     if (path.size() > Constants::MAX_CACHE_DIR_SIZE) {
290         LOG_E(BMS_TAG_INSTALLD, "cache path size invalid");
291         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
292     }
293     if (!data.WriteUint32(path.size())) {
294         LOG_E(BMS_TAG_INSTALLD, "failed: write path count fail");
295         return ERR_APPEXECFWK_PARCEL_ERROR;
296     }
297     for (size_t i = 0; i < path.size(); i++) {
298         if (!data.WriteString(path[i])) {
299             LOG_E(BMS_TAG_INSTALLD, "WriteParcelable path:[%{public}s] failed",
300                 path[i].c_str());
301             return ERR_APPEXECFWK_PARCEL_ERROR;
302         }
303     }
304 
305     MessageParcel reply;
306     MessageOption option(MessageOption::TF_SYNC, WAIT_TIME);
307     ErrCode ret = TransactInstalldCmd(InstalldInterfaceCode::GET_DISK_USAGE_FROM_PATH, data, reply, option);
308     if (ret == ERR_OK) {
309         statSize = reply.ReadInt64();
310     }
311     return ret;
312 }
313 
CleanBundleDataDir(const std::string & bundleDir)314 ErrCode InstalldProxy::CleanBundleDataDir(const std::string &bundleDir)
315 {
316     MessageParcel data;
317     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
318     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleDir));
319 
320     MessageParcel reply;
321     MessageOption option(MessageOption::TF_SYNC, WAIT_TIME);
322     return TransactInstalldCmd(InstalldInterfaceCode::CLEAN_BUNDLE_DATA_DIR, data, reply, option);
323 }
324 
CleanBundleDataDirByName(const std::string & bundleName,const int userid,const int appIndex)325 ErrCode InstalldProxy::CleanBundleDataDirByName(const std::string &bundleName, const int userid, const int appIndex)
326 {
327     MessageParcel data;
328     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
329     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
330     INSTALLD_PARCEL_WRITE(data, Int32, userid);
331     INSTALLD_PARCEL_WRITE(data, Int32, appIndex);
332     MessageParcel reply;
333     MessageOption option;
334     return TransactInstalldCmd(InstalldInterfaceCode::CLEAN_BUNDLE_DATA_DIR_BY_NAME, data, reply, option);
335 }
336 
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)337 ErrCode InstalldProxy::GetBundleStats(const std::string &bundleName, const int32_t userId,
338     std::vector<int64_t> &bundleStats, const int32_t uid, const int32_t appIndex,
339     const uint32_t statFlag, const std::vector<std::string> &moduleNameList)
340 {
341     MessageParcel data;
342     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
343     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
344     INSTALLD_PARCEL_WRITE(data, Int32, userId);
345     INSTALLD_PARCEL_WRITE(data, Int32, uid);
346     INSTALLD_PARCEL_WRITE(data, Int32, appIndex);
347     INSTALLD_PARCEL_WRITE(data, Uint32, statFlag);
348     if (!data.WriteInt32(moduleNameList.size())) {
349         LOG_E(BMS_TAG_INSTALLD, "GetBundleStats failed: write module name count fail");
350         return ERR_APPEXECFWK_PARCEL_ERROR;
351     }
352     for (size_t i = 0; i < moduleNameList.size(); i++) {
353         if (!data.WriteString(moduleNameList[i])) {
354             LOG_E(BMS_TAG_INSTALLD, "WriteParcelable moduleNames:[%{public}s] failed",
355                 moduleNameList[i].c_str());
356             return ERR_APPEXECFWK_PARCEL_ERROR;
357         }
358     }
359     MessageParcel reply;
360     MessageOption option(MessageOption::TF_SYNC);
361     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_BUNDLE_STATS, data, reply, option);
362     if (ret == ERR_OK) {
363         if (reply.ReadInt64Vector(&bundleStats)) {
364             return ERR_OK;
365         } else {
366             return ERR_APPEXECFWK_PARCEL_ERROR;
367         }
368     }
369     return ret;
370 }
371 
GetAllBundleStats(const int32_t userId,std::vector<int64_t> & bundleStats,const std::vector<int32_t> & uids)372 ErrCode InstalldProxy::GetAllBundleStats(const int32_t userId,
373     std::vector<int64_t> &bundleStats, const std::vector<int32_t> &uids)
374 {
375     MessageParcel data;
376     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
377     INSTALLD_PARCEL_WRITE(data, Int32, userId);
378     uint32_t uidSize = uids.size();
379     INSTALLD_PARCEL_WRITE(data, Uint32, uidSize);
380     for (const auto &uid : uids) {
381         INSTALLD_PARCEL_WRITE(data, Int32, uid);
382     }
383     MessageParcel reply;
384     MessageOption option(MessageOption::TF_SYNC);
385     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_ALL_BUNDLE_STATS, data, reply, option);
386     if (ret == ERR_OK) {
387         if (!reply.ReadInt64Vector(&bundleStats)) {
388             return ERR_APPEXECFWK_PARCEL_ERROR;
389         }
390         return ERR_OK;
391     }
392     return ret;
393 }
394 
SetDirApl(const std::string & dir,const std::string & bundleName,const std::string & apl,bool isPreInstallApp,bool debug)395 ErrCode InstalldProxy::SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl,
396     bool isPreInstallApp, bool debug)
397 {
398     MessageParcel data;
399     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
400     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
401     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
402     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(apl));
403     INSTALLD_PARCEL_WRITE(data, Bool, isPreInstallApp);
404     INSTALLD_PARCEL_WRITE(data, Bool, debug);
405 
406     MessageParcel reply;
407     MessageOption option(MessageOption::TF_SYNC);
408     return TransactInstalldCmd(InstalldInterfaceCode::SET_DIR_APL, data, reply, option);
409 }
410 
GetBundleCachePath(const std::string & dir,std::vector<std::string> & cachePath)411 ErrCode InstalldProxy::GetBundleCachePath(const std::string &dir, std::vector<std::string> &cachePath)
412 {
413     MessageParcel data;
414     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
415     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
416     MessageParcel reply;
417     MessageOption option(MessageOption::TF_SYNC);
418     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_BUNDLE_CACHE_PATH, data, reply, option);
419     if (ret == ERR_OK) {
420         if (reply.ReadStringVector(&cachePath)) {
421             return ERR_OK;
422         } else {
423             return ERR_APPEXECFWK_PARCEL_ERROR;
424         }
425     }
426     return ret;
427 }
428 
ScanDir(const std::string & dir,ScanMode scanMode,ResultMode resultMode,std::vector<std::string> & paths)429 ErrCode InstalldProxy::ScanDir(
430     const std::string &dir, ScanMode scanMode, ResultMode resultMode, std::vector<std::string> &paths)
431 {
432     MessageParcel data;
433     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
434     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
435     INSTALLD_PARCEL_WRITE(data, Int32, static_cast<int32_t>(scanMode));
436     INSTALLD_PARCEL_WRITE(data, Int32, static_cast<int32_t>(resultMode));
437 
438     MessageParcel reply;
439     MessageOption option(MessageOption::TF_SYNC);
440     auto ret = TransactInstalldCmd(InstalldInterfaceCode::SCAN_DIR, data, reply, option);
441     if (ret != ERR_OK) {
442         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
443         return ret;
444     }
445 
446     if (!reply.ReadStringVector(&paths)) {
447         return ERR_APPEXECFWK_PARCEL_ERROR;
448     }
449 
450     return ERR_OK;
451 }
452 
MoveFile(const std::string & oldPath,const std::string & newPath)453 ErrCode InstalldProxy::MoveFile(const std::string &oldPath, const std::string &newPath)
454 {
455     MessageParcel data;
456     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
457     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(oldPath));
458     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(newPath));
459 
460     MessageParcel reply;
461     MessageOption option(MessageOption::TF_SYNC);
462     return TransactInstalldCmd(InstalldInterfaceCode::MOVE_FILE, data, reply, option);
463 }
464 
CopyFile(const std::string & oldPath,const std::string & newPath,const std::string & signatureFilePath)465 ErrCode InstalldProxy::CopyFile(const std::string &oldPath, const std::string &newPath,
466     const std::string &signatureFilePath)
467 {
468     MessageParcel data;
469     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
470     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(oldPath));
471     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(newPath));
472     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(signatureFilePath));
473 
474     MessageParcel reply;
475     MessageOption option(MessageOption::TF_SYNC);
476     return TransactInstalldCmd(InstalldInterfaceCode::COPY_FILE, data, reply, option);
477 }
478 
Mkdir(const std::string & dir,const int32_t mode,const int32_t uid,const int32_t gid)479 ErrCode InstalldProxy::Mkdir(
480     const std::string &dir, const int32_t mode, const int32_t uid, const int32_t gid)
481 {
482     MessageParcel data;
483     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
484     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
485     INSTALLD_PARCEL_WRITE(data, Int32, mode);
486     INSTALLD_PARCEL_WRITE(data, Int32, uid);
487     INSTALLD_PARCEL_WRITE(data, Int32, gid);
488 
489     MessageParcel reply;
490     MessageOption option(MessageOption::TF_SYNC);
491     return TransactInstalldCmd(InstalldInterfaceCode::MKDIR, data, reply, option);
492 }
493 
GetFileStat(const std::string & file,FileStat & fileStat)494 ErrCode InstalldProxy::GetFileStat(const std::string &file, FileStat &fileStat)
495 {
496     MessageParcel data;
497     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
498     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(file));
499 
500     MessageParcel reply;
501     MessageOption option(MessageOption::TF_SYNC);
502     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_FILE_STAT, data, reply, option);
503     if (ret != ERR_OK) {
504         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
505         return ret;
506     }
507 
508     std::unique_ptr<FileStat> info(reply.ReadParcelable<FileStat>());
509     if (info == nullptr) {
510         LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
511         return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
512     }
513 
514     fileStat = *info;
515     return ERR_OK;
516 }
517 
ExtractDiffFiles(const std::string & filePath,const std::string & targetPath,const std::string & cpuAbi)518 ErrCode InstalldProxy::ExtractDiffFiles(const std::string &filePath, const std::string &targetPath,
519     const std::string &cpuAbi)
520 {
521     MessageParcel data;
522     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
523     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(filePath));
524     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(targetPath));
525     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi));
526 
527     MessageParcel reply;
528     MessageOption option(MessageOption::TF_SYNC);
529     return TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_DIFF_FILES, data, reply, option);
530 }
531 
ApplyDiffPatch(const std::string & oldSoPath,const std::string & diffFilePath,const std::string & newSoPath,int32_t uid)532 ErrCode InstalldProxy::ApplyDiffPatch(const std::string &oldSoPath, const std::string &diffFilePath,
533     const std::string &newSoPath, int32_t uid)
534 {
535     MessageParcel data;
536     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
537     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(oldSoPath));
538     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(diffFilePath));
539     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(newSoPath));
540     INSTALLD_PARCEL_WRITE(data, Int32, uid);
541 
542     MessageParcel reply;
543     MessageOption option(MessageOption::TF_SYNC);
544     return TransactInstalldCmd(InstalldInterfaceCode::APPLY_DIFF_PATCH, data, reply, option);
545 }
546 
IsExistDir(const std::string & dir,bool & isExist)547 ErrCode InstalldProxy::IsExistDir(const std::string &dir, bool &isExist)
548 {
549     MessageParcel data;
550     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
551     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
552 
553     MessageParcel reply;
554     MessageOption option(MessageOption::TF_SYNC);
555     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_EXIST_DIR, data, reply, option);
556     if (ret != ERR_OK) {
557         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
558         return ret;
559     }
560     isExist = reply.ReadBool();
561     return ERR_OK;
562 }
563 
IsExistFile(const std::string & path,bool & isExist)564 ErrCode InstalldProxy::IsExistFile(const std::string &path, bool &isExist)
565 {
566     MessageParcel data;
567     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
568     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(path));
569 
570     MessageParcel reply;
571     MessageOption option(MessageOption::TF_SYNC);
572     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_EXIST_FILE, data, reply, option);
573     if (ret != ERR_OK) {
574         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
575         return ret;
576     }
577     isExist = reply.ReadBool();
578     return ERR_OK;
579 }
580 
IsExistApFile(const std::string & path,bool & isExist)581 ErrCode InstalldProxy::IsExistApFile(const std::string &path, bool &isExist)
582 {
583     MessageParcel data;
584     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
585     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(path));
586 
587     MessageParcel reply;
588     MessageOption option(MessageOption::TF_SYNC);
589     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_EXIST_AP_FILE, data, reply, option);
590     if (ret != ERR_OK) {
591         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
592         return ret;
593     }
594     isExist = reply.ReadBool();
595     return ERR_OK;
596 }
597 
IsDirEmpty(const std::string & dir,bool & isDirEmpty)598 ErrCode InstalldProxy::IsDirEmpty(const std::string &dir, bool &isDirEmpty)
599 {
600     MessageParcel data;
601     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
602     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
603 
604     MessageParcel reply;
605     MessageOption option(MessageOption::TF_SYNC);
606     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_DIR_EMPTY, data, reply, option);
607     if (ret != ERR_OK) {
608         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
609         return ret;
610     }
611     isDirEmpty = reply.ReadBool();
612     return ERR_OK;
613 }
614 
ObtainQuickFixFileDir(const std::string & dir,std::vector<std::string> & dirVec)615 ErrCode InstalldProxy::ObtainQuickFixFileDir(const std::string &dir, std::vector<std::string> &dirVec)
616 {
617     MessageParcel data;
618     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
619     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(dir));
620 
621     MessageParcel reply;
622     MessageOption option(MessageOption::TF_SYNC);
623     auto ret = TransactInstalldCmd(InstalldInterfaceCode::OBTAIN_QUICK_FIX_DIR, data, reply, option);
624     if (ret != ERR_OK) {
625         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
626         return ret;
627     }
628     if (!reply.ReadStringVector(&dirVec)) {
629         return ERR_APPEXECFWK_PARCEL_ERROR;
630     }
631     return ERR_OK;
632 }
633 
CopyFiles(const std::string & sourceDir,const std::string & destinationDir)634 ErrCode InstalldProxy::CopyFiles(const std::string &sourceDir, const std::string &destinationDir)
635 {
636     MessageParcel data;
637     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
638     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(sourceDir));
639     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(destinationDir));
640 
641     MessageParcel reply;
642     MessageOption option(MessageOption::TF_SYNC);
643     auto ret = TransactInstalldCmd(InstalldInterfaceCode::COPY_FILES, data, reply, option);
644     if (ret != ERR_OK) {
645         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
646         return ret;
647     }
648     return ERR_OK;
649 }
650 
GetNativeLibraryFileNames(const std::string & filePath,const std::string & cpuAbi,std::vector<std::string> & fileNames)651 ErrCode InstalldProxy::GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi,
652     std::vector<std::string> &fileNames)
653 {
654     MessageParcel data;
655     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
656     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(filePath));
657     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi));
658 
659     MessageParcel reply;
660     MessageOption option(MessageOption::TF_SYNC);
661     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_NATIVE_LIBRARY_FILE_NAMES, data, reply, option);
662     if (ret != ERR_OK) {
663         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
664         return ret;
665     }
666     if (!reply.ReadStringVector(&fileNames)) {
667         LOG_E(BMS_TAG_INSTALLD, "ReadStringVector failed");
668         return ERR_APPEXECFWK_PARCEL_ERROR;
669     }
670     return ERR_OK;
671 }
672 
VerifyCodeSignature(const CodeSignatureParam & codeSignatureParam)673 ErrCode InstalldProxy::VerifyCodeSignature(const CodeSignatureParam &codeSignatureParam)
674 {
675     MessageParcel data;
676     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
677     if (!data.WriteParcelable(&codeSignatureParam)) {
678         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable codeSignatureParam failed");
679         return ERR_APPEXECFWK_PARCEL_ERROR;
680     }
681 
682     MessageParcel reply;
683     MessageOption option(MessageOption::TF_SYNC);
684     auto ret = TransactInstalldCmd(InstalldInterfaceCode::VERIFY_CODE_SIGNATURE, data, reply, option);
685     if (ret != ERR_OK) {
686         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
687         return ret;
688     }
689     return ERR_OK;
690 }
691 
CheckEncryption(const CheckEncryptionParam & checkEncryptionParam,bool & isEncryption)692 ErrCode InstalldProxy::CheckEncryption(const CheckEncryptionParam &checkEncryptionParam, bool &isEncryption)
693 {
694     MessageParcel data;
695     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
696     if (!data.WriteParcelable(&checkEncryptionParam)) {
697         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable checkEncryptionParam failed");
698         return ERR_APPEXECFWK_PARCEL_ERROR;
699     }
700     MessageParcel reply;
701     MessageOption option(MessageOption::TF_SYNC);
702     auto ret = TransactInstalldCmd(InstalldInterfaceCode::CHECK_ENCRYPTION, data, reply, option);
703     isEncryption = reply.ReadBool();
704     if (ret != ERR_OK) {
705         LOG_E(BMS_TAG_INSTALLD, "CheckEncryption failed");
706         return ret;
707     }
708     return ERR_OK;
709 }
710 
MoveFiles(const std::string & srcDir,const std::string & desDir)711 ErrCode InstalldProxy::MoveFiles(const std::string &srcDir, const std::string &desDir)
712 {
713     MessageParcel data;
714     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
715     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(srcDir));
716     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(desDir));
717 
718     MessageParcel reply;
719     MessageOption option(MessageOption::TF_SYNC);
720     auto ret = TransactInstalldCmd(InstalldInterfaceCode::MOVE_FILES, data, reply, option);
721     if (ret != ERR_OK) {
722         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
723         return ret;
724     }
725     return ERR_OK;
726 }
727 
ExtractDriverSoFiles(const std::string & srcPath,const std::unordered_multimap<std::string,std::string> & dirMap)728 ErrCode InstalldProxy::ExtractDriverSoFiles(const std::string &srcPath,
729     const std::unordered_multimap<std::string, std::string> &dirMap)
730 {
731     MessageParcel data;
732     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
733     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(srcPath));
734     INSTALLD_PARCEL_WRITE(data, Int32, static_cast<int32_t>(dirMap.size()));
735     for (auto &[orignialDir, destinedDir] : dirMap) {
736         INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(orignialDir));
737         INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(destinedDir));
738     }
739     MessageParcel reply;
740     MessageOption option(MessageOption::TF_SYNC);
741     auto ret = TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_DRIVER_SO_FILE, data, reply, option);
742     if (ret != ERR_OK) {
743         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
744         return ret;
745     }
746     return ERR_OK;
747 }
748 
ExtractEncryptedSoFiles(const std::string & hapPath,const std::string & realSoFilesPath,const std::string & cpuAbi,const std::string & tmpSoPath,int32_t uid)749 ErrCode InstalldProxy::ExtractEncryptedSoFiles(const std::string &hapPath, const std::string &realSoFilesPath,
750     const std::string &cpuAbi, const std::string &tmpSoPath, int32_t uid)
751 {
752     MessageParcel data;
753     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
754     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(hapPath));
755     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(realSoFilesPath));
756     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi));
757     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(tmpSoPath));
758     INSTALLD_PARCEL_WRITE(data, Int32, uid);
759 
760     MessageParcel reply;
761     MessageOption option(MessageOption::TF_SYNC);
762     auto ret = TransactInstalldCmd(InstalldInterfaceCode::EXTRACT_CODED_SO_FILE, data, reply, option);
763     if (ret != ERR_OK) {
764         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
765         return ret;
766     }
767     return ERR_OK;
768 }
769 
VerifyCodeSignatureForHap(const CodeSignatureParam & codeSignatureParam)770 ErrCode InstalldProxy::VerifyCodeSignatureForHap(const CodeSignatureParam &codeSignatureParam)
771 {
772     MessageParcel data;
773     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
774     if (!data.WriteParcelable(&codeSignatureParam)) {
775         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable codeSignatureParam failed");
776         return ERR_APPEXECFWK_PARCEL_ERROR;
777     }
778 
779     MessageParcel reply;
780     MessageOption option(MessageOption::TF_SYNC);
781     auto ret = TransactInstalldCmd(InstalldInterfaceCode::VERIFY_CODE_SIGNATURE_FOR_HAP, data, reply, option);
782     if (ret != ERR_OK) {
783         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
784         return ret;
785     }
786     return ERR_OK;
787 }
788 
DeliverySignProfile(const std::string & bundleName,int32_t profileBlockLength,const unsigned char * profileBlock)789 ErrCode InstalldProxy::DeliverySignProfile(const std::string &bundleName, int32_t profileBlockLength,
790     const unsigned char *profileBlock)
791 {
792     if (profileBlockLength == 0 || profileBlockLength > Constants::MAX_PARCEL_CAPACITY || profileBlock == nullptr) {
793         LOG_E(BMS_TAG_INSTALLD, "invalid params");
794         return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
795     }
796     MessageParcel data;
797     (void)data.SetMaxCapacity(Constants::MAX_PARCEL_CAPACITY);
798     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
799     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
800     INSTALLD_PARCEL_WRITE(data, Int32, profileBlockLength);
801     if (!data.WriteRawData(profileBlock, profileBlockLength)) {
802         LOG_E(BMS_TAG_INSTALLD, "Failed to write raw data");
803         return ERR_APPEXECFWK_PARCEL_ERROR;
804     }
805 
806     MessageParcel reply;
807     MessageOption option(MessageOption::TF_SYNC);
808     auto ret = TransactInstalldCmd(InstalldInterfaceCode::DELIVERY_SIGN_PROFILE, data, reply, option);
809     if (ret != ERR_OK) {
810         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
811         return ret;
812     }
813     return ERR_OK;
814 }
815 
RemoveSignProfile(const std::string & bundleName)816 ErrCode InstalldProxy::RemoveSignProfile(const std::string &bundleName)
817 {
818     MessageParcel data;
819     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
820     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName));
821 
822     MessageParcel reply;
823     MessageOption option(MessageOption::TF_SYNC);
824     auto ret = TransactInstalldCmd(InstalldInterfaceCode::REMOVE_SIGN_PROFILE, data, reply, option);
825     if (ret != ERR_OK) {
826         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
827         return ret;
828     }
829     return ERR_OK;
830 }
831 
SetEncryptionPolicy(const EncryptionParam & encryptionParam,std::string & keyId)832 ErrCode InstalldProxy::SetEncryptionPolicy(const EncryptionParam &encryptionParam, std::string &keyId)
833 {
834     MessageParcel data;
835     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
836     if (!data.WriteParcelable(&encryptionParam)) {
837         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable encryptionParam failed");
838         return ERR_APPEXECFWK_PARCEL_ERROR;
839     }
840 
841     MessageParcel reply;
842     MessageOption option(MessageOption::TF_SYNC);
843     auto ret = TransactInstalldCmd(InstalldInterfaceCode::SET_ENCRYPTION_DIR, data, reply, option);
844     if (ret != ERR_OK) {
845         APP_LOGE("TransactInstalldCmd failed");
846         return ret;
847     }
848     keyId = reply.ReadString();
849     return ERR_OK;
850 }
851 
DeleteEncryptionKeyId(const EncryptionParam & encryptionParam)852 ErrCode InstalldProxy::DeleteEncryptionKeyId(const EncryptionParam &encryptionParam)
853 {
854     MessageParcel data;
855     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
856     if (!data.WriteParcelable(&encryptionParam)) {
857         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable encryptionParam failed");
858         return ERR_APPEXECFWK_PARCEL_ERROR;
859     }
860 
861     MessageParcel reply;
862     MessageOption option(MessageOption::TF_SYNC);
863     auto ret = TransactInstalldCmd(InstalldInterfaceCode::DELETE_ENCRYPTION_KEY_ID, data, reply, option);
864     if (ret != ERR_OK) {
865         APP_LOGE("TransactInstalldCmd failed");
866         return ret;
867     }
868     return ERR_OK;
869 }
870 
RemoveExtensionDir(int32_t userId,const std::vector<std::string> & extensionBundleDirs)871 ErrCode InstalldProxy::RemoveExtensionDir(int32_t userId, const std::vector<std::string> &extensionBundleDirs)
872 {
873     MessageParcel data;
874     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
875     INSTALLD_PARCEL_WRITE(data, Int32, userId);
876     const auto size = extensionBundleDirs.size();
877     if (size > MAX_VEC_SIZE) {
878         APP_LOGE("fail to RemoveExtensionDir due to extensionBundleDirs size %{public}zu is too big", size);
879         return ERR_APPEXECFWK_PARCEL_ERROR;
880     }
881     INSTALLD_PARCEL_WRITE(data, Int32, size);
882     for (size_t i = 0; i < size; i++) {
883         if (extensionBundleDirs[i].size() > MAX_STRING_SIZE) {
884             APP_LOGE("extensionBundleDirs %{public}zu is too long", i);
885             return ERR_APPEXECFWK_PARCEL_ERROR;
886         }
887         if (!data.WriteString(extensionBundleDirs[i])) {
888             APP_LOGE("fail to RemoveExtensionDir due to write extensionBundleDirs %{public}zu fail", i);
889             return ERR_APPEXECFWK_PARCEL_ERROR;
890         }
891     }
892 
893     MessageParcel reply;
894     MessageOption option(MessageOption::TF_SYNC);
895     auto ret = TransactInstalldCmd(InstalldInterfaceCode::REMOVE_EXTENSION_DIR, data, reply, option);
896     if (ret != ERR_OK) {
897         APP_LOGE("TransactInstalldCmd failed");
898         return ret;
899     }
900     return ERR_OK;
901 }
902 
IsExistExtensionDir(int32_t userId,const std::string & extensionBundleDir,bool & isExist)903 ErrCode InstalldProxy::IsExistExtensionDir(int32_t userId, const std::string &extensionBundleDir, bool &isExist)
904 {
905     MessageParcel data;
906     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
907     INSTALLD_PARCEL_WRITE(data, Int32, userId);
908     if (extensionBundleDir.size() > MAX_STRING_SIZE) {
909         APP_LOGE("extensionBundleDir is too long");
910         return ERR_APPEXECFWK_PARCEL_ERROR;
911     }
912     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(extensionBundleDir));
913 
914     MessageParcel reply;
915     MessageOption option(MessageOption::TF_SYNC);
916     auto ret = TransactInstalldCmd(InstalldInterfaceCode::IS_EXIST_EXTENSION_DIR, data, reply, option);
917     if (ret != ERR_OK) {
918         APP_LOGE("TransactInstalldCmd failed");
919         return ret;
920     }
921     isExist = reply.ReadBool();
922     return ERR_OK;
923 }
924 
GetExtensionSandboxTypeList(std::vector<std::string> & typeList)925 ErrCode InstalldProxy::GetExtensionSandboxTypeList(std::vector<std::string> &typeList)
926 {
927     MessageParcel data;
928     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
929     MessageParcel reply;
930     MessageOption option(MessageOption::TF_SYNC);
931     auto ret = TransactInstalldCmd(InstalldInterfaceCode::GET_EXTENSION_SANDBOX_TYPE_LIST, data, reply, option);
932     if (ret != ERR_OK) {
933         APP_LOGE("TransactInstalldCmd failed");
934         return ret;
935     }
936     if (!reply.ReadStringVector(&typeList)) {
937         APP_LOGE("fail to GetExtensionSandboxTypeList from reply");
938         return ERR_APPEXECFWK_PARCEL_ERROR;
939     }
940     return ERR_OK;
941 }
942 
AddUserDirDeleteDfx(int32_t userId)943 ErrCode InstalldProxy::AddUserDirDeleteDfx(int32_t userId)
944 {
945     MessageParcel data;
946     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
947     INSTALLD_PARCEL_WRITE(data, Int32, userId);
948     MessageParcel reply;
949     MessageOption option(MessageOption::TF_SYNC);
950     auto ret = TransactInstalldCmd(InstalldInterfaceCode::ADD_USER_DIR_DELETE_DFX, data, reply, option);
951     if (ret != ERR_OK) {
952         APP_LOGE("TransactInstalldCmd failed");
953         return ret;
954     }
955     return ERR_OK;
956 }
957 
CreateExtensionDataDir(const CreateDirParam & createDirParam)958 ErrCode InstalldProxy::CreateExtensionDataDir(const CreateDirParam &createDirParam)
959 {
960     MessageParcel data;
961     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
962     if (!data.WriteParcelable(&createDirParam)) {
963         LOG_E(BMS_TAG_INSTALLD, "WriteParcelable createDirParam failed");
964         return ERR_APPEXECFWK_PARCEL_ERROR;
965     }
966 
967     MessageParcel reply;
968     MessageOption option;
969     return TransactInstalldCmd(InstalldInterfaceCode::CREATE_EXTENSION_DATA_DIR, data, reply, option);
970 }
971 
MoveHapToCodeDir(const std::string & originPath,const std::string & targetPath)972 ErrCode InstalldProxy::MoveHapToCodeDir(const std::string &originPath, const std::string &targetPath)
973 {
974     MessageParcel data;
975     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
976     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(originPath));
977     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(targetPath));
978 
979     MessageParcel reply;
980     MessageOption option(MessageOption::TF_SYNC);
981     return TransactInstalldCmd(InstalldInterfaceCode::MOVE_HAP_TO_CODE_DIR, data, reply, option);
982 }
983 
MigrateData(const std::vector<std::string> & sourcePaths,const std::string & destinationPath)984 ErrCode InstalldProxy::MigrateData(const std::vector<std::string> &sourcePaths, const std::string &destinationPath)
985 {
986     MessageParcel data;
987     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
988     INSTALLD_PARCEL_WRITE(data, Int32, static_cast<int32_t>(sourcePaths.size()));
989     for (auto &path : sourcePaths) {
990         INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(path));
991     }
992     INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(destinationPath));
993     MessageParcel reply;
994     MessageOption option(MessageOption::TF_SYNC);
995     auto ret = TransactInstalldCmd(InstalldInterfaceCode::MIGRATE_DATA, data, reply, option);
996     if (ret != ERR_OK) {
997         LOG_E(BMS_TAG_INSTALLD, "TransactInstalldCmd failed");
998         return ret;
999     }
1000     return ERR_OK;
1001 }
1002 
CreateDataGroupDirs(const std::vector<CreateDirParam> & params)1003 ErrCode InstalldProxy::CreateDataGroupDirs(const std::vector<CreateDirParam> &params)
1004 {
1005     MessageParcel data;
1006     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
1007     if (params.empty()) {
1008         LOG_E(BMS_TAG_INSTALLD, "params is empty");
1009         return ERR_BUNDLE_MANAGER_INVALID_PARAMETER;
1010     }
1011     INSTALLD_PARCEL_WRITE(data, Uint32, params.size());
1012     for (const auto &param : params) {
1013         if (!data.WriteParcelable(&param)) {
1014             LOG_E(BMS_TAG_INSTALLD, "WriteParcelable param failed");
1015             return ERR_APPEXECFWK_PARCEL_ERROR;
1016         }
1017     }
1018 
1019     MessageParcel reply;
1020     MessageOption option;
1021     return TransactInstalldCmd(InstalldInterfaceCode::CREATE_DATA_GROUP_DIRS, data, reply, option);
1022 }
1023 
DeleteDataGroupDirs(const std::vector<std::string> & uuidList,int32_t userId)1024 ErrCode InstalldProxy::DeleteDataGroupDirs(const std::vector<std::string> &uuidList, int32_t userId)
1025 {
1026     MessageParcel data;
1027     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
1028     INSTALLD_PARCEL_WRITE(data, Uint32, uuidList.size());
1029     for (const std::string &dir : uuidList) {
1030         INSTALLD_PARCEL_WRITE(data, String, dir);
1031     }
1032     INSTALLD_PARCEL_WRITE(data, Int32, userId);
1033 
1034     MessageParcel reply;
1035     MessageOption option;
1036     return TransactInstalldCmd(InstalldInterfaceCode::DELETE_DATA_GROUP_DIRS, data, reply, option);
1037 }
1038 
BackUpFirstBootLog()1039 ErrCode InstalldProxy::BackUpFirstBootLog()
1040 {
1041     MessageParcel data;
1042     INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
1043     MessageParcel reply;
1044     MessageOption option;
1045     return TransactInstalldCmd(InstalldInterfaceCode::BACK_UP_FIRST_BOOT_LOG, data, reply, option);
1046 }
1047 
TransactInstalldCmd(InstalldInterfaceCode code,MessageParcel & data,MessageParcel & reply,MessageOption & option)1048 ErrCode InstalldProxy::TransactInstalldCmd(InstalldInterfaceCode code, MessageParcel &data, MessageParcel &reply,
1049     MessageOption &option)
1050 {
1051     sptr<IRemoteObject> remote = Remote();
1052     if (remote == nullptr) {
1053         LOG_E(BMS_TAG_INSTALLD, "fail to send %{public}u cmd to service due to remote object is null",
1054             (unsigned int)(code));
1055         return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
1056     }
1057 
1058     if (remote->SendRequest(static_cast<uint32_t>(code), data, reply, option) != OHOS::NO_ERROR) {
1059         LOG_E(BMS_TAG_INSTALLD, "fail to send %{public}u request to service due to transact error",
1060             (unsigned int)(code));
1061         return ERR_APPEXECFWK_INSTALLD_SERVICE_DIED;
1062     }
1063     return reply.ReadInt32();
1064 }
1065 }  // namespace AppExecFwk
1066 }  // namespace OHOS