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 "form_share_info.h"
17 #include "fms_log_wrapper.h"
18 #include "message_parcel.h"
19 #include "string_ex.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)23 bool FormShareInfo::ReadFromParcel(Parcel &parcel)
24 {
25     formId = parcel.ReadInt64();
26     formName = Str16ToStr8(parcel.ReadString16());
27     bundleName = Str16ToStr8(parcel.ReadString16());
28     moduleName = Str16ToStr8(parcel.ReadString16());
29     abilityName = Str16ToStr8(parcel.ReadString16());
30     formTempFlag = parcel.ReadBool();
31     dimensionId = parcel.ReadInt32();
32 
33     std::unique_ptr<AAFwk::WantParams> wantParams(parcel.ReadParcelable<AAFwk::WantParams>());
34     if (wantParams == nullptr) {
35         return false;
36     }
37     providerShareData = *wantParams;
38 
39     deviceId = Str16ToStr8(parcel.ReadString16());
40 
41     return true;
42 }
43 
Marshalling(Parcel & parcel) const44 bool FormShareInfo::Marshalling(Parcel &parcel) const
45 {
46     // write formId
47     if (!parcel.WriteInt64(formId)) {
48         return false;
49     }
50 
51     // write formName
52     if (!parcel.WriteString16(Str8ToStr16(formName))) {
53         return false;
54     }
55 
56     // write bundleName
57     if (!parcel.WriteString16(Str8ToStr16(bundleName))) {
58         return false;
59     }
60 
61     // write moduleName
62     if (!parcel.WriteString16(Str8ToStr16(moduleName))) {
63         return false;
64     }
65 
66     // write abilityName
67     if (!parcel.WriteString16(Str8ToStr16(abilityName))) {
68         return false;
69     }
70 
71     // write tempFlag
72     if (!parcel.WriteBool(formTempFlag)) {
73         return false;
74     }
75 
76     // write dimensionId
77     if (!parcel.WriteInt32(dimensionId)) {
78         return false;
79     }
80 
81     // write providerShareData
82     if (!parcel.WriteParcelable(&providerShareData)) {
83         return false;
84     }
85 
86     // write deviceId
87     if (!parcel.WriteString16(Str8ToStr16(deviceId))) {
88         return false;
89     }
90 
91     return true;
92 }
93 
Unmarshalling(Parcel & parcel)94 FormShareInfo* FormShareInfo::Unmarshalling(Parcel &parcel)
95 {
96     std::unique_ptr<FormShareInfo> object = std::make_unique<FormShareInfo>();
97     if (object && !object->ReadFromParcel(parcel)) {
98         object = nullptr;
99         return nullptr;
100     }
101     return object.release();
102 }
103 } // namespace AppExecFwk
104 } // namespace OHOS
105