1885b47fbSopenharmony_ci/* 2885b47fbSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3885b47fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4885b47fbSopenharmony_ci * you may not use this file except in compliance with the License. 5885b47fbSopenharmony_ci * You may obtain a copy of the License at 6885b47fbSopenharmony_ci * 7885b47fbSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8885b47fbSopenharmony_ci * 9885b47fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10885b47fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11885b47fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12885b47fbSopenharmony_ci * See the License for the specific language governing permissions and 13885b47fbSopenharmony_ci * limitations under the License. 14885b47fbSopenharmony_ci */ 15885b47fbSopenharmony_ci 16885b47fbSopenharmony_ci#include "accessibility_display_manager.h" 17885b47fbSopenharmony_ci#include "accessible_ability_manager_service.h" 18885b47fbSopenharmony_ci#include "hilog_wrapper.h" 19885b47fbSopenharmony_ci 20885b47fbSopenharmony_cinamespace OHOS { 21885b47fbSopenharmony_cinamespace Accessibility { 22885b47fbSopenharmony_ci 23885b47fbSopenharmony_ciconstexpr int32_t DEFAULT_DPI = 540; 24885b47fbSopenharmony_ciconstexpr int32_t DEFAULT_WIDTH = 1260; 25885b47fbSopenharmony_ciconstexpr int32_t DEFAULT_HEIGHT = 2720; 26885b47fbSopenharmony_ci 27885b47fbSopenharmony_ciAccessibilityDisplayManager::AccessibilityDisplayManager() 28885b47fbSopenharmony_ci{ 29885b47fbSopenharmony_ci} 30885b47fbSopenharmony_ci 31885b47fbSopenharmony_ciAccessibilityDisplayManager::~AccessibilityDisplayManager() 32885b47fbSopenharmony_ci{ 33885b47fbSopenharmony_ci UnregisterDisplayListener(); 34885b47fbSopenharmony_ci} 35885b47fbSopenharmony_ci 36885b47fbSopenharmony_ciconst sptr<Rosen::Display> AccessibilityDisplayManager::GetDisplay(uint64_t id) 37885b47fbSopenharmony_ci{ 38885b47fbSopenharmony_ci HILOG_DEBUG(); 39885b47fbSopenharmony_ci return Rosen::DisplayManager::GetInstance().GetDisplayById(id); 40885b47fbSopenharmony_ci} 41885b47fbSopenharmony_ci 42885b47fbSopenharmony_cistd::vector<sptr<Rosen::Display>> AccessibilityDisplayManager::GetDisplays() 43885b47fbSopenharmony_ci{ 44885b47fbSopenharmony_ci HILOG_DEBUG(); 45885b47fbSopenharmony_ci return Rosen::DisplayManager::GetInstance().GetAllDisplays(); 46885b47fbSopenharmony_ci} 47885b47fbSopenharmony_ci 48885b47fbSopenharmony_ciconst sptr<Rosen::Display> AccessibilityDisplayManager::GetDefaultDisplay() 49885b47fbSopenharmony_ci{ 50885b47fbSopenharmony_ci HILOG_DEBUG(); 51885b47fbSopenharmony_ci return Rosen::DisplayManager::GetInstance().GetDefaultDisplay(); 52885b47fbSopenharmony_ci} 53885b47fbSopenharmony_ci 54885b47fbSopenharmony_ciuint64_t AccessibilityDisplayManager::GetDefaultDisplayId() 55885b47fbSopenharmony_ci{ 56885b47fbSopenharmony_ci HILOG_DEBUG(); 57885b47fbSopenharmony_ci return Rosen::DisplayManager::GetInstance().GetDefaultDisplayId(); 58885b47fbSopenharmony_ci} 59885b47fbSopenharmony_ci 60885b47fbSopenharmony_ciint32_t AccessibilityDisplayManager::GetWidth() 61885b47fbSopenharmony_ci{ 62885b47fbSopenharmony_ci HILOG_DEBUG(); 63885b47fbSopenharmony_ci sptr<Rosen::Display> displaySync = GetDefaultDisplaySync(); 64885b47fbSopenharmony_ci if (displaySync == nullptr) { 65885b47fbSopenharmony_ci HILOG_ERROR("default displaySync is null"); 66885b47fbSopenharmony_ci return DEFAULT_WIDTH; 67885b47fbSopenharmony_ci } 68885b47fbSopenharmony_ci 69885b47fbSopenharmony_ci return displaySync->GetWidth(); 70885b47fbSopenharmony_ci} 71885b47fbSopenharmony_ci 72885b47fbSopenharmony_ciint32_t AccessibilityDisplayManager::GetHeight() 73885b47fbSopenharmony_ci{ 74885b47fbSopenharmony_ci HILOG_DEBUG(); 75885b47fbSopenharmony_ci sptr<Rosen::Display> displaySync = GetDefaultDisplaySync(); 76885b47fbSopenharmony_ci if (displaySync == nullptr) { 77885b47fbSopenharmony_ci HILOG_ERROR("default displaySync is null"); 78885b47fbSopenharmony_ci return DEFAULT_HEIGHT; 79885b47fbSopenharmony_ci } 80885b47fbSopenharmony_ci 81885b47fbSopenharmony_ci return displaySync->GetHeight(); 82885b47fbSopenharmony_ci} 83885b47fbSopenharmony_ci 84885b47fbSopenharmony_ciOHOS::Rosen::DisplayOrientation AccessibilityDisplayManager::GetOrientation() 85885b47fbSopenharmony_ci{ 86885b47fbSopenharmony_ci HILOG_DEBUG(); 87885b47fbSopenharmony_ci sptr<Rosen::Display> displaySync = GetDefaultDisplaySync(); 88885b47fbSopenharmony_ci if (displaySync == nullptr) { 89885b47fbSopenharmony_ci HILOG_ERROR("default displaySync is null"); 90885b47fbSopenharmony_ci return OHOS::Rosen::DisplayOrientation::PORTRAIT; 91885b47fbSopenharmony_ci } 92885b47fbSopenharmony_ci 93885b47fbSopenharmony_ci auto displayInfo = displaySync->GetDisplayInfo(); 94885b47fbSopenharmony_ci if (displayInfo == nullptr) { 95885b47fbSopenharmony_ci HILOG_ERROR("default displayInfo is null"); 96885b47fbSopenharmony_ci return OHOS::Rosen::DisplayOrientation::PORTRAIT; 97885b47fbSopenharmony_ci } 98885b47fbSopenharmony_ci 99885b47fbSopenharmony_ci return displayInfo->GetDisplayOrientation(); 100885b47fbSopenharmony_ci} 101885b47fbSopenharmony_ci 102885b47fbSopenharmony_cisptr<Rosen::Display> AccessibilityDisplayManager::GetDefaultDisplaySync() 103885b47fbSopenharmony_ci{ 104885b47fbSopenharmony_ci HILOG_DEBUG(); 105885b47fbSopenharmony_ci return Rosen::DisplayManager::GetInstance().GetDefaultDisplaySync(); 106885b47fbSopenharmony_ci} 107885b47fbSopenharmony_ci 108885b47fbSopenharmony_ciint32_t AccessibilityDisplayManager::GetDefaultDisplayDpi() 109885b47fbSopenharmony_ci{ 110885b47fbSopenharmony_ci HILOG_DEBUG(); 111885b47fbSopenharmony_ci if (GetDefaultDisplay() == nullptr) { 112885b47fbSopenharmony_ci HILOG_ERROR("default display is null"); 113885b47fbSopenharmony_ci return DEFAULT_DPI; 114885b47fbSopenharmony_ci } 115885b47fbSopenharmony_ci 116885b47fbSopenharmony_ci return GetDefaultDisplay()->GetDpi(); 117885b47fbSopenharmony_ci} 118885b47fbSopenharmony_ci 119885b47fbSopenharmony_cibool AccessibilityDisplayManager::IsFoldable() 120885b47fbSopenharmony_ci{ 121885b47fbSopenharmony_ci HILOG_DEBUG(); 122885b47fbSopenharmony_ci return Rosen::DisplayManager::GetInstance().IsFoldable(); 123885b47fbSopenharmony_ci} 124885b47fbSopenharmony_ci 125885b47fbSopenharmony_ciRosen::FoldDisplayMode AccessibilityDisplayManager::GetFoldDisplayMode() 126885b47fbSopenharmony_ci{ 127885b47fbSopenharmony_ci HILOG_DEBUG(); 128885b47fbSopenharmony_ci return Rosen::DisplayManager::GetInstance().GetFoldDisplayMode(); 129885b47fbSopenharmony_ci} 130885b47fbSopenharmony_ci 131885b47fbSopenharmony_ciRosen::FoldStatus AccessibilityDisplayManager::GetFoldStatus() 132885b47fbSopenharmony_ci{ 133885b47fbSopenharmony_ci HILOG_DEBUG(); 134885b47fbSopenharmony_ci return Rosen::DisplayManager::GetInstance().GetFoldStatus(); 135885b47fbSopenharmony_ci} 136885b47fbSopenharmony_ci 137885b47fbSopenharmony_civoid AccessibilityDisplayManager::SetDisplayScale(const uint64_t screenId, 138885b47fbSopenharmony_ci float scaleX, float scaleY, float pivotX, float pivotY) 139885b47fbSopenharmony_ci{ 140885b47fbSopenharmony_ci HILOG_DEBUG("scaleX = %{public}f, scaleY = %{public}f, pivotX = %{public}f, pivotY = %{public}f", 141885b47fbSopenharmony_ci scaleX, scaleY, pivotX, pivotY); 142885b47fbSopenharmony_ci Rosen::DisplayManager::GetInstance().SetDisplayScale(screenId, scaleX, 143885b47fbSopenharmony_ci scaleY, pivotX, pivotY); 144885b47fbSopenharmony_ci} 145885b47fbSopenharmony_ci 146885b47fbSopenharmony_civoid AccessibilityDisplayManager::RegisterDisplayListener( 147885b47fbSopenharmony_ci const std::shared_ptr<AppExecFwk::EventHandler> &handler) 148885b47fbSopenharmony_ci{ 149885b47fbSopenharmony_ci HILOG_DEBUG(); 150885b47fbSopenharmony_ci if (listener_) { 151885b47fbSopenharmony_ci HILOG_DEBUG("Display listener is already registed!"); 152885b47fbSopenharmony_ci return; 153885b47fbSopenharmony_ci } 154885b47fbSopenharmony_ci handler_ = handler; 155885b47fbSopenharmony_ci listener_ = new(std::nothrow) DisplayListener(); 156885b47fbSopenharmony_ci if (!listener_) { 157885b47fbSopenharmony_ci HILOG_ERROR("Create display listener fail!"); 158885b47fbSopenharmony_ci return; 159885b47fbSopenharmony_ci } 160885b47fbSopenharmony_ci Rosen::DisplayManager::GetInstance().RegisterDisplayListener(listener_); 161885b47fbSopenharmony_ci} 162885b47fbSopenharmony_ci 163885b47fbSopenharmony_civoid AccessibilityDisplayManager::UnregisterDisplayListener() 164885b47fbSopenharmony_ci{ 165885b47fbSopenharmony_ci HILOG_DEBUG(); 166885b47fbSopenharmony_ci if (listener_) { 167885b47fbSopenharmony_ci Rosen::DisplayManager::GetInstance().UnregisterDisplayListener(listener_); 168885b47fbSopenharmony_ci listener_ = nullptr; 169885b47fbSopenharmony_ci handler_ = nullptr; 170885b47fbSopenharmony_ci } 171885b47fbSopenharmony_ci} 172885b47fbSopenharmony_ci} // namespace Accessibility 173885b47fbSopenharmony_ci} // namespace OHOS