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_proxy.h"
17
18 #include <ipc_types.h>
19 #include <message_option.h>
20
21 #include "window_manager_hilog.h"
22
23 namespace OHOS {
24 namespace Rosen {
25 namespace {
26 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionProxy"};
27 }
28
SetBounds(const Rect & rect)29 void WindowExtensionProxy::SetBounds(const Rect& rect)
30 {
31 MessageParcel data;
32 MessageParcel reply;
33 MessageOption option;
34
35 if (!data.WriteInterfaceToken(GetDescriptor())) {
36 WLOGFE("write interface token failed");
37 return;
38 }
39 if (!(data.WriteInt32(rect.posX_) && data.WriteInt32(rect.posY_) &&
40 data.WriteInt32(rect.width_) && data.WriteInt32(rect.height_))) {
41 WLOGFE("write rect failed");
42 return;
43 }
44
45 sptr<IRemoteObject> remote = Remote();
46 if (remote == nullptr) {
47 WLOGFE("remote is null");
48 return;
49 }
50
51 if (remote->SendRequest(TRANS_ID_SETBOUNDS, data, reply, option) != ERR_NONE) {
52 WLOGFE("send request failed");
53 return;
54 }
55 }
56
Hide()57 void WindowExtensionProxy::Hide()
58 {
59 MessageParcel data;
60 MessageParcel reply;
61 MessageOption option;
62 if (!data.WriteInterfaceToken(GetDescriptor())) {
63 WLOGFE("write interface 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_HIDE_WINDOW, data, reply, option) != ERR_NONE) {
74 WLOGFE("send request failed");
75 }
76 }
77
Show()78 void WindowExtensionProxy::Show()
79 {
80 MessageParcel data;
81 MessageParcel reply;
82 MessageOption option;
83 if (!data.WriteInterfaceToken(GetDescriptor())) {
84 WLOGFE("write interface token failed");
85 return;
86 }
87
88 sptr<IRemoteObject> remote = Remote();
89 if (remote == nullptr) {
90 WLOGFE("remote is null");
91 return;
92 }
93
94 if (remote->SendRequest(TRANS_ID_SHOW_WINDOW, data, reply, option) != ERR_NONE) {
95 WLOGFE("send request failed");
96 }
97 }
98
GetExtensionWindow(sptr<IWindowExtensionClient> & token)99 void WindowExtensionProxy::GetExtensionWindow(sptr<IWindowExtensionClient>& token)
100 {
101 MessageParcel data;
102 MessageParcel replay;
103 MessageOption option;
104 if (!data.WriteInterfaceToken(GetDescriptor())) {
105 WLOGFE("write interface token failed");
106 return;
107 }
108 if (!data.WriteRemoteObject(token->AsObject())) {
109 WLOGFE("write object failed");
110 return;
111 }
112
113 sptr<IRemoteObject> remote = Remote();
114 if (remote == nullptr) {
115 WLOGFE("remote is null");
116 return;
117 }
118
119 if (remote->SendRequest(TRANS_ID_CONNECT_TO_EXTENSION, data, replay, option) != ERR_NONE) {
120 WLOGFE("send request failed");
121 }
122 }
123
RequestFocus()124 void WindowExtensionProxy::RequestFocus()
125 {
126 WLOGI("called.");
127 }
128 } // namespace Rosen
129 } // namespace OHOS