1 /*
2  * Copyright (c) 2023-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 "form_instance.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 FormInstance::ReadFromParcel(Parcel &parcel)
24 {
25     formId = parcel.ReadInt64();
26     formHostName = Str16ToStr8(parcel.ReadString16());
27     formVisiblity = static_cast<FormVisibilityType>(parcel.ReadInt32());
28     specification = parcel.ReadInt32();
29     bundleName = Str16ToStr8(parcel.ReadString16());
30     moduleName = Str16ToStr8(parcel.ReadString16());
31     abilityName = Str16ToStr8(parcel.ReadString16());
32     formName = Str16ToStr8(parcel.ReadString16());
33     formUsageState = static_cast<FormUsageState>(parcel.ReadInt32());
34     description = Str16ToStr8(parcel.ReadString16());
35     appIndex = parcel.ReadInt32();
36     userId = parcel.ReadInt32();
37     return true;
38 }
39 
Marshalling(Parcel &parcel) const40 bool FormInstance::Marshalling(Parcel &parcel) const
41 {
42     // write formId
43     if (!parcel.WriteInt64(formId)) {
44         return false;
45     }
46 
47     // write formHostName
48     if (!parcel.WriteString16(Str8ToStr16(formHostName))) {
49         return false;
50     }
51 
52     // write formVisiblity
53     if (!parcel.WriteInt32(static_cast<int32_t>(formVisiblity))) {
54         return false;
55     }
56 
57     // write specification
58     if (!parcel.WriteInt32(specification)) {
59         return false;
60     }
61 
62     // write bundleName
63     if (!parcel.WriteString16(Str8ToStr16(bundleName))) {
64         return false;
65     }
66 
67     // write moduleName
68     if (!parcel.WriteString16(Str8ToStr16(moduleName))) {
69         return false;
70     }
71 
72     // write abilityName
73     if (!parcel.WriteString16(Str8ToStr16(abilityName))) {
74         return false;
75     }
76 
77     // write formName
78     if (!parcel.WriteString16(Str8ToStr16(formName))) {
79         return false;
80     }
81 
82     // write formUsageState
83     if (!parcel.WriteInt32(static_cast<int32_t>(formUsageState))) {
84         return false;
85     }
86 
87     // write description
88     if (!parcel.WriteString16(Str8ToStr16(description))) {
89         return false;
90     }
91 
92     // write appIndex
93     if (!parcel.WriteInt32(appIndex)) {
94         return false;
95     }
96 
97     // write userId
98     if (!parcel.WriteInt32(userId)) {
99         return false;
100     }
101     return true;
102 }
103 
Unmarshalling(Parcel &parcel)104 FormInstance* FormInstance::Unmarshalling(Parcel &parcel)
105 {
106     std::unique_ptr<FormInstance> object = std::make_unique<FormInstance>();
107     if (object && !object->ReadFromParcel(parcel)) {
108         object = nullptr;
109         return nullptr;
110     }
111     return object.release();
112 }
113 } // namespace AppExecFwk
114 } // namespace OHOS
115