diff --git a/interfaces/kits/ndk/libwm.ndk.json b/interfaces/kits/ndk/libwm.ndk.json index 5d32531b5815fe6316a25163ee4eb18f0fefd277..ad56fb5abce88e0d87572d19055a54028ad54223 100644 --- a/interfaces/kits/ndk/libwm.ndk.json +++ b/interfaces/kits/ndk/libwm.ndk.json @@ -30,5 +30,45 @@ { "first_instroduced":"16", "name":"OH_WindowManager_IsWindowShown" + }, + { + "first_instroduced":"16", + "name":"OH_WindowManager_SetWindowStatusBarEnabled" + }, + { + "first_instroduced":"16", + "name":"OH_WindowManager_SetWindowStatusBarColor" + }, + { + "first_instroduced":"16", + "name":"OH_WindowManager_SetWindowNavigationBarEnabled" + }, + { + "first_instroduced":"16", + "name":"OH_WindowManager_GetWindowAvoidArea" + }, + { + "first_instroduced":"16", + "name":"OH_WindowManager_SetWindowBackgroundColor" + }, + { + "first_instroduced":"16", + "name":"OH_WindowManager_SetWindowBrightness" + }, + { + "first_instroduced":"16", + "name":"OH_WindowManager_SetWindowKeepScreenOn" + }, + { + "first_instroduced":"16", + "name":"OH_WindowManager_SetWindowPrivacyMode" + }, + { + "first_instroduced":"16", + "name":"OH_WindowManager_GetWindowProperties" + }, + { + "first_instroduced":"16", + "name":"OH_WindowManager_Snapshot" } ] \ No newline at end of file diff --git a/interfaces/kits/ndk/wm/oh_window.h b/interfaces/kits/ndk/wm/oh_window.h index 717f10e2b2a4175d21d96288dddbb8c2e94e7fc9..135953fc5097588285fd5f0773c61a35d12d82af 100644 --- a/interfaces/kits/ndk/wm/oh_window.h +++ b/interfaces/kits/ndk/wm/oh_window.h @@ -33,6 +33,72 @@ extern "C" { #endif +/** + * @brief Set whether to show status bar. + * + * @param windowId WindowId when window is created. + * @param enabled If true, the status bar is displayed. If false, the status bar is hidden. + * @param enableAnimation If true, the status bar is displayed and hidden with animation. + * If false, the status bar is displayed and hidden with no animation. + * @return Return the result code. + * {@link OK} the function call is successful. + * {@link WINDOW_MANAGER_ERRORCODE_INVALID_PARAM} parameter error. + * {@link WINDOW_MANAGER_ERRORCODE_DEVICE_NOT_SUPPORT} capability not supported. + * {@link WINDOW_MANAGER_ERRORCODE_STATE_ABNORMALLY} this window state is abnormal. + * {@link WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMALLY} the window manager service works abnormal. + * @since 16 + */ +int32_t OH_WindowManager_SetWindowStatusBarEnabled(int32_t windowId, bool enabled, bool enableAnimation); + +/** + * @brief Set status bar content color. + * + * @param windowId WindowId when window is created. + * @param color The color value to set, the format is ARGB. + * @return Return the result code. + * {@link OK} the function call is successful. + * {@link WINDOW_MANAGER_ERRORCODE_INVALID_PARAM} parameter error. + * {@link WINDOW_MANAGER_ERRORCODE_DEVICE_NOT_SUPPORT} capability not supported. + * {@link WINDOW_MANAGER_ERRORCODE_STATE_ABNORMALLY} this window state is abnormal. + * {@link WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMALLY} the window manager service works abnormal. + * @since 16 + */ +int32_t OH_WindowManager_SetWindowStatusBarColor(int32_t windowId, int32_t color); + +/** + * @brief Set whether to show navigation bar. + * + * @param windowId WindowId when window is created. + * @param enabled If true, the navigation bar is displayed. If false, the navigation bar is hidden. + * @param enableAnimation If true, the navigation bar is displayed and hidden with animation. + * If false, the navigation bar is displayed and hidden with no animation. + * @return Return the result code. + * {@link OK} the function call is successful. + * {@link WINDOW_MANAGER_ERRORCODE_INVALID_PARAM} parameter error. + * {@link WINDOW_MANAGER_ERRORCODE_DEVICE_NOT_SUPPORT} capability not supported. + * {@link WINDOW_MANAGER_ERRORCODE_STATE_ABNORMALLY} this window state is abnormal. + * {@link WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMALLY} the window manager service works abnormal. + * @since 16 + */ +int32_t OH_WindowManager_SetWindowNavigationBarEnabled(int32_t windowId, bool enabled, bool enableAnimation); + +/** + * @brief Get the avoid area + * + * @param windowId WindowId when window is created. + * @param type Type of the avoid area. + * @param avoidArea Indicates the pointer to a WindowManager_AvoidArea object. + * @return Returns the status code of the execution. + * @return Return the result code. + * {@link OK} the function call is successful, return avoid area ptr in avoidArea. + * {@link WINDOW_MANAGER_ERRORCODE_INVALID_PARAM} parameter error. + * {@link WINDOW_MANAGER_ERRORCODE_STATE_ABNORMALLY} this window state is abnormal. + * {@link WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMALLY} the window manager service works abnormal. + * @since 16 + */ +int32_t OH_WindowManager_GetWindowAvoidArea( + int32_t windowId, WindowManager_AvoidAreaType type, WindowManager_AvoidArea* avoidArea); + /** * @brief Checks whether the window is displayed. * @@ -53,6 +119,90 @@ WindowManager_ErrorCode OH_WindowManager_IsWindowShown(int32_t windowId, bool* i */ WindowManager_ErrorCode OH_WindowManager_ShowWindow(int32_t windowId); +/** + * @brief Sets the background color of window. + * + * @param windowId WindowId when window is created. + * @param color the specified color. + * @return Return the result code. + * {@link OK} the function call is successful. + * {@link WINDOW_MANAGER_ERRORCODE_INVALID_PARAM} parameter error. + * {@link WINDOW_MANAGER_ERRORCODE_STATE_ABNORMALLY} this window state is abnormal. + * @since 16 + */ +int32_t OH_WindowManager_SetWindowBackgroundColor(int32_t windowId, const char* color); + +/** + * @brief Sets the brightness of window. + * + * @param windowId WindowId when window is created. + * @param brightness the specified brightness value. + * @return Return the result code. + * {@link OK} the function call is successful. + * {@link WINDOW_MANAGER_ERRORCODE_INVALID_PARAM} parameter error. + * {@link WINDOW_MANAGER_ERRORCODE_STATE_ABNORMALLY} this window state is abnormal. + * {@link WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMALLY} the window manager service works abnormal. + * @since 16 + */ +int32_t OH_WindowManager_SetWindowBrightness(int32_t windowId, float brightness); + +/** + * @brief Sets whether keep screen on or not. + * + * @param windowId WindowId when window is created. + * @param isKeepScreenOn keep screen on if true, or not if false. + * @return Return the result code. + * {@link OK} the function call is successful. + * {@link WINDOW_MANAGER_ERRORCODE_INVALID_PARAM} parameter error. + * {@link WINDOW_MANAGER_ERRORCODE_STATE_ABNORMALLY} this window state is abnormal. + * {@link WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMALLY} the window manager service works abnormal. + * @since 16 + */ +int32_t OH_WindowManager_SetWindowKeepScreenOn(int32_t windowId, bool isKeepScreenOn); + +/** + * @brief Sets whether is private mode or not. + * + * @param windowId WindowId when window is created. + * @param isPrivacy In private mode if true, or not if false. + * @return Return the result code. + * {@link OK} the function call is successful. + * {@link WINDOW_MANAGER_ERRORCODE_INVALID_PARAM} parameter error. + * {@link WINDOW_MANAGER_ERRORCODE_STATE_ABNORMALLY} this window state is abnormal. + * {@link WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMALLY} the window manager service works abnormal. + * @since 16 + */ +int32_t OH_WindowManager_SetWindowPrivacyMode(int32_t windowId, bool isPrivacy); + +/** + * @brief Get the properties of current window. + * + * @param windowId WindowId when window is created. + * @param windowProperties Properties of current window. + * @return Return the result code. + * {@link OK} the function call is successful, return window properties ptr in windowProperties. + * {@link WINDOW_MANAGER_ERRORCODE_INVALID_PARAM} parameter error. + * {@link WINDOW_MANAGER_ERRORCODE_STATE_ABNORMALLY} this window state is abnormal. + * {@link WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMALLY} the window manager service works abnormal. + * @since 16 + */ +int32_t OH_WindowManager_GetWindowProperties( + int32_t windowId, WindowManager_WindowProperties* windowProperties); + +/** + * @brief Obtains snapshot of window. + * + * @param windowId windowId when window is created. + * @param pixelMap snapshot of window. + * @return Return the result code. + * {@link OK} the function call is successful, return pixel map ptr in pixelMap. + * {@link WINDOW_MANAGER_ERRORCODE_INVALID_PARAM} parameter error. + * {@link WINDOW_MANAGER_ERRORCODE_STATE_ABNORMALLY} this window state is abnormal. + * {@link WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMALLY} the window manager service works abnormal. + * @since 16 + */ +int32_t OH_WindowManager_Snapshot(int32_t windowId, OH_PixelmapNative* pixelMap); + #ifdef __cplusplus } #endif diff --git a/interfaces/kits/ndk/wm/oh_window_comm.h b/interfaces/kits/ndk/wm/oh_window_comm.h index 0c954a946d1aca9f1491d29b26dd4e7506307892..ac529fbc91bd103670d672dd273056192738bd8d 100644 --- a/interfaces/kits/ndk/wm/oh_window_comm.h +++ b/interfaces/kits/ndk/wm/oh_window_comm.h @@ -22,6 +22,13 @@ extern "C" { #endif +/** + * @brief The native pixel map information defined by Image Kit. + * + * @since 16 + */ +struct OH_PixelmapNative; + /** * @brief Enumerates the result types of the wm interface * @@ -30,14 +37,137 @@ extern "C" { typedef enum { /** succ. */ OK = 0, - + /** + * Param is invaild. + * + * @since 16 + */ + WINDOW_MANAGER_ERRORCODE_INVALID_PARAM = 401, + /** + * Device not support. + * + * @since 16 + */ + WINDOW_MANAGER_ERRORCODE_DEVICE_NOT_SUPPORT = 801, /** window id is invaild. */ INVAILD_WINDOW_ID = 1000, /** failed. */ SERVICE_ERROR = 2000, + /** + * Window state is abnormal. + * + * @since 16 + */ + WINDOW_MANAGER_ERRORCODE_STATE_ABNORMALLY = 1300002, + /** + * Window state is abnormal. + * + * @since 16 + */ + WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMALLY = 1300003, } WindowManager_ErrorCode; +/** + * @brief Enumerates the avoid area types. + * + * @since 16 + */ +typedef enum { + /** System. */ + WINDOW_MANAGER_AVOID_AREA_TYPE_SYSTEM = 0, + /** Cutout. */ + WINDOW_MANAGER_AVOID_AREA_TYPE_CUTOUT = 1, + /** System gesture. */ + WINDOW_MANAGER_AVOID_AREA_TYPE_SYSTEM_GESTURE = 2, + /** Keyboard. */ + WINDOW_MANAGER_AVOID_AREA_TYPE_KEYBOARD = 3, + /** Navigation indicator. */ + WINDOW_MANAGER_AVOID_AREA_TYPE_NAVIGATION_INDICATOR = 4, +} WindowManager_AvoidAreaType; + +/** + * @brief The type of a window + * + * @since 16 + */ +typedef enum { + /** Sub window. */ + WINDOW_MANAGER_WINDOW_TYPE_APP = 0, + /** Main Window. */ + WINDOW_MANAGER_WINDOW_TYPE_MAIN = 1, + /** Float. */ + WINDOW_MANAGER_WINDOW_TYPE_FLOAT = 8, + /** Dialog. */ + WINDOW_MANAGER_WINDOW_TYPE_DIALOG = 16, +} WindowManager_WindowType; + +/** + * @brief Defines the window rect data structure. + * + * @since 16 + */ +typedef struct { + /** X-axis of the window. */ + int32_t posX; + /** Y-axis of the window. */ + int32_t posY; + /** Width of the window. */ + uint32_t width; + /** Height of the window. */ + uint32_t height; +} WindowManager_Rect; + +/** + * @brief Properties of window + * + * @since 16 +*/ +typedef struct { + /** The position and size of the window */ + WindowManager_Rect windowRect; + /** The position relative to the window and size of drawable area */ + WindowManager_Rect drawableRect; + /** Window type */ + WindowManager_WindowType type; + /** Whether the window is displayed in full screen mode. The default value is false */ + bool isFullScreen; + /** Whether the window layout is in full screen mode(whether the window is immersive). The default value is false */ + bool isLayoutFullScreen; + /** Whether the window can gain focus. The default value is true */ + bool focusable; + /** Whether the window is touchable. The default value is false */ + bool touchable; + /** Brightness value of window */ + float brightness; + /** Whether keep screen on */ + bool isKeepScreenOn; + /** Whether make window in privacy mode or not */ + bool isPrivacyMode; + /** Whether is transparent or not */ + bool isTransparent; + /** Window id */ + uint32_t id; + /** Display id */ + uint32_t displayId; +} WindowManager_WindowProperties; + +/** + * @brief Defines the avoid area data structure. + * + * @since 16 + */ +typedef struct { + /** Top rect of the avoid area. */ + WindowManager_Rect topRect; + /** Left rect of the avoid area. */ + WindowManager_Rect leftRect; + /** Right rect of the avoid area. */ + WindowManager_Rect rightRect; + /** Bottom rect of the avoid area. */ + WindowManager_Rect bottomRect; +} WindowManager_AvoidArea; + #ifdef __cplusplus } #endif diff --git a/wm/BUILD.gn b/wm/BUILD.gn index 6eaec2cea49b1804bc9fbc2ae4329d2dbb442693..0b047f87f29b2bc3d71472c958db0e39adf421e8 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -433,9 +433,12 @@ ohos_shared_library("libwm_ndk") { innerapi_tags = [ "ndk" ] external_deps = [ + "ace_engine:ace_uicontent", "c_utils:utils", "eventhandler:libeventhandler", + "graphic_2d:librender_service_client", "hilog:libhilog", + "image_framework:pixelmap", "input:libmmi-client", "input:oh_input_manager", "ipc:ipc_core", diff --git a/wm/src/oh_window.cpp b/wm/src/oh_window.cpp index 8090927ed15a280ce51af55895eca806a7173347..e692b0754a66c30d02991badb5c1f264f5312e47 100644 --- a/wm/src/oh_window.cpp +++ b/wm/src/oh_window.cpp @@ -13,18 +13,25 @@ * limitations under the License. */ +#include "oh_window.h" + #include #include #include +#include "image/pixelmap_native.h" +#include "pixelmap_native_impl.h" +#include "ui_content.h" + #include #include -#include "oh_window.h" #include "oh_window_comm.h" #include "window.h" #include "window_manager_hilog.h" #include "wm_common.h" +using namespace OHOS::Rosen; + namespace OHOS { namespace Rosen { namespace { @@ -114,4 +121,320 @@ WindowManager_ErrorCode OH_WindowManager_ShowWindow(int32_t windowId) WindowManager_ErrorCode OH_WindowManager_IsWindowShown(int32_t windowId, bool* isShow) { return OHOS::Rosen::IsWindowShownInner(windowId, isShow); +} + +namespace { +/* + * Used to map from WMError to WindowManager_ErrorCode. + */ +const std::unordered_map OH_WINDOW_TO_ERROR_CODE_MAP { + { WMError::WM_OK, WindowManager_ErrorCode::OK }, + { WMError::WM_ERROR_INVALID_PARAM, WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INVALID_PARAM }, + { WMError::WM_ERROR_DEVICE_NOT_SUPPORT, WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_DEVICE_NOT_SUPPORT }, + { WMError::WM_ERROR_INVALID_WINDOW, WindowManager_ErrorCode::INVAILD_WINDOW_ID }, + { WMError::WM_ERROR_INVALID_CALLING, WindowManager_ErrorCode::SERVICE_ERROR }, + { WMError::WM_ERROR_NULLPTR, WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_STATE_ABNORMALLY }, + { WMError::WM_ERROR_SYSTEM_ABNORMALLY, WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMALLY }, +}; + +/* + * Used to map from WindowType to WindowManager_WindowType. + */ +const std::unordered_map OH_WINDOW_TO_WINDOW_TYPE_MAP { + { WindowType::WINDOW_TYPE_APP_SUB_WINDOW, WindowManager_WindowType::WINDOW_MANAGER_WINDOW_TYPE_APP }, + { WindowType::WINDOW_TYPE_DIALOG, WindowManager_WindowType::WINDOW_MANAGER_WINDOW_TYPE_DIALOG }, + { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowManager_WindowType::WINDOW_MANAGER_WINDOW_TYPE_MAIN }, + { WindowType::WINDOW_TYPE_FLOAT, WindowManager_WindowType::WINDOW_MANAGER_WINDOW_TYPE_FLOAT }, +}; + +void TransformedToWindowManagerRect(const Rect& rect, WindowManager_Rect& wmRect) +{ + wmRect.posX = rect.posX_; + wmRect.posY = rect.posY_; + wmRect.width = rect.width_; + wmRect.height = rect.height_; +} + +void TransformedToWindowManagerAvoidArea(const AvoidArea& allAvoidArea, WindowManager_AvoidArea* avoidArea) +{ + if (avoidArea == nullptr) { + TLOGE(WmsLogTag::WMS_IMMS, "avoidArea is nullptr"); + return; + } + TransformedToWindowManagerRect(allAvoidArea.topRect_, avoidArea->topRect); + TransformedToWindowManagerRect(allAvoidArea.leftRect_, avoidArea->leftRect); + TransformedToWindowManagerRect(allAvoidArea.rightRect_, avoidArea->rightRect); + TransformedToWindowManagerRect(allAvoidArea.bottomRect_, avoidArea->bottomRect); +} +} // namespace + +int32_t OH_WindowManager_GetWindowAvoidArea( + int32_t windowId, WindowManager_AvoidAreaType type, WindowManager_AvoidArea* avoidArea) +{ + if (avoidArea == nullptr) { + TLOGE(WmsLogTag::WMS_IMMS, "avoidArea is null, windowId:%{public}d", windowId); + return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INVALID_PARAM; + } + auto eventHandler = GetMainEventHandler(); + if (eventHandler == nullptr) { + TLOGE(WmsLogTag::WMS_IMMS, "eventHandler null, windowId:%{public}d", windowId); + return WindowManager_ErrorCode::SERVICE_ERROR; + } + WindowManager_ErrorCode errCode = WindowManager_ErrorCode::SERVICE_ERROR; + eventHandler->PostSyncTask([windowId, type, avoidArea, &errCode, where = __func__] { + auto window = Window::GetWindowWithId(windowId); + if (window == nullptr) { + TLOGNE(WmsLogTag::WMS_IMMS, "%{public}s window is null, windowId:%{public}d", where, windowId); + errCode = WindowManager_ErrorCode::INVAILD_WINDOW_ID; + return; + } + AvoidArea allAvoidArea; + errCode = OH_WINDOW_TO_ERROR_CODE_MAP.at( + window->GetAvoidAreaByType(static_cast(type), allAvoidArea)); + TransformedToWindowManagerAvoidArea(allAvoidArea, avoidArea); + }, __func__); + return errCode; +} + +int32_t OH_WindowManager_SetWindowStatusBarEnabled(int32_t windowId, bool enabled, bool enableAnimation) +{ + auto eventHandler = GetMainEventHandler(); + if (eventHandler == nullptr) { + TLOGE(WmsLogTag::WMS_IMMS, "eventHandler null, windowId:%{public}d", windowId); + return WindowManager_ErrorCode::SERVICE_ERROR; + } + WindowManager_ErrorCode errCode = WindowManager_ErrorCode::SERVICE_ERROR; + eventHandler->PostSyncTask([windowId, enabled, enableAnimation, &errCode, where = __func__] { + auto window = Window::GetWindowWithId(windowId); + if (window == nullptr) { + TLOGNE(WmsLogTag::WMS_IMMS, "%{public}s window is null, windowId:%{public}d", where, windowId); + errCode = WindowManager_ErrorCode::INVAILD_WINDOW_ID; + return; + } + if (window->IsPcWindow()) { + TLOGNE(WmsLogTag::WMS_IMMS, "%{public}s device is not support, windowId:%{public}d", where, windowId); + errCode = WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_DEVICE_NOT_SUPPORT; + return; + } + auto property = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR); + property.enable_ = enabled; + property.enableAnimation_ = enableAnimation; + errCode = OH_WINDOW_TO_ERROR_CODE_MAP.at( + window->SetSpecificBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property)); + }, __func__); + return errCode; +} + +int32_t OH_WindowManager_SetWindowStatusBarColor(int32_t windowId, int32_t color) +{ + auto eventHandler = GetMainEventHandler(); + if (eventHandler == nullptr) { + TLOGE(WmsLogTag::WMS_IMMS, "eventHandler null, windowId:%{public}d", windowId); + return WindowManager_ErrorCode::SERVICE_ERROR; + } + WindowManager_ErrorCode errCode = WindowManager_ErrorCode::SERVICE_ERROR; + eventHandler->PostSyncTask([windowId, color, &errCode, where = __func__] { + auto window = Window::GetWindowWithId(windowId); + if (window == nullptr) { + TLOGNE(WmsLogTag::WMS_IMMS, "%{public}s window is null, windowId:%{public}d", where, windowId); + errCode = WindowManager_ErrorCode::INVAILD_WINDOW_ID; + return; + } + if (window->IsPcWindow()) { + TLOGNE(WmsLogTag::WMS_IMMS, "%{public}s device is not support, windowId:%{public}d", where, windowId); + errCode = WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_DEVICE_NOT_SUPPORT; + return; + } + auto property = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR); + property.contentColor_ = color; + errCode = OH_WINDOW_TO_ERROR_CODE_MAP.at( + window->SetSpecificBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property)); + }, __func__); + return errCode; +} + +int32_t OH_WindowManager_SetWindowNavigationBarEnabled(int32_t windowId, bool enabled, bool enableAnimation) +{ + auto eventHandler = GetMainEventHandler(); + if (eventHandler == nullptr) { + TLOGE(WmsLogTag::WMS_IMMS, "eventHandler null, windowId:%{public}d", windowId); + return WindowManager_ErrorCode::SERVICE_ERROR; + } + WindowManager_ErrorCode errCode = WindowManager_ErrorCode::SERVICE_ERROR; + eventHandler->PostSyncTask([windowId, enabled, enableAnimation, &errCode, where = __func__] { + auto window = Window::GetWindowWithId(windowId); + if (window == nullptr) { + TLOGNE(WmsLogTag::WMS_IMMS, "%{public}s window is null, windowId:%{public}d", where, windowId); + errCode = WindowManager_ErrorCode::INVAILD_WINDOW_ID; + return; + } + if (window->IsPcWindow()) { + TLOGNE(WmsLogTag::WMS_IMMS, "%{public}s device is not support, windowId:%{public}d", where, windowId); + errCode = WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_DEVICE_NOT_SUPPORT; + return; + } + auto property = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR); + property.enable_ = enabled; + property.enableAnimation_ = enableAnimation; + errCode = OH_WINDOW_TO_ERROR_CODE_MAP.at( + window->SetSpecificBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR, property)); + }, __func__); + return errCode; +} + +int32_t OH_WindowManager_Snapshot(int32_t windowId, OH_PixelmapNative* pixelMap) +{ + if (pixelMap == nullptr) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "pixelMap is null, windowId:%{public}d", windowId); + return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INVALID_PARAM; + } + auto eventHandler = GetMainEventHandler(); + if (eventHandler == nullptr) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "eventHandler null, windowId:%{public}d", windowId); + return WindowManager_ErrorCode::SERVICE_ERROR; + } + WindowManager_ErrorCode errCode = WindowManager_ErrorCode::SERVICE_ERROR; + eventHandler->PostSyncTask([windowId, pixelMap, &errCode, where = __func__]() mutable { + auto window = Window::GetWindowWithId(windowId); + if (window == nullptr) { + TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "%{public}s window is null, windowId:%{public}d", where, windowId); + errCode = WindowManager_ErrorCode::INVAILD_WINDOW_ID; + return; + } + pixelMap = new OH_PixelmapNative(window->Snapshot()); + }, __func__); + return pixelMap != nullptr ? WindowManager_ErrorCode::OK : errCode; +} + +int32_t OH_WindowManager_SetWindowBackgroundColor(int32_t windowId, const char* color) +{ + if (color == nullptr) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "color is null, windowId:%{public}d", windowId); + return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INVALID_PARAM; + } + auto eventHandler = GetMainEventHandler(); + if (eventHandler == nullptr) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "eventHandler null, windowId:%{public}d", windowId); + return WindowManager_ErrorCode::SERVICE_ERROR; + } + WindowManager_ErrorCode errCode = WindowManager_ErrorCode::SERVICE_ERROR; + eventHandler->PostSyncTask([windowId, color, &errCode, where = __func__] { + auto window = Window::GetWindowWithId(windowId); + if (window == nullptr) { + TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "%{public}s window is null, windowId:%{public}d", where, windowId); + errCode = WindowManager_ErrorCode::INVAILD_WINDOW_ID; + return; + } + errCode = OH_WINDOW_TO_ERROR_CODE_MAP.at(window->SetBackgroundColor(std::string(color))); + }, __func__); + return errCode; +} + +int32_t OH_WindowManager_SetWindowBrightness(int32_t windowId, float brightness) +{ + auto eventHandler = GetMainEventHandler(); + if (eventHandler == nullptr) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "eventHandler null, windowId:%{public}d", windowId); + return WindowManager_ErrorCode::SERVICE_ERROR; + } + WindowManager_ErrorCode errCode = WindowManager_ErrorCode::SERVICE_ERROR; + eventHandler->PostSyncTask([windowId, brightness, &errCode, where = __func__] { + auto window = Window::GetWindowWithId(windowId); + if (window == nullptr) { + TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "%{public}s window is null, windowId:%{public}d", where, windowId); + errCode = WindowManager_ErrorCode::INVAILD_WINDOW_ID; + return; + } + errCode = OH_WINDOW_TO_ERROR_CODE_MAP.at(window->SetBrightness(brightness)); + }, __func__); + return errCode; +} + +int32_t OH_WindowManager_SetWindowKeepScreenOn(int32_t windowId, bool isKeepScreenOn) +{ + auto eventHandler = GetMainEventHandler(); + if (eventHandler == nullptr) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "eventHandler null, windowId:%{public}d", windowId); + return WindowManager_ErrorCode::SERVICE_ERROR; + } + WindowManager_ErrorCode errCode = WindowManager_ErrorCode::SERVICE_ERROR; + eventHandler->PostSyncTask([windowId, isKeepScreenOn, &errCode, where = __func__] { + auto window = Window::GetWindowWithId(windowId); + if (window == nullptr) { + TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "%{public}s window is null, windowId:%{public}d", where, windowId); + errCode = WindowManager_ErrorCode::INVAILD_WINDOW_ID; + return; + } + errCode = OH_WINDOW_TO_ERROR_CODE_MAP.at(window->SetKeepScreenOn(isKeepScreenOn)); + }, __func__); + return errCode; +} + +int32_t OH_WindowManager_SetWindowPrivacyMode(int32_t windowId, bool isPrivacy) +{ + auto eventHandler = GetMainEventHandler(); + if (eventHandler == nullptr) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "eventHandler null, windowId:%{public}d", windowId); + return WindowManager_ErrorCode::SERVICE_ERROR; + } + WindowManager_ErrorCode errCode = WindowManager_ErrorCode::SERVICE_ERROR; + eventHandler->PostSyncTask([windowId, isPrivacy, &errCode, where = __func__] { + auto window = Window::GetWindowWithId(windowId); + if (window == nullptr) { + TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "%{public}s window is null, windowId:%{public}d", where, windowId); + errCode = WindowManager_ErrorCode::INVAILD_WINDOW_ID; + return; + } + errCode = OH_WINDOW_TO_ERROR_CODE_MAP.at(window->SetPrivacyMode(isPrivacy)); + }, __func__); + return errCode; +} + +int32_t OH_WindowManager_GetWindowProperties( + int32_t windowId, WindowManager_WindowProperties* windowProperties) +{ + if (windowProperties == nullptr) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "windowProperties is null, windowId:%{public}d", windowId); + return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INVALID_PARAM; + } + auto eventHandler = GetMainEventHandler(); + if (eventHandler == nullptr) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "eventHandler null, windowId:%{public}d", windowId); + return WindowManager_ErrorCode::SERVICE_ERROR; + } + WindowManager_ErrorCode errCode = WindowManager_ErrorCode::OK; + eventHandler->PostSyncTask([windowId, windowProperties, &errCode, where = __func__] { + auto window = Window::GetWindowWithId(windowId); + if (window == nullptr) { + TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "%{public}s window is null, windowId:%{public}d", where, windowId); + errCode = WindowManager_ErrorCode::INVAILD_WINDOW_ID; + return; + } + if (OH_WINDOW_TO_WINDOW_TYPE_MAP.count(window->GetType()) != 0) { + windowProperties->type = OH_WINDOW_TO_WINDOW_TYPE_MAP.at(window->GetType()); + } else { + windowProperties->type = static_cast(window->GetType()); + } + TransformedToWindowManagerRect(window->GetRect(), windowProperties->windowRect); + windowProperties->isLayoutFullScreen = window->IsLayoutFullScreen(); + windowProperties->isFullScreen = window->IsFullScreen(); + windowProperties->touchable = window->GetTouchable(); + windowProperties->focusable = window->GetFocusable(); + windowProperties->isPrivacyMode = window->IsPrivacyMode(); + windowProperties->isKeepScreenOn = window->IsKeepScreenOn(); + windowProperties->brightness = window->GetBrightness(); + windowProperties->isTransparent = window->IsTransparent(); + windowProperties->id = window->GetWindowId(); + windowProperties->displayId = window->GetDisplayId(); + Rect drawableRect; + auto uicontent = window->GetUIContent(); + if (uicontent == nullptr) { + TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "%{public}s uicontent is null, windowId:%{public}d", where, windowId); + errCode = WindowManager_ErrorCode::SERVICE_ERROR; + return; + } + uicontent->GetAppPaintSize(drawableRect); + TransformedToWindowManagerRect(drawableRect, windowProperties->drawableRect); + }, __func__); + return errCode; } \ No newline at end of file