1 /*
2 * Copyright (c) 2025-2025 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 "floating_ball_manager.h"
17
18 #include "parameters.h"
19 #include "floating_ball_controller.h"
20 #include "window_manager_hilog.h"
21 #include "window_scene_session_impl.h"
22 #include "scene_board_judgement.h"
23
24 namespace OHOS {
25 namespace Rosen {
26 namespace {
27 const std::string ACTION_CLICK = "click";
28 const std::string ACTION_CLOSE = "close";
29
30 const std::map<std::string, std::function<void()>> FB_ACTION_MAP {
31 {ACTION_CLICK, FloatingBallManager::DoActionClick},
32 {ACTION_CLOSE, FloatingBallManager::DoActionClose},
33 };
34 }
35
36 sptr<FloatingBallController> FloatingBallManager::activeController_ = nullptr;
37
HasActiveController()38 bool FloatingBallManager::HasActiveController()
39 {
40 return activeController_ != nullptr;
41 }
42
IsActiveController(const wptr<FloatingBallController> & fbController)43 bool FloatingBallManager::IsActiveController(const wptr<FloatingBallController>& fbController)
44 {
45 if (!HasActiveController()) {
46 return false;
47 }
48 bool res = fbController.GetRefPtr() == activeController_.GetRefPtr();
49 TLOGD(WmsLogTag::WMS_SYSTEM, "res: %{public}u", res);
50 return res;
51 }
52
SetActiveController(const sptr<FloatingBallController> & fbController)53 void FloatingBallManager::SetActiveController(const sptr<FloatingBallController>& fbController)
54 {
55 TLOGD(WmsLogTag::WMS_SYSTEM, "in");
56 activeController_ = fbController;
57 }
58
RemoveActiveController(const wptr<FloatingBallController> & fbController)59 void FloatingBallManager::RemoveActiveController(const wptr<FloatingBallController>& fbController)
60 {
61 TLOGD(WmsLogTag::WMS_SYSTEM, "in");
62 if (HasActiveController() && fbController.GetRefPtr() == activeController_.GetRefPtr()) {
63 activeController_ = nullptr;
64 }
65 }
66
67 // LCOV_EXCL_START
DoActionClick()68 void FloatingBallManager::DoActionClick()
69 {
70 TLOGI(WmsLogTag::WMS_SYSTEM, "click in");
71 if (auto controller = GetActiveController()) {
72 controller->OnFloatingBallClick();
73 }
74 }
75
DoActionClose()76 void FloatingBallManager::DoActionClose()
77 {
78 TLOGI(WmsLogTag::WMS_SYSTEM, "close in");
79 if (auto controller = GetActiveController()) {
80 controller->StopFloatingBall();
81 }
82 }
83
DoDestroy()84 void FloatingBallManager::DoDestroy()
85 {
86 TLOGI(WmsLogTag::WMS_SYSTEM, "in");
87 if (auto controller = GetActiveController()) {
88 controller->DestroyFloatingBallWindow();
89 }
90 }
91
DoFbActionEvent(const std::string & actionName)92 void FloatingBallManager::DoFbActionEvent(const std::string& actionName)
93 {
94 TLOGI(WmsLogTag::WMS_SYSTEM, "in, actionName %{public}s", actionName.c_str());
95 auto func = FB_ACTION_MAP.find(actionName);
96 if (func == FB_ACTION_MAP.end()) {
97 TLOGE(WmsLogTag::WMS_SYSTEM, "no func to process");
98 return;
99 }
100 func->second();
101 }
102
IsSupportFloatingBall()103 bool FloatingBallManager::IsSupportFloatingBall()
104 {
105 return false;
106 }
107 // LCOV_EXCL_STOP
108
109 }
110 }