• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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/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     appIndex = parcel.ReadInt32();
38     isPreInstallApp = parcel.ReadBool();
39     debug = parcel.ReadBool();
40     isDlpSandbox = parcel.ReadBool();
41     createDirFlag = static_cast<CreateDirFlag>(parcel.ReadInt32());
42     uuid = Str16ToStr8(parcel.ReadString16());
43     dataDirEl = static_cast<DataDirEl>(parcel.ReadUint8());
44     return true;
45 }
46 
Marshalling(Parcel & parcel) const47 bool CreateDirParam::Marshalling(Parcel &parcel) const
48 {
49     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
50     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, extensionDirs.size());
51     for (auto &item : extensionDirs) {
52         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(item));
53     }
54     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(apl));
55     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, userId);
56     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uid);
57     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, gid);
58     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appIndex);
59     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isPreInstallApp);
60     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, debug);
61     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isDlpSandbox);
62     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(createDirFlag));
63     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uuid));
64     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint8, parcel, static_cast<uint8_t>(dataDirEl));
65     return true;
66 }
67 
Unmarshalling(Parcel & parcel)68 CreateDirParam *CreateDirParam::Unmarshalling(Parcel &parcel)
69 {
70     CreateDirParam *info = new (std::nothrow) CreateDirParam();
71     if (info != nullptr && !info->ReadFromParcel(parcel)) {
72         APP_LOGE("read from parcel failed");
73         delete info;
74         info = nullptr;
75     }
76     return info;
77 }
78 }  // namespace AppExecFwk
79 }  // namespace OHOS
80