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 #ifndef FOUNDATION_DM_DISPLAY_MANAGER_LITE_H 17 #define FOUNDATION_DM_DISPLAY_MANAGER_LITE_H 18 19 #include <vector> 20 #include <mutex> 21 22 #include "display_lite.h" 23 #include "dm_common.h" 24 #include "wm_single_instance.h" 25 #include "display_change_info.h" 26 27 namespace OHOS::Rosen { 28 class DisplayManagerLite { 29 WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerLite); 30 friend class DMSDeathRecipientLite; 31 public: 32 class IDisplayListener : public virtual RefBase { 33 public: 34 /** 35 * @brief Notify when a new display is created. 36 */ 37 virtual void OnCreate(DisplayId) = 0; 38 39 /** 40 * @brief Notify when the display is destroyed. 41 */ 42 virtual void OnDestroy(DisplayId) = 0; 43 44 /** 45 * @brief Notify when the state of a display changes 46 */ 47 virtual void OnChange(DisplayId) = 0; 48 }; 49 50 class IFoldStatusListener : public virtual RefBase { 51 public: 52 /** 53 * @brief Notify listeners when screen fold status changed. 54 * 55 * @param foldStatus Screen foldStatus. 56 */ OnFoldStatusChanged(FoldStatus foldStatus)57 virtual void OnFoldStatusChanged([[maybe_unused]]FoldStatus foldStatus) {} 58 }; 59 60 /** 61 * @brief Resgister a display listener. 62 * 63 * @param listener IDisplayListener. 64 * @return DM_OK means register success, others means register failed. 65 */ 66 DMError RegisterDisplayListener(sptr<IDisplayListener> listener); 67 68 /** 69 * @brief Unregister an existed display listener. 70 * 71 * @param listener IDisplayListener. 72 * @return DM_OK means unregister success, others means unregister failed. 73 */ 74 DMError UnregisterDisplayListener(sptr<IDisplayListener> listener); 75 76 /** 77 * @brief Register a listener for the event of screen fold status changed. 78 * 79 * @param listener IFoldStatusListener. 80 * @return DM_OK means register success, others means register failed. 81 */ 82 DMError RegisterFoldStatusListener(sptr<IFoldStatusListener> listener); 83 84 /** 85 * @brief Unregister an existed listener for the event of screen fold status changed. 86 * 87 * @param listener IFoldStatusListener. 88 * @return DM_OK means unregister success, others means unregister failed. 89 */ 90 DMError UnregisterFoldStatusListener(sptr<IFoldStatusListener> listener); 91 92 /** 93 * @brief Get the default display object. 94 * 95 * @return Default display object. 96 */ 97 sptr<DisplayLite> GetDefaultDisplay(); 98 99 /** 100 * @brief Check whether the device is foldable. 101 * 102 * @return true means the device is foldable. 103 */ 104 bool IsFoldable(); 105 106 /** 107 * @brief Get the current fold status of the foldable device. 108 * 109 * @return fold status of device. 110 */ 111 FoldStatus GetFoldStatus(); 112 113 /** 114 * @brief Get the display mode of the foldable device. 115 * 116 * @return display mode of the foldable device. 117 */ 118 FoldDisplayMode GetFoldDisplayMode(); 119 private: 120 DisplayManagerLite(); 121 ~DisplayManagerLite(); 122 void OnRemoteDied(); 123 124 class Impl; 125 std::recursive_mutex mutex_; 126 bool destroyed_ = false; 127 sptr<Impl> pImpl_; 128 }; 129 } // namespace OHOS::Rosen 130 131 #endif // FOUNDATION_DM_DISPLAY_MANAGER_LITE_H