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 OHOS_ROSEN_SCREEN_SESSION_MANAGER_CLIENT_H 17 #define OHOS_ROSEN_SCREEN_SESSION_MANAGER_CLIENT_H 18 19 #include <map> 20 #include <mutex> 21 22 #include <common/rs_rect.h> 23 24 #include "display_change_listener.h" 25 #include "display_change_info.h" 26 #include "dm_common.h" 27 #include "session/screen/include/screen_session.h" 28 #include "interfaces/include/ws_common.h" 29 #include "wm_single_instance.h" 30 #include "zidl/screen_session_manager_client_stub.h" 31 #include "zidl/screen_session_manager_interface.h" 32 33 namespace OHOS::Rosen { 34 using ScreenInfoChangeClientListener = std::function<void(uint64_t)>; 35 class IScreenConnectionListener { 36 public: 37 virtual void OnScreenConnected(const sptr<ScreenSession>& screenSession) = 0; 38 virtual void OnScreenDisconnected(const sptr<ScreenSession>& screenSession) = 0; 39 }; 40 41 class ScreenSessionManagerClient : public ScreenSessionManagerClientStub { 42 WM_DECLARE_SINGLE_INSTANCE_BASE(ScreenSessionManagerClient) 43 44 public: 45 void RegisterScreenConnectionListener(IScreenConnectionListener* listener); 46 void RegisterDisplayChangeListener(const sptr<IDisplayChangeListener>& listener); 47 48 sptr<ScreenSession> GetScreenSession(ScreenId screenId) const; 49 std::map<ScreenId, ScreenProperty> GetAllScreensProperties() const; 50 FoldDisplayMode GetFoldDisplayMode() const; 51 52 void UpdateScreenRotationProperty(ScreenId screenId, const RRect& bounds, ScreenDirectionInfo directionInfo, 53 ScreenPropertyChangeType screenPropertyChangeType); 54 uint32_t GetCurvedCompressionArea(); 55 ScreenProperty GetPhyScreenProperty(ScreenId screenId); 56 void SetScreenPrivacyState(bool hasPrivate); 57 void SetPrivacyStateByDisplayId(DisplayId id, bool hasPrivate); 58 void SetScreenPrivacyWindowList(DisplayId id, std::vector<std::string> privacyWindowList); 59 void NotifyDisplayChangeInfoChanged(const sptr<DisplayChangeInfo>& info); 60 void OnDisplayStateChanged(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo, 61 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type) override; 62 void OnScreenshot(DisplayId displayId) override; 63 void OnImmersiveStateChanged(bool& immersive) override; 64 void OnGetSurfaceNodeIdsFromMissionIdsChanged(std::vector<uint64_t>& missionIds, 65 std::vector<uint64_t>& surfaceNodeIds, bool isBlackList = false) override; 66 void OnUpdateFoldDisplayMode(FoldDisplayMode displayMode) override; 67 void UpdateAvailableArea(ScreenId screenId, DMRect area); 68 int32_t SetScreenOffDelayTime(int32_t delay); 69 void SetCameraStatus(int32_t cameraStatus, int32_t cameraPosition); 70 void NotifyFoldToExpandCompletion(bool foldToExpand); 71 FoldStatus GetFoldStatus(); 72 std::shared_ptr<Media::PixelMap> GetScreenSnapshot(ScreenId screenId, float scaleX, float scaleY); 73 DeviceScreenConfig GetDeviceScreenConfig(); 74 sptr<ScreenSession> GetScreenSessionById(const ScreenId id); 75 ScreenId GetDefaultScreenId(); 76 bool IsFoldable(); 77 void SetVirtualPixelRatioSystem(ScreenId screenId, float virtualPixelRatio) override; 78 void UpdateDisplayHookInfo(int32_t uid, bool enable, const DMHookInfo& hookInfo); 79 80 void RegisterSwitchingToAnotherUserFunction(std::function<void()>&& func); 81 void SwitchingCurrentUser(); 82 void SwitchUserCallback(std::vector<int32_t> oldScbPids, int32_t currentScbPid) override; 83 84 void OnFoldStatusChangedReportUE(const std::vector<std::string>& screenFoldInfo) override; 85 86 void UpdateDisplayScale(ScreenId id, float scaleX, float scaleY, float pivotX, float pivotY, float translateX, 87 float translateY); 88 protected: 89 ScreenSessionManagerClient() = default; 90 virtual ~ScreenSessionManagerClient() = default; 91 92 private: 93 void ConnectToServer(); 94 bool CheckIfNeedCennectScreen(ScreenId screenId, ScreenId rsId, const std::string& name); 95 void OnScreenConnectionChanged(ScreenId screenId, ScreenEvent screenEvent, 96 ScreenId rsId, const std::string& name) override; 97 void OnPropertyChanged(ScreenId screenId, 98 const ScreenProperty& property, ScreenPropertyChangeReason reason) override; 99 void OnPowerStatusChanged(DisplayPowerEvent event, EventStatus status, 100 PowerStateChangeReason reason) override; 101 void OnSensorRotationChanged(ScreenId screenId, float sensorRotation) override; 102 void OnHoverStatusChanged(ScreenId screenId, int32_t hoverStatus) override; 103 void OnScreenOrientationChanged(ScreenId screenId, float screenOrientation) override; 104 void OnScreenRotationLockedChanged(ScreenId screenId, bool isLocked) override; 105 106 void SetDisplayNodeScreenId(ScreenId screenId, ScreenId displayNodeScreenId) override; 107 void ScreenCaptureNotify(ScreenId mainScreenId, int32_t uid, const std::string& clientName) override; 108 109 mutable std::mutex screenSessionMapMutex_; 110 std::map<ScreenId, sptr<ScreenSession>> screenSessionMap_; 111 std::function<void()> switchingToAnotherUserFunc_ = nullptr; 112 113 sptr<IScreenSessionManager> screenSessionManager_; 114 115 IScreenConnectionListener* screenConnectionListener_; 116 sptr<IDisplayChangeListener> displayChangeListener_; 117 FoldDisplayMode displayMode_ = FoldDisplayMode::UNKNOWN; 118 119 bool hasCheckFoldableStatus_ = false; 120 bool isFoldable_ = false; 121 }; 122 } // namespace OHOS::Rosen 123 124 #endif // OHOS_ROSEN_SCREEN_SESSION_MANAGER_CLIENT_STUB_H 125