1 /*
2  * Copyright (c) 2022-2024 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_state_data.h"
17 
18 #include "hilog_tag_wrapper.h"
19 #include "string_ex.h"
20 
21 namespace OHOS {
22 namespace AbilityRuntime {
Marshalling(Parcel & parcel) const23 bool DlpStateData::Marshalling(Parcel &parcel) const
24 {
25     if (!parcel.WriteInt32(targetPid)) {
26         return false;
27     }
28 
29     if (!parcel.WriteInt32(targetUid)) {
30         return false;
31     }
32 
33     if (!parcel.WriteString16(Str8ToStr16(targetBundleName))) {
34         return false;
35     }
36 
37     if (!parcel.WriteString16(Str8ToStr16(targetModuleName))) {
38         return false;
39     }
40 
41     if (!parcel.WriteString16(Str8ToStr16(targetAbilityName))) {
42         return false;
43     }
44 
45     if (!parcel.WriteInt32(callerUid)) {
46         return false;
47     }
48 
49     if (!parcel.WriteInt32(callerPid)) {
50         return false;
51     }
52 
53     if (!parcel.WriteString16(Str8ToStr16(callerName))) {
54         return false;
55     }
56 
57     TAG_LOGD(AAFwkTag::CONNECTION, "end");
58     return true;
59 }
60 
ReadFromParcel(Parcel & parcel)61 bool DlpStateData::ReadFromParcel(Parcel &parcel)
62 {
63     if (!parcel.ReadInt32(targetPid)) {
64         return false;
65     }
66 
67     if (!parcel.ReadInt32(targetUid)) {
68         return false;
69     }
70 
71     std::u16string strValue;
72     if (!parcel.ReadString16(strValue)) {
73         return false;
74     }
75     targetBundleName = Str16ToStr8(strValue);
76 
77     if (!parcel.ReadString16(strValue)) {
78         return false;
79     }
80     targetModuleName = Str16ToStr8(strValue);
81 
82     if (!parcel.ReadString16(strValue)) {
83         return false;
84     }
85     targetAbilityName = Str16ToStr8(strValue);
86 
87     if (!parcel.ReadInt32(callerUid)) {
88         TAG_LOGW(AAFwkTag::CONNECTION, "read callerUid failed");
89         return false;
90     }
91 
92     if (!parcel.ReadInt32(callerPid)) {
93         TAG_LOGW(AAFwkTag::CONNECTION, "read callerPid failed");
94         return false;
95     }
96 
97     if (!parcel.ReadString16(strValue)) {
98         TAG_LOGW(AAFwkTag::CONNECTION, "read strValue failed");
99         return false;
100     }
101     callerName = Str16ToStr8(strValue);
102 
103     return true;
104 }
105 
Unmarshalling(Parcel & parcel)106 DlpStateData *DlpStateData::Unmarshalling(Parcel &parcel)
107 {
108     DlpStateData *data = new DlpStateData();
109     if (!data->ReadFromParcel(parcel)) {
110         delete data;
111         data = nullptr;
112     }
113     return data;
114 }
115 }  // namespace AbilityRuntime
116 }  // namespace OHOS
117