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