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