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 dataDirEl = static_cast<DataDirEl>(parcel.ReadUint8());
42 return true;
43 }
44
Marshalling(Parcel & parcel) const45 bool CreateDirParam::Marshalling(Parcel &parcel) const
46 {
47 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
48 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, extensionDirs.size());
49 for (auto &item : extensionDirs) {
50 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(item));
51 }
52 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(apl));
53 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, userId);
54 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uid);
55 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, gid);
56 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isPreInstallApp);
57 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, debug);
58 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isDlpSandbox);
59 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(createDirFlag));
60 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint8, parcel, static_cast<uint8_t>(dataDirEl));
61 return true;
62 }
63
Unmarshalling(Parcel & parcel)64 CreateDirParam *CreateDirParam::Unmarshalling(Parcel &parcel)
65 {
66 CreateDirParam *info = new (std::nothrow) CreateDirParam();
67 if (info != nullptr && !info->ReadFromParcel(parcel)) {
68 APP_LOGE("read from parcel failed");
69 delete info;
70 info = nullptr;
71 }
72 return info;
73 }
74 } // namespace AppExecFwk
75 } // namespace OHOS
76