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