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 "dlp_permission_info_parcel.h"
17 #include "dlp_permission_log.h"
18 namespace OHOS {
19 namespace Security {
20 namespace DlpPermission {
21 namespace {
22 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_DLP_PERMISSION, "DlpPermissionParcel"};
23 }
Marshalling(Parcel & out) const24 bool DLPPermissionInfoParcel::Marshalling(Parcel& out) const
25 {
26     if (!(out.WriteUint32(this->permInfo_.dlpFileAccess))) {
27         DLP_LOG_ERROR(LABEL, "Write dlp file access fail");
28         return false;
29     }
30     if (!(out.WriteUint32(this->permInfo_.flags))) {
31         DLP_LOG_ERROR(LABEL, "Write flags fail");
32         return false;
33     }
34     return true;
35 }
36 
Unmarshalling(Parcel & in)37 DLPPermissionInfoParcel* DLPPermissionInfoParcel::Unmarshalling(Parcel& in)
38 {
39     auto permInfoParcel = new (std::nothrow) DLPPermissionInfoParcel();
40     if (permInfoParcel == nullptr) {
41         DLP_LOG_ERROR(LABEL, "Alloc buff for perm info parcel fail");
42         return nullptr;
43     }
44 
45     uint32_t res;
46     if (!(in.ReadUint32(res))) {
47         DLP_LOG_ERROR(LABEL, "Read dlpFileAccess fail");
48         delete permInfoParcel;
49         permInfoParcel = nullptr;
50         return nullptr;
51     }
52     permInfoParcel->permInfo_.dlpFileAccess = static_cast<DLPFileAccess>(res);
53 
54     if (!(in.ReadUint32(res))) {
55         DLP_LOG_ERROR(LABEL, "Read flags fail");
56         delete permInfoParcel;
57         permInfoParcel = nullptr;
58         return nullptr;
59     }
60     permInfoParcel->permInfo_.flags = static_cast<ActionFlags>(res);
61     return permInfoParcel;
62 }
63 }  // namespace DlpPermission
64 }  // namespace Security
65 }  // namespace OHOS
66