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 if (Remote()->SendRequest(TRANS_ID_ON_WINDOW_READY, data, replay, option) != ERR_NONE) {
44 WLOGFE("send request failed");
45 }
46 WLOGFI("end");
47 }
48
OnBackPress()49 void WindowExtensionClientProxy::OnBackPress()
50 {
51 MessageParcel data;
52 MessageParcel replay;
53 MessageOption option(MessageOption::TF_SYNC);
54 WLOGFI("call");
55 if (!data.WriteInterfaceToken(GetDescriptor())) {
56 WLOGFE("write token failed");
57 return;
58 }
59 if (Remote()->SendRequest(TRANS_ID_ON_BACK_PRESS, data, replay, option) != ERR_NONE) {
60 WLOGFE("send request failed");
61 }
62 WLOGFI("end");
63 }
64
OnKeyEvent(const std::shared_ptr<MMI::KeyEvent> & keyEvent)65 void WindowExtensionClientProxy::OnKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
66 {
67 MessageParcel data;
68 MessageParcel replay;
69 MessageOption option(MessageOption::TF_SYNC);
70
71 if (!data.WriteInterfaceToken(GetDescriptor())) {
72 WLOGFE("write token failed");
73 return;
74 }
75
76 if (!keyEvent->WriteToParcel(data)) {
77 WLOGFE("write key event failed");
78 return;
79 }
80 if (Remote()->SendRequest(TRANS_ID_ON_KEY_EVENT, data, replay, option) != ERR_NONE) {
81 WLOGFE("send request failed");
82 }
83 WLOGFI("end");
84 }
85
OnPointerEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)86 void WindowExtensionClientProxy::OnPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
87 {
88 MessageParcel data;
89 MessageParcel replay;
90 MessageOption option(MessageOption::TF_SYNC);
91
92 if (!data.WriteInterfaceToken(GetDescriptor())) {
93 WLOGFE("write token failed");
94 return;
95 }
96
97 if (!pointerEvent->WriteToParcel(data)) {
98 WLOGFE("write key event failed");
99 return;
100 }
101 if (Remote()->SendRequest(TRANS_ID_ON_POINTER_EVENT, data, replay, option) != ERR_NONE) {
102 WLOGFE("send request failed");
103 }
104 WLOGFI("end");
105 }
106 } // namespace Rosen
107 } // namespace OHOS