1 /*
2 * Copyright (c) 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/create_dir_param.h"
17
18 #include "parcel_macro.h"
19 #include "string_ex.h"
20
21 namespace OHOS {
22 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)23 bool CreateDirParam::ReadFromParcel(Parcel &parcel)
24 {
25 bundleName = Str16ToStr8(parcel.ReadString16());
26 int32_t extensionDirsSize;
27 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, extensionDirsSize);
28 CONTAINER_SECURITY_VERIFY(parcel, extensionDirsSize, &extensionDirs);
29 for (int32_t i = 0; i < extensionDirsSize; ++i) {
30 std::string extensionDir = Str16ToStr8(parcel.ReadString16());
31 extensionDirs.emplace_back(extensionDir);
32 }
33 apl = Str16ToStr8(parcel.ReadString16());
34 userId = parcel.ReadInt32();
35 uid = parcel.ReadInt32();
36 gid = parcel.ReadInt32();
37 isPreInstallApp = parcel.ReadBool();
38 debug = parcel.ReadBool();
39 isDlpSandbox = parcel.ReadBool();
40 createDirFlag = static_cast<CreateDirFlag>(parcel.ReadInt32());
41 return true;
42 }
43
Marshalling(Parcel & parcel) const44 bool CreateDirParam::Marshalling(Parcel &parcel) const
45 {
46 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
47 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, extensionDirs.size());
48 for (auto &item : extensionDirs) {
49 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(item));
50 }
51 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(apl));
52 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, userId);
53 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uid);
54 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, gid);
55 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isPreInstallApp);
56 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, debug);
57 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isDlpSandbox);
58 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(createDirFlag));
59 return true;
60 }
61
Unmarshalling(Parcel & parcel)62 CreateDirParam *CreateDirParam::Unmarshalling(Parcel &parcel)
63 {
64 CreateDirParam *info = new (std::nothrow) CreateDirParam();
65 if (info != nullptr && !info->ReadFromParcel(parcel)) {
66 APP_LOGE("read from parcel failed");
67 delete info;
68 info = nullptr;
69 }
70 return info;
71 }
72 } // namespace AppExecFwk
73 } // namespace OHOS
74