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 "session/host/include/session.h"
17
18 #include "ability_info.h"
19 #include "ipc_skeleton.h"
20 #include "key_event.h"
21 #include "pointer_event.h"
22
23 #include "anr_manager.h"
24 #include "foundation/ability/ability_base/interfaces/kits/native/want/include/want.h"
25 #include "interfaces/include/ws_common.h"
26 #include <surface_capture_future.h>
27 #include <transaction/rs_interfaces.h>
28 #include <ui/rs_surface_node.h>
29 #include "util.h"
30 #include <want.h>
31
32 #include "ability_start_setting.h"
33 #include "window_manager_hilog.h"
34 #include "session_helper.h"
35
36 namespace OHOS::Rosen {
37 namespace {
38 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "Session" };
39 std::atomic<int32_t> g_persistentId = INVALID_SESSION_ID;
40 std::set<int32_t> g_persistentIdSet;
41 } // namespace
42
GetPersistentId() const43 int32_t Session::GetPersistentId() const
44 {
45 return persistentId_;
46 }
47
GetParentPersistentId() const48 int32_t Session::GetParentPersistentId() const
49 {
50 if (property_ != nullptr) {
51 return property_->GetParentPersistentId();
52 }
53 return INVALID_SESSION_ID;
54 }
55
SetParentPersistentId(int32_t parentId)56 void Session::SetParentPersistentId(int32_t parentId)
57 {
58 if (property_ == nullptr) {
59 return;
60 }
61 property_->SetParentPersistentId(parentId);
62 }
63
SetWindowSessionProperty(const sptr<WindowSessionProperty> & property)64 void Session::SetWindowSessionProperty(const sptr<WindowSessionProperty>& property)
65 {
66 property_ = property;
67 }
68
GetWindowSessionProperty() const69 sptr<WindowSessionProperty> Session::GetWindowSessionProperty() const
70 {
71 return property_;
72 }
73
GetSurfaceNode() const74 std::shared_ptr<RSSurfaceNode> Session::GetSurfaceNode() const
75 {
76 return surfaceNode_;
77 }
78
GetSnapshot() const79 std::shared_ptr<Media::PixelMap> Session::GetSnapshot() const
80 {
81 return snapshot_;
82 }
83
GetSessionInfo()84 SessionInfo& Session::GetSessionInfo()
85 {
86 return sessionInfo_;
87 }
88
RegisterLifecycleListener(const std::shared_ptr<ILifecycleListener> & listener)89 bool Session::RegisterLifecycleListener(const std::shared_ptr<ILifecycleListener>& listener)
90 {
91 return RegisterListenerLocked(lifecycleListeners_, listener);
92 }
93
UnregisterLifecycleListener(const std::shared_ptr<ILifecycleListener> & listener)94 bool Session::UnregisterLifecycleListener(const std::shared_ptr<ILifecycleListener>& listener)
95 {
96 return UnregisterListenerLocked(lifecycleListeners_, listener);
97 }
98
99 template<typename T>
RegisterListenerLocked(std::vector<std::shared_ptr<T>> & holder,const std::shared_ptr<T> & listener)100 bool Session::RegisterListenerLocked(std::vector<std::shared_ptr<T>>& holder, const std::shared_ptr<T>& listener)
101 {
102 if (listener == nullptr) {
103 WLOGFE("listener is nullptr");
104 return false;
105 }
106 std::lock_guard<std::recursive_mutex> lock(mutex_);
107 if (std::find(holder.begin(), holder.end(), listener) != holder.end()) {
108 WLOGFE("Listener already registered");
109 return false;
110 }
111 holder.emplace_back(listener);
112 return true;
113 }
114
115 template<typename T>
UnregisterListenerLocked(std::vector<std::shared_ptr<T>> & holder,const std::shared_ptr<T> & listener)116 bool Session::UnregisterListenerLocked(std::vector<std::shared_ptr<T>>& holder, const std::shared_ptr<T>& listener)
117 {
118 if (listener == nullptr) {
119 WLOGFE("listener could not be null");
120 return false;
121 }
122 std::lock_guard<std::recursive_mutex> lock(mutex_);
123 holder.erase(std::remove_if(holder.begin(), holder.end(),
124 [listener](std::shared_ptr<T> registeredListener) { return registeredListener == listener; }),
125 holder.end());
126 return true;
127 }
128
NotifyConnect()129 void Session::NotifyConnect()
130 {
131 auto lifecycleListeners = GetListeners<ILifecycleListener>();
132 for (auto& listener : lifecycleListeners) {
133 if (!listener.expired()) {
134 listener.lock()->OnConnect();
135 }
136 }
137 }
138
NotifyForeground()139 void Session::NotifyForeground()
140 {
141 auto lifecycleListeners = GetListeners<ILifecycleListener>();
142 for (auto& listener : lifecycleListeners) {
143 if (!listener.expired()) {
144 listener.lock()->OnForeground();
145 }
146 }
147 }
148
NotifyBackground()149 void Session::NotifyBackground()
150 {
151 auto lifecycleListeners = GetListeners<ILifecycleListener>();
152 for (auto& listener : lifecycleListeners) {
153 if (!listener.expired()) {
154 listener.lock()->OnBackground();
155 }
156 }
157 }
158
NotifyDisconnect()159 void Session::NotifyDisconnect()
160 {
161 auto lifecycleListeners = GetListeners<ILifecycleListener>();
162 for (auto& listener : lifecycleListeners) {
163 if (!listener.expired()) {
164 listener.lock()->OnDisconnect();
165 }
166 }
167 }
168
NotifyExtensionDied()169 void Session::NotifyExtensionDied()
170 {
171 auto lifecycleListeners = GetListeners<ILifecycleListener>();
172 for (auto& listener : lifecycleListeners) {
173 if (!listener.expired()) {
174 listener.lock()->OnExtensionDied();
175 }
176 }
177 }
178
GetAspectRatio() const179 float Session::GetAspectRatio() const
180 {
181 return aspectRatio_;
182 }
183
SetAspectRatio(float ratio)184 WSError Session::SetAspectRatio(float ratio)
185 {
186 aspectRatio_ = ratio;
187 return WSError::WS_OK;
188 }
189
GetSessionState() const190 SessionState Session::GetSessionState() const
191 {
192 return state_;
193 }
194
UpdateSessionState(SessionState state)195 void Session::UpdateSessionState(SessionState state)
196 {
197 state_ = state;
198 NotifySessionStateChange(state);
199 }
200
UpdateSessionFocusable(bool isFocusable)201 void Session::UpdateSessionFocusable(bool isFocusable)
202 {
203 property_->SetFocusable(isFocusable);
204 NotifySessionFocusableChange(isFocusable);
205 }
206
UpdateSessionTouchable(bool touchable)207 void Session::UpdateSessionTouchable(bool touchable)
208 {
209 property_->SetTouchable(touchable);
210 NotifySessionTouchableChange(touchable);
211 }
212
SetFocusable(bool isFocusable)213 WSError Session::SetFocusable(bool isFocusable)
214 {
215 if (!IsSessionValid()) {
216 return WSError::WS_ERROR_INVALID_SESSION;
217 }
218 if (isFocusable == property_->GetFocusable()) {
219 WLOGFD("Session focusable do not change: [%{public}d]", isFocusable);
220 return WSError::WS_DO_NOTHING;
221 }
222 UpdateSessionFocusable(isFocusable);
223 return WSError::WS_OK;
224 }
225
GetFocusable() const226 bool Session::GetFocusable() const
227 {
228 if (property_ != nullptr) {
229 return property_->GetFocusable();
230 }
231 WLOGFD("property is null");
232 return true;
233 }
234
SetNeedNotify(bool needNotify)235 void Session::SetNeedNotify(bool needNotify)
236 {
237 needNotify_ = needNotify;
238 }
239
NeedNotify() const240 bool Session::NeedNotify() const
241 {
242 return needNotify_;
243 }
244
SetTouchable(bool touchable)245 WSError Session::SetTouchable(bool touchable)
246 {
247 if (!IsSessionValid()) {
248 return WSError::WS_ERROR_INVALID_SESSION;
249 }
250 UpdateSessionTouchable(touchable);
251 return WSError::WS_OK;
252 }
253
GetTouchable() const254 bool Session::GetTouchable() const
255 {
256 return property_->GetTouchable();
257 }
258
SetVisible(bool isVisible)259 WSError Session::SetVisible(bool isVisible)
260 {
261 if (!IsSessionValid()) {
262 return WSError::WS_ERROR_INVALID_SESSION;
263 }
264 isVisible_ = isVisible;
265 return WSError::WS_OK;
266 }
267
GetVisible() const268 bool Session::GetVisible() const
269 {
270 return isVisible_;
271 }
272
GetWindowId() const273 int32_t Session::GetWindowId() const
274 {
275 return GetPersistentId();
276 }
277
SetCallingPid(int32_t id)278 void Session::SetCallingPid(int32_t id)
279 {
280 callingPid_ = id;
281 }
282
SetCallingUid(int32_t id)283 void Session::SetCallingUid(int32_t id)
284 {
285 callingUid_ = id;
286 }
287
GetCallingPid() const288 int32_t Session::GetCallingPid() const
289 {
290 return callingPid_;
291 }
292
GetCallingUid() const293 int32_t Session::GetCallingUid() const
294 {
295 return callingUid_;
296 }
297
SetAbilityToken(sptr<IRemoteObject> token)298 void Session::SetAbilityToken(sptr<IRemoteObject> token)
299 {
300 abilityToken_ = token;
301 }
302
GetAbilityToken() const303 sptr<IRemoteObject> Session::GetAbilityToken() const
304 {
305 return abilityToken_;
306 }
307
SetBrightness(float brightness)308 WSError Session::SetBrightness(float brightness)
309 {
310 if (!property_) {
311 return WSError::WS_ERROR_NULLPTR;
312 }
313 property_->SetBrightness(brightness);
314 return WSError::WS_OK;
315 }
316
GetBrightness() const317 float Session::GetBrightness() const
318 {
319 if (!property_) {
320 return UNDEFINED_BRIGHTNESS;
321 }
322 return property_->GetBrightness();
323 }
324
IsSessionValid() const325 bool Session::IsSessionValid() const
326 {
327 bool res = state_ > SessionState::STATE_DISCONNECT && state_ < SessionState::STATE_END;
328 if (!res) {
329 WLOGFI("session is already destroyed or not created! id: %{public}d state: %{public}u",
330 GetPersistentId(), state_);
331 }
332 return res;
333 }
334
IsActive() const335 bool Session::IsActive() const
336 {
337 return isActive_;
338 }
339
UpdateRect(const WSRect & rect,SizeChangeReason reason)340 WSError Session::UpdateRect(const WSRect& rect, SizeChangeReason reason)
341 {
342 WLOGFI("session update rect: id: %{public}d, rect[%{public}d, %{public}d, %{public}u, %{public}u], "\
343 "reason:%{public}u", GetPersistentId(), rect.posX_, rect.posY_, rect.width_, rect.height_, reason);
344 if (!IsSessionValid()) {
345 winRect_ = rect;
346 return WSError::WS_ERROR_INVALID_SESSION;
347 }
348 winRect_ = rect;
349 sessionStage_->UpdateRect(rect, reason);
350 return WSError::WS_OK;
351 }
352
Connect(const sptr<ISessionStage> & sessionStage,const sptr<IWindowEventChannel> & eventChannel,const std::shared_ptr<RSSurfaceNode> & surfaceNode,SystemSessionConfig & systemConfig,sptr<WindowSessionProperty> property,sptr<IRemoteObject> token)353 WSError Session::Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
354 const std::shared_ptr<RSSurfaceNode>& surfaceNode, SystemSessionConfig& systemConfig, sptr<WindowSessionProperty> property, sptr<IRemoteObject> token)
355 {
356 callingPid_ = IPCSkeleton::GetCallingPid();
357 callingUid_ = IPCSkeleton::GetCallingUid();
358 return ConnectImpl(sessionStage, eventChannel, surfaceNode, systemConfig, property, token);
359 }
360
ConnectImpl(const sptr<ISessionStage> & sessionStage,const sptr<IWindowEventChannel> & eventChannel,const std::shared_ptr<RSSurfaceNode> & surfaceNode,SystemSessionConfig & systemConfig,sptr<WindowSessionProperty> property,sptr<IRemoteObject> token)361 WSError Session::ConnectImpl(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
362 const std::shared_ptr<RSSurfaceNode>& surfaceNode, SystemSessionConfig& systemConfig, sptr<WindowSessionProperty> property, sptr<IRemoteObject> token)
363 {
364 WLOGFI("Connect session, id: %{public}d, state: %{public}u", GetPersistentId(),
365 static_cast<uint32_t>(GetSessionState()));
366 if (GetSessionState() != SessionState::STATE_DISCONNECT) {
367 WLOGFE("state is not disconnect!");
368 return WSError::WS_ERROR_INVALID_SESSION;
369 }
370 if (sessionStage == nullptr || eventChannel == nullptr) {
371 WLOGFE("session stage or eventChannel is nullptr");
372 return WSError::WS_ERROR_NULLPTR;
373 }
374 sessionStage_ = sessionStage;
375 windowEventChannel_ = eventChannel;
376 surfaceNode_ = surfaceNode;
377 abilityToken_ = token;
378 systemConfig = systemConfig_;
379 if (property) {
380 property->SetPersistentId(GetPersistentId());
381 }
382 property_ = property;
383
384 UpdateSessionState(SessionState::STATE_CONNECT);
385 // once update rect before connect, update again when connect
386 UpdateRect(winRect_, SizeChangeReason::UNDEFINED);
387 NotifyConnect();
388 callingBundleName_ = DelayedSingleton<ANRManager>::GetInstance()->GetBundleName(callingPid_, callingUid_);
389 DelayedSingleton<ANRManager>::GetInstance()->SetApplicationInfo(persistentId_, callingPid_, callingBundleName_);
390 return WSError::WS_OK;
391 }
392
UpdateWindowSessionProperty(sptr<WindowSessionProperty> property)393 WSError Session::UpdateWindowSessionProperty(sptr<WindowSessionProperty> property)
394 {
395 property_ = property;
396 return WSError::WS_OK;
397 }
398
Foreground(sptr<WindowSessionProperty> property)399 WSError Session::Foreground(sptr<WindowSessionProperty> property)
400 {
401 HandleDialogForeground();
402 SessionState state = GetSessionState();
403 WLOGFI("Foreground session, id: %{public}d, state: %{public}" PRIu32"", GetPersistentId(),
404 static_cast<uint32_t>(state));
405 if (state != SessionState::STATE_CONNECT && state != SessionState::STATE_BACKGROUND) {
406 WLOGFE("state invalid!");
407 return WSError::WS_ERROR_INVALID_SESSION;
408 }
409
410 UpdateSessionState(SessionState::STATE_FOREGROUND);
411 if (!isActive_) {
412 SetActive(true);
413 }
414
415 if (GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) {
416 NotifyCallingSessionForeground();
417 }
418 return WSError::WS_OK;
419 }
420
NotifyCallingSessionForeground()421 void Session::NotifyCallingSessionForeground()
422 {
423 if (notifyCallingSessionForegroundFunc_) {
424 WLOGFI("Notify calling window that input method shown");
425 notifyCallingSessionForegroundFunc_(persistentId_);
426 }
427 }
428
HandleDialogBackground()429 void Session::HandleDialogBackground()
430 {
431 const auto& type = GetWindowType();
432 if (type < WindowType::APP_MAIN_WINDOW_BASE || type >= WindowType::APP_MAIN_WINDOW_END) {
433 WLOGFD("Current session is not main window, id: %{public}d, type: %{public}d", GetPersistentId(), type);
434 return;
435 }
436 for (const auto& dialog : dialogVec_) {
437 if (dialog == nullptr) {
438 continue;
439 }
440 WLOGFD("Background dialog, id: %{public}d, dialogId: %{public}d", GetPersistentId(), dialog->GetPersistentId());
441 dialog->SetActive(false);
442 dialog->Background();
443 }
444 }
445
HandleDialogForeground()446 void Session::HandleDialogForeground()
447 {
448 const auto& type = GetWindowType();
449 if (type < WindowType::APP_MAIN_WINDOW_BASE || type >= WindowType::APP_MAIN_WINDOW_END) {
450 WLOGFD("Current session is not main window, id: %{public}d, type: %{public}d", GetPersistentId(), type);
451 }
452 for (const auto& dialog : dialogVec_) {
453 if (dialog == nullptr) {
454 continue;
455 }
456 WLOGFD("Foreground dialog, id: %{public}d, dialogId: %{public}d", GetPersistentId(), dialog->GetPersistentId());
457 dialog->Foreground(dialog->GetSessionProperty());
458 }
459 }
460
Background()461 WSError Session::Background()
462 {
463 HandleDialogBackground();
464 SessionState state = GetSessionState();
465 WLOGFI("Background session, id: %{public}d, state: %{public}" PRIu32"", GetPersistentId(),
466 static_cast<uint32_t>(state));
467 if (state != SessionState::STATE_INACTIVE) {
468 WLOGFE("state invalid!");
469 return WSError::WS_ERROR_INVALID_SESSION;
470 }
471 UpdateSessionState(SessionState::STATE_BACKGROUND);
472 if (GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) {
473 NotifyCallingSessionBackground();
474 }
475 return WSError::WS_OK;
476 }
477
NotifyCallingSessionBackground()478 void Session::NotifyCallingSessionBackground()
479 {
480 if (notifyCallingSessionBackgroundFunc_) {
481 WLOGFI("Notify calling window that input method hide");
482 notifyCallingSessionBackgroundFunc_();
483 }
484 }
485
Disconnect()486 WSError Session::Disconnect()
487 {
488 SessionState state = GetSessionState();
489 WLOGFI("Disconnect session, id: %{public}d, state: %{public}" PRIu32"", GetPersistentId(),
490 static_cast<uint32_t>(state));
491 if (state == SessionState::STATE_ACTIVE) {
492 snapshot_ = Snapshot();
493 if (scenePersistence_ && snapshot_) {
494 scenePersistence_->SaveSnapshot(snapshot_);
495 }
496 }
497 UpdateSessionState(SessionState::STATE_BACKGROUND);
498 UpdateSessionState(SessionState::STATE_DISCONNECT);
499 NotifyDisconnect();
500 snapshot_.reset();
501 DelayedSingleton<ANRManager>::GetInstance()->OnSessionLost(persistentId_);
502 return WSError::WS_OK;
503 }
504
SetActive(bool active)505 WSError Session::SetActive(bool active)
506 {
507 SessionState state = GetSessionState();
508 WLOGFI("Session update active: %{public}d, id: %{public}d, state: %{public}" PRIu32"",
509 active, GetPersistentId(), static_cast<uint32_t>(state));
510 if (!IsSessionValid()) {
511 return WSError::WS_ERROR_INVALID_SESSION;
512 }
513 if (active == isActive_) {
514 WLOGFD("Session active do not change: [%{public}d]", active);
515 return WSError::WS_DO_NOTHING;
516 }
517 if (active && GetSessionState() == SessionState::STATE_FOREGROUND) {
518 sessionStage_->SetActive(true);
519 UpdateSessionState(SessionState::STATE_ACTIVE);
520 isActive_ = active;
521 }
522 if (!active && GetSessionState() == SessionState::STATE_ACTIVE) {
523 sessionStage_->SetActive(false);
524 UpdateSessionState(SessionState::STATE_INACTIVE);
525 isActive_ = active;
526 }
527 return WSError::WS_OK;
528 }
529
PendingSessionActivation(const sptr<AAFwk::SessionInfo> abilitySessionInfo)530 WSError Session::PendingSessionActivation(const sptr<AAFwk::SessionInfo> abilitySessionInfo)
531 {
532 if (abilitySessionInfo == nullptr) {
533 WLOGFE("abilitySessionInfo is null");
534 return WSError::WS_ERROR_INVALID_SESSION;
535 }
536 sessionInfo_.startMethod = OHOS::Rosen::StartMethod::START_CALL;
537
538 SessionInfo info;
539 info.abilityName_ = abilitySessionInfo->want.GetElement().GetAbilityName();
540 info.bundleName_ = abilitySessionInfo->want.GetElement().GetBundleName();
541 info.moduleName_ = abilitySessionInfo->want.GetModuleName();
542 info.persistentId_ = abilitySessionInfo->persistentId;
543 info.callerPersistentId_ = GetPersistentId();
544 info.callState_ = static_cast<uint32_t>(abilitySessionInfo->state);
545 info.uiAbilityId_ = abilitySessionInfo->uiAbilityId;
546 info.want = new AAFwk::Want(abilitySessionInfo->want);
547 info.requestCode = abilitySessionInfo->requestCode;
548 info.callerToken_ = abilitySessionInfo->callerToken;
549 info.startSetting = abilitySessionInfo->startSetting;
550 info.callingTokenId_ = abilitySessionInfo->callingTokenId;
551 info.reuse = abilitySessionInfo->reuse;
552 WLOGFI("PendingSessionActivation:bundleName %{public}s, moduleName:%{public}s, abilityName:%{public}s",
553 info.bundleName_.c_str(), info.moduleName_.c_str(), info.abilityName_.c_str());
554 WLOGFI("PendingSessionActivation callState:%{public}d, want persistentId: %{public}d, callingTokenId:%{public}d, \
555 uiAbilityId: %{public}" PRIu64 "", info.callState_, info.persistentId_, info.callingTokenId_,
556 info.uiAbilityId_);
557 if (pendingSessionActivationFunc_) {
558 pendingSessionActivationFunc_(info);
559 }
560 return WSError::WS_OK;
561 }
562
SetPendingSessionActivationEventListener(const NotifyPendingSessionActivationFunc & func)563 void Session::SetPendingSessionActivationEventListener(const NotifyPendingSessionActivationFunc& func)
564 {
565 pendingSessionActivationFunc_ = func;
566 }
567
SetBackPressedListenser(const NotifyBackPressedFunc & func)568 void Session::SetBackPressedListenser(const NotifyBackPressedFunc& func)
569 {
570 backPressedFunc_ = func;
571 }
572
TerminateSession(const sptr<AAFwk::SessionInfo> abilitySessionInfo)573 WSError Session::TerminateSession(const sptr<AAFwk::SessionInfo> abilitySessionInfo)
574 {
575 if (abilitySessionInfo == nullptr) {
576 WLOGFE("abilitySessionInfo is null");
577 return WSError::WS_ERROR_INVALID_SESSION;
578 }
579 SessionInfo info;
580 info.abilityName_ = abilitySessionInfo->want.GetElement().GetAbilityName();
581 info.bundleName_ = abilitySessionInfo->want.GetElement().GetBundleName();
582 info.callerToken_ = abilitySessionInfo->callerToken;
583 info.persistentId_ = static_cast<int32_t>(abilitySessionInfo->persistentId);
584 sessionInfo_.want = new AAFwk::Want(abilitySessionInfo->want);
585 sessionInfo_.resultCode = abilitySessionInfo->resultCode;
586 if (terminateSessionFunc_) {
587 terminateSessionFunc_(info);
588 }
589 return WSError::WS_OK;
590 }
591
SetTerminateSessionListener(const NotifyTerminateSessionFunc & func)592 void Session::SetTerminateSessionListener(const NotifyTerminateSessionFunc& func)
593 {
594 terminateSessionFunc_ = func;
595 }
596
TerminateSessionNew(const sptr<AAFwk::SessionInfo> abilitySessionInfo,bool needStartCaller)597 WSError Session::TerminateSessionNew(const sptr<AAFwk::SessionInfo> abilitySessionInfo, bool needStartCaller)
598 {
599 if (abilitySessionInfo == nullptr) {
600 WLOGFE("abilitySessionInfo is null");
601 return WSError::WS_ERROR_INVALID_SESSION;
602 }
603 SessionInfo info;
604 info.abilityName_ = abilitySessionInfo->want.GetElement().GetAbilityName();
605 info.bundleName_ = abilitySessionInfo->want.GetElement().GetBundleName();
606 info.callerToken_ = abilitySessionInfo->callerToken;
607 info.persistentId_ = static_cast<int32_t>(abilitySessionInfo->persistentId);
608 sessionInfo_.want = new AAFwk::Want(abilitySessionInfo->want);
609 sessionInfo_.resultCode = abilitySessionInfo->resultCode;
610 if (terminateSessionFuncNew_) {
611 terminateSessionFuncNew_(info, needStartCaller);
612 }
613 return WSError::WS_OK;
614 }
615
SetTerminateSessionListenerNew(const NotifyTerminateSessionFuncNew & func)616 void Session::SetTerminateSessionListenerNew(const NotifyTerminateSessionFuncNew& func)
617 {
618 terminateSessionFuncNew_ = func;
619 }
620
TerminateSessionTotal(const sptr<AAFwk::SessionInfo> abilitySessionInfo,TerminateType terminateType)621 WSError Session::TerminateSessionTotal(const sptr<AAFwk::SessionInfo> abilitySessionInfo, TerminateType terminateType)
622 {
623 if (abilitySessionInfo == nullptr) {
624 WLOGFE("abilitySessionInfo is null");
625 return WSError::WS_ERROR_INVALID_SESSION;
626 }
627 SessionInfo info;
628 info.abilityName_ = abilitySessionInfo->want.GetElement().GetAbilityName();
629 info.bundleName_ = abilitySessionInfo->want.GetElement().GetBundleName();
630 info.callerToken_ = abilitySessionInfo->callerToken;
631 info.persistentId_ = static_cast<int32_t>(abilitySessionInfo->persistentId);
632 sessionInfo_.want = new AAFwk::Want(abilitySessionInfo->want);
633 sessionInfo_.resultCode = abilitySessionInfo->resultCode;
634 if (terminateSessionFuncTotal_) {
635 terminateSessionFuncTotal_(info, terminateType);
636 }
637 return WSError::WS_OK;
638 }
639
SetTerminateSessionListenerTotal(const NotifyTerminateSessionFuncTotal & func)640 void Session::SetTerminateSessionListenerTotal(const NotifyTerminateSessionFuncTotal& func)
641 {
642 terminateSessionFuncTotal_ = func;
643 }
644
Clear()645 WSError Session::Clear()
646 {
647 SessionInfo info = GetSessionInfo();
648 if (terminateSessionFuncTotal_) {
649 terminateSessionFuncTotal_(info, TerminateType::CLOSE_AND_CLEAR_MULTITASK);
650 }
651 return WSError::WS_OK;
652 }
653
NotifySessionException(const sptr<AAFwk::SessionInfo> abilitySessionInfo)654 WSError Session::NotifySessionException(const sptr<AAFwk::SessionInfo> abilitySessionInfo)
655 {
656 if (abilitySessionInfo == nullptr) {
657 WLOGFE("abilitySessionInfo is null");
658 return WSError::WS_ERROR_INVALID_SESSION;
659 }
660 SessionInfo info;
661 info.abilityName_ = abilitySessionInfo->want.GetElement().GetAbilityName();
662 info.bundleName_ = abilitySessionInfo->want.GetElement().GetBundleName();
663 info.callerToken_ = abilitySessionInfo->callerToken;
664 info.errorCode = abilitySessionInfo->errorCode;
665 info.errorReason = abilitySessionInfo->errorReason;
666 info.persistentId_ = static_cast<int32_t>(abilitySessionInfo->persistentId);
667 sessionInfo_.want = new AAFwk::Want(abilitySessionInfo->want);
668 sessionInfo_.errorCode = abilitySessionInfo->errorCode;
669 sessionInfo_.errorReason = abilitySessionInfo->errorReason;
670 std::lock_guard<std::recursive_mutex> lock(mutex_);
671 if (!sessionExceptionFuncs_.empty()) {
672 for (std::shared_ptr<NotifySessionExceptionFunc> funcSptr: sessionExceptionFuncs_) {
673 auto sessionExceptionFunc = *funcSptr;
674 sessionExceptionFunc(info);
675 }
676 }
677 return WSError::WS_OK;
678 }
679
SetSessionExceptionListener(const NotifySessionExceptionFunc & func)680 void Session::SetSessionExceptionListener(const NotifySessionExceptionFunc& func)
681 {
682 if (func == nullptr) {
683 WLOGFE("func is nullptr");
684 return;
685 }
686 std::lock_guard<std::recursive_mutex> lock(mutex_);
687 std::shared_ptr<NotifySessionExceptionFunc> funcSptr = std::make_shared<NotifySessionExceptionFunc>(func);
688 if (std::find(sessionExceptionFuncs_.begin(), sessionExceptionFuncs_.end(), funcSptr) !=
689 sessionExceptionFuncs_.end()) {
690 WLOGFW("func already regitered");
691 return;
692 }
693 sessionExceptionFuncs_.emplace_back(funcSptr);
694 }
695
SetPendingSessionToForegroundListener(const NotifyPendingSessionToForegroundFunc & func)696 void Session::SetPendingSessionToForegroundListener(const NotifyPendingSessionToForegroundFunc& func)
697 {
698 pendingSessionToForegroundFunc_ = func;
699 }
700
PendingSessionToForeground()701 WSError Session::PendingSessionToForeground()
702 {
703 WLOGFI("run PendingSessionToForeground");
704 SessionInfo info = GetSessionInfo();
705 if (pendingSessionActivationFunc_) {
706 pendingSessionActivationFunc_(info);
707 }
708 return WSError::WS_OK;
709 }
710
SetPendingSessionToBackgroundForDelegatorListener(const NotifyPendingSessionToBackgroundForDelegatorFunc & func)711 void Session::SetPendingSessionToBackgroundForDelegatorListener(
712 const NotifyPendingSessionToBackgroundForDelegatorFunc& func)
713 {
714 pendingSessionToBackgroundForDelegatorFunc_ = func;
715 }
716
PendingSessionToBackgroundForDelegator()717 WSError Session::PendingSessionToBackgroundForDelegator()
718 {
719 WLOGFI("run PendingSessionToBackgroundForDelegator");
720 SessionInfo info = GetSessionInfo();
721 if (pendingSessionToBackgroundForDelegatorFunc_) {
722 pendingSessionToBackgroundForDelegatorFunc_(info);
723 }
724 return WSError::WS_OK;
725 }
726
SetNotifyCallingSessionForegroundFunc(const NotifyCallingSessionForegroundFunc & func)727 void Session::SetNotifyCallingSessionForegroundFunc(const NotifyCallingSessionForegroundFunc& func)
728 {
729 notifyCallingSessionForegroundFunc_ = func;
730 }
731
SetNotifyCallingSessionBackgroundFunc(const NotifyCallingSessionBackgroundFunc & func)732 void Session::SetNotifyCallingSessionBackgroundFunc(const NotifyCallingSessionBackgroundFunc& func)
733 {
734 notifyCallingSessionBackgroundFunc_ = func;
735 }
736
NotifyTouchDialogTarget()737 void Session::NotifyTouchDialogTarget()
738 {
739 if (!sessionStage_) {
740 return;
741 }
742 sessionStage_->NotifyTouchDialogTarget();
743 }
744
NotifyScreenshot()745 void Session::NotifyScreenshot()
746 {
747 if (!sessionStage_) {
748 return;
749 }
750 sessionStage_->NotifyScreenshot();
751 }
752
NotifyDestroy()753 WSError Session::NotifyDestroy()
754 {
755 if (!sessionStage_) {
756 return WSError::WS_ERROR_NULLPTR;
757 }
758 return sessionStage_->NotifyDestroy();
759 }
760
SetSessionContinueState(const ContinueState & continueState)761 void Session::SetSessionContinueState(const ContinueState& continueState)
762 {
763 auto sessionInfo = GetSessionInfo();
764 WLOGFD("SetSessionContinueState, continueState : %{public}d", static_cast<int32_t>(continueState));
765 sessionInfo.continueState = continueState;
766 }
767
SetParentSession(const sptr<Session> & session)768 void Session::SetParentSession(const sptr<Session>& session)
769 {
770 parentSession_ = session;
771 }
772
BindDialogToParentSession(const sptr<Session> & session)773 void Session::BindDialogToParentSession(const sptr<Session>& session)
774 {
775 auto iter = std::find(dialogVec_.begin(), dialogVec_.end(), session);
776 if (iter != dialogVec_.end()) {
777 WLOGFW("Dialog is existed in parentVec, id: %{public}d, parentId: %{public}d",
778 session->GetPersistentId(), GetPersistentId());
779 return;
780 }
781 dialogVec_.push_back(session);
782 WLOGFD("Bind dialog success, id: %{public}d, parentId: %{public}d",
783 session->GetPersistentId(), GetPersistentId());
784 }
785
RemoveDialogToParentSession(const sptr<Session> & session)786 void Session::RemoveDialogToParentSession(const sptr<Session>& session)
787 {
788 auto iter = std::find(dialogVec_.begin(), dialogVec_.end(), session);
789 if (iter != dialogVec_.end()) {
790 WLOGFD("Remove dialog success, id: %{public}d, parentId: %{public}d",
791 session->GetPersistentId(), GetPersistentId());
792 dialogVec_.erase(iter);
793 }
794 WLOGFW("Remove dialog failed, id: %{public}d, parentId: %{public}d",
795 session->GetPersistentId(), GetPersistentId());
796 }
797
GetDialogVector() const798 std::vector<sptr<Session>> Session::GetDialogVector() const
799 {
800 return dialogVec_;
801 }
802
CheckDialogOnForeground()803 bool Session::CheckDialogOnForeground()
804 {
805 if (dialogVec_.empty()) {
806 return false;
807 }
808 for (auto dialogSession : dialogVec_) {
809 if (dialogSession && dialogSession->GetSessionState() == SessionState::STATE_ACTIVE) {
810 dialogSession->NotifyTouchDialogTarget();
811 WLOGFD("Notify touch dialog window");
812 return true;
813 }
814 }
815 return false;
816 }
817
TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)818 WSError Session::TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
819 {
820 if (GetWindowType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW) {
821 if (CheckDialogOnForeground()) {
822 WLOGFD("Has dialog on foreground, not transfer pointer event");
823 return WSError::WS_ERROR_INVALID_PERMISSION;
824 }
825 } else if (GetWindowType() == WindowType::WINDOW_TYPE_APP_SUB_WINDOW) {
826 if (parentSession_ && parentSession_->CheckDialogOnForeground()) {
827 WLOGFD("Its main window has dialog on foreground, not transfer pointer event");
828 return WSError::WS_ERROR_INVALID_PERMISSION;
829 }
830 }
831 if (pointerEvent == nullptr) {
832 WLOGFE("PointerEvent is nullptr");
833 return WSError::WS_ERROR_NULLPTR;
834 }
835 WLOGFD("Session TransferPointEvent, eventId:%{public}d, persistentId:%{public}d, "
836 "bundleName:%{public}s, pid:%{public}d",
837 pointerEvent->GetId(), persistentId_, callingBundleName_.c_str(), callingPid_);
838 if (DelayedSingleton<ANRManager>::GetInstance()->IsANRTriggered(persistentId_)) {
839 WLOGFD("The pointerEvent does not report normally, bundleName:%{public}s not response, pid:%{public}d",
840 callingBundleName_.c_str(), callingPid_);
841 return WSError::WS_DO_NOTHING;
842 }
843 auto action = pointerEvent->GetPointerAction();
844 if (!isFocused_ && GetFocusable() && (action == MMI::PointerEvent::POINTER_ACTION_DOWN ||
845 action == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN)) {
846 NotifyClick();
847 }
848 if (!windowEventChannel_) {
849 WLOGFE("windowEventChannel_ is null");
850 return WSError::WS_ERROR_NULLPTR;
851 }
852 if (WSError ret = windowEventChannel_->TransferPointerEvent(pointerEvent); ret != WSError::WS_OK) {
853 WLOGFE("TransferPointer failed");
854 return ret;
855 }
856 auto pointerAction = pointerEvent->GetPointerAction();
857 if (pointerAction == MMI::PointerEvent::POINTER_ACTION_ENTER_WINDOW ||
858 pointerAction == MMI::PointerEvent::POINTER_ACTION_LEAVE_WINDOW ||
859 pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_IN_WINDOW ||
860 pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW) {
861 WLOGFD("Action:%{public}s, eventId:%{public}d, report without timer",
862 pointerEvent->DumpPointerAction(), pointerEvent->GetId());
863 } else {
864 DelayedSingleton<ANRManager>::GetInstance()->AddTimer(pointerEvent->GetId(), persistentId_);
865 }
866 return WSError::WS_OK;
867 }
868
TransferKeyEvent(const std::shared_ptr<MMI::KeyEvent> & keyEvent)869 WSError Session::TransferKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
870 {
871 if (GetWindowType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW) {
872 if (CheckDialogOnForeground()) {
873 WLOGFD("Has dialog on foreground, not transfer pointer event");
874 return WSError::WS_ERROR_INVALID_PERMISSION;
875 }
876 } else if (GetWindowType() == WindowType::WINDOW_TYPE_APP_SUB_WINDOW) {
877 if (parentSession_ && parentSession_->CheckDialogOnForeground()) {
878 WLOGFD("Its main window has dialog on foreground, not transfer pointer event");
879 return WSError::WS_ERROR_INVALID_PERMISSION;
880 }
881 }
882 if (keyEvent == nullptr) {
883 WLOGFE("KeyEvent is nullptr");
884 return WSError::WS_ERROR_NULLPTR;
885 }
886 WLOGFD("Session TransferKeyEvent, eventId:%{public}d, persistentId:%{public}d, "
887 "bundleName:%{public}s, pid:%{public}d",
888 keyEvent->GetId(), persistentId_, callingBundleName_.c_str(), callingPid_);
889 if (DelayedSingleton<ANRManager>::GetInstance()->IsANRTriggered(persistentId_)) {
890 WLOGFD("The keyEvent does not report normally, bundleName:%{public}s not response, pid:%{public}d",
891 callingBundleName_.c_str(), callingPid_);
892 return WSError::WS_DO_NOTHING;
893 }
894 if (!windowEventChannel_) {
895 WLOGFE("windowEventChannel_ is null");
896 return WSError::WS_ERROR_NULLPTR;
897 }
898 WLOGD("TransferKeyEvent, id: %{public}d", persistentId_);
899 if (WSError ret = windowEventChannel_->TransferKeyEvent(keyEvent); ret != WSError::WS_OK) {
900 WLOGFE("TransferKeyEvent failed");
901 return ret;
902 }
903 DelayedSingleton<ANRManager>::GetInstance()->AddTimer(keyEvent->GetId(), persistentId_);
904 return WSError::WS_OK;
905 }
906
TransferKeyEventForConsumed(const std::shared_ptr<MMI::KeyEvent> & keyEvent,bool & isConsumed)907 WSError Session::TransferKeyEventForConsumed(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed)
908 {
909 if (!windowEventChannel_) {
910 WLOGFE("windowEventChannel_ is null");
911 return WSError::WS_ERROR_NULLPTR;
912 }
913 if (keyEvent == nullptr) {
914 WLOGFE("KeyEvent is nullptr");
915 return WSError::WS_ERROR_NULLPTR;
916 }
917 return windowEventChannel_->TransferKeyEventForConsumed(keyEvent, isConsumed);
918 }
919
TransferFocusActiveEvent(bool isFocusActive)920 WSError Session::TransferFocusActiveEvent(bool isFocusActive)
921 {
922 if (!windowEventChannel_) {
923 WLOGFE("windowEventChannel_ is null");
924 return WSError::WS_ERROR_NULLPTR;
925 }
926 return windowEventChannel_->TransferFocusActiveEvent(isFocusActive);
927 }
928
TransferFocusStateEvent(bool focusState)929 WSError Session::TransferFocusStateEvent(bool focusState)
930 {
931 if (!windowEventChannel_) {
932 WLOGFE("windowEventChannel_ is null");
933 return WSError::WS_ERROR_NULLPTR;
934 }
935 return windowEventChannel_->TransferFocusState(focusState);
936 }
937
Snapshot()938 std::shared_ptr<Media::PixelMap> Session::Snapshot()
939 {
940 auto callback = std::make_shared<SurfaceCaptureFuture>();
941 constexpr float scale = 0.5;
942 bool ret = RSInterfaces::GetInstance().TakeSurfaceCapture(surfaceNode_, callback, scale, scale);
943 if (!ret) {
944 WLOGFE("TakeSurfaceCapture failed");
945 return nullptr;
946 }
947 auto pixelMap = callback->GetResult(2000); // wait for <= 2000ms
948 if (pixelMap != nullptr) {
949 WLOGFD("Save pixelMap WxH = %{public}dx%{public}d", pixelMap->GetWidth(), pixelMap->GetHeight());
950 } else {
951 WLOGFE("Failed to get pixelMap, return nullptr");
952 }
953 return pixelMap;
954 }
955
SetSessionStateChangeListenser(const NotifySessionStateChangeFunc & func)956 void Session::SetSessionStateChangeListenser(const NotifySessionStateChangeFunc& func)
957 {
958 sessionStateChangeFunc_ = func;
959 NotifySessionStateChange(state_);
960 }
961
SetSessionStateChangeNotifyManagerListener(const NotifySessionStateChangeNotifyManagerFunc & func)962 void Session::SetSessionStateChangeNotifyManagerListener(const NotifySessionStateChangeNotifyManagerFunc& func)
963 {
964 sessionStateChangeNotifyManagerFunc_ = func;
965 NotifySessionStateChange(state_);
966 }
967
NotifySessionStateChange(const SessionState & state)968 void Session::NotifySessionStateChange(const SessionState& state)
969 {
970 WLOGFI("state: %{public}u", static_cast<uint32_t>(state));
971 if (sessionStateChangeFunc_) {
972 sessionStateChangeFunc_(state);
973 }
974 if (sessionStateChangeNotifyManagerFunc_) {
975 sessionStateChangeNotifyManagerFunc_(GetPersistentId(), state);
976 }
977 }
978
SetSessionFocusableChangeListener(const NotifySessionFocusableChangeFunc & func)979 void Session::SetSessionFocusableChangeListener(const NotifySessionFocusableChangeFunc& func)
980 {
981 sessionFocusableChangeFunc_ = func;
982 sessionFocusableChangeFunc_(GetFocusable());
983 }
984
SetSessionTouchableChangeListener(const NotifySessionTouchableChangeFunc & func)985 void Session::SetSessionTouchableChangeListener(const NotifySessionTouchableChangeFunc& func)
986 {
987 sessionTouchableChangeFunc_ = func;
988 sessionTouchableChangeFunc_(GetTouchable());
989 }
990
SetClickListener(const NotifyClickFunc & func)991 void Session::SetClickListener(const NotifyClickFunc& func)
992 {
993 clickFunc_ = func;
994 }
995
NotifySessionFocusableChange(bool isFocusable)996 void Session::NotifySessionFocusableChange(bool isFocusable)
997 {
998 WLOGFI("Notify session focusable change: %{public}u", isFocusable);
999 if (sessionFocusableChangeFunc_) {
1000 sessionFocusableChangeFunc_(isFocusable);
1001 }
1002 }
1003
NotifySessionTouchableChange(bool touchable)1004 void Session::NotifySessionTouchableChange(bool touchable)
1005 {
1006 WLOGFI("Notify session touchable change: %{public}u", touchable);
1007 if (sessionTouchableChangeFunc_) {
1008 sessionTouchableChangeFunc_(touchable);
1009 }
1010 }
1011
NotifyClick()1012 void Session::NotifyClick()
1013 {
1014 WLOGFI("Notify click");
1015 if (clickFunc_) {
1016 clickFunc_();
1017 }
1018 }
1019
UpdateFocus(bool isFocused)1020 WSError Session::UpdateFocus(bool isFocused)
1021 {
1022 WLOGFI("Session update focus id: %{public}d", GetPersistentId());
1023 if (isFocused_ == isFocused) {
1024 WLOGFD("Session focus do not change: [%{public}d]", isFocused);
1025 return WSError::WS_DO_NOTHING;
1026 }
1027 isFocused_ = isFocused;
1028 if (!IsSessionValid()) {
1029 return WSError::WS_ERROR_INVALID_SESSION;
1030 }
1031 sessionStage_->UpdateFocus(isFocused);
1032
1033 return WSError::WS_OK;
1034 }
1035
UpdateWindowMode(WindowMode mode)1036 WSError Session::UpdateWindowMode(WindowMode mode)
1037 {
1038 WLOGFI("Session update window mode, id: %{public}d, mode: %{public}d", GetPersistentId(),
1039 static_cast<int32_t>(mode));
1040 if (!IsSessionValid()) {
1041 return WSError::WS_ERROR_INVALID_SESSION;
1042 }
1043 return sessionStage_->UpdateWindowMode(mode);
1044 }
1045
SetSessionRect(const WSRect & rect)1046 void Session::SetSessionRect(const WSRect& rect)
1047 {
1048 winRect_ = rect;
1049 }
1050
GetSessionRect() const1051 WSRect Session::GetSessionRect() const
1052 {
1053 return winRect_;
1054 }
1055
SetSessionRequestRect(const WSRect & rect)1056 void Session::SetSessionRequestRect(const WSRect& rect)
1057 {
1058 if (property_ == nullptr) {
1059 WLOGFD("id: %{public}d property is nullptr", persistentId_);
1060 return;
1061 }
1062 property_->SetRequestRect(SessionHelper::TransferToRect(rect));
1063 WLOGFD("is: %{public}d, rect: [%{public}d, %{public}d, %{public}u, %{public}u]", persistentId_,
1064 rect.posX_, rect.posY_, rect.width_, rect.height_);
1065 }
1066
GetSessionRequestRect() const1067 WSRect Session::GetSessionRequestRect() const
1068 {
1069 WSRect rect;
1070 if (property_ == nullptr) {
1071 WLOGFD("id: %{public}d property is nullptr", persistentId_);
1072 return rect;
1073 }
1074 rect = SessionHelper::TransferToWSRect(property_->GetRequestRect());
1075 WLOGFD("is: %{public}d, rect: [%{public}d, %{public}d, %{public}u, %{public}u]", persistentId_,
1076 rect.posX_, rect.posY_, rect.width_, rect.height_);
1077 return rect;
1078 }
1079
UpdateActiveStatus(bool isActive)1080 WSError Session::UpdateActiveStatus(bool isActive)
1081 {
1082 if (!IsSessionValid()) {
1083 return WSError::WS_ERROR_INVALID_SESSION;
1084 }
1085 if (isActive == isActive_) {
1086 WLOGFD("Session active do not change: [%{public}d]", isActive);
1087 return WSError::WS_DO_NOTHING;
1088 }
1089 WSError ret = WSError::WS_DO_NOTHING;
1090
1091 if (isActive && GetSessionState() == SessionState::STATE_FOREGROUND) {
1092 UpdateSessionState(SessionState::STATE_ACTIVE);
1093 isActive_ = isActive;
1094 ret = WSError::WS_OK;
1095 }
1096 if (!isActive && GetSessionState() == SessionState::STATE_ACTIVE) {
1097 UpdateSessionState(SessionState::STATE_INACTIVE);
1098 isActive_ = isActive;
1099 ret = WSError::WS_OK;
1100 }
1101 WLOGFD("UpdateActiveStatus, isActive: %{public}d, state: %{public}u", isActive_,
1102 static_cast<uint32_t>(state_));
1103 return ret;
1104 }
1105
OnSessionEvent(SessionEvent event)1106 WSError Session::OnSessionEvent(SessionEvent event)
1107 {
1108 WLOGFD("Session OnSessionEvent");
1109 return WSError::WS_OK;
1110 }
1111
OnNeedAvoid(bool status)1112 WSError Session::OnNeedAvoid(bool status)
1113 {
1114 return WSError::WS_OK;
1115 }
1116
UpdateSessionRect(const WSRect & rect,const SizeChangeReason & reason)1117 WSError Session::UpdateSessionRect(const WSRect& rect, const SizeChangeReason& reason)
1118 {
1119 WLOGFD("UpdateSessionRect");
1120 return WSError::WS_OK;
1121 }
1122
RaiseToAppTop()1123 WSError Session::RaiseToAppTop()
1124 {
1125 return WSError::WS_OK;
1126 }
1127
RaiseAboveTarget(int32_t subWindowId)1128 WSError Session::RaiseAboveTarget(int32_t subWindowId)
1129 {
1130 return WSError::WS_OK;
1131 }
1132
CreateAndConnectSpecificSession(const sptr<ISessionStage> & sessionStage,const sptr<IWindowEventChannel> & eventChannel,const std::shared_ptr<RSSurfaceNode> & surfaceNode,sptr<WindowSessionProperty> property,int32_t & persistentId,sptr<ISession> & session,sptr<IRemoteObject> token)1133 WSError Session::CreateAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage,
1134 const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
1135 sptr<WindowSessionProperty> property, int32_t& persistentId, sptr<ISession>& session, sptr<IRemoteObject> token)
1136 {
1137 return WSError::WS_OK;
1138 }
1139
DestroyAndDisconnectSpecificSession(const int32_t & persistentId)1140 WSError Session::DestroyAndDisconnectSpecificSession(const int32_t& persistentId)
1141 {
1142 return WSError::WS_OK;
1143 }
1144
GetSessionProperty() const1145 sptr<WindowSessionProperty> Session::GetSessionProperty() const
1146 {
1147 return property_;
1148 }
1149
GetWindowType() const1150 WindowType Session::GetWindowType() const
1151 {
1152 if (property_ != nullptr) {
1153 return property_->GetWindowType();
1154 }
1155 return WindowType::WINDOW_TYPE_APP_MAIN_WINDOW;
1156 }
1157
SetSystemConfig(const SystemSessionConfig & systemConfig)1158 void Session::SetSystemConfig(const SystemSessionConfig& systemConfig)
1159 {
1160 systemConfig_ = systemConfig;
1161 }
1162
RequestSessionBack()1163 WSError Session::RequestSessionBack()
1164 {
1165 if (!backPressedFunc_) {
1166 WLOGFW("Session didn't register back event consumer!");
1167 return WSError::WS_DO_NOTHING;
1168 }
1169 backPressedFunc_();
1170 return WSError::WS_OK;
1171 }
1172
ProcessBackEvent()1173 WSError Session::ProcessBackEvent()
1174 {
1175 if (!IsSessionValid()) {
1176 return WSError::WS_ERROR_INVALID_SESSION;
1177 }
1178 return sessionStage_->HandleBackEvent();
1179 }
1180
MarkProcessed(int32_t eventId)1181 WSError Session::MarkProcessed(int32_t eventId)
1182 {
1183 int32_t persistentId = GetPersistentId();
1184 WLOGFI("persistentId:%{public}d, eventId:%{public}d", persistentId, eventId);
1185 DelayedSingleton<ANRManager>::GetInstance()->MarkProcessed(eventId, persistentId);
1186 return WSError::WS_OK;
1187 }
1188
GeneratePersistentId(bool isExtension,const SessionInfo & sessionInfo)1189 void Session::GeneratePersistentId(bool isExtension, const SessionInfo& sessionInfo)
1190 {
1191 if (sessionInfo.persistentId_ != INVALID_SESSION_ID) {
1192 g_persistentIdSet.insert(sessionInfo.persistentId_);
1193 persistentId_ = sessionInfo.persistentId_;
1194 return;
1195 }
1196
1197 if (g_persistentId == INVALID_SESSION_ID) {
1198 g_persistentId++; // init non system session id from 2
1199 }
1200
1201 g_persistentId++;
1202 while (g_persistentIdSet.count(g_persistentId)) {
1203 g_persistentId++;
1204 }
1205 persistentId_ = isExtension ? static_cast<uint32_t>(
1206 g_persistentId.load()) | 0x40000000 : static_cast<uint32_t>(g_persistentId.load()) & 0x3fffffff;
1207 g_persistentIdSet.insert(g_persistentId);
1208 }
1209
GetScenePersistence() const1210 sptr<ScenePersistence> Session::GetScenePersistence() const
1211 {
1212 return scenePersistence_;
1213 }
1214
SetGlobalMaximizeMode(MaximizeMode mode)1215 WSError Session::SetGlobalMaximizeMode(MaximizeMode mode)
1216 {
1217 WLOGFD("Session SetGlobalMaximizeMode");
1218 return WSError::WS_OK;
1219 }
1220
GetGlobalMaximizeMode(MaximizeMode & mode)1221 WSError Session::GetGlobalMaximizeMode(MaximizeMode& mode)
1222 {
1223 WLOGFD("Session GetGlobalMaximizeMode");
1224 return WSError::WS_OK;
1225 }
1226
GetAvoidAreaByType(AvoidAreaType type)1227 AvoidArea Session::GetAvoidAreaByType(AvoidAreaType type)
1228 {
1229 AvoidArea avoidArea;
1230 return avoidArea;
1231 }
1232
TransferAbilityResult(uint32_t resultCode,const AAFwk::Want & want)1233 WSError Session::TransferAbilityResult(uint32_t resultCode, const AAFwk::Want& want)
1234 {
1235 return WSError::WS_OK;
1236 }
1237
TransferExtensionData(const AAFwk::WantParams & wantParams)1238 WSError Session::TransferExtensionData(const AAFwk::WantParams& wantParams)
1239 {
1240 return WSError::WS_OK;
1241 }
1242
NotifyOccupiedAreaChangeInfo(sptr<OccupiedAreaChangeInfo> info)1243 void Session::NotifyOccupiedAreaChangeInfo(sptr<OccupiedAreaChangeInfo> info)
1244 {
1245 if (!sessionStage_) {
1246 WLOGFE("session stage is nullptr");
1247 return;
1248 }
1249 sessionStage_->NotifyOccupiedAreaChangeInfo(info);
1250 }
1251
NotifyRemoteReady()1252 void Session::NotifyRemoteReady()
1253 {
1254 return;
1255 }
1256
GetWindowMode()1257 WindowMode Session::GetWindowMode()
1258 {
1259 if (property_ == nullptr) {
1260 WLOGFW("null property.");
1261 return WindowMode::WINDOW_MODE_UNDEFINED;
1262 }
1263 return property_->GetWindowMode();
1264 }
1265
SetZOrder(uint32_t zOrder)1266 void Session::SetZOrder(uint32_t zOrder)
1267 {
1268 zOrder_ = zOrder;
1269 }
1270
GetZOrder() const1271 uint32_t Session::GetZOrder() const
1272 {
1273 return zOrder_;
1274 }
1275
SetUINodeId(uint32_t uiNodeId)1276 void Session::SetUINodeId(uint32_t uiNodeId)
1277 {
1278 uiNodeId_ = uiNodeId;
1279 }
1280
GetUINodeId() const1281 uint32_t Session::GetUINodeId() const
1282 {
1283 return uiNodeId_;
1284 }
1285
UpdateWindowAnimationFlag(bool needDefaultAnimationFlag)1286 WSError Session::UpdateWindowAnimationFlag(bool needDefaultAnimationFlag)
1287 {
1288 WLOGFD("UpdateWindowAnimationFlag");
1289 return WSError::WS_OK;
1290 }
1291
UpdateWindowSceneAfterCustomAnimation(bool isAdd)1292 WSError Session::UpdateWindowSceneAfterCustomAnimation(bool isAdd)
1293 {
1294 return WSError::WS_OK;
1295 }
1296
SetShowRecent(bool showRecent)1297 void Session::SetShowRecent(bool showRecent)
1298 {
1299 showRecent_ = showRecent;
1300 }
1301
GetShowRecent() const1302 bool Session::GetShowRecent() const
1303 {
1304 return showRecent_;
1305 }
1306
SetBufferAvailable(bool bufferAvailable)1307 void Session::SetBufferAvailable(bool bufferAvailable)
1308 {
1309 bufferAvailable_ = bufferAvailable;
1310 }
1311
GetBufferAvailable() const1312 bool Session::GetBufferAvailable() const
1313 {
1314 return bufferAvailable_;
1315 }
1316 } // namespace OHOS::Rosen
1317