• 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 #include "accessibility_display_manager.h"
17 #include "accessible_ability_manager_service.h"
18 #include "hilog_wrapper.h"
19 
20 namespace OHOS {
21 namespace Accessibility {
AccessibilityDisplayManager()22 AccessibilityDisplayManager::AccessibilityDisplayManager()
23 {
24 }
25 
~AccessibilityDisplayManager()26 AccessibilityDisplayManager::~AccessibilityDisplayManager()
27 {
28     UnregisterDisplayListener();
29 }
30 
GetDisplay(uint64_t id)31 const sptr<Rosen::Display> AccessibilityDisplayManager::GetDisplay(uint64_t id)
32 {
33     HILOG_DEBUG();
34     return Rosen::DisplayManager::GetInstance().GetDisplayById(id);
35 }
36 
GetDisplays()37 std::vector<sptr<Rosen::Display>> AccessibilityDisplayManager::GetDisplays()
38 {
39     HILOG_DEBUG();
40     return Rosen::DisplayManager::GetInstance().GetAllDisplays();
41 }
42 
GetDefaultDisplay()43 const sptr<Rosen::Display> AccessibilityDisplayManager::GetDefaultDisplay()
44 {
45     HILOG_DEBUG();
46     return Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
47 }
48 
GetDefaultDisplayId()49 uint64_t AccessibilityDisplayManager::GetDefaultDisplayId()
50 {
51     HILOG_DEBUG();
52     return Rosen::DisplayManager::GetInstance().GetDefaultDisplayId();
53 }
54 
RegisterDisplayListener(const std::shared_ptr<AppExecFwk::EventHandler> & handler)55 void AccessibilityDisplayManager::RegisterDisplayListener(
56     const std::shared_ptr<AppExecFwk::EventHandler> &handler)
57 {
58     HILOG_DEBUG();
59     if (listener_) {
60         HILOG_DEBUG("Display listener is already registed!");
61         return;
62     }
63     handler_ = handler;
64     listener_ = new(std::nothrow) DisplayListener();
65     if (!listener_) {
66         HILOG_ERROR("Create display listener fail!");
67         return;
68     }
69     Rosen::DisplayManager::GetInstance().RegisterDisplayListener(listener_);
70 }
71 
UnregisterDisplayListener()72 void AccessibilityDisplayManager::UnregisterDisplayListener()
73 {
74     HILOG_DEBUG();
75     if (listener_) {
76         Rosen::DisplayManager::GetInstance().UnregisterDisplayListener(listener_);
77         listener_ = nullptr;
78         handler_ = nullptr;
79     }
80 }
81 } // namespace Accessibility
82 } // namespace OHOS