• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_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     return true;
58 }
59 
ReadFromParcel(Parcel & parcel)60 bool DlpStateData::ReadFromParcel(Parcel &parcel)
61 {
62     if (!parcel.ReadInt32(targetPid)) {
63         return false;
64     }
65 
66     if (!parcel.ReadInt32(targetUid)) {
67         return false;
68     }
69 
70     std::u16string strValue;
71     if (!parcel.ReadString16(strValue)) {
72         return false;
73     }
74     targetBundleName = Str16ToStr8(strValue);
75 
76     if (!parcel.ReadString16(strValue)) {
77         return false;
78     }
79     targetModuleName = Str16ToStr8(strValue);
80 
81     if (!parcel.ReadString16(strValue)) {
82         return false;
83     }
84     targetAbilityName = Str16ToStr8(strValue);
85 
86     if (!parcel.ReadInt32(callerUid)) {
87         HILOG_WARN("DlpStateData::ReadFromParcel read callerUid failed");
88         return false;
89     }
90 
91     if (!parcel.ReadInt32(callerPid)) {
92         HILOG_WARN("DlpStateData::ReadFromParcel read callerPid failed");
93         return false;
94     }
95 
96     if (!parcel.ReadString16(strValue)) {
97         HILOG_WARN("DlpStateData::ReadFromParcel read strValue failed");
98         return false;
99     }
100     callerName = Str16ToStr8(strValue);
101 
102     return true;
103 }
104 
Unmarshalling(Parcel & parcel)105 DlpStateData *DlpStateData::Unmarshalling(Parcel &parcel)
106 {
107     DlpStateData *data = new DlpStateData();
108     if (!data->ReadFromParcel(parcel)) {
109         delete data;
110         data = nullptr;
111     }
112     return data;
113 }
114 }  // namespace AbilityRuntime
115 }  // namespace OHOS
116