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