1 /*
2  * Copyright (c) 2024 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 #ifndef FOUNDATION_ACE_INTERFACE_UI_SESSION_MANAGER_H
17 #define FOUNDATION_ACE_INTERFACE_UI_SESSION_MANAGER_H
18 #include <cstdint>
19 #include <iremote_object.h>
20 #include <map>
21 #include <mutex>
22 
23 #include "ui_report_stub.h"
24 #include "ui_session_json_util.h"
25 
26 #include "base/utils/macros.h"
27 namespace OHOS::Ace {
28 class ACE_FORCE_EXPORT UiSessionManager {
29 public:
30     using InspectorFunction = std::function<void()>;
31     using NotifyAllWebFunction = std::function<void(bool isRegister)>;
32     /**
33      * @description: Get ui_manager instance,this object process singleton
34      * @return The return value is ui_manager singleton
35      */
36     static UiSessionManager& GetInstance();
37 
38     /**
39      * @description: execute click callback when component click event occurs
40      */
41     void ReportClickEvent(const std::string& data);
42 
43     /**
44      * @description: execute search callback when component search event occurs
45      */
46     void ReportSearchEvent(const std::string& data);
47 
48     /**
49      * @description: execute switch callback when page switch to another page occurs
50      */
51     void ReportRouterChangeEvent(const std::string& data);
52 
53     /**
54      * @description: execute click callback when page some component change occurs
55      */
56     void ReportComponentChangeEvent(const std::string& key, const std::string& value);
57 
58     /**
59      * @description: save report communication stub side
60      * @param reportStub report communication stub side
61      */
62     void SaveReportStub(sptr<IRemoteObject> reportStub, int32_t processId);
63 
64     /**
65      * @description: get current page inspector tree value
66      */
67     void GetInspectorTree();
68     void AddValueForTree(int32_t id, const std::string& value);
69     void WebTaskNumsChange(int32_t num);
70     void ReportInspectorTreeValue(const std::string& value);
71     void SaveInspectorTreeFunction(InspectorFunction&& function);
72     void SaveRegisterForWebFunction(NotifyAllWebFunction&& function);
73     void ReportWebUnfocusEvent(int64_t accessibilityId, const std::string& data);
74     void NotifyAllWebPattern(bool isRegister);
75     void SetClickEventRegistered(bool status);
76     void SetSearchEventRegistered(bool status);
77     void OnRouterChange(const std::string& path, const std::string& event);
78     void SetRouterChangeEventRegistered(bool status);
79     void SetComponentChangeEventRegistered(bool status);
80     bool GetClickEventRegistered();
81     bool GetSearchEventRegistered();
82     bool GetRouterChangeEventRegistered();
83     bool GetComponentChangeEventRegistered();
84     bool GetWebFocusRegistered();
85     void SaveBaseInfo(const std::string& info);
86     void SendBaseInfo(int32_t processId);
87 
88 private:
89     static std::mutex mutex_;
90     std::map<int32_t, sptr<IRemoteObject>> reportObjectMap_;
91     int32_t clickEventRegisterProcesses_ = 0;
92     int32_t searchEventRegisterProcesses_ = 0;
93     int32_t routerChangeEventRegisterProcesses_ = 0;
94     int32_t componentChangeEventRegisterProcesses_ = 0;
95     bool webFocusEventRegistered = false;
96     InspectorFunction inspectorFunction_ = 0;
97     NotifyAllWebFunction notifyWebFunction_ = 0;
98     std::shared_ptr<InspectorJsonValue> jsonValue_ = nullptr;
99     int32_t webTaskNums = 0;
100     std::string baseInfo_;
101 };
102 } // namespace OHOS::Ace
103 #endif // FOUNDATION_ACE_INTERFACE_UI_SESSION_MANAGER_H
104