• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (C) 2025 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 "input_client_info.h"
17 
18 namespace OHOS {
19 namespace MiscServices {
20 
ReadFromParcel(Parcel & in)21 bool InputClientInfoInner::ReadFromParcel(Parcel &in)
22 {
23     pid = in.ReadInt32();
24     uid = in.ReadInt32();
25     userID = in.ReadInt32();
26     displayId = in.ReadUint64();
27     isShowKeyboard = in.ReadBool();
28     int32_t bindImeTypeData = in.ReadInt32();
29     bindImeType = static_cast<ImeType>(bindImeTypeData);
30 
31     std::unique_ptr<TextTotalConfigInner> configInfo(in.ReadParcelable<TextTotalConfigInner>());
32     if (configInfo == nullptr) {
33         return false;
34     }
35     config = *configInfo;
36 
37     eventFlag = in.ReadUint32();
38 
39     std::unique_ptr<InputAttributeInner> attributeInfo(in.ReadParcelable<InputAttributeInner>());
40     if (attributeInfo == nullptr) {
41         return false;
42     }
43     attribute = *attributeInfo;
44 
45     if (in.ReadBool()) {
46         sptr<IRemoteObject> clientObj;
47         clientObj = (static_cast<MessageParcel*>(&in))->ReadRemoteObject();
48         client = iface_cast<IInputClient>(clientObj);
49     }
50 
51     if (in.ReadBool()) {
52         channel = (static_cast<MessageParcel*>(&in))->ReadRemoteObject();
53     }
54     uint32_t stateData = in.ReadUint32();
55     state = static_cast<ClientState>(stateData);
56     isNotifyInputStart = in.ReadBool();
57     needHide = in.ReadBool();
58     uiExtensionTokenId = in.ReadUint32();
59     int32_t requestKeyboardReasonData = in.ReadInt32();
60     requestKeyboardReason = static_cast<RequestKeyboardReason>(requestKeyboardReasonData);
61     uint32_t typeData = in.ReadUint32();
62     type = static_cast<ClientType>(typeData);
63     name = in.ReadString();
64     return true;
65 }
66 
Unmarshalling(Parcel & in)67 InputClientInfoInner *InputClientInfoInner::Unmarshalling(Parcel &in)
68 {
69     InputClientInfoInner *data = new (std::nothrow) InputClientInfoInner();
70     if (data && !data->ReadFromParcel(in)) {
71         delete data;
72         data = nullptr;
73     }
74     return data;
75 }
76 
Marshalling(Parcel & out) const77 bool InputClientInfoInner::Marshalling(Parcel &out) const
78 {
79     if (!out.WriteInt32(pid)) {
80         return false;
81     }
82     if (!out.WriteInt32(uid)) {
83         return false;
84     }
85     if (!out.WriteInt32(userID)) {
86         return false;
87     }
88     if (!out.WriteUint64(displayId)) {
89         return false;
90     }
91     if (!out.WriteBool(isShowKeyboard)) {
92         return false;
93     }
94     if (!out.WriteInt32(static_cast<int32_t>(bindImeType))) {
95         return false;
96     }
97     if (!out.WriteParcelable(&config)) {
98         return false;
99     }
100     if (!out.WriteUint32(eventFlag)) {
101         return false;
102     }
103     if (!out.WriteParcelable(&attribute)) {
104         return false;
105     }
106     if (!MarshallingTwo(out)) {
107         return false;
108     }
109     if (!MarshallingOne(out)) {
110         return false;
111     }
112     return true;
113 }
114 
MarshallingTwo(Parcel & out) const115 bool InputClientInfoInner::MarshallingTwo(Parcel &out) const
116 {
117     if (client == nullptr) {
118         if (!out.WriteBool(false)) {
119             return false;
120         }
121     } else {
122         if (!out.WriteBool(true)) {
123             return false;
124         }
125         if (!out.WriteRemoteObject(client->AsObject())) {
126             return false;
127         }
128     }
129     if (channel == nullptr) {
130         if (!out.WriteBool(false)) {
131             return false;
132         }
133     } else {
134         if (!out.WriteBool(true)) {
135             return false;
136         }
137         if (!out.WriteRemoteObject(channel)) {
138             return false;
139         }
140     }
141     return true;
142 }
143 
MarshallingOne(Parcel & out) const144 bool InputClientInfoInner::MarshallingOne(Parcel &out) const
145 {
146     if (!out.WriteUint32(static_cast<uint32_t>(state))) {
147         return false;
148     }
149     if (!out.WriteBool(isNotifyInputStart)) {
150         return false;
151     }
152     if (!out.WriteBool(needHide)) {
153         return false;
154     }
155     if (!out.WriteUint32(uiExtensionTokenId)) {
156         return false;
157     }
158     if (!out.WriteInt32(static_cast<int32_t>(requestKeyboardReason))) {
159         return false;
160     }
161     if (!out.WriteUint32(static_cast<uint32_t>(type))) {
162         return false;
163     }
164     if (!out.WriteString(name)) {
165         return false;
166     }
167     return true;
168 }
169 } // namespace MiscServices
170 } // namespace OHOS