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