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_stub.h"
18
19 #include "ability_manager_errors.h"
20 #include "hilog_wrapper.h"
21
22 namespace OHOS {
23 namespace AAFwk {
WindowManagerServiceHandlerStub()24 WindowManagerServiceHandlerStub::WindowManagerServiceHandlerStub()
25 {
26 Init();
27 }
28
~WindowManagerServiceHandlerStub()29 WindowManagerServiceHandlerStub::~WindowManagerServiceHandlerStub()
30 {
31 requestFuncMap_.clear();
32 }
33
Init()34 void WindowManagerServiceHandlerStub::Init()
35 {
36 requestFuncMap_[ON_NOTIFY_WINDOW_TRANSITION] = &WindowManagerServiceHandlerStub::NotifyWindowTransitionInner;
37 requestFuncMap_[ON_GET_FOCUS_ABILITY] = &WindowManagerServiceHandlerStub::GetFocusWindowInner;
38 requestFuncMap_[ON_COLD_STARTING_WINDOW] = &WindowManagerServiceHandlerStub::StartingWindowCold;
39 requestFuncMap_[ON_HOT_STARTING_WINDOW] = &WindowManagerServiceHandlerStub::StartingWindowHot;
40 requestFuncMap_[ON_CANCEL_STARTING_WINDOW] = &WindowManagerServiceHandlerStub::CancelStartingWindowInner;
41 }
42
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)43 int WindowManagerServiceHandlerStub::OnRemoteRequest(
44 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
45 {
46 if (data.ReadInterfaceToken() != IWindowManagerServiceHandler::GetDescriptor()) {
47 HILOG_ERROR("InterfaceToken not equal IWindowManagerServiceHandler's descriptor.");
48 return ERR_AAFWK_PARCEL_FAIL;
49 }
50
51 auto itFunc = requestFuncMap_.find(code);
52 if (itFunc != requestFuncMap_.end()) {
53 auto requestFunc = itFunc->second;
54 if (requestFunc != nullptr) {
55 return (this->*requestFunc)(data, reply);
56 }
57 }
58 HILOG_WARN("default case, need check.");
59 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
60 }
61
NotifyWindowTransitionInner(MessageParcel & data,MessageParcel & reply)62 int WindowManagerServiceHandlerStub::NotifyWindowTransitionInner(MessageParcel &data, MessageParcel &reply)
63 {
64 HILOG_DEBUG("%{public}s is called.", __func__);
65 sptr<AbilityTransitionInfo> fromInfo(data.ReadParcelable<AbilityTransitionInfo>());
66 if (!fromInfo) {
67 HILOG_ERROR("To read fromInfo failed.");
68 return ERR_AAFWK_PARCEL_FAIL;
69 }
70 sptr<AbilityTransitionInfo> toInfo(data.ReadParcelable<AbilityTransitionInfo>());
71 if (!toInfo) {
72 HILOG_ERROR("To read toInfo failed.");
73 return ERR_AAFWK_PARCEL_FAIL;
74 }
75 NotifyWindowTransition(fromInfo, toInfo);
76 return ERR_OK;
77 }
78
GetFocusWindowInner(MessageParcel & data,MessageParcel & reply)79 int WindowManagerServiceHandlerStub::GetFocusWindowInner(MessageParcel &data, MessageParcel &reply)
80 {
81 HILOG_DEBUG("%{public}s is called.", __func__);
82 sptr<IRemoteObject> abilityToken = nullptr;
83 int32_t ret = GetFocusWindow(abilityToken);
84 if (!reply.WriteInt32(ret)) {
85 HILOG_ERROR("To write result failed.");
86 return ERR_AAFWK_PARCEL_FAIL;
87 }
88 if (abilityToken) {
89 if (!reply.WriteBool(true)) {
90 HILOG_ERROR("To write true failed.");
91 return ERR_AAFWK_PARCEL_FAIL;
92 }
93 if (!reply.WriteObject(abilityToken)) {
94 HILOG_ERROR("To write abilityToken failed.");
95 return ERR_AAFWK_PARCEL_FAIL;
96 }
97 } else {
98 if (!reply.WriteBool(false)) {
99 HILOG_ERROR("To write false failed.");
100 return ERR_AAFWK_PARCEL_FAIL;
101 }
102 }
103 return ERR_OK;
104 }
105
StartingWindowCold(MessageParcel & data,MessageParcel & reply)106 int WindowManagerServiceHandlerStub::StartingWindowCold(MessageParcel &data, MessageParcel &reply)
107 {
108 HILOG_DEBUG("%{public}s is called.", __func__);
109 sptr<AbilityTransitionInfo> info(data.ReadParcelable<AbilityTransitionInfo>());
110 if (!info) {
111 HILOG_ERROR("To read info failed.");
112 return ERR_AAFWK_PARCEL_FAIL;
113 }
114 std::shared_ptr<Media::PixelMap> pixelMap
115 = std::shared_ptr<Media::PixelMap>(data.ReadParcelable<Media::PixelMap>());
116 if (pixelMap == nullptr) {
117 HILOG_ERROR("To read pixelMap failed.");
118 return ERR_AAFWK_PARCEL_FAIL;
119 }
120 auto bgColor = data.ReadUint32();
121 StartingWindow(info, pixelMap, bgColor);
122 return ERR_OK;
123 }
124
StartingWindowHot(MessageParcel & data,MessageParcel & reply)125 int WindowManagerServiceHandlerStub::StartingWindowHot(MessageParcel &data, MessageParcel &reply)
126 {
127 HILOG_DEBUG("%{public}s is called.", __func__);
128 sptr<AbilityTransitionInfo> info(data.ReadParcelable<AbilityTransitionInfo>());
129 if (!info) {
130 HILOG_ERROR("To read info failed.");
131 return ERR_AAFWK_PARCEL_FAIL;
132 }
133 std::shared_ptr<Media::PixelMap> pixelMap
134 = std::shared_ptr<Media::PixelMap>(data.ReadParcelable<Media::PixelMap>());
135 if (pixelMap == nullptr) {
136 HILOG_ERROR("To read pixelMap failed.");
137 return ERR_AAFWK_PARCEL_FAIL;
138 }
139 StartingWindow(info, pixelMap);
140 return ERR_OK;
141 }
142
CancelStartingWindowInner(MessageParcel & data,MessageParcel & reply)143 int WindowManagerServiceHandlerStub::CancelStartingWindowInner(MessageParcel &data, MessageParcel &reply)
144 {
145 HILOG_DEBUG("%{public}s is called.", __func__);
146 sptr<IRemoteObject> abilityToken = nullptr;
147 if (data.ReadBool()) {
148 HILOG_DEBUG("abilityToken is valid.");
149 abilityToken = data.ReadObject<IRemoteObject>();
150 }
151 CancelStartingWindow(abilityToken);
152 return ERR_OK;
153 }
154 } // namespace AAFwk
155 } // namespace OHOS
156 #endif
157