• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "command/rs_node_showing_command.h"
17 
18 #include "pipeline/rs_render_node.h"
19 #include "platform/common/rs_log.h"
20 #include "transaction/rs_marshalling_helper.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 RSNodeGetShowingPropertyAndCancelAnimation::Registrar RSNodeGetShowingPropertyAndCancelAnimation::instance_;
25 RSNodeGetShowingPropertiesAndCancelAnimation::Registrar RSNodeGetShowingPropertiesAndCancelAnimation::instance_;
26 
Marshalling(Parcel & parcel) const27 bool RSNodeGetShowingPropertyAndCancelAnimation::Marshalling(Parcel& parcel) const
28 {
29     return RSMarshallingHelper::Marshalling(parcel, commandType) &&
30            RSMarshallingHelper::Marshalling(parcel, commandSubType) &&
31            RSMarshallingHelper::Marshalling(parcel, targetId_) &&
32            RSMarshallingHelper::Marshalling(parcel, timeoutNS_) &&
33            RSMarshallingHelper::Marshalling(parcel, isTimeout_) &&
34            RSMarshallingHelper::Marshalling(parcel, success_) &&
35            (property_ == nullptr || RSRenderPropertyBase::Marshalling(parcel, property_));
36 }
37 
Unmarshalling(Parcel & parcel)38 RSCommand* RSNodeGetShowingPropertyAndCancelAnimation::Unmarshalling(Parcel& parcel)
39 {
40     NodeId targetId;
41     std::shared_ptr<RSRenderPropertyBase> property;
42     uint64_t timeoutNS;
43     if (!(RSMarshallingHelper::Unmarshalling(parcel, targetId) &&
44             RSMarshallingHelper::Unmarshalling(parcel, timeoutNS))) {
45         return nullptr;
46     }
47     auto command = new RSNodeGetShowingPropertyAndCancelAnimation(targetId, property, timeoutNS);
48     if (!command->ReadFromParcel(parcel)) {
49         delete command;
50         return nullptr;
51     }
52     return command;
53 }
54 
CheckHeader(Parcel & parcel) const55 bool RSNodeGetShowingPropertyAndCancelAnimation::CheckHeader(Parcel& parcel) const
56 {
57     uint16_t type;
58     uint16_t subType;
59     uint64_t timeoutNS;
60     NodeId targetId;
61     return RSMarshallingHelper::Unmarshalling(parcel, type) && type == commandType &&
62            RSMarshallingHelper::Unmarshalling(parcel, subType) && subType == commandSubType &&
63            RSMarshallingHelper::Unmarshalling(parcel, targetId) && targetId == targetId_ &&
64            RSMarshallingHelper::Unmarshalling(parcel, timeoutNS) && timeoutNS == timeoutNS_;
65 }
66 
ReadFromParcel(Parcel & parcel)67 bool RSNodeGetShowingPropertyAndCancelAnimation::ReadFromParcel(Parcel& parcel)
68 {
69     return RSMarshallingHelper::Unmarshalling(parcel, isTimeout_) &&
70            RSMarshallingHelper::Unmarshalling(parcel, success_) &&
71            RSRenderPropertyBase::Unmarshalling(parcel, property_);
72 }
73 
Process(RSContext & context)74 void RSNodeGetShowingPropertyAndCancelAnimation::Process(RSContext& context)
75 {
76     isTimeout_ = false;
77     auto& nodeMap = context.GetNodeMap();
78     auto node = nodeMap.GetRenderNode<RSRenderNode>(targetId_);
79     if (!node || !property_) {
80         success_ = false;
81         ROSEN_LOGE("RSNodeGetShowingPropertyAndCancelAnimation::Process, "
82             "node [%{public}" PRIu64 "] or property is null!", targetId_);
83         return;
84     }
85     auto modifier = node->GetModifier(property_->GetId());
86     if (!modifier) {
87         success_ = false;
88         ROSEN_LOGE("RSNodeGetShowingPropertyAndCancelAnimation::Process, modifier is null!");
89         return;
90     }
91     property_ = modifier->GetProperty();
92     success_ = (property_ != nullptr);
93     if (success_) {
94         auto& animationManager = node->GetAnimationManager();
95         animationManager.CancelAnimationByPropertyId(property_->GetId());
96     }
97 }
98 
IsCallingPidValid(pid_t callingPid,const RSRenderNodeMap & nodeMap) const99 bool RSNodeGetShowingPropertyAndCancelAnimation::IsCallingPidValid(pid_t callingPid,
100     const RSRenderNodeMap& nodeMap) const
101 {
102     if (ExtractPid(targetId_) != callingPid && !nodeMap.IsUIExtensionSurfaceNode(targetId_)) {
103         ROSEN_LOGE("RSNodeGetShowingPropertyAndCancelAnimation::IsCallingPidValid, "
104                 "callingPid [%{public}d] no permission "
105                 "EXECUTE_SYNCHRONOUS_TASK on node [%{public}" PRIu64 "] ",
106                 static_cast<int>(callingPid), targetId_);
107         return false;
108     }
109     return true;
110 }
111 
Marshalling(Parcel & parcel) const112 bool RSNodeGetShowingPropertiesAndCancelAnimation::Marshalling(Parcel& parcel) const
113 {
114     bool result = RSMarshallingHelper::Marshalling(parcel, commandType) &&
115            RSMarshallingHelper::Marshalling(parcel, commandSubType) &&
116            RSMarshallingHelper::Marshalling(parcel, timeoutNS_) &&
117            RSMarshallingHelper::Marshalling(parcel, success_) &&
118            RSMarshallingHelper::Marshalling(parcel, propertiesMap_);
119     return result;
120 }
121 
122 // construct cancelAnimation & SetProperties
Unmarshalling(Parcel & parcel)123 RSCommand* RSNodeGetShowingPropertiesAndCancelAnimation::Unmarshalling(Parcel& parcel)
124 {
125     uint64_t timeoutNS;
126     if (!RSMarshallingHelper::Unmarshalling(parcel, timeoutNS)) {
127         return nullptr;
128     }
129     auto command = new RSNodeGetShowingPropertiesAndCancelAnimation(timeoutNS);
130     if (!command->ReadFromParcel(parcel)) {
131         delete command;
132         return nullptr;
133     }
134     return command;
135 }
136 
CheckHeader(Parcel & parcel) const137 bool RSNodeGetShowingPropertiesAndCancelAnimation::CheckHeader(Parcel& parcel) const
138 {
139     uint16_t type;
140     uint16_t subType;
141     uint64_t timeoutNS;
142 
143     return RSMarshallingHelper::Unmarshalling(parcel, type) && type == commandType &&
144            RSMarshallingHelper::Unmarshalling(parcel, subType) && subType == commandSubType &&
145            RSMarshallingHelper::Unmarshalling(parcel, timeoutNS) && timeoutNS == timeoutNS_;
146 }
147 
ReadFromParcel(Parcel & parcel)148 bool RSNodeGetShowingPropertiesAndCancelAnimation::ReadFromParcel(Parcel& parcel)
149 {
150     if (!RSMarshallingHelper::Unmarshalling(parcel, success_)) {
151         return false;
152     }
153     if (!RSMarshallingHelper::Unmarshalling(parcel, propertiesMap_)) {
154         return false;
155     }
156     return true;
157 }
158 
Process(RSContext & context)159 void RSNodeGetShowingPropertiesAndCancelAnimation::Process(RSContext& context)
160 {
161     success_ = true;
162     auto& nodeMap = context.GetNodeMap();
163     for (auto& [key, value] : propertiesMap_) {
164         // value should already initialized as nullptr
165         auto& [nodeId, propertyId] = key;
166         auto& [property, animations] = value;
167         auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
168         if (!node) {
169             ROSEN_LOGE("RSNodeGetShowingPropertiesAndCancelAnimation::Process, "
170                 "node [%{public}" PRIu64 "] is null!", nodeId);
171             continue;
172         }
173         auto modifier = node->GetModifier(propertyId);
174         if (modifier) {
175             property = modifier->GetProperty();
176         }
177         node->GetAnimationManager().AttemptCancelAnimationByAnimationId(animations);
178     }
179 }
180 
IsCallingPidValid(pid_t callingPid,const RSRenderNodeMap & nodeMap) const181 bool RSNodeGetShowingPropertiesAndCancelAnimation::IsCallingPidValid(pid_t callingPid,
182     const RSRenderNodeMap& nodeMap) const
183 {
184     for (auto& [key, _] : propertiesMap_) {
185         auto& nodeId = key.first;
186         if (ExtractPid(nodeId) != callingPid && !nodeMap.IsUIExtensionSurfaceNode(nodeId)) {
187             ROSEN_LOGE("RSNodeGetShowingPropertiesAndCancelAnimation::IsCallingPidValid, "
188                 "callingPid [%{public}d] no permission "
189                 "EXECUTE_SYNCHRONOUS_TASK on node [%{public}" PRIu64 "] ",
190                 static_cast<int>(callingPid), nodeId);
191             return false;
192         }
193     }
194     return true;
195 }
196 
Marshalling(Parcel & parcel) const197 bool RSNodeGetAnimationsValueFraction::Marshalling(Parcel& parcel) const
198 {
199     bool result = RSMarshallingHelper::Marshalling(parcel, commandType) &&
200            RSMarshallingHelper::Marshalling(parcel, commandSubType) &&
201            RSMarshallingHelper::Marshalling(parcel, timeoutNS_) &&
202            RSMarshallingHelper::Marshalling(parcel, success_) &&
203            RSMarshallingHelper::Marshalling(parcel, nodeId_) &&
204            RSMarshallingHelper::Marshalling(parcel, animationId_);
205     return result;
206 }
207 
Unmarshalling(Parcel & parcel)208 RSCommand* RSNodeGetAnimationsValueFraction::Unmarshalling(Parcel& parcel)
209 {
210     uint64_t timeoutNS;
211     if (!RSMarshallingHelper::Unmarshalling(parcel, timeoutNS)) {
212         return nullptr;
213     }
214     auto command = new RSNodeGetAnimationsValueFraction(timeoutNS);
215     if (!command->ReadFromParcel(parcel)) {
216         delete command;
217         return nullptr;
218     }
219     return command;
220 }
221 
CheckHeader(Parcel & parcel) const222 bool RSNodeGetAnimationsValueFraction::CheckHeader(Parcel& parcel) const
223 {
224     uint16_t type;
225     uint16_t subType;
226     uint64_t timeoutNS;
227     return RSMarshallingHelper::Unmarshalling(parcel, type) && type == commandType &&
228            RSMarshallingHelper::Unmarshalling(parcel, subType) && subType == commandSubType &&
229            RSMarshallingHelper::Unmarshalling(parcel, timeoutNS) && timeoutNS == timeoutNS_;
230 }
231 
ReadFromParcel(Parcel & parcel)232 bool RSNodeGetAnimationsValueFraction::ReadFromParcel(Parcel& parcel)
233 {
234     if (!RSMarshallingHelper::Unmarshalling(parcel, success_)) {
235         return false;
236     }
237     if (!RSMarshallingHelper::Unmarshalling(parcel, nodeId_)) {
238         return false;
239     }
240     if (!RSMarshallingHelper::Unmarshalling(parcel, animationId_)) {
241         return false;
242     }
243     return true;
244 }
245 
Process(RSContext & context)246 void RSNodeGetAnimationsValueFraction::Process(RSContext& context)
247 {
248     auto& nodeMap = context.GetNodeMap();
249     auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId_);
250     if (node == nullptr) {
251         ROSEN_LOGE("RSNodeGetAnimationsValueFraction::Process, node is null!");
252         return;
253     }
254     auto animation = node->GetAnimationManager().GetAnimation(animationId_);
255     if (animation == nullptr) {
256         ROSEN_LOGE("RSNodeGetAnimationsValueFraction::Process, animation is null!");
257         return;
258     }
259     success_ = true;
260     fraction_ = animation->GetValueFraction();
261 }
262 
IsCallingPidValid(pid_t callingPid,const RSRenderNodeMap & nodeMap) const263 bool RSNodeGetAnimationsValueFraction::IsCallingPidValid(pid_t callingPid,
264     const RSRenderNodeMap& nodeMap) const
265 {
266     if (ExtractPid(nodeId_) != callingPid && !nodeMap.IsUIExtensionSurfaceNode(nodeId_)) {
267         ROSEN_LOGE("RSNodeGetAnimationsValueFraction::IsCallingPidValid, "
268                 "callingPid [%{public}d] no permission "
269                 "EXECUTE_SYNCHRONOUS_TASK on node [%{public}" PRIu64 "] ",
270                 static_cast<int>(callingPid), nodeId_);
271         return false;
272     }
273     return true;
274 }
275 } // namespace Rosen
276 } // namespace OHOS
277