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 "window_extension_client_proxy.h"
17 
18 #include <ipc_types.h>
19 #include <message_option.h>
20 #include "window_manager_hilog.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace {
25 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionProxy"};
26 }
27 
OnWindowReady(const std::shared_ptr<RSSurfaceNode> & surfaceNode)28 void WindowExtensionClientProxy::OnWindowReady(const std::shared_ptr<RSSurfaceNode>& surfaceNode)
29 {
30     MessageParcel data;
31     MessageParcel replay;
32     MessageOption option(MessageOption::TF_SYNC);
33 
34     if (!data.WriteInterfaceToken(GetDescriptor())) {
35         WLOGFE("write token failed");
36         return;
37     }
38 
39     if (surfaceNode == nullptr || (!surfaceNode->Marshalling(data))) {
40         WLOGFE("write surfaceNode failed");
41         return;
42     }
43 
44     sptr<IRemoteObject> remote = Remote();
45     if (remote == nullptr) {
46         WLOGFE("remote is null");
47         return;
48     }
49 
50     if (remote->SendRequest(TRANS_ID_ON_WINDOW_READY, data, replay, option) != ERR_NONE) {
51         WLOGFE("send request failed");
52     }
53     WLOGI("end");
54 }
55 
OnBackPress()56 void WindowExtensionClientProxy::OnBackPress()
57 {
58     MessageParcel data;
59     MessageParcel replay;
60     MessageOption option(MessageOption::TF_SYNC);
61     WLOGI("call");
62     if (!data.WriteInterfaceToken(GetDescriptor())) {
63         WLOGFE("write token failed");
64         return;
65     }
66 
67     sptr<IRemoteObject> remote = Remote();
68     if (remote == nullptr) {
69         WLOGFE("remote is null");
70         return;
71     }
72 
73     if (remote->SendRequest(TRANS_ID_ON_BACK_PRESS, data, replay, option) != ERR_NONE) {
74         WLOGFE("send request failed");
75     }
76     WLOGI("end");
77 }
78 
OnKeyEvent(const std::shared_ptr<MMI::KeyEvent> & keyEvent)79 void WindowExtensionClientProxy::OnKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
80 {
81     MessageParcel data;
82     MessageParcel replay;
83     MessageOption option(MessageOption::TF_SYNC);
84 
85     if (!data.WriteInterfaceToken(GetDescriptor())) {
86         WLOGFE("write token failed");
87         return;
88     }
89 
90     if (!keyEvent->WriteToParcel(data)) {
91         WLOGFE("write key event failed");
92         return;
93     }
94 
95     sptr<IRemoteObject> remote = Remote();
96     if (remote == nullptr) {
97         WLOGFE("remote is null");
98         return;
99     }
100 
101     if (remote->SendRequest(TRANS_ID_ON_KEY_EVENT, data, replay, option) != ERR_NONE) {
102         WLOGFE("send request failed");
103     }
104     WLOGI("end");
105 }
106 
OnPointerEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)107 void WindowExtensionClientProxy::OnPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
108 {
109     MessageParcel data;
110     MessageParcel replay;
111     MessageOption option(MessageOption::TF_SYNC);
112 
113     if (!data.WriteInterfaceToken(GetDescriptor())) {
114         WLOGFE("write token failed");
115         return;
116     }
117 
118     if (!pointerEvent->WriteToParcel(data)) {
119         WLOGFE("write key event failed");
120         return;
121     }
122 
123     sptr<IRemoteObject> remote = Remote();
124     if (remote == nullptr) {
125         WLOGFE("remote is null");
126         return;
127     }
128 
129     if (remote->SendRequest(TRANS_ID_ON_POINTER_EVENT, data, replay, option) != ERR_NONE) {
130         WLOGFE("send request failed");
131     }
132     WLOGI("end");
133 }
134 } // namespace Rosen
135 } // namespace OHOS