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 #ifdef SUPPORT_GRAPHICS
17 #include "window_manager_service_handler_proxy.h"
18
19 #include "ability_manager_errors.h"
20 #include "hilog_wrapper.h"
21 #include "parcel.h"
22
23 namespace OHOS {
24 namespace AAFwk {
WindowManagerServiceHandlerProxy(const sptr<IRemoteObject> & impl)25 WindowManagerServiceHandlerProxy::WindowManagerServiceHandlerProxy(const sptr<IRemoteObject> &impl)
26 : IRemoteProxy<IWindowManagerServiceHandler>(impl) {}
27
NotifyWindowTransition(sptr<AbilityTransitionInfo> fromInfo,sptr<AbilityTransitionInfo> toInfo)28 void WindowManagerServiceHandlerProxy::NotifyWindowTransition(sptr<AbilityTransitionInfo> fromInfo,
29 sptr<AbilityTransitionInfo> toInfo)
30 {
31 HILOG_DEBUG("%{public}s is called.", __func__);
32 MessageParcel data;
33 if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
34 HILOG_ERROR("Write interface token failed.");
35 return;
36 }
37 if (!data.WriteParcelable(fromInfo.GetRefPtr())) {
38 HILOG_ERROR("Write fromInfo failed.");
39 return;
40 }
41 if (!data.WriteParcelable(toInfo.GetRefPtr())) {
42 HILOG_ERROR("Write toInfo failed.");
43 return;
44 }
45 MessageParcel reply;
46 MessageOption option(MessageOption::TF_ASYNC);
47 int error = Remote()->SendRequest(WMSCmd::ON_NOTIFY_WINDOW_TRANSITION, data, reply, option);
48 if (error != ERR_OK) {
49 HILOG_ERROR("SendRequest fail, error: %{public}d", error);
50 }
51 }
52
GetFocusWindow(sptr<IRemoteObject> & abilityToken)53 int32_t WindowManagerServiceHandlerProxy::GetFocusWindow(sptr<IRemoteObject>& abilityToken)
54 {
55 HILOG_DEBUG("%{public}s is called.", __func__);
56 MessageParcel data;
57 if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
58 HILOG_ERROR("Write interface token failed.");
59 return ERR_AAFWK_PARCEL_FAIL;
60 }
61
62 MessageParcel reply;
63 MessageOption option;
64 int error = Remote()->SendRequest(WMSCmd::ON_GET_FOCUS_ABILITY, data, reply, option);
65 if (error != ERR_OK) {
66 HILOG_ERROR("SendRequest fail, error: %{public}d", error);
67 return ERR_AAFWK_PARCEL_FAIL;
68 }
69 auto ret = reply.ReadInt32();
70 if (ret == 0 && reply.ReadBool()) {
71 abilityToken = reply.ReadObject<IRemoteObject>();
72 }
73 return ret;
74 }
75
StartingWindow(sptr<AbilityTransitionInfo> info,std::shared_ptr<Media::PixelMap> pixelMap,uint32_t bgColor)76 void WindowManagerServiceHandlerProxy::StartingWindow(sptr<AbilityTransitionInfo> info,
77 std::shared_ptr<Media::PixelMap> pixelMap, uint32_t bgColor)
78 {
79 HILOG_DEBUG("%{public}s is called.", __func__);
80 MessageParcel data;
81 if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
82 HILOG_ERROR("Write interface token failed.");
83 return;
84 }
85 if (!data.WriteParcelable(info.GetRefPtr())) {
86 HILOG_ERROR("Write info failed.");
87 return;
88 }
89 if (!data.WriteParcelable(pixelMap.get())) {
90 HILOG_ERROR("Write pixelMap failed.");
91 return;
92 }
93 if (!data.WriteUint32(bgColor)) {
94 HILOG_ERROR("Write bgColor failed.");
95 return;
96 }
97 MessageParcel reply;
98 MessageOption option(MessageOption::TF_ASYNC);
99 int error = Remote()->SendRequest(WMSCmd::ON_COLD_STARTING_WINDOW, data, reply, option);
100 if (error != ERR_OK) {
101 HILOG_ERROR("SendRequest fail, error: %{public}d", error);
102 }
103 }
104
StartingWindow(sptr<AbilityTransitionInfo> info,std::shared_ptr<Media::PixelMap> pixelMap)105 void WindowManagerServiceHandlerProxy::StartingWindow(sptr<AbilityTransitionInfo> info,
106 std::shared_ptr<Media::PixelMap> pixelMap)
107 {
108 HILOG_DEBUG("%{public}s is called.", __func__);
109 MessageParcel data;
110 if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
111 HILOG_ERROR("Write interface token failed.");
112 return;
113 }
114 if (!data.WriteParcelable(info.GetRefPtr())) {
115 HILOG_ERROR("Write info failed.");
116 return;
117 }
118 if (!data.WriteParcelable(pixelMap.get())) {
119 HILOG_ERROR("Write pixelMap failed.");
120 return;
121 }
122 MessageParcel reply;
123 MessageOption option(MessageOption::TF_ASYNC);
124 int error = Remote()->SendRequest(WMSCmd::ON_HOT_STARTING_WINDOW, data, reply, option);
125 if (error != ERR_OK) {
126 HILOG_ERROR("SendRequest fail, error: %{public}d", error);
127 }
128 }
129
CancelStartingWindow(sptr<IRemoteObject> abilityToken)130 void WindowManagerServiceHandlerProxy::CancelStartingWindow(sptr<IRemoteObject> abilityToken)
131 {
132 HILOG_DEBUG("%{public}s is called.", __func__);
133 MessageParcel data;
134 if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
135 HILOG_ERROR("Write interface token failed.");
136 return;
137 }
138 if (!abilityToken) {
139 if (!data.WriteBool(false)) {
140 HILOG_ERROR("Write false failed.");
141 return;
142 }
143 } else {
144 if (!data.WriteBool(true)) {
145 HILOG_ERROR("Write true failed.");
146 return;
147 }
148 if (!data.WriteObject(abilityToken)) {
149 HILOG_ERROR("Write abilityToken failed.");
150 return;
151 }
152 }
153 MessageParcel reply;
154 MessageOption option(MessageOption::TF_ASYNC);
155 int error = Remote()->SendRequest(WMSCmd::ON_CANCEL_STARTING_WINDOW, data, reply, option);
156 if (error != ERR_OK) {
157 HILOG_ERROR("SendRequest fail, error: %{public}d", error);
158 }
159 }
160 } // namespace AAFwk
161 } // namespace OHOS
162 #endif
163