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 "retention_sandbox_info.h"
17 #include "dlp_permission_log.h"
18 #include "i_json_operator.h"
19 
20 namespace OHOS {
21 namespace Security {
22 namespace DlpPermission {
23 namespace {
24 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, SECURITY_DOMAIN_DLP_PERMISSION,
25                                                        "RetentionSandBoxInfo" };
26 constexpr uint32_t APP_INDEX = 0;
27 }
28 
RetentionSandBoxInfo()29 RetentionSandBoxInfo::RetentionSandBoxInfo()
30 {
31     bundleName_ = "";
32     appIndex_ = APP_INDEX;
33     dlpFileAccess_ = NO_PERMISSION;
34     hasRead_ = false;
35     docUriSet_.clear();
36 }
37 
Marshalling(Parcel& out) const38 bool RetentionSandBoxInfo::Marshalling(Parcel& out) const
39 {
40     if (!(out.WriteInt32(this->appIndex_))) {
41         DLP_LOG_ERROR(LABEL, "Write appIndex fail");
42         return false;
43     }
44     if (!(out.WriteString(this->bundleName_))) {
45         DLP_LOG_ERROR(LABEL, "Write bundleName fail");
46         return false;
47     }
48     std::vector<std::string> docUriVec(this->docUriSet_.begin(), this->docUriSet_.end());
49     if (!(out.WriteStringVector(docUriVec))) {
50         DLP_LOG_ERROR(LABEL, "Write docUriVec fail");
51         return false;
52     }
53     return true;
54 }
55 
Unmarshalling(Parcel& in)56 RetentionSandBoxInfo* RetentionSandBoxInfo::Unmarshalling(Parcel& in)
57 {
58     auto* parcel = new (std::nothrow) RetentionSandBoxInfo();
59     if (parcel == nullptr) {
60         DLP_LOG_ERROR(LABEL, "Alloc buff for parcel fail");
61         return nullptr;
62     }
63     if (!(in.ReadInt32(parcel->appIndex_))) {
64         DLP_LOG_ERROR(LABEL, "Read appIndex fail");
65         delete parcel;
66         return nullptr;
67     }
68     if (!(in.ReadString(parcel->bundleName_))) {
69         DLP_LOG_ERROR(LABEL, "Read bundleName fail");
70         delete parcel;
71         return nullptr;
72     }
73     std::vector<std::string> docUriVec;
74     if (!(in.ReadStringVector(&docUriVec))) {
75         DLP_LOG_ERROR(LABEL, "Read docUriVec fail");
76         delete parcel;
77         return nullptr;
78     }
79 
80     std::set<std::string> docUriSet(docUriVec.begin(), docUriVec.end());
81     parcel->docUriSet_ = docUriSet;
82     return parcel;
83 }
84 } // namespace DlpPermission
85 } // namespace Security
86 } // namespace OHOS
87