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_ADAPTER_LITE_H 17 #define FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_LITE_H 18 19 #include <map> 20 #include <mutex> 21 22 #include "display_lite.h" 23 #include "dm_common.h" 24 #include "singleton_delegator.h" 25 #include "display_manager_lite_proxy.h" 26 #include "zidl/display_manager_agent_interface.h" 27 28 namespace OHOS::Rosen { 29 class BaseAdapterLite { 30 public: 31 virtual ~BaseAdapterLite(); 32 virtual DMError RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent, 33 DisplayManagerAgentType type); 34 virtual DMError UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent, 35 DisplayManagerAgentType type); 36 virtual void Clear(); 37 protected: 38 bool InitDMSProxy(); 39 std::recursive_mutex mutex_; 40 sptr<DisplayManagerLiteProxy> displayManagerServiceProxy_ = nullptr; 41 sptr<IRemoteObject::DeathRecipient> dmsDeath_ = nullptr; 42 bool isProxyValid_ { false }; 43 }; 44 45 class DMSDeathRecipientLite : public IRemoteObject::DeathRecipient { 46 public: 47 explicit DMSDeathRecipientLite(BaseAdapterLite& adapter); 48 virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override; 49 private: 50 BaseAdapterLite& adapter_; 51 }; 52 53 class DisplayManagerAdapterLite : public BaseAdapterLite { 54 WM_DECLARE_SINGLE_INSTANCE(DisplayManagerAdapterLite); 55 public: 56 virtual sptr<DisplayInfo> GetDefaultDisplayInfo(); 57 virtual std::vector<DisplayId> GetAllDisplayIds(); 58 virtual bool IsFoldable(); 59 virtual FoldStatus GetFoldStatus(); 60 virtual FoldDisplayMode GetFoldDisplayMode(); 61 virtual void SetFoldDisplayMode(const FoldDisplayMode); 62 virtual sptr<DisplayInfo> GetDisplayInfo(DisplayId displayId); 63 virtual sptr<CutoutInfo> GetCutoutInfo(DisplayId displayId); 64 virtual VirtualScreenFlag GetVirtualScreenFlag(ScreenId screenId); 65 /* 66 * used by powermgr 67 */ 68 virtual bool WakeUpBegin(PowerStateChangeReason reason); 69 virtual bool WakeUpEnd(); 70 virtual bool SuspendBegin(PowerStateChangeReason reason); 71 virtual bool SuspendEnd(); 72 virtual bool SetDisplayState(DisplayState state); 73 virtual DisplayState GetDisplayState(DisplayId displayId); 74 virtual bool TryToCancelScreenOff(); 75 virtual bool SetScreenBrightness(uint64_t screenId, uint32_t level); 76 virtual uint32_t GetScreenBrightness(uint64_t screenId); 77 private: 78 static inline SingletonDelegator<DisplayManagerAdapterLite> delegator; 79 }; 80 81 class ScreenManagerAdapterLite : public BaseAdapterLite { 82 WM_DECLARE_SINGLE_INSTANCE(ScreenManagerAdapterLite); 83 public: 84 /* 85 * used by powermgr 86 */ 87 virtual bool SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason); 88 virtual bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason); 89 virtual ScreenPowerState GetScreenPower(ScreenId dmsScreenId); 90 private: 91 static inline SingletonDelegator<ScreenManagerAdapterLite> delegator; 92 }; 93 94 95 } // namespace OHOS::Rosen 96 #endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_LITE_H 97