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_WINDOW_SCENE_SCREEN_SETTING_HELPER_H 17 #define OHOS_ROSEN_WINDOW_SCENE_SCREEN_SETTING_HELPER_H 18 19 #include <cstdint> 20 #include <string> 21 #include <sstream> 22 #include <cinttypes> 23 #include <set> 24 25 #include "screen_edid_parse.h" 26 #include "setting_observer.h" 27 #include "dm_common.h" 28 29 namespace OHOS { 30 namespace Rosen { 31 class ScreenSettingHelper { 32 public: 33 static void RegisterSettingDpiObserver(SettingObserver::UpdateFunc func); 34 static void UnregisterSettingDpiObserver(); 35 static bool GetSettingDpi(uint32_t& dpi, const std::string& key = SETTING_DPI_KEY); 36 static bool SetSettingDefaultDpi(uint32_t& dpi, const std::string& key); 37 static bool GetSettingValue(uint32_t& value, const std::string& key); 38 static bool SetSettingValue(const std::string& key, uint32_t value); 39 static bool GetSettingValue(const std::string& key, std::string& value); 40 static bool SetSettingValue(const std::string& key, const std::string& value); 41 static void RegisterSettingCastObserver(SettingObserver::UpdateFunc func); 42 static void UnregisterSettingCastObserver(); 43 static bool GetSettingCast(bool& enable, const std::string& key = SETTING_CAST_KEY); 44 static void RegisterSettingRotationObserver(SettingObserver::UpdateFunc func); 45 static void UnregisterSettingRotationObserver(); 46 static void SetSettingRotation(int32_t rotation); 47 static void SetSettingRotationScreenId(int32_t screenId); 48 static bool GetSettingRotation(int32_t& rotation, const std::string& key = SETTING_ROTATION_KEY); 49 static bool GetSettingRotationScreenID(int32_t& screenId, const std::string& key = SETTING_ROTATION_SCREEN_ID_KEY); 50 static std::string RemoveInvalidChar(const std::string& input); 51 static bool SplitString(std::vector<std::string>& splitValues, const std::string& input, char delimiter = ','); 52 static bool IsNumber(const std::string& str); 53 static std::map<std::string, MultiScreenInfo> GetMultiScreenInfo(const std::string& key = SETTING_SCREEN_MODE_KEY); 54 static bool GetScreenMode(MultiScreenInfo& info, const std::string& inputString); 55 static bool UpdateScreenMode(MultiScreenInfo& info, uint32_t mode, bool isExternal); 56 static bool GetScreenRelativePosition(MultiScreenInfo& info, const std::string& inputString); 57 static ScreenShape GetScreenShape(ScreenId screenId); 58 static void RegisterSettingHalfScreenObserver(SettingObserver::UpdateFunc func); 59 static void UnregisterSettingHalfScreenObserver(); 60 static bool GetHalfScreenSwitchState(const std::string& key = SETTING_HALF_SCREEN_SWITCH_KEY); 61 static void RegisterSettingscreenSkipProtectedWindowObserver(SettingObserver::UpdateFunc func); 62 static void UnregisterSettingscreenSkipProtectedWindowObserver(); 63 static bool GetSettingscreenSkipProtectedWindow(bool& enable, 64 const std::string& key = SETTING_SCREEN_SHARE_PROTECT_KEY); 65 static void RegisterSettingWireCastObserver(SettingObserver::UpdateFunc func); 66 static void UnregisterSettingWireCastObserver(); 67 68 private: 69 static const constexpr char* SETTING_DPI_KEY {"user_set_dpi_value"}; 70 static const constexpr char* SETTING_CAST_KEY {"huaweicast.data.privacy_projection_state"}; 71 static const constexpr char* SETTING_ROTATION_KEY {"screen_rotation_value"}; 72 static const constexpr char* SETTING_ROTATION_SCREEN_ID_KEY {"screen_rotation_screen_id_value"}; 73 static const constexpr char* SETTING_SCREEN_MODE_KEY {"user_set_screen_mode_edid"}; 74 static const constexpr char* SETTING_HALF_SCREEN_SWITCH_KEY {"half_screen_display"}; 75 static const constexpr char* SETTING_SCREEN_SHARE_PROTECT_KEY {"spamshield_screenshare_protect"}; 76 static sptr<SettingObserver> dpiObserver_; 77 static sptr<SettingObserver> castObserver_; 78 static sptr<SettingObserver> rotationObserver_; 79 static sptr<SettingObserver> halfScreenObserver_; 80 static sptr<SettingObserver> screenSkipProtectedWindowObserver_; 81 static sptr<SettingObserver> wireCastObserver_; 82 }; 83 } // namespace Rosen 84 } // namespace OHOS 85 86 #endif // OHOS_ROSEN_WINDOW_SCENE_SCREEN_SETTING_HELPER_H 87