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 docUriSet_.clear();
37 }
38
Marshalling(Parcel & out) const39 bool RetentionSandBoxInfo::Marshalling(Parcel& out) const
40 {
41 if (!(out.WriteInt32(this->appIndex_))) {
42 DLP_LOG_ERROR(LABEL, "Write appIndex fail");
43 return false;
44 }
45 if (!(out.WriteString(this->bundleName_))) {
46 DLP_LOG_ERROR(LABEL, "Write bundleName fail");
47 return false;
48 }
49 std::vector<std::string> docUriVec(this->docUriSet_.begin(), this->docUriSet_.end());
50 if (!(out.WriteStringVector(docUriVec))) {
51 DLP_LOG_ERROR(LABEL, "Write docUriVec fail");
52 return false;
53 }
54 return true;
55 }
56
Unmarshalling(Parcel & in)57 RetentionSandBoxInfo* RetentionSandBoxInfo::Unmarshalling(Parcel& in)
58 {
59 auto* parcel = new (std::nothrow) RetentionSandBoxInfo();
60 if (parcel == nullptr) {
61 DLP_LOG_ERROR(LABEL, "Alloc buff for parcel fail");
62 return nullptr;
63 }
64 if (!(in.ReadInt32(parcel->appIndex_))) {
65 DLP_LOG_ERROR(LABEL, "Read appIndex fail");
66 delete parcel;
67 parcel = nullptr;
68 return nullptr;
69 }
70 if (!(in.ReadString(parcel->bundleName_))) {
71 DLP_LOG_ERROR(LABEL, "Read bundleName fail");
72 delete parcel;
73 parcel = nullptr;
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 parcel = nullptr;
81 return nullptr;
82 }
83
84 std::set<std::string> docUriSet(docUriVec.begin(), docUriVec.end());
85 parcel->docUriSet_ = docUriSet;
86 return parcel;
87 }
88 } // namespace DlpPermission
89 } // namespace Security
90 } // namespace OHOS
91