• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     requestFuncMap_[ON_NOTIFY_ANIMATION_ABILITY_DIED] =
42         &WindowManagerServiceHandlerStub::NotifyAnimationAbilityDiedInner;
43     requestFuncMap_[ON_MOVE_MISSINONS_TO_FOREGROUND] = &WindowManagerServiceHandlerStub::MoveMissionsToForegroundInner;
44     requestFuncMap_[ON_MOVE_MISSIONS_TO_BACKGROUND] = &WindowManagerServiceHandlerStub::MoveMissionsToBackgroundInner;
45 }
46 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)47 int WindowManagerServiceHandlerStub::OnRemoteRequest(
48     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
49 {
50     if (data.ReadInterfaceToken() != IWindowManagerServiceHandler::GetDescriptor()) {
51         HILOG_ERROR("InterfaceToken not equal IWindowManagerServiceHandler's descriptor.");
52         return ERR_AAFWK_PARCEL_FAIL;
53     }
54 
55     auto itFunc = requestFuncMap_.find(code);
56     if (itFunc != requestFuncMap_.end()) {
57         auto requestFunc = itFunc->second;
58         if (requestFunc != nullptr) {
59             return (this->*requestFunc)(data, reply);
60         }
61     }
62     HILOG_WARN("default case, need check.");
63     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
64 }
65 
NotifyWindowTransitionInner(MessageParcel & data,MessageParcel & reply)66 int WindowManagerServiceHandlerStub::NotifyWindowTransitionInner(MessageParcel &data, MessageParcel &reply)
67 {
68     HILOG_DEBUG("%{public}s is called.", __func__);
69     sptr<AbilityTransitionInfo> fromInfo(data.ReadParcelable<AbilityTransitionInfo>());
70     if (!fromInfo) {
71         HILOG_ERROR("To read fromInfo failed.");
72         return ERR_AAFWK_PARCEL_FAIL;
73     }
74     sptr<AbilityTransitionInfo> toInfo(data.ReadParcelable<AbilityTransitionInfo>());
75     if (!toInfo) {
76         HILOG_ERROR("To read toInfo failed.");
77         return ERR_AAFWK_PARCEL_FAIL;
78     }
79     bool animaEnabled = data.ReadBool();
80     NotifyWindowTransition(fromInfo, toInfo, animaEnabled);
81     reply.WriteBool(animaEnabled);
82     return ERR_OK;
83 }
84 
GetFocusWindowInner(MessageParcel & data,MessageParcel & reply)85 int WindowManagerServiceHandlerStub::GetFocusWindowInner(MessageParcel &data, MessageParcel &reply)
86 {
87     HILOG_DEBUG("%{public}s is called.", __func__);
88     sptr<IRemoteObject> abilityToken = nullptr;
89     int32_t ret = GetFocusWindow(abilityToken);
90     if (!reply.WriteInt32(ret)) {
91         HILOG_ERROR("To write result failed.");
92         return ERR_AAFWK_PARCEL_FAIL;
93     }
94     if (abilityToken) {
95         if (!reply.WriteBool(true)) {
96             HILOG_ERROR("To write true failed.");
97             return ERR_AAFWK_PARCEL_FAIL;
98         }
99         if (!reply.WriteObject(abilityToken)) {
100             HILOG_ERROR("To write abilityToken failed.");
101             return ERR_AAFWK_PARCEL_FAIL;
102         }
103     } else {
104         if (!reply.WriteBool(false)) {
105             HILOG_ERROR("To write false failed.");
106             return ERR_AAFWK_PARCEL_FAIL;
107         }
108     }
109     return ERR_OK;
110 }
111 
StartingWindowCold(MessageParcel & data,MessageParcel & reply)112 int WindowManagerServiceHandlerStub::StartingWindowCold(MessageParcel &data, MessageParcel &reply)
113 {
114     HILOG_DEBUG("%{public}s is called.", __func__);
115     sptr<AbilityTransitionInfo> info(data.ReadParcelable<AbilityTransitionInfo>());
116     if (!info) {
117         HILOG_ERROR("To read info failed.");
118         return ERR_AAFWK_PARCEL_FAIL;
119     }
120     std::shared_ptr<Media::PixelMap> pixelMap
121         = std::shared_ptr<Media::PixelMap>(data.ReadParcelable<Media::PixelMap>());
122     if (pixelMap == nullptr) {
123         HILOG_ERROR("To read pixelMap failed.");
124         return ERR_AAFWK_PARCEL_FAIL;
125     }
126     auto bgColor = data.ReadUint32();
127     StartingWindow(info, pixelMap, bgColor);
128     return ERR_OK;
129 }
130 
StartingWindowHot(MessageParcel & data,MessageParcel & reply)131 int WindowManagerServiceHandlerStub::StartingWindowHot(MessageParcel &data, MessageParcel &reply)
132 {
133     HILOG_DEBUG("%{public}s is called.", __func__);
134     sptr<AbilityTransitionInfo> info(data.ReadParcelable<AbilityTransitionInfo>());
135     if (!info) {
136         HILOG_ERROR("To read info failed.");
137         return ERR_AAFWK_PARCEL_FAIL;
138     }
139     std::shared_ptr<Media::PixelMap> pixelMap
140         = std::shared_ptr<Media::PixelMap>(data.ReadParcelable<Media::PixelMap>());
141     if (pixelMap == nullptr) {
142         HILOG_ERROR("To read pixelMap failed.");
143         return ERR_AAFWK_PARCEL_FAIL;
144     }
145     StartingWindow(info, pixelMap);
146     return ERR_OK;
147 }
148 
CancelStartingWindowInner(MessageParcel & data,MessageParcel & reply)149 int WindowManagerServiceHandlerStub::CancelStartingWindowInner(MessageParcel &data, MessageParcel &reply)
150 {
151     HILOG_DEBUG("%{public}s is called.", __func__);
152     sptr<IRemoteObject> abilityToken = nullptr;
153     if (data.ReadBool()) {
154         HILOG_DEBUG("abilityToken is valid.");
155         abilityToken = data.ReadObject<IRemoteObject>();
156     }
157     CancelStartingWindow(abilityToken);
158     return ERR_OK;
159 }
160 
NotifyAnimationAbilityDiedInner(MessageParcel & data,MessageParcel & reply)161 int WindowManagerServiceHandlerStub::NotifyAnimationAbilityDiedInner(MessageParcel &data, MessageParcel &reply)
162 {
163     HILOG_DEBUG("%{public}s is called.", __func__);
164     sptr<AbilityTransitionInfo> info(data.ReadParcelable<AbilityTransitionInfo>());
165     if (!info) {
166         HILOG_ERROR("To read info failed.");
167         return ERR_AAFWK_PARCEL_FAIL;
168     }
169     NotifyAnimationAbilityDied(info);
170     return ERR_OK;
171 }
172 
MoveMissionsToForegroundInner(MessageParcel & data,MessageParcel & reply)173 int WindowManagerServiceHandlerStub::MoveMissionsToForegroundInner(MessageParcel &data, MessageParcel &reply)
174 {
175     HILOG_DEBUG("%{public}s is called.", __func__);
176     std::vector<int32_t> missionIds;
177     data.ReadInt32Vector(&missionIds);
178     int32_t topMissionId = data.ReadInt32();
179     auto errCode = MoveMissionsToForeground(missionIds, topMissionId);
180     reply.WriteInt32(errCode);
181     return errCode;
182 }
183 
MoveMissionsToBackgroundInner(MessageParcel & data,MessageParcel & reply)184 int WindowManagerServiceHandlerStub::MoveMissionsToBackgroundInner(MessageParcel &data, MessageParcel &reply)
185 {
186     HILOG_DEBUG("%{public}s is called.", __func__);
187     std::vector<int32_t> missionIds;
188     std::vector<int32_t> result;
189     data.ReadInt32Vector(&missionIds);
190     auto errCode = MoveMissionsToBackground(missionIds, result);
191     reply.WriteInt32Vector(result);
192     return errCode;
193 }
194 
195 }  // namespace AAFwk
196 }  // namespace OHOS
197 #endif
198