From e2266251360fbc954e8f7aca1532e413966cc4ef Mon Sep 17 00:00:00 2001 From: lie Date: Tue, 22 Mar 2022 19:55:39 +0800 Subject: [PATCH] fixed 66f3ddb from https://gitee.com/LongLie/third_party_chromium/pulls/13 rm ohos_ndk_aosp of 0004 patch Signed-off-by: lie Change-Id: I300d567e988c16ca7c4ad863dbe96d60df0dc549 --- patch/0004_nweb_cve_bugfix.patch | 23520 ----------------------------- 1 file changed, 23520 deletions(-) diff --git a/patch/0004_nweb_cve_bugfix.patch b/patch/0004_nweb_cve_bugfix.patch index 3e8c591..e85efda 100644 --- a/patch/0004_nweb_cve_bugfix.patch +++ b/patch/0004_nweb_cve_bugfix.patch @@ -6219,23526 +6219,6 @@ index b36b8d9022..82d219d37d 100644 return OK; } -diff --git a/ohos_ndk_aosp/includes/common/graphic_common.h b/ohos_ndk_aosp/includes/common/graphic_common.h -new file mode 100644 -index 0000000000..e6c675222b ---- /dev/null -+++ b/ohos_ndk_aosp/includes/common/graphic_common.h -@@ -0,0 +1,127 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef INTERFACES_INNERKITS_COMMON_GRAPHIC_COMMON_H -+#define INTERFACES_INNERKITS_COMMON_GRAPHIC_COMMON_H -+ -+#ifdef __cplusplus -+#include -+#include -+#include -+#include -+#include -+ -+namespace OHOS { -+#endif -+ -+#include "graphic_common_c.h" -+ -+#ifdef __cplusplus -+static const std::map GSErrorStrs = { -+ {GSERROR_OK, "<200 ok>"}, -+ {GSERROR_INVALID_ARGUMENTS, "<400 invalid arguments>"}, -+ {GSERROR_NO_PERMISSION, "<403 no permission>"}, -+ {GSERROR_CONNOT_CONNECT_SAMGR, "<404 connot connect to samgr>"}, -+ {GSERROR_CONNOT_CONNECT_SERVER, "<404 connot connect to server>"}, -+ {GSERROR_CONNOT_CONNECT_WESTON, "<404 connot connect to weston>"}, -+ {GSERROR_NO_BUFFER, "<406 no buffer>"}, -+ {GSERROR_NO_ENTRY, "<406 no entry>"}, -+ {GSERROR_OUT_OF_RANGE, "<406 out of range>"}, -+ {GSERROR_NO_SCREEN, "<406 no screen>"}, -+ {GSERROR_INVALID_OPERATING, "<412 invalid operating>"}, -+ {GSERROR_NO_CONSUMER, "<412 no consumer>"}, -+ {GSERROR_NOT_INIT, "<412 not init>"}, -+ {GSERROR_TYPE_ERROR, "<412 type error>"}, -+ {GSERROR_API_FAILED, "<500 api call failed>"}, -+ {GSERROR_INTERNEL, "<500 internal error>"}, -+ {GSERROR_NO_MEM, "<500 no memory>"}, -+ {GSERROR_PROXY_NOT_INCLUDE, "<500 proxy not include>"}, -+ {GSERROR_SERVER_ERROR, "<500 server occur error>"}, -+ {GSERROR_ANIMATION_RUNNING, "<500 animation is running>"}, -+ {GSERROR_NOT_IMPLEMENT, "<501 not implement>"}, -+ {GSERROR_NOT_SUPPORT, "<501 not support>"}, -+ {GSERROR_BINDER, "<504 binder occur error>"}, -+}; -+ -+static inline std::string LowErrorStrSpecial(GSError err) -+{ -+ if (err == LOWERROR_INVALID) { -+ char num[] = {err / 0x64 % 0xa, err / 0xa % 0xa, err % 0xa, 0}; // int to string (in 1000) -+ return std::string("with low error <") + num + ">"; -+ } else if (err == LOWERROR_FAILURE) { -+ return "with low error "; -+ } -+ return ""; -+} -+ -+static inline std::string LowErrorStr(GSError lowerr) -+{ -+ std::string lowError = LowErrorStrSpecial(lowerr); -+ if (lowError == "" && lowerr != 0) { -+ char buf[256] = {0}; // 256 mean buffer max length -+ strerror_r(lowerr, buf, sizeof buf); -+ lowError = std::string("with low error <") + buf + ">"; -+ } -+ return lowError; -+} -+ -+static inline std::string GSErrorStr(GSError err) -+{ -+ GSError diff = static_cast(err % LOWERROR_MAX); -+ auto it = GSErrorStrs.find(static_cast(err - diff)); -+ if (it == GSErrorStrs.end()) { -+ return ""; -+ } -+ return it->second + LowErrorStr(diff); -+} -+ -+static inline std::string WMErrorStr(GSError err) -+{ -+ return GSErrorStr(err); -+} -+ -+static inline std::string SurfaceErrorStr(GSError err) -+{ -+ return GSErrorStr(err); -+} -+ -+static inline std::string VsyncErrorStr(GSError err) -+{ -+ return GSErrorStr(err); -+} -+ -+static inline std::ostream &operator <<(std::ostream &os, const GSError &err) -+{ -+ os << GSErrorStr(err); -+ return os; -+} -+ -+static inline bool operator ==(GSError a, GSError b) -+{ -+ return static_cast(a) / LOWERROR_MAX == static_cast(b) / LOWERROR_MAX; -+} -+ -+static inline bool operator !=(GSError a, GSError b) -+{ -+ return static_cast(a) / LOWERROR_MAX != static_cast(b) / LOWERROR_MAX; -+} -+ -+using WMError = GSError; -+using SurfaceError = GSError; -+using VsyncError = GSError; -+} // namespace OHOS -+#endif // __cplusplus -+ -+#endif // INTERFACES_INNERKITS_COMMON_GRAPHIC_COMMON_H -diff --git a/ohos_ndk_aosp/includes/common/graphic_common_c.h b/ohos_ndk_aosp/includes/common/graphic_common_c.h -new file mode 100644 -index 0000000000..4ea8c48fc9 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/common/graphic_common_c.h -@@ -0,0 +1,107 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef INTERFACES_INNERKITS_COMMON_GRAPHIC_COMMON_C_H -+#define INTERFACES_INNERKITS_COMMON_GRAPHIC_COMMON_C_H -+ -+// GraphicStandard Error, number just find fast, it may change -+const int LOWERROR_MAX = 1000; -+const int LOWERROR_FAILURE = 999; -+const int LOWERROR_INVALID = 998; -+enum GSError { -+ GSERROR_OK = 0, -+ -+ // 400 BAD_REQUEST -+ GSERROR_INVALID_ARGUMENTS = 40001000, -+ -+ // 403 FORBIDDEN -+ GSERROR_NO_PERMISSION = 40301000, -+ -+ // 404 NOT_FOUND -+ GSERROR_CONNOT_CONNECT_SAMGR = 40401000, -+ GSERROR_CONNOT_CONNECT_SERVER = 40402000, -+ GSERROR_CONNOT_CONNECT_WESTON = 40403000, -+ -+ // 406 NOT_ACCEPTABLE -+ GSERROR_NO_BUFFER = 40601000, -+ GSERROR_NO_ENTRY = 40602000, -+ GSERROR_OUT_OF_RANGE = 40603000, -+ GSERROR_NO_SCREEN = 40604000, -+ -+ // 412 PRECONDITION_FAILED -+ GSERROR_INVALID_OPERATING = 41201000, -+ GSERROR_NO_CONSUMER = 41202000, -+ GSERROR_NOT_INIT = 41203000, -+ GSERROR_TYPE_ERROR = 41204000, -+ GSERROR_DESTROYED_OBJECT = 41205000, -+ -+ // 500 INTERNAL ERROR -+ GSERROR_API_FAILED = 50001000, -+ GSERROR_INTERNEL = 50002000, -+ GSERROR_NO_MEM = 50003000, -+ GSERROR_PROXY_NOT_INCLUDE = 50004000, -+ GSERROR_SERVER_ERROR = 50005000, -+ GSERROR_ANIMATION_RUNNING = 50006000, -+ -+ // 501 NOT_IMPLEMENTED -+ GSERROR_NOT_IMPLEMENT = 50101000, -+ GSERROR_NOT_SUPPORT = 50102000, -+ -+ // 504 GATEWAY ERROR -+ GSERROR_BINDER = 50401000, -+ -+ WM_OK = GSERROR_OK, -+ WM_ERROR_SAMGR = GSERROR_CONNOT_CONNECT_SAMGR, -+ WM_ERROR_WMS_NOT_FOUND = GSERROR_CONNOT_CONNECT_SERVER, -+ WM_ERROR_NOT_INIT = GSERROR_NOT_INIT, -+ WM_ERROR_API_FAILED = GSERROR_API_FAILED, -+ WM_ERROR_NEW = GSERROR_NO_MEM, -+ WM_ERROR_INNER = GSERROR_INTERNEL, -+ WM_ERROR_NULLPTR = GSERROR_INVALID_ARGUMENTS, -+ WM_ERROR_INVALID_PARAM = GSERROR_INVALID_ARGUMENTS, -+ WM_ERROR_CONNOT_CONNECT_WESTON = GSERROR_CONNOT_CONNECT_WESTON, -+ WM_ERROR_SERVER = GSERROR_SERVER_ERROR, -+ WM_ERROR_NOT_SUPPORT = GSERROR_NOT_SUPPORT, -+ WM_ERROR_DESTROYED_OBJECT = GSERROR_DESTROYED_OBJECT, -+ -+ SURFACE_ERROR_OK = GSERROR_OK, -+ SURFACE_ERROR_ERROR = GSERROR_INTERNEL, -+ SURFACE_ERROR_BINDER_ERROR = GSERROR_BINDER, -+ SURFACE_ERROR_NULLPTR = GSERROR_INVALID_ARGUMENTS, -+ SURFACE_ERROR_NO_ENTRY = GSERROR_NO_ENTRY, -+ SURFACE_ERROR_INVALID_OPERATING = GSERROR_INVALID_OPERATING, -+ SURFACE_ERROR_NO_BUFFER = GSERROR_NO_BUFFER, -+ SURFACE_ERROR_INVALID_PARAM = GSERROR_INVALID_ARGUMENTS, -+ SURFACE_ERROR_INIT = GSERROR_INTERNEL, -+ SURFACE_ERROR_NOMEM = GSERROR_NO_MEM, -+ SURFACE_ERROR_API_FAILED = GSERROR_API_FAILED, -+ SURFACE_ERROR_NOT_SUPPORT = GSERROR_NOT_SUPPORT, -+ SURFACE_ERROR_OUT_OF_RANGE = GSERROR_OUT_OF_RANGE, -+ SURFACE_ERROR_TYPE_ERROR = GSERROR_TYPE_ERROR, -+ SURFACE_ERROR_NO_CONSUMER = GSERROR_NO_CONSUMER, -+ -+ VSYNC_ERROR_OK = GSERROR_OK, -+ VSYNC_ERROR_API_FAILED = GSERROR_API_FAILED, -+ VSYNC_ERROR_INVALID_OPERATING = GSERROR_INVALID_OPERATING, -+ VSYNC_ERROR_NULLPTR = GSERROR_INVALID_ARGUMENTS, -+ VSYNC_ERROR_BINDER_ERROR = GSERROR_BINDER, -+ VSYNC_ERROR_SAMGR = GSERROR_CONNOT_CONNECT_SAMGR, -+ VSYNC_ERROR_SERVICE_NOT_FOUND = GSERROR_SERVER_ERROR, -+ VSYNC_ERROR_PROXY_NOT_INCLUDE = GSERROR_PROXY_NOT_INCLUDE, -+ VSYNC_ERROR_INNER = GSERROR_INTERNEL, -+ VSYNC_ERROR_INVALID_ARGUMENTS = GSERROR_INVALID_ARGUMENTS, -+}; -+ -+#endif // INTERFACES_INNERKITS_COMMON_GRAPHIC_COMMON_H -diff --git a/ohos_ndk_aosp/includes/display/display_device.h b/ohos_ndk_aosp/includes/display/display_device.h -new file mode 100644 -index 0000000000..35f4988588 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/display/display_device.h -@@ -0,0 +1,688 @@ -+/* -+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+/** -+ * @addtogroup Display -+ * @{ -+ * -+ * @brief Defines driver functions of the display module. -+ * -+ * This module provides driver functions for the graphics subsystem, including graphics layer management, -+ * device control, graphics hardware acceleration, display memory management, and callbacks. -+ * @since 1.0 -+ * @version 2.0 -+ */ -+ -+ /** -+ * @file display_device.h -+ * -+ * @brief Declares control functions of the display device. -+ * -+ * @since 1.0 -+ * @version 2.0 -+ */ -+ -+#ifndef DISPLAY_DEVICE_H -+#define DISPLAY_DEVICE_H -+#include "display_type.h" -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+/* * -+ * @brief Called when a hot plug event occurs. -+ * -+ * This callback must be registered by calling RegHotPlugCallback. -+ * -+ * @param devId Indicates the ID of the display device. This ID is generated by the HDI implementation layer and -+ * transferred to the graphics service through the current callback. It identifies the display device to connect. -+ * @param connected Indicates the connection status of the display device. The value true means that the -+ * display device is connected, and false means the opposite. -+ * @param data Indicates the private data carried by the graphics service. This parameter carries the private data -+ * address transferred when RegHotPlugCallback is called. For details, see {@link RegHotPlugCallback}. -+ * -+ * -+ * @since 1.0 -+ * @version 1.0 -+ */ -+typedef void (*HotPlugCallback)(uint32_t devId, bool connected, void *data); -+ -+/* * -+ * @brief Called when a VBLANK event occurs. -+ * -+ * This callback must be registered by calling RegDisplayVBlankCallback. -+ * -+ * @param sequence Indicates the VBLANK sequence, which is an accumulated value. -+ * @param ns Indicates the timestamp (in ns) of the VBLANK event. -+ * @param data Indicates the pointer to the private data carried by the graphics service. This parameter carries -+ * the address passed when RegDisplayVBlankCallback is called. -+ * -+ * @since 1.0 -+ * @version 1.0 -+ */ -+typedef void (*VBlankCallback)(unsigned int sequence, uint64_t ns, void *data); -+ -+/* * -+ * @brief Called when the graphics service needs to refresh data frames. -+ * -+ * This callback must be registered by calling RegDisplayRefreshCallback. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param data Indicates the pointer to the private data carried by the graphics service. This parameter carries -+ * the address passed when RegDisplayRefreshCallback is called. -+ * -+ * @since 1.0 -+ * @version 1.0 -+ */ -+typedef void (*RefreshCallback)(uint32_t devId, void *data); -+ -+/** -+ * @brief Defines pointers to the functions of the display device. -+ */ -+typedef struct { -+ /* * -+ * @brief Registers the callback to be invoked when a hot plug event occurs. -+ * -+ * @param callback Indicates the instance used to notify the graphics service of a hot plug event occurred. -+ * @param data Indicates the pointer to the private data returned to the graphics service in the -+ * HotPlugCallback callback. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*RegHotPlugCallback)(HotPlugCallback callback, void *data); -+ -+ /* * -+ * @brief Registers the callback to be invoked when a VBLANK event occurs. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param callback Indicates the instance used to notify the graphics service of the VBLANK event occurred when -+ * DisplayVsync is enabled. -+ * @param data Indicates the pointer to the private data returned to the graphics service in the -+ * VBlankCallback callback. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*RegDisplayVBlankCallback)(uint32_t devId, VBlankCallback callback, void *data); -+ -+ /* * -+ * @brief Called when the graphics service needs to refresh data frames. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param callback Indicates the instance used to notify the graphics service of the request for refreshing -+ * data frames. -+ * @param data Indicates the pointer to the private data returned to the graphics service in the -+ * RefreshCallback callback. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*RegDisplayRefreshCallback)(uint32_t devId, RefreshCallback callback, void *data); -+ -+ /* * -+ * @brief Obtains the capabilities of a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param info Indicates the pointer to the capabilities supported by the display device. For details, -+ * see {@link DisplayCapability}. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetDisplayCapability)(uint32_t devId, DisplayCapability *info); -+ -+ /* * -+ * @brief Obtains the display modes supported by a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param num Indicates the pointer to the number of modes supported by the display device. -+ * @param modes Indicates the pointer to the information about all modes supported by the display device, -+ * including all supported resolutions and refresh rates. Each mode has an ID, which will be used when -+ * the mode is set or obtained. For details, see {@link DisplayModeInfo}. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetDisplaySupportedModes)(uint32_t devId, uint32_t *num, DisplayModeInfo *modes); -+ -+ /* * -+ * @brief Obtains the current display mode of a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param modeId indicates the pointer to the ID of the current display mode of the device. The display mode ID -+ * is written by this API. -+ * -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetDisplayMode)(uint32_t devId, uint32_t *modeId); -+ -+ /* * -+ * @brief Sets the display mode of a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param modeId Indicates the ID of the display mode. The device is switched to the display mode specified by -+ * this parameter in this interface. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetDisplayMode)(uint32_t devId, uint32_t modeId); -+ -+ /* * -+ * @brief Obtains the power status of a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param status Indicates the pointer to the power status of the device. The status is written by this interface. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetDisplayPowerStatus)(uint32_t devId, DispPowerStatus *status); -+ -+ /* * -+ * @brief Sets the power status of a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param status Indicates the power status to set. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetDisplayPowerStatus)(uint32_t devId, DispPowerStatus status); -+ -+ /* * -+ * @brief Obtains the backlight value of a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param level Indicates the pointer to the backlight value of the device. The backlight value is written -+ * by this interface. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetDisplayBacklight)(uint32_t devId, uint32_t *level); -+ -+ /* * -+ * @brief Sets the backlight value for a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param level Indicates the backlight value to set. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetDisplayBacklight)(uint32_t devId, uint32_t level); -+ -+ /* * -+ * @brief Obtains the property for a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param id Indicates the property ID returned by GetDisplayCapability. -+ * @param level Indicates the pointer to the property corresponding to the property ID. The property value is -+ * written by this interface. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetDisplayProperty)(uint32_t devId, uint32_t id, uint64_t *value); -+ -+ /* * -+ * @brief Sets the property for a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param id Indicates the property ID returned by GetDisplayCapability. -+ * @param value Indicates the property to set. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetDisplayProperty)(uint32_t devId, uint32_t id, uint64_t value); -+ -+ /* * -+ * @brief Prepares for the composition to be performed by a display device. -+ * -+ * Before the composition, the graphics service needs to notify the display device of the preparation to be made -+ * through this interface. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param needFlushFb Indicates the pointer that specifies whether the graphics service needs to reset the display -+ * framebuffer by using SetDisplayClientBuffer before the commit operation. -+ * The value true means that the framebuffer needs to be reset, and false means the opposite. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*PrepareDisplayLayers)(uint32_t devId, bool *needFlushFb); -+ -+ /* * -+ * @brief Obtains the layers whose composition types have changed. -+ * -+ * In the preparation for composition, the display device changes the composition type for each layer based on -+ * the composition capability of the device. This function returns the layers whose composition types have changed. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param num Indicates the pointer to the number of layers whose composition types have changed. -+ * @param Layers Indicates the pointer to the start address of the layer array. -+ * @param Layers Indicates the pointer to the start address of the composition type array. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetDisplayCompChange)(uint32_t devId, uint32_t *num, uint32_t *Layers, int32_t *type); -+ -+ /* * -+ * @brief Sets the cropped region for a display device. -+ * -+ * You can use this interface to set the cropped region of the client buffer of the display device. -+ * The cropped region cannot exceed the size of the client buffer. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param rect Indicates the pointer to the cropped region of the client buffer. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetDisplayClientCrop)(uint32_t devId, IRect *rect); -+ -+ /* * -+ * @brief Sets the display region for a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param rect Indicates the pointer to the display region. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetDisplayClientDestRect)(uint32_t devId, IRect *rect); -+ -+ /* * -+ * @brief Sets the display buffer for a display device. -+ * -+ * The display buffer stores the hardware composition result of the display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param buffer Indicates the pointer to the display buffer. -+ * @param fence Indicates the sync fence that specifies whether the display buffer can be accessed. The display -+ * buffer is created and released by the graphics service. It can be accessed only when the sync fence is in the -+ * signaled state. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetDisplayClientBuffer)(uint32_t devId, const BufferHandle *buffer, int32_t fence); -+ -+ /* * -+ * @brief Sets the dirty region for a display device. -+ * -+ * The dirty region consists of multiple rectangular regions. The rectangular regions can be refreshed based on -+ * the settings. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param num Indicates the number of rectangles. -+ * @param rect Indicates the pointer to the start address of the rectangle array. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetDisplayClientDamage)(uint32_t devId, uint32_t num, IRect *rect); -+ -+ /* * -+ * @brief Enables or disables the vertical sync signal. -+ * -+ * When the vertical sync signal is generated, the VBlankCallback callback registered -+ * by RegDisplayVBlankCallback will be invoked. The vertical sync signal must be enabled when the graphics -+ * service needs to refresh the display, and disabled when display refresh is not required. The display does not -+ * need to refresh when VBlankCallback is invoked and the graphics service composes layers and sends the -+ * composition result to the device for display. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param enabled Specifies whether to enable the vertical sync signal. The value true means to enable the -+ * vertical sync signal, and false means to disable it. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode}otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetDisplayVsyncEnabled)(uint32_t devId, bool enabled); -+ -+ /* * -+ * @brief Obtains the fences of the display layers after the commit operation. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param num Indicates the pointer to the number of layers. -+ * @param layers Indicates the pointer to the start address of the layer array. -+ * @param fences Indicates the pointer to the start address of the fence array. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetDisplayReleaseFence)(uint32_t devId, uint32_t *num, uint32_t *layers, int32_t *fences); -+ -+ /* * -+ * @brief Obtains the color gamuts supported by a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param num Indicates the pointer to the number of color gamuts supported by the display device. -+ * @param gamuts Indicates the pointer to the information about all color gamuts supported by the display device. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetDisplaySupportedColorGamuts)(uint32_t devId, uint32_t *num, ColorGamut *gamuts); -+ -+ /* * -+ * @brief Obtains the color gamut of a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param gamut Indicates the pointer to the color gamut of the device. The color gamut is written -+ * by this interface. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetDisplayColorGamut)(uint32_t devId, ColorGamut *gamut); -+ -+ /* * -+ * @brief Sets the color gamut for a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param gamut Indicates the color gamut to set. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetDisplayColorGamut)(uint32_t devId, ColorGamut gamut); -+ -+ /* * -+ * @brief Obtains the gamut map of a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param gamutMap Indicates the pointer to the gamut map of the device. The gamut map is written -+ * by this interface. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetDisplayGamutMap)(uint32_t devId, GamutMap *gamutMap); -+ -+ /* * -+ * @brief Sets the gamut map for a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param gamutMap Indicates the gamut map to set. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetDisplayGamutMap)(uint32_t devId, GamutMap gamutMap); -+ -+ /* * -+ * @brief Sets a 4x4 color transformation matrix for a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param matrix Indicates the pointer to the 4x4 color transformation matrix to set. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetDisplayColorTransform)(uint32_t devId, const float *matrix); -+ -+ /* * -+ * @brief Obtains the HDR capability of a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param info Indicates the pointer to the HDR capability of the device. The info is written -+ * by this interface. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetHDRCapabilityInfos)(uint32_t devId, HDRCapability *info); -+ -+ /* * -+ * @brief Obtains the HDR metadata keys supported by a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param num Indicates the pointer to the number of metadata keys supported by the display device. -+ * @param keys Indicates the pointer to the information about all HDR metadata keys supported by the display device. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetSupportedMetadataKey)(uint32_t devId, uint32_t *num, HDRMetadataKey *keys); -+ -+ /* * -+ * @brief Commits the request for composition and display. -+ * -+ * If there is a hardware composition layer, the composition is performed and the composition result is sent to -+ * the hardware for display. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param num Indicates the pointer to the number of layers. -+ * @param layers Indicates the pointer to the start address of the layer array. -+ * @param fences Indicates the pointer to the start address of the fence array. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*Commit)(uint32_t devId, int32_t *fence); -+ -+ /* * -+ * @brief Invokes the display device commands. -+ * -+ * This function extends the APIs between the graphics service and implementation layer, eliminating the need -+ * to add new APIs. -+ * -+ * @param devId Indicates the ID of the display device. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*InvokeDisplayCmd)(uint32_t devId, ...); -+ -+ /* * -+ * @brief Creates a virtual display device. -+ * -+ * @param width Indicates the pixel width of the display device. -+ * @param height Indicates the pixel height of the display device. -+ * @param format Indicates the pointer to the pixel format of the display device. -+ * For details, see {@link PixelFormat}. The format can be modified based on hardware requirements and -+ * returned to the graphics service. -+ * @param devId Indicates the pointer to the ID of the virtual display device created. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*CreateVirtualDisplay)(uint32_t width, uint32_t height, int32_t *format, uint32_t *devId); -+ -+ /* * -+ * @brief Destroys a virtual display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*DestroyVirtualDisplay)(uint32_t devId); -+ -+ /* * -+ * @brief Sets the output buffer for a virtual display device. -+ * -+ * This buffer stores the output of the virtual display device. The buffer can be used only after the sync fence -+ * is in the signaled state. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param buffer Indicates the pointer to the output buffer. -+ * @param fence Indicates the sync fence. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetVirtualDisplayBuffer)(uint32_t devId, BufferHandle *buffer, int32_t fence); -+ -+ /* * -+ * @brief Obtains the writeback frame of a display device. -+ * -+ * This function is used to obtain data of the writeback endpoint specified by devId. The data is written -+ * to the specified buffer by this interface. -+ * -+ * @param devId Indicates the ID of the display device. -+ * @param buffer Indicates the pointer to the buffer of the writeback endpoint data. -+ * @param fence Indicates the pointer to the sync fence. When calling this interface, the graphics service needs -+ * to pass the release fence of the buffer to -+ * specify whether data can be written to the buffer. Then, acquire fence of the buffer needs to be written -+ * and sent to the graphics service to specify whether the writeback data has been written to the buffer. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetWriteBackFrame)(uint32_t devId, BufferHandle *buffer, int32_t *fence); -+ -+ /* * -+ * @brief Creates a writeback endpoint for a display device. -+ * -+ * If the number of writeback endpoints exceeds the limit, a failure message will be returned. -+ * -+ * @param devId Indicates the pointer to the ID of the display device. After a writeback endpoint is created, the -+ * device ID of the writeback endpoint is written in this parameter and returned to the graphics service. -+ * @param width Indicates the writeback pixel width. -+ * @param height Indicates the writeback pixel height. -+ * @param format Indicates the pointer to the writeback point data format. For details, see {@link PixelFormat}. -+ * The format can be modified based on hardware requirements and returned to the graphics service. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*CreateWriteBack)(uint32_t *devId, uint32_t width, uint32_t height, int32_t *format); -+ -+ /* * -+ * @brief Destroys the writeback endpoint of a display device. -+ * -+ * @param devId Indicates the ID of the display device. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*DestroyWriteBack)(uint32_t devId); -+} DeviceFuncs; -+ -+/** -+ * @brief Initializes the control functions of a display device. You can apply for resources for -+ * using control functions and then operate the display device by using the control functions. -+ * -+ * @param funcs Indicates the double pointer to the control functions of the display device. The caller obtains -+ * the double pointer to operate the display device. The memory is allocated during initialization, and therefore -+ * the caller does not need to allocate the memory. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * -+ * @since 1.0 -+ * @version 1.0 -+ */ -+int32_t DeviceInitialize(DeviceFuncs **funcs); -+ -+/** -+ * @brief Uninitializes control functions of the display device. The resources used by the control functions will be -+ * released. In other words, the memory allocated during initialization of the control functions will be released. -+ * -+ * @param funcs Indicates the double pointer to the control functions of the display device. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined -+ * in {@link DispErrCode} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+int32_t DeviceUninitialize(DeviceFuncs *funcs); -+ -+#ifdef __cplusplus -+} -+#endif -+#endif -+/* @} */ -diff --git a/ohos_ndk_aosp/includes/display/display_gfx.h b/ohos_ndk_aosp/includes/display/display_gfx.h -new file mode 100644 -index 0000000000..1b9e770fc3 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/display/display_gfx.h -@@ -0,0 +1,196 @@ -+/* -+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+/** -+ * @addtogroup Display -+ * @{ -+ * -+ * @brief Defines driver functions of the display module. -+ * -+ * This module provides driver functions for the graphics subsystem, including graphics layer management, -+ * device control, graphics hardware acceleration, display memory management, and callbacks. -+ * -+ * @since 1.0 -+ * @version 2.0 -+ */ -+ -+/** -+ * @file display_gfx.h -+ * -+ * @brief Declares the driver functions for implementing hardware acceleration. -+ * -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ -+#ifndef DISPLAY_GFX_H -+#define DISPLAY_GFX_H -+#include "display_type.h" -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+/** -+ * @brief Defines pointers to the hardware acceleration driver functions. -+ */ -+typedef struct { -+ /** -+ * @brief Initializes hardware acceleration. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see DeinitGfx -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*InitGfx)(void); -+ -+ /** -+ * @brief Deinitializes hardware acceleration. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see InitGfx -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*DeinitGfx)(void); -+ -+ /** -+ * @brief Fills a rectangle with a given color on the canvas. -+ * -+ * @param surface Indicates the pointer to the canvas. -+ * @param rect Indicates the pointer to the rectangle to fill. -+ * @param color Indicates the color to fill. -+ * @param opt Indicates the pointer to the hardware acceleration option. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*FillRect)(ISurface *surface, IRect *rect, uint32_t color, GfxOpt *opt); -+ -+ /** -+ * @brief Draws a rectangle with a given color on the canvas. -+ * -+ * @param surface Indicates the pointer to the canvas. -+ * @param rect Indicates the pointer to the rectangle to draw. -+ * @param color Indicates the color to draw. -+ * @param opt Indicates the pointer to the hardware acceleration option. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*DrawRectangle)(ISurface *surface, Rectangle *rect, uint32_t color, GfxOpt *opt); -+ -+ /** -+ * @brief Draws a straight line with a given color on the canvas. -+ * -+ * @param surface Indicates the pointer to the canvas. -+ * @param line Indicates the pointer to the line to draw. -+ * @param opt Indicates the pointer to the hardware acceleration option. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*DrawLine)(ISurface *surface, ILine *line, GfxOpt *opt); -+ -+ /** -+ * @brief Draws a circle with a specified center and radius on the canvas using a given color. -+ * -+ * @param surface Indicates the pointer to the canvas. -+ * @param circle Indicates the pointer to the circle to draw. -+ * @param opt Indicates the pointer to the hardware acceleration option. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*DrawCircle)(ISurface *surface, ICircle *circle, GfxOpt *opt); -+ -+ /** -+ * @brief Blits bitmaps. -+ * -+ * During bit blit, color space conversion (CSC), scaling, and rotation can be implemented. -+ * -+ * @param srcSurface Indicates the pointer to the source bitmap. -+ * @param srcRect Indicates the pointer to the rectangle of the source bitmap. -+ * @param dstSurface Indicates the pointer to the destination bitmap. -+ * @param dstRect Indicates the pointer to the rectangle of the destination bitmap. -+ * @param opt Indicates the pointer to the hardware acceleration option. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*Blit)(ISurface *srcSurface, IRect *srcRect, ISurface *dstSurface, IRect *dstRect, GfxOpt *opt); -+ -+ /** -+ * @brief Synchronizes hardware acceleration when it is used to draw and blit bitmaps. -+ * -+ * This function blocks the process until hardware acceleration is complete. -+ * -+ * @param timeOut Indicates the timeout duration for hardware acceleration synchronization. The value 0 -+ * indicates no timeout, so the process waits until hardware acceleration is complete. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*Sync)(int32_t timeOut); -+} GfxFuncs; -+ -+/** -+ * @brief Initializes the hardware acceleration module to obtain the pointer to functions for hardware acceleration -+ * operations. -+ * -+ * @param funcs Indicates the double pointer to functions for hardware acceleration operations. Memory is allocated -+ * automatically when you initiate the hardware acceleration module, so you can simply use the pointer to gain access -+ * to the functions. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+int32_t GfxInitialize(GfxFuncs **funcs); -+ -+/** -+ * @brief Deinitializes the hardware acceleration module to release the pointer to functions for hardware -+ * acceleration operations. -+ * -+ * @param funcs Indicates the pointer to the functions for hardware acceleration operations. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+int32_t GfxUninitialize(GfxFuncs *funcs); -+ -+#ifdef __cplusplus -+} -+#endif -+#endif -+/** @} */ -diff --git a/ohos_ndk_aosp/includes/display/display_gralloc.h b/ohos_ndk_aosp/includes/display/display_gralloc.h -new file mode 100644 -index 0000000000..44617418b4 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/display/display_gralloc.h -@@ -0,0 +1,175 @@ -+/* -+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+/** -+ * @addtogroup Display -+ * @{ -+ * -+ * @brief Defines driver functions of the display module. -+ * -+ * This module provides driver functions for the graphics subsystem, including graphics layer management, -+ * device control, graphics hardware acceleration, display memory management, and callbacks. -+ * @since 1.0 -+ * @version 2.0 -+ */ -+ -+ -+/** -+ * @file display_gralloc.h -+ * -+ * @brief Declares the driver functions for memory. -+ * -+ * @since 1.0 -+ * @version 2.0 -+ */ -+ -+#ifndef DISPLAY_GRALLOC_H -+#define DISPLAY_GRALLOC_H -+#include "display_type.h" -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+/** -+ * @brief Defines pointers to the memory driver functions. -+ */ -+typedef struct { -+ /** -+ * @brief Allocates memory based on the parameters passed by the GUI. -+ * -+ * @param info Indicates the pointer to the description info of the memory to allocate. -+ * -+ * @param handle Indicates the double pointer to the buffer of the memory to allocate. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*AllocMem)(const AllocInfo* info, BufferHandle** handle); -+ -+ /** -+ * @brief Releases memory. -+ * -+ * @param handle Indicates the pointer to the buffer of the memory to release. -+ * -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ void (*FreeMem)(BufferHandle *handle); -+ -+ /** -+ * @brief Maps memory to memory without cache in the process's address space. -+ * -+ * @param handle Indicates the pointer to the buffer of the memory to map. -+ * -+ * @return Returns the pointer to a valid address if the operation is successful; returns NULL otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ void *(*Mmap)(BufferHandle *handle); -+ -+ /** -+ * @brief Maps memory to memory with cache in the process's address space. -+ * -+ * @param handle Indicates the pointer to the buffer of the memory to map. -+ * -+ * @return Returns the pointer to a valid address if the operation is successful; returns NULL otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ void *(*MmapCache)(BufferHandle *handle); -+ -+ /** -+ * @brief Unmaps memory, that is, removes any mappings in the process's address space. -+ * -+ * @param handle Indicates the pointer to the buffer of the memory to unmap. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*Unmap)(BufferHandle *handle); -+ -+ /** -+ * @brief Flushes data from the cache to memory and invalidates the data in the cache. -+ * -+ * @param handle Indicates the pointer to the buffer of the cache to flush. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*FlushCache)(BufferHandle *handle); -+ -+ /** -+ * @brief Flushes data from the cache mapped via {@link Mmap} to memory and invalidates the data in the cache. -+ * -+ * @param handle Indicates the pointer to the buffer of the cache to flush. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*FlushMCache)(BufferHandle *handle); -+ -+ /** -+ * @brief Invalidate the Cache, it will update the cache from memory. -+ * -+ * @param handle Indicates the pointer to the buffer of the cache which will been invalidated -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*InvalidateCache)(BufferHandle* handle); -+} GrallocFuncs; -+ -+/** -+ * @brief Initializes the memory module to obtain the pointer to functions for memory operations. -+ * -+ * @param funcs Indicates the double pointer to functions for memory operations. Memory is allocated automatically when -+ * you initiate the memory module initialization, so you can simply use the pointer to gain access to the functions. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+int32_t GrallocInitialize(GrallocFuncs **funcs); -+ -+/** -+ * @brief Deinitializes the memory module to release the memory allocated to the pointer to functions for memory -+ * operations. -+ * -+ * @param funcs Indicates the pointer to functions for memory operations. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+int32_t GrallocUninitialize(GrallocFuncs *funcs); -+ -+#ifdef __cplusplus -+} -+#endif -+#endif -+/** @} */ -diff --git a/ohos_ndk_aosp/includes/display/display_layer.h b/ohos_ndk_aosp/includes/display/display_layer.h -new file mode 100644 -index 0000000000..8fe2c95df3 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/display/display_layer.h -@@ -0,0 +1,749 @@ -+/* -+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+/** -+ * @addtogroup Display -+ * @{ -+ * -+ * @brief Defines driver functions of the display module. -+ * -+ * This module provides driver functions for the graphics subsystem, including graphics layer management, -+ * device control, graphics hardware acceleration, display memory management, and callbacks. -+ * -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ -+/** -+ * @file display_layer.h -+ * -+ * @brief Declares the driver functions for implementing layer operations. -+ * -+ * @since 1.0 -+ * @version 2.0 -+ */ -+ -+#ifndef DISPLAY_LAYTER_H -+#define DISPLAY_LAYTER_H -+#include "display_type.h" -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+/** -+ * @brief Defines pointers to the layer driver functions. -+ */ -+typedef struct { -+ /** -+ * @brief Initializes a display device. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see DeinitDisplay -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*InitDisplay)(uint32_t devId); -+ -+ /** -+ * @brief Deinitializes a display device. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see InitDisplay -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*DeinitDisplay)(uint32_t devId); -+ -+ /** -+ * @brief Obtains information about a display device. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param dispInfo Indicates the pointer to the display device information obtained. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetDisplayInfo)(uint32_t devId, DisplayInfo *dispInfo); -+ -+ /** -+ * @brief Opens a layer on a specified display device. -+ * -+ * Before using a layer on the GUI, you must open the layer based on the layer information. After the layer is -+ * opened, you can obtain the layer ID and then use other functions based on the layer ID. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerInfo Indicates the pointer to the layer information passed to open a layer, including the layer -+ * type, layer size, and pixel format. -+ * @param layerId Indicates the pointer to the layer ID, which uniquely identifies a layer. The layer ID is returned -+ * to the GUI after the layer is successfully opened. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see CloseLayer -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ -+ int32_t (*CreateLayer)(uint32_t devId, const LayerInfo *layerInfo, uint32_t *layerId); -+ /** -+ * @brief Closes a layer that is no longer required on a specified display device. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see OpenLayer -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*CloseLayer)(uint32_t devId, uint32_t layerId); -+ -+ /** -+ * @brief Sets whether a layer is visible. -+ * -+ * A visible layer is displayed on the screen, whereas an invisible layer is not displayed on the screen. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param visible Indicates the visibility to set for the layer. The value true means to set the layer to be -+ * visible, and false means the opposite. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see GetLayerVisibleState -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetLayerVisible)(uint32_t devId, uint32_t layerId, bool visible); -+ -+ /** -+ * @brief Checks whether a layer is visible. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param visible Indicates the pointer to the obtained layer visibility. The value true indicates that the -+ * layer is visible, and false indicates that the layer is invisible. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see SetLayerVisible -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetLayerVisibleState)(uint32_t devId, uint32_t layerId, bool *visible); -+ -+ /** -+ * @brief Sets the size of a layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param rect Indicates the pointer to the layer size to set, in pixels. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see GetLayerSize -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetLayerSize)(uint32_t devId, uint32_t layerId, IRect *rect); -+ -+ /** -+ * @brief Obtains the size of a layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param rect Indicates the pointer to the obtained layer size. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see SetLayerSize -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetLayerSize)(uint32_t devId, uint32_t layerId, IRect *rect); -+ -+ /** -+ * @brief Sets the rectangular area to crop for a layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param rect Indicates the pointer to the rectangular area to crop. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetLayerCrop)(uint32_t devId, uint32_t layerId, IRect *rect); -+ -+ /** -+ * @brief Sets the z-order for a layer. -+ * -+ * A larger z-order value indicates a higher layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param zorder Indicates the z-order to set. The value is an integer ranging from 0 to 255. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see GetLayerZorder -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetLayerZorder)(uint32_t devId, uint32_t layerId, uint32_t zorder); -+ -+ /** -+ * @brief Obtains the z-order of a layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param zorder Indicates the pointer to the obtained z-order. The value is an integer ranging from 0 to 255. -+ * A larger z-order value indicates a higher layer. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see SetLayerZorder -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetLayerZorder)(uint32_t devId, uint32_t layerId, uint32_t *zorder); -+ -+ /** -+ * @brief Sets layer premultiplication. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param preMul Specifies whether to enable layer premultiplication. The value 1 means to enable layer -+ * premultiplication, and 0 means the opposite. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see GetLayerPreMulti -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetLayerPreMulti)(uint32_t devId, uint32_t layerId, bool preMul); -+ -+ /** -+ * @brief Obtains the premultiplication flag of a layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param preMul Indicates the pointer to the obtained layer premultiplication flag. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see SetLayerPreMulti -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetLayerPreMulti)(uint32_t devId, uint32_t layerId, bool *preMul); -+ -+ /** -+ * @brief Sets the alpha value for a layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param alpha Indicates the pointer to the alpha value to set. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see GetLayerAlpha -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetLayerAlpha)(uint32_t devId, uint32_t layerId, LayerAlpha *alpha); -+ -+ /** -+ * @brief Obtains the alpha value of a layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param alpha Indicates the pointer to the obtained alpha value. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see SetLayerAlpha -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetLayerAlpha)(uint32_t devId, uint32_t layerId, LayerAlpha *alpha); -+ -+ /** -+ * @brief Sets the color key for a layer. The color key is used during layer overlay. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param enable Specify whether to enable the color key. -+ * @param key Indicates the color key. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see GetLayerColorKey -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetLayerColorKey)(uint32_t devId, uint32_t layerId, bool enable, uint32_t key); -+ -+ /** -+ * @brief Obtains the color key of a layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param enable Indicates the pointer to the color key enable bit. -+ * @param key Indicates the pointer to the color key. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see SetLayerColorKey -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetLayerColorKey)(uint32_t devId, uint32_t layerId, bool *enable, uint32_t *key); -+ -+ /** -+ * @brief Sets the palette for a layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param palette Indicates the pointer to the palette to set. -+ * @param len Indicates the length of the palette. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see GetLayerPalette -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetLayerPalette)(uint32_t devId, uint32_t layerId, uint32_t *palette, uint32_t len); -+ -+ /** -+ * @brief Obtains the palette of a layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param palette Indicates the pointer to the obtained palette. -+ * @param len Indicates the length of the palette. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see SetLayerPalette -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetLayerPalette)(uint32_t devId, uint32_t layerId, uint32_t *palette, uint32_t len); -+ -+ /** -+ * @brief Sets the transform mode for rotating, scaling, or moving a layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param type Indicates the transformation mode to set. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetTransformMode)(uint32_t devId, uint32_t layerId, TransformType type); -+ -+ /** -+ * @brief Sets the compression feature for a layer. -+ * -+ * In specific scenarios, images need to be compressed. You can set whether to enable layer compression. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param compType Specifies whether to enable the compression feature. The value true>/b> means to enable -+ * compression, and false> means the opposite. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see GetLayerCompression -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetLayerCompression)(uint32_t devId, uint32_t layerId, int32_t compType); -+ -+ /** -+ * @brief Checks whether the compression feature is enabled for a layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param compType Indicates the pointer to the variable specifying whether the compression feature is enabled. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see SetLayerCompression -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetLayerCompression)(uint32_t devId, uint32_t layerId, int32_t *compType); -+ -+ /** -+ * @brief Sets the flushing area for a layer. -+ * -+ * After the GUI draws an image, you must set the layer flushing area before calling the {@link Flush} function to -+ * flush the screen. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param region Indicates the pointer to the flushing area to set. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetLayerDirtyRegion)(uint32_t devId, uint32_t layerId, IRect *region); -+ -+ /** -+ * @brief Obtains the buffer of a layer. -+ * -+ * After drawing a picture in the buffer, the application calls the {@link Flush} function to display the picture -+ * on the screen. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param buffer Indicates the pointer to the obtained buffer. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see Flush -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetLayerBuffer)(uint32_t devId, uint32_t layerId, LayerBuffer *buffer); -+ -+ /** -+ * @brief Flushes a layer. -+ * -+ * Display data in the buffer is flushed to a specified layer so that the image data is displayed on the screen. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param buffer Indicates the pointer to the buffer in which the display data is to flush. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*Flush)(uint32_t devId, uint32_t layerId, LayerBuffer *buffer); -+ -+ /** -+ * @brief Waits for the arrival of vertical blanking. -+ * -+ * This function blocks the process until vertical blanking arrives, implementing the synchronization between -+ * software and hardware. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param timeOut Indicates the maximum duration that the process waits for the arrival of vertical blanking. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*WaitForVBlank)(uint32_t devId, uint32_t layerId, int32_t timeOut); -+ -+ /** -+ * @brief Implements the snapshot feature. -+ * -+ * This function saves the screenshot of image data on the display device to the buffer for debugging or as -+ * requested by applications. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param buffer Indicates the pointer to the buffer for saving screenshots. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SnapShot)(uint32_t devId, LayerBuffer *buffer); -+ -+ /** -+ * @brief Set the visible region for a layer -+ * -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param num Indiactes the count of rect. the region contains multiple IRect, the num means how much rects in the -+ * region. -+ * @param rect Indiactes the pointer of the rectes. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 2.0 -+ * @version 2.0 -+ */ -+ int32_t (*SetLayerVisibleRegion)(uint32_t devId, uint32_t layerId, uint32_t num, IRect *rect); -+ -+ /** -+ * @brief Set the buffer for a layer. -+ * -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param buffer Indiactes pointer of the buffer handle, the buffer handle should contain all the information of the -+ * buffer which will been used for composition -+ * @param fence Indiactes the fd of a sync file -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 2.0 -+ * @version 2.0 -+ */ -+ int32_t (*SetLayerBuffer)(uint32_t devId, uint32_t layerId, const BufferHandle *buffer, int32_t fence); -+ -+ /** -+ * @brief Extension interface -+ * -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param cmd Indiactes externsion cmd, the implement will use it to identify different intention -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 2.0 -+ * @version 2.0 -+ */ -+ int32_t (*InvokeLayerCmd)(uint32_t devId, uint32_t layerId, uint32_t cmd, ...); -+ -+ /** -+ * @brief set the composition type which the client expect -+ * -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param type Indicates composition type which the client expect, it may be chagne by the implement -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 2.0 -+ * @version 2.0 -+ */ -+ int32_t (*SetLayerCompositionType)(uint32_t devId, uint32_t layerId, CompositionType type); -+ -+ /** -+ * @brief set the blend type -+ * -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param type Indicates blend type -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 2.0 -+ * @version 2.0 -+ */ -+ int32_t (*SetLayerBlendType)(uint32_t devId, uint32_t layerId, BlendType type); -+ -+ /** -+ * @brief Sets a 4x4 color transformation matrix. -+ * -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param matrix Indicates the 4x4 color transformation matrix. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetLayerColorTransform)(uint32_t devId, uint32_t layerId, const float *matrix); -+ -+ /** -+ * @brief Sets a color data space for a layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param colorSpace Indicates the color data space to set. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetLayerColorDataSpace)(uint32_t devId, uint32_t layerId, ColorDataSpace colorSpace); -+ -+ /** -+ * @brief Obtains the color data space of a layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param colorSpace Indicates the pointer to the color data space obtained. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*GetLayerColorDataSpace)(uint32_t devId, uint32_t layerId, ColorDataSpace *colorSpace); -+ -+ /** -+ * @brief Sets metadata for a layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param num Indicates the number of metadata records. -+ * @param metaData Indicates the pointer to the metadata to set. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetLayerMetaData)(uint32_t devId, uint32_t layerId, uint32_t num, const HDRMetaData *metaData); -+ -+ /** -+ * @brief Sets a metadata set for a layer. -+ * -+ * @param devId Indicates the ID of the display device. The value ranges from 0 to 4, where 0 indicates the first -+ * display device, and 4 indicates the last display device. -+ * @param layerId Indicates the layer ID, which uniquely identifies a layer. You can perform operations on the layer -+ * with the specified layer ID. -+ * @param key Indicates the metadata key. -+ * @param num Indicates the number of metadata records. -+ * @param metaData Indicates the pointer to the metadata set of the uint8_t type to set. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ int32_t (*SetLayerMetaDataSet)(uint32_t devId, uint32_t layerId, HDRMetadataKey key, uint32_t num, -+ const uint8_t *metaData); -+} LayerFuncs; -+ -+/** -+ * @brief Initializes the layer to apply for resources used by the layer and obtain the pointer to functions for -+ * layer operations. -+ * -+ * @param funcs Indicates the double pointer to functions for layer operations. Memory is allocated automatically when -+ * you initiate the layer module, so you can simply use the pointer to gain access to the functions. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see LayerUninitialize -+ * @since 1.0 -+ * @version 1.0 -+ */ -+int32_t LayerInitialize(LayerFuncs **funcs); -+ -+/** -+ * @brief Deinitializes the layer module to release the memory allocated to the pointer to functions for -+ * layer operations. -+ * -+ * @param funcs Indicates the pointer to functions for layer operations. -+ * -+ * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} -+ * otherwise. -+ * @see LayerInitialize -+ * @since 1.0 -+ * @version 1.0 -+ */ -+int32_t LayerUninitialize(LayerFuncs *funcs); -+ -+#ifdef __cplusplus -+} -+#endif -+#endif -+/** @} */ -diff --git a/ohos_ndk_aosp/includes/display/display_type.h b/ohos_ndk_aosp/includes/display/display_type.h -new file mode 100644 -index 0000000000..438f1dd2e7 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/display/display_type.h -@@ -0,0 +1,608 @@ -+/* -+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+/** -+ * @addtogroup Display -+ * @{ -+ * -+ * @brief Defines driver functions of the display module. -+ * -+ * This module provides driver functions for the graphics subsystem, including graphics layer management, -+ * device control, graphics hardware acceleration, display memory management, and callbacks. -+ * -+ * @since 1.0 -+ * @version 2.0 -+ */ -+ -+/** -+ * @file display_type.h -+ * -+ * @brief Declares the data types used by the display driver functions. -+ * -+ * @since 1.0 -+ * @version 2.0 -+ */ -+ -+#ifndef DISPLAY_TYPE_H -+#define DISPLAY_TYPE_H -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include "buffer_handle.h" -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+/** -+ * @brief Enumerates return values of the functions. -+ * -+ */ -+typedef enum { -+ DISPLAY_SUCCESS = 0, /**< Success */ -+ DISPLAY_FAILURE = -1, /**< Failure */ -+ DISPLAY_FD_ERR = -2, /**< File handle (FD) error */ -+ DISPLAY_PARAM_ERR = -3, /**< Parameter error */ -+ DISPLAY_NULL_PTR = -4, /**< Null pointer */ -+ DISPLAY_NOT_SUPPORT = -5, /**< Unsupported feature */ -+ DISPLAY_NOMEM = -6, /**< Insufficient memory */ -+ DISPLAY_SYS_BUSY = -7, /**< System busy */ -+ DISPLAY_NOT_PERM = -8 /**< Forbidden operation */ -+} DispErrCode; -+ -+/** -+ * @brief Enumerates layer types. -+ * -+ */ -+typedef enum { -+ LAYER_TYPE_GRAPHIC, /**< Graphic layer */ -+ LAYER_TYPE_OVERLAY, /**< Overlay layer */ -+ LAYER_TYPE_SDIEBAND, /**< Sideband layer */ -+ LAYER_TYPE_CURSOR, /**< Cursor Layer */ -+ LAYER_TYPE_BUTT /**< Empty layer */ -+} LayerType; -+ -+/* * -+ * @brief Defines the buffer usage. -+ * -+ */ -+enum { -+ HBM_USE_CPU_READ = (1 << 0), /**< CPU will read the memory */ -+ HBM_USE_CPU_WRITE = (1 << 1), /**< CPU will write the memory */ -+ HBM_USE_MEM_MMZ = (1 << 2), /**< will use mmz to allocate memory */ -+ HBM_USE_MEM_DMA = (1 << 3), /**< the allocator should support dma buffer */ -+ HBM_USE_MEM_SHARE = (1 << 4), /**< the allocator should support shared memory buffer*/ -+ HBM_USE_MEM_MMZ_CACHE = (1 << 5), /**< will use mmz to allocate memory with cache*/ -+ HBM_USE_MEM_FB = (1 << 6), /**< the buffer allocate for framebuffer */ -+ HBM_USE_ASSIGN_SIZE = (1 << 7), /**< assign memory size from requester */ -+}; -+ -+/** -+ * @brief Enumerates pixel formats. -+ * -+ */ -+typedef enum { -+ PIXEL_FMT_CLUT8 = 0, /**< CLUT8 format */ -+ PIXEL_FMT_CLUT1, /**< CLUT1 format */ -+ PIXEL_FMT_CLUT4, /**< CLUT4 format */ -+ PIXEL_FMT_RGB_565, /**< RGB565 format */ -+ PIXEL_FMT_RGBA_5658, /**< RGBA5658 format */ -+ PIXEL_FMT_RGBX_4444, /**< RGBX4444 format */ -+ PIXEL_FMT_RGBA_4444, /**< RGBA4444 format */ -+ PIXEL_FMT_RGB_444, /**< RGB444 format */ -+ PIXEL_FMT_RGBX_5551, /**< RGBX5551 format */ -+ PIXEL_FMT_RGBA_5551, /**< RGBA5551 format */ -+ PIXEL_FMT_RGB_555, /**< RGB555 format */ -+ PIXEL_FMT_RGBX_8888, /**< RGBX8888 format */ -+ PIXEL_FMT_RGBA_8888, /**< RGBA8888 format */ -+ PIXEL_FMT_RGB_888, /**< RGB888 format */ -+ PIXEL_FMT_BGR_565, /**< BGR565 format */ -+ PIXEL_FMT_BGRX_4444, /**< BGRX4444 format */ -+ PIXEL_FMT_BGRA_4444, /**< BGRA4444 format */ -+ PIXEL_FMT_BGRX_5551, /**< BGRX5551 format */ -+ PIXEL_FMT_BGRA_5551, /**< BGRA5551 format */ -+ PIXEL_FMT_BGRX_8888, /**< BGRX8888 format */ -+ PIXEL_FMT_BGRA_8888, /**< BGRA8888 format */ -+ PIXEL_FMT_YUV_422_I, /**< YUV422 interleaved format */ -+ PIXEL_FMT_YCBCR_422_SP, /**< YCBCR422 semi-planar format */ -+ PIXEL_FMT_YCRCB_422_SP, /**< YCRCB422 semi-planar format */ -+ PIXEL_FMT_YCBCR_420_SP, /**< YCBCR420 semi-planar format */ -+ PIXEL_FMT_YCRCB_420_SP, /**< YCRCB420 semi-planar format */ -+ PIXEL_FMT_YCBCR_422_P, /**< YCBCR422 planar format */ -+ PIXEL_FMT_YCRCB_422_P, /**< YCRCB422 planar format */ -+ PIXEL_FMT_YCBCR_420_P, /**< YCBCR420 planar format */ -+ PIXEL_FMT_YCRCB_420_P, /**< YCRCB420 planar format */ -+ PIXEL_FMT_YUYV_422_PKG, /**< YUYV422 packed format */ -+ PIXEL_FMT_UYVY_422_PKG, /**< UYVY422 packed format */ -+ PIXEL_FMT_YVYU_422_PKG, /**< YVYU422 packed format */ -+ PIXEL_FMT_VYUY_422_PKG, /**< VYUY422 packed format */ -+ PIXEL_FMT_BUTT /**< Invalid pixel format */ -+} PixelFormat; -+ -+/** -+ * @brief Enumerates transform types of images. -+ * -+ */ -+typedef enum { -+ ROTATE_NONE = 0, /**< No rotation */ -+ ROTATE_90, /**< Rotation by 90 degrees */ -+ ROTATE_180, /**< Rotation by 180 degrees */ -+ ROTATE_270, /**< Rotation by 270 degrees */ -+ ROTATE_BUTT /**< Invalid operation */ -+} TransformType; -+ -+/** -+ * @brief Enumerates image blending types. -+ * -+ * The system combines images based on a specified blending type during hardware acceleration. -+ * -+ */ -+typedef enum { -+ BLEND_NONE = 0, /**< No blending */ -+ BLEND_CLEAR, /**< CLEAR blending */ -+ BLEND_SRC, /**< SRC blending */ -+ BLEND_SRCOVER, /**< SRC_OVER blending */ -+ BLEND_DSTOVER, /**< DST_OVER blending */ -+ BLEND_SRCIN, /**< SRC_IN blending */ -+ BLEND_DSTIN, /**< DST_IN blending */ -+ BLEND_SRCOUT, /**< SRC_OUT blending */ -+ BLEND_DSTOUT, /**< DST_OUT blending */ -+ BLEND_SRCATOP, /**< SRC_ATOP blending */ -+ BLEND_DSTATOP, /**< DST_ATOP blending */ -+ BLEND_ADD, /**< ADD blending */ -+ BLEND_XOR, /**< XOR blending */ -+ BLEND_DST, /**< DST blending */ -+ BLEND_AKS, /**< AKS blending */ -+ BLEND_AKD, /**< AKD blending */ -+ BLEND_BUTT /**< Null operation */ -+} BlendType; -+ -+/** -+ * @brief Enumerates ROP types supported by hardware acceleration. -+ * -+ * ROP performs bitwise Boolean operations (including bitwise AND and bitwise OR) on the RGB color and -+ * alpha values of the foreground bitmap with those of the background bitmap, and then outputs the result. -+ * -+ */ -+typedef enum { -+ ROP_BLACK = 0, /**< Blackness */ -+ ROP_NOTMERGEPEN, /**< ~(S2+S1) */ -+ ROP_MASKNOTPEN, /**< ~S2&S1 */ -+ ROP_NOTCOPYPEN, /**< ~S2 */ -+ ROP_MASKPENNOT, /**< S2&~S1 */ -+ ROP_NOT, /**< ~S1 */ -+ ROP_XORPEN, /**< S2^S1 */ -+ ROP_NOTMASKPEN, /**< ~(S2&S1) */ -+ ROP_MASKPEN, /**< S2&S1 */ -+ ROP_NOTXORPEN, /**< ~(S2^S1) */ -+ ROP_NOP, /**< S1 */ -+ ROP_MERGENOTPEN, /**< ~S2+S1 */ -+ ROP_COPYPE, /**< S2 */ -+ ROP_MERGEPENNOT, /**< S2+~S1 */ -+ ROP_MERGEPEN, /**< S2+S1 */ -+ ROP_WHITE, /**< Whiteness */ -+ ROP_BUTT /**< Invalid ROP type */ -+} RopType; -+ -+/** -+ * @brief Enumerates color key types supported by hardware acceleration. -+ * -+ */ -+typedef enum { -+ CKEY_NONE = 0, /**< No color key */ -+ CKEY_SRC, /**< Source color key */ -+ CKEY_DST, /**< Destination color key */ -+ CKEY_BUTT /**< Null operation */ -+} ColorKey; -+ -+/** -+ * @brief Enumerates mirror types supported by hardware acceleration. -+ * -+ */ -+typedef enum { -+ MIRROR_NONE = 0, /**< No mirror */ -+ MIRROR_LR, /**< Left and right mirrors */ -+ MIRROR_TB, /**< Top and bottom mirrors */ -+ MIRROR_BUTT /**< Null operation */ -+} MirrorType; -+ -+/** -+ * @brief Enumerates connection types of hot plugging. -+ * -+ */ -+typedef enum { -+ INVALID = 0, /**< Invalid connection */ -+ CONNECTED, /**< Connected */ -+ DISCONNECTED /**< Disconnected */ -+} Connection; -+ -+/** -+ * @brief Defines display information. -+ * -+ */ -+typedef struct { -+ uint32_t width; /**< Display width */ -+ uint32_t height; /**< Display height */ -+ int32_t rotAngle; /**< Rotation angle of the display */ -+} DisplayInfo; -+ -+/** -+ * @brief Defines layer information. -+ * -+ * LayerInfo must be passed to the {@link OpenLayer} function, which creates a layer based on the layer -+ * information. -+ * -+ */ -+typedef struct { -+ int32_t width; /**< Layer width */ -+ int32_t height; /**< Layer height */ -+ LayerType type; /**< Layer type, which can be a graphic layer, overlay layer, or sideband layer */ -+ int32_t bpp; /**< Number of bits occupied by each pixel */ -+ PixelFormat pixFormat; /**< Pixel format of the layer */ -+} LayerInfo; -+ -+/** -+ * @brief Defines alpha information about a layer. -+ * -+ */ -+typedef struct { -+ bool enGlobalAlpha; /**< Global alpha enable bit */ -+ bool enPixelAlpha; /**< Pixel alpha enable bit */ -+ uint8_t alpha0; /**< Alpha0 value, ranging from 0 to 255 */ -+ uint8_t alpha1; /**< Alpha1 value, ranging from 0 to 255 */ -+ uint8_t gAlpha; /**< Global alpha value, ranging from 0 to 255 */ -+} LayerAlpha; -+ -+ -+/** -+ * @brief Defines buffer data of a layer, including the virtual and physical memory addresses. -+ * -+ */ -+typedef struct { -+ uint64_t phyAddr; /**< Physical memory address */ -+ void *virAddr; /**< Virtual memory address */ -+} BufferData; -+ -+/** -+ * @brief Defines the buffer, which is used to store layer data. -+ * -+ */ -+typedef struct { -+ int32_t fenceId; /**< Fence ID of the buffer */ -+ int32_t width; /**< Buffer width */ -+ int32_t height; /**< Buffer height */ -+ int32_t pitch; /**< Number of bytes from one row of pixels in memory to the next */ -+ PixelFormat pixFormat; /**< Pixel format of the buffer */ -+ BufferData data; /**< Layer buffer data */ -+ BufferHandle* hdl; /**< Layer buffer handle */ -+} LayerBuffer; -+ -+/** -+ * @brief Defines the information about a rectangle. -+ * -+ */ -+typedef struct { -+ int32_t x; /**< Start X coordinate of the rectangle */ -+ int32_t y; /**< Start Y coordinate of the rectangle */ -+ int32_t w; /**< Width of the rectangle */ -+ int32_t h; /**< Height of the rectangle */ -+} IRect; -+ -+/** -+ * @brief Stores surface information for hardware acceleration, such as draw image and bit blit. -+ * -+ */ -+typedef struct { -+ uint64_t phyAddr; /**< Start physical address of an image */ -+ int32_t height; /**< Image height */ -+ int32_t width; /**< Image width */ -+ int32_t stride; /**< Image stride */ -+ PixelFormat enColorFmt; /**< Image format */ -+ bool bYCbCrClut; /**< Whether the color lookup table (CLUT) is in the YCbCr space */ -+ bool bAlphaMax255; /**< Maximum alpha value of an image (255 or 128) */ -+ bool bAlphaExt1555; /**< ARGB1555 alpha extension enable bit */ -+ uint8_t alpha0; /**< Value of alpha0, ranging from 0 to 255 */ -+ uint8_t alpha1; /**< Value of alpha1, ranging from 0 to 255 */ -+ uint64_t cbcrPhyAddr; /**< CbCr physical address */ -+ int32_t cbcrStride; /**< CbCr stride */ -+ uint64_t clutPhyAddr; /**< Start physical address of the CLUT, used for color extension or correction */ -+} ISurface; -+ -+/** -+ * @brief Describes a line to help draw lines in hardware acceleration. -+ * -+ */ -+typedef struct { -+ int32_t x0; /**< X coordinate of the start point of a line */ -+ int32_t y0; /**< Y coordinate of the start point of a line */ -+ int32_t x1; /**< X coordinate of the end point of a line */ -+ int32_t y1; /**< Y coordinate of the end point of a line */ -+ uint32_t color; /**< Line color */ -+} ILine; -+ -+/** -+ * @brief Describes a circle to help draw circles in hardware acceleration. -+ * -+ */ -+typedef struct { -+ int32_t x; /**< X coordinate of a circle center */ -+ int32_t y; /**< Y coordinate of a circle center */ -+ int32_t r; /**< Radius of a circle */ -+ uint32_t color; /**< Circle color */ -+} ICircle; -+ -+/** -+ * @brief Describes a rectangle to help draw rectangles in hardware acceleration. -+ * -+ */ -+typedef struct { -+ IRect rect; /**< Bounds of a rectangle */ -+ uint32_t color; /**< Rectangle color */ -+} Rectangle; -+ -+/** -+ * @brief Defines hardware acceleration options. -+ * -+ */ -+typedef struct { -+ bool enGlobalAlpha; /**< Golbal alpha enable bit */ -+ uint32_t globalAlpha; /**< Global alpha value */ -+ bool enPixelAlpha; /**< Pixel alpha enable bit */ -+ BlendType blendType; /**< Blending type */ -+ ColorKey colorKeyFrom; /**< Color key mode */ -+ bool enableRop; /**< Raster operations pipeline (ROP) enable bit */ -+ RopType colorRopType; /**< Color ROP type */ -+ RopType alphaRopType; /**< Alpha ROP type */ -+ bool enableScale; /**< Scaling enable bit */ -+ TransformType rotateType; /**< Rotation type */ -+ MirrorType mirrorType; /**< Mirror type */ -+} GfxOpt; -+ -+#define PROPERTY_NAME_LEN 50 -+ -+/** -+ * @brief Defines property object which contains name, property id and value. -+ * -+ */ -+typedef struct { -+ char name[PROPERTY_NAME_LEN]; /**< Name of the property */ -+ uint32_t propId; /**< Property id which was decided in the DRM internal */ -+ uint64_t value; /**< the value of property */ -+} PropertyObject; -+ -+/** -+ * @brief Enumerates interface types. -+ * -+ */ -+typedef enum { -+ DISP_INTF_HDMI = 0, /**< HDMI interface */ -+ DISP_INTF_LCD, /**< LCD interface */ -+ DISP_INTF_BT1120, /**< BT1120 interface */ -+ DISP_INTF_BT656, /**< BT656 interface */ -+ DISP_INTF_YPBPR, /**< YPBPR interface */ -+ DISP_INTF_RGB, /**< RGB interface */ -+ DISP_INTF_CVBS, /**< CVBS interface */ -+ DISP_INTF_SVIDEO, /**< SVIDEO interface */ -+ DISP_INTF_VGA, /**< VGA interface */ -+ DISP_INTF_MIPI, /**< MIPI interface */ -+ DISP_INTF_PANEL, /**< PANEL interface */ -+ DISP_INTF_BUTT, -+} InterfaceType; -+ -+/** -+ * @brief Defines the capability of the output. -+ */ -+typedef struct { -+ char name[PROPERTY_NAME_LEN]; /**< name of output */ -+ InterfaceType type; /**< interface type of output */ -+ uint32_t phyWidth; /**< Physical width */ -+ uint32_t phyHeight; /**< Physical width */ -+ uint32_t supportLayers; /**< BitMask of LayerType */ -+ uint32_t virtualDispCount; /**< the count of virtual displays supported*/ -+ bool supportWriteBack; /**< wether support writeback*/ -+ uint32_t propertyCount; /**< Count of properties */ -+ PropertyObject* props; /**< Array of property objects */ -+} DisplayCapability; -+ -+/** -+ * @brief Defines output mode info -+ */ -+typedef struct { -+ int32_t width; /**< width in pixel */ -+ int32_t height; /**< height in pixel */ -+ uint32_t freshRate; /**< fresh rate in one second */ -+ int32_t id; /**< the id of the mode */ -+} DisplayModeInfo; -+ -+/** -+ * @brief Defines information for allocate memory -+ * -+ */ -+typedef struct { -+ uint32_t width; /**< The width of the request allocation */ -+ uint32_t height; /**< The height of the request allocation */ -+ uint64_t usage; /**< The usage of the request allocation */ -+ PixelFormat format; /**< The format of the request allocation */ -+ uint32_t expectedSize; /**< The size assigned by memory requester */ -+} AllocInfo; -+/** -+ * @brief Enumerates power status. -+ */ -+ -+typedef enum { -+ POWER_STATUS_ON, /**< The power status is on */ -+ POWER_STATUS_STANDBY, /**< The power status is standby */ -+ POWER_STATUS_SUSPEND, /**< The power status is suspend */ -+ POWER_STATUS_OFF, /**< The power status is off */ -+ POWER_STATUS_BUTT -+} DispPowerStatus; -+ -+/** -+ * @brief Enumerates composition type for special layer -+ */ -+typedef enum { -+ COMPOSITION_CLIENT, /**< client composistion type, the composer should been cpu or gpu */ -+ COMPOSITION_DEVICE, /**< device composistion type, the composer should been a hardware */ -+ COMPOSITION_CURSOR, /**< cursor composistion type. it should been used for cursor */ -+ COMPOSITION_VIDEO, /**< cursor composistion type. it should been used for video */ -+ COMPOSITION_BUTT -+} CompositionType; -+ -+/** -+ * @brief Enumerates the color gamuts. -+ * -+ */ -+typedef enum { -+ COLOR_GAMUT_INVALID = -1, /**< Invalid */ -+ COLOR_GAMUT_NATIVE = 0, /**< Native or default */ -+ COLOR_GAMUT_SATNDARD_BT601 = 1, /**< Standard BT601 */ -+ COLOR_GAMUT_STANDARD_BT709 = 2, /**< Standard BT709 */ -+ COLOR_GAMUT_DCI_P3 = 3, /**< DCI P3 */ -+ COLOR_GAMUT_SRGB = 4, /**< SRGB */ -+ COLOR_GAMUT_ADOBE_RGB = 5, /**< Adobe RGB */ -+ COLOR_GAMUT_DISPLAY_P3 = 6, /**< display P3 */ -+ COLOR_GAMUT_BT2020 = 7, /**< BT2020 */ -+ COLOR_GAMUT_BT2100_PQ = 8, /**< BT2100 PQ */ -+ COLOR_GAMUT_BT2100_HLG = 9, /**< BT2100 HLG */ -+ COLOR_GAMUT_DISPLAY_BT2020 = 10, /**< Display BT2020 */ -+} ColorGamut; -+ -+/** -+ * @brief Enumerates the color gamut maps. -+ * -+ */ -+typedef enum { -+ GAMUT_MAP_CONSTANT = 0, -+ GAMUT_MAP_EXPANSION = 1, -+ GAMUT_MAP_HDR_CONSTANT = 2, -+ GAMUT_MAP_HDR_EXPANSION = 3, -+} GamutMap; -+ -+/** -+ * @brief Enumerates the color data spaces. -+ * -+ */ -+ -+typedef enum { -+ COLOR_DATA_SPACE_UNKNOWN = 0, -+ GAMUT_BT601 = 0x00000001, -+ GAMUT_BT709 = 0x00000002, -+ GAMUT_DCI_P3 = 0x00000003, -+ GAMUT_SRGB = 0x00000004, -+ GAMUT_ADOBE_RGB = 0x00000005, -+ GAMUT_DISPLAY_P3 = 0x00000006, -+ GAMUT_BT2020 = 0x00000007, -+ GAMUT_BT2100_PQ = 0x00000008, -+ GAMUT_BT2100_HLG = 0x00000009, -+ GAMUT_DISPLAY_BT2020 = 0x0000000a, -+ TRANSFORM_FUNC_UNSPECIFIED = 0x00000100, -+ TRANSFORM_FUNC_LINEAR = 0x00000200, -+ TRANSFORM_FUNC_SRGB = 0x00000300, -+ TRANSFORM_FUNC_SMPTE_170M = 0x00000400, -+ TRANSFORM_FUNC_GM2_2 = 0x00000500, -+ TRANSFORM_FUNC_GM2_6 = 0x00000600, -+ TRANSFORM_FUNC_GM2_8 = 0x00000700, -+ TRANSFORM_FUNC_ST2084 = 0x00000800, -+ TRANSFORM_FUNC_HLG = 0x00000900, -+ PRECISION_UNSPECIFIED = 0x00010000, -+ PRECISION_FULL = 0x00020000, -+ PRESION_LIMITED = 0x00030000, -+ PRESION_EXTENDED = 0x00040000, -+ BT601_SMPTE170M_FULL = GAMUT_BT601 | TRANSFORM_FUNC_SMPTE_170M | PRECISION_FULL, -+ BT601_SMPTE170M_LIMITED = GAMUT_BT601 | TRANSFORM_FUNC_SMPTE_170M | PRESION_LIMITED, -+ BT709_LINEAR_FULL = GAMUT_BT709 | TRANSFORM_FUNC_LINEAR | PRECISION_FULL, -+ BT709_LINEAR_EXTENDED = GAMUT_BT709 | TRANSFORM_FUNC_LINEAR | PRESION_EXTENDED, -+ BT709_SRGB_FULL = GAMUT_BT709 | TRANSFORM_FUNC_SRGB | PRECISION_FULL, -+ BT709_SRGB_EXTENDED = GAMUT_BT709 | TRANSFORM_FUNC_SRGB | PRESION_EXTENDED, -+ BT709_SMPTE170M_LIMITED = GAMUT_BT709 | TRANSFORM_FUNC_SMPTE_170M | PRESION_LIMITED, -+ DCI_P3_LINEAR_FULL = GAMUT_DCI_P3 | TRANSFORM_FUNC_LINEAR | PRECISION_FULL, -+ DCI_P3_GAMMA26_FULL = GAMUT_DCI_P3 | TRANSFORM_FUNC_GM2_6 | PRECISION_FULL, -+ DISPLAY_P3_LINEAR_FULL = GAMUT_DISPLAY_P3 | TRANSFORM_FUNC_LINEAR | PRECISION_FULL, -+ DCI_P3_SRGB_FULL = GAMUT_DCI_P3 | TRANSFORM_FUNC_SRGB | PRECISION_FULL, -+ ADOBE_RGB_GAMMA22_FULL = GAMUT_ADOBE_RGB | TRANSFORM_FUNC_GM2_2 | PRECISION_FULL, -+ BT2020_LINEAR_FULL = GAMUT_BT2020 | TRANSFORM_FUNC_LINEAR | PRECISION_FULL, -+ BT2020_SRGB_FULL = GAMUT_BT2020 | TRANSFORM_FUNC_SRGB | PRECISION_FULL, -+ BT2020_SMPTE170M_FULL = GAMUT_BT2020 | TRANSFORM_FUNC_SMPTE_170M | PRECISION_FULL, -+ BT2020_ST2084_FULL = GAMUT_BT2020 | TRANSFORM_FUNC_ST2084 | PRECISION_FULL, -+ BT2020_HLG_FULL = GAMUT_BT2020 | TRANSFORM_FUNC_HLG | PRECISION_FULL, -+ BT2020_ST2084_LIMITED = GAMUT_BT2020 | TRANSFORM_FUNC_ST2084 | PRESION_LIMITED, -+} ColorDataSpace; -+ -+/** -+ * @brief Enumerates the HDR formats. -+ * -+ */ -+typedef enum { -+ NOT_SUPPORT_HDR = 0, -+ DOLBY_VISION = 1, -+ HDR10 = 2, -+ HLG = 3, -+ HDR10_PLUS = 4, -+ HDR_VIVID = 5, -+} HDRFormat; -+ -+/** -+ * @brief Defines the HDR capability. -+ * -+ */ -+typedef struct { -+ uint32_t formatCount; -+ HDRFormat* formats; -+ float maxLum; -+ float maxAverageLum; -+ float minLum; -+} HDRCapability; -+ -+/** -+ * @brief Enumerates the HDR metadata keys. -+ * -+ */ -+typedef enum { -+ MATAKEY_RED_PRIMARY_X = 0, -+ MATAKEY_RED_PRIMARY_Y = 1, -+ MATAKEY_GREEN_PRIMARY_X = 2, -+ MATAKEY_GREEN_PRIMARY_Y = 3, -+ MATAKEY_BLUE_PRIMARY_X = 4, -+ MATAKEY_BLUE_PRIMARY_Y = 5, -+ MATAKEY_WHITE_PRIMARY_X = 6, -+ MATAKEY_WHITE_PRIMARY_Y = 7, -+ MATAKEY_MAX_LUMINANCE = 8, -+ MATAKEY_MIN_LUMINANCE = 9, -+ MATAKEY_MAX_CONTENT_LIGHT_LEVEL = 10, -+ MATAKEY_MAX_FRAME_AVERAGE_LIGHT_LEVEL = 11, -+ MATAKEY_HDR10_PLUS = 12, -+ MATAKEY_HDR_VIVID = 13, -+} HDRMetadataKey; -+ -+/** -+ * @brief Defines the HDR metadata. -+ * -+ */ -+typedef struct { -+ HDRMetadataKey key; -+ float value; -+} HDRMetaData; -+ -+#ifdef __cplusplus -+} -+#endif -+#endif -+/* @} */ -diff --git a/ohos_ndk_aosp/includes/display/display_vgu.h b/ohos_ndk_aosp/includes/display/display_vgu.h -new file mode 100644 -index 0000000000..6214bfaa1a ---- /dev/null -+++ b/ohos_ndk_aosp/includes/display/display_vgu.h -@@ -0,0 +1,769 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+/* * -+ * @addtogroup Display -+ * @{ -+ * -+ * @brief Defines driver functions of the display module. -+ * -+ * This module provides driver functions for the graphics subsystem, including graphics layer management, -+ * device control, graphics hardware acceleration, display memory management, and callbacks. -+ * -+ * @since 3.0 -+ */ -+ -+/* * -+ * @file display_vgu.h -+ * -+ * @brief Declares the driver functions for implementing 2D vector hardware acceleration. -+ * -+ * @since 3.0 -+ */ -+ -+#ifndef DISPLAY_VGU_H -+#define DISPLAY_VGU_H -+#include "display_type.h" -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+#undef HDI_VGU_SCALAR_IS_FLOAT -+#define HDI_VGU_SCALAR_IS_FLOAT 1 -+ -+#ifdef HDI_VGU_SCALAR_IS_FLOAT -+typedef float VGUScalar; -+#else -+typedef int32_t VGUScalar; -+#endif -+ -+typedef PixelFormat VGUPixelFormat; /* < Pixel formats */ -+typedef BlendType VGUBlendType; /* < Blend types supported by hardware acceleration */ -+ -+/* * -+ * @brief Enumerates data types of paths. -+ * -+ */ -+typedef enum { -+ VGU_DATA_TYPE_S16 = 0, /* < Integer (2 bytes) */ -+ VGU_DATA_TYPE_S32, /* < Integer (4 bytes) */ -+ VGU_DATA_TYPE_F32 /* < Floating point number (4 bytes) */ -+} VGUPathDataType; -+ -+/* * -+ * @brief Enumerates supported hardware acceleration capabilities. -+ * -+ */ -+typedef enum { -+ VGU_CAP_BLIT = (1 << 0), /* < Bit blit */ -+ VGU_CAP_BLIT_NUM = (1 << 1), /* < Maximum number of images that can be combined during bit blit */ -+ VGU_CAP_PATH = (1 << 2), /* < Path filling and stroking */ -+ VGU_CAP_FILTER_BLUR = (1 << 3), /* < Blur filter */ -+} VGUCapability; -+ -+/* * -+ * @brief Enumerates result codes that may return. -+ * -+ */ -+typedef enum { -+ VGU_SUCCESS = 0, /* < The operation is successful. */ -+ VGU_NO_SUPPORT = -1, /* < This feature is not supported. */ -+ VGU_OPERATION_FAILED = -2, /* < The operation failed. */ -+ VGU_OUT_OF_MEMORY = -3, /* < The operation ran out of memory. */ -+ VGU_TIMEOUT = -4, /* < The operation times out. */ -+ VGU_INVALID_PARAMETER = -5, /* < One or more parameters are invalid. */ -+ VGU_BUSY = -6, /* < The device is busy. */ -+ VGU_NO_CONTEXT = -7, /* < There is no context specified. */ -+} VGUResult; -+ -+/* * -+ * @brief Enumerates styles for the endpoints of a stroked line. -+ * -+ */ -+typedef enum { -+ VGU_LINECAP_BUTT = 0, /* < A line with a squared-off end (default value) */ -+ VGU_LINECAP_ROUND, /* < A line with a rounded end */ -+ VGU_LINECAP_SQUARE /* < A line with a squared-off end */ -+} VGULineCap; -+ -+/* * -+ * @brief Enumerates join types for stroked lines. -+ * -+ */ -+typedef enum { -+ VGU_LINE_JOIN_MITER = 0, /* < A join with a sharp corner (default value) */ -+ VGU_LINE_JOIN_ROUND, /* < A join with a rounded end */ -+ VGU_LINE_JOIN_BEVEL, /* < A join with a squared-off end */ -+ VGU_LINE_JOIN_BUTT /* < Invalid definition */ -+} VGUJointType; -+ -+/* * -+ * @brief Defines the coordinates of a point. -+ * -+ */ -+typedef struct { -+ VGUScalar x; /* < Horizontal coordinate of the point */ -+ VGUScalar y; /* < Vertical coordinate of the point */ -+} VGUPoint; -+ -+/* * -+ * @brief Defines a rectangle. -+ * -+ */ -+typedef struct { -+ VGUScalar x; /* < Horizontal coordinate of the start point of the rectangle */ -+ VGUScalar y; /* < Vertical coordinate of the start point of the rectangle */ -+ VGUScalar w; /* < Width of the rectangle */ -+ VGUScalar h; /* < Height of the rectangle */ -+} VGURect; -+ -+/* * -+ * @brief Enumerates filter types for rendering an image. -+ * -+ */ -+typedef enum { -+ VGU_FILTER_BILINEAR = 0, /* < Bilinear interpolation filter (default value) */ -+ VGU_FILTER_NEAREST, /* < No interpolation filter */ -+ VGU_FILTER_LINEAR, /* < Linear interpolation filter */ -+ VGU_FILTER_BUTT /* < Invalid definition */ -+} VGUFilter; -+ -+/* * -+ * @brief Enumerates fill rules for graphics. -+ * -+ */ -+typedef enum { -+ VGU_RULE_WINDING = 0, /* < Non-zero winding rule (default value) */ -+ VGU_RULE_EVEN_ODD, /* < Even-odd rule */ -+ VGU_RULE_BUTT /* < Invalid definition */ -+} VGUFillRule; -+ -+/* * -+ * @brief Enumerates fill types of the outside of the gradient area. -+ * -+ */ -+typedef enum { -+ VGU_SPREAD_PAD = 0, /* < The area is filled with the closest gradient stop color. (Default value) */ -+ VGU_SPREAD_REFLECT, /* < The gradient is reflected outside the area. */ -+ VGU_SPREAD_REPEAT, /* < The gradient is repeated outside the area. */ -+ VGU_SPREAD_BUTT /* < Invalid definition */ -+} VGUFillSpread; -+ -+/* * -+ * @brief Enumerates wrap types of a pattern. -+ * -+ */ -+typedef enum { -+ VGU_WRAP_REFLECT = 0, /* < The pattern is reflected. */ -+ VGU_WRAP_REPEAT, /* < The pattern is repeated. */ -+ VGU_WRAP_BUTT /* < Invalid definition */ -+} VGUWrapType; -+ -+/* * -+ * @brief Enumerates commands for drawing a path. -+ * -+ */ -+typedef enum { -+ VGU_PATH_CMD_CLOSE = 0, /* < Close the current subpath (coordinates: none). */ -+ VGU_PATH_CMD_MOVE, /* < Move to the specified point (coordinates: x0, y0). */ -+ VGU_PATH_CMD_LINE, /* < Draw a line (coordinates: x0, y0). */ -+ VGU_PATH_CMD_HLINE, /* < Draw a horizontal line (coordinates: x0). */ -+ VGU_PATH_CMD_VLINE, /* < Draw a vertical line (coordinates: y0). */ -+ VGU_PATH_CMD_QUAD, /* < Draw a quadratic Bezier curve (coordinates: x0, y0, x1, y1). */ -+ VGU_PATH_CMD_CUBIC, /* < Draw a cubic Bezier curve (coordinates: x0, y0, x1, y1, x2, y2). */ -+ VGU_PATH_CMD_SQUAD, /* < Draw a smooth quadratic Bezier curve (coordinates: x1, y1). */ -+ VGU_PATH_CMD_SCUBIC, /* < Draw a smooth cubic Bezier curve (coordinates: x1, y1, x2, y2). */ -+ VGU_PATH_CMD_BUTT, /* < Invalid definition */ -+} VGUPathCmd; -+ -+/* * -+ * @brief Defines a path object, which stores path-related commands and coordinates. -+ * -+ */ -+typedef struct { -+ uint8_t *segment; /* < Pointer to the path command data */ -+ int32_t numSegments; /* < Total number of path commands */ -+ uint8_t *data; /* < Pointer to the coordinates used in the path commands */ -+ VGUPathDataType type; /* < Data type of the path */ -+ bool enAlias; /* < Whether to enable anti-aliasing */ -+ VGURect boundBox; /* < Bounding box of the path */ -+} VGUPath; -+ -+/* * -+ * @brief Enumerates transform types. -+ * -+ */ -+typedef enum { -+ VGU_TRANSFORM_TRANSLATE = (1 << 0), /* < Translate */ -+ VGU_TRANSFORM_SCALE = (1 << 1), /* < Scale */ -+ VGU_TRANSFORM_ROTATE_90 = (1 << 2), /* < Rotate by 90 degrees */ -+ VGU_TRANSFORM_ROTATE_180 = (1 << 3), /* < Rotate by 180 degrees */ -+ VGU_TRANSFORM_ROTATE_270 = (1 << 4), /* < Rotate by 270 degrees */ -+ VGU_TRANSFORM_OTHER = (1 << 16) /* < Other transform type */ -+} VGUTransformType; -+ -+/* * -+ * @brief Defines a transformation matrix. -+ * -+ */ -+typedef struct { -+ float m[3][3]; /* < 3x3 transformation matrix */ -+ uint32_t type; /* < Transform type, which can be scale, translate, or rotate by 90 x N degrees */ -+} VGUMatrix3; -+ -+/* * -+ * @brief Stores bitmap information for hardware acceleration. -+ * -+ */ -+typedef struct { -+ VGUPixelFormat pixelFormat; /* < Pixel format */ -+ uint32_t width; /* < Bitmap width */ -+ uint32_t height; /* < Bitmap height */ -+ uint32_t stride; /* < Bitmap stride */ -+ void *virAddr; /* < Virtual address of the requested memory */ -+ uint64_t phyAddr; /* < Physical memory address */ -+} VGUBuffer; -+ -+/* * -+ * @brief Enumerates clip types of a surface. -+ * -+ */ -+typedef enum { -+ VGU_CLIP_RECT = 0, /* < Rectangle clip (default value) */ -+ VGU_CLIP_PATH, /* < Path clip */ -+ VGU_CLIP_BUTT /* < Invalid definition */ -+} VGUClipType; -+ -+/* * -+ * @brief Defines a mask layer. -+ * -+ */ -+typedef struct { -+ VGUBuffer *buffer; /* < Pointer to the buffer for the mask */ -+ VGURect *rect; /* < Pointer to the rectangle for the mask */ -+} VGUMaskLayer; -+ -+/* * -+ * @brief Stores surface information for 2D hardware acceleration. -+ * -+ */ -+typedef struct { -+ VGUBuffer *buffer; /* < Bitmap buffer */ -+ union { -+ VGURect *clipRect; /* < Pointer to the clip rectangle. If it is null, the entire surface will be rendered. */ -+ VGUPath *clipPath; /* < Pointer to the clip path. If it is null, the entire surface will be rendered. */ -+ }; -+ VGUClipType clipType; /* < Clip type of the surface */ -+ VGUMaskLayer *mask; /* < Mask layer, which can be null */ -+ VGUBlendType blend; /* < Blend type, specifying how a new image is drawn onto an existing surface */ -+ VGUFilter filter; /* < Filter type */ -+} VGUSurface; -+ -+/* * -+ * @brief Defines how the colors are distributed along the gradient. -+ * -+ */ -+typedef struct { -+ float stop; /* < Stop position. The value ranges from 0.0 to 1.0. */ -+ uint32_t color; /* < Color of the stop */ -+} VGUColorStop; -+ -+/* * -+ * @brief Defines a linear gradient. -+ * -+ */ -+typedef struct { -+ VGUScalar x1; /* < Horizontal coordinate of the start point of the linear gradient */ -+ VGUScalar y1; /* < Vertical coordinate of the start point of the linear gradient */ -+ VGUScalar x2; /* < Horizontal coordinate of the end point of the linear gradient */ -+ VGUScalar y2; /* < Vertical coordinate of the end point of the linear gradient */ -+} VGULinear; -+ -+/* * -+ * @brief Defines a radial gradient. -+ * -+ */ -+typedef struct { -+ VGUScalar x0; /* < Horizontal coordinate of the center of the inner circle */ -+ VGUScalar y0; /* < Vertical coordinate of the center of the inner circle */ -+ VGUScalar r0; /* < Radius of the inner circle */ -+ VGUScalar x1; /* < Horizontal coordinate of the center of the outer circle */ -+ VGUScalar y1; /* < Vertical coordinate of the center of the outer circle */ -+ VGUScalar r1; /* < Radius of the outer circle */ -+} VGURadial; -+ -+/* * -+ * @brief Defines a conic gradient. -+ * -+ */ -+typedef struct { -+ VGUScalar cx; /* < Horizontal coordinate of the center of the circle */ -+ VGUScalar cy; /* < Vertical coordinate of the center of the circle */ -+} VGUConic; -+ -+/* * -+ * @brief Defines an image. -+ * -+ */ -+typedef struct { -+ VGUBuffer *buffer; /* < Image buffer */ -+ VGUMatrix3 *matrix; /* < Pointer to the transformation matrix. If it is null, the identity matrix is used. */ -+ VGURect *rect; /* < Pointer to the rectangle of the image. If it is null, the entire buffer data is used. */ -+ uint8_t opacity; /* < Opacity. The value ranges from 0 to 255. */ -+} VGUImage; -+ -+/* * -+ * @brief Defines an image pattern. -+ * -+ */ -+typedef struct { -+ VGUImage *image; /* < Pointer to the image object */ -+ VGUWrapType wrapx; /* < Wrap the image horizontally. */ -+ VGUWrapType wrapy; /* < Wrap the image vertically. */ -+} VGUPattern; -+ -+/* * -+ * @brief Enumerates gradient types. -+ * -+ */ -+typedef enum { -+ VGU_GRADIENT_LINEAR = 0, /* < Linear gradient */ -+ VGU_GRADIENT_RADIAL, /* < Radial gradient */ -+ VGU_GRADIENT_CONIC, /* < Conic gradient */ -+ VGU_GRADIENT_BUTT /* < Invalid definition */ -+} VGUGradientType; -+ -+/* * -+ * @brief Defines a gradient object. -+ * -+ */ -+typedef struct { -+ VGUMatrix3 *matrix; /* < Pointer to the transformation matrix of the gradient object */ -+ VGUColorStop *colorStops; /* < Pointer to the gradient stop color array */ -+ uint16_t stopCount; /* < Number of stop colors */ -+ union { -+ VGULinear linear; /* < Linear gradient object */ -+ VGURadial radial; /* < Radial gradient object */ -+ VGUConic conic; /* < Conic gradient object */ -+ }; -+ VGUGradientType type; /* < Gradient type */ -+ VGUFillSpread spread; /* < Gradient spread mode */ -+ uint8_t opacity; /* < Opacity. The value ranges from 0 to 255. */ -+} VGUGradient; -+ -+/* * -+ * @brief Defines a solid color. -+ * -+ */ -+typedef struct { -+ uint32_t color; /* < Solid color */ -+ uint8_t opacity; /* < Opacity. The value ranges from 0 to 255. */ -+} VGUSolid; -+ -+/* * -+ * @brief Enumerates paint types. -+ * -+ */ -+typedef enum { -+ VGU_PAINT_SOLID = 0, /* < Paint a solid color. */ -+ VGU_PAINT_GRADIENT, /* < Paint a gradient object. */ -+ VGU_PAINT_PATTERN, /* < Paint a pattern. */ -+ VGU_PAINT_BUTT /* < Invalid operation */ -+} VGUPaintType; -+ -+/* * -+ * @brief Defines the paint style when filling or stroking a path. -+ * -+ */ -+typedef struct { -+ union { -+ VGUGradient *gradient; /* < Pointer to the gradient object */ -+ VGUPattern *pattern; /* < Pointer to the pattern object */ -+ VGUSolid *solid; /* < Pointer to the solid color object */ -+ }; -+ VGUPaintType type; /* < Paint type */ -+} VGUPaintStyle; -+ -+/* * -+ * @brief Defines path filling attributes. -+ * -+ */ -+typedef struct { -+ VGUFillRule rule; /* < Fill rule */ -+} VGUFillAttr; -+ -+/* * -+ * @brief Defines path stroking attributes. -+ * -+ */ -+typedef struct { -+ VGULineCap cap; /* < Line cap style */ -+ VGUJointType join; /* < Join type */ -+ float miterLimit; /* < Miter limit */ -+ float width; /* < Line width */ -+} VGUStrokeAttr; -+ -+/* * -+ * @brief Defines driver functions for 2D hardware acceleration. -+ */ -+typedef struct { -+ /* * -+ * @brief Initializes hardware acceleration. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @see DeinitVgu -+ * @since 3.0 -+ */ -+ VGUResult (*InitVgu)(void); -+ -+ /* * -+ * @brief Deinitializes hardware acceleration. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @see InitVgu -+ * @since 3.0 -+ */ -+ VGUResult (*DeinitVgu)(void); -+ -+ /* * -+ * @brief Queries hardware acceleration capabilities. -+ * -+ * @param cap Indicates the capabilities to query, which are defined by VGUCapability. -+ * -+ * @return Returns a value greater than or equal to 0 if the operation is successful; returns an error code defined -+ * in {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+ int32_t (*QueryCapability)(uint32_t cap); -+ -+ /* * -+ * @brief Fills the given path with a specified paint style. -+ * -+ * @param target Indicates the pointer to the target surface. -+ * @param path Indicates the pointer to the path object. -+ * @param matrix Indicates the pointer to the transformation matrix object. If this parameter is null, -+ * the identity matrix is used by default. -+ * @param attr Indicates the pointer to the path filling attributes. -+ * @param style Indicates the pointer to the paint style to use. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+ VGUResult (*RenderFill)(VGUSurface *target, const VGUPath *path, const VGUMatrix3 *matrix, const VGUFillAttr *attr, -+ const VGUPaintStyle *style); -+ -+ /* * -+ * @brief Strokes the given path with a specified paint style. -+ * -+ * @param target Indicates the pointer to the target surface. -+ * @param path Indicates the pointer to the path object. -+ * @param matrix Indicates the pointer to the transformation matrix object. If this parameter is null, -+ * the identity matrix is used by default. -+ * @param attr Indicates the pointer to the path stroking attributes. -+ * @param style Indicates the pointer to the paint style to use. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+ VGUResult (*RenderStroke)(VGUSurface *target, const VGUPath *path, const VGUMatrix3 *matrix, -+ const VGUStrokeAttr *attr, const VGUPaintStyle *style); -+ -+ /* * -+ * @brief Blurs a specified surface. -+ * -+ * @param target Indicates the pointer to the target surface. -+ * @param blur Indicates the blur radius. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+ VGUResult (*RenderBlur)(VGUSurface *target, uint16_t blur); -+ -+ /* * -+ * @brief Blits an image to the target surface. -+ * -+ * During bit blit, color space conversion (CSC) and transformation can be implemented. -+ * -+ * @param target Indicates the pointer to the target surface. -+ * @param src Indicates the pointer to the source image. -+ * @param color Indicates the color for blending. If this parameter is 0, color blending is not performed. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+ VGUResult (*RenderBlit)(VGUSurface *target, const VGUImage *src, uint32_t color); -+ -+ /* * -+ * @brief Blits multiple images to the target surface. -+ * -+ * During bit blit, color space conversion (CSC) and transformation can be implemented. You can use this -+ * function to combine multiple source images to the target surface. -+ * To query the maximum number of source images allowed, call the QueryCapability function. -+ * -+ * @param target Indicates the pointer to the target surface. -+ * @param src Indicates the pointer to the array of source images. -+ * @param count Indicates the number of source images. -+ * @param color Indicates the color for blending. If this parameter is 0, color blending is not performed. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+ VGUResult (*RenderBlitN)(VGUSurface *target, const VGUImage *src, uint16_t count, uint32_t color); -+ -+ /* * -+ * @brief Clears a rectangle with a given color on the target surface. -+ * -+ * @param target Indicates the pointer to the target surface. -+ * @param rect Indicates the pointer to the rectangle to clear. If this parameter is null, the entire surface -+ * will be cleared. -+ * @param color Indicates the color to fill. -+ * @param opacity Indicates the opacity to set. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+ VGUResult (*RenderClearRect)(VGUSurface *target, const VGURect *rect, uint32_t color, uint8_t opacity); -+ -+ /* * -+ * @brief Disables hardware acceleration for rendering. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+ VGUResult (*RenderCancel)(); -+ -+ /* * -+ * @brief Synchronizes hardware acceleration when it is used to draw and blit bitmaps. -+ * -+ * This function blocks the process until hardware acceleration is complete. -+ * -+ * @param timeOut Indicates the timeout duration for hardware acceleration synchronization. -+ * The value 0 indicates no timeout, so the process keeps waiting until hardware acceleration is complete. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+ VGUResult (*RenderSync)(int32_t timeOut); -+} VGUFuncs; -+ -+/* * -+ * @brief Initializes a path object. -+ * -+ * @param path Indicates the pointer to the path object. -+ * @param type Indicates the data type of the path. -+ * @param segments Indicates the pointer to the path commands. -+ * @param numSegments Indicates the total number of path commands. -+ * @param data Indicates the pointer to the coordinate data used in the path commands. -+ * @param enAlias Specifies whether to enable anti-aliasing. -+ * @param boundBox Indicates the bounding box of the path. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+VGUResult VGUPathInit(VGUPath *path, VGUPathDataType type, const uint8_t* segments, int numSegments, -+ const uint8_t *data, bool enAlias, VGURect boundBox); -+ -+/* * -+ * @brief Adds a subpath to a specified path. -+ * -+ * @param path Indicates the pointer to the path object. -+ * @param subpath Indicates the pointer to the subpath object. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+VGUResult VGUPathAppend(VGUPath *path, const VGUPath *subpath); -+ -+/* * -+ * @brief Clears the memory of a specified path object. -+ * -+ * @param path Indicates the pointer to the path object. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+VGUResult VGUPathClear(VGUPath *path); -+ -+/* * -+ * @brief Loads an identity matrix into a specified matrix object. -+ * -+ * @param matrix Indicates the pointer to the transformation matrix object. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+VGUResult VGUMatrixIdentity(VGUMatrix3 *matrix); -+ -+/* * -+ * @brief Scales a specified transformation matrix. -+ * -+ * @param matrix Indicates the pointer to the transformation matrix object. -+ * @param xScale Indicates how much you want to scale the horizontal coordinate by. -+ * @param yScale Indicates how much you want to scale the vertical coordinate by. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+VGUResult VGUMatrixScale(VGUMatrix3 *matrix, float xScale, float yScale); -+ -+/* * -+ * @brief Rotates a specified transformation matrix. -+ * -+ * @param matrix Indicates the pointer to the transformation matrix object. -+ * @param degree Indicates the number of degrees to rotate. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+VGUResult VGUMatrixRotate(VGUMatrix3 *matrix, float degree); -+ -+/* * -+ * @brief Translates a specified transformation matrix. -+ * -+ * @param matrix Indicates the pointer to the transformation matrix object. -+ * @param x Indicates how much you want to translate the horizontal coordinate by. -+ * @param y Indicates how much you want to translate the vertical coordinate by. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+VGUResult VGUMatrixTranslate(VGUMatrix3 *matrix, float x, float y); -+ -+/* * -+ * @brief Adds color stops to a specified gradient. -+ * -+ * @param gradient Indicates the pointer to the gradient object. -+ * @param colorStop Indicates the pointer to the color stop array. -+ * @param count Indicates the total number of color stops. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+VGUResult VGUGradientColorStop(VGUGradient *gradient, const VGUColorStop *colorStop, uint32_t count); -+ -+/* * -+ * @brief Clears color stops of a specified gradient. -+ * -+ * @param gradient Indicates the pointer to the gradient object. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+VGUResult VGUGradientClearStop(VGUGradient *gradient); -+ -+/* * -+ * @brief Sets a transformation matrix for a specified gradient. -+ * -+ * @param gradient Indicates the pointer to the gradient object. -+ * @param matrix Indicates the pointer to the transformation matrix object to set. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+VGUResult VGUGradientMatrix(VGUGradient *gradient, const VGUMatrix3 *matrix); -+ -+/* * -+ * @brief Creates a linear gradient object. -+ * -+ * @param gradient Indicates the pointer to the gradient object. -+ * @param p1 Indicates the pointer to the coordinates of the start point. -+ * @param p2 Indicates the pointer to the coordinates of the end point. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+VGUResult VGUGradientLinear(VGUGradient *gradient, const VGUPoint *p1, const VGUPoint *p2); -+ -+/* * -+ * @brief Creates a radial gradient object. -+ * -+ * @param gradient Indicates the pointer to the gradient object. -+ * @param p1 Indicates the pointer to the center point coordinates of the inner circle. -+ * @param r1 Indicates the radius of the inner circle. -+ * @param p2 Indicates the pointer to the center point coordinates of the outer circle. -+ * @param r2 Indicates the radius of the outer circle. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+VGUResult VGUGradientRadial(VGUGradient *gradient, const VGUPoint *p1, VGUScalar r1, const VGUPoint *p2, VGUScalar r2); -+ -+/* * -+ * @brief Creates a conic gradient object. -+ * -+ * @param gradient Indicates the pointer to the gradient object. -+ * @param cx Indicates the horizontal coordinate of the center point of the gradient. -+ * @param cy Indicates the vertical coordinate of the center point of the gradient. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+VGUResult VGUGradientConic(VGUGradient *gradient, VGUScalar cx, VGUScalar cy); -+ -+/* * -+ * @brief Initializes the hardware acceleration module to obtain the pointer to functions for -+ * hardware acceleration operations. -+ * -+ * @param funcs Indicates the double pointer to the functions for hardware acceleration operations. -+ * Memory is allocated automatically when you initiate the hardware acceleration module, so you can simply use -+ * the pointer to gain access to the functions. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * -+ * @since 3.0 -+ */ -+VGUResult VGUInitialize(VGUFuncs **funcs); -+ -+/* * -+ * @brief Deinitializes the hardware acceleration module to release the pointer to functions -+ * for hardware acceleration operations. -+ * -+ * @param funcs Indicates the pointer to the functions for hardware acceleration operations. -+ * -+ * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in -+ * {@link VGUResult} otherwise. -+ * @since 3.0 -+ */ -+VGUResult VGUUninitialize(VGUFuncs *funcs); -+ -+#ifdef __cplusplus -+} -+#endif -+#endif -diff --git a/ohos_ndk_aosp/includes/graphic_util/buffer_handle_parcel.h b/ohos_ndk_aosp/includes/graphic_util/buffer_handle_parcel.h -new file mode 100755 -index 0000000000..d399bbabe9 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/graphic_util/buffer_handle_parcel.h -@@ -0,0 +1,40 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_INCLUDE_BUFFER_HANDLE_PARCEL_H -+#define UTILS_INCLUDE_BUFFER_HANDLE_PARCEL_H -+ -+#ifdef __cplusplus -+#include "buffer_handle.h" -+#include "message_parcel.h" -+namespace OHOS { -+/* * -+ * @Description: Write BufferHanedle to MessageParcel -+ * @param parcel which the buffer handle will write to -+ * @param handle Buffer handle which will wtite to parcel -+ * @return Returns true if the operation is successful; returns false otherwise. -+ */ -+bool WriteBufferHandle(MessageParcel &parcel, const BufferHandle &handle); -+ -+/* * -+ * @Description: Read BufferHanedle from MessageParcel -+ * @param parcel message parcel which should has a buffer handle -+ * @return Returns pointer to buffer handle if the operation is successful; returns nullptr otherwise. -+ */ -+BufferHandle *ReadBufferHandle(MessageParcel &parcel); -+} // namespace OHO -+#endif // __cplusplus -+ -+#endif // UTILS_INCLUDE_BUFFER_HANDLE_PARCEL_H -diff --git a/ohos_ndk_aosp/includes/graphic_util/buffer_handle_utils.h b/ohos_ndk_aosp/includes/graphic_util/buffer_handle_utils.h -new file mode 100644 -index 0000000000..0ef9cc94cc ---- /dev/null -+++ b/ohos_ndk_aosp/includes/graphic_util/buffer_handle_utils.h -@@ -0,0 +1,52 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef INCLUDE_BUFFER_HANDLE_UTILS_H -+#define INCLUDE_BUFFER_HANDLE_UTILS_H -+ -+#include -+#include -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+/** -+* @Description: Init buffer handle, and must be freeed by FreeBufferHandle to avoid memory leak -+* @param reserveInts The number of reserved integers -+* @param reserveFds The number of reserved fds -+* @return Returns pointer to buffer handle if the operation is successful; returns nullptr otherwise. -+*/ -+BufferHandle *AllocateBufferHandle(uint32_t reserveInts, uint32_t reserveFds); -+ -+/** -+* @Description: Free buffer handle allocated by AllocateBufferHandle, and close the fd at the same time. -+* @param handle Buffer handle which is to be freed. -+* @return Returns 0 if the operation is successful; returns -1 if failed -+*/ -+int32_t FreeBufferHandle(BufferHandle *handle); -+ -+/** -+* @Description: clone a new buffer handle based on given buffer handle -+* @param handle Buffer handle which is to be cloned. -+* @return Returns pointer to buffer handle if the operation is successful; returns nullptr otherwise. -+*/ -+BufferHandle *CloneBufferHandle(const BufferHandle *handle); -+ -+#ifdef __cplusplus -+} -+#endif -+ -+#endif // INCLUDE_BUFFER_HANDLE_UTILS_H -diff --git a/ohos_ndk_aosp/includes/hilog/log.h b/ohos_ndk_aosp/includes/hilog/log.h -new file mode 100644 -index 0000000000..4b0bc93cb3 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/hilog/log.h -@@ -0,0 +1,22 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef HIVIEWDFX_HILOG_H -+#define HIVIEWDFX_HILOG_H -+ -+#include "hilog/log_c.h" -+#include "hilog/log_cpp.h" -+ -+#endif // HIVIEWDFX_HILOG_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/hilog/log_c.h b/ohos_ndk_aosp/includes/hilog/log_c.h -new file mode 100644 -index 0000000000..dbbba724e9 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/hilog/log_c.h -@@ -0,0 +1,77 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef HIVIEWDFX_HILOG_C_H -+#define HIVIEWDFX_HILOG_C_H -+ -+#include -+#include -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+// Log domain -+#ifndef LOG_DOMAIN -+#define LOG_DOMAIN 0 -+#endif -+ -+// Log tag -+#ifndef LOG_TAG -+#define LOG_TAG NULL -+#endif -+ -+// Log type -+typedef enum { -+ LOG_TYPE_MIN = 0, -+ LOG_APP = 0, -+ LOG_INIT = 1, -+ // Used by core service, framework. -+ LOG_CORE = 3, -+ LOG_KMSG = 4, -+ LOG_TYPE_MAX -+} LogType; -+ -+// Log level -+typedef enum { -+ LOG_LEVEL_MIN = 0, -+ LOG_DEBUG = 3, -+ LOG_INFO = 4, -+ LOG_WARN = 5, -+ LOG_ERROR = 6, -+ LOG_FATAL = 7, -+ LOG_LEVEL_MAX, -+} LogLevel; -+ -+int HiLogPrint(LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...) -+ __attribute__((__format__(os_log, 5, 6))); -+ -+#define HILOG_DEBUG(type, ...) ((void)HiLogPrint((type), LOG_DEBUG, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) -+ -+#define HILOG_INFO(type, ...) ((void)HiLogPrint((type), LOG_INFO, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) -+ -+#define HILOG_WARN(type, ...) ((void)HiLogPrint((type), LOG_WARN, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) -+ -+#define HILOG_ERROR(type, ...) ((void)HiLogPrint((type), LOG_ERROR, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) -+ -+#define HILOG_FATAL(type, ...) ((void)HiLogPrint((type), LOG_FATAL, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) -+ -+bool HiLogIsLoggable(unsigned int domain, const char *tag, LogLevel level); -+ -+#ifdef __cplusplus -+} -+#endif -+ -+#endif // HIVIEWDFX_HILOG_C_H -diff --git a/ohos_ndk_aosp/includes/hilog/log_cpp.h b/ohos_ndk_aosp/includes/hilog/log_cpp.h -new file mode 100644 -index 0000000000..2f894e7ead ---- /dev/null -+++ b/ohos_ndk_aosp/includes/hilog/log_cpp.h -@@ -0,0 +1,46 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef HIVIEWDFX_HILOG_CPP_H -+#define HIVIEWDFX_HILOG_CPP_H -+ -+#include "hilog/log_c.h" -+ -+#ifdef __cplusplus -+ -+namespace OHOS { -+namespace HiviewDFX { -+ -+typedef struct HiLogLabel { -+ LogType type; -+ unsigned int domain; -+ const char *tag; -+} HiLogLabel; -+ -+class HiLog final { -+public: -+ static int Debug(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(os_log, 2, 3))); -+ static int Info(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(os_log, 2, 3))); -+ static int Warn(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(os_log, 2, 3))); -+ static int Error(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(os_log, 2, 3))); -+ static int Fatal(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(os_log, 2, 3))); -+}; -+ -+} // namespace HiviewDFX -+} // namespace OHOS -+ -+#endif // __cplusplus -+ -+#endif // HIVIEWDFX_HILOG_CPP_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/inputmethod_ability/i_input_method_agent.h b/ohos_ndk_aosp/includes/inputmethod_ability/i_input_method_agent.h -new file mode 100644 -index 0000000000..74d7156188 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_ability/i_input_method_agent.h -@@ -0,0 +1,45 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_IINPUTMETHODAGENT_H -+#define FM_IMMS_PROJECT_IINPUTMETHODAGENT_H -+ -+#include "iremote_broker.h" -+#include "global.h" -+ -+/** -+ * brief Definition of interface IInputMethodAgent -+ * It defines the remote calls from input client to input method service -+ */ -+namespace OHOS { -+namespace MiscServices { -+ class IInputMethodAgent : public IRemoteBroker { -+ public: -+ enum { -+ DISPATCH_KEY_EVENT = FIRST_CALL_TRANSACTION, -+ ON_CURSOR_UPDATE, -+ ON_SELECTION_CHANGE, -+ }; -+ -+ DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputMethodAgent"); -+ -+ virtual bool DispatchKeyEvent(MessageParcel& data) = 0; -+ virtual void OnCursorUpdate(int32_t positionX, int32_t positionY, int height) = 0; -+ virtual void OnSelectionChange(std::u16string text, int32_t oldBegin, int32_t oldEnd, -+ int32_t newBegin, int32_t newEnd) = 0; -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_IINPUTMETHODAGENT_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_ability/i_input_method_core.h b/ohos_ndk_aosp/includes/inputmethod_ability/i_input_method_core.h -new file mode 100644 -index 0000000000..8018dd8a18 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_ability/i_input_method_core.h -@@ -0,0 +1,66 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_IINPUTMETHODCORE_H -+#define FM_IMMS_PROJECT_IINPUTMETHODCORE_H -+#include "iremote_broker.h" -+#include "i_input_data_channel.h" -+#include "i_input_control_channel.h" -+#include "ipc_types.h" -+#include "input_attribute.h" -+#include "keyboard_type.h" -+#include "input_channel.h" -+#include "global.h" -+ -+/** -+ * brief Definition of interface IInputMethodCore -+ * It defines the remote calls from input method management service to input method service -+ */ -+namespace OHOS { -+namespace MiscServices { -+ class IInputMethodCore : public IRemoteBroker { -+ public: -+ enum { -+ INITIALIZE_INPUT = FIRST_CALL_TRANSACTION, -+ SET_CLIENT_STATE, -+ START_INPUT, -+ STOP_INPUT, -+ SHOW_KEYBOARD, -+ STOP_INPUT_SERVICE, -+ HIDE_KEYBOARD, -+ SET_KEYBOARD_TYPE, -+ GET_KEYBOARD_WINDOW_HEIGHT, -+ INIT_INPUT_CONTROL_CHANNEL -+ }; -+ -+ DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputMethodCore"); -+ -+ virtual int32_t initializeInput(sptr& startInputToken, int32_t displayId, -+ sptr& inputControlChannel) = 0; -+ virtual bool startInput(const sptr& startInputToken, -+ const InputAttribute& editorAttribute, -+ bool supportPhysicalKbd) = 0; -+ virtual int32_t stopInput() = 0; -+ virtual bool showKeyboard(const sptr& inputDataChannel) = 0; -+ virtual bool hideKeyboard(int32_t flags) = 0; -+ virtual int32_t setKeyboardType(const KeyboardType& type) = 0; -+ virtual int32_t getKeyboardWindowHeight(int32_t retHeight) = 0; -+ virtual int32_t InitInputControlChannel(sptr &inputControlChannel) = 0; -+ virtual void SetClientState(bool state) = 0; -+ virtual void StopInputService(std::string imeId) = 0; -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_IINPUTMETHODCORE_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_ability/input_method_ability.h b/ohos_ndk_aosp/includes/inputmethod_ability/input_method_ability.h -new file mode 100644 -index 0000000000..679a8d80da ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_ability/input_method_ability.h -@@ -0,0 +1,110 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_INPUTMETHODABILITY_H -+#define FM_IMMS_PROJECT_INPUTMETHODABILITY_H -+ -+#include -+#include "js_input_method_engine_listener.h" -+#include "js_keyboard_delegate_listener.h" -+#include "iremote_object.h" -+#include "i_input_control_channel.h" -+#include "i_input_method_core.h" -+#include "i_input_data_channel.h" -+#include "i_input_method_agent.h" -+#include "input_method_core_stub.h" -+#include "input_control_channel_proxy.h" -+#include "input_attribute.h" -+#include "message_handler.h" -+#include "input_channel.h" -+#include "message.h" -+#include "utils.h" -+#include "input_method_system_ability_proxy.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class JsInputMethodEngineListener; -+ class MessageHandler; -+ class InputMethodAbility : public RefBase { -+ public: -+ InputMethodAbility(); -+ ~InputMethodAbility(); -+ static sptr GetInstance(); -+ sptr OnConnect(); -+ bool InsertText(const std::string text); -+ void setImeListener(sptr &imeListener); -+ void setKdListener(sptr &kdListener); -+ void DeleteForward(int32_t length); -+ void DeleteBackward(int32_t length); -+ void HideKeyboardSelf(); -+ std::u16string GetTextBeforeCursor(int32_t number); -+ std::u16string GetTextAfterCursor(int32_t number); -+ void SendFunctionKey(int32_t funcKey); -+ void MoveCursor(int32_t keyCode); -+ bool DispatchKeyEvent(int32_t keyCode, int32_t keyStatus); -+ int32_t GetEnterKeyType(); -+ int32_t GetInputPattern(); -+ void StopInput(); -+ -+ private: -+ std::thread workThreadHandler; -+ MessageHandler *msgHandler; -+ bool mSupportPhysicalKbd = false; -+ InputAttribute *editorAttribute; -+ int32_t displyId = 0; -+ sptr startInputToken; -+ InputChannel *writeInputChannel; -+ bool stop_; -+ int32_t KEYBOARD_HIDE = 1; -+ int32_t KEYBOARD_SHOW = 2; -+ bool isBindClient = false; -+ -+ // communicating with IMSA -+ sptr inputControlChannel; -+ void SetCoreAndAgent(); -+ -+ // communicating with IMC -+ sptr inputDataChannel; -+ sptr imeListener_; -+ sptr kdListener_; -+ static std::mutex instanceLock_; -+ static sptr instance_; -+ sptr mImms; -+ sptr GetImsaProxy(); -+ -+ void Initialize(); -+ void WorkThread(); -+ -+ // the message from IMSA -+ void OnInitialInput(Message *msg); -+ void OnStartInput(Message *msg); -+ void OnStopInput(Message *msg); -+ void OnSetKeyboardType(Message *msg); -+ void OnShowKeyboard(Message *msg); -+ void OnHideKeyboard(Message *msg); -+ void OnInitInputControlChannel(Message *msg); -+ -+ // the message from IMC -+ void OnCursorUpdate(Message *msg); -+ void OnSelectionChange(Message *msg); -+ -+ // control inputwindow -+ void InitialInputWindow(); -+ void ShowInputWindow(); -+ void DissmissInputWindow(); -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_INPUTMETHODABILITY_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/inputmethod_ability/input_method_agent_proxy.h b/ohos_ndk_aosp/includes/inputmethod_ability/input_method_agent_proxy.h -new file mode 100644 -index 0000000000..da635de89d ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_ability/input_method_agent_proxy.h -@@ -0,0 +1,39 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMC_PROJECT_INPUTMETHODAGENTPROXY_H -+#define FM_IMC_PROJECT_INPUTMETHODAGENTPROXY_H -+ -+#include "iremote_proxy.h" -+#include "i_input_method_agent.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputMethodAgentProxy : public IRemoteProxy { -+ public: -+ explicit InputMethodAgentProxy(const sptr &object); -+ ~InputMethodAgentProxy() = default; -+ DISALLOW_COPY_AND_MOVE(InputMethodAgentProxy); -+ -+ bool DispatchKeyEvent(MessageParcel& data) override; -+ void OnCursorUpdate(int32_t positionX, int32_t positionY, int32_t height) override; -+ void OnSelectionChange(std::u16string text, int32_t oldBegin, int32_t oldEnd, -+ int32_t newBegin, int32_t newEnd) override; -+ private: -+ static inline BrokerDelegator delegator_; -+ }; -+} -+} -+#endif // FM_IMC_PROJECT_INPUTMETHODAGENTPROXY_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/inputmethod_ability/input_method_agent_stub.h b/ohos_ndk_aosp/includes/inputmethod_ability/input_method_agent_stub.h -new file mode 100644 -index 0000000000..9a3ccec77a ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_ability/input_method_agent_stub.h -@@ -0,0 +1,45 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMC_PROJECT_INPUTMETHODAGENTSTUB_H -+#define FM_IMC_PROJECT_INPUTMETHODAGENTSTUB_H -+ -+#include "iremote_stub.h" -+#include "message_parcel.h" -+#include "message_option.h" -+#include "i_input_method_agent.h" -+#include "message_handler.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputMethodAgentStub : public IRemoteStub { -+ public: -+ explicit InputMethodAgentStub(); -+ virtual ~InputMethodAgentStub(); -+ virtual int32_t OnRemoteRequest(uint32_t code, -+ MessageParcel &data, -+ MessageParcel &reply, -+ MessageOption &option) override; -+ virtual bool DispatchKeyEvent(MessageParcel &data) override; -+ virtual void OnCursorUpdate(int32_t positionX, int32_t positionY, int height) override; -+ virtual void OnSelectionChange(std::u16string text, int32_t oldBegin, int32_t oldEnd, -+ int32_t newBegin, int32_t newEnd) override; -+ void SetMessageHandler(MessageHandler *msgHandler); -+ private: -+ MessageHandler *msgHandler_; -+ }; -+} -+} -+#endif // FM_IMC_PROJECT_INPUTMETHODAGENTSTUB_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/inputmethod_ability/input_method_core_proxy.h b/ohos_ndk_aosp/includes/inputmethod_ability/input_method_core_proxy.h -new file mode 100644 -index 0000000000..aa1849ce1e ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_ability/input_method_core_proxy.h -@@ -0,0 +1,55 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMC_PROJECT_INPUTMETHODCOREPROXY_H -+#define FM_IMC_PROJECT_INPUTMETHODCOREPROXY_H -+ -+#include "iremote_proxy.h" -+#include "iremote_object.h" -+#include "message_parcel.h" -+#include "message_option.h" -+#include "i_input_method_core.h" -+#include "i_input_control_channel.h" -+#include "i_input_data_channel.h" -+#include "input_attribute.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputMethodCoreProxy : public IRemoteProxy { -+ public: -+ explicit InputMethodCoreProxy(const sptr& object); -+ ~InputMethodCoreProxy(); -+ -+ DISALLOW_COPY_AND_MOVE(InputMethodCoreProxy); -+ -+ virtual int32_t initializeInput(sptr& startInputToken, int32_t displayId, -+ sptr& inputControlChannel) override; -+ virtual bool startInput(const sptr& inputDataChannel, -+ const InputAttribute& editorAttribute, -+ bool supportPhysicalKbd) override; -+ virtual int32_t stopInput() override; -+ virtual bool showKeyboard(const sptr& inputDataChannel) override; -+ virtual bool hideKeyboard(int32_t flags) override; -+ virtual int32_t setKeyboardType(const KeyboardType& type) override; -+ virtual int32_t getKeyboardWindowHeight(int32_t retHeight) override; -+ virtual int32_t InitInputControlChannel(sptr &inputControlChannel) override; -+ virtual void SetClientState(bool state) override; -+ virtual void StopInputService(std::string imeId) override; -+ private: -+ static inline BrokerDelegator delegator_; -+ }; -+} -+} -+#endif // FM_IMC_PROJECT_INPUTMETHODCOREPROXY_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/inputmethod_ability/input_method_core_stub.h b/ohos_ndk_aosp/includes/inputmethod_ability/input_method_core_stub.h -new file mode 100644 -index 0000000000..ae6a3c661d ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_ability/input_method_core_stub.h -@@ -0,0 +1,67 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_INPUTCONTROLCHANNEL_SK_H -+#define FM_IMMS_PROJECT_INPUTCONTROLCHANNEL_SK_H -+ -+#include -+#include -+#include -+#include "iremote_broker.h" -+#include "iremote_stub.h" -+#include "i_input_method_agent.h" -+#include "input_channel.h" -+#include "message_parcel.h" -+#include "input_attribute.h" -+#include "i_input_data_channel.h" -+#include "i_input_method_core.h" -+#include "i_input_control_channel.h" -+#include "keyboard_type.h" -+#include "message_handler.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputMethodCoreStub : public IRemoteStub { -+ public: -+ DISALLOW_COPY_AND_MOVE(InputMethodCoreStub); -+ explicit InputMethodCoreStub(int userId); -+ virtual ~InputMethodCoreStub(); -+ virtual int OnRemoteRequest(uint32_t code, -+ MessageParcel &data, -+ MessageParcel &reply, -+ MessageOption &option) override; -+ -+ virtual int32_t initializeInput(sptr& startInputToken, int32_t displayId, -+ sptr& inputControlChannel) override; -+ virtual bool startInput(const sptr& inputDataChannel, -+ const InputAttribute& editorAttribute, -+ bool supportPhysicalKbd) override; -+ virtual int32_t stopInput() override; -+ virtual bool showKeyboard(const sptr& inputDataChannel) override; -+ virtual bool hideKeyboard(int32_t flags)override; -+ virtual int32_t setKeyboardType(const KeyboardType& type) override; -+ virtual int32_t getKeyboardWindowHeight(int32_t retHeight) override; -+ virtual int32_t InitInputControlChannel(sptr &inputControlChannel) override; -+ virtual void SetClientState(bool state) override; -+ virtual void StopInputService(std::string imeId) override; -+ void SetMessageHandler(MessageHandler *msgHandler); -+ -+ private: -+ int userId_; -+ MessageHandler *msgHandler_; -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_INPUTCONTROLCHANNEL_SK_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_controller/i_input_client.h b/ohos_ndk_aosp/includes/inputmethod_controller/i_input_client.h -new file mode 100644 -index 0000000000..9b18ed64ce ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_controller/i_input_client.h -@@ -0,0 +1,46 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_IINPUTCLIENT_H -+#define FM_IMMS_PROJECT_IINPUTCLIENT_H -+ -+#include "iremote_broker.h" -+#include "i_input_method_agent.h" -+#include "input_channel.h" -+#include "global.h" -+ -+/** -+ * brief Definition of interface IInputClient -+ * It defines the remote calls from input method management service to input client. -+ */ -+namespace OHOS { -+namespace MiscServices { -+ class IInputClient : public IRemoteBroker { -+ public: -+ enum { -+ ON_INPUT_READY = 0, -+ ON_INPUT_RELEASED, -+ SET_DISPLAY_MODE, -+ }; -+ -+ DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.InputClient"); -+ -+ virtual int32_t onInputReady(const sptr& agent) = 0; -+ virtual int32_t onInputReleased(int32_t retValue) = 0; -+ virtual int32_t setDisplayMode(int32_t mode) = 0; -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_IINPUTCLIENT_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/inputmethod_controller/i_input_data_channel.h b/ohos_ndk_aosp/includes/inputmethod_controller/i_input_data_channel.h -new file mode 100644 -index 0000000000..4052fc2a98 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_controller/i_input_data_channel.h -@@ -0,0 +1,63 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_IINPUTDATACHANNEL_H -+#define FM_IMMS_PROJECT_IINPUTDATACHANNEL_H -+#include -+#include "iremote_broker.h" -+#include "global.h" -+#include "input_method_utils.h" -+ -+/** -+ * brief Definition of interface IInputDataChannel -+ * It defines the remote calls from input method service to input client -+ */ -+namespace OHOS { -+namespace MiscServices { -+ class IInputDataChannel : public IRemoteBroker { -+ public: -+ enum { -+ INSERT_TEXT = 0, -+ DELETE_FORWARD, -+ DELETE_BACKWARD, -+ CLOSE, -+ GET_TEXT_BEFORE_CURSOR, -+ GET_TEXT_AFTER_CURSOR, -+ GET_ENTER_KEY_TYPE, -+ GET_INPUT_PATTERN, -+ STOP_INPUT, -+ SEND_KEYBOARD_STATUS, -+ SEND_FUNCTION_KEY, -+ MOVE_CURSOR, -+ }; -+ -+ DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputDataChannel"); -+ -+ virtual bool InsertText(const std::u16string& text) = 0; -+ virtual bool DeleteForward(int32_t length) = 0; -+ virtual bool DeleteBackward(int32_t length) = 0; -+ virtual void Close() = 0; -+ virtual std::u16string GetTextBeforeCursor(int32_t number) = 0; -+ virtual std::u16string GetTextAfterCursor(int32_t number) = 0; -+ virtual void SendKeyboardStatus(int32_t status) = 0; -+ virtual void SendFunctionKey(int32_t funcKey) = 0; -+ virtual void MoveCursor(int32_t keyCode) = 0; -+ virtual int32_t GetEnterKeyType() = 0; -+ virtual int32_t GetInputPattern() = 0; -+ virtual void StopInput() = 0; -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_IINPUTDATACHANNEL_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_controller/input_client_proxy.h b/ohos_ndk_aosp/includes/inputmethod_controller/input_client_proxy.h -new file mode 100644 -index 0000000000..8d4a71ec24 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_controller/input_client_proxy.h -@@ -0,0 +1,40 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+ -+#ifndef FM_IMC_PROJECT_INPUTCLIENTPROXY_H -+#define FM_IMC_PROJECT_INPUTCLIENTPROXY_H -+ -+#include "iremote_proxy.h" -+#include "i_input_client.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputClientProxy : public IRemoteProxy { -+ public: -+ explicit InputClientProxy(const sptr &object); -+ ~InputClientProxy() = default; -+ DISALLOW_COPY_AND_MOVE(InputClientProxy); -+ -+ int32_t onInputReady(const sptr& agent) override; -+ int32_t onInputReleased(int32_t retValue) override; -+ int32_t setDisplayMode(int32_t mode) override; -+ -+ private: -+ static inline BrokerDelegator delegator_; -+ }; -+} -+} -+#endif -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/inputmethod_controller/input_client_stub.h b/ohos_ndk_aosp/includes/inputmethod_controller/input_client_stub.h -new file mode 100644 -index 0000000000..a601b92552 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_controller/input_client_stub.h -@@ -0,0 +1,44 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+ -+#ifndef FM_IMC_PROJECT_INPUTCLIENTSTUB_H -+#define FM_IMC_PROJECT_INPUTCLIENTSTUB_H -+ -+#include "iremote_stub.h" -+#include "i_input_client.h" -+#include "message_handler.h" -+#include "message.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputClientStub : public IRemoteStub { -+ public: -+ DISALLOW_COPY_AND_MOVE(InputClientStub); -+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, -+ MessageParcel &reply, MessageOption &option) override; -+ InputClientStub(); -+ ~InputClientStub(); -+ void SetHandler(MessageHandler *handler); -+ -+ int32_t onInputReady(const sptr& agent) override; -+ int32_t onInputReleased(int32_t retValue) override; -+ int32_t setDisplayMode(int32_t mode) override; -+ private: -+ MessageHandler *msgHandler = nullptr; -+ }; -+} -+} -+#endif -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/inputmethod_controller/input_data_channel_proxy.h b/ohos_ndk_aosp/includes/inputmethod_controller/input_data_channel_proxy.h -new file mode 100644 -index 0000000000..83cefdaa5c ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_controller/input_data_channel_proxy.h -@@ -0,0 +1,49 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMC_PROJECT_INPUTDATACHANNELPROXY_H -+#define FM_IMC_PROJECT_INPUTDATACHANNELPROXY_H -+ -+#include "iremote_proxy.h" -+#include "i_input_data_channel.h" -+#include "input_method_utils.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputDataChannelProxy : public IRemoteProxy { -+ public: -+ explicit InputDataChannelProxy(const sptr &object); -+ ~InputDataChannelProxy() = default; -+ DISALLOW_COPY_AND_MOVE(InputDataChannelProxy); -+ -+ bool InsertText(const std::u16string& text) override; -+ bool DeleteForward(int32_t length) override; -+ bool DeleteBackward(int32_t length) override; -+ void Close() override; -+ std::u16string GetTextBeforeCursor(int32_t number) override; -+ std::u16string GetTextAfterCursor(int32_t number) override; -+ void SendKeyboardStatus(int32_t status) override; -+ void SendFunctionKey(int32_t funcKey) override; -+ void MoveCursor(int32_t keyCode) override; -+ int32_t GetEnterKeyType() override; -+ int32_t GetInputPattern() override; -+ void StopInput() override; -+ -+ private: -+ static inline BrokerDelegator delegator_; -+ }; -+} -+} -+#endif -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/inputmethod_controller/input_data_channel_stub.h b/ohos_ndk_aosp/includes/inputmethod_controller/input_data_channel_stub.h -new file mode 100644 -index 0000000000..20ff48c7a5 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_controller/input_data_channel_stub.h -@@ -0,0 +1,56 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+ -+#ifndef FM_IMC_PROJECT_INPUTDATACHANNELSTUB_H -+#define FM_IMC_PROJECT_INPUTDATACHANNELSTUB_H -+ -+#include "i_input_data_channel.h" -+#include "iremote_stub.h" -+#include "message_handler.h" -+#include "input_method_utils.h" -+#include "input_method_controller.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputMethodController; -+ -+ class InputDataChannelStub : public IRemoteStub { -+ public: -+ DISALLOW_COPY_AND_MOVE(InputDataChannelStub); -+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, -+ MessageOption &option) override; -+ InputDataChannelStub(); -+ ~InputDataChannelStub(); -+ void SetHandler(MessageHandler *handler); -+ -+ bool InsertText(const std::u16string& text) override; -+ bool DeleteForward(int32_t length) override; -+ bool DeleteBackward(int32_t length) override; -+ void Close() override; -+ std::u16string GetTextBeforeCursor(int32_t number) override; -+ std::u16string GetTextAfterCursor(int32_t number) override; -+ void SendKeyboardStatus(int32_t status) override; -+ void SendFunctionKey(int32_t funcKey) override; -+ void MoveCursor(int32_t keyCode) override; -+ int32_t GetEnterKeyType() override; -+ int32_t GetInputPattern() override; -+ void StopInput() override; -+ private: -+ MessageHandler *msgHandler; -+ }; -+} -+} -+#endif -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/inputmethod_controller/input_method_controller.h b/ohos_ndk_aosp/includes/inputmethod_controller/input_method_controller.h -new file mode 100644 -index 0000000000..354552ddb2 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_controller/input_method_controller.h -@@ -0,0 +1,111 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+ -+#ifndef FM_IMC_PROJECT_INPUTMETHODCONTROLLER_H -+#define FM_IMC_PROJECT_INPUTMETHODCONTROLLER_H -+ -+#include -+#include -+#include "input_data_channel_stub.h" -+#include "input_client_stub.h" -+#include "input_method_system_ability_proxy.h" -+#include "input_method_agent_proxy.h" -+#include "i_input_method_agent.h" -+#include "message_handler.h" -+#include "iremote_object.h" -+#include "input_method_utils.h" -+#include "key_event.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputDataChannelStub; -+ class InputMethodSystemAbilityProxy; -+ class OnTextChangedListener : public virtual RefBase { -+ public: -+ virtual void InsertText(const std::u16string& text) = 0; -+ virtual void DeleteForward(int32_t length) = 0; -+ virtual void DeleteBackward(int32_t length) = 0; -+ virtual void SendKeyEventFromInputMethod(const KeyEvent& event) = 0; -+ virtual void SendKeyboardInfo(const KeyboardInfo& info) = 0; -+ virtual void SetKeyboardStatus(bool status) = 0; -+ virtual void MoveCursor(const Direction direction) = 0; -+ }; -+ -+ class ImsaDeathRecipient : public IRemoteObject::DeathRecipient { -+ public: -+ explicit ImsaDeathRecipient(); -+ ~ImsaDeathRecipient() = default; -+ -+ void OnRemoteDied(const wptr &object) override; -+ }; -+ -+ class InputMethodController : public RefBase { -+ public: -+ static sptr GetInstance(); -+ void Attach(sptr &listener); -+ std::u16string GetTextBeforeCursor(int32_t number); -+ std::u16string GetTextAfterCursor(int32_t number); -+ void ShowTextInput(); -+ void HideTextInput(); -+ void Close(); -+ void OnRemoteSaDied(const wptr &object); -+ void OnCursorUpdate(CursorInfo cursorInfo); -+ void OnSelectionChange(std::u16string text, int start, int end); -+ void OnConfigurationChange(Configuration info); -+ bool dispatchKeyEvent(std::shared_ptr keyEvent); -+ void DisplayOptionalInputMethod(); -+ std::vector ListInputMethod(); -+ int32_t GetEnterKeyType(); -+ int32_t GetInputPattern(); -+ void HideCurrentInput(); -+ private: -+ InputMethodController(); -+ ~InputMethodController(); -+ -+ bool Initialize(); -+ sptr GetImsaProxy(); -+ void PrepareInput(int32_t displayId, sptr &client, sptr &channel, -+ InputAttribute &attribute); -+ void StartInput(sptr &client); -+ void StopInput(sptr &client); -+ void ReleaseInput(sptr &client); -+ void WorkThread(); -+ -+ sptr mInputDataChannel; -+ sptr mClient; -+ sptr mImms; -+ sptr deathRecipient_; -+ sptr mAgent; -+ OnTextChangedListener *textListener; -+ InputAttribute mAttribute; -+ std::u16string mTextString; -+ int mSelectOldBegin = 0; -+ int mSelectOldEnd = 0; -+ int mSelectNewBegin = 0; -+ int mSelectNewEnd = 0; -+ CursorInfo cursorInfo_; -+ -+ static std::mutex instanceLock_; -+ static sptr instance_; -+ std::thread workThreadHandler; -+ MessageHandler *msgHandler; -+ bool stop_; -+ int32_t enterKeyType_ = 0; -+ int32_t inputPattern_ = 0; -+ }; -+} -+} -+#endif -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/inputmethod_controller/input_method_system_ability_proxy.h b/ohos_ndk_aosp/includes/inputmethod_controller/input_method_system_ability_proxy.h -new file mode 100644 -index 0000000000..5f1ef4704c ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_controller/input_method_system_ability_proxy.h -@@ -0,0 +1,65 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMC_PROJECT_INPUTMETHODSYSTEMABILITYPROXY_H -+#define FM_IMC_PROJECT_INPUTMETHODSYSTEMABILITYPROXY_H -+ -+#include -+#include "iremote_proxy.h" -+#include "i_input_method_system_ability.h" -+#include "message_parcel.h" -+#include "keyboard_type.h" -+#include "input_method_property.h" -+#include "input_client_stub.h" -+#include "input_data_channel_stub.h" -+#include "input_attribute.h" -+#include "global.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputDataChannelStub; -+ class InputMethodSystemAbilityProxy : public IRemoteProxy { -+ public: -+ explicit InputMethodSystemAbilityProxy(const sptr &object); -+ ~InputMethodSystemAbilityProxy() = default; -+ DISALLOW_COPY_AND_MOVE(InputMethodSystemAbilityProxy); -+ -+ virtual void prepareInput(MessageParcel& data) override; -+ virtual void releaseInput(MessageParcel& data) override; -+ virtual void startInput(MessageParcel& data) override; -+ virtual void stopInput(MessageParcel& data) override; -+ virtual void SetCoreAndAgent(MessageParcel& data) override; -+ virtual void HideCurrentInput(MessageParcel& data) override; -+ -+ int32_t Prepare(int32_t displayId, sptr &client, sptr &channel, -+ InputAttribute &attribute); -+ int32_t Release(sptr &client); -+ int32_t Start(sptr &client); -+ int32_t Stop(sptr &client); -+ -+ virtual void displayOptionalInputMethod(MessageParcel& data) override; -+ virtual int32_t getDisplayMode(int32_t retMode) override; -+ virtual int32_t getKeyboardWindowHeight(int32_t retHeight) override; -+ virtual int32_t getCurrentKeyboardType(KeyboardType *retType) override; -+ virtual int32_t listInputMethodEnabled(std::vector *properties) override; -+ virtual int32_t listInputMethod(std::vector *properties) override; -+ virtual int32_t listKeyboardType(const std::u16string& imeId, std::vector *types) override; -+ -+ private: -+ static inline BrokerDelegator delegator_; -+ }; -+} -+} -+#endif -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/inputmethod_controller/input_method_utils.h b/ohos_ndk_aosp/includes/inputmethod_controller/input_method_utils.h -new file mode 100644 -index 0000000000..5441014256 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_controller/input_method_utils.h -@@ -0,0 +1,127 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMC_PROJECT_INPUT_METHOD_UTILS_H -+#define FM_IMC_PROJECT_INPUT_METHOD_UTILS_H -+ -+#include -+ -+namespace OHOS { -+namespace MiscServices { -+ enum class EnterKeyType { -+ UNSPECIFIED = 0, -+ NONE, -+ GO, -+ SEARCH, -+ SEND, -+ NEXT, -+ DONE, -+ PREVIOUS -+ }; -+ -+ enum class TextInputType { -+ NONE = -1, -+ TEXT = 0, -+ MULTILINE, -+ NUMBER, -+ PHONE, -+ DATETIME, -+ EMAIL_ADDRESS, -+ URL, -+ VISIBLE_PASSWORD, -+ }; -+ -+ enum class Direction { -+ NONE = 0, -+ UP = 1, -+ DOWN, -+ LEFT, -+ RIGHT, -+ }; -+ -+ class Configuration { -+ public: -+ EnterKeyType GetEnterKeyType() const -+ { -+ return enterKeyType; -+ } -+ -+ void SetEnterKeyType(EnterKeyType keyType) -+ { -+ enterKeyType = keyType; -+ } -+ -+ TextInputType GetTextInputType() const -+ { -+ return textInputType; -+ } -+ -+ void SetTextInputType(TextInputType textType) -+ { -+ textInputType = textType; -+ } -+ -+ private: -+ EnterKeyType enterKeyType = EnterKeyType::UNSPECIFIED; -+ TextInputType textInputType = TextInputType::TEXT; -+ }; -+ -+ struct CursorInfo { -+ double left = 0.0; -+ double top = 0.0; -+ double width = 0.0; -+ double height = 0.0; -+ }; -+ -+ class KeyEvent { -+ }; -+ -+ enum class KeyboardStatus { -+ NONE = 0, -+ HIDE, -+ SHOW -+ }; -+ enum class FunctionKey { -+ NONE = 0, -+ CONFIRM -+ }; -+ class KeyboardInfo { -+ public: -+ KeyboardStatus GetKeyboardStatus() const -+ { -+ return keyboardStatus; -+ } -+ -+ void SetKeyboardStatus(int32_t status) -+ { -+ keyboardStatus = static_cast(status); -+ } -+ -+ FunctionKey GetFunctionKey() const -+ { -+ return functionKey; -+ } -+ -+ void SetFunctionKey(int32_t key) -+ { -+ functionKey = static_cast(key); -+ } -+ private: -+ KeyboardStatus keyboardStatus = KeyboardStatus::NONE; -+ FunctionKey functionKey = FunctionKey::NONE; -+ }; -+} -+} -+#endif // FM_IMC_PROJECT_INPUT_METHOD_UTILS_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/global.h b/ohos_ndk_aosp/includes/inputmethod_services/global.h -new file mode 100644 -index 0000000000..353e550905 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/global.h -@@ -0,0 +1,170 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_GLOBAL_H -+#define FM_IMMS_PROJECT_GLOBAL_H -+ -+#include -+#include -+#include -+#include "iremote_broker.h" -+#include "peer_holder.h" -+#include "ipc_object_stub.h" -+#include "refbase.h" -+#include "hilog/log.h" -+ -+namespace OHOS { -+namespace MiscServices { -+#define PLATFORM OHOS -+ -+using BRemoteObject = IPCObjectStub; -+ -+#define INPUTMETHOD_DEBUG 0 -+ -+#define LOG_INFO(fmt, args...) \ -+ LogTimeStamp(); printf("I %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args) -+ -+#define LOG_ERROR(fmt, args...) \ -+ LogTimeStamp(); printf("E %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args) -+ -+#define LOG_WARNING(fmt, args...) \ -+ LogTimeStamp(); printf("W %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args) -+ -+#if DEBUG -+#define LOG_DEBUG(fmt, args...) \ -+ LogTimeStamp(); printf("D %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args) -+#else -+#define LOG_DEBUG(fmt, args...) -+#endif -+ -+void LogTimeStamp(); -+ -+namespace CommonEvent { -+ // the events handled in input method management system -+ enum { -+ COMMON_EVENT_USER_STARTED = 10001, // a user is started. -+ COMMON_EVENT_USER_STOPPED = 10002, // a user is stopped. -+ COMMON_EVENT_USER_UNLOCKED = 10003, // a user is unlocked. -+ COMMON_EVENT_USER_LOCKED = 10004, // a user is locked. -+ COMMON_EVENT_SETTING_CHANGED = 10005, // input method setting data is changed. -+ COMMON_EVENT_PACKAGE_ADDED = 10006, // a package is installed. -+ COMMON_EVENT_PACKAGE_REMOVED = 10007, // a package is removed -+ }; -+}; -+ -+// User State -+namespace UserState { -+ // The states of a user in the system. -+ enum { -+ USER_STATE_NOT_AVAILABLE = -1, -+ USER_STATE_STARTED = 0, // a user is started. -+ USER_STATE_UNLOCKED, // a user is unlocked. -+ }; -+}; -+ -+// Error Code -+namespace ErrorCode { -+ // Error Code definition in the input method management system -+ enum { -+ ERROR_STATUS_UNKNOWN_ERROR = (-2147483647 - 1), // unknown error -+ ERROR_STATUS_NO_MEMORY = -ENOMEM, // no memory -+ ERROR_STATUS_INVALID_OPERATION = -ENOSYS, // invalid operation -+ ERROR_STATUS_BAD_VALUE = -EINVAL, // bad value -+ ERROR_STATUS_BAD_TYPE = ERROR_STATUS_UNKNOWN_ERROR + 1, // bad type -+ ERROR_STATUS_NAME_NOT_FOUND = -ENOENT, // name not found -+ ERROR_STATUS_PERMISSION_DENIED = -EPERM, // permission denied -+ ERROR_STATUS_NO_INIT = -ENODEV, // no init -+ ERROR_STATUS_ALREADY_EXISTS = -EEXIST, // already exist -+ ERROR_STATUS_DEAD_OBJECT = -EPIPE, // dead object -+ ERROR_STATUS_FAILED_TRANSACTION = ERROR_STATUS_UNKNOWN_ERROR + 2, // failed transaction -+ ERROR_STATUS_BAD_INDEX = -EOVERFLOW, // bad index -+ ERROR_STATUS_NOT_ENOUGH_DATA = -ENODATA, // not enough data -+ ERROR_STATUS_WOULD_BLOCK = -EWOULDBLOCK, // would block -+ ERROR_STATUS_TIMED_OUT = -ETIMEDOUT, // time out -+ ERROR_STATUS_UNKNOWN_TRANSACTION = -EBADMSG, // unknown transaction -+ ERROR_STATUS_FDS_NOT_ALLOWED = ERROR_STATUS_UNKNOWN_ERROR + 7, // fds not allowed -+ ERROR_STATUS_UNEXPECTED_NULL = ERROR_STATUS_UNKNOWN_ERROR + 8, // unexpected null, -+ -+ // binder exception error code from Status.h -+ ERROR_EX_ILLEGAL_ARGUMENT = -3, // illegal argument exception -+ ERROR_EX_NULL_POINTER = -4, // null pointer exception -+ ERROR_EX_ILLEGAL_STATE = -5, // illegal state exception -+ ERROR_EX_NETWORK_MAIN_THREAD = -6, // network main thread exception -+ ERROR_EX_UNSUPPORTED_OPERATION = -7, // unsupported operation exception -+ ERROR_EX_SERVICE_SPECIFIC = -8, // service specific exception -+ ERROR_EX_PARCELABLE = -9, // parcelable exception -+ // no error -+ NO_ERROR = 0, // no error -+ -+ // system service error -+ ERROR_NULL_POINTER, // null pointer -+ ERROR_BAD_PARAMETERS, // bad parameters -+ ERROR_SERVICE_START_FAILED, // failed to start service -+ ERROR_USER_NOT_STARTED, // user is not started -+ ERROR_USER_ALREADY_STARTED, // user has already started -+ ERROR_USER_NOT_UNLOCKED, // user is not unlocked -+ ERROR_USER_ALREADY_UNLOCKED, // user has already unlocked -+ ERROR_USER_NOT_LOCKED, // user is not locked -+ -+ ERROR_IME_NOT_AVAILABLE, // input method engine is not available -+ ERROR_SECURITY_IME_NOT_AVAILABLE, // security input method engine is not available -+ ERROR_TOKEN_CREATE_FAILED, // failed to create window token -+ ERROR_TOKEN_DESTROY_FAILED, // failed to destroy window token -+ ERROR_IME_BIND_FAILED, // failed to bind IME service -+ ERROR_IME_UNBIND_FAILED, // failed to unbind IME service -+ ERROR_IME_START_FAILED, // failed to start IME service -+ ERROR_IME_STOP_FAILED, // failed to stop IME service -+ ERROR_KBD_SHOW_FAILED, // failed to show keyboard -+ ERROR_KBD_HIDE_FAILED, // failed to hide keyboard -+ ERROR_IME_NOT_STARTED, // input method service is not started -+ ERROR_KBD_IS_OCCUPIED, // keyboard is showing by other client -+ ERROR_KBD_IS_NOT_SHOWING, // keyboard is not showing -+ ERROR_IME_ALREADY_STARTED, // input method service has already started -+ ERROR_NOT_IME_PACKAGE, // not an IME package -+ ERROR_IME_PACKAGE_DUPLICATED, // duplicated IME package -+ ERROR_SETTING_SAME_VALUE, // same setting value -+ ERROR_NO_NEXT_IME, // no next ime is available -+ ERROR_CLIENTWINDOW_NOT_FOCUSED, // the input client window is not focused -+ ERROR_CLIENT_NOT_WINDOW, // the input client is not from a valid window -+ // error from ime -+ ERROR_REMOTE_IME_DIED, // remote input method service died abnormally -+ ERROR_RESTART_IME_FAILED, // failed to restart input method service -+ // error from client -+ ERROR_REMOTE_CLIENT_DIED, // remote client died abnormally -+ ERROR_CLIENT_DUPLICATED, // duplicated client -+ ERROR_CLIENT_NOT_FOUND, // client is not found -+ }; -+ const char* ToString(int errorCode); -+}; -+ -+static constexpr HiviewDFX::HiLogLabel g_SMALL_SERVICES_LABEL = { -+ LOG_CORE, -+ 0xD001C00, -+ "ImsaKit" -+}; -+ -+#define IMSA_HILOGD(fmt, ...) (void)OHOS::HiviewDFX::HiLog::Debug(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \ -+ "line: %d, function: %s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__) -+#define IMSA_HILOGE(fmt, ...) (void)OHOS::HiviewDFX::HiLog::Error(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \ -+ "line: %d, function: %s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__) -+#define IMSA_HILOGF(fmt, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \ -+ "line: %d, function: %s," fmt, __LINE__FILE__, __FUNCTION__, ##__VA_ARGS__) -+#define IMSA_HILOGI(fmt, ...) (void)OHOS::HiviewDFX::HiLog::Info(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \ -+ "line: %d, function: %s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__) -+#define IMSA_HILOGW(fmt, ...) (void)OHOS::HiviewDFX::HiLog::Warn(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \ -+ "line: %d, function: %s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__) -+} -+} -+#endif // FM_IMMS_PROJECT_GLOBAL_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/i_input_control_channel.h b/ohos_ndk_aosp/includes/inputmethod_services/i_input_control_channel.h -new file mode 100644 -index 0000000000..7fd71af1b5 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/i_input_control_channel.h -@@ -0,0 +1,44 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_IINPUTCONTROLCHANNEL_H -+#define FM_IMMS_PROJECT_IINPUTCONTROLCHANNEL_H -+ -+#include "iremote_broker.h" -+#include "input_channel.h" -+#include "i_input_method_agent.h" -+#include "global.h" -+ -+namespace OHOS { -+ namespace MiscServices { -+ class IInputControlChannel : public IRemoteBroker { -+ public: -+ enum { -+ HIDE_KEYBOARD_SELF = FIRST_CALL_TRANSACTION, -+ ADVANCE_TO_NEXT, -+ SET_DISPLAY_MODE, -+ ON_KEYBOARD_SHOWED, -+ }; -+ -+ DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.InputControlChannel"); -+ -+ virtual void hideKeyboardSelf(int flags) = 0; -+ virtual bool advanceToNext(bool isCurrentIme) = 0; -+ virtual void setDisplayMode(int mode) = 0; -+ virtual void onKeyboardShowed() = 0; -+ }; -+ } -+} -+#endif // FM_IMMS_PROJECT_IINPUTCONTROLCHANNEL_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/i_input_method_system_ability.h b/ohos_ndk_aosp/includes/inputmethod_services/i_input_method_system_ability.h -new file mode 100644 -index 0000000000..d688d98a9b ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/i_input_method_system_ability.h -@@ -0,0 +1,71 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_IINPUTMETHODSYSTEMABILITY_H -+#define FM_IMMS_PROJECT_IINPUTMETHODSYSTEMABILITY_H -+ -+#include -+#include -+#include "iremote_broker.h" -+#include "i_input_client.h" -+#include "i_input_data_channel.h" -+#include "input_attribute.h" -+#include "input_method_property.h" -+#include "keyboard_type.h" -+#include "global.h" -+#include "message_parcel.h" -+#include "i_input_method_core.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class IInputMethodSystemAbility : public IRemoteBroker { -+ public: -+ enum { -+ PREPARE_INPUT = 0, -+ RELEASE_INPUT, -+ START_INPUT, -+ STOP_INPUT, -+ HIDE_CURRENT_INPUT, -+ SET_INPUT_METHOD_CORE, -+ GET_DISPLAY_MODE, -+ GET_KEYBOARD_WINDOW_HEIGHT, -+ GET_CURRENT_KEYBOARD_TYPE, -+ LIST_INPUT_METHOD_ENABLED, -+ LIST_INPUT_METHOD, -+ LIST_KEYBOARD_TYPE, -+ SET_CORE_AND_AGENT, -+ DISPLAY_OPTIONAL_INPUT_METHOD, -+ }; -+ -+ DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputMethodSystemAbility"); -+ -+ virtual void prepareInput(MessageParcel& data) = 0; -+ virtual void releaseInput(MessageParcel& data) = 0; -+ virtual void startInput(MessageParcel& data) = 0; -+ virtual void stopInput(MessageParcel& data) = 0; -+ virtual void SetCoreAndAgent(MessageParcel& data) = 0; -+ virtual void HideCurrentInput(MessageParcel& data) = 0; -+ -+ virtual void displayOptionalInputMethod(MessageParcel& data) = 0; -+ virtual int32_t getDisplayMode(int32_t retMode) = 0; -+ virtual int32_t getKeyboardWindowHeight(int32_t retHeight) = 0; -+ virtual int32_t getCurrentKeyboardType(KeyboardType *retType) = 0; -+ virtual int32_t listInputMethodEnabled(std::vector *properties) = 0; -+ virtual int32_t listInputMethod(std::vector *properties) = 0; -+ virtual int32_t listKeyboardType(const std::u16string& imeId, std::vector *types) = 0; -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_IINPUTMETHODSYSTEMABILITY_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/i_platform_api.h b/ohos_ndk_aosp/includes/inputmethod_services/i_platform_api.h -new file mode 100644 -index 0000000000..006b03955c ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/i_platform_api.h -@@ -0,0 +1,62 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_IPLATFORMAPI_H -+#define FM_IMMS_PROJECT_IPLATFORMAPI_H -+ -+#include -+#include -+#include "iremote_broker.h" -+#include "ipc_types.h" -+ -+#include "i_platform_callback.h" -+#include "input_method_property.h" -+#include "input_method_setting.h" -+#include "i_input_method_core.h" -+#include "global.h" -+ -+namespace OHOS { -+ namespace MiscServices { -+ class IPlatformApi : public IRemoteBroker { -+ public: -+ enum { -+ REGISTER_CALLBACK = FIRST_CALL_TRANSACTION, -+ BIND_IMS, -+ UNBIND_IMS, -+ CREATE_WINDOW_TOKEN, -+ DESTROY_WINDOW_TOKEN, -+ LIST_INPUT_METHOD, -+ GET_INPUT_METHOD_PROPERTY, -+ GET_INPUT_METHOD_SETTING, -+ SET_INPUT_METHOD_SETTING, -+ }; -+ -+ DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IPlatformApi"); -+ -+ virtual int32_t registerCallback(const sptr& cb) = 0; -+ virtual sptr bindInputMethodService(const std::u16string& packageName, -+ const std::u16string& intention, int userId) = 0; -+ virtual int32_t unbindInputMethodService(int userId, const std::u16string& packageName) = 0; -+ virtual sptr createWindowToken(int userId, int displayId, const std::u16string& packageName) = 0; -+ virtual int32_t destroyWindowToken(int userId, const std::u16string& packageName) = 0; -+ virtual int32_t listInputMethod(int userId, std::vector *properties) = 0; -+ virtual int32_t getInputMethodProperty(int userId, const std::u16string& packageName, -+ InputMethodProperty *inputMethodProperty) = 0; -+ virtual int32_t getInputMethodSetting(int userId, InputMethodSetting *inputMethodSetting) = 0; -+ virtual int32_t setInputMethodSetting(int userId, const InputMethodSetting& inputMethodSetting) = 0; -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_IPLATFORMAPI_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/i_platform_callback.h b/ohos_ndk_aosp/includes/inputmethod_services/i_platform_callback.h -new file mode 100644 -index 0000000000..2c94b538b4 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/i_platform_callback.h -@@ -0,0 +1,39 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_IPLATFORMCALLBACK_H -+#define FM_IMMS_PROJECT_IPLATFORMCALLBACK_H -+ -+#include -+#include -+#include "iremote_broker.h" -+#include "ipc_types.h" -+#include "global.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class IPlatformCallback : public IRemoteBroker { -+ public: -+ enum { -+ NOTIFY_EVENT = OHOS::FIRST_CALL_TRANSACTION, -+ }; -+ -+ DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IPlatformCallback"); -+ -+ virtual void notifyEvent(int eventId, int userId, const std::vector& eventContent) = 0; -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_IPLATFORMCALLBACK_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/im_common_event_manager.h b/ohos_ndk_aosp/includes/inputmethod_services/im_common_event_manager.h -new file mode 100644 -index 0000000000..4b7e0d6b10 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/im_common_event_manager.h -@@ -0,0 +1,49 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_IMCOMMONEVENTMANAGER_H -+#define FM_IMMS_PROJECT_IMCOMMONEVENTMANAGER_H -+ -+#include -+#include "common_event_subscriber.h" -+#include "common_event_subscribe_info.h" -+#include "common_event_data.h" -+#include "matching_skills.h" -+ -+namespace OHOS { -+namespace MiscServices { -+class ImCommonEventManager : public RefBase { -+public: -+ ImCommonEventManager(); -+ ~ImCommonEventManager(); -+ static sptr GetInstance(); -+ bool SubscribeEvent(const std::string &event); -+ bool UnsubscribeEvent(); -+ -+ class EventSubscriber : public EventFwk::CommonEventSubscriber { -+ public: -+ EventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo) -+ : EventFwk::CommonEventSubscriber(subscribeInfo) {} -+ void OnReceiveEvent(const EventFwk::CommonEventData &data); -+ void startUser(int32_t newUserId); -+ }; -+ -+private: -+ static std::mutex instanceLock_; -+ static sptr instance_; -+}; -+} // namespace MiscServices -+} // namespace OHOS -+#endif // FM_IMMS_PROJECT_IPLATFORMCALLBACK_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/input_attribute.h b/ohos_ndk_aosp/includes/inputmethod_services/input_attribute.h -new file mode 100644 -index 0000000000..a2912391c8 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/input_attribute.h -@@ -0,0 +1,42 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_INPUTATTRIBUTE_H -+#define FM_IMMS_PROJECT_INPUTATTRIBUTE_H -+#include "parcel.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputAttribute : public Parcelable { -+ public: -+ InputAttribute(); -+ InputAttribute(const InputAttribute& attribute); -+ InputAttribute& operator =(const InputAttribute& attribute); -+ ~InputAttribute(); -+ virtual bool Marshalling(Parcel &parcel) const override; -+ static InputAttribute *Unmarshalling(Parcel &parcel); -+ void SetInputPattern(int32_t pattern); -+ bool GetSecurityFlag(); -+ static const int32_t PATTERN_TEXT = 0x00000001; -+ static const int32_t PATTERN_PASSWORD = 0x00000007; -+ private: -+ int32_t inputPattern; -+ int32_t enterKeyType; -+ int32_t inputOption; -+ }; -+} -+} -+ -+#endif // FM_IMMS_PROJECT_INPUTATTRIBUTE_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/input_channel.h b/ohos_ndk_aosp/includes/inputmethod_services/input_channel.h -new file mode 100644 -index 0000000000..c22a79de6c ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/input_channel.h -@@ -0,0 +1,39 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT__INPUTCHANNEL_H -+#define FM_IMMS_PROJECT__INPUTCHANNEL_H -+#include -+#include "parcel.h" -+#include "global.h" -+#include "message_parcel.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputChannel : public Parcelable { -+ public: -+ InputChannel(); -+ ~InputChannel(); -+ virtual bool Marshalling(Parcel &parcel) const override; -+ static InputChannel *Unmarshalling(Parcel &parcel); -+ private: -+ std::u16string name; -+ MessageParcel inputChannelParcel; -+ InputChannel(const InputChannel& channel); -+ InputChannel& operator =(const InputChannel& channel); -+ }; -+} -+} -+#endif // INPUTMETHODSYSTEMSERVICE_INPUTCHANNEL_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/input_control_channel_proxy.h b/ohos_ndk_aosp/includes/inputmethod_services/input_control_channel_proxy.h -new file mode 100644 -index 0000000000..fca53776d9 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/input_control_channel_proxy.h -@@ -0,0 +1,43 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_INPUTCONTROLCHANNELPROXY_H -+#define FM_IMMS_PROJECT_INPUTCONTROLCHANNELPROXY_H -+ -+#include "parcel.h" -+#include "iremote_broker.h" -+#include "message_parcel.h" -+#include "message_handler.h" -+ -+#include "global.h" -+#include "iremote_proxy.h" -+#include "i_input_control_channel.h" -+#include "i_input_method_agent.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputControlChannelProxy : public IRemoteProxy { -+ public: -+ InputControlChannelProxy(const sptr &impl); -+ ~InputControlChannelProxy(); -+ -+ virtual void hideKeyboardSelf(int flags) override; -+ virtual bool advanceToNext(bool isCurrentIme) override; -+ virtual void setDisplayMode(int mode) override; -+ virtual void onKeyboardShowed() override; -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_INPUTCONTROLCHANNELPROXY_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/input_control_channel_stub.h b/ohos_ndk_aosp/includes/inputmethod_services/input_control_channel_stub.h -new file mode 100644 -index 0000000000..15ea287bcd ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/input_control_channel_stub.h -@@ -0,0 +1,56 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_INPUTCONTROLCHANNELSTUB_H -+#define FM_IMMS_PROJECT_INPUTCONTROLCHANNELSTUB_H -+ -+#include -+#include -+#include "iremote_broker.h" -+#include "iremote_stub.h" -+#include "i_input_method_agent.h" -+#include "input_channel.h" -+#include "message_parcel.h" -+#include "i_input_control_channel.h" -+ -+namespace OHOS { -+ namespace MiscServices { -+ class InputControlChannelStub : public IRemoteStub { -+ public: -+ explicit InputControlChannelStub(int userId); -+ virtual ~InputControlChannelStub(); -+ virtual int OnRemoteRequest(uint32_t code, -+ MessageParcel &data, -+ MessageParcel &reply, -+ MessageOption &option) override; -+ virtual void hideKeyboardSelf(int flags) override; -+ virtual bool advanceToNext(bool isCurrentIme) override; -+ virtual void setDisplayMode(int mode) override; -+ virtual void onKeyboardShowed() override; -+ -+ void ResetFlag(); -+ bool WaitKeyboardReady(); -+ private: -+ int userId_; -+ -+ std::mutex mtx; -+ std::condition_variable cv; -+ bool agentReadyFlag = false; -+ bool keyboardReadyFlag = false; -+ const int32_t sleepTime = 300; -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_INPUTCONTROLCHANNELSTUB_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/input_method_ability_connection_stub.h b/ohos_ndk_aosp/includes/inputmethod_services/input_method_ability_connection_stub.h -new file mode 100644 -index 0000000000..bc4426127c ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/input_method_ability_connection_stub.h -@@ -0,0 +1,46 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+#ifndef SERVICES_INPUTMETHODABILITYCONNECTIONSTUB_H -+#define SERVICES_INPUTMETHODABILITYCONNECTIONSTUB_H -+#include "ability_connect_callback_stub.h" -+#include "want.h" -+#include "element_name.h" -+#include "message_handler.h" -+#include "iremote_object.h" -+#include "global.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputMethodAbilityConnectionStub : public AAFwk::AbilityConnectionStub { -+ public: -+ enum MessageID { -+ MSG_ID_ABILITY_CONNECT_DONE = 1, -+ MSG_ID_ABILITY_DISCONNECT_DONE, -+ }; -+ -+ InputMethodAbilityConnectionStub(const int index); -+ ~InputMethodAbilityConnectionStub(); -+ void OnAbilityConnectDone(const AppExecFwk::ElementName &element, -+ const sptr &remoteObject, int resultCode) override; -+ void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; -+ void SetHandler(MessageHandler *handler); -+ -+ private: -+ MessageHandler *messageHandler; -+ int mIndex; -+ }; -+} -+} -+#endif // SERVICES_INPUTMETHODABILITYCONNECTIONSTUB_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/input_method_property.h b/ohos_ndk_aosp/includes/inputmethod_services/input_method_property.h -new file mode 100644 -index 0000000000..c87be3eb46 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/input_method_property.h -@@ -0,0 +1,48 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_INPUTMETHODPROPERTY_H -+#define FM_IMMS_PROJECT_INPUTMETHODPROPERTY_H -+#include -+#include -+#include "parcel.h" -+#include "keyboard_type.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputMethodProperty : public Parcelable { -+ public: -+ std::u16string mImeId; -+ std::u16string mPackageName; -+ std::u16string mAbilityName; -+ std::u16string mConfigurationPage; -+ bool isSystemIme; -+ int32_t mDefaultImeId; -+ std::vector mTypes; -+ int32_t labelId; -+ int32_t descriptionId; -+ std::u16string label; -+ std::u16string description; -+ -+ InputMethodProperty(); -+ ~InputMethodProperty(); -+ InputMethodProperty(const InputMethodProperty& property); -+ InputMethodProperty& operator =(const InputMethodProperty& property); -+ virtual bool Marshalling(Parcel &parcel) const override; -+ static InputMethodProperty *Unmarshalling(Parcel &parcel); -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_INPUTMETHODPROPERTY_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/input_method_setting.h b/ohos_ndk_aosp/includes/inputmethod_services/input_method_setting.h -new file mode 100644 -index 0000000000..0594a12457 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/input_method_setting.h -@@ -0,0 +1,70 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_INPUTMETHODSETTING_H -+#define FM_IMMS_PROJECT_INPUTMETHODSETTING_H -+#include -+#include -+#include "string.h" -+#include "global.h" -+#include "parcel.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputMethodSetting : public Parcelable { -+ public: -+ -+ const static std::u16string CURRENT_INPUT_METHOD_TAG; // default IME -+ const static std::u16string ENABLED_INPUT_METHODS_TAG; // enabled IME list -+ const static std::u16string CURRENT_KEYBOARD_TYPE_TAG; // default keyboard type -+ const static std::u16string CURRENT_SYS_KEYBOARD_TYPE_TAG; // default keyboard type for security IME -+ const static std::u16string SYSTEM_LOCALE_TAG; // locale list supported in the system -+ -+ InputMethodSetting(); -+ ~InputMethodSetting(); -+ InputMethodSetting(const InputMethodSetting& inputMethodSetting); -+ InputMethodSetting& operator =(const InputMethodSetting& inputMethodSetting); -+ -+ void SetValue(const std::u16string& key, const std::u16string& value); -+ std::u16string GetValue(const std::u16string& key) const; -+ -+ std::u16string GetCurrentInputMethod() const; -+ void SetCurrentInputMethod(const std::u16string& imeId); -+ -+ std::vector GetEnabledInputMethodList(); -+ bool AddEnabledInputMethod(const std::u16string& imeId, const std::vector& types); -+ bool RemoveEnabledInputMethod(const std::u16string& imdId); -+ -+ std::vector GetEnabledKeyboardTypes(const std::u16string& imeId); -+ int32_t GetCurrentKeyboardType(); -+ void SetCurrentKeyboardType(int32_t type); -+ int32_t GetCurrentSysKeyboardType(); -+ void SetCurrentSysKeyboardType(int32_t type); -+ void ClearData(); -+ bool FindKey(const std::u16string& key) const; -+ -+ virtual bool Marshalling(Parcel &parcel) const override; -+ static InputMethodSetting *Unmarshalling(Parcel &parcel); -+ -+ private: -+ std::map setting; -+ const char16_t DELIM_IME = ':'; -+ const char16_t DELIM_KBD_TYPE = ';'; -+ std::vector Split(const std::u16string& str, char16_t delim); -+ std::u16string BuildString(const std::vector& vector, char16_t delim); -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_INPUTMETHODSETTING_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/input_method_system_ability.h b/ohos_ndk_aosp/includes/inputmethod_services/input_method_system_ability.h -new file mode 100644 -index 0000000000..01beb52adc ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/input_method_system_ability.h -@@ -0,0 +1,101 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_INPUTMETHODSYSTEMABILITY_H -+#define FM_IMMS_PROJECT_INPUTMETHODSYSTEMABILITY_H -+ -+#include -+#include -+#include "system_ability.h" -+#include "input_method_system_ability_stub.h" -+#include "peruser_setting.h" -+#include "peruser_session.h" -+#include "event_handler.h" -+#include "bundle_mgr_proxy.h" -+#include "ability_manager_interface.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputDataChannelStub; -+ enum class ServiceRunningState { -+ STATE_NOT_START, -+ STATE_RUNNING -+ }; -+ -+ class InputMethodSystemAbility : public SystemAbility, public InputMethodSystemAbilityStub { -+ DECLARE_SYSTEM_ABILITY(InputMethodSystemAbility); -+ public: -+ DISALLOW_COPY_AND_MOVE(InputMethodSystemAbility); -+ InputMethodSystemAbility(int32_t systemAbilityId, bool runOnCreate); -+ InputMethodSystemAbility(); -+ ~InputMethodSystemAbility(); -+ static sptr GetInstance(); -+ -+ int32_t GetUserState(int32_t userId); -+ -+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, -+ MessageOption &option) override; -+ virtual int32_t getDisplayMode(int32_t retMode) override; -+ virtual int32_t getKeyboardWindowHeight(int32_t retHeight) override; -+ virtual int32_t getCurrentKeyboardType(KeyboardType *retType) override; -+ virtual int32_t listInputMethodEnabled(std::vector *properties) override; -+ virtual int32_t listInputMethod(std::vector *properties) override; -+ virtual int32_t listInputMethodByUserId(int32_t userId, std::vector *properties) override; -+ virtual int32_t listKeyboardType(const std::u16string& imeId, std::vector *types) override; -+ protected: -+ void OnStart() override; -+ void OnStop() override; -+ private: -+ int32_t Init(); -+ void Initialize(); -+ -+ std::thread workThreadHandler; /*!< thread handler of the WorkThread */ -+ -+ std::map userSettings; -+ -+ std::map userSessions; -+ std::map msgHandlers; -+ -+ void WorkThread(); -+ PerUserSetting *GetUserSetting(int32_t userId); -+ PerUserSession *GetUserSession(int32_t userId); -+ void StartInputService(std::string imeId); -+ void StopInputService(std::string imeId); -+ int32_t OnUserStarted(const Message *msg); -+ int32_t OnUserStopped(const Message *msg); -+ int32_t OnUserUnlocked(const Message *msg); -+ int32_t OnUserLocked(const Message *msg); -+ int32_t OnHandleMessage(Message *msg); -+ int32_t OnRemotePeerDied(const Message *msg); -+ int32_t OnSettingChanged(const Message *msg); -+ int32_t OnPackageRemoved(const Message *msg); -+ int32_t OnPackageAdded(const Message *msg); -+ int32_t OnDisableIms(const Message *msg); -+ int32_t OnAdvanceToNext(const Message *msg); -+ void OnDisplayOptionalInputMethod(int32_t userId); -+ static sptr GetAbilityManagerService(); -+ OHOS::sptr GetBundleMgr(); -+ void StartUserIdListener(); -+ -+ ServiceRunningState state_; -+ void InitServiceHandler(); -+ static std::mutex instanceLock_; -+ static sptr instance_; -+ static std::shared_ptr serviceHandler_; -+ int32_t userId_; -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_INPUTMETHODSYSTEMABILITY_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/input_method_system_ability_stub.h b/ohos_ndk_aosp/includes/inputmethod_services/input_method_system_ability_stub.h -new file mode 100644 -index 0000000000..df92a0245f ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/input_method_system_ability_stub.h -@@ -0,0 +1,47 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_INPUTMETHODSYSTEMABILITY_SK_H -+#define FM_IMMS_PROJECT_INPUTMETHODSYSTEMABILITY_SK_H -+#include -+#include "refbase.h" -+#include "i_input_method_system_ability.h" -+#include "iremote_stub.h" -+#include "global.h" -+#include "message_parcel.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class InputMethodSystemAbilityStub : public IRemoteStub { -+ public: -+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, -+ MessageOption &option) override; -+ -+ virtual void prepareInput(MessageParcel& data) override; -+ virtual void releaseInput(MessageParcel& data) override; -+ virtual void startInput(MessageParcel& data) override; -+ virtual void stopInput(MessageParcel& data) override; -+ virtual void SetCoreAndAgent(MessageParcel& data) override; -+ virtual void HideCurrentInput(MessageParcel& data) override; -+ virtual void displayOptionalInputMethod(MessageParcel& data) override; -+ virtual int32_t listInputMethodByUserId(int32_t userId, std::vector *properties) = 0; -+ protected: -+ int32_t getUserId(int32_t uid); -+ int USER_ID_CHANGE_VALUE = 200000; // user range -+ }; -+} -+} -+ -+#endif // FM_IMMS_PROJECT_INPUTMETHODSYSTEMABILITY_SK_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/keyboard_type.h b/ohos_ndk_aosp/includes/inputmethod_services/keyboard_type.h -new file mode 100644 -index 0000000000..abd5b8e078 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/keyboard_type.h -@@ -0,0 +1,63 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_KEYBOARDTYPE_H -+#define FM_IMMS_PROJECT_KEYBOARDTYPE_H -+ -+#include -+#include -+#include "parcel.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class KeyboardType : public Parcelable { -+ public: -+ KeyboardType(); -+ KeyboardType(const KeyboardType& type); -+ ~KeyboardType(); -+ KeyboardType& operator =(const KeyboardType& type); -+ virtual bool Marshalling(Parcel &parcel) const override; -+ static KeyboardType *Unmarshalling(Parcel &parcel); -+ void setId(int32_t typeId); -+ void setLabelId(int32_t labelId); -+ void setIconId(int32_t iconId); -+ void setAsciiCapability(bool isAsciiCapable); -+ void setLanguage(std::u16string language); -+ void setInputSource(std::u16string inputSource); -+ void setCustomizedValue(std::u16string customizedValue); -+ int32_t getId() const; -+ int32_t getLabelId() const; -+ int32_t getIconId() const; -+ int32_t getHashCode() const; -+ std::u16string getLanguage() const; -+ std::u16string getInputSource() const; -+ std::u16string getCustomizedValue() const; -+ bool supportsAscii(); -+ -+ private: -+ int32_t mId; -+ int32_t mHashCode; -+ int32_t mLabelId; -+ int32_t mIconId; -+ bool mIsAsciiCapable; -+ std::u16string mLanguage; -+ std::u16string mInputSource; -+ std::u16string mCustomizedValue; -+ -+ const int32_t ID_NONE = 0; -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_KEYBOARDTYPE_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/message.h b/ohos_ndk_aosp/includes/inputmethod_services/message.h -new file mode 100644 -index 0000000000..9f7cc3a969 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/message.h -@@ -0,0 +1,39 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+/*! \file MessageHandler.h */ -+#ifndef FM_IMMS_PROJECT_MESSAGE_H -+#define FM_IMMS_PROJECT_MESSAGE_H -+ -+#include "global.h" -+#include "message_parcel.h" -+namespace OHOS { -+namespace MiscServices { -+ class Message { -+ public: -+ int32_t msgId_; // message id -+ MessageParcel *msgContent_ = nullptr; // message content -+ Message(int32_t msgId, MessageParcel *msgContent); -+ explicit Message(const Message& msg); -+ Message& operator =(const Message& msg); -+ ~Message(); -+ private: -+ Message(const Message&&); -+ Message& operator =(const Message&&); -+ }; -+} -+} -+ -+#endif // FM_IMMS_PROJECT_MESSAGE_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/message_handler.h b/ohos_ndk_aosp/includes/inputmethod_services/message_handler.h -new file mode 100644 -index 0000000000..9d05044903 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/message_handler.h -@@ -0,0 +1,109 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+/*! \file MessageHandler.h */ -+#ifndef FM_IMMS_PROJECT_MESSAGEHANDLER_H -+#define FM_IMMS_PROJECT_MESSAGEHANDLER_H -+ -+#include -+#include -+#include -+#include "global.h" -+#include "message_parcel.h" -+#include "message.h" -+ -+namespace OHOS { -+namespace MiscServices { -+namespace MessageID { -+ enum { -+ // for system broadcast -+ MSG_ID_SYSTEM_START = 0, // system started -+ MSG_ID_SYSTEM_STOP, // system stopped -+ MSG_ID_USER_START, // a user started -+ MSG_ID_USER_STOP, // a user stopped -+ MSG_ID_USER_UNLOCK, // a user unlocked -+ MSG_ID_USER_LOCK, // a user locked -+ MSG_ID_PACKAGE_ADDED, // a package is installed -+ MSG_ID_PACKAGE_REMOVED, // a package is removed -+ MSG_ID_SETTING_CHANGED, // input method setting is changed -+ -+ // the request from client -+ MSG_ID_PREPARE_INPUT, // prepare input -+ MSG_ID_START_INPUT, // start input -+ MSG_ID_STOP_INPUT, // stop input -+ MSG_ID_RELEASE_INPUT, // release input -+ MSG_ID_SET_CORE_AND_AGENT, -+ MSG_HIDE_CURRENT_INPUT, -+ -+ // the request to handle the condition that the remote object died -+ MSG_ID_CLIENT_DIED, // input client died -+ MSG_ID_IMS_DIED, // input method service died -+ MSG_ID_DISABLE_IMS, // disable input method service -+ MSG_ID_RESTART_IMS, // restart input method service -+ MSG_ID_HIDE_KEYBOARD_SELF, // hide the current keyboard -+ MSG_ID_DISPLAY_OPTIONAL_INPUT_METHOD, -+ MSG_ID_ADVANCE_TO_NEXT, // switch to next -+ MSG_ID_SET_DISPLAY_MODE, // set display mode -+ -+ MSG_ID_SHELL_COMMAND, // shell command -+ MSG_ID_EXIT_SERVICE, // exit service -+ -+ // the request from IMSA to IMC -+ MSG_ID_INSERT_CHAR, -+ MSG_ID_DELETE_FORWARD, -+ MSG_ID_DELETE_BACKWARD, -+ MSG_ID_CLOSE, -+ MSG_ID_ON_INPUT_READY, -+ MSG_ID_SEND_KEYBOARD_STATUS, -+ MSG_ID_SEND_FUNCTION_KEY, -+ MSG_ID_MOVE_CURSOR, -+ -+ // the request from IMSA to IMA -+ MSG_ID_SET_CLIENT_STATE, -+ MSG_ID_SHOW_KEYBOARD, -+ MSG_ID_INITIALIZE_INPUT, -+ MSG_ID_HIDE_KEYBOARD, -+ MSG_ID_SET_KEYBOARD_TYPE, -+ MSG_ID_STOP_INPUT_SERVICE, -+ MSG_ID_GET_KEYBOARD_WINDOW_HEIGHT, -+ MSG_ID_INIT_INPUT_CONTROL_CHANNEL, -+ -+ // the request from IMC to IMA -+ MSG_ID_ON_CURSOR_UPDATE, -+ MSG_ID_ON_SELECTION_CHANGE, -+ }; -+} -+ -+ class MessageHandler { -+ public: -+ MessageHandler(); -+ ~MessageHandler(); -+ void SendMessage(Message *msg); -+ Message *GetMessage(); -+ static MessageHandler *Instance(); -+ -+ private: -+ std::mutex mMutex; // a mutex to guard message queue -+ std::condition_variable mCV; // condition variable to work with mMutex -+ std::queue mQueue; // Message queue, guarded by mMutex; -+ -+ MessageHandler(const MessageHandler&); -+ MessageHandler& operator =(const MessageHandler&); -+ MessageHandler(const MessageHandler&&); -+ MessageHandler& operator =(const MessageHandler&&); -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_MESSAGEHANDLER_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/peruser_session.h b/ohos_ndk_aosp/includes/inputmethod_services/peruser_session.h -new file mode 100644 -index 0000000000..c9e470c0d7 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/peruser_session.h -@@ -0,0 +1,191 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_PERUSERSESSION_H -+#define FM_IMMS_PROJECT_PERUSERSESSION_H -+ -+#include -+#include -+#include -+#include -+ -+#include "iremote_object.h" -+#include "i_input_control_channel.h" -+#include "i_input_client.h" -+#include "i_input_method_core.h" -+#include "i_input_data_channel.h" -+#include "i_input_method_agent.h" -+#include "input_attribute.h" -+#include "input_method_property.h" -+#include "input_method_setting.h" -+#include "input_control_channel_stub.h" -+#include "message.h" -+#include "message_handler.h" -+#include "global.h" -+#include "platform.h" -+#include "keyboard_type.h" -+#include "ability_manager_interface.h" -+#include "ability_connect_callback_proxy.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class RemoteObjectDeathRecipient : public IRemoteObject::DeathRecipient { -+ public: -+ RemoteObjectDeathRecipient(int userId, int msgId); -+ ~RemoteObjectDeathRecipient(); -+ void OnRemoteDied(const wptr& who) override; -+ private: -+ int userId_; // the id of the user to whom the object is linking -+ int msgId_; // the message id can be MessageID::MSG_ID_CLIENT_DIED and MessageID::MSG_ID_IMS_DIED -+ }; -+ -+ /*! \class ClientInfo -+ \brief The class defines the details of an input client. -+ */ -+ class ClientInfo { -+ public: -+ int pid; // the process id of the process in which the input client is running -+ int uid; // the uid of the process in which the input client is running -+ int userId; // the user if of the user under which the input client is running -+ int displayId; // the display id on which the input client is showing -+ sptr client; // the remote object handler for the service to callback to the input client -+ sptr channel; // the remote object handler for IMSA callback to input client -+ InputAttribute attribute; // the input attribute of the input client -+ -+ ClientInfo(int pid, int uid, int userId, int displayId, const sptr& client, -+ const sptr& channel, const InputAttribute& attribute) -+ { -+ this->pid = pid; -+ this->uid = uid; -+ this->userId = userId; -+ this->displayId = displayId; -+ this->client = client; -+ this->channel = channel; -+ this->attribute = attribute; -+ }; -+ -+ ~ClientInfo() -+ { -+ this->client = nullptr; -+ this->channel = nullptr; -+ }; -+ }; -+ -+ /*! \class PerUserSession -+ \brief The class provides session management in input method management service -+ -+ This class manages the sessions between input clients and input method engines for each unlocked user. -+ */ -+ class PerUserSession { -+ enum { -+ DEFAULT_IME = 0, // index for default input method service -+ SECURITY_IME = 1, // index for security input method service -+ MAX_IME = 2, // the maximum count of ims started for a user -+ }; -+ -+ public: -+ explicit PerUserSession(int userId); -+ ~PerUserSession(); -+ -+ void SetCurrentIme(InputMethodProperty *ime); -+ void SetSecurityIme(InputMethodProperty *ime); -+ void SetInputMethodSetting(InputMethodSetting *setting); -+ void ResetIme(InputMethodProperty *defaultIme, InputMethodProperty *securityIme); -+ void OnPackageRemoved(const std::u16string& packageName); -+ -+ int GetDisplayMode(); -+ int GetKeyboardWindowHeight(int retHeight); -+ KeyboardType *GetCurrentKeyboardType(); -+ -+ int OnSettingChanged(const std::u16string& key, const std::u16string& value); -+ void CreateWorkThread(MessageHandler& handler); -+ void JoinWorkThread(); -+ void StopInputService(std::string imeId); -+ static bool StartInputService(); -+ private: -+ int userId_; // the id of the user to whom the object is linking -+ int userState; // the state of the user to whom the object is linking -+ int displayId; // the id of the display screen on which the user is -+ int currentIndex; -+ std::map, ClientInfo*> mapClients; -+ int MIN_IME = 2; -+ int IME_ERROR_CODE = 3; -+ int COMMON_COUNT_THREE_HUNDRED = 300; -+ int SLEEP_TIME = 300000; -+ -+ InputMethodProperty *currentIme[MAX_IME]; // 0 - the default ime. 1 - security ime -+ -+ InputControlChannelStub *localControlChannel[MAX_IME]; -+ sptr inputControlChannel[MAX_IME]; -+ sptr imsCore[MAX_IME]; // the remote handlers of input method service -+ sptr inputMethodToken[MAX_IME]; // the window token of keyboard -+ int currentKbdIndex[MAX_IME]; // current keyboard index -+ int lastImeIndex; // The last ime which showed keyboard -+ InputMethodSetting *inputMethodSetting; // The pointer referred to the object in PerUserSetting -+ int currentDisplayMode; // the display mode of the current keyboard -+ -+ sptr imsAgent; -+ InputChannel *imsChannel; // the write channel created by input method service -+ sptr currentClient; // the current input client -+ sptr needReshowClient; // the input client for which keyboard need to re-show -+ -+ sptr clientDeathRecipient; // remote object death monitor for input client -+ sptr imsDeathRecipient; -+ MessageHandler *msgHandler = nullptr; // message handler working with Work Thread -+ std::thread workThreadHandler; // work thread handler -+ std::mutex mtx; // mutex to lock the operations among multi work threads -+ sptr connCallback; -+ -+ PerUserSession(const PerUserSession&); -+ PerUserSession& operator =(const PerUserSession&); -+ PerUserSession(const PerUserSession&&); -+ PerUserSession& operator =(const PerUserSession&&); -+ int IncreaseOrResetImeError(bool resetFlag, int imeIndex); -+ KeyboardType *GetKeyboardType(int imeIndex, int typeIndex); -+ void ResetCurrentKeyboardType(int imeIndex); -+ int OnCurrentKeyboardTypeChanged(int index, const std::u16string& value); -+ void CopyInputMethodService(int imeIndex); -+ ClientInfo *GetClientInfo(const sptr& inputClient); -+ void WorkThread(); -+ void OnPrepareInput(Message *msg); -+ void OnReleaseInput(Message *msg); -+ void OnStartInput(Message *msg); -+ void OnStopInput(Message *msg); -+ void SetCoreAndAgent(Message *msg); -+ void OnClientDied(const wptr& who); -+ void OnImsDied(const wptr& who); -+ void OnHideKeyboardSelf(int flags); -+ void OnAdvanceToNext(); -+ void OnSetDisplayMode(int mode); -+ void OnRestartIms(int index, const std::u16string& imeId); -+ void OnUserLocked(); -+ int AddClient(int pid, int uid, int displayId, const sptr& inputClient, -+ const sptr& channel, -+ const InputAttribute& attribute); -+ int RemoveClient(const sptr& inputClient, int retClientNum); -+ int StartInputMethod(int index); -+ int StopInputMethod(int index); -+ int ShowKeyboard(const sptr& inputClient); -+ int HideKeyboard(const sptr& inputClient); -+ void SetDisplayId(int displayId); -+ int GetImeIndex(const sptr& inputClient); -+ static sptr GetAbilityManagerService(); -+ void SendAgentToSingleClient(const sptr& inputClient); -+ void InitInputControlChannel(); -+ void SendAgentToAllClients(); -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_PERUSERSESSION_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/peruser_setting.h b/ohos_ndk_aosp/includes/inputmethod_services/peruser_setting.h -new file mode 100644 -index 0000000000..28e1a5575d ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/peruser_setting.h -@@ -0,0 +1,74 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_PERUSERSETTING_H -+#define FM_IMMS_PROJECT_PERUSERSETTING_H -+ -+#include -+#include -+#include -+#include "input_method_property.h" -+#include "input_method_setting.h" -+#include "global.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class PerUserSetting { -+ public: -+ explicit PerUserSetting(int32_t userId); -+ -+ ~PerUserSetting(); -+ -+ void Initialize(); -+ int32_t GetUserState(); -+ InputMethodProperty *GetCurrentInputMethod(); -+ InputMethodProperty *GetSecurityInputMethod(); -+ InputMethodProperty *GetNextInputMethod(); -+ InputMethodSetting *GetInputMethodSetting(); -+ InputMethodProperty *GetInputMethodProperty(const std::u16string& imeId); -+ -+ int32_t OnPackageAdded(std::u16string& packageName, bool isSecurityIme); -+ int32_t OnPackageRemoved(std::u16string& packageName, bool isSecurityIme); -+ int32_t OnSettingChanged(const std::u16string& key, const std::u16string& value); -+ void OnAdvanceToNext(); -+ void OnUserLocked(); -+ void Dump(int32_t fd); -+ -+ int32_t ListInputMethodEnabled(std::vector *properties); -+ int32_t ListInputMethod(std::vector *properties); -+ int32_t ListKeyboardType(const std::u16string& imeId, std::vector *types); -+ -+ static bool CheckIfSecurityIme(const InputMethodProperty& property); -+ -+ private: -+ int32_t userId_; // the id of the user to whom the object is linking -+ int32_t userState; // the state of the user to whom the object is linking -+ std::vector inputMethodProperties; // a vector to save all IME installed for this user -+ std::u16string currentImeId; // the id of the default input method engine. -+ InputMethodSetting inputMethodSetting; // the object to manage the setting data for this user -+ int COMMON_COUNT_ONE_HUNDRED_THOUSAND = 100000; -+ -+ PerUserSetting(const PerUserSetting&); -+ PerUserSetting& operator =(const PerUserSetting&); -+ PerUserSetting(const PerUserSetting&&); -+ PerUserSetting& operator =(const PerUserSetting&&); -+ void InitInputMethodSetting(); -+ void ResetCurrentInputMethod(); -+ std::u16string GetKeyboardTypeLanguage(const InputMethodProperty *property, int32_t hashCode); -+ std::u16string GetImeId(const std::u16string& packageName); -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_PERUSERSETTING_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/platform.h b/ohos_ndk_aosp/includes/inputmethod_services/platform.h -new file mode 100644 -index 0000000000..3088e11393 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/platform.h -@@ -0,0 +1,65 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_PLATFORMAPI_H -+#define FM_IMMS_PROJECT_PLATFORMAPI_H -+ -+#include -+#include -+#include -+#include "iremote_broker.h" -+#include "iremote_object.h" -+#include "i_platform_api.h" -+#include "i_input_method_core.h" -+#include "input_method_property.h" -+#include "input_method_setting.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class Platform { -+ public: -+ static Platform *Instance(); -+ void SetPlatform(const sptr& platformApi); -+ sptr BindInputMethodService(int userId, const std::u16string& packageName, -+ const std::u16string& intention); -+ int UnbindInputMethodService(int userId, const std::u16string& packageName); -+ sptr CreateWindowToken(int userId, int displayId, const std::u16string& packageName); -+ int DestroyWindowToken(int userId, const std::u16string& packageName); -+ int ListInputMethod(int userId, std::vector *properties); -+ int GetInputMethodProperty(int userId, const std::u16string& packageName, -+ InputMethodProperty *inputMethodProperty); -+ int GetInputMethodSetting(int userId, InputMethodSetting *inputMethodSetting); -+ int SetInputMethodSetting(int userId, const InputMethodSetting& inputMethodSetting); -+ bool CheckPhysicalKeyboard(); -+ bool IsValidWindow(int uid, int pid, int displayId); -+ bool IsWindowFocused(int uid, int pid, int displayId); -+ -+ static inline sptr RemoteBrokerToObject(const sptr& broker) -+ { -+ return broker->AsObject(); -+ } -+ -+ private: -+ sptr platformApi; -+ Platform(); -+ ~Platform(); -+ Platform(const Platform&); -+ Platform& operator =(const Platform&); -+ Platform(const Platform&&); -+ Platform& operator =(const Platform&&); -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_PLATFORMAPI_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/platform_callback_stub.h b/ohos_ndk_aosp/includes/inputmethod_services/platform_callback_stub.h -new file mode 100644 -index 0000000000..982f0ca95d ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/platform_callback_stub.h -@@ -0,0 +1,38 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FM_IMMS_PROJECT_PLATFORMCALLBACK_SK_H -+#define FM_IMMS_PROJECT_PLATFORMCALLBACK_SK_H -+ -+#include -+#include "iremote_stub.h" -+#include "message_option.h" -+#include "message_parcel.h" -+#include "i_platform_callback.h" -+ -+namespace OHOS { -+namespace MiscServices { -+ class PlatformCallbackStub : public IRemoteStub { -+ public: -+ PlatformCallbackStub(); -+ ~PlatformCallbackStub(); -+ -+ virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, -+ MessageOption &option) override; -+ virtual void notifyEvent(int eventId, int userId, const std::vector& eventContent) override; -+ }; -+} -+} -+#endif // FM_IMMS_PROJECT_PLATFORMCALLBACK_SK_H -diff --git a/ohos_ndk_aosp/includes/inputmethod_services/utils.h b/ohos_ndk_aosp/includes/inputmethod_services/utils.h -new file mode 100644 -index 0000000000..087846c523 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/inputmethod_services/utils.h -@@ -0,0 +1,42 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+/*! \file utils.h */ -+ -+#ifndef FM_IMMS_PROJECT_UTILS_H -+#define FM_IMMS_PROJECT_UTILS_H -+ -+#include -+#include -+#include -+#include -+ -+namespace OHOS { -+namespace MiscServices { -+ class Utils { -+ public: -+ static std::string to_utf8(std::u16string str16) -+ { -+ return std::wstring_convert, char16_t> {}.to_bytes(str16); -+ } -+ static std::u16string to_utf16(std::string str) -+ { -+ return std::wstring_convert, char16_t> {}.from_bytes(str); -+ } -+ }; -+} -+} -+ -+#endif -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/ipc_core/ipc_file_descriptor.h b/ohos_ndk_aosp/includes/ipc_core/ipc_file_descriptor.h -new file mode 100755 -index 0000000000..6f0c242d9a ---- /dev/null -+++ b/ohos_ndk_aosp/includes/ipc_core/ipc_file_descriptor.h -@@ -0,0 +1,38 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef OHOS_IPC_IPC_FILE_DESCRIPTOR_H -+#define OHOS_IPC_IPC_FILE_DESCRIPTOR_H -+ -+#include "parcel.h" -+ -+namespace OHOS { -+class IPCFileDescriptor : public virtual Parcelable { -+public: -+ IPCFileDescriptor(); -+ explicit IPCFileDescriptor(int fd); -+ ~IPCFileDescriptor(); -+ -+ bool Marshalling(Parcel &parcel) const override; -+ static bool Marshalling(Parcel &parcel, const sptr &object); -+ static IPCFileDescriptor *Unmarshalling(Parcel &parcel); -+ int GetFd() const; -+ void SetFd(int fd); -+ -+private: -+ int fd_ = -1; -+}; -+} // namespace OHOS -+#endif // OHOS_IPC_IPC_FILE_DESCRIPTOR_H -diff --git a/ohos_ndk_aosp/includes/ipc_core/ipc_object_proxy.h b/ohos_ndk_aosp/includes/ipc_core/ipc_object_proxy.h -new file mode 100755 -index 0000000000..67d0a97bc9 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/ipc_core/ipc_object_proxy.h -@@ -0,0 +1,118 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef OHOS_IPC_IPC_OBJECT_PROXY_H -+#define OHOS_IPC_IPC_OBJECT_PROXY_H -+ -+#include -+#include -+ -+#include "iremote_object.h" -+ -+namespace OHOS { -+class IPCObjectProxy : public IRemoteObject { -+public: -+ explicit IPCObjectProxy(int handle, std::u16string descriptor = std::u16string(), -+ int proto = IRemoteObject::IF_PROT_DEFAULT); -+ ~IPCObjectProxy(); -+ -+ int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &optionoption) override; -+ -+ bool IsProxyObject() const override -+ { -+ return true; -+ }; -+ -+ bool IsObjectDead() const; -+ -+ int32_t GetObjectRefCount() override; -+ -+ int Dump(int fd, const std::vector &args) override; -+ -+ void OnFirstStrongRef(const void *objectId) override; -+ -+ void OnLastStrongRef(const void *objectId) override; -+ -+ bool AddDeathRecipient(const sptr &recipient) override; -+ -+ bool RemoveDeathRecipient(const sptr &recipient) override; -+ -+ void SendObituary(); -+ -+ bool IsSubscribeDeathNotice() const -+ { -+ if (recipients_.empty()) { -+ return false; -+ } -+ return true; -+ }; -+ -+ uint32_t GetHandle() const -+ { -+ return handle_; -+ }; -+ -+ int InvokeListenThread(MessageParcel &data, MessageParcel &reply); -+ int32_t NoticeServiceDie(); -+ std::string GetPidAndUidInfo(); -+ -+ std::string GetDataBusName(); -+ std::string TransDataBusName(uint32_t uid, uint32_t pid); -+ int GetProto() const; -+ void WaitForInit(); -+ std::u16string GetInterfaceDescriptor(); -+ -+private: -+ void MarkObjectDied(); -+ int SendLocalRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &optionoption); -+ int SendRequestInner(bool isLocal, uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); -+ -+#ifndef CONFIG_IPC_SINGLE -+ void SetProto(int proto); -+ -+ int UpdateProto(); -+ -+ void ReleaseProto(); -+ -+ void IncRefToRemote(); -+ -+ int GetSessionFromDBinderService(); -+ -+ bool AddDbinderDeathRecipient(); -+ -+ bool RemoveDbinderDeathRecipient(); -+ -+ void ReleaseDatabusProto(); -+ -+ void ReleaseBinderProto(); -+ -+ bool UpdateDatabusClientSession(int handle, MessageParcel &reply); -+ -+ bool CheckHaveSession(uint32_t &type); -+#endif -+ -+private: -+ std::mutex initMutex_; -+ std::recursive_mutex mutex_; -+ -+ std::vector> recipients_; -+ const uint32_t handle_; -+ int proto_; -+ bool isFinishInit_; -+ bool isRemoteDead_; -+ std::u16string remoteDescriptor_; -+}; -+} // namespace OHOS -+#endif // OHOS_IPC_IPC_OBJECT_PROXY_H -diff --git a/ohos_ndk_aosp/includes/ipc_core/ipc_object_stub.h b/ohos_ndk_aosp/includes/ipc_core/ipc_object_stub.h -new file mode 100755 -index 0000000000..8e922a882c ---- /dev/null -+++ b/ohos_ndk_aosp/includes/ipc_core/ipc_object_stub.h -@@ -0,0 +1,93 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef OHOS_IPC_IPC_OBJECT_STUB_H -+#define OHOS_IPC_IPC_OBJECT_STUB_H -+ -+#include "iremote_object.h" -+#include -+#include "ipc_object_proxy.h" -+ -+namespace OHOS { -+struct RefCountNode { -+ int remotePid; -+ std::string deviceId; -+}; -+ -+class IPCObjectStub : public IRemoteObject { -+public: -+ enum { -+ OBJECT_TYPE_NATIVE, -+ OBJECT_TYPE_JAVA, -+ OBJECT_TYPE_JAVASCRIPT, -+ }; -+ -+ explicit IPCObjectStub(std::u16string descriptor = nullptr); -+ ~IPCObjectStub(); -+ -+ bool IsProxyObject() const override -+ { -+ return false; -+ }; -+ -+ int32_t GetObjectRefCount() override; -+ -+ int Dump(int fd, const std::vector &args) override; -+ -+ virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); -+ -+ int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; -+ -+ void OnFirstStrongRef(const void *objectId) override; -+ -+ void OnLastStrongRef(const void *objectId) override; -+ -+ bool AddDeathRecipient(const sptr &recipient) override; -+ -+ bool RemoveDeathRecipient(const sptr &recipient) override; -+ -+ int GetCallingPid(); -+ -+ int GetCallingUid(); -+ -+ uint32_t GetCallingTokenID(); -+ -+ uint32_t GetFirstTokenID(); -+ -+ virtual int OnRemoteDump(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); -+ -+ virtual int32_t ProcessProto(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); -+ -+ virtual int GetObjectType() const; -+ -+#ifndef CONFIG_IPC_SINGLE -+ int32_t InvokerThread(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); -+ int32_t NoticeServiceDie(MessageParcel &data, MessageParcel &reply, MessageOption &option); -+ int32_t InvokerDataBusThread(MessageParcel &data, MessageParcel &reply); -+ int32_t IncStubRefs(MessageParcel &data, MessageParcel &reply); -+ int32_t DecStubRefs(MessageParcel &data, MessageParcel &reply); -+ int32_t AddAuthInfo(MessageParcel &data, MessageParcel &reply, uint32_t code); -+ -+private: -+ int32_t GrantDataBusName(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); -+ int32_t TransDataBusName(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); -+ std::string CreateDatabusName(int uid, int pid); -+ std::string GetDataBusName(); -+#endif -+private: -+ bool IsDeviceIdIllegal(const std::string &deviceID); -+}; -+} // namespace OHOS -+#endif // OHOS_IPC_IPC_OBJECT_STUB_H -diff --git a/ohos_ndk_aosp/includes/ipc_core/ipc_skeleton.h b/ohos_ndk_aosp/includes/ipc_core/ipc_skeleton.h -new file mode 100755 -index 0000000000..4ea3c1a3bf ---- /dev/null -+++ b/ohos_ndk_aosp/includes/ipc_core/ipc_skeleton.h -@@ -0,0 +1,63 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef OHOS_IPC_IPC_SKELETON_H -+#define OHOS_IPC_IPC_SKELETON_H -+ -+#include "iremote_object.h" -+ -+namespace OHOS { -+class IPCSkeleton { -+public: -+ IPCSkeleton() = default; -+ ~IPCSkeleton() = default; -+ -+ // default max is 4, only if you need a customize value -+ static bool SetMaxWorkThreadNum(int maxThreadNum); -+ -+ // join current thread into work loop. -+ static void JoinWorkThread(); -+ -+ // remove current thread from work loop. -+ static void StopWorkThread(); -+ -+ static pid_t GetCallingPid(); -+ -+ static pid_t GetCallingUid(); -+ -+ static uint32_t GetCallingTokenID(); -+ -+ static uint32_t GetFirstTokenID(); -+ -+ static std::string GetLocalDeviceID(); -+ -+ static std::string GetCallingDeviceID(); -+ -+ static bool IsLocalCalling(); -+ -+ static IPCSkeleton &GetInstance(); -+ -+ static sptr GetContextObject(); -+ -+ static bool SetContextObject(sptr &object); -+ -+ static int FlushCommands(IRemoteObject *object); -+ -+ static std::string ResetCallingIdentity(); -+ -+ static bool SetCallingIdentity(std::string &identity); -+}; -+} // namespace OHOS -+#endif // OHOS_IPC_IPC_SKELETON_H -diff --git a/ohos_ndk_aosp/includes/ipc_core/ipc_types.h b/ohos_ndk_aosp/includes/ipc_core/ipc_types.h -new file mode 100755 -index 0000000000..66b46ad1b8 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/ipc_core/ipc_types.h -@@ -0,0 +1,130 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef OHOS_IPC_IPC_TYPES_H -+#define OHOS_IPC_IPC_TYPES_H -+ -+#include -+#include -+#include "errors.h" -+ -+namespace OHOS { -+#define ZIPC_PACK_CHARS(c1, c2, c3, c4) ((((c1) << 24)) | (((c2) << 16)) | (((c3) << 8)) | (c4)) -+ -+constexpr int REGISTRY_HANDLE = 0; -+ -+enum { -+ FIRST_CALL_TRANSACTION = 0x00000001, -+ LAST_CALL_TRANSACTION = 0x00ffffff, -+ PING_TRANSACTION = ZIPC_PACK_CHARS('_', 'P', 'N', 'G'), -+ DUMP_TRANSACTION = ZIPC_PACK_CHARS('_', 'D', 'M', 'P'), -+ SHELL_COMMAND_TRANSACTION = ZIPC_PACK_CHARS('_', 'C', 'M', 'D'), -+ INTERFACE_TRANSACTION = ZIPC_PACK_CHARS('_', 'N', 'T', 'F'), -+ SYSPROPS_TRANSACTION = ZIPC_PACK_CHARS('_', 'S', 'P', 'R'), -+ SYNCHRONIZE_REFERENCE = ZIPC_PACK_CHARS('_', 'S', 'Y', 'C'), -+ INVOKE_LISTEN_THREAD = ZIPC_PACK_CHARS('_', 'I', 'L', 'T'), -+ GET_PROTO_INFO = ZIPC_PACK_CHARS('_', 'G', 'R', 'I'), -+ GET_UIDPID_INFO = ZIPC_PACK_CHARS('_', 'G', 'U', 'I'), -+ GRANT_DATABUS_NAME = ZIPC_PACK_CHARS('_', 'G', 'D', 'N'), -+ TRANS_DATABUS_NAME = ZIPC_PACK_CHARS('_', 'T', 'D', 'N'), -+ DBINDER_OBITUARY_TRANSACTION = ZIPC_PACK_CHARS('_', 'D', 'O', 'T'), -+ DBINDER_INCREFS_TRANSACTION = ZIPC_PACK_CHARS('_', 'D', 'I', 'T'), -+ DBINDER_DECREFS_TRANSACTION = ZIPC_PACK_CHARS('_', 'D', 'D', 'T'), -+ DBINDER_ADD_COMMAUTH = ZIPC_PACK_CHARS('_', 'D', 'A', 'C'), -+ DBINDER_TRANS_COMMAUTH = ZIPC_PACK_CHARS('_', 'D', 'T', 'C'), -+ TRANS_SYNC = 0, -+ TRANS_ASYNC = 1, -+}; -+ -+enum { -+ NO_ERROR = 0, -+ TRANSACTION_ERR, -+ FLATTEN_ERR = 3, -+ UNKNOWN_TRANSACTION = 4, -+ INVALID_DATA = 5, -+ OBJECT_NULL = 7, -+ INVALID_OPERATION = 8, -+ DEAD_OBJECT = -EPIPE, -+ UNKNOWN_ERROR, -+}; -+ -+constexpr int MIN_TRANSACTION_ID = 0x1; -+constexpr int MAX_TRANSACTION_ID = 0x00ffffff; -+constexpr int INVALID_FD = -1; -+ -+enum { -+ ERR_NONE = 0, -+ ERR_TRANSACTION_FAILED = 1, -+ ERR_UNKNOWN_OBJECT = 2, -+ ERR_FLATTEN_OBJECT = 3, -+ ERR_UNKNOWN_TRANSACTION = 4, -+ ERR_INVALID_DATA = 5, -+ ERR_NULL_OBJECT = 7, -+ ERR_UNKNOWN_REASON, -+ ERR_INVALID_REPLY, -+ ERR_INVALID_STATE, -+ IPC_SKELETON_ERR = 100, -+ IPC_SKELETON_NULL_OBJECT_ERR, -+ IPC_PROXY_ERR = 200, -+ IPC_PROXY_DEAD_OBJECT_ERR, -+ IPC_PROXY_NULL_INVOKER_ERR, -+ IPC_PROXY_TRANSACTION_ERR, -+ IPC_PROXY_INVALID_CODE_ERR, -+ IPC_STUB_ERR = 300, -+ IPC_STUB_WRITE_PARCEL_ERR, -+ IPC_STUB_INVOKE_THREAD_ERR, -+ IPC_STUB_INVALID_DATA_ERR, -+ IPC_STUB_CURRENT_NULL_ERR, -+ IPC_STUB_UNKNOW_TRANS_ERR, -+ IPC_STUB_CREATE_BUS_SERVER_ERR, -+ IPC_INVOKER_ERR = 400, -+ IPC_INVOKER_WRITE_TRANS_ERR, -+ IPC_INVOKER_TRANSLATE_ERR, -+ IPC_INVOKER_CONNECT_ERR, -+ IPC_INVOKER_ON_TRANSACT_ERR, -+ IPC_INVOKER_INVALID_DATA_ERR, -+ IPC_INVOKER_INVALID_REPLY_ERR, -+ RPC_BASE_INVOKER_ERR = 500, -+ RPC_BASE_INVOKER_INVALID_REPLY_ERR, -+ RPC_BASE_INVOKER_WAIT_REPLY_ERR, -+ RPC_BASE_INVOKER_CURRENT_NULL_ERR, -+ RPC_BASE_INVOKER_INVALID_DATA_ERR, -+ RPC_BASE_INVOKER_WRITE_TRANS_ERR, -+ RPC_BASE_INVOKER_SEND_REPLY_ERR, -+ RPC_DATABUS_INVOKER_ERR = 600, -+ RPC_DATABUS_INVOKER_INVALID_DATA_ERR, -+ RPC_DATABUS_INVOKER_CLOSED_PEER_ERR, -+ RPC_DATABUS_INVOKER_INVALID_STUB_INDEX, -+ DBINDER_SERVICE_ERR = 700, -+ DBINDER_SERVICE_INVALID_DATA_ERR, -+ DBINDER_SERVICE_NOTICE_DIE_ERR, -+ DBINDER_SERVICE_PROCESS_PROTO_ERR, -+ DBINDER_SERVICE_UNKNOW_TRANS_ERR, -+ DBINDER_SERVICE_ADD_DEATH_ERR, -+ DBINDER_SERVICE_REMOVE_DEATH_ERR, -+ DBINDER_SERVICE_WRONG_SESSION, -+ SESSION_WRONG_FD_ERR = 800, -+ SESSION_INVOKER_NULL_ERR, -+ SESSION_UNAUTHENTICATED_ERR, -+ SESSION_UNOPEN_ERR = -1, -+ DBINDER_CALLBACK_ERR = 900, -+ DBINDER_CALLBACK_ADD_DEATH_ERR, -+ DBINDER_CALLBACK_RMV_DEATH_ERR, -+ DBINDER_CALLBACK_READ_OBJECT_ERR, -+ BINDER_CALLBACK_AUTHCOMM_ERR, -+ BINDER_CALLBACK_STUBINDEX_ERR -+}; -+} // namespace OHOS -+#endif // OHOS_IPC_IPC_TYPES_H -diff --git a/ohos_ndk_aosp/includes/ipc_core/iremote_broker.h b/ohos_ndk_aosp/includes/ipc_core/iremote_broker.h -new file mode 100755 -index 0000000000..4251a993d8 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/ipc_core/iremote_broker.h -@@ -0,0 +1,109 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef OHOS_IPC_IREMOTE_BROKER_H -+#define OHOS_IPC_IREMOTE_BROKER_H -+ -+#include -+#include -+#include "iremote_object.h" -+#include "refbase.h" -+ -+namespace OHOS { -+template class BrokerCreator { -+public: -+ BrokerCreator() = default; -+ ~BrokerCreator() = default; -+ sptr operator () (const sptr &object) -+ { -+ return static_cast(new T(object)); -+ }; -+}; -+ -+class IRemoteBroker : public virtual RefBase { -+public: -+ IRemoteBroker() = default; -+ virtual ~IRemoteBroker() override = default; -+ virtual sptr AsObject() = 0; -+ static inline sptr AsImplement(const sptr &object) -+ { -+ return nullptr; -+ } -+}; -+ -+#define DECLARE_INTERFACE_DESCRIPTOR(DESCRIPTOR) \ -+ static inline const std::u16string metaDescriptor_ = { DESCRIPTOR }; \ -+ static inline const std::u16string &GetDescriptor() \ -+ { \ -+ return metaDescriptor_; \ -+ } -+ -+class BrokerRegistration { -+ using Constructor = std::function(const sptr &object)>; -+ -+public: -+ static BrokerRegistration &Get(); -+ bool Register(const std::u16string &descriptor, const Constructor &creator); -+ void Unregister(const std::u16string &descriptor); -+ sptr NewInstance(const std::u16string &descriptor, const sptr &object); -+ -+protected: -+ BrokerRegistration() = default; -+ ~BrokerRegistration(); -+ -+private: -+ BrokerRegistration(const BrokerRegistration &) = delete; -+ BrokerRegistration(BrokerRegistration &&) = delete; -+ BrokerRegistration &operator = (const BrokerRegistration &) = delete; -+ BrokerRegistration &operator = (BrokerRegistration &&) = delete; -+ std::mutex creatorMutex_; -+ std::unordered_map creators_; -+}; -+ -+template class BrokerDelegator { -+public: -+ BrokerDelegator(); -+ ~BrokerDelegator(); -+ -+private: -+ BrokerDelegator(const BrokerDelegator &) = delete; -+ BrokerDelegator(BrokerDelegator &&) = delete; -+ BrokerDelegator &operator = (const BrokerDelegator &) = delete; -+ BrokerDelegator &operator = (BrokerDelegator &&) = delete; -+}; -+ -+template BrokerDelegator::BrokerDelegator() -+{ -+ const std::u16string descriptor = T::GetDescriptor(); -+ BrokerRegistration ®istration = BrokerRegistration::Get(); -+ registration.Register(descriptor, BrokerCreator()); -+} -+ -+template BrokerDelegator::~BrokerDelegator() -+{ -+ const std::u16string descriptor = T::GetDescriptor(); -+ BrokerRegistration ®istration = BrokerRegistration::Get(); -+ registration.Unregister(descriptor); -+} -+ -+template inline sptr iface_cast(const sptr &object) -+{ -+ const std::u16string descriptor = INTERFACE::GetDescriptor(); -+ BrokerRegistration ®istration = BrokerRegistration::Get(); -+ sptr broker = registration.NewInstance(descriptor, object); -+ return static_cast(broker.GetRefPtr()); -+} -+} // namespace OHOS -+#endif // OHOS_IPC_IREMOTE_BROKER_H -diff --git a/ohos_ndk_aosp/includes/ipc_core/iremote_object.h b/ohos_ndk_aosp/includes/ipc_core/iremote_object.h -new file mode 100755 -index 0000000000..7c4b8e064d ---- /dev/null -+++ b/ohos_ndk_aosp/includes/ipc_core/iremote_object.h -@@ -0,0 +1,87 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef OHOS_IPC_IREMOTE_OBJECT_H -+#define OHOS_IPC_IREMOTE_OBJECT_H -+ -+#include -+#include -+#include -+#include -+#include "ipc_types.h" -+#include "message_parcel.h" -+#include "message_option.h" -+ -+namespace OHOS { -+class IRemoteBroker; -+inline std::u16string to_utf16(const std::string &str) -+{ -+ return std::wstring_convert, char16_t> {}.from_bytes(str); -+} -+ -+class IRemoteObject : public virtual Parcelable, public virtual RefBase { -+public: -+ enum { -+ IF_PROT_DEFAULT, /* Invoker family. */ -+ IF_PROT_BINDER = IF_PROT_DEFAULT, -+ IF_PROT_DATABUS, -+ }; -+ enum { -+ DATABUS_TYPE, -+ }; -+ class DeathRecipient : public RefBase { -+ public: -+ enum { -+ ADD_DEATH_RECIPIENT, -+ REMOVE_DEATH_RECIPIENT, -+ NOTICE_DEATH_RECIPIENT, -+ TEST_SERVICE_DEATH_RECIPIENT, -+ TEST_DEVICE_DEATH_RECIPIENT, -+ }; -+ virtual void OnRemoteDied(const wptr &object) = 0; -+ }; -+ -+ virtual int32_t GetObjectRefCount() = 0; -+ -+ virtual int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) = 0; -+ -+ virtual bool IsProxyObject() const; -+ -+ virtual bool CheckObjectLegality() const; -+ -+ virtual bool AddDeathRecipient(const sptr &recipient) = 0; -+ -+ virtual bool RemoveDeathRecipient(const sptr &recipient) = 0; -+ -+ virtual bool Marshalling(Parcel &parcel) const override; -+ -+ static IRemoteObject *Unmarshalling(Parcel &parcel); -+ -+ static bool Marshalling(Parcel &parcel, const sptr &object); -+ -+ virtual sptr AsInterface(); -+ -+ virtual int Dump(int fd, const std::vector &args) = 0; -+ -+ const std::u16string descriptor_; -+ -+ std::u16string GetObjectDescriptor() const; -+ -+protected: -+ explicit IRemoteObject(std::u16string descriptor = nullptr); -+ virtual ~IRemoteObject() = default; -+}; -+} // namespace OHOS -+#endif // OHOS_IPC_IREMOTE_OBJECT_H -diff --git a/ohos_ndk_aosp/includes/ipc_core/iremote_proxy.h b/ohos_ndk_aosp/includes/ipc_core/iremote_proxy.h -new file mode 100755 -index 0000000000..fff5bc5f21 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/ipc_core/iremote_proxy.h -@@ -0,0 +1,43 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef OHOS_IPC_IREMOTE_PROXY_H -+#define OHOS_IPC_IREMOTE_PROXY_H -+ -+#include "iremote_broker.h" -+#include "peer_holder.h" -+#include "iremote_object.h" -+ -+namespace OHOS { -+template class IRemoteProxy : public PeerHolder, public INTERFACE { -+public: -+ explicit IRemoteProxy(const sptr &object); -+ ~IRemoteProxy() override = default; -+ -+protected: -+ sptr AsObject() override; -+}; -+ -+template -+IRemoteProxy::IRemoteProxy(const sptr &object) : PeerHolder(object) -+{ -+} -+ -+template sptr IRemoteProxy::AsObject() -+{ -+ return Remote(); -+} -+} // namespace OHOS -+#endif // OHOS_IPC_IREMOTE_PROXY_H -diff --git a/ohos_ndk_aosp/includes/ipc_core/iremote_stub.h b/ohos_ndk_aosp/includes/ipc_core/iremote_stub.h -new file mode 100755 -index 0000000000..3151a93a4c ---- /dev/null -+++ b/ohos_ndk_aosp/includes/ipc_core/iremote_stub.h -@@ -0,0 +1,44 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef OHOS_IPC_IREMOTE_STUB_H -+#define OHOS_IPC_IREMOTE_STUB_H -+ -+#include -+#include "iremote_broker.h" -+#include "ipc_object_stub.h" -+ -+namespace OHOS { -+template class IRemoteStub : public IPCObjectStub, public INTERFACE { -+public: -+ IRemoteStub(); -+ virtual ~IRemoteStub() = default; -+ sptr AsObject() override; -+ sptr AsInterface() override; -+}; -+ -+template IRemoteStub::IRemoteStub() : IPCObjectStub(INTERFACE::GetDescriptor()) {} -+ -+template sptr IRemoteStub::AsInterface() -+{ -+ return this; -+} -+ -+template sptr IRemoteStub::AsObject() -+{ -+ return this; -+} -+} // namespace OHOS -+#endif // OHOS_IPC_IREMOTE_STUB_H -diff --git a/ohos_ndk_aosp/includes/ipc_core/jni_help.h b/ohos_ndk_aosp/includes/ipc_core/jni_help.h -new file mode 100755 -index 0000000000..fb286bfd33 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/ipc_core/jni_help.h -@@ -0,0 +1,26 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef OHOS_IPC_JNI_HELP_H -+#define OHOS_IPC_JNI_HELP_H -+ -+#include -+#include -+#include -+ -+namespace OHOS { -+jobject JNIHelperGetJavaRemoteObject(JNIEnv *env, const sptr &target); -+} // namespace OHOS -+#endif // OHOS_IPC_JNI_HELP_H -diff --git a/ohos_ndk_aosp/includes/ipc_core/message_option.h b/ohos_ndk_aosp/includes/ipc_core/message_option.h -new file mode 100755 -index 0000000000..7aa96519d9 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/ipc_core/message_option.h -@@ -0,0 +1,43 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef OHOS_IPC_MESSAGE_OPTION_H -+#define OHOS_IPC_MESSAGE_OPTION_H -+ -+#include -+namespace OHOS { -+class MessageOption { -+public: -+ enum { -+ TF_SYNC = 0x00, -+ TF_ASYNC = 0x01, -+ TF_STATUS_CODE = 0x08, -+ TF_ACCEPT_FDS = 0x10, -+ TF_WAIT_TIME = 0x4, -+ }; -+ MessageOption(int flags = TF_SYNC, int waitTime = TF_WAIT_TIME); -+ ~MessageOption() = default; -+ void SetFlags(int flags); -+ int GetFlags() const; -+ void SetWaitTime(int waitTime); -+ int GetWaitTime() const; -+ -+private: -+ uint32_t flags_; -+ int waitTime_; -+}; -+using MessageOptionPtr = std::shared_ptr; -+} // namespace OHOS -+#endif // OHOS_IPC_MESSAGE_OPTION_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/ipc_core/message_parcel.h b/ohos_ndk_aosp/includes/ipc_core/message_parcel.h -new file mode 100755 -index 0000000000..af5bfb8964 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/ipc_core/message_parcel.h -@@ -0,0 +1,70 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef OHOS_IPC_MESSAGE_PARCEL_H -+#define OHOS_IPC_MESSAGE_PARCEL_H -+ -+#include -+#include "parcel.h" -+#include "refbase.h" -+#include -+ -+namespace OHOS { -+class IRemoteObject; -+class MessageParcel : public Parcel { -+public: -+ MessageParcel(); -+ ~MessageParcel(); -+ explicit MessageParcel(Allocator *allocator); -+ bool WriteRemoteObject(const sptr &object); -+ sptr ReadRemoteObject(); -+ bool WriteFileDescriptor(int fd); -+ int ReadFileDescriptor(); -+ bool ContainFileDescriptors() const; -+ bool WriteInterfaceToken(std::u16string name); -+ std::u16string ReadInterfaceToken(); -+ bool WriteRawData(const void *data, size_t size); -+ const void *ReadRawData(size_t size); -+ bool RestoreRawData(std::shared_ptr rawData, size_t size); -+ const void *GetRawData() const; -+ size_t GetRawDataSize() const; -+ size_t GetRawDataCapacity() const; -+ void WriteNoException(); -+ int32_t ReadException(); -+ bool WriteAshmem(sptr ashmem); -+ sptr ReadAshmem(); -+ void ClearFileDescriptor(); -+ void SetClearFdFlag() -+ { -+ needCloseFd_ = true; -+ }; -+ -+private: -+#ifndef CONFIG_IPC_SINGLE -+ bool WriteDBinderProxy(const sptr &object, uint32_t handle, uint64_t stubIndex); -+#endif -+ static constexpr size_t MAX_RAWDATA_SIZE = 128 * 1024 * 1024; // 128M -+ static constexpr size_t MIN_RAWDATA_SIZE = 32 * 1024; // 32k -+ bool needCloseFd_ = false; -+ std::vector> holders_; -+ int writeRawDataFd_; -+ int readRawDataFd_; -+ void *kernelMappedWrite_; -+ void *kernelMappedRead_; -+ std::shared_ptr rawData_; -+ size_t rawDataSize_; -+}; -+} // namespace OHOS -+#endif // OHOS_IPC_MESSAGE_PARCEL_H -diff --git a/ohos_ndk_aosp/includes/ipc_core/peer_holder.h b/ohos_ndk_aosp/includes/ipc_core/peer_holder.h -new file mode 100755 -index 0000000000..9ca9c7bffe ---- /dev/null -+++ b/ohos_ndk_aosp/includes/ipc_core/peer_holder.h -@@ -0,0 +1,34 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef OHOS_IPC_PEER_HOLDER_H -+#define OHOS_IPC_PEER_HOLDER_H -+ -+#include "iremote_object.h" -+ -+namespace OHOS { -+class PeerHolder { -+protected: -+ PeerHolder(const sptr &object); -+ -+ ~PeerHolder() = default; -+ -+ sptr Remote(); -+ -+private: -+ const sptr remoteObject_; -+}; -+} // namespace OHOS -+#endif // OHOS_IPC_PEER_HOLDER_H -diff --git a/ohos_ndk_aosp/includes/libeventhandler/dumper.h b/ohos_ndk_aosp/includes/libeventhandler/dumper.h -new file mode 100644 -index 0000000000..59d5d476db ---- /dev/null -+++ b/ohos_ndk_aosp/includes/libeventhandler/dumper.h -@@ -0,0 +1,39 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_DUMPER_H -+#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_DUMPER_H -+ -+namespace OHOS { -+namespace AppExecFwk { -+class Dumper { -+public: -+ /** -+ * Processes the content of a specified string. -+ * @param message the content of a specified string. -+ */ -+ virtual void Dump(const std::string &message) = 0; -+ -+ /** -+ * Obtains the tag information. -+ * which is a prefix added to each string before the string content is processed. -+ * @return the tag information. -+ */ -+ virtual std::string GetTag() = 0; -+}; -+} // namespace AppExecFwk -+} // namespace OHOS -+ -+#endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_DUMPER_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/libeventhandler/event_handler.h b/ohos_ndk_aosp/includes/libeventhandler/event_handler.h -new file mode 100644 -index 0000000000..aa01f68744 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/libeventhandler/event_handler.h -@@ -0,0 +1,927 @@ -+/* -+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_EVENT_HANDLER_H -+#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_EVENT_HANDLER_H -+ -+#include "event_runner.h" -+#include "dumper.h" -+ -+namespace OHOS { -+namespace AppExecFwk { -+enum class EventType { -+ SYNC_EVENT = 0, -+ DELAY_EVENT = 1, -+ TIMING_EVENT = 2, -+}; -+ -+template -+class ThreadLocalData; -+ -+class EventHandler : public std::enable_shared_from_this { -+public: -+ using CallbackTimeout = std::function; -+ using Callback = InnerEvent::Callback; -+ using Priority = EventQueue::Priority; -+ -+ /** -+ * Constructor, set 'EventRunner' automatically. -+ * -+ * @param runner The 'EventRunner'. -+ */ -+ explicit EventHandler(const std::shared_ptr &runner = nullptr); -+ virtual ~EventHandler(); -+ DISALLOW_COPY_AND_MOVE(EventHandler); -+ -+ /** -+ * Get event handler that running on current thread. -+ * -+ * @return Returns shared pointer of the current 'EventHandler'. -+ */ -+ static std::shared_ptr Current(); -+ -+ /** -+ * Send an event. -+ * -+ * @param event Event which should be handled. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @param priority Priority of the event queue for this event. -+ * @return Returns true if event has been sent successfully. If returns false, event should be released manually. -+ */ -+ bool SendEvent(InnerEvent::Pointer &event, int64_t delayTime = 0, Priority priority = Priority::LOW); -+ -+ /** -+ * Send an event. -+ * -+ * @param event Event which should be handled. -+ * @param taskTime Process the event at taskTime. -+ * @param priority Priority of the event queue for this event. -+ * @return Returns true if event has been sent successfully. If returns false, event should be released manually. -+ */ -+ bool SendTimingEvent(InnerEvent::Pointer &event, int64_t taskTime, Priority priority = Priority::LOW); -+ -+ /** -+ * Send an event. -+ * -+ * @param event Event which should be handled. -+ * @param priority Priority of the event queue for this event. -+ * @return Returns true if event has been sent successfully. If returns false, event should be released manually. -+ */ -+ inline bool SendEvent(InnerEvent::Pointer &event, Priority priority) -+ { -+ return SendEvent(event, 0, priority); -+ } -+ -+ /** -+ * Send an event. -+ * -+ * @param event Event which should be handled. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @param priority Priority of the event queue for this event. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendEvent(InnerEvent::Pointer &&event, int64_t delayTime = 0, Priority priority = Priority::LOW) -+ { -+ return SendEvent(event, delayTime, priority); -+ } -+ -+ /** -+ * Send an event. -+ * -+ * @param innerEventId The id of the event. -+ * @param param Basic parameter of the event, default is 0. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendEvent(uint32_t innerEventId, int64_t param, int64_t delayTime) -+ { -+ return SendEvent(InnerEvent::Get(innerEventId, param), delayTime); -+ } -+ -+ /** -+ * Send an event. -+ * -+ * @param innerEventId The id of the event. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @param priority Priority of the event queue for this event. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendEvent(uint32_t innerEventId, int64_t delayTime = 0, Priority priority = Priority::LOW) -+ { -+ return SendEvent(InnerEvent::Get(innerEventId, 0), delayTime, priority); -+ } -+ -+ /** -+ * Send an event. -+ * -+ * @param innerEventId The id of the event. -+ * @param priority Priority of the event queue for this event. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendEvent(uint32_t innerEventId, Priority priority) -+ { -+ return SendEvent(InnerEvent::Get(innerEventId, 0), 0, priority); -+ } -+ -+ /** -+ * Send an event. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Shared pointer of object. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendEvent(uint32_t innerEventId, const std::shared_ptr &object, int64_t delayTime = 0) -+ { -+ return SendEvent(InnerEvent::Get(innerEventId, object), delayTime); -+ } -+ -+ /** -+ * Send an event. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Weak pointer of object. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendEvent(uint32_t innerEventId, const std::weak_ptr &object, int64_t delayTime = 0) -+ { -+ return SendEvent(InnerEvent::Get(innerEventId, object), delayTime); -+ } -+ -+ /** -+ * Send an event. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Unique pointer of object. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendEvent(uint32_t innerEventId, std::unique_ptr &object, int64_t delayTime = 0) -+ { -+ return SendEvent(InnerEvent::Get(innerEventId, object), delayTime); -+ } -+ -+ /** -+ * Send an event. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Unique pointer of object. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendEvent(uint32_t innerEventId, std::unique_ptr &&object, int64_t delayTime = 0) -+ { -+ return SendEvent(InnerEvent::Get(innerEventId, object), delayTime); -+ } -+ -+ /** -+ * Send an immediate event. -+ * -+ * @param event Event which should be handled. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendImmediateEvent(InnerEvent::Pointer &event) -+ { -+ return SendEvent(event, 0, Priority::IMMEDIATE); -+ } -+ -+ /** -+ * Send an immediate event. -+ * -+ * @param event Event which should be handled. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendImmediateEvent(InnerEvent::Pointer &&event) -+ { -+ return SendImmediateEvent(event); -+ } -+ -+ /** -+ * Send an immediate event. -+ * -+ * @param innerEventId The id of the event. -+ * @param param Basic parameter of the event, default is 0. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendImmediateEvent(uint32_t innerEventId, int64_t param = 0) -+ { -+ return SendImmediateEvent(InnerEvent::Get(innerEventId, param)); -+ } -+ -+ /** -+ * Send an immediate event. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Shared pointer of object. -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendImmediateEvent(uint32_t innerEventId, const std::shared_ptr &object) -+ { -+ return SendImmediateEvent(InnerEvent::Get(innerEventId, object)); -+ } -+ -+ /** -+ * Send an immediate event. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Weak pointer of object. -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendImmediateEvent(uint32_t innerEventId, const std::weak_ptr &object) -+ { -+ return SendImmediateEvent(InnerEvent::Get(innerEventId, object)); -+ } -+ -+ /** -+ * Send an immediate event. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Unique pointer of object. -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendImmediateEvent(uint32_t innerEventId, std::unique_ptr &object) -+ { -+ return SendImmediateEvent(InnerEvent::Get(innerEventId, object)); -+ } -+ -+ /** -+ * Send an immediate event. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Unique pointer of object. -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendImmediateEvent(uint32_t innerEventId, std::unique_ptr &&object) -+ { -+ return SendImmediateEvent(InnerEvent::Get(innerEventId, object)); -+ } -+ -+ /** -+ * Send an high priority event. -+ * -+ * @param event Event which should be handled. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendHighPriorityEvent(InnerEvent::Pointer &event, int64_t delayTime = 0) -+ { -+ return SendEvent(event, delayTime, Priority::HIGH); -+ } -+ -+ /** -+ * Send an high priority event. -+ * -+ * @param event Event which should be handled. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendHighPriorityEvent(InnerEvent::Pointer &&event, int64_t delayTime = 0) -+ { -+ return SendHighPriorityEvent(event, delayTime); -+ } -+ -+ /** -+ * Send an high priority event. -+ * -+ * @param innerEventId The id of the event. -+ * @param param Basic parameter of the event, default is 0. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendHighPriorityEvent(uint32_t innerEventId, int64_t param = 0, int64_t delayTime = 0) -+ { -+ return SendHighPriorityEvent(InnerEvent::Get(innerEventId, param), delayTime); -+ } -+ -+ /** -+ * Send an high priority event. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Shared pointer of object. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendHighPriorityEvent(uint32_t innerEventId, const std::shared_ptr &object, int64_t delayTime = 0) -+ { -+ return SendHighPriorityEvent(InnerEvent::Get(innerEventId, object), delayTime); -+ } -+ -+ /** -+ * Send an high priority event. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Weak pointer of object. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendHighPriorityEvent(uint32_t innerEventId, const std::weak_ptr &object, int64_t delayTime = 0) -+ { -+ return SendHighPriorityEvent(InnerEvent::Get(innerEventId, object), delayTime); -+ } -+ -+ /** -+ * Send an high priority event. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Unique pointer of object. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendHighPriorityEvent(uint32_t innerEventId, std::unique_ptr &object, int64_t delayTime = 0) -+ { -+ return SendHighPriorityEvent(InnerEvent::Get(innerEventId, object), delayTime); -+ } -+ -+ /** -+ * Send an high priority event. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Unique pointer of object. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendHighPriorityEvent(uint32_t innerEventId, std::unique_ptr &&object, int64_t delayTime = 0) -+ { -+ return SendHighPriorityEvent(InnerEvent::Get(innerEventId, object), delayTime); -+ } -+ -+ /** -+ * Post a task. -+ * -+ * @param callback Task callback. -+ * @param name Name of the task. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @param priority Priority of the event queue for this event. -+ * @return Returns true if task has been sent successfully. -+ */ -+ inline bool PostTask(const Callback &callback, const std::string &name = std::string(), int64_t delayTime = 0, -+ Priority priority = Priority::LOW) -+ { -+ return SendEvent(InnerEvent::Get(callback, name), delayTime, priority); -+ } -+ -+ /** -+ * Set delivery time out callback. -+ * -+ * @param callback Delivery Time out callback. -+ */ -+ void SetDeliveryTimeoutCallback(const Callback &callback) -+ { -+ deliveryTimeoutCallback_ = callback; -+ } -+ -+ /** -+ * Set distribute time out callback. -+ * -+ * @param callback Distribute Time out callback. -+ */ -+ void SetDistributeTimeoutCallback(const Callback &callback) -+ { -+ distributeTimeoutCallback_ = callback; -+ } -+ -+ /** -+ * Post a task. -+ * -+ * @param callback Task callback. -+ * @param priority Priority of the event queue for this event. -+ * @return Returns true if task has been sent successfully. -+ */ -+ inline bool PostTask(const Callback &callback, Priority priority) -+ { -+ return PostTask(callback, std::string(), 0, priority); -+ } -+ -+ /** -+ * Post a task. -+ * -+ * @param callback Task callback. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @param priority Priority of the event queue for this event. -+ * @return Returns true if task has been sent successfully. -+ */ -+ inline bool PostTask(const Callback &callback, int64_t delayTime, Priority priority = Priority::LOW) -+ { -+ return PostTask(callback, std::string(), delayTime, priority); -+ } -+ -+ /** -+ * Post an immediate task. -+ * -+ * @param callback Task callback. -+ * @param name Remove events by name of the task. -+ * @return Returns true if task has been sent successfully. -+ */ -+ inline bool PostImmediateTask(const Callback &callback, const std::string &name = std::string()) -+ { -+ return SendEvent(InnerEvent::Get(callback, name), 0, Priority::IMMEDIATE); -+ } -+ -+ /** -+ * Post a high priority task. -+ * -+ * @param callback Task callback. -+ * @param name Name of the task. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @return Returns true if task has been sent successfully. -+ */ -+ inline bool PostHighPriorityTask( -+ const Callback &callback, const std::string &name = std::string(), int64_t delayTime = 0) -+ { -+ return PostTask(callback, name, delayTime, Priority::HIGH); -+ } -+ -+ /** -+ * Post a high priority task. -+ * -+ * @param callback Task callback. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @return Returns true if task has been sent successfully. -+ */ -+ inline bool PostHighPriorityTask(const Callback &callback, int64_t delayTime) -+ { -+ return PostHighPriorityTask(callback, std::string(), delayTime); -+ } -+ -+ /** -+ * Post a idle task. -+ * -+ * @param callback task callback. -+ * @param name Name of the task. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @return Returns true if task has been sent successfully. -+ */ -+ inline bool PostIdleTask(const Callback &callback, const std::string &name = std::string(), int64_t delayTime = 0) -+ { -+ return PostTask(callback, name, delayTime, Priority::IDLE); -+ } -+ -+ /** -+ * Post a idle task. -+ * -+ * @param callback Task callback. -+ * @param delayTime Process the event after 'delayTime' milliseconds. -+ * @return Returns true if task has been sent successfully. -+ */ -+ inline bool PostIdleTask(const Callback &callback, int64_t delayTime) -+ { -+ return PostIdleTask(callback, std::string(), delayTime); -+ } -+ -+ /** -+ * Send an event, and wait until this event has been handled. -+ * -+ * @param event Event which should be handled. -+ * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. -+ * @return Returns true if event has been sent successfully. If returns false, event should be released manually. -+ */ -+ bool SendSyncEvent(InnerEvent::Pointer &event, Priority priority = Priority::LOW); -+ -+ /** -+ * Send an event. -+ * -+ * @param event Event which should be handled. -+ * @param priority Priority of the event queue for this event. -+ * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendSyncEvent(InnerEvent::Pointer &&event, Priority priority = Priority::LOW) -+ { -+ return SendSyncEvent(event, priority); -+ } -+ -+ /** -+ * Send an event, and wait until this event has been handled. -+ * -+ * @param innerEventId The id of the event. -+ * @param param Basic parameter of the event, default is 0. -+ * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendSyncEvent(uint32_t innerEventId, int64_t param = 0, Priority priority = Priority::LOW) -+ { -+ return SendSyncEvent(InnerEvent::Get(innerEventId, param), priority); -+ } -+ -+ /** -+ * Send an event, and wait until this event has been handled. -+ * -+ * @param innerEventId The id of the event. -+ * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendSyncEvent(uint32_t innerEventId, Priority priority) -+ { -+ return SendSyncEvent(InnerEvent::Get(innerEventId, 0), priority); -+ } -+ -+ /** -+ * Send an event, and wait until this event has been handled. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Shared pointer of object. -+ * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendSyncEvent( -+ uint32_t innerEventId, const std::shared_ptr &object, Priority priority = Priority::LOW) -+ { -+ return SendSyncEvent(InnerEvent::Get(innerEventId, object), priority); -+ } -+ -+ /** -+ * Send an event, and wait until this event has been handled. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Weak pointer of object. -+ * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendSyncEvent(uint32_t innerEventId, const std::weak_ptr &object, Priority priority = Priority::LOW) -+ { -+ return SendSyncEvent(InnerEvent::Get(innerEventId, object), priority); -+ } -+ -+ /** -+ * Send an event, and wait until this event has been handled. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Unique pointer of object. -+ * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendSyncEvent(uint32_t innerEventId, std::unique_ptr &object, Priority priority = Priority::LOW) -+ { -+ return SendSyncEvent(InnerEvent::Get(innerEventId, object), priority); -+ } -+ -+ /** -+ * Send an event, and wait until this event has been handled. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Unique pointer of object. -+ * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendSyncEvent(uint32_t innerEventId, std::unique_ptr &&object, Priority priority = Priority::LOW) -+ { -+ return SendSyncEvent(InnerEvent::Get(innerEventId, object), priority); -+ } -+ -+ /** -+ * Post a task, and wait until this task has been handled. -+ * -+ * @param callback Task callback. -+ * @param name Name of the task. -+ * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. -+ * @return Returns true if task has been sent successfully. -+ */ -+ inline bool PostSyncTask(const Callback &callback, const std::string &name, Priority priority = Priority::LOW) -+ { -+ return SendSyncEvent(InnerEvent::Get(callback, name), priority); -+ } -+ -+ /** -+ * Post a task, and wait until this task has been handled. -+ * -+ * @param callback Task callback. -+ * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. -+ * @return Returns true if task has been sent successfully. -+ */ -+ inline bool PostSyncTask(const Callback &callback, Priority priority = Priority::LOW) -+ { -+ return PostSyncTask(callback, std::string(), priority); -+ } -+ -+ /** -+ * Send a timing event. -+ * -+ * @param event Event which should be handled. -+ * @param taskTime Process the event at taskTime. -+ * @param priority Priority of the event queue for this event. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendTimingEvent(InnerEvent::Pointer &&event, int64_t taskTime, Priority priority) -+ { -+ return SendTimingEvent(event, taskTime, priority); -+ } -+ -+ /** -+ * Send a timing event. -+ * -+ * @param event Event which should be handled. -+ * @param taskTime Process the event at taskTime. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendTimingEvent(InnerEvent::Pointer &&event, int64_t taskTime) -+ { -+ return SendTimingEvent(event, taskTime, Priority::LOW); -+ } -+ -+ /** -+ * Send a timing event. -+ * -+ * @param innerEventId The id of the event. -+ * @param taskTime Process the event at taskTime. -+ * @param param Basic parameter of the event. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendTimingEvent(uint32_t innerEventId, int64_t taskTime, int64_t param) -+ { -+ return SendTimingEvent(InnerEvent::Get(innerEventId, param), taskTime); -+ } -+ -+ /** -+ * Send a timing event. -+ * -+ * @param innerEventId The id of the event. -+ * @param taskTime Process the event at taskTime. -+ * @param priority Priority of the event queue for this event. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendTimingEvent(uint32_t innerEventId, int64_t taskTime, Priority priority) -+ { -+ return SendTimingEvent(InnerEvent::Get(innerEventId, 0), taskTime, priority); -+ } -+ -+ /** -+ * Send a timing event. -+ * -+ * @param innerEventId The id of the event. -+ * @param taskTime Process the event at taskTime. -+ * @param priority Priority of the event queue for this event. -+ * @return Returns true if event has been sent successfully. -+ */ -+ inline bool SendTimingEvent(uint32_t innerEventId, int64_t taskTime) -+ { -+ return SendTimingEvent(InnerEvent::Get(innerEventId, 0), taskTime, Priority::LOW); -+ } -+ -+ /** -+ * Send a timing event. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Shared pointer of object. -+ * @param taskTime Process the event at taskTime. -+ * @param priority Priority of the event queue for this event -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendTimingEvent( -+ uint32_t innerEventId, const std::shared_ptr &object, int64_t taskTime, Priority priority = Priority::LOW) -+ { -+ return SendTimingEvent(InnerEvent::Get(innerEventId, object), taskTime, priority); -+ } -+ -+ /** -+ * Send a timing event. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Weak pointer of object. -+ * @param taskTime Process the event at taskTime. -+ * @param priority Priority of the event queue for this event -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendTimingEvent( -+ uint32_t innerEventId, const std::weak_ptr &object, int64_t taskTime, Priority priority = Priority::LOW) -+ { -+ return SendTimingEvent(InnerEvent::Get(innerEventId, object), taskTime, priority); -+ } -+ -+ /** -+ * Send a timing event. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Unique pointer of object. -+ * @param taskTime Process the event at taskTime. -+ * @param priority Priority of the event queue for this event -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendTimingEvent( -+ uint32_t innerEventId, std::unique_ptr &object, int64_t taskTime, Priority priority = Priority::LOW) -+ { -+ return SendTimingEvent(InnerEvent::Get(innerEventId, object), taskTime, priority); -+ } -+ -+ /** -+ * Send a timing event. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Unique pointer of object. -+ * @param taskTime Process the event at taskTime. -+ * @param priority Priority of the event queue for this event -+ * @return Returns true if event has been sent successfully. -+ */ -+ template -+ inline bool SendTimingEvent( -+ uint32_t innerEventId, std::unique_ptr &&object, int64_t taskTime, Priority priority = Priority::LOW) -+ { -+ return SendTimingEvent(InnerEvent::Get(innerEventId, object), taskTime, priority); -+ } -+ -+ /** -+ * Post a timing task. -+ * -+ * @param callback Task callback. -+ * @param taskTime Process the event at taskTime. -+ * @param name Name of the task. -+ * @param priority Priority of the event queue for this event. -+ * @return Returns true if task has been sent successfully. -+ */ -+ inline bool PostTimingTask(const Callback &callback, int64_t taskTime, const std::string &name = std::string(), -+ Priority priority = Priority::LOW) -+ { -+ return SendTimingEvent(InnerEvent::Get(callback, name), taskTime, priority); -+ } -+ -+ /** -+ * Post a timing task. -+ * -+ * @param callback Task callback. -+ * @param taskTime Process the event at taskTime. -+ * @param priority Priority of the event queue for this event. -+ * @return Returns true if task has been sent successfully. -+ */ -+ inline bool PostTimingTask(const Callback &callback, int64_t taskTime, Priority priority = Priority::LOW) -+ { -+ return PostTimingTask(callback, taskTime, std::string(), priority); -+ } -+ -+ /** -+ * Remove all sent events. -+ */ -+ void RemoveAllEvents(); -+ -+ /** -+ * Remove sent events. -+ * -+ * @param innerEventId The id of the event. -+ */ -+ void RemoveEvent(uint32_t innerEventId); -+ -+ /** -+ * Remove sent events. -+ * -+ * @param innerEventId The id of the event. -+ * @param param Basic parameter of the event. -+ */ -+ void RemoveEvent(uint32_t innerEventId, int64_t param); -+ -+ /** -+ * Remove a task. -+ * -+ * @param name Name of the task. -+ */ -+ void RemoveTask(const std::string &name); -+ -+ /** -+ * Add file descriptor listener for a file descriptor. -+ * -+ * @param fileDescriptor File descriptor. -+ * @param events Events from file descriptor, such as input, output, error -+ * @param listener Listener callback. -+ * @return Return 'ERR_OK' on success. -+ */ -+ ErrCode AddFileDescriptorListener( -+ int32_t fileDescriptor, uint32_t events, const std::shared_ptr &listener); -+ -+ /** -+ * Remove all file descriptor listeners. -+ */ -+ void RemoveAllFileDescriptorListeners(); -+ -+ /** -+ * Remove file descriptor listener for a file descriptor. -+ * -+ * @param fileDescriptor File descriptor. -+ */ -+ void RemoveFileDescriptorListener(int32_t fileDescriptor); -+ -+ /** -+ * Set the 'EventRunner' to the 'EventHandler'. -+ * -+ * @param runner The 'EventRunner'. -+ */ -+ void SetEventRunner(const std::shared_ptr &runner); -+ -+ /** -+ * Get the 'EventRunner' of the 'EventHandler'. -+ * -+ * @return Return the 'EventRunner'. -+ */ -+ inline const std::shared_ptr &GetEventRunner() const -+ { -+ return eventRunner_; -+ } -+ -+ /** -+ * Distribute the event. -+ * -+ * @param event The event should be distributed. -+ */ -+ void DistributeEvent(const InnerEvent::Pointer &event); -+ -+ /** -+ * Distribute time out action. -+ * -+ * @param event The event should be distribute. -+ * @param nowStart Dotting before distribution. -+ */ -+ void DistributeTimeAction(const InnerEvent::Pointer &event, InnerEvent::TimePoint nowStart); -+ -+ /** -+ * Delivery time out action. -+ * -+ * @param event The event should be distribute. -+ * @param nowStart Dotting before distribution. -+ */ -+ void DeliveryTimeAction(const InnerEvent::Pointer &event, InnerEvent::TimePoint nowStart); -+ -+ /** -+ * Print out the internal information about an object in the specified format, -+ * helping you diagnose internal errors of the object. -+ * -+ * @param dumpr The Dumper object you have implemented to process the output internal information. -+ */ -+ void Dump(Dumper &dumper); -+ -+ /** -+ * Check whether an event with the given ID can be found among the events that have been sent but not processed. -+ * -+ * @param innerEventId The id of the event. -+ */ -+ bool HasInnerEvent(uint32_t innerEventId); -+ -+ /** -+ * Check whether an event carrying the given param can be found among the events that have been sent but not -+ * processed. -+ * -+ * @param param Basic parameter of the event. -+ */ -+ bool HasInnerEvent(int64_t param); -+ -+ /** -+ * Check whether an event carrying the given param can be found among the events that have been sent but not -+ * processed. -+ * -+ * @param event InnerEvent whose name is to be obtained. -+ * @return Returns the task name if the given event contains a specific task; returns the event ID otherwise. -+ */ -+ std::string GetEventName(const InnerEvent::Pointer &event); -+ -+ /** -+ * Checks whether the current event handler is idle -+ * @return Returns true if current event handler is idle otherwise return false. -+ */ -+ bool IsIdle(); -+ -+protected: -+ /** -+ * Process the event. Developers should override this method. -+ * -+ * @param event The event should be processed. -+ */ -+ virtual void ProcessEvent(const InnerEvent::Pointer &event); -+ -+private: -+ std::shared_ptr eventRunner_; -+ CallbackTimeout deliveryTimeoutCallback_; -+ CallbackTimeout distributeTimeoutCallback_; -+ -+ static ThreadLocalData> currentEventHandler; -+}; -+} // namespace AppExecFwk -+} // namespace OHOS -+ -+#endif // #ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_EVENT_HANDLER_H -diff --git a/ohos_ndk_aosp/includes/libeventhandler/event_handler_errors.h b/ohos_ndk_aosp/includes/libeventhandler/event_handler_errors.h -new file mode 100644 -index 0000000000..f8aadc7ac9 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/libeventhandler/event_handler_errors.h -@@ -0,0 +1,46 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_EVENT_HANDLER_ERRORS_H -+#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_EVENT_HANDLER_ERRORS_H -+ -+#include "errors.h" -+ -+namespace OHOS { -+namespace AppExecFwk { -+// Module id of event handler is assigned in "appexecfwk_errors.h" -+const uint32_t APPEXECFWK_MODULE_EVENT_HANDLER = 0x10; -+constexpr ErrCode EVENT_HANDLER_ERR_OFFSET = ErrCodeOffset(SUBSYS_APPEXECFWK, APPEXECFWK_MODULE_EVENT_HANDLER); -+ -+enum { -+ // Invalid parameters. -+ EVENT_HANDLER_ERR_INVALID_PARAM = EVENT_HANDLER_ERR_OFFSET, -+ // Have not set event runner yet. -+ EVENT_HANDLER_ERR_NO_EVENT_RUNNER, -+ // Not support to listen file descriptors. -+ EVENT_HANDLER_ERR_FD_NOT_SUPPORT, -+ // File descriptor is already in listening. -+ EVENT_HANDLER_ERR_FD_ALREADY, -+ // Failed to listen file descriptor. -+ EVENT_HANDLER_ERR_FD_FAILED, -+ // No permit to start or stop deposited event runner. -+ EVENT_HANDLER_ERR_RUNNER_NO_PERMIT, -+ // Event runner is already running. -+ EVENT_HANDLER_ERR_RUNNER_ALREADY, -+}; -+} // namespace AppExecFwk -+} // namespace OHOS -+ -+#endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_EVENT_HANDLER_ERRORS_H -diff --git a/ohos_ndk_aosp/includes/libeventhandler/event_queue.h b/ohos_ndk_aosp/includes/libeventhandler/event_queue.h -new file mode 100644 -index 0000000000..a8029e795e ---- /dev/null -+++ b/ohos_ndk_aosp/includes/libeventhandler/event_queue.h -@@ -0,0 +1,261 @@ -+/* -+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_EVENT_QUEUE_H -+#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_EVENT_QUEUE_H -+ -+#include -+#include -+#include -+#include -+ -+#include "inner_event.h" -+#include "event_handler_errors.h" -+#include "file_descriptor_listener.h" -+#include "dumper.h" -+#include "logger.h" -+ -+namespace OHOS { -+namespace AppExecFwk { -+class IoWaiter; -+ -+class EventQueue final { -+public: -+ // Priority for the events -+ enum class Priority : uint32_t { -+ // Event that should be distributed at once if possible. -+ IMMEDIATE = 0, -+ // High priority event, sorted by handle time, should be distributed before low priority event. -+ HIGH, -+ // Normal event, sorted by handle time. -+ LOW, -+ // Event that should be distributed only if no other event right now. -+ IDLE, -+ }; -+ -+ EventQueue(); -+ explicit EventQueue(const std::shared_ptr &ioWaiter); -+ ~EventQueue() = default; -+ DISALLOW_COPY_AND_MOVE(EventQueue); -+ -+ /** -+ * Insert an event into event queue with different priority. -+ * The events will be sorted by handle time. -+ * -+ * @param event Event instance which should be added into event queue. -+ * @param Priority Priority of the event -+ * -+ * @see #Priority -+ */ -+ void Insert(InnerEvent::Pointer &event, Priority priority = Priority::LOW); -+ -+ /** -+ * Remove events if its owner is invalid. -+ */ -+ void RemoveOrphan(); -+ -+ /** -+ * Remove events with specified requirements. -+ * -+ * @param owner Owner of the event which is point to an instance of 'EventHandler'. -+ */ -+ void Remove(const std::shared_ptr &owner); -+ -+ /** -+ * Remove events with specified requirements. -+ * -+ * @param owner Owner of the event which is point to an instance of 'EventHandler'. -+ * @param innerEventId Remove events by event id. -+ */ -+ void Remove(const std::shared_ptr &owner, uint32_t innerEventId); -+ -+ /** -+ * Remove events with specified requirements. -+ * -+ * @param owner Owner of the event which is point to an instance of 'EventHandler'. -+ * @param innerEventId Remove events by event id. -+ * @param param Remove events by value of param. -+ */ -+ void Remove(const std::shared_ptr &owner, uint32_t innerEventId, int64_t param); -+ -+ /** -+ * Remove events with specified requirements. -+ * -+ * @param owner Owner of the event which is point to an instance of 'EventHandler'. -+ * @param name Remove events by name of the task. -+ */ -+ void Remove(const std::shared_ptr &owner, const std::string &name); -+ -+ /** -+ * Add file descriptor listener for a file descriptor. -+ * -+ * @param fileDescriptor File descriptor. -+ * @param events Events from file descriptor, such as input, output, error -+ * @param listener Listener callback. -+ * @return Return 'ERR_OK' on success. -+ */ -+ ErrCode AddFileDescriptorListener( -+ int32_t fileDescriptor, uint32_t events, const std::shared_ptr &listener); -+ -+ /** -+ * Remove all file descriptor listeners for a specified owner. -+ * -+ * @param owner Owner of the event which is point to an instance of 'FileDescriptorListener'. -+ */ -+ void RemoveFileDescriptorListener(const std::shared_ptr &owner); -+ -+ /** -+ * Remove file descriptor listener for a file descriptor. -+ * -+ * @param fileDescriptor File descriptor. -+ */ -+ void RemoveFileDescriptorListener(int32_t fileDescriptor); -+ -+ /** -+ * Prepare event queue, before calling {@link #GetEvent}. -+ * If {@link #Finish} is called, prepare event queue again, before calling {@link #GetEvent}. -+ */ -+ void Prepare(); -+ -+ /** -+ * Exit from blocking in {@link #GetEvent}, and mark the event queue finished. -+ * After calling {@link #Finish}, {@link #GetEvent} never returns any event, until {@link #Prepare} is called. -+ */ -+ void Finish(); -+ -+ /** -+ * Get event from event queue one by one. -+ * Before calling this method, developers should call {@link #Prepare} first. -+ * If none should be handled right now, the thread will be blocked in this method. -+ * Call {@link #Finish} to exit from blocking. -+ * -+ * @return Returns nullptr if event queue is not prepared yet, or {@link #Finish} is called. -+ * Otherwise returns event instance. -+ */ -+ InnerEvent::Pointer GetEvent(); -+ -+ /** -+ * Get expired event from event queue one by one. -+ * Before calling this method, developers should call {@link #Prepare} first. -+ * -+ * @param nextExpiredTime Output the expired time for the next event. -+ * @return Returns nullptr if none in event queue is expired. -+ * Otherwise returns event instance. -+ */ -+ InnerEvent::Pointer GetExpiredEvent(InnerEvent::TimePoint &nextExpiredTime); -+ -+ /** -+ * Prints out the internal information about an object in the specified format, -+ * helping you diagnose internal errors of the object. -+ * -+ * @param dumpr The Dumper object you have implemented to process the output internal information. -+ */ -+ void Dump(Dumper &dumper); -+ -+ /** -+ * Print out the internal information about an object in the specified format, -+ * helping you diagnose internal errors of the object. -+ * -+ * @param queueInfo queue Info. -+ */ -+ void DumpQueueInfo(std::string& queueInfo); -+ -+ /** -+ * Checks whether the current EventHandler is idle. -+ * -+ * @return Returns true if all events have been processed; returns false otherwise. -+ */ -+ bool IsIdle(); -+ -+ /** -+ * Check whether this event queue is empty. -+ * -+ * @return If queue is empty return true otherwise return false. -+ */ -+ bool IsQueueEmpty(); -+ -+ /** -+ * Check whether an event with the given ID can be found among the events that have been sent but not processed. -+ * -+ * @param owner Owner of the event which is point to an instance of 'EventHandler'. -+ * @param innerEventId The id of the event. -+ */ -+ bool HasInnerEvent(const std::shared_ptr &owner, uint32_t innerEventId); -+ -+ /** -+ * Check whether an event carrying the given param can be found among the events that have been sent but not -+ * processed. -+ * -+ * @param owner The owner of the event which is point to an instance of 'EventHandler'. -+ * @param param The basic parameter of the event. -+ */ -+ bool HasInnerEvent(const std::shared_ptr &owner, int64_t param); -+ -+private: -+ using RemoveFilter = std::function; -+ using HasFilter = std::function; -+ -+ /* -+ * To avoid starvation of lower priority event queue, give a chance to process lower priority events, -+ * after continuous processing several higher priority events. -+ */ -+ static const uint32_t DEFAULT_MAX_HANDLED_EVENT_COUNT = 5; -+ -+ // Sub event queues for IMMEDIATE, HIGH and LOW priority. So use value of IDLE as size. -+ static const uint32_t SUB_EVENT_QUEUE_NUM = static_cast(Priority::IDLE); -+ -+ struct SubEventQueue { -+ std::list queue; -+ uint32_t handledEventsCount{0}; -+ uint32_t maxHandledEventsCount{DEFAULT_MAX_HANDLED_EVENT_COUNT}; -+ }; -+ -+ void Remove(const RemoveFilter &filter); -+ bool HasInnerEvent(const HasFilter &filter); -+ InnerEvent::Pointer PickEventLocked(const InnerEvent::TimePoint &now, InnerEvent::TimePoint &nextWakeUpTime); -+ InnerEvent::Pointer GetExpiredEventLocked(InnerEvent::TimePoint &nextExpiredTime); -+ void WaitUntilLocked(const InnerEvent::TimePoint &when, std::unique_lock &lock); -+ void HandleFileDescriptorEvent(int32_t fileDescriptor, uint32_t events); -+ bool EnsureIoWaiterSupportListerningFileDescriptorLocked(); -+ -+ std::mutex queueLock_; -+ -+ // Sub event queues for different priority. -+ std::array subEventQueues_; -+ -+ // Event queue for IDLE events. -+ std::list idleEvents_; -+ -+ // Next wake up time when block in 'GetEvent'. -+ InnerEvent::TimePoint wakeUpTime_ { InnerEvent::TimePoint::max() }; -+ -+ // Mark if in idle mode, and record the start time of idle. -+ InnerEvent::TimePoint idleTimeStamp_ { InnerEvent::Clock::now() }; -+ -+ bool isIdle_{true}; -+ -+ // Mark if the event queue is finished. -+ bool finished_{true}; -+ -+ // IO waiter used to block if no events while calling 'GetEvent'. -+ std::shared_ptr ioWaiter_; -+ -+ // File descriptor listeners to handle IO events. -+ std::map> listeners_; -+}; -+} // namespace AppExecFwk -+} // namespace OHOS -+ -+#endif // #ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_EVENT_QUEUE_H -diff --git a/ohos_ndk_aosp/includes/libeventhandler/event_runner.h b/ohos_ndk_aosp/includes/libeventhandler/event_runner.h -new file mode 100644 -index 0000000000..df408141f9 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/libeventhandler/event_runner.h -@@ -0,0 +1,222 @@ -+/* -+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_EVENT_RUNNER_H -+#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_EVENT_RUNNER_H -+ -+#include -+ -+#include "event_queue.h" -+#include "dumper.h" -+#include "logger.h" -+ -+namespace OHOS { -+namespace AppExecFwk { -+class EventInnerRunner; -+ -+class EventRunner final { -+public: -+ EventRunner() = delete; -+ ~EventRunner(); -+ DISALLOW_COPY_AND_MOVE(EventRunner); -+ -+ /** -+ * Create new 'EventRunner'. -+ * -+ * @param inNewThread True if create new thread to start the 'EventRunner' automatically. -+ * @return Returns shared pointer of the new 'EventRunner'. -+ */ -+ static std::shared_ptr Create(bool inNewThread = true); -+ -+ /** -+ * Create new 'EventRunner' and start to run in a new thread. -+ * -+ * @param threadName Thread name of the new created thread. -+ * @return Returns shared pointer of the new 'EventRunner'. -+ */ -+ static std::shared_ptr Create(const std::string &threadName); -+ -+ /** -+ * Create new 'EventRunner' and start to run in a new thread. -+ * Eliminate ambiguity, while calling like 'EventRunner::Create("threadName")'. -+ * -+ * @param threadName Thread name of the new created thread. -+ * @return Returns shared pointer of the new 'EventRunner'. -+ */ -+ static inline std::shared_ptr Create(const char *threadName) -+ { -+ return Create((threadName != nullptr) ? std::string(threadName) : std::string()); -+ } -+ -+ /** -+ * Get event runner on current thread. -+ * -+ * @return Returns shared pointer of the current 'EventRunner'. -+ */ -+ static std::shared_ptr Current(); -+ -+ /** -+ * Start to run the 'EventRunner'. Only used for the 'EventRunner' which is not running in new thread. -+ * Only running on single thread. -+ * -+ * @return Returns 'ERR_OK' on success. -+ */ -+ ErrCode Run(); -+ -+ /** -+ * Stop to run the 'EventRunner'. Only used for the 'EventRunner' which is not running in new thread. -+ * It is a good practice to call {@link #Stop} on the same thread that called {@link #Run}. -+ * -+ * @return Returns 'ERR_OK' on success. -+ */ -+ ErrCode Stop(); -+ -+ /** -+ * Get thread name -+ * -+ * @return Returns thread name. -+ */ -+ std::string GetRunnerThreadName() const; -+ -+ /** -+ * Get event queue from event runner. -+ * This method only called by 'EventHandler'. -+ * -+ * @return Returns event queue. -+ */ -+ inline const std::shared_ptr &GetEventQueue() const -+ { -+ return queue_; -+ } -+ -+ /** -+ * Obtain the event queue of the EventRunner associated with the current thread. -+ * -+ * @return Return current event queue. -+ */ -+ static std::shared_ptr GetCurrentEventQueue(); -+ -+ /** -+ * Print out the internal information about an object in the specified format, -+ * helping you diagnose internal errors of the object. -+ * -+ * @param dumpr The Dumper object you have implemented to process the output internal information. -+ */ -+ void Dump(Dumper &dumper); -+ -+ /** -+ * Print out the internal information about an object in the specified format, -+ * helping you diagnose internal errors of the object. -+ * -+ * @param runnerInfo runner Info. -+ */ -+ void DumpRunnerInfo(std::string& runnerInfo); -+ -+ /** -+ * Set the Logger object for logging messages that are processed by this event runner. -+ * -+ * @param logger The Logger object you have implemented for logging messages. -+ */ -+ void SetLogger(const std::shared_ptr &logger); -+ -+ /** -+ * Obtain the ID of the worker thread associated with this EventRunner. -+ * -+ * @return thread id. -+ */ -+ uint64_t GetThreadId(); -+ -+ /** -+ * Check whether the current thread is the worker thread of this EventRunner. -+ * -+ * @return Returns true if the current thread is the worker thread of this EventRunner; returns false otherwise. -+ */ -+ bool IsCurrentRunnerThread(); -+ -+ /** -+ * Set the distribution standard expiration time. -+ * -+ * @param deliveryTimeout the distribution standard expiration time. -+ */ -+ void SetDeliveryTimeout(int64_t deliveryTimeout) -+ { -+ deliveryTimeout_ = deliveryTimeout; -+ } -+ -+ /** -+ * Get the distribution standard expiration time. -+ * -+ * @return the distribution standard expiration time. -+ */ -+ int64_t GetDeliveryTimeout() const -+ { -+ return deliveryTimeout_; -+ } -+ -+ /** -+ * Set the execution standard timeout period. -+ * -+ * @param distributeTimeout the distribution standard expiration time. -+ */ -+ void SetDistributeTimeout(int64_t distributeTimeout) -+ { -+ distributeTimeout_ = distributeTimeout; -+ } -+ -+ /** -+ * Get the execution standard timeout period. -+ * -+ * @return the distribution standard expiration time. -+ */ -+ int64_t GetDistributeTimeout() const -+ { -+ return distributeTimeout_; -+ } -+ -+ /** -+ * Obtains the EventRunner for the main thread of the application. -+ * -+ * @return Returns the EventRunner for the main thread of the application. -+ */ -+ static std::shared_ptr GetMainEventRunner(); -+ -+private: -+ explicit EventRunner(bool deposit); -+ -+ friend class EventHandler; -+ -+ /** -+ * Check whether this event runner is running. -+ * -+ * @return if this event runner is running return true otherwise return false -+ */ -+ inline bool IsRunning() const -+ { -+ // If this runner is deposited, it it always running -+ return (deposit_) || (running_.load()); -+ } -+ -+ int64_t deliveryTimeout_ = 0; -+ int64_t distributeTimeout_ = 0; -+ bool deposit_{true}; -+ std::atomic running_{false}; -+ std::shared_ptr queue_; -+ std::shared_ptr innerRunner_; -+ static std::shared_ptr mainRunner_; -+}; -+} // namespace AppExecFwk -+} // namespace OHOS -+ -+#endif // #ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_EVENT_RUNNER_H -diff --git a/ohos_ndk_aosp/includes/libeventhandler/file_descriptor_listener.h b/ohos_ndk_aosp/includes/libeventhandler/file_descriptor_listener.h -new file mode 100644 -index 0000000000..e299c16033 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/libeventhandler/file_descriptor_listener.h -@@ -0,0 +1,98 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_FILE_DESCRIPTOR_LISTENER_H -+#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_FILE_DESCRIPTOR_LISTENER_H -+ -+#include -+#include -+ -+#include "nocopyable.h" -+ -+namespace OHOS { -+namespace AppExecFwk { -+// Listen input or output events -+const uint32_t FILE_DESCRIPTOR_INPUT_EVENT = 1; -+const uint32_t FILE_DESCRIPTOR_OUTPUT_EVENT = 2; -+// Listen shutdown and exception events automatically, so not necessary to set. -+const uint32_t FILE_DESCRIPTOR_SHUTDOWN_EVENT = 4; -+const uint32_t FILE_DESCRIPTOR_EXCEPTION_EVENT = 8; -+const uint32_t FILE_DESCRIPTOR_EVENTS_MASK = (FILE_DESCRIPTOR_INPUT_EVENT | FILE_DESCRIPTOR_OUTPUT_EVENT); -+ -+class EventHandler; -+ -+class FileDescriptorListener { -+public: -+ DISALLOW_COPY_AND_MOVE(FileDescriptorListener); -+ -+ /** -+ * Called while file descriptor is readable. -+ * -+ * @param fileDescriptor File descriptor which is readable. -+ */ -+ virtual void OnReadable(int32_t fileDescriptor); -+ -+ /** -+ * Called while file descriptor is writable. -+ * -+ * @param fileDescriptor File descriptor which is writable. -+ */ -+ virtual void OnWritable(int32_t fileDescriptor); -+ -+ /** -+ * Called while shutting down this file descriptor. -+ * -+ * @param fileDescriptor File descriptor which is shutting down. -+ */ -+ virtual void OnShutdown(int32_t fileDescriptor); -+ -+ /** -+ * Called while error happened on this file descriptor. -+ * -+ * @param fileDescriptor Error happened on this file descriptor. -+ */ -+ virtual void OnException(int32_t fileDescriptor); -+ -+ /** -+ * Get owner of the event. -+ * -+ * @return Returns owner of the event after it has been sent. -+ */ -+ inline std::shared_ptr GetOwner() const -+ { -+ return owner_.lock(); -+ } -+ -+ /** -+ * Set owner of the event. -+ * -+ * @param owner Owner for the event. -+ */ -+ inline void SetOwner(const std::shared_ptr &owner) -+ { -+ owner_ = owner; -+ } -+ -+protected: -+ FileDescriptorListener() = default; -+ virtual ~FileDescriptorListener() = default; -+ -+private: -+ std::weak_ptr owner_; -+}; -+} // namespace AppExecFwk -+} // namespace OHOS -+ -+#endif // #ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_FILE_DESCRIPTOR_LISTENER_H -diff --git a/ohos_ndk_aosp/includes/libeventhandler/inner_event.h b/ohos_ndk_aosp/includes/libeventhandler/inner_event.h -new file mode 100644 -index 0000000000..e05a7c0497 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/libeventhandler/inner_event.h -@@ -0,0 +1,530 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_INNER_EVENT_H -+#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_INNER_EVENT_H -+ -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#include "nocopyable.h" -+ -+namespace OHOS { -+namespace HiviewDFX { -+class HiTraceId; -+} -+ -+namespace AppExecFwk { -+using HiTraceId = OHOS::HiviewDFX::HiTraceId; -+ -+class EventHandler; -+ -+const std::string LINE_SEPARATOR = "\n"; -+ -+class InnerEvent final { -+public: -+ using Clock = std::chrono::steady_clock; -+ using TimePoint = std::chrono::time_point; -+ using Callback = std::function; -+ using Pointer = std::unique_ptr; -+ -+ class Waiter { -+ public: -+ Waiter() = default; -+ virtual ~Waiter() = default; -+ DISALLOW_COPY_AND_MOVE(Waiter); -+ -+ virtual void Wait() = 0; -+ virtual void Notify() = 0; -+ }; -+ -+ DISALLOW_COPY_AND_MOVE(InnerEvent); -+ -+ /** -+ * Get InnerEvent instance from pool. -+ * -+ * @param innerEventId The id of the event. -+ * @param param Basic parameter of the event, default is 0. -+ * @return Returns the pointer of InnerEvent instance. -+ */ -+ static Pointer Get(uint32_t innerEventId, int64_t param = 0); -+ -+ /** -+ * Get InnerEvent instance from pool. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Shared pointer of the object. -+ * @param param Basic parameter of the event, default is 0. -+ * @return Returns the pointer of InnerEvent instance. -+ */ -+ template -+ static inline Pointer Get(uint32_t innerEventId, const std::shared_ptr &object, int64_t param = 0) -+ { -+ auto event = Get(innerEventId, param); -+ event->SaveSharedPtr(object); -+ return event; -+ } -+ -+ /** -+ * Get InnerEvent instance from pool. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Weak pointer of the object. -+ * @param param Basic parameter of the event, default is 0. -+ * @return Returns the pointer of InnerEvent instance. -+ */ -+ template -+ static inline Pointer Get(uint32_t innerEventId, const std::weak_ptr &object, int64_t param = 0) -+ { -+ auto event = Get(innerEventId, param); -+ event->SaveSharedPtr(object); -+ return event; -+ } -+ -+ /** -+ * Get InnerEvent instance from pool. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Unique pointer of the object. -+ * @param param Basic parameter of the event, default is 0. -+ * @return Returns the pointer of InnerEvent instance. -+ */ -+ template -+ static inline Pointer Get(uint32_t innerEventId, std::unique_ptr &&object, int64_t param = 0) -+ { -+ auto event = Get(innerEventId, param); -+ event->SaveUniquePtr(object); -+ return event; -+ } -+ -+ /** -+ * Get InnerEvent instance from pool. -+ * -+ * @param innerEventId The id of the event. -+ * @param object Unique pointer of the object. -+ * @param param Basic parameter of the event, default is 0. -+ * @return Returns the pointer of InnerEvent instance. -+ */ -+ template -+ static inline Pointer Get(uint32_t innerEventId, std::unique_ptr &object, int64_t param = 0) -+ { -+ auto event = Get(innerEventId, param); -+ event->SaveUniquePtr(object); -+ return event; -+ } -+ -+ /** -+ * Get InnerEvent instance from pool. -+ * -+ * @param innerEventId The id of the event. -+ * @param param Basic parameter of the event. -+ * @param object Shared pointer of the object. -+ * @return Returns the pointer of InnerEvent instance. -+ */ -+ template -+ static inline Pointer Get(uint32_t innerEventId, int64_t param, const std::shared_ptr &object) -+ { -+ auto event = Get(innerEventId, param); -+ event->SaveSharedPtr(object); -+ return event; -+ } -+ -+ /** -+ * Get InnerEvent instance from pool. -+ * -+ * @param innerEventId The id of the event. -+ * @param param Basic parameter of the event. -+ * @param object Weak pointer of the object. -+ * @return Returns the pointer of InnerEvent instance. -+ */ -+ template -+ static inline Pointer Get(uint32_t innerEventId, int64_t param, const std::weak_ptr &object) -+ { -+ auto event = Get(innerEventId, param); -+ event->SaveSharedPtr(object); -+ return event; -+ } -+ -+ /** -+ * Get InnerEvent instance from pool. -+ * -+ * @param innerEventId The id of the event. -+ * @param param Basic parameter of the event. -+ * @param object Unique pointer of the object. -+ * @return Returns the pointer of InnerEvent instance. -+ */ -+ template -+ static inline Pointer Get(uint32_t innerEventId, int64_t param, std::unique_ptr &&object) -+ { -+ auto event = Get(innerEventId, param); -+ event->SaveUniquePtr(object); -+ return event; -+ } -+ -+ /** -+ * Get InnerEvent instance from pool. -+ * -+ * @param innerEventId The id of the event. -+ * @param param Basic parameter of the event. -+ * @param object Unique pointer of the object. -+ * @return Returns the pointer of InnerEvent instance. -+ */ -+ template -+ static inline Pointer Get(uint32_t innerEventId, int64_t param, std::unique_ptr &object) -+ { -+ auto event = Get(innerEventId, param); -+ event->SaveUniquePtr(object); -+ return event; -+ } -+ -+ /** -+ * Get InnerEvent instance from pool. -+ * -+ * @param callback Callback for task. -+ * @param name Name of task. -+ * @return Returns the pointer of InnerEvent instance, if callback is invalid, returns nullptr object. -+ */ -+ static Pointer Get(const Callback &callback, const std::string &name = std::string()); -+ -+ /** -+ * Get InnerEvent instance from pool. -+ * -+ * @return Returns the pointer of InnerEvent instance -+ */ -+ static Pointer Get(); -+ -+ /** -+ * Get owner of the event. -+ * -+ * @return Returns owner of the event after it has been sent. -+ */ -+ inline std::shared_ptr GetOwner() const -+ { -+ return owner_.lock(); -+ } -+ -+ /** -+ * Set owner of the event. -+ * -+ * @param owner Owner for the event. -+ */ -+ inline void SetOwner(const std::shared_ptr &owner) -+ { -+ owner_ = owner; -+ } -+ -+ /** -+ * Get handle time of the event. -+ * -+ * @return Returns handle time of the event after it has been sent. -+ */ -+ inline const TimePoint &GetHandleTime() const -+ { -+ return handleTime_; -+ } -+ -+ /** -+ * Set handle time of the event. -+ * -+ * @param handleTime Handle time of the event. -+ */ -+ inline void SetHandleTime(const TimePoint &handleTime) -+ { -+ handleTime_ = handleTime; -+ } -+ -+ /** -+ * Get send time of the event. -+ * -+ * @return Returns send time of the event after it has been sent. -+ */ -+ inline const TimePoint &GetSendTime() const -+ { -+ return sendTime_; -+ } -+ -+ /** -+ * Set send time of the event. -+ * -+ * @param sendTime Send time of the event. -+ */ -+ inline void SetSendTime(const TimePoint &sendTime) -+ { -+ sendTime_ = sendTime; -+ } -+ -+ /** -+ * Get id of the event. -+ * Make sure {@link #hasTask} returns false. -+ * -+ * @return Returns id of the event after it has been sent. -+ */ -+ inline uint32_t GetInnerEventId() const -+ { -+ return innerEventId_; -+ } -+ -+ /** -+ * Get basic param of the event. -+ * Make sure {@link #hasTask} returns false. -+ * -+ * @return Returns basic param of the event after it has been sent. -+ */ -+ inline int64_t GetParam() const -+ { -+ return param_; -+ } -+ -+ /** -+ * Get saved object. -+ * -+ * @return Returns shared pointer of saved object. -+ */ -+ template -+ std::shared_ptr GetSharedObject() const -+ { -+ const std::shared_ptr &sharedObject = *reinterpret_cast *>(smartPtr_); -+ if (CalculateSmartPtrTypeId(sharedObject) == smartPtrTypeId_) { -+ return sharedObject; -+ } -+ -+ const std::weak_ptr &weakObject = *reinterpret_cast *>(smartPtr_); -+ if (CalculateSmartPtrTypeId(weakObject) == smartPtrTypeId_) { -+ return weakObject.lock(); -+ } -+ -+ WarnSmartPtrCastMismatch(); -+ return nullptr; -+ } -+ -+ /** -+ * Get saved object. -+ * -+ * @return Returns unique pointer of saved object. -+ */ -+ template -+ std::unique_ptr GetUniqueObject() const -+ { -+ std::unique_ptr &object = *reinterpret_cast *>(smartPtr_); -+ if (CalculateSmartPtrTypeId(object) == smartPtrTypeId_) { -+ return std::move(object); -+ } -+ -+ WarnSmartPtrCastMismatch(); -+ return nullptr; -+ } -+ -+ /** -+ * Get saved object. -+ * -+ * @return Returns unique pointer of saved object. -+ */ -+ template -+ std::unique_ptr GetUniqueObject() const -+ { -+ std::unique_ptr &object = *reinterpret_cast *>(smartPtr_); -+ if (CalculateSmartPtrTypeId(object) == smartPtrTypeId_) { -+ return std::move(object); -+ } -+ -+ WarnSmartPtrCastMismatch(); -+ return std::unique_ptr(nullptr, nullptr); -+ } -+ -+ /** -+ * Get task name. -+ * Make sure {@link #hasTask} returns true. -+ * -+ * @return Returns the task name. -+ */ -+ inline const std::string &GetTaskName() const -+ { -+ return taskName_; -+ } -+ -+ /** -+ * Get task callback. -+ * Make sure {@link #hasTask} returns true. -+ * -+ * @return Returns the callback of the task. -+ */ -+ inline const Callback &GetTaskCallback() const -+ { -+ return taskCallback_; -+ } -+ -+ /** -+ * Obtains the Runnable task that will be executed when this InnerEvent is handled. -+ * -+ * @return Returns the callback of the task. -+ */ -+ inline const Callback &GetTask() const -+ { -+ return GetTaskCallback(); -+ } -+ -+ /** -+ * Check whether it takes a task callback in event. -+ * -+ * @return Returns true if it takes a task callback. -+ */ -+ inline bool HasTask() const -+ { -+ return static_cast(taskCallback_); -+ } -+ -+ /** -+ * Prints out the internal information about an object in the specified format, -+ * helping you diagnose internal errors of the object. -+ * -+ * @param return The content of the event. -+ */ -+ std::string Dump(); -+ -+private: -+ using SmartPtrDestructor = void (*)(void *); -+ -+ InnerEvent() = default; -+ ~InnerEvent() = default; -+ -+ void ClearEvent(); -+ -+ static void WarnSmartPtrCastMismatch(); -+ -+ template -+ static void ReleaseSmartPtr(void *smartPtr) -+ { -+ if (smartPtr != nullptr) { -+ delete reinterpret_cast(smartPtr); -+ } -+ } -+ -+ template -+ inline void SaveSharedPtr(const T &object) -+ { -+ smartPtr_ = new T(object); -+ smartPtrDtor_ = ReleaseSmartPtr; -+ smartPtrTypeId_ = CalculateSmartPtrTypeId(object); -+ } -+ -+ template -+ inline void SaveUniquePtr(T &object) -+ { -+ smartPtr_ = new T(std::move(object)); -+ smartPtrDtor_ = ReleaseSmartPtr; -+ smartPtrTypeId_ = CalculateSmartPtrTypeId(object); -+ } -+ -+ /** -+ * if event has trace id ,return trace id, else create span id, -+ * store it in event and return. -+ * -+ * @return return hiTrace Id. -+ */ -+ const std::shared_ptr GetOrCreateTraceId(); -+ -+ /** -+ * return trace id. -+ * -+ * @return return hiTrace Id. -+ */ -+ const std::shared_ptr GetTraceId(); -+ -+ /* -+ * Calculate the type id for different smart pointers. -+ */ -+#ifdef __GXX_RTTI -+ // If RTTI(Run-Time Type Info) is enabled, use hash code of type info. -+ template -+ static inline size_t CalculateSmartPtrTypeId(const T &) -+ { -+ return typeid(T).hash_code(); -+ } -+#else // #ifdef __GXX_RTTI -+ // Otherwise, generate type id using smart pointer type and the size of the elements they contain. -+ static const size_t SHARED_PTR_TYPE = 0x10000000; -+ static const size_t WEAK_PTR_TYPE = 0x20000000; -+ static const size_t UNIQUE_PTR_TYPE = 0x30000000; -+ static const size_t UNIQUE_PTR_ARRAY_TYPE = 0x40000000; -+ -+ template -+ static inline size_t CalculateSmartPtrTypeId(const std::shared_ptr &) -+ { -+ return (sizeof(T) | SHARED_PTR_TYPE); -+ } -+ -+ template -+ static inline size_t CalculateSmartPtrTypeId(const std::weak_ptr &) -+ { -+ return (sizeof(T) | WEAK_PTR_TYPE); -+ } -+ -+ template -+ static inline size_t CalculateSmartPtrTypeId(const std::unique_ptr &) -+ { -+ return (sizeof(T) | (sizeof(D) - 1) | UNIQUE_PTR_TYPE); -+ } -+ -+ template -+ static inline size_t CalculateSmartPtrTypeId(const std::unique_ptr &) -+ { -+ return (sizeof(T) | (sizeof(D) - 1) | UNIQUE_PTR_ARRAY_TYPE); -+ } -+#endif // #ifdef __GXX_RTTI -+ -+ // Used by event handler to create waiter. -+ const std::shared_ptr &CreateWaiter(); -+ -+ // Used by event handler to tell whether event has waiter. -+ bool HasWaiter() const; -+ -+ // Let event pool to create instance of events. -+ friend class InnerEventPool; -+ // Let event handler to access private interface. -+ friend class EventHandler; -+ -+ std::weak_ptr owner_; -+ TimePoint handleTime_; -+ TimePoint sendTime_; -+ -+ // Event id of the event, if it is not a task object -+ uint32_t innerEventId_{0}; -+ -+ // Simple parameter for the event. -+ int64_t param_{0}; -+ -+ // Using to save smart pointer -+ size_t smartPtrTypeId_{0}; -+ void *smartPtr_{nullptr}; -+ SmartPtrDestructor smartPtrDtor_{nullptr}; -+ -+ // Task callback and its name. -+ Callback taskCallback_; -+ std::string taskName_; -+ -+ // Used for synchronized event. -+ std::shared_ptr waiter_; -+ -+ // use to store hitrace Id -+ std::shared_ptr hiTraceId_; -+}; -+} // namespace AppExecFwk -+} // namespace OHOS -+ -+#endif // #ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_INNER_EVENT_H -diff --git a/ohos_ndk_aosp/includes/libeventhandler/logger.h b/ohos_ndk_aosp/includes/libeventhandler/logger.h -new file mode 100644 -index 0000000000..e5b10bf64f ---- /dev/null -+++ b/ohos_ndk_aosp/includes/libeventhandler/logger.h -@@ -0,0 +1,32 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_LOGGER_H -+#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_LOGGER_H -+ -+namespace OHOS { -+namespace AppExecFwk { -+class Logger { -+public: -+ /** -+ * Processes the content of a specified string. -+ * @param message the content of a specified string. -+ */ -+ virtual void Log(const std::string &line) = 0; -+}; -+} // namespace AppExecFwk -+} // namespace OHOS -+ -+#endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_LIBEVENTHANDLER_INCLUDE_LOGGER_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/libeventhandler/native_implement_eventhandler.h b/ohos_ndk_aosp/includes/libeventhandler/native_implement_eventhandler.h -new file mode 100644 -index 0000000000..f100447077 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/libeventhandler/native_implement_eventhandler.h -@@ -0,0 +1,86 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef AAFWK_APPEXECFWK_NATIVE_IMPLEMENT_EVENTHANDLER_H -+#define AAFWK_APPEXECFWK_NATIVE_IMPLEMENT_EVENTHANDLER_H -+ -+#include "event_runner.h" -+ -+using OHOS::ErrCode; -+using OHOS::AppExecFwk::EventHandler; -+using OHOS::AppExecFwk::EventRunner; -+ -+typedef void (*FileFDCallback)(int32_t filedescriptor); -+ -+struct FileDescriptorCallbacks; -+struct EventRunnerNativeImplement { -+public: -+ EventRunnerNativeImplement(bool current); -+ ~EventRunnerNativeImplement(); -+ -+ /** -+ * Get current thread 'EventRunnerNativeImplement'. -+ * -+ * @return Returns pointer of the new 'EventRunnerNativeImplement'. -+ */ -+ static const EventRunnerNativeImplement *GetEventRunnerNativeObj(); -+ -+ /** -+ * Create new 'EventRunnerNativeImplement'. -+ * -+ * @return Returns pointer of the new 'EventRunnerNativeImplement'. -+ */ -+ static const EventRunnerNativeImplement *CreateEventRunnerNativeObj(); -+ -+ /** -+ * Start to run the 'EventRunnerNativeImplement'. Only running on single thread. -+ * -+ * @return Returns 'ERR_OK' on success. -+ */ -+ ErrCode RunEventRunnerNativeObj() const; -+ -+ /** -+ * Stop to run the 'EventRunnerNativeImplement'. -+ * -+ * @return Returns 'ERR_OK' on success. -+ */ -+ ErrCode StopEventRunnerNativeObj() const; -+ -+ /** -+ * Add file descriptor listener for a file descriptor. -+ * -+ * @param fileDescriptor File descriptor. -+ * @param events Events from file descriptor, such as input, output, error -+ * @param onReadableCallback Called while file descriptor is readable. -+ * @param onWritableCallback Called while file descriptor is writable. -+ * @param onShutdownCallback Called while shutting down this file descriptor. -+ * @param onExceptionCallback Called while error happened on this file descriptor. -+ * @return Return 'ERR_OK' on success. -+ */ -+ ErrCode AddFileDescriptorListener( -+ int32_t fileDescriptor, uint32_t events, const FileDescriptorCallbacks *fdCallbacks) const; -+ -+ /** -+ * Remove file descriptor listener for a file descriptor. -+ * -+ * @param fileDescriptor File descriptor. -+ */ -+ void RemoveFileDescriptorListener(int32_t fileDescriptor) const; -+ -+private: -+ std::shared_ptr eventRunner_ = nullptr; -+}; -+ -+#endif // AAFWK_APPEXECFWK_NATIVE_IMPLEMENT_EVENTHANDLER_H -diff --git a/ohos_ndk_aosp/includes/media/av_common.h b/ohos_ndk_aosp/includes/media/av_common.h -new file mode 100644 -index 0000000000..ea366fe7d3 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/av_common.h -@@ -0,0 +1,110 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+#ifndef AV_COMMOM_H -+#define AV_COMMOM_H -+ -+#include -+#include -+#include "format.h" -+ -+namespace OHOS { -+namespace Media { -+/** -+ * @brief Media type -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum MediaType : int32_t { -+ /** -+ * track is audio. -+ */ -+ MEDIA_TYPE_AUD = 0, -+ /** -+ * track is video. -+ */ -+ MEDIA_TYPE_VID = 1, -+ /** -+ * track is subtitle. -+ */ -+ MEDIA_TYPE_SUBTITLE = 2, -+}; -+ -+/** -+ * @brief -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum VideoPixelFormat { -+ /** -+ * yuv 420 planar. -+ */ -+ YUVI420 = 1, -+ /** -+ * NV12. yuv 420 semiplanar. -+ */ -+ NV12 = 2, -+ /** -+ * NV21. yvu 420 semiplanar. -+ */ -+ NV21 = 3, -+ /** -+ * format from surface. -+ */ -+ SURFACE_FORMAT = 4, -+}; -+ -+/** -+ * @brief the struct of geolocation -+ * -+ * @param latitude float: latitude in degrees. Its value must be in the range [-90, 90]. -+ * @param longitude float: longitude in degrees. Its value must be in the range [-180, 180]. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+struct Location { -+ float latitude = 0; -+ float longitude = 0; -+}; -+ -+/** -+ * @brief Enumerates the seek mode. -+ */ -+enum AVSeekMode : uint8_t { -+ /** -+ * @brief this mode is used to seek to a key frame that is located right or before at -+ * the given timestamp. -+ */ -+ AV_SEEK_PREV_SYNC = 0, -+ /** -+ * @brief this mode is used to seek to a key frame that is located right or after at -+ * the given timestamp. -+ */ -+ AV_SEEK_NEXT_SYNC = 1, -+ /** -+ * @brief this mode is used to seek to a key frame that is located right or closest at -+ * the given timestamp. -+ */ -+ AV_SEEK_CLOSEST_SYNC = 2, -+ /** -+ * @brief this mode is used to seek to a frame that is located right or closest at -+ * the given timestamp. -+ */ -+ AV_SEEK_CLOSEST = 3, -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // AV_COMMOM_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/media/avcodec_audio_decoder.h b/ohos_ndk_aosp/includes/media/avcodec_audio_decoder.h -new file mode 100644 -index 0000000000..906dd5b6a6 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/avcodec_audio_decoder.h -@@ -0,0 +1,221 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef AVCODEC_AUDIO_DECODER_H -+#define AVCODEC_AUDIO_DECODER_H -+ -+#include "avcodec_common.h" -+#include "avcodec_info.h" -+#include "avsharedmemory.h" -+#include "format.h" -+ -+namespace OHOS { -+namespace Media { -+class AudioDecoder { -+public: -+ virtual ~AudioDecoder() = default; -+ -+ /** -+ * @brief Configure the decoder. -+ * -+ * @param format The format of the input data and the desired format of the output data. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Configure(const Format &format) = 0; -+ -+ /** -+ * @brief Prepare for decoding. -+ * -+ * This function must be called after {@link Configure} and before {@link Start} -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Prepare() = 0; -+ -+ /** -+ * @brief Start decoding. -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Start() = 0; -+ -+ /** -+ * @brief Stop decoding. -+ * -+ * This function must be called during running -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Stop() = 0; -+ -+ /** -+ * @brief Flush both input and output buffers of the decoder. -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Flush() = 0; -+ -+ /** -+ * @brief Restores the decoder to the initial state. -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Reset() = 0; -+ -+ /** -+ * @brief Releases decoder resources. All methods are unavailable after calling this. -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Release() = 0; -+ -+ /** -+ * @brief Returns a {@link AVSharedMemory} object for a input buffer index that contains the data. -+ * -+ * This function must be called during running -+ * -+ * @param index The index of the input buffer. -+ * @return Returns {@link AVSharedMemory} if success; returns nullptr otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual std::shared_ptr GetInputBuffer(uint32_t index) = 0; -+ -+ /** -+ * @brief Submits input buffer to decoder. -+ * -+ * This function must be called during running -+ * -+ * @param index The index of the input buffer. -+ * @param info The info of the input buffer. For details, see {@link AVCodecBufferInfo} -+ * @param flag The flag of the input buffer. For details, see {@link AVCodecBufferFlag} -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0; -+ -+ /** -+ * @brief Returns a {@link AVSharedMemory} object for a output buffer index that contains the data. -+ * -+ * This function must be called during running -+ * -+ * @param index The index of the output buffer. -+ * @return Returns {@link AVSharedMemory} if success; returns nullptr otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual std::shared_ptr GetOutputBuffer(uint32_t index) = 0; -+ -+ /** -+ * @brief Gets the format of the output data. -+ * -+ * This function must be called after {@link Configure} -+ * -+ * @param format -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t GetOutputFormat(Format &format) = 0; -+ -+ /** -+ * @brief Gets the audio decoder capability. -+ * -+ * @return Returns {@link AudioCaps}. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual std::shared_ptr GetAudioDecoderCaps() = 0; -+ -+ /** -+ * @brief Returns the output buffer to the decoder. -+ * -+ * This function must be called during running -+ * -+ * @param index The index of the output buffer. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t ReleaseOutputBuffer(uint32_t index) = 0; -+ -+ /** -+ * @brief Sets the parameters to the decoder. -+ * -+ * This function must be called after {@link Configure} -+ * -+ * @param format The parameters. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t SetParameter(const Format &format) = 0; -+ -+ /** -+ * @brief Registers a decoder listener. -+ * -+ * This function must be called before {@link Configure} -+ * -+ * @param callback Indicates the decoder listener to register. For details, see {@link AVCodecCallback}. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t SetCallback(const std::shared_ptr &callback) = 0; -+}; -+ -+class __attribute__((visibility("default"))) AudioDecoderFactory { -+public: -+ /** -+ * @brief Instantiate the preferred decoder of the given mime type. -+ * -+ * @param mime The mime type. -+ * @return Returns the preferred decoder. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ static std::shared_ptr CreateByMime(const std::string &mime); -+ -+ /** -+ * @brief Instantiates the designated decoder. -+ * -+ * @param name The decoder's name. -+ * @return Returns the designated decoder. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ static std::shared_ptr CreateByName(const std::string &name); -+private: -+ AudioDecoderFactory() = default; -+ ~AudioDecoderFactory() = default; -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // AVCODEC_AUDIO_DECODER_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/media/avcodec_audio_encoder.h b/ohos_ndk_aosp/includes/media/avcodec_audio_encoder.h -new file mode 100644 -index 0000000000..3b66b572a5 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/avcodec_audio_encoder.h -@@ -0,0 +1,221 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef AVCODEC_AUDIO_ENCODER_H -+#define AVCODEC_AUDIO_ENCODER_H -+ -+#include "avcodec_common.h" -+#include "avcodec_info.h" -+#include "avsharedmemory.h" -+#include "format.h" -+ -+namespace OHOS { -+namespace Media { -+class AudioEncoder { -+public: -+ virtual ~AudioEncoder() = default; -+ -+ /** -+ * @brief Configure the encoder. -+ * -+ * @param format The format of the input data and the desired format of the output data. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Configure(const Format &format) = 0; -+ -+ /** -+ * @brief Prepare for decoding. -+ * -+ * This function must be called after {@link Configure} and before {@link Start} -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Prepare() = 0; -+ -+ /** -+ * @brief Start decoding. -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Start() = 0; -+ -+ /** -+ * @brief Stop decoding. -+ * -+ * This function must be called during running -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Stop() = 0; -+ -+ /** -+ * @brief Flush both input and output buffers of the encoder. -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Flush() = 0; -+ -+ /** -+ * @brief Restores the encoder to the initial state. -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Reset() = 0; -+ -+ /** -+ * @brief Releases encoder resources. All methods are unavailable after calling this. -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Release() = 0; -+ -+ /** -+ * @brief Returns a {@link AVSharedMemory} object for a input buffer index that contains the data. -+ * -+ * This function must be called during running -+ * -+ * @param index The index of the input buffer. -+ * @return Returns {@link AVSharedMemory} if success; returns nullptr otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual std::shared_ptr GetInputBuffer(uint32_t index) = 0; -+ -+ /** -+ * @brief Submits input buffer to encoder. -+ * -+ * This function must be called during running -+ * -+ * @param index The index of the input buffer. -+ * @param info The info of the input buffer. For details, see {@link AVCodecBufferInfo} -+ * @param flag The flag of the input buffer. For details, see {@link AVCodecBufferFlag} -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0; -+ -+ /** -+ * @brief Returns a {@link AVSharedMemory} object for a output buffer index that contains the data. -+ * -+ * This function must be called during running -+ * -+ * @param index The index of the output buffer. -+ * @return Returns {@link AVSharedMemory} if success; returns nullptr otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual std::shared_ptr GetOutputBuffer(uint32_t index) = 0; -+ -+ /** -+ * @brief Gets the format of the output data. -+ * -+ * This function must be called after {@link Configure} -+ * -+ * @param format -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t GetOutputFormat(Format &format) = 0; -+ -+ /** -+ * @brief Gets the audio encoder capability. -+ * -+ * @return Returns {@link AudioCaps}. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual std::shared_ptr GetAudioEncoderCaps() = 0; -+ -+ /** -+ * @brief Returns the output buffer to the encoder. -+ * -+ * This function must be called during running -+ * -+ * @param index The index of the output buffer. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t ReleaseOutputBuffer(uint32_t index) = 0; -+ -+ /** -+ * @brief Sets the parameters to the encoder. -+ * -+ * This function must be called after {@link Configure} -+ * -+ * @param format The parameters. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t SetParameter(const Format &format) = 0; -+ -+ /** -+ * @brief Registers a encoder listener. -+ * -+ * This function must be called before {@link Configure} -+ * -+ * @param callback Indicates the encoder listener to register. For details, see {@link AVCodecCallback}. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t SetCallback(const std::shared_ptr &callback) = 0; -+}; -+ -+class __attribute__((visibility("default"))) AudioEncoderFactory { -+public: -+ /** -+ * @brief Instantiate the preferred encoder of the given mime type. -+ * -+ * @param mime The mime type. -+ * @return Returns the preferred encoder. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ static std::shared_ptr CreateByMime(const std::string &mime); -+ -+ /** -+ * @brief Instantiates the designated encoder. -+ * -+ * @param name The encoder's name. -+ * @return Returns the designated encoder. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ static std::shared_ptr CreateByName(const std::string &name); -+private: -+ AudioEncoderFactory() = default; -+ ~AudioEncoderFactory() = default; -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // AVCODEC_AUDIO_ENCODER_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/media/avcodec_common.h b/ohos_ndk_aosp/includes/media/avcodec_common.h -new file mode 100644 -index 0000000000..9907aa23fb ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/avcodec_common.h -@@ -0,0 +1,105 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+#ifndef AVCODEC_COMMOM_H -+#define AVCODEC_COMMOM_H -+ -+#include -+#include "av_common.h" -+#include "format.h" -+ -+namespace OHOS { -+namespace Media { -+/** -+ * @brief Error type of AVCodec -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum AVCodecErrorType : int32_t { -+ /* internal errors, error code passed by the errorCode, and definition see "MediaServiceErrCode" */ -+ AVCODEC_ERROR_INTERNAL, -+ /* extend error start. The extension error code agreed upon by the plug-in and -+ the application will be transparently transmitted by the service. */ -+ AVCODEC_ERROR_EXTEND_START = 0X10000, -+}; -+ -+enum AVCodecBufferFlag : uint32_t { -+ AVCODEC_BUFFER_FLAG_NONE = 0, -+ /* This signals the end of stream */ -+ AVCODEC_BUFFER_FLAG_EOS = 1 << 0, -+ /* This indicates that the buffer contains the data for a sync frame */ -+ AVCODEC_BUFFER_FLAG_SYNC_FRAME = 1 << 1, -+ /* This indicates that the buffer only contains part of a frame */ -+ AVCODEC_BUFFER_FLAG_PARTIAL_FRAME = 1 << 2, -+ /* This indicated that the buffer contains codec specific data */ -+ AVCODEC_BUFFER_FLAG_CODEC_DATA = 1 << 3, -+}; -+ -+struct AVCodecBufferInfo { -+ /* The presentation timestamp in microseconds for the buffer */ -+ int64_t presentationTimeUs = 0; -+ /* The amount of data (in bytes) in the buffer */ -+ int32_t size = 0; -+ /* The start-offset of the data in the buffer */ -+ int32_t offset = 0; -+}; -+ -+class AVCodecCallback { -+public: -+ virtual ~AVCodecCallback() = default; -+ /** -+ * Called when an error occurred. -+ * -+ * @param errorType Error type. For details, see {@link AVCodecErrorType}. -+ * @param errorCode Error code. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual void OnError(AVCodecErrorType errorType, int32_t errorCode) = 0; -+ -+ /** -+ * Called when the output format has changed. -+ * -+ * @param format The new output format. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual void OnOutputFormatChanged(const Format &format) = 0; -+ -+ /** -+ * Called when an input buffer becomes available. -+ * -+ * @param index The index of the available input buffer. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual void OnInputBufferAvailable(uint32_t index) = 0; -+ -+ /** -+ * Called when an output buffer becomes available. -+ * -+ * @param index The index of the available output buffer. -+ * @param info The info of the available output buffer. For details, see {@link AVCodecBufferInfo} -+ * @param flag The flag of the available output buffer. For details, see {@link AVCodecBufferFlag} -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0; -+}; -+ -+__attribute__((visibility("default"))) std::string AVCodecErrorTypeToString(AVCodecErrorType type); -+} // namespace Media -+} // namespace OHOS -+#endif // AVCODEC_COMMOM_H -diff --git a/ohos_ndk_aosp/includes/media/avcodec_info.h b/ohos_ndk_aosp/includes/media/avcodec_info.h -new file mode 100644 -index 0000000000..2e5bc3ec22 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/avcodec_info.h -@@ -0,0 +1,795 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef AVCODEC_INFO_H -+#define AVCODEC_INFO_H -+ -+#include -+#include -+#include -+#include "av_common.h" -+#include "nocopyable.h" -+ -+namespace OHOS { -+namespace Media { -+/** -+ * @brief AVCodec Type -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum AVCodecType : int32_t { -+ AVCODEC_TYPE_NONE = -1, -+ AVCODEC_TYPE_VIDEO_ENCODER = 0, -+ AVCODEC_TYPE_VIDEO_DECODER, -+ AVCODEC_TYPE_AUDIO_ENCODER, -+ AVCODEC_TYPE_AUDIO_DECODER, -+}; -+ -+/** -+ * @brief Range contain min and max value -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+struct Range { -+ int32_t minVal; -+ int32_t maxVal; -+ Range() : minVal(0), maxVal(0) {} -+ Range(const int32_t &min, const int32_t &max) -+ { -+ if (min <= max) { -+ this->minVal = min; -+ this->maxVal = max; -+ } else { -+ this->minVal = 0; -+ this->maxVal = 0; -+ } -+ } -+ -+ Range Create(const int32_t &min, const int32_t &max) -+ { -+ return Range(min, max); -+ } -+ -+ Range Intersect(const int32_t &min, const int32_t &max) -+ { -+ int32_t minCmp = this->minVal > min ? this->minVal : min; -+ int32_t maxCmp = this->maxVal < max ? this->maxVal : max; -+ return this->Create(minCmp, maxCmp); -+ } -+ -+ Range Intersect(const Range &range) -+ { -+ int32_t minCmp = this->minVal > range.minVal ? this->minVal : range.minVal; -+ int32_t maxCmp = this->maxVal < range.maxVal ? this->maxVal : range.maxVal; -+ return this->Create(minCmp, maxCmp); -+ } -+}; -+ -+/** -+ * @brief ImgSize contain width and height -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+struct ImgSize { -+ int32_t width; -+ int32_t height; -+ -+ ImgSize() : width(0), height(0) {} -+ -+ ImgSize(const int32_t &width, const int32_t &height) -+ { -+ this->width = width; -+ this->height = height; -+ } -+ -+ bool operator<(const ImgSize &p) const -+ { -+ return (width < p.width) || (width == p.width && height < p.height); -+ } -+}; -+ -+/** -+ * @brief Capability Data struct of Codec, parser from config file -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+struct CapabilityData { -+ std::string codecName = ""; -+ int32_t codecType = AVCODEC_TYPE_NONE; -+ std::string mimeType = ""; -+ bool isVendor = false; -+ Range bitrate; -+ Range channels; -+ Range complexity; -+ Range alignment; -+ Range width; -+ Range height; -+ Range frameRate; -+ Range encodeQuality; -+ Range quality; -+ Range blockPerFrame; -+ Range blockPerSecond; -+ ImgSize blockSize; -+ std::vector sampleRate; -+ std::vector format; -+ std::vector profiles; -+ std::vector bitrateMode; -+ std::vector levels; -+ std::map> profileLevelsMap; -+ std::map measuredFrameRate; -+}; -+ -+struct LevelParams { -+ int32_t maxBlockPerFrame = 0; -+ int32_t maxBlockPerSecond = 0; -+ int32_t maxFrameRate = 0; -+ int32_t maxWidth = 0; -+ int32_t maxHeight = 0; -+ LevelParams(const int32_t &blockPerFrame, const int32_t &blockPerSecond, -+ const int32_t &frameRate, const int32_t &width, const int32_t height) -+ { -+ this->maxBlockPerFrame = blockPerFrame; -+ this->maxBlockPerSecond = blockPerSecond; -+ this->maxFrameRate = frameRate; -+ this->maxWidth = width; -+ this->maxHeight = height; -+ } -+ LevelParams(const int32_t &blockPerFrame, const int32_t &blockPerSecond) -+ { -+ this->maxBlockPerFrame = blockPerFrame; -+ this->maxBlockPerSecond = blockPerSecond; -+ } -+}; -+ -+class __attribute__((visibility("default"))) AVCodecInfo { -+public: -+ explicit AVCodecInfo(CapabilityData &capabilityData); -+ ~AVCodecInfo(); -+ -+ /** -+ * @brief Get name of this codec, used to create the codec instance. -+ * @return Returns codec name. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ std::string GetName(); -+ -+ /** -+ * @brief Get type of this codec -+ * @return Returns codec type, see {@link AVCodecType} -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ AVCodecType GetType(); -+ -+ /** -+ * @brief Get mime type of this codec -+ * @return Returns codec mime type, see {@link CodecMimeType} -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ std::string GetMimeType(); -+ -+ /** -+ * @brief Check whether the codec is accelerated by hardware. -+ * @return Returns true if the codec is hardware accelerated; false otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ bool IsHardwareAccelerated(); -+ -+ /** -+ * @brief Check whether the codec is software implemented only. -+ * @return Returns true if the codec is software implemented only; false otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ bool IsSoftwareOnly(); -+ -+ /** -+ * @brief Check whether the codec is provided by vendor. -+ * @return Returns true if the codec is provided by vendor; false otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ bool IsVendor(); -+ -+private: -+ CapabilityData data_; -+}; -+ -+class __attribute__((visibility("default"))) VideoCaps { -+public: -+ explicit VideoCaps(CapabilityData &capabilityData); -+ ~VideoCaps(); -+ -+ /** -+ * @brief Get codec information, such as the codec name, codec type, -+ * whether hardware acceleration is supported, whether only software is supported, -+ * and whether the codec is provided by the vendor. -+ * @return Returns the pointer of {@link AVCodecInfo}. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ std::shared_ptr GetCodecInfo(); -+ -+ /** -+ * @brief Get supported bitrate range. -+ * @return Returns the range of supported bitrates. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ Range GetSupportedBitrate(); -+ -+ /** -+ * @brief Get supported video raw formats. -+ * @return Returns an array of supported formats. For Details, see {@link VideoPixelFormat}. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ std::vector GetSupportedFormats(); -+ -+ /** -+ * @brief Get supported alignment of video height, only used for video codecs. -+ * @return Returns the supported alignment of video height (in pixels). -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ int32_t GetSupportedHeightAlignment(); -+ -+ /** -+ * @brief Get supported alignment of video width, only used for video codecs. -+ * @return Returns the supported alignment of video width (in pixels). -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ int32_t GetSupportedWidthAlignment(); -+ -+ /** -+ * @brief Get supported width range of video. -+ * @return Returns the supported width range of video. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ Range GetSupportedWidth(); -+ -+ /** -+ * @brief Get supported height range of video. -+ * @return Returns the supported height range of video. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ Range GetSupportedHeight(); -+ -+ /** -+ * @brief Get supported profiles of this codec. -+ * @return Returns an array of supported profiles: -+ * returns {@link H263Profile} array if codec is h263, -+ * returns {@link AVCProfile} array if codec is h264, -+ * returns {@link HEVCProfile} array if codec is h265, -+ * returns {@link MPEG2Profile} array if codec is mpeg2, -+ * returns {@link MPEG4Profile} array if codec is mpeg4, -+ * returns {@link VP8Profile} array if codec is vp8. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ std::vector GetSupportedProfiles(); -+ -+ /** -+ * @brief Get supported codec level array. -+ * @return Returns an array of supported codec level number. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ std::vector GetSupportedLevels(); -+ -+ /** -+ * @brief Get supported video encode quality Range. -+ * @return Returns an array of supported video encode quality Range. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ Range GetSupportedEncodeQuality(); -+ -+ /** -+ * @brief Check whether the width and height is supported. -+ * @param width Indicates the specified video width (in pixels). -+ * @param height Indicates the specified video height (in pixels). -+ * @return Returns true if the codec supports {@link width} * {@link height} size video, false otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ bool IsSizeSupported(int32_t width, int32_t height); -+ -+ /** -+ * @brief Get supported frameRate. -+ * @return Returns the supported frameRate range of video. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ Range GetSupportedFrameRate(); -+ -+ /** -+ * @brief Get supported frameRate range for the specified width and height. -+ * @param width Indicates the specified video width (in pixels). -+ * @param height Indicates the specified video height (in pixels). -+ * @return Returns the supported frameRate range for the specified width and height. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ Range GetSupportedFrameRatesFor(int32_t width, int32_t height); -+ -+ /** -+ * @brief Check whether the size and frameRate is supported. -+ * @param width Indicates the specified video width (in pixels). -+ * @param height Indicates the specified video height (in pixels). -+ * @param frameRate Indicates the specified video frameRate. -+ * @return Returns true if the codec supports the specified size and frameRate; false otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ bool IsSizeAndRateSupported(int32_t width, int32_t height, double frameRate); -+ -+ /** -+ * @brief Get preferred frameRate range for the specified width and height, -+ * these framerates can be reach the performance. -+ * @param width Indicates the specified video width (in pixels). -+ * @param height Indicates the specified video height (in pixels). -+ * @return Returns preferred frameRate range for the specified width and height. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ Range GetPreferredFrameRate(int32_t width, int32_t height); -+ -+ /** -+ * @brief Get supported encode bitrate mode. -+ * @return Returns an array of supported encode bitrate mode. For details, see {@link VideoEncodeBitrateMode}. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ std::vector GetSupportedBitrateMode(); -+ -+ /** -+ * @brief Get supported encode qualit range. -+ * @return Returns supported encode qualit range. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ Range GetSupportedQuality(); -+ -+ /** -+ * @brief Get supported encode complexity range. -+ * @return Returns supported encode complexity range. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ Range GetSupportedComplexity(); -+ -+ /** -+ * @brief Check video encoder wether support request key frame dynamicly. -+ * @return Returns true if support, false not support. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ bool IsSupportDynamicIframe(); -+ -+private: -+ CapabilityData data_; -+ int32_t blockWidth_; -+ int32_t blockHeight_; -+ Range horizontalBlockRange_; -+ Range verticalBlockRange_; -+ Range blockPerFrameRange_; -+ Range blockPerSecondRange_; -+ Range widthRange_; -+ Range heightRange_; -+ Range frameRateRange_; -+ void InitParams(); -+ void UpdateParams(); -+ void LoadLevelParams(); -+ void LoadAVCLevelParams(); -+ void LoadMPEG2LevelParams(); -+ void LoadMPEG4LevelParams(); -+ ImgSize MatchClosestSize(const ImgSize &imgSize); -+ int32_t DivCeil(const int32_t ÷nd, const int32_t &divisor); -+ Range DivRange(const Range &range, const int32_t &divisor); -+ void UpdateBlockParams(const int32_t &blockWidth, const int32_t &blockHeight, -+ Range &blockPerFrameRange, Range &blockPerSecondRange); -+}; -+ -+class __attribute__((visibility("default"))) AudioCaps { -+public: -+ explicit AudioCaps(CapabilityData &capabilityData); -+ ~AudioCaps(); -+ -+ /** -+ * @brief Get codec information, such as the codec name, codec type, -+ * whether hardware acceleration is supported, whether only software is supported, -+ * and whether the codec is provided by the vendor. -+ * @return Returns the pointer of {@link AVCodecInfo} -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ std::shared_ptr GetCodecInfo(); -+ -+ /** -+ * @brief Get supported bitrate range. -+ * @return Returns the range of supported bitrates. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ Range GetSupportedBitrate(); -+ -+ /** -+ * @brief Get supported channel range. -+ * @return Returns the range of supported channel. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ Range GetSupportedChannel(); -+ -+ /** -+ * @brief Get supported audio raw format range. -+ * @return Returns the range of supported audio raw format. For details, see {@link AudioRawFormat}. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ std::vector GetSupportedFormats(); -+ -+ /** -+ * @brief Get supported audio samplerates. -+ * @return Returns an array of supported samplerates. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ std::vector GetSupportedSampleRates(); -+ -+ /** -+ * @brief Get supported codec profile number. -+ * @return Returns an array of supported codec profile number. For details, see {@link AACProfile}. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ std::vector GetSupportedProfiles(); -+ -+ /** -+ * @brief Get supported codec level array. -+ * @return Returns an array of supported codec level number. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ std::vector GetSupportedLevels(); -+ -+ /** -+ * @brief Get supported encode complexity range. -+ * @return Returns supported encode complexity range. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ Range GetSupportedComplexity(); -+ -+private: -+ CapabilityData data_; -+}; -+ -+/** -+ * @brief Enumerates the codec mime type. -+ */ -+class CodecMimeType { -+public: -+ static constexpr std::string_view VIDEO_H263 = "video/h263"; -+ static constexpr std::string_view VIDEO_AVC = "video/avc"; -+ static constexpr std::string_view VIDEO_MPEG2 = "video/mpeg2"; -+ static constexpr std::string_view VIDEO_HEVC = "video/hevc"; -+ static constexpr std::string_view VIDEO_MPEG4 = "video/mp4v-es"; -+ static constexpr std::string_view VIDEO_VP8 = "video/x-vnd.on2.vp8"; -+ static constexpr std::string_view VIDEO_VP9 = "video/x-vnd.on2.vp9"; -+ static constexpr std::string_view AUDIO_AMR_NB = "audio/3gpp"; -+ static constexpr std::string_view AUDIO_AMR_WB = "audio/amr-wb"; -+ static constexpr std::string_view AUDIO_MPEG = "audio/mpeg"; -+ static constexpr std::string_view AUDIO_AAC = "audio/mp4a-latm"; -+ static constexpr std::string_view AUDIO_VORBIS = "audio/vorbis"; -+ static constexpr std::string_view AUDIO_OPUS = "audio/opus"; -+ static constexpr std::string_view AUDIO_FLAC = "audio/flac"; -+ static constexpr std::string_view AUDIO_RAW = "audio/raw"; -+}; -+ -+/** -+ * @brief AVC Profile -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum AVCProfile { -+ AVC_PROFILE_BASELINE = 0, -+ AVC_PROFILE_CONSTRAINED_BASELINE = 1, -+ AVC_PROFILE_CONSTRAINED_HIGH = 2, -+ AVC_PROFILE_EXTENDED = 3, -+ AVC_PROFILE_HIGH = 4, -+ AVC_PROFILE_HIGH_10 = 5, -+ AVC_PROFILE_HIGH_422 = 6, -+ AVC_PROFILE_HIGH_444 = 7, -+ AVC_PROFILE_MAIN = 8, -+}; -+ -+/** -+ * @brief HEVC Profile -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum HEVCProfile { -+ HEVC_PROFILE_MAIN = 0, -+ HEVC_PROFILE_MAIN_10 = 1, -+ HEVC_PROFILE_MAIN_STILL = 3, -+}; -+ -+/** -+ * @brief MPEG2 Profile -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum MPEG2Profile { -+ MPEG2_PROFILE_422 = 0, -+ MPEG2_PROFILE_HIGH = 1, -+ MPEG2_PROFILE_MAIN = 2, -+ MPEG2_PROFILE_SNR = 3, -+ MPEG2_PROFILE_SIMPLE = 4, -+ MPEG2_PROFILE_SPATIAL = 5, -+}; -+ -+/** -+ * @brief MPEG4 Profile -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum MPEG4Profile { -+ MPEG4_PROFILE_ADVANCED_CODING = 0, -+ MPEG4_PROFILE_ADVANCED_CORE = 1, -+ MPEG4_PROFILE_ADVANCED_REAL_TIME = 2, -+ MPEG4_PROFILE_ADVANCED_SCALABLE = 3, -+ MPEG4_PROFILE_ADVANCED_SIMPLE = 4, -+ MPEG4_PROFILE_BASIC_ANIMATED = 5, -+ MPEG4_PROFILE_CORE = 6, -+ MPEG4_PROFILE_CORE_SCALABLE = 7, -+ MPEG4_PROFILE_HYBRID = 8, -+ MPEG4_PROFILE_MAIN = 9, -+ MPEG4_PROFILE_NBIT = 10, -+ MPEG4_PROFILE_SCALABLE_TEXTURE = 11, -+ MPEG4_PROFILE_SIMPLE = 12, -+ MPEG4_PROFILE_SIMPLE_FBA = 13, -+ MPEG4_PROFILE_SIMPLE_FACE = 14, -+ MPEG4_PROFILE_SIMPLE_SCALABLE = 15, -+}; -+ -+/** -+ * @brief H263 Profile -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum H263Profile { -+ H263_PROFILE_BACKWARD_COMPATIBLE = 0, -+ H263_PROFILE_BASELINE = 1, -+ H263_PROFILE_H320_CODING = 2, -+ H263_PROFILE_HIGH_COMPRESSION = 3, -+ H263_PROFILE_HIGH_LATENCY = 4, -+ H263_PROFILE_ISW_V2 = 5, -+ H263_PROFILE_ISW_V3 = 6, -+ H263_PROFILE_INTERLACE = 7, -+ H263_PROFILE_INTERNET = 8, -+}; -+ -+/** -+ * @brief -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum VP8Profile { -+ VP8_PROFILE_MAIN = 0, -+}; -+ -+/** -+ * @brief -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum AACProfile { -+ AAC_PROFILE_LC = 0, -+ AAC_PROFILE_ELD = 1, -+ AAC_PROFILE_ERLC = 2, -+ AAC_PROFILE_HE = 3, -+ AAC_PROFILE_HE_V2 = 4, -+ AAC_PROFILE_LD = 5, -+ AAC_PROFILE_MAIN = 6, -+}; -+ -+/** -+ * @brief -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum AVCLevel { -+ AVC_LEVEL_1 = 0, -+ AVC_LEVEL_1b = 1, -+ AVC_LEVEL_11 = 2, -+ AVC_LEVEL_12 = 3, -+ AVC_LEVEL_13 = 4, -+ AVC_LEVEL_2 = 5, -+ AVC_LEVEL_21 = 6, -+ AVC_LEVEL_22 = 7, -+ AVC_LEVEL_3 = 8, -+ AVC_LEVEL_31 = 9, -+ AVC_LEVEL_32 = 10, -+ AVC_LEVEL_4 = 11, -+ AVC_LEVEL_41 = 12, -+ AVC_LEVEL_42 = 13, -+ AVC_LEVEL_5 = 14, -+ AVC_LEVEL_51 = 15, -+}; -+ -+/** -+ * @brief -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum HEVCLevel { -+ HEVC_LEVEL_1 = 0, -+ HEVC_LEVEL_2 = 1, -+ HEVC_LEVEL_21 = 2, -+ HEVC_LEVEL_3 = 3, -+ HEVC_LEVEL_31 = 4, -+ HEVC_LEVEL_4 = 5, -+ HEVC_LEVEL_41 = 6, -+ HEVC_LEVEL_5 = 7, -+ HEVC_LEVEL_51 = 8, -+}; -+ -+/** -+ * @brief -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum MPEG2Level { -+ MPEG2_LEVEL_LL = 0, -+ MPEG2_LEVEL_ML = 1, -+ MPEG2_LEVEL_H14 = 2, -+ MPEG2_LEVEL_HL = 3, -+}; -+ -+/** -+ * @brief -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum MPEG4Level { -+ MPEG4_LEVEL_0 = 0, -+ MPEG4_LEVEL_0B = 1, -+ MPEG4_LEVEL_1 = 2, -+ MPEG4_LEVEL_2 = 3, -+ MPEG4_LEVEL_3 = 4, -+ MPEG4_LEVEL_4 = 5, -+ MPEG4_LEVEL_4A = 6, -+ MPEG4_LEVEL_5 = 7, -+}; -+ -+/** -+ * @brief -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum AudioRawFormat { -+ /** -+ * signed 8 bits. -+ */ -+ AUDIO_PCM_S8 = 1, -+ /** -+ * unsigned 8 bits. -+ */ -+ AUDIO_PCM_8 = 2, -+ /** -+ * signed 16 bits in big endian. -+ */ -+ AUDIO_PCM_S16_BE = 3, -+ /** -+ * signed 16 bits in little endian. -+ */ -+ AUDIO_PCM_S16_LE = 4, -+ /** -+ * unsigned 16 bits in big endian. -+ */ -+ AUDIO_PCM_16_BE = 5, -+ /** -+ * unsigned 16 bits in little endian. -+ */ -+ AUDIO_PCM_16_LE = 6, -+ /** -+ * signed 24 bits in big endian. -+ */ -+ AUDIO_PCM_S24_BE = 7, -+ /** -+ * signed 24 bits in little endian. -+ */ -+ AUDIO_PCM_S24_LE = 8, -+ /** -+ * unsigned 24 bits in big endian. -+ */ -+ AUDIO_PCM_24_BE = 9, -+ /** -+ * unsigned 24 bits in little endian. -+ */ -+ AUDIO_PCM_24_LE = 10, -+ /** -+ * signed 32 bits in big endian. -+ */ -+ AUDIO_PCM_S32_BE = 11, -+ /** -+ * signed 32 bits in little endian. -+ */ -+ AUDIO_PCM_S32_LE = 12, -+ /** -+ * unsigned 32 bits in big endian. -+ */ -+ AUDIO_PCM_32_BE = 13, -+ /** -+ * unsigned 32 bits in little endian. -+ */ -+ AUDIO_PCM_32_LE = 14, -+ /** -+ * float 32 bits in big endian. -+ */ -+ AUDIO_PCM_F32_BE = 15, -+ /** -+ * float 32 bits in little endian. -+ */ -+ AUDIO_PCM_F32_LE = 16, -+}; -+ -+/** -+ * @brief -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum VideoEncodeBitrateMode { -+ /** -+ * constant bit rate mode. -+ */ -+ CBR = 0, -+ /** -+ * variable bit rate mode. -+ */ -+ VBR = 1, -+ /** -+ * constant quality mode. -+ */ -+ CQ = 2, -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // AVCODEC_INFO_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/media/avcodec_list.h b/ohos_ndk_aosp/includes/media/avcodec_list.h -new file mode 100644 -index 0000000000..7122dd2dd6 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/avcodec_list.h -@@ -0,0 +1,108 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef AVCODEC_LIST_H -+#define AVCODEC_LIST_H -+ -+#include -+#include -+#include "avcodec_info.h" -+ -+namespace OHOS { -+namespace Media { -+class AVCodecList { -+public: -+ virtual ~AVCodecList() = default; -+ -+ /** -+ * @brief Find the supported video decoder name by format(usually contains video decoder MIME). -+ * @param format Indicates a media description which contains required video decoder capability. -+ * @return Returns video decoder name, if not find, return empty string. -+ * @since 1.0 -+ * @version 3.1 -+ */ -+ virtual std::string FindVideoDecoder(const Format &format) = 0; -+ -+ /** -+ * @brief Find the supported video encoder name by format(usually contains video encoder MIME). -+ * @param format Indicates a media description which contains required video encoder capability. -+ * @return Returns video encoder name, if not find, return empty string. -+ * @since 1.0 -+ * @version 3.1 -+ */ -+ virtual std::string FindVideoEncoder(const Format &format) = 0; -+ -+ /** -+ * @brief Find the supported audio decoder name by format(usually contains audio decoder MIME). -+ * @param format Indicates a media description which contains required audio decoder capability. -+ * @return Returns audio decoder name, if not find, return empty string. -+ * @since 1.0 -+ * @version 3.1 -+ */ -+ virtual std::string FindAudioDecoder(const Format &format) = 0; -+ -+ /** -+ * @brief Find the supported audio encoder name by format(usually contains audio encoder MIME). -+ * @param format Indicates a media description which contains required audio encoder capability. -+ * @return Returns audio encoder name, if not find, return empty string. -+ * @since 1.0 -+ * @version 3.1 -+ */ -+ virtual std::string FindAudioEncoder(const Format &format) = 0; -+ -+ /** -+ * @brief Get the supported video decoder capabilities. -+ * @return Returns an array of supported video decoder capability. -+ * @since 1.0 -+ * @version 3.1 -+ */ -+ virtual std::vector> GetVideoDecoderCaps() = 0; -+ -+ /** -+ * @brief Get the supported video encoder capabilities. -+ * @return Returns an array of supported video encoder capability. -+ * @since 1.0 -+ * @version 3.1 -+ */ -+ virtual std::vector> GetVideoEncoderCaps() = 0; -+ -+ /** -+ * @brief Get the supported audio decoder capabilities. -+ * @return Returns an array of supported audio decoder capability. -+ * @since 1.0 -+ * @version 3.1 -+ */ -+ virtual std::vector> GetAudioDecoderCaps() = 0; -+ -+ /** -+ * @brief Get the supported audio encoder capabilities. -+ * @return Returns an array of supported audio encoder capability. -+ * @since 1.0 -+ * @version 3.1 -+ */ -+ virtual std::vector> GetAudioEncoderCaps() = 0; -+}; -+ -+class __attribute__((visibility("default"))) AVCodecListFactory { -+public: -+ -+ static std::shared_ptr CreateAVCodecList(); -+private: -+ AVCodecListFactory() = default; -+ ~AVCodecListFactory() = default; -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // AVCODEC_LIST_H -diff --git a/ohos_ndk_aosp/includes/media/avcodec_video_decoder.h b/ohos_ndk_aosp/includes/media/avcodec_video_decoder.h -new file mode 100644 -index 0000000000..602e6869f3 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/avcodec_video_decoder.h -@@ -0,0 +1,234 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef AVCODEC_VIDEO_DECODER_H -+#define AVCODEC_VIDEO_DECODER_H -+ -+#include "avcodec_common.h" -+#include "avcodec_info.h" -+#include "avsharedmemory.h" -+#include "format.h" -+#include "surface.h" -+ -+namespace OHOS { -+namespace Media { -+class VideoDecoder { -+public: -+ virtual ~VideoDecoder() = default; -+ -+ /** -+ * @brief Configure the decoder. -+ * -+ * @param format The format of the input data and the desired format of the output data. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Configure(const Format &format) = 0; -+ -+ /** -+ * @brief Prepare for decoding. -+ * -+ * This function must be called after {@link Configure} and before {@link Start} -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Prepare() = 0; -+ -+ /** -+ * @brief Start decoding. -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Start() = 0; -+ -+ /** -+ * @brief Stop decoding. -+ * -+ * This function must be called during running -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Stop() = 0; -+ -+ /** -+ * @brief Flush both input and output buffers of the decoder. -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Flush() = 0; -+ -+ /** -+ * @brief Restores the decoder to the initial state. -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Reset() = 0; -+ -+ /** -+ * @brief Releases decoder resources. All methods are unavailable after calling this. -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Release() = 0; -+ -+ /** -+ * @brief Sets the surface on which to render the output of this decoder. -+ * -+ * This function must be called before {@link Prepare} -+ * -+ * @param index The index of the output buffer. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t SetOutputSurface(sptr surface) = 0; -+ -+ /** -+ * @brief Returns a {@link AVSharedMemory} object for a input buffer index that contains the data. -+ * -+ * This function must be called during running -+ * -+ * @param index The index of the input buffer. -+ * @return Returns {@link AVSharedMemory} if success; returns nullptr otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual std::shared_ptr GetInputBuffer(uint32_t index) = 0; -+ -+ /** -+ * @brief Submits input buffer to decoder. -+ * -+ * This function must be called during running -+ * -+ * @param index The index of the input buffer. -+ * @param info The info of the input buffer. For details, see {@link AVCodecBufferInfo} -+ * @param flag The flag of the input buffer. For details, see {@link AVCodecBufferFlag} -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0; -+ -+ /** -+ * @brief Returns a {@link AVSharedMemory} object for a output buffer index that contains the data. -+ * -+ * This function must be called during running -+ * -+ * @param index The index of the output buffer. -+ * @return Returns {@link AVSharedMemory} if success; returns nullptr otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual std::shared_ptr GetOutputBuffer(uint32_t index) = 0; -+ -+ /** -+ * @brief Gets the format of the output data. -+ * -+ * This function must be called after {@link Configure} -+ * -+ * @param format -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t GetOutputFormat(Format &format) = 0; -+ -+ /** -+ * @brief Gets the video decoder capability. -+ * -+ * @return Returns {@link VideoCaps}. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual std::shared_ptr GetVideoDecoderCaps() = 0; -+ -+ /** -+ * @brief Returns the output buffer to the decoder. -+ * -+ * This function must be called during running -+ * -+ * @param index The index of the output buffer. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t ReleaseOutputBuffer(uint32_t index, bool render) = 0; -+ -+ /** -+ * @brief Sets the parameters to the decoder. -+ * -+ * This function must be called after {@link Configure} -+ * -+ * @param format The parameters. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t SetParameter(const Format &format) = 0; -+ -+ /** -+ * @brief Registers a decoder listener. -+ * -+ * This function must be called before {@link Configure} -+ * -+ * @param callback Indicates the decoder listener to register. For details, see {@link AVCodecCallback}. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t SetCallback(const std::shared_ptr &callback) = 0; -+}; -+ -+class __attribute__((visibility("default"))) VideoDecoderFactory { -+public: -+ /** -+ * @brief Instantiate the preferred decoder of the given mime type. -+ * -+ * @param mime The mime type. -+ * @return Returns the preferred decoder. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ static std::shared_ptr CreateByMime(const std::string &mime); -+ -+ /** -+ * @brief Instantiates the designated decoder. -+ * -+ * @param name The decoder's name. -+ * @return Returns the designated decoder. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ static std::shared_ptr CreateByName(const std::string &name); -+private: -+ VideoDecoderFactory() = default; -+ ~VideoDecoderFactory() = default; -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // AVCODEC_VIDEO_DECODER_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/media/avcodec_video_encoder.h b/ohos_ndk_aosp/includes/media/avcodec_video_encoder.h -new file mode 100644 -index 0000000000..2158093314 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/avcodec_video_encoder.h -@@ -0,0 +1,233 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef AVCODEC_VIDEO_ENCODER_H -+#define AVCODEC_VIDEO_ENCODER_H -+ -+#include "avcodec_common.h" -+#include "avcodec_info.h" -+#include "avsharedmemory.h" -+#include "format.h" -+#include "surface.h" -+ -+namespace OHOS { -+namespace Media { -+class VideoEncoder { -+public: -+ virtual ~VideoEncoder() = default; -+ -+ /** -+ * @brief Configure the encoder. -+ * -+ * @param format The format of the input data and the desired format of the output data. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Configure(const Format &format) = 0; -+ -+ /** -+ * @brief Prepare for decoding. -+ * -+ * This function must be called after {@link Configure} and before {@link Start} -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Prepare() = 0; -+ -+ /** -+ * @brief Start decoding. -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Start() = 0; -+ -+ /** -+ * @brief Stop decoding. -+ * -+ * This function must be called during running -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Stop() = 0; -+ -+ /** -+ * @brief Flush both input and output buffers of the encoder. -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Flush() = 0; -+ -+ /** -+ * @brief Restores the encoder to the initial state. -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Reset() = 0; -+ -+ /** -+ * @brief Releases encoder resources. All methods are unavailable after calling this. -+ * -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t Release() = 0; -+ -+ /** -+ * @brief Obtains the surface from encoder. -+ * -+ * This function can only be called after {@link Configure} and before {@link Prepare} -+ * -+ * @return Returns the pointer to the surface. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual sptr CreateInputSurface() = 0; -+ -+ /** -+ * @brief Returns a {@link AVSharedMemory} object for a input buffer index that contains the data. -+ * -+ * This function must be called during running -+ * -+ * @param index The index of the input buffer. -+ * @return Returns {@link AVSharedMemory} if success; returns nullptr otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual std::shared_ptr GetInputBuffer(uint32_t index) = 0; -+ -+ /** -+ * @brief Submits input buffer to encoder. -+ * -+ * This function must be called during running -+ * -+ * @param index The index of the input buffer. -+ * @param info The info of the input buffer. For details, see {@link AVCodecBufferInfo} -+ * @param flag The flag of the input buffer. For details, see {@link AVCodecBufferFlag} -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0; -+ -+ /** -+ * @brief Returns a {@link AVSharedMemory} object for a output buffer index that contains the data. -+ * -+ * This function must be called during running -+ * -+ * @param index The index of the output buffer. -+ * @return Returns {@link AVSharedMemory} if success; returns nullptr otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual std::shared_ptr GetOutputBuffer(uint32_t index) = 0; -+ -+ /** -+ * @brief Gets the format of the output data. -+ * -+ * This function must be called after {@link Configure} -+ * -+ * @param format -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t GetOutputFormat(Format &format) = 0; -+ -+ /** -+ * @brief Gets the video encoder capability. -+ * -+ * @return Returns {@link VideoCaps}. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual std::shared_ptr GetVideoEncoderCaps() = 0; -+ -+ /** -+ * @brief Returns the output buffer to the encoder. -+ * -+ * This function must be called during running -+ * -+ * @param index The index of the output buffer. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t ReleaseOutputBuffer(uint32_t index) = 0; -+ -+ /** -+ * @brief Sets the parameters to the encoder. -+ * -+ * This function must be called after {@link Configure} -+ * -+ * @param format The parameters. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t SetParameter(const Format &format) = 0; -+ -+ /** -+ * @brief Registers a encoder listener. -+ * -+ * This function must be called before {@link Configure} -+ * -+ * @param callback Indicates the encoder listener to register. For details, see {@link AVCodecCallback}. -+ * @return Returns {@link MSERR_OK} if success; returns an error code otherwise. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ virtual int32_t SetCallback(const std::shared_ptr &callback) = 0; -+}; -+ -+class __attribute__((visibility("default"))) VideoEncoderFactory { -+public: -+ /** -+ * @brief Instantiate the preferred encoder of the given mime type. -+ * -+ * @param mime The mime type. -+ * @return Returns the preferred encoder. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ static std::shared_ptr CreateByMime(const std::string &mime); -+ -+ /** -+ * @brief Instantiates the designated encoder. -+ * -+ * @param name The encoder's name. -+ * @return Returns the designated encoder. -+ * @since 3.1 -+ * @version 3.1 -+ */ -+ static std::shared_ptr CreateByName(const std::string &name); -+private: -+ VideoEncoderFactory() = default; -+ ~VideoEncoderFactory() = default; -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // AVCODEC_VIDEO_ENCODER_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/media/avcontainer_types.h b/ohos_ndk_aosp/includes/media/avcontainer_types.h -new file mode 100644 -index 0000000000..3ed5c2e1c5 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/avcontainer_types.h -@@ -0,0 +1,58 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef AVCONTAINER_TYPES_H -+#define AVCONTAINER_TYPES_H -+ -+#include -+#include "av_common.h" -+#include "avcodec_common.h" -+ -+namespace OHOS { -+namespace Media { -+/** -+ * @brief Enumerates the container format types. -+ */ -+class ContainerFormatType { -+public: -+ static constexpr std::string_view CFT_MPEG_4A = "m4a"; -+ static constexpr std::string_view CFT_MPEG_4 = "mp4"; -+}; -+ -+/** -+ * @brief Description information of a sample associated a media track. -+ */ -+struct TrackSampleInfo { -+ /** -+ * @brief the id of track that this sample belongs to. -+ */ -+ uint32_t trackIdx; -+ /** -+ * @brief the presentation timestamp in microseconds. -+ */ -+ int64_t timeUs; -+ /** -+ * @brief the size in bytes. -+ */ -+ uint32_t size; -+ /** -+ * @brief the flags associated with the sample, this -+ * maybe be a combination of multiple {@link AVCodecBufferFlag}. -+ */ -+ AVCodecBufferFlag flags; -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // AVCONTAINER_TYPES_H -diff --git a/ohos_ndk_aosp/includes/media/avmemory.h b/ohos_ndk_aosp/includes/media/avmemory.h -new file mode 100644 -index 0000000000..a4142a25b9 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/avmemory.h -@@ -0,0 +1,84 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef AVMEMORY_H -+#define AVMEMORY_H -+ -+#include -+#include -+#include "nocopyable.h" -+ -+namespace OHOS { -+namespace Media { -+/** -+ * @brief Provides a wrap for raw byte buffer. -+ */ -+class __attribute__((visibility("default"))) AVMemory { -+public: -+ /** -+ * @brief Construct a new AVMemory object with specified capacity, the raw buffer will be allocated. -+ */ -+ explicit AVMemory(size_t capacity); -+ -+ /** -+ * @brief Construct a new AVMemory object with specified raw buffer address and capacity. -+ */ -+ AVMemory(uint8_t *base, size_t capacity); -+ -+ ~AVMemory(); -+ -+ uint8_t *Base() const -+ { -+ return base_; -+ } -+ -+ uint8_t *Data() const -+ { -+ return base_ + offset_; -+ } -+ -+ size_t Capacity() const -+ { -+ return capacity_; -+ } -+ -+ size_t Size() const -+ { -+ return size_; -+ } -+ -+ size_t Offset() const -+ { -+ return offset_; -+ } -+ -+ void SetRange(size_t offset, size_t size) -+ { -+ offset_ = offset; -+ size_ = size; -+ } -+ -+ DISALLOW_COPY_AND_MOVE(AVMemory); -+ -+private: -+ uint8_t *base_ = nullptr; -+ size_t offset_ = 0; -+ size_t size_ = 0; -+ size_t capacity_ = 0; -+ bool ownership = false; -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // AVMEMORY_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/media/avmetadatahelper.h b/ohos_ndk_aosp/includes/media/avmetadatahelper.h -new file mode 100644 -index 0000000000..e300085a24 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/avmetadatahelper.h -@@ -0,0 +1,243 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef AVMETADATAHELPER_H -+#define AVMETADATAHELPER_H -+ -+#include -+#include -+#include -+#include "pixel_map.h" -+#include "nocopyable.h" -+#include "avsharedmemory.h" -+ -+namespace OHOS { -+namespace Media { -+/** -+ * @brief Enumerates avmetadata usage. -+ */ -+enum AVMetadataUsage : int32_t { -+ /** -+ * Indicates that the avmetadahelper's instance will only be used for resolving the -+ * metadata from the given media resource. -+ */ -+ AV_META_USAGE_META_ONLY, -+ /** -+ * Indicates that the avmetadahelper's instance will be used for fetching the video frame -+ * and resolving metadata from the given media resource. -+ */ -+ AV_META_USAGE_PIXEL_MAP, -+}; -+ -+/** -+ * @brief Enumerates avmetadata's metadata key. -+ */ -+enum AVMetadataCode : int32_t { -+ /** -+ * The metadata key to retrieve the information about the album title -+ * of the media source. -+ */ -+ AV_KEY_ALBUM = 0, -+ /** -+ * The metadata key to retrieve the information about the performers or -+ * artist associated with the media source. -+ */ -+ AV_KEY_ALBUM_ARTIST = 1, -+ /** -+ * The metadata key to retrieve the information about the artist of -+ * the media source. -+ */ -+ AV_KEY_ARTIST = 2, -+ /** -+ * The metadata key to retrieve the information about the author of -+ * the media source. -+ */ -+ AV_KEY_AUTHOR = 3, -+ /** -+ * The metadata key to retrieve the information about the composer of -+ * the media source. -+ */ -+ AV_KEY_COMPOSER = 12, -+ /** -+ * The metadata key to retrieve the playback duration of the media source. -+ */ -+ AV_KEY_DURATION = 15, -+ /** -+ * The metadata key to retrieve the content type or genre of the data -+ * source. -+ */ -+ AV_KEY_GENRE = 18, -+ /** -+ * If this key exists the media contains audio content. -+ */ -+ AV_KEY_HAS_AUDIO = 19, -+ /** -+ * If this key exists the media contains video content. -+ */ -+ AV_KEY_HAS_VIDEO = 21, -+ /** -+ * The metadata key to retrieve the mime type of the media source. Some -+ * example mime types include: "video/mp4", "audio/mp4", "audio/amr-wb", -+ * etc. -+ */ -+ AV_KEY_MIME_TYPE = 29, -+ /** -+ * The metadata key to retrieve the number of tracks, such as audio, video, -+ * text, in the media source, such as a mp4 or 3gpp file. -+ */ -+ AV_KEY_NUM_TRACKS = 30, -+ /** -+ * This key retrieves the sample rate, if available. -+ */ -+ AV_KEY_SAMPLE_RATE = 31, -+ /** -+ * The metadata key to retrieve the media source title. -+ */ -+ AV_KEY_TITLE = 33, -+ /** -+ * If the media contains video, this key retrieves its height. -+ */ -+ AV_KEY_VIDEO_HEIGHT = 35, -+ /** -+ * If the media contains video, this key retrieves its width. -+ */ -+ AV_KEY_VIDEO_WIDTH = 37, -+}; -+ -+/** -+ * @brief Enumerates avmetadata's query option. -+ */ -+enum AVMetadataQueryOption : int32_t { -+ /** -+ * This option is used to fetch a key frame from the given media -+ * resource that is located right after or at the given time. -+ */ -+ AV_META_QUERY_NEXT_SYNC, -+ /** -+ * This option is used to fetch a key frame from the given media -+ * resource that is located right before or at the given time. -+ */ -+ AV_META_QUERY_PREVIOUS_SYNC, -+ /** -+ * This option is used to fetch a key frame from the given media -+ * resource that is located closest to or at the given time. -+ */ -+ AV_META_QUERY_CLOSEST_SYNC, -+ /** -+ * This option is used to fetch a frame (maybe not keyframe) from -+ * the given media resource that is located closest to or at the given time. -+ */ -+ AV_META_QUERY_CLOSEST, -+}; -+ -+/** -+ * @brief Provides the definition of the returned pixelmap's configuration -+ */ -+struct PixelMapParams { -+ /** -+ * Expected pixelmap's width, -1 means to keep consistent with the -+ * original dimensions of the given video resource. -+ */ -+ int32_t dstWidth = -1; -+ /** -+ * Expected pixelmap's width, -1 means to keep consistent with the -+ * original dimensions of the given video resource. -+ */ -+ int32_t dstHeight = -1; -+ /** -+ * Expected pixelmap's color format, see {@link PixelFormat}. Currently, -+ * RGB_565, RGB_888, RGBA_8888 are supported. -+ */ -+ PixelFormat colorFormat = PixelFormat::RGB_565; -+}; -+ -+/** -+ * @brief Provides the interfaces to resolve metadata or fetch frame -+ * from a given media resource. -+ */ -+class AVMetadataHelper { -+public: -+ virtual ~AVMetadataHelper() = default; -+ -+ /** -+ * Set the media source uri to use. Calling this method before the reset -+ * of the methods in this class. This method maybe time consuming. -+ * @param uri the URI of input media source. -+ * @param usage indicates which scene the avmedatahelper's instance will -+ * be used to, see {@link AVMetadataUsage}. If the usage need to be changed, -+ * this method must be called again. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns -+ * an error code otherwise. -+ */ -+ virtual int32_t SetSource(const std::string &uri, int32_t usage = AVMetadataUsage::AV_META_USAGE_PIXEL_MAP) = 0; -+ -+ /** -+ * Retrieve the meta data associated with the specified key. This method must be -+ * called after the SetSource. -+ * @param key One of the constants listed above at the definition of {@link AVMetadataCode}. -+ * @return Returns the meta data value associate with the given key code on -+ * success; empty string on failure. -+ */ -+ virtual std::string ResolveMetadata(int32_t key) = 0; -+ -+ /** -+ * Retrieve all meta data within the listed above at the definition of {@link AVMetadataCode}. -+ * This method must be called after the SetSource. -+ * @return Returns the meta data values on success; empty hash map on failure. -+ */ -+ virtual std::unordered_map ResolveMetadata() = 0; -+ -+ /** -+ * Fetch the album art picture associated with the data source. If there are -+ * more than one pictures, the cover image will be returned preferably. -+ * @return Returns the a chunk of shared memory containing a picture, which can be -+ * null, if such a picture can not be fetched. -+ */ -+ virtual std::shared_ptr FetchArtPicture() = 0; -+ -+ /** -+ * Fetch a representative video frame near a given timestamp by considering the given -+ * option if possible, and return a pixelmap with given parameters. This method must be -+ * called after the SetSource. -+ * @param timeUs The time position in microseconds where the frame will be fetched. -+ * When fetching the frame at the given time position, there is no guarantee that -+ * the video source has a frame located at the position. When this happens, a frame -+ * nearby will be returned. If timeUs is negative, time position and option will ignored, -+ * and any frame that the implementation considers as representative may be returned. -+ * @param option the hint about how to fetch a frame, see {@link AVMetadataQueryOption} -+ * @param param the desired configuration of returned pixelmap, see {@link PixelMapParams}. -+ * @return Returns a pixelmap containing a scaled video frame, which can be null, if such a -+ * frame cannot be fetched. -+ */ -+ virtual std::shared_ptr FetchFrameAtTime(int64_t timeUs, int32_t option, const PixelMapParams ¶m) = 0; -+ -+ /** -+ * Release the internel resource. After this method called, the avmetadatahelper instance -+ * can not be used again. -+ */ -+ virtual void Release() = 0; -+}; -+ -+class __attribute__((visibility("default"))) AVMetadataHelperFactory { -+public: -+ static std::shared_ptr CreateAVMetadataHelper(); -+ -+private: -+ AVMetadataHelperFactory() = default; -+ ~AVMetadataHelperFactory() = default; -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // AVMETADATAHELPER_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/media/avmuxer.h b/ohos_ndk_aosp/includes/media/avmuxer.h -new file mode 100644 -index 0000000000..c916340651 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/avmuxer.h -@@ -0,0 +1,52 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef AVMUXER_H -+#define AVMUXER_H -+ -+#include -+#include -+#include -+#include "avmemory.h" -+#include "media_types.h" -+#include "media_description.h" -+ -+namespace OHOS { -+namespace Media { -+class AVMuxer { -+public: -+ virtual ~AVMuxer() = default; -+ -+ virtual std::vector GetAVMuxerFormatList() = 0; -+ virtual int32_t SetOutput(const std::string &path, const std::string &format) = 0; -+ virtual int32_t SetLocation(float latitude, float longtitude) = 0; -+ virtual int32_t SetOrientationHint(int degrees) = 0; -+ virtual int32_t AddTrack(const MediaDescription &trackDesc, int32_t &trackIdx) = 0; -+ virtual int32_t Start() = 0; -+ virtual int32_t WriteTrackSample(std::shared_ptr sampleData, const TrackSampleInfo &info) = 0; -+ virtual int32_t Stop() = 0; -+ virtual void Release() = 0; -+}; -+ -+class __attribute__((visibility("default"))) AVMuxerFactory { -+public: -+ static std::shared_ptr CreateAVMuxer(); -+private: -+ AVMuxerFactory() = default; -+ ~AVMuxerFactory() = default; -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // AVMUXER_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/media/avsharedmemory.h b/ohos_ndk_aosp/includes/media/avsharedmemory.h -new file mode 100644 -index 0000000000..adc462e0cf ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/avsharedmemory.h -@@ -0,0 +1,76 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef AVSHAREDMEMORY_H -+#define AVSHAREDMEMORY_H -+ -+#include -+#include -+#include -+ -+namespace OHOS { -+namespace Media { -+/** -+ * @brief Provides a unified interface to implement convenient memory sharing -+ * mechanism. For those platforms that do not support multi-process, it may -+ * simply encapsulate ordinary memory blocks, not really multi-process shareable memory. -+ */ -+class __attribute__((visibility("default"))) AVSharedMemory { -+public: -+ virtual ~AVSharedMemory() = default; -+ -+ /** -+ * @brief Enumerates the flag bits used to create a new shared memory. -+ */ -+ enum Flags : uint32_t { -+ /** -+ * This flag bit indicates that the remote process is allowed to read and write -+ * the shared memory. If no flags are specified, this is the default memory -+ * sharing policy. If the FLAGS_READ_ONLY bit is set, this flag bit is ignored. -+ */ -+ FLAGS_READ_WRITE = 0x1, -+ /** -+ * For platforms that support multiple processes, this flag bit indicates that the -+ * remote process can only read data in the shared memory. If this flag is not set, -+ * the remote process has both read and write permissions by default. Adding this -+ * flag does not affect the process that creates the memory, which always has the -+ * read and write permission on the shared memory. For platforms that do not support -+ * multi-processes, the memory read and write permission control capability may -+ * not be available. In this case, this flag is invalid. -+ */ -+ FLAGS_READ_ONLY = 0x2, -+ }; -+ -+ /** -+ * @brief Get the memory's virtual address -+ * @return the memory's virtual address if the memory is valid, otherwise nullptr. -+ */ -+ virtual uint8_t *GetBase() const = 0; -+ -+ /** -+ * @brief Get the memory's size -+ * @return the memory's size if the memory is valid, otherwise -1. -+ */ -+ virtual int32_t GetSize() const = 0; -+ -+ /** -+ * @brief Get the memory's flags set by the creator, refer to {@Flags} -+ * @return the memory's flags if the memory is valid, otherwise 0. -+ */ -+ virtual uint32_t GetFlags() const = 0; -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // AVSHAREDMEMORY_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/media/avspliter.h b/ohos_ndk_aosp/includes/media/avspliter.h -new file mode 100644 -index 0000000000..8d25be4cc9 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/avspliter.h -@@ -0,0 +1,176 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef AVSPLITER_H -+#define AVSPLITER_H -+ -+#include -+#include "avmemory.h" -+#include "avcontainer_types.h" -+#include "media_data_source.h" -+#include "media_description.h" -+ -+namespace OHOS { -+namespace Media { -+/** -+ * @brief Enumerates the track select mode. -+ */ -+enum TrackSelectMode : uint8_t { -+ /** -+ * @brief this mode indicates that all track will be processed synchronized. When -+ * selecting a track, this track's starting position to read will be forced to keep -+ * sync with the other already selected tracks. If it is the first track selected, -+ * this track will be read from zero timestamp. -+ */ -+ TRACK_TIME_SYNC, -+ /** -+ * @brief this mode indicates that all track will be processed independent. When -+ * selecting a track, this track's starting position to read will be restored to -+ * last unselected position. If it it selected for the first time, this track will -+ * be read from zero timestamp. -+ */ -+ TRACK_TIME_INDEPENDENT, -+}; -+ -+/** -+ * @brief Provides the track spliter for media files to get sample data of each track. -+ */ -+class AVSpliter { -+public: -+ virtual ~AVSpliter() = default; -+ -+ /** -+ * @brief Set the uri source for avspliter. Calling this method before the reset -+ * of the methods in this class. This method maybe time consuming. -+ * -+ * @param uri the URI of input media source. -+ * @param mode the mode indicates how to set the track's sample read position -+ * when select a new track, see {@link TrackSelectMode}. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns -+ * an error code otherwise. -+ */ -+ virtual int32_t SetSource(const std::string &uri, TrackSelectMode mode) = 0; -+ -+ /** -+ * @brief Set the data source for avspliter. Calling this method before the reset -+ * of the methods in this class. This method maybe time consuming. -+ * -+ * @param dataSource the media data source to be split -+ * @param mode the mode indicates how to set the track's sample read position -+ * when select a new track, see {@link TrackSelectMode}. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns -+ * an error code otherwise. -+ */ -+ virtual int32_t SetSource(std::shared_ptr dataSource, TrackSelectMode mode) = 0; -+ -+ /** -+ * @brief Get the container description. -+ * -+ * @param desc the output result will be filled into this parameter, and -+ * all container informations will be represented by key-value pairs. For -+ * keys, see {@link media_description.h} -+ * @return Returns {@link MSERR_OK} if resolving the container informations -+ * is successful; returns an error code otherwise. -+ */ -+ virtual int32_t GetContainerDescription(MediaDescription &desc) = 0; -+ -+ /** -+ * @brief Get the track description for specified track index. -+ * -+ * @param trackIdx the specified track index, for all track count in the -+ * container, refer to the {@link GetContainerDescription}'s result. -+ * @param desc the output result will be filled into this parameter, and -+ * the specified track's all informations will be represented by key-value pairs. -+ * For keys, see {@link media_description.h} -+ * @return Returns {@link MSERR_OK} if resolving the track informations -+ * is successful; returns an error code otherwise. -+ */ -+ virtual int32_t GetTrackDescription(uint32_t trackIdx, MediaDescription &desc) = 0; -+ -+ /** -+ * @brief Selecting a specified track to read track sample. Selecting the same track -+ * multiple times has no effect. This function has different behavior when set the -+ * input source with different mode, see {@link TrackSelectMode}. -+ * -+ * @param trackIdx the specified track index. -+ * @return Returns {@link MSERR_OK} if the selecting is success, returns an error code -+ * otherwise. -+ */ -+ virtual int32_t SelectTrack(uint32_t trackIdx) = 0; -+ -+ /** -+ * @brief Unselecting a specified track. After this function called, the {@link ReadTrackSample} -+ * will not output sample of the specified track. Unselecting the same track multiple -+ * times has no effect. -+ * -+ * @param trackIdx the specified track index. -+ * @return Returns {@link MSERR_OK} if the unselecting is success, returns an error code -+ * otherwise. -+ */ -+ virtual int32_t UnSelectTrack(uint32_t trackIdx) = 0; -+ -+ /** -+ * @brief Read a encoded sample from all selected track sample, and store it in the -+ * buffer starting at the given offset. All sample will be read in sequence based on -+ * timestamps. If no track selected, the default track for supported media type will -+ * be read. If the Codec Specific Data exists, it will be output before any frame data. -+ * Such data would be marked using the flag {@link AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_CODEC_DATA}. -+ * -+ * @param buffer the destination output buffer, see{@link AVMemory}. -+ * @param info the sample's description information, see {@link TrackSampleInfo}. -+ * @return Returns {@link MSERR_OK} if the reading is success, returns an error code -+ * otherwise. -+ */ -+ virtual int32_t ReadTrackSample(std::shared_ptr buffer, TrackSampleInfo &info) = 0; -+ -+ /** -+ * @brief Seek all track to specified time position according the given seek mode. -+ * -+ * @param timeUs the time position in microseconds where the sample will be read. -+ * @param mode the hint about how to seek to the specified time position. -+ * @return Returns {@link MSERR_OK} if the seek is success, returns an error code -+ * otherwise. -+ */ -+ virtual int32_t Seek(int64_t timeUs, AVSeekMode mode) = 0; -+ -+ /** -+ * @brief Get the an current estimate of how much data is cached in memory, and -+ * the information about whether the cached data has reached the end of stream. -+ * This API is only valid for network streams. -+ * -+ * @param durationUs cached duration in microseconds. -+ * @param endOfStream true if the cached data has reached the end of stream. -+ * @return Returns {@link MSERR_OK} if the query is success, returns an error code -+ * otherwise. -+ */ -+ virtual int32_t GetCacheState(int64_t &durationUs, bool &endOfStream) = 0; -+ -+ /** -+ * @brief Release the internel resource. After this method called, the avspliter -+ * instance can not be used again. -+ */ -+ virtual void Release() = 0; -+}; -+ -+class __attribute__((visibility("default"))) AVSpliterFactory { -+public: -+ static std::shared_ptr CreateAVSpliter(); -+private: -+ AVSpliterFactory() = default; -+ ~AVSpliterFactory() = default; -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // AVSPLITER_H -diff --git a/ohos_ndk_aosp/includes/media/format.h b/ohos_ndk_aosp/includes/media/format.h -new file mode 100644 -index 0000000000..bee434bbd0 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/format.h -@@ -0,0 +1,246 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef FORMAT_H -+#define FORMAT_H -+ -+#include -+#include -+#include -+ -+namespace OHOS { -+namespace Media { -+enum FormatDataType : uint32_t { -+ /* None */ -+ FORMAT_TYPE_NONE, -+ /* Int32 */ -+ FORMAT_TYPE_INT32, -+ /* Int64 */ -+ FORMAT_TYPE_INT64, -+ /* Float */ -+ FORMAT_TYPE_FLOAT, -+ /* Double */ -+ FORMAT_TYPE_DOUBLE, -+ /* String */ -+ FORMAT_TYPE_STRING, -+ /* Addr */ -+ FORMAT_TYPE_ADDR, -+}; -+ -+struct FormatData { -+ FormatDataType type = FORMAT_TYPE_NONE; -+ union Val { -+ int32_t int32Val; -+ int64_t int64Val; -+ float floatVal; -+ double doubleVal; -+ } val = {0}; -+ std::string stringVal = ""; -+ uint8_t *addr = nullptr; -+ size_t size = 0; -+}; -+ -+class __attribute__((visibility("default"))) Format { -+public: -+ Format() = default; -+ ~Format(); -+ -+ Format(const Format &rhs); -+ Format(Format &&rhs) noexcept; -+ Format &operator=(const Format &rhs); -+ Format &operator=(Format &&rhs) noexcept; -+ -+ /** -+ * @brief Sets metadata of the integer type. -+ * -+ * @param key Indicates the metadata key. -+ * @param value Indicates the metadata value, which is a 32-bit integer. -+ * @return Returns true if the setting is successful; returns false otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ bool PutIntValue(const std::string_view &key, int32_t value); -+ -+ /** -+ * @brief Sets metadata of the long integer type. -+ * -+ * @param key Indicates the metadata key. -+ * @param value Indicates the metadata value, which is a 64-bit integer. -+ * @return Returns true if the setting is successful; returns false otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ bool PutLongValue(const std::string_view &key, int64_t value); -+ -+ /** -+ * @brief Sets metadata of the single-precision floating-point type. -+ * -+ * @param key Indicates the metadata key. -+ * @param value Indicates the metadata value, which is a single-precision floating-point number. -+ * @return Returns true if the metadata is successfully set; returns false otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ bool PutFloatValue(const std::string_view &key, float value); -+ -+ /** -+ * @brief Sets metadata of the double-precision floating-point type. -+ * -+ * @param key Indicates the metadata key. -+ * @param value Indicates the metadata value, which is a double-precision floating-point number. -+ * @return Returns true if the setting is successful; returns false otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ bool PutDoubleValue(const std::string_view &key, double value); -+ -+ /** -+ * @brief Sets metadata of the string type. -+ * -+ * @param key Indicates the metadata key. -+ * @param value Indicates the metadata value, which is a string. -+ * @return Returns true if the metadata is successfully set; returns false otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ bool PutStringValue(const std::string_view &key, const std::string_view &value); -+ -+ /** -+ * @brief Sets metadata of the string type. -+ * -+ * @param key Indicates the metadata key. -+ * @param addr Indicates the metadata addr, which is a uint8_t *. -+ * @param size Indicates the metadata addr size, which is a size_t. -+ * @return Returns true if the metadata is successfully set; returns false otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ bool PutBuffer(const std::string_view &key, const uint8_t *addr, size_t size); -+ -+ /** -+ * @brief Obtains the metadata value of the integer type. -+ * -+ * @param key Indicates the metadata key. -+ * @param value Indicates the metadata value to obtain, which is a 32-bit integer. -+ * @return Returns true if the integer is successfully obtained; returns false otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ bool GetIntValue(const std::string_view &key, int32_t &value) const; -+ -+ /** -+ * @brief Obtains the metadata value of the long integer type. -+ * -+ * @param key Indicates the metadata key. -+ * @param value Indicates the metadata value to obtain, which is a 64-bit long integer. -+ * @return Returns true if the integer is successfully obtained; returns false otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ bool GetLongValue(const std::string_view &key, int64_t &value) const; -+ -+ /** -+ * @brief Obtains the metadata value of the single-precision floating-point type. -+ * -+ * @param key Indicates the metadata key. -+ * @param value Indicates the metadata value to obtain, which is a single-precision floating-point number. -+ * @return Returns true if the single-precision number is successfully obtained; returns -+ * false otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ bool GetFloatValue(const std::string_view &key, float &value) const; -+ -+ /** -+ * @brief Obtains the metadata value of the double-precision floating-point type. -+ * -+ * @param key Indicates the metadata key. -+ * @param value Indicates the metadata value to obtain, which is a double-precision floating-point number. -+ * @return Returns true if the double-precision number is successfully obtained; returns -+ * false otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ bool GetDoubleValue(const std::string_view &key, double &value) const; -+ -+ /** -+ * @brief Obtains the metadata value of the string type. -+ * -+ * @param key Indicates the metadata key. -+ * @param value Indicates the metadata value to obtain, which is a string. -+ * @return Returns true if the string is successfully obtained; returns false otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ bool GetStringValue(const std::string_view &key, std::string &value) const; -+ -+ /** -+ * @brief Obtains the metadata value of the string type. -+ * -+ * @param key Indicates the metadata key. -+ * @param addr Indicates the metadata addr to obtain, which is a uint8_t **. -+ * @param size Indicates the metadata addr size to obtain, which is a size_t. -+ * @return Returns true if the string is successfully obtained; returns false otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ bool GetBuffer(const std::string_view &key, uint8_t **addr, size_t &size) const; -+ -+ /** -+ * @brief Query whether the key exists in this Format. -+ * -+ * @param key Indicates the metadata key. -+ * @return true -+ * @return false -+ */ -+ bool ContainKey(const std::string_view &key) const; -+ -+ /** -+ * @brief Get the value type for the key if the key exists in this Format. -+ * -+ * @param key Indicates the metadata key. -+ * @return FormatDataType. If the key does not exists, return FORMAT_TYPE_NONE. -+ */ -+ FormatDataType GetValueType(const std::string_view &key) const; -+ -+ /** -+ * @brief Remove the key from the Format -+ * -+ * @param keys the key will be removed. -+ */ -+ void RemoveKey(const std::string_view &key); -+ -+ /** -+ * @brief A trick to enable the comparision between the std::string and std::string_view for -+ * std::map, the trick called Transparent Comparator. -+ * -+ */ -+ using FormatDataMap = std::map>; -+ -+ /** -+ * @brief Obtains the metadata map. -+ * -+ * @return Returns the map object. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ const FormatDataMap &GetFormatMap() const; -+ -+private: -+ FormatDataMap formatMap_; -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // FORMAT_H -diff --git a/ohos_ndk_aosp/includes/media/media_data_source.h b/ohos_ndk_aosp/includes/media/media_data_source.h -new file mode 100644 -index 0000000000..0bd8396c15 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/media_data_source.h -@@ -0,0 +1,80 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef MEDIA_DATA_SOURCE_H_ -+#define MEDIA_DATA_SOURCE_H_ -+ -+#include "avsharedmemory.h" -+ -+namespace OHOS { -+namespace Media { -+/** -+ * @brief Use with IMediaDataSource::ReadAt. -+ */ -+enum MediaDataSourceError : int32_t { -+ /** -+ * use with ReadAt.the resource is cut off and player will end. -+ * And the player will complete buffers and return an error. -+ */ -+ SOURCE_ERROR_IO = -2, -+ /* use with ReadAt.the resource is eos and player will complete. */ -+ SOURCE_ERROR_EOF = -1, -+}; -+ -+/** -+ * @brief the mediaDataSource instance need set to player. -+ * -+ */ -+class IMediaDataSource { -+public: -+ virtual ~IMediaDataSource() = default; -+ -+ /** -+ * @brief If the size of the datasource is greater than 0, provide the implementation of this interface. -+ * Player use ReadAt to tell the position and length of mem want get.(length is number of Bytes) -+ * Then usr filled the mem, and return the actual length of mem. -+ * @param pos The stream pos player want get start. -+ * @param length Stream length player want to get. -+ * @param mem Stream mem need to fill. see avsharedmemory.h. -+ * The memory length is greater than or equal to the length. -+ * The length of the filled memory must match the actual length returned. -+ * @return The actual length of stream mem filled, if failed or no mem return MediaDataSourceError. -+ */ -+ virtual int32_t ReadAt(int64_t pos, uint32_t length, const std::shared_ptr &mem) = 0; -+ -+ /** -+ * @brief One-to-one use with getMem. -+ * If the size of the datasource is -1, provide the implementation of this interface. -+ * Player use ReadAt to tell the length of mem want get.(length is number of Bytes) -+ * Then usr filled the mem, and return the actual length of mem. -+ * @param length Stream length player want to get. -+ * @param mem Stream mem need to fill.see avsharedmemory.h. -+ * The memory length is greater than or equal to the length. -+ * The length of the filled memory must match the actual length returned. -+ * @return The actual length of stream mem filled, if failed or no mem return MediaDataSourceError. -+ */ -+ virtual int32_t ReadAt(uint32_t length, const std::shared_ptr &mem) = 0; -+ -+ /** -+ * @brief Get the total size of the stream. -+ * If the stream does not have the length, return -1. With -1, player will use the datasource not seekable. -+ * @param size Total size of the stream. If no size set -1. -+ * @return MSERR_OK if ok; others if failed. see media_errors.h -+ */ -+ virtual int32_t GetSize(int64_t &size) = 0; -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // MEDIA_DATA_SOURCE_H_ -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/media/media_description.h b/ohos_ndk_aosp/includes/media/media_description.h -new file mode 100644 -index 0000000000..44aa7fd146 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/media_description.h -@@ -0,0 +1,132 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef MEDIA_DESCRIPTION_H -+#define MEDIA_DESCRIPTION_H -+ -+#include -+#include "format.h" -+ -+namespace OHOS { -+namespace Media { -+/** -+ * @brief Provides the uniform container for storing the media description. -+ */ -+using MediaDescription = Format; -+ -+/** -+ * @brief Provides the key's definition for MediaDescription. -+ */ -+class MediaDescriptionKey { -+public: -+ /** -+ * Key for track index, value type is uint32_t -+ */ -+ static constexpr std::string_view MD_KEY_TRACK_INDEX = "track_index"; -+ -+ /** -+ * Key for track type, value type is uint8_t, see {link @MediaTrackType} -+ */ -+ static constexpr std::string_view MD_KEY_TRACK_TYPE = "track_type"; -+ -+ /** -+ * Key for codec mime type, value type is string -+ */ -+ static constexpr std::string_view MD_KEY_CODEC_MIME = "codec_mime"; -+ -+ /** -+ * Key for duration, value type is int64_t -+ */ -+ static constexpr std::string_view MD_KEY_DURATION = "duration"; -+ -+ /** -+ * Key for bitrate, value type is uint32_t -+ */ -+ static constexpr std::string_view MD_KEY_BITRATE = "bitrate"; -+ -+ /** -+ * Key for max input size, value type is uint32_t -+ */ -+ static constexpr std::string_view MD_KEY_MAX_INPUT_SIZE = "max_input_size"; -+ -+ /** -+ * Key for video width, value type is uint32_t -+ */ -+ static constexpr std::string_view MD_KEY_WIDTH = "width"; -+ -+ /** -+ * Key for video height, value type is uint32_t -+ */ -+ static constexpr std::string_view MD_KEY_HEIGHT = "height"; -+ -+ /** -+ * Key for video pixelformat, value type is int32_t, see {link @MediaPixelFormat} -+ */ -+ static constexpr std::string_view MD_KEY_PIXEL_FORMAT = "pixel_format"; -+ -+ /** -+ * Key for video frame rate, value type is double. -+ */ -+ static constexpr std::string_view MD_KEY_FRAME_RATE = "frame_rate"; -+ -+ /** -+ * Key for video capture rate, value type is double -+ */ -+ static constexpr std::string_view MD_KEY_CAPTURE_RATE = "capture_rate"; -+ -+ /** -+ * Key for the interval of key frame. value type is int32_t, the unit is milliseconds. -+ * A negative value means no key frames are requested after the first frame. A zero -+ * value means a stream containing all key frames is requested. -+ */ -+ static constexpr std::string_view MD_KEY_I_FRAME_INTERVAL = "i_frame_interval"; -+ -+ /** -+ * Key for the request a I-Frame immediately. value type is boolean -+ */ -+ static constexpr std::string_view MD_KEY_REQUEST_I_FRAME = "req_i_frame"; -+ -+ /** -+ * Key for audio channel count, value type is uint32_t -+ */ -+ static constexpr std::string_view MD_KEY_CHANNEL_COUNT = "channel_count"; -+ -+ /** -+ * Key for audio sample rate, value type is uint32_t -+ */ -+ static constexpr std::string_view MD_KEY_SAMPLE_RATE = "sample_rate"; -+ -+ /** -+ * Key for track count in the container, value type is uint32_t -+ */ -+ static constexpr std::string_view MD_KEY_TRACK_COUNT = "track_count"; -+ -+ /** -+ * Key for container format type, value type is string -+ */ -+ static constexpr std::string_view MD_KEY_CONTAINER_FORMAT = "container_format"; -+ -+ /** -+ * custom key prefix, media service will pass through to HAL. -+ */ -+ static constexpr std::string_view MD_KEY_CUSTOM_PREFIX = "vendor.custom"; -+ -+private: -+ MediaDescriptionKey() = delete; -+ ~MediaDescriptionKey() = delete; -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // MEDIA_DESCRIPTION_H -diff --git a/ohos_ndk_aosp/includes/media/media_errors.h b/ohos_ndk_aosp/includes/media/media_errors.h -new file mode 100644 -index 0000000000..cadfbf26c9 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/media_errors.h -@@ -0,0 +1,95 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+#ifndef MEDIA_ERRORS_H -+#define MEDIA_ERRORS_H -+ -+#include -+#include -+#include "errors.h" -+ -+namespace OHOS { -+namespace Media { -+using MSErrCode = ErrCode; -+ -+// bit 28~21 is subsys, bit 20~16 is Module. bit 15~0 is code -+constexpr MSErrCode MS_MODULE = 0X01000; -+constexpr MSErrCode MS_ERR_OFFSET = ErrCodeOffset(SUBSYS_MULTIMEDIA, MS_MODULE); -+enum MediaServiceErrCode : ErrCode { -+ MSERR_OK = ERR_OK, -+ MSERR_NO_MEMORY = MS_ERR_OFFSET + ENOMEM, // no memory -+ MSERR_INVALID_OPERATION = MS_ERR_OFFSET + ENOSYS, // opertation not be permitted -+ MSERR_INVALID_VAL = MS_ERR_OFFSET + EINVAL, // invalid argument -+ MSERR_UNKNOWN = MS_ERR_OFFSET + 0x200, // unkown error. -+ MSERR_SERVICE_DIED, // media service died -+ MSERR_CREATE_REC_ENGINE_FAILED, // create recorder engine failed. -+ MSERR_CREATE_PLAYER_ENGINE_FAILED, // create player engine failed. -+ MSERR_CREATE_AVMETADATAHELPER_ENGINE_FAILED, // create avmetadatahelper engine failed. -+ MSERR_CREATE_AVCODEC_ENGINE_FAILED, // create avcodec engine failed. -+ MSERR_INVALID_STATE, // the state is not support this operation. -+ MSERR_UNSUPPORT, // unsupport interface. -+ MSERR_UNSUPPORT_AUD_SRC_TYPE, // unsupport audio source type. -+ MSERR_UNSUPPORT_AUD_SAMPLE_RATE, // unsupport audio sample rate. -+ MSERR_UNSUPPORT_AUD_CHANNEL_NUM, // unsupport audio channel. -+ MSERR_UNSUPPORT_AUD_ENC_TYPE, // unsupport audio encoder type. -+ MSERR_UNSUPPORT_AUD_PARAMS, // unsupport audio params(other params). -+ MSERR_UNSUPPORT_VID_SRC_TYPE, // unsupport video source type. -+ MSERR_UNSUPPORT_VID_ENC_TYPE, // unsupport video encoder type. -+ MSERR_UNSUPPORT_VID_PARAMS, // unsupport video params(other params). -+ MSERR_UNSUPPORT_CONTAINER_TYPE, // unsupport container format type. -+ MSERR_UNSUPPORT_PROTOCOL_TYPE, // unsupport protocol type. -+ MSERR_UNSUPPORT_VID_DEC_TYPE, // unsupport video decoder type. -+ MSERR_UNSUPPORT_AUD_DEC_TYPE, // unsupport audio decoder type. -+ MSERR_AUD_ENC_FAILED, // audio encode failed. -+ MSERR_VID_ENC_FAILED, // video encode failed. -+ MSERR_AUD_DEC_FAILED, // audio decode failed. -+ MSERR_VID_DEC_FAILED, // video decode failed. -+ MSERR_MUXER_FAILED, // stream muxer failed. -+ MSERR_DEMUXER_FAILED, // stream demuxer or parser failed. -+ MSERR_OPEN_FILE_FAILED, // open file failed. -+ MSERR_FILE_ACCESS_FAILED, // read or write file failed. -+ MSERR_START_FAILED, // audio/video start failed. -+ MSERR_PAUSE_FAILED, // audio/video pause failed. -+ MSERR_STOP_FAILED, // audio/video stop failed. -+ MSERR_SEEK_FAILED, // audio/video seek failed. -+ MSERR_NETWORK_TIMEOUT, // network timeout. -+ MSERR_NOT_FIND_CONTAINER, // not find a demuxer. -+ MSERR_DATA_SOURCE_IO_ERROR, // media data source IO failed. -+ MSERR_DATA_SOURCE_OBTAIN_MEM_ERROR, // media data source get mem failed. -+ MSERR_DATA_SOURCE_ERROR_UNKNOWN, // media data source error unknow. -+ MSERR_EXTEND_START = MS_ERR_OFFSET + 0xF000, // extend err start. -+}; -+ -+// media api error code -+enum MediaServiceExtErrCode : ErrCode { -+ MSERR_EXT_OK = 0, -+ MSERR_EXT_NO_MEMORY = 1, // no memory. -+ MSERR_EXT_OPERATE_NOT_PERMIT = 2, // opertation not be permitted. -+ MSERR_EXT_INVALID_VAL = 3, // invalid argument. -+ MSERR_EXT_IO = 4, // IO error. -+ MSERR_EXT_TIMEOUT = 5, // network timeout. -+ MSERR_EXT_UNKNOWN = 6, // unknown error. -+ MSERR_EXT_SERVICE_DIED = 7, // media service died. -+ MSERR_EXT_INVALID_STATE = 8, // the state is not support this operation. -+ MSERR_EXT_UNSUPPORT = 9, // unsupport interface. -+ MSERR_EXT_EXTEND_START = 100, // extend err start. -+}; -+ -+__attribute__((visibility("default"))) std::string MSErrorToString(MediaServiceErrCode code); -+__attribute__((visibility("default"))) std::string MSExtErrorToString(MediaServiceExtErrCode code); -+__attribute__((visibility("default"))) std::string MSErrorToExtErrorString(MediaServiceErrCode code); -+__attribute__((visibility("default"))) MediaServiceExtErrCode MSErrorToExtError(MediaServiceErrCode code); -+} // namespace Media -+} // namespace OHOS -+#endif // MEDIA_ERRORS_H -diff --git a/ohos_ndk_aosp/includes/media/media_surface.h b/ohos_ndk_aosp/includes/media/media_surface.h -new file mode 100644 -index 0000000000..9fc3558424 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/media_surface.h -@@ -0,0 +1,40 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef MEDIA_SURFACE_H -+#define MEDIA_SURFACE_H -+ -+#include "surface.h" -+ -+namespace OHOS { -+namespace Media { -+class MediaSurface { -+public: -+ virtual ~MediaSurface() = default; -+ virtual std::string GetSurfaceId(const sptr &surface) = 0; -+ virtual sptr GetSurface() = 0; -+ virtual sptr GetSurface(const std::string &id) = 0; -+ virtual void Release() = 0; -+}; -+ -+class __attribute__((visibility("default"))) MediaSurfaceFactory { -+public: -+ static std::shared_ptr CreateMediaSurface(); -+ MediaSurfaceFactory() = delete; -+ ~MediaSurfaceFactory() = delete; -+}; -+} // namespace Media -+} // namespace OHOS -+#endif // MEDIA_SURFACE_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/media/player.h b/ohos_ndk_aosp/includes/media/player.h -new file mode 100644 -index 0000000000..a88c0cca3d ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/player.h -@@ -0,0 +1,478 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef PLAYER_H -+#define PLAYER_H -+ -+#include -+#include "surface.h" -+#include "format.h" -+#include "media_data_source.h" -+ -+namespace OHOS { -+namespace Media { -+class PlayerKeys { -+public: -+ static constexpr std::string_view PLAYER_TRACK_INDEX = "track_index"; -+ static constexpr std::string_view PLAYER_TRACK_TYPE = "track_type"; -+ static constexpr std::string_view PLAYER_WIDTH = "width"; -+ static constexpr std::string_view PLAYER_HEIGHT = "height"; -+ static constexpr std::string_view PLAYER_MIME = "codec_mime"; -+ static constexpr std::string_view PLAYER_BITRATE = "bitrate"; -+ static constexpr std::string_view PLAYER_FRAMERATE = "frame_rate"; -+ static constexpr std::string_view PLAYER_LANGUGAE = "language_code"; -+ static constexpr std::string_view PLAYER_SAMPLE_RATE = "sample_rate"; -+ static constexpr std::string_view PLAYER_CHANNELS = "channel_count"; -+ static constexpr std::string_view PLAYER_BUFFERING_START = "buffering_start"; -+ static constexpr std::string_view PLAYER_BUFFERING_END = "buffering_end"; -+ static constexpr std::string_view PLAYER_BUFFERING_PERCENT = "buffering_percent"; -+ static constexpr std::string_view PLAYER_CACHED_DURATION = "cached_duration"; -+ static constexpr std::string_view CONTENT_TYPE = "content_type"; -+ static constexpr std::string_view STREAM_USAGE = "stream_usage"; -+}; -+ -+enum BufferingInfoType : int32_t { -+ /* begin to b buffering */ -+ BUFFERING_START = 1, -+ /* end to buffering */ -+ BUFFERING_END = 2, -+ /* buffering percent */ -+ BUFFERING_PERCENT = 3, -+ /* cached duration in milliseconds */ -+ CACHED_DURATION = 4, -+}; -+ -+enum PlayerErrorType : int32_t { -+ /* Valid error, error code reference defined in media_errors.h */ -+ PLAYER_ERROR, -+ /* Unknown error */ -+ PLAYER_ERROR_UNKNOWN, -+ /** extend error type start,The extension error type agreed upon by the plug-in and -+ the application will be transparently transmitted by the service. */ -+ PLAYER_ERROR_EXTEND_START = 0X10000, -+}; -+ -+enum PlayerMessageType : int32_t { -+ /* unknown info */ -+ PLAYER_INFO_UNKNOWN = 0, -+ /* first video frame start to render. */ -+ PLAYER_INFO_VIDEO_RENDERING_START, -+ /* network bandwidth, uint is KB and passed by "extra"(arg 2). */ -+ PLAYER_INFO_NETWORK_BANDWIDTH, -+ /* not fatal errors accured, errorcode see "media_errors.h" and passed by "extra"(arg 2). */ -+ PLAYER_INFO_WARNING, -+ /* system new info type should be added here. -+ extend start. App and plugins or PlayerEngine extended info type start. */ -+ PLAYER_INFO_EXTEND_START = 0X1000, -+}; -+ -+enum PlayerOnInfoType : int32_t { -+ /* return the message when seeking done. */ -+ INFO_TYPE_SEEKDONE = 1, -+ /* return the message when speeding done. */ -+ INFO_TYPE_SPEEDDONE, -+ /* return the message when playback is end of steam. */ -+ INFO_TYPE_EOS, -+ /* return the message when PlayerStates changed. */ -+ INFO_TYPE_STATE_CHANGE, -+ /* return the current posion of playback automatically. */ -+ INFO_TYPE_POSITION_UPDATE, -+ /* return the playback message. */ -+ INFO_TYPE_MESSAGE, -+ /* return the message when volume changed. */ -+ INFO_TYPE_VOLUME_CHANGE, -+ /* return the message when video size is first known or updated. */ -+ INFO_TYPE_RESOLUTION_CHANGE, -+ /* return multiqueue buffering time. */ -+ INFO_TYPE_BUFFERING_UPDATE, -+ /* return the message with extra information in format. */ -+ INFO_TYPE_EXTRA_FORMAT -+}; -+ -+enum PlayerStates : int32_t { -+ /* error states */ -+ PLAYER_STATE_ERROR = 0, -+ /* idle states */ -+ PLAYER_IDLE = 1, -+ /* initialized states(Internal states) */ -+ PLAYER_INITIALIZED = 2, -+ /* preparing states(Internal states) */ -+ PLAYER_PREPARING = 3, -+ /* prepared states */ -+ PLAYER_PREPARED = 4, -+ /* started states */ -+ PLAYER_STARTED = 5, -+ /* paused states */ -+ PLAYER_PAUSED = 6, -+ /* stopped states */ -+ PLAYER_STOPPED = 7, -+ /* Play to the end states */ -+ PLAYER_PLAYBACK_COMPLETE = 8, -+}; -+ -+enum PlayerSeekMode : int32_t { -+ /* sync to keyframes after the time point. */ -+ SEEK_NEXT_SYNC = 0, -+ /* sync to keyframes before the time point. */ -+ SEEK_PREVIOUS_SYNC, -+ /* sync to closest keyframes. */ -+ SEEK_CLOSEST_SYNC, -+ /* seek to frames closest the time point. */ -+ SEEK_CLOSEST, -+}; -+ -+enum PlaybackRateMode : int32_t { -+ /* Video playback at 0.75x normal speed */ -+ SPEED_FORWARD_0_75_X, -+ /* Video playback at normal speed */ -+ SPEED_FORWARD_1_00_X, -+ /* Video playback at 1.25x normal speed */ -+ SPEED_FORWARD_1_25_X, -+ /* Video playback at 1.75x normal speed */ -+ SPEED_FORWARD_1_75_X, -+ /* Video playback at 2.0x normal speed */ -+ SPEED_FORWARD_2_00_X, -+}; -+ -+class PlayerCallback { -+public: -+ virtual ~PlayerCallback() = default; -+ /** -+ * Called when an error occurred. -+ * -+ * @param errorType Error type. For details, see {@link PlayerErrorType}. -+ * @param errorCode Error code. -+ */ -+ virtual void OnError(PlayerErrorType errorType, int32_t errorCode) = 0; -+ -+ /** -+ * Called when a player message or alarm is received. -+ * -+ * @param type Indicates the information type. For details, see {@link PlayerOnInfoType}. -+ * @param extra Indicates other information, for example, the start time position of a playing file. -+ * @param infoBody According to the info type, the information carrier passed.Is an optional parameter. -+ */ -+ virtual void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody) = 0; -+}; -+ -+class Player { -+public: -+ virtual ~Player() = default; -+ -+ /** -+ * @brief Sets the playback source for the player. The corresponding source can be http url -+ * -+ * @param url Indicates the playback source. -+ * @return Returns {@link MSERR_OK} if the url is set successfully; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetSource(const std::string &url) = 0; -+ -+ /** -+ * @brief Sets the playback media data source for the player. -+ * -+ * @param dataSrc Indicates the media data source. in {@link media_data_source.h} -+ * @return Returns {@link MSERR_OK} if the mediadatasource is set successfully; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetSource(const std::shared_ptr &dataSrc) = 0; -+ -+ /** -+ * @brief Sets the playback media file descriptor source for the player. -+ * -+ * @param fd Indicates the file descriptor of media source. -+ * @param offset Indicates the offset of media source in file descriptor. -+ * @param size Indicates the size of media source. -+ * @return Returns {@link MSERR_OK} if the fd source is set successfully; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetSource(int32_t fd, int64_t offset = 0, int64_t size = 0) = 0; -+ -+ /** -+ * @brief Start playback. -+ * -+ * This function must be called after {@link Prepare}. If the player state is Prepared, -+ * this function is called to start playback. -+ * -+ * @return Returns {@link MSERR_OK} if the playback is started; otherwise returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t Play() = 0; -+ -+ /** -+ * @brief Prepares the playback environment and buffers media data. -+ * -+ * This function must be called after {@link SetSource}. -+ * -+ * @return Returns {@link MSERR_OK} if the playback is prepared; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t Prepare() = 0; -+ -+ /** -+ * @brief Prepare the playback environment and buffers media data asynchronous. -+ * -+ * This function must be called after {@link SetSource}. -+ * -+ * @return Returns {@link MSERR_OK} if the playback is preparing; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t PrepareAsync() = 0; -+ -+ /** -+ * @brief Pauses playback. -+ * -+ * @return Returns {@link MSERR_OK} if the playback is paused; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t Pause() = 0; -+ -+ /** -+ * @brief Stop playback. -+ * -+ * @return Returns {@link MSERR_OK} if the playback is stopped; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t Stop() = 0; -+ -+ /** -+ * @brief Restores the player to the initial state. -+ * -+ * After the function is called, add a playback source by calling {@link SetSource}, -+ * call {@link Play} to start playback again after {@link Prepare} is called. -+ * -+ * @return Returns {@link MSERR_OK} if the playback is reset; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t Reset() = 0; -+ -+ /** -+ * @brief Releases player resources -+ * -+ * @return Returns {@link MSERR_OK} if the playback is released; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t Release() = 0; -+ -+ /** -+ * @brief Sets the volume of the player. -+ * -+ * This function can be used during playback or pause. The value 0 indicates no sound, -+ * and 1 indicates the original volume. If no audio device is started or no audio -+ * stream exists, the value -1 is returned. -+ * -+ * @param leftVolume Indicates the target volume of the left audio channel to set, -+ * ranging from 0 to 1. each step is 0.01. -+ * @param rightVolume Indicates the target volume of the right audio channel to set, -+ * ranging from 0 to 1. each step is 0.01. -+ * @return Returns {@link MSERR_OK} if the volume is set; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetVolume(float leftVolume, float rightVolume) = 0; -+ -+ /** -+ * @brief Changes the playback position. -+ * -+ * This function can be used during play or pause. -+ * -+ * @param mSeconds Indicates the target playback position, accurate to milliseconds. -+ * @param mode Indicates the player seek mode. For details, see {@link PlayerSeekMode}. -+ * @return Returns {@link MSERR_OK} if the seek is done; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) = 0; -+ -+ /** -+ * @brief Obtains the playback position, accurate to millisecond. -+ * -+ * @param currentTime Indicates the playback position. -+ * @return Returns {@link MSERR_OK} if the current position is get; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t GetCurrentTime(int32_t ¤tTime) = 0; -+ -+ /** -+ * @brief Obtains the video track info, contains mimeType, bitRate, width, height, frameRata. -+ * -+ * @param video track info vec. -+ * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t GetVideoTrackInfo(std::vector &videoTrack) = 0; -+ -+ /** -+ * @brief Obtains the audio track info, contains mimeType, bitRate, sampleRate, channels, language. -+ * -+ * @param audio track info vec. -+ * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t GetAudioTrackInfo(std::vector &audioTrack) = 0; -+ -+ /** -+ * @brief get the video width. -+ * -+ * @return Returns width if success; else returns 0 -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t GetVideoWidth() = 0; -+ -+ /** -+ * @brief get the video height. -+ * -+ * @return Returns height if success; else returns 0 -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t GetVideoHeight() = 0; -+ -+ /** -+ * @brief Obtains the total duration of media files, accurate to milliseconds. -+ * -+ * @param duration Indicates the total duration of media files. -+ * @return Returns {@link MSERR_OK} if the current duration is get; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t GetDuration(int32_t &duration) = 0; -+ -+ /** -+ * @brief set the player playback rate -+ * -+ * @param mode the rate mode {@link PlaybackRateMode} which can set. -+ * @return Returns {@link MSERR_OK} if the playback rate is set successful; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetPlaybackSpeed(PlaybackRateMode mode) = 0; -+ -+ /** -+ * @brief get the current player playback rate -+ * -+ * @param mode the rate mode {@link PlaybackRateMode} which can get. -+ * @return Returns {@link MSERR_OK} if the current player playback rate is get; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t GetPlaybackSpeed(PlaybackRateMode &mode) = 0; -+ -+ /** -+ * @brief Method to set the surface. -+ * -+ * @param surface pointer of the surface. -+ * @return Returns {@link MSERR_OK} if the surface is set; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetVideoSurface(sptr surface) = 0; -+ -+ /** -+ * @brief Checks whether the player is playing. -+ * -+ * @return Returns true if the playback is playing; false otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual bool IsPlaying() = 0; -+ -+ /** -+ * @brief Returns the value whether single looping is enabled or not . -+ * -+ * @return Returns true if the playback is single looping; false otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual bool IsLooping() = 0; -+ -+ /** -+ * @brief Enables single looping of the media playback. -+ * -+ * @return Returns {@link MSERR_OK} if the single looping is set; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetLooping(bool loop) = 0; -+ -+ /** -+ * @brief Method to set player callback. -+ * -+ * @param callback object pointer. -+ * @return Returns {@link MSERR_OK} if the playercallback is set; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetPlayerCallback(const std::shared_ptr &callback) = 0; -+ -+ /** -+ * @brief Sets an extended parameter for player -+ * -+ * @param format Indicates the string key and value. For details, see {@link Format} -+ * @return Returns {@link MSERR_OK} if the parameters are set; returns an error code defined -+ * in {@link media_errors.h} otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetParameter(const Format ¶m) = 0; -+}; -+ -+class __attribute__((visibility("default"))) PlayerFactory { -+public: -+ static std::shared_ptr CreatePlayer(); -+ -+private: -+ PlayerFactory() = default; -+ ~PlayerFactory() = default; -+}; -+__attribute__((visibility("default"))) std::string PlayerErrorTypeToString(PlayerErrorType type); -+} // namespace Media -+} // namespace OHOS -+#endif // PLAYER_H -diff --git a/ohos_ndk_aosp/includes/media/recorder.h b/ohos_ndk_aosp/includes/media/recorder.h -new file mode 100644 -index 0000000000..dbe3967cf4 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/media/recorder.h -@@ -0,0 +1,662 @@ -+/* -+ * Copyright (C) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef RECORDER_H -+#define RECORDER_H -+ -+#include -+#include -+#include "format.h" -+#include "surface.h" -+#include "av_common.h" -+ -+namespace OHOS { -+namespace Media { -+/** -+ * @brief Enumerates video source types. -+ * -+ * @since 1.0 -+ * @version 1.0 -+ */ -+enum VideoSourceType : int32_t { -+ /** Unsupported App Usage. */ -+ /** YUV video data provided through {@link Surface} */ -+ VIDEO_SOURCE_SURFACE_YUV = 0, -+ /** Raw encoded data provided through {@link Surface} */ -+ VIDEO_SOURCE_SURFACE_ES, -+ /** Invalid value */ -+ VIDEO_SOURCE_BUTT -+}; -+ -+/** -+ * @brief Enumerates audio source types. -+ * -+ * @since 1.0 -+ * @version 1.0 -+ */ -+enum AudioSourceType : int32_t { -+ /** Invalid audio source */ -+ AUDIO_SOURCE_INVALID = -1, -+ /** Default audio source */ -+ AUDIO_SOURCE_DEFAULT = 0, -+ /** Microphone */ -+ AUDIO_MIC = 1, -+}; -+ -+/** -+ * Unsupported app usage. -+ * @brief Enumerates data source types. -+ * -+ * @since 1.0 -+ * @version 1.0 -+ */ -+enum DataSourceType : int32_t { -+ /** meta data source */ -+ METADATA = 0 -+}; -+ -+/** -+ * @brief Enumerates output format types. -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum OutputFormatType : int32_t { -+ /** Default format */ -+ FORMAT_DEFAULT = 0, -+ /** MPEG4 format */ -+ FORMAT_MPEG_4 = 2, -+ /** M4A format */ -+ FORMAT_M4A = 6, -+ /** BUTT */ -+ FORMAT_BUTT, -+}; -+ -+/** -+ * @brief Enumerates video codec formats. -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum VideoCodecFormat : int32_t { -+ /** Default format */ -+ VIDEO_DEFAULT = 0, -+ /** H.264 */ -+ H264 = 2, -+ /** MPEG4 */ -+ MPEG4 = 6, -+ VIDEO_CODEC_FORMAT_BUTT, -+}; -+ -+/** -+ * @brief Enumerates audio codec formats. -+ * -+ * @since 3.1 -+ * @version 3.1 -+ */ -+enum AudioCodecFormat : int32_t { -+ /** Default format */ -+ AUDIO_DEFAULT = 0, -+ /** Advanced Audio Coding Low Complexity (AAC-LC) */ -+ AAC_LC = 3, -+ /** Invalid value */ -+ AUDIO_CODEC_FORMAT_BUTT, -+}; -+ -+/** -+ * Unsupported App Usage. -+ * @brief Enumerates file split types. -+ * -+ * @since 1.0 -+ * @version 1.0 -+ */ -+enum FileSplitType : int32_t { -+ /** Delayed/Backward split */ -+ FILE_SPLIT_POST = 0, -+ /** Advanced/Forward split */ -+ FILE_SPLIT_PRE, -+ /** Normal split */ -+ FILE_SPLIT_NORMAL, -+ /** Invalid value */ -+ FILE_SPLIT_BUTT, -+}; -+ -+/** -+ * @brief Enumerates recording information types. -+ * -+ * @since 1.0 -+ * @version 1.0 -+ */ -+enum RecorderInfoType : int32_t { -+ /** -+ * The recording duration is reaching the threshold specified by {@link SetMaxDuration}. This type of -+ * information is reported when only one second or 10% is left to reach the allowed duration. -+ */ -+ RECORDER_INFO_MAX_DURATION_APPROACHING = 0, -+ /** -+ * The recorded file size is reaching the threshold specified by {@link SetMaxFileSize}. This type of -+ * information is reported when only 100 KB or 10% is left to reach the allowed size. -+ */ -+ RECORDER_INFO_MAX_FILESIZE_APPROACHING, -+ /** -+ * The threshold specified by {@link SetMaxDuration} is reached, and the recording ends. -+ * Before calling {@link SetNextOutputFile}, you must close the file. -+ */ -+ RECORDER_INFO_MAX_DURATION_REACHED, -+ /** -+ * The threshold specified by {@link SetMaxFileSize} is reached, and the recording ends. -+ * Before calling {@link SetNextOutputFile}, you must close the file. -+ */ -+ RECORDER_INFO_MAX_FILESIZE_REACHED, -+ /** Recording started for the next output file. */ -+ RECORDER_INFO_NEXT_OUTPUT_FILE_STARTED, -+ /** Manual file split completed. */ -+ RECORDER_INFO_FILE_SPLIT_FINISHED, -+ /** The start time position of the recording file is not supported. */ -+ RECORDER_INFO_FILE_START_TIME_MS, -+ /** Next file fd is needed but not set. */ -+ RECORDER_INFO_NEXT_FILE_FD_NOT_SET, -+ -+ /** warnings, and the err code passed by the 'extra' argument, the code see "MediaServiceErrCode". */ -+ RECORDER_INFO_INTERNEL_WARNING, -+ -+ /** extend info start,The extension information code agreed upon by the plug-in and -+ the application will be transparently transmitted by the service. */ -+ RECORDER_INFO_EXTEND_START = 0X10000, -+}; -+ -+/** -+ * @brief Enumerates recording error types. -+ * -+ * @since 1.0 -+ * @version 1.0 -+ */ -+enum RecorderErrorType : int32_t { -+ /* internal errors, error code passed by the errorCode, and definition see "MediaServiceErrCode" */ -+ RECORDER_ERROR_INTERNAL, -+ -+ /** extend error start,The extension error code agreed upon by the plug-in and -+ the application will be transparently transmitted by the service. */ -+ RECORDER_ERROR_EXTEND_START = 0X10000, -+}; -+ -+/** -+ * @brief Provides listeners for recording errors and information events. -+ * -+ * @since 1.0 -+ * @version 1.0 -+ */ -+class RecorderCallback { -+public: -+ virtual ~RecorderCallback() = default; -+ -+ /** -+ * @brief Called when an error occurs during recording. This callback is used to report recording errors. -+ * -+ * @param errorType Indicates the error type. For details, see {@link RecorderErrorType}. -+ * @param errorCode Indicates the error code. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual void OnError(RecorderErrorType errorType, int32_t errorCode) = 0; -+ -+ /** -+ * @brief Called when an information event occurs during recording. This callback is used to report recording -+ * information. -+ * -+ * @param type Indicates the information type. For details, see {@link RecorderInfoType}. -+ * @param extra Indicates other information, for example, the start time position of a recording file. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual void OnInfo(int32_t type, int32_t extra) = 0; -+}; -+ -+/** -+ * @brief Provides functions for audio and video recording. -+ * -+ * @since 1.0 -+ * @version 1.0 -+ */ -+class Recorder { -+public: -+ virtual ~Recorder() = default; -+ -+ /** -+ * @brief Sets a video source for recording. -+ * -+ * If this function is not called, the output file does not contain the video track. -+ * -+ * @param source Indicates the video source type. For details, see {@link VideoSourceType}. -+ * @param sourceId Indicates the video source ID. The value -1 indicates an invalid ID and the setting fails. -+ * -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetVideoSource(VideoSourceType source, int32_t &sourceId) = 0; -+ -+ /** -+ * @brief Sets the audio source for recording. -+ * -+ * If this function is not called, the output file does not contain the audio track. -+ * -+ * @param source Indicates the audio source type. For details, see {@link AudioSourceType}. -+ * @param sourceId Indicates the audio source ID. The value -1 indicates an invalid ID and the setting fails. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetAudioSource(AudioSourceType source, int32_t &sourceId) = 0; -+ -+ /** -+ * Unsupported App Usage. -+ * @brief Sets a data source for recording. -+ * -+ * If this function is not called, the output file does not contain the data track. -+ * -+ * @param sourceId Indicates the data source ID. The value -1 indicates an invalid ID and the setting fails. -+ * -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetDataSource(DataSourceType dataType, int32_t &sourceId) = 0; -+ -+ /** -+ * @brief Sets the output file format. -+ * -+ * This function must be called before {@link Prepare} and after after all required sources have been set. After -+ * this function called, no more source settings allowed. -+ * -+ * @param format Indicates the output file format. For details, see {@link OutputFormatType}. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetOutputFormat(OutputFormatType format) = 0; -+ -+ /** -+ * @brief Sets a video encoder for recording. -+ * -+ * If this function is not called, the output file does not contain the video track. -+ * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. -+ * -+ * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}. -+ * @param encoder Indicates the video encoder to set. For details, see {@link VideoCodecFormat}. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetVideoEncoder(int32_t sourceId, VideoCodecFormat encoder) = 0; -+ -+ /** -+ * @brief Sets the width and height of the video to record. -+ * -+ * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. -+ * -+ * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}. -+ * @param width Indicates the video width to set. -+ * @param height Indicates the video height to set. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetVideoSize(int32_t sourceId, int32_t width, int32_t height) = 0; -+ -+ /** -+ * Unsupported App Usage. -+ * @brief Sets the frame rate of the video to record. -+ * -+ * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. -+ * -+ * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}. -+ * @param frameRate Indicates the frame rate to set. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetVideoFrameRate(int32_t sourceId, int32_t frameRate) = 0; -+ -+ /** -+ * @brief Sets the encoding bit rate of the video to record. -+ * -+ * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. -+ * -+ * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}. -+ * @param rate Indicates the encoding bit rate to set. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetVideoEncodingBitRate(int32_t sourceId, int32_t rate) = 0; -+ -+ /** -+ * Unsupported App Usage. -+ * @brief Sets the video capture rate. -+ * -+ * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. It is valid when the -+ * video source is YUV or RGB. -+ * -+ * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}. -+ * @param fps Indicates the rate at which frames are captured per second. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetCaptureRate(int32_t sourceId, double fps) = 0; -+ -+ /** -+ * @brief Obtains the surface of the video source. This function can only be called after {@link Prepare} and -+ * before {@link Stop}. -+ * -+ * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}. -+ * @return Returns the pointer to the surface. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual sptr GetSurface(int32_t sourceId) = 0; -+ -+ /** -+ * @brief Sets an audio encoder for recording. -+ * -+ * If this function is not called, the output file does not contain the audio track. -+ * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. -+ * -+ * @param sourceId Indicates the audio source ID, which can be obtained from {@link SetAudioSource}. -+ * @param encoder Indicates the audio encoder to set. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetAudioEncoder(int32_t sourceId, AudioCodecFormat encoder) = 0; -+ -+ /** -+ * @brief Sets the audio sampling rate for recording. -+ * -+ * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. -+ * -+ * @param sourceId Indicates the audio source ID, which can be obtained from {@link SetAudioSource}. -+ * @param rate Indicates the sampling rate of the audio per second. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetAudioSampleRate(int32_t sourceId, int32_t rate) = 0; -+ -+ /** -+ * @brief Sets the number of audio channels to record. -+ * -+ * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. -+ * -+ * @param sourceId Indicates the audio source ID, which can be obtained from {@link SetAudioSource}. -+ * @param num Indicates the number of audio channels to set. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetAudioChannels(int32_t sourceId, int32_t num) = 0; -+ -+ /** -+ * @brief Sets the encoding bit rate of the audio to record. -+ * -+ * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. -+ * -+ * @param sourceId Indicates the audio source ID, which can be obtained from {@link SetAudioSource}. -+ * @param bitRate Indicates the audio encoding bit rate, in bit/s. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetAudioEncodingBitRate(int32_t sourceId, int32_t bitRate) = 0; -+ -+ /** -+ * Unsupported App Usage. -+ * @brief Sets the maximum duration of a recorded file, in seconds. -+ * -+ * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. If the setting is valid, -+ * {@link RECORDER_INFO_MAX_DURATION_APPROACHING} is reported through {@link OnInfo} in the {@link RecorderCallback} -+ * class when only one second or 10% is left to reach the allowed duration. -+ * If the recording output file is set by calling {@link SetOutputFile}, call {@link SetNextOutputFile} to set the -+ * next output file. Otherwise, the current file will be overwritten when the allowed duration is reached. -+ * -+ * @param duration Indicates the maximum recording duration to set. If the value is 0 or a negative number, -+ * a failure message is returned. The default duration is 60s. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetMaxDuration(int32_t duration) = 0; -+ -+ /** -+ * Unsupported App Usage. -+ * @brief Sets the maximum size of a recorded file, in bytes. -+ * -+ * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. If the setting is valid, -+ * {@link RECORDER_INFO_MAX_DURATION_APPROACHING} is reported through {@link OnInfo} in the {@link RecorderCallback} -+ * class when only 100 KB or 10% is left to reach the allowed size. -+ * If the recording output file is set by calling {@link SetOutputFile}, call {@link SetNextOutputFile} to set the -+ * next output file. Otherwise, when the allowed size is reached, the current file will be overwritten. If -+ * MaxDuration is also set by calling {@link SetMaxDuration}, MaxDuration or MaxFileSize -+ * prevails depending on which of them is first satisfied. -+ * -+ * @param size Indicates the maximum file size to set. If the value is 0 or a negative number, a failure -+ * message is returned. -+ * By default, the maximum size of a single file supported by the current file system is used as the limit. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetMaxFileSize(int64_t size) = 0; -+ -+ /** -+ * @brief Sets the output file path. -+ * -+ * This function must be called after {@link SetOutputFormat} but before {@link Prepare} and One of them -+ * {@link SetOutputFile} must be set. -+ * -+ * @param path Indicates the output file path. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetOutputPath(const std::string &path) = 0; -+ -+ /** -+ * @brief Sets the file descriptor (FD) of the output file. -+ * -+ * This function must be called after {@link SetOutputFormat} but before {@link Prepare} and One of them -+ * {@link SetOutputPath} must be set. -+ * -+ * @param fd Indicates the FD of the file. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetOutputFile(int32_t fd) = 0; -+ -+ /** -+ * Unsupported App Usage. -+ * @brief Sets the FD of the next output file. -+ * -+ * If {@link SetOutputFile} is successful, call this function to set the FD of the next output file after -+ * {@link RECORDER_INFO_MAX_DURATION_APPROACHING} or {@link RECORDER_INFO_MAX_FILESIZE_APPROACHING} is received. -+ * -+ * @param fd Indicates the FD of the next output file. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetNextOutputFile(int32_t fd) = 0; -+ -+ /** -+ * @brief Set and store the geodata (latitude and longitude) in the output file. -+ * This method should be called before prepare(). The geodata is stored in udta box if -+ * the output format is OutputFormat.THREE_GPP or OutputFormat.MPEG_4, -+ * and is ignored for other output formats. -+ * -+ * @param latitude float: latitude in degrees. Its value must be in the range [-90, 90]. -+ * @param longitude float: longitude in degrees. Its value must be in the range [-180, 180]. -+ * @since openharmony 3.1 -+ * @version 1.0 -+ */ -+ virtual void SetLocation(float latitude, float longitude) = 0; -+ -+ /** -+ * @brief set the orientation hint in output file, and for the file to playback. mp4 support. -+ * the range of orientation should be {0, 90, 180, 270}, default is 0. -+ * -+ * @param rotation int32_t: should be {0, 90, 180, 270}, default is 0. -+ * @since openharmony 3.1 -+ * @version 1.0 -+ */ -+ virtual void SetOrientationHint(int32_t rotation) = 0; -+ -+ /** -+ * @brief Registers a recording listener. -+ * -+ * This function must be called after {@link SetOutputFormat} but before {@link Prepare} -+ * -+ * @param callback Indicates the recording listener to register. For details, see {@link RecorderCallback}. -+ * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetRecorderCallback(const std::shared_ptr &callback) = 0; -+ -+ /** -+ * @brief Prepares for recording. -+ * -+ * This function must be called before {@link Start}. -+ * -+ * @return Returns {@link MSERR_OK} if the preparation is successful; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t Prepare() = 0; -+ -+ /** -+ * @brief Starts recording. -+ * -+ * This function must be called after {@link Prepare}. -+ * -+ * @return Returns {@link MSERR_OK} if the recording is started; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t Start() = 0; -+ -+ /** -+ * @brief Pauses recording. -+ * -+ * After {@link Start} is called, you can call this function to pause recording. -+ * -+ * @return Returns {@link MSERR_OK} if the recording is paused; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t Pause() = 0; -+ -+ /** -+ * @brief Resumes recording. -+ * -+ * You can call this function to resume recording after {@link Pause} is called. -+ * -+ * @return Returns {@link MSERR_OK} if the recording is resumed; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t Resume() = 0; -+ -+ /** -+ * @brief Stops recording. -+ * -+ * @param block Indicates the stop mode. The value true indicates that the processing stops after all caches -+ * are processed, and false indicates that the processing stops immediately and all caches are discarded. -+ * After the recording stopped, all sources and parameters must be set again to restore recording. The function is -+ * like to {@link Reset}, except that the block parameter is allowed to be specified. -+ * @return Returns {@link MSERR_OK} if the recording is stopped; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t Stop(bool block) = 0; -+ -+ /** -+ * @brief Resets the recording. -+ * -+ * After the function is called, add a recording source by calling {@link SetVideoSource} or {@link SetAudioSource}, -+ * set related parameters, and call {@link Start} to start recording again after {@link Prepare} is called. -+ * -+ * @return Returns {@link MSERR_OK} if the recording is stopped; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t Reset() = 0; -+ -+ /** -+ * @brief Releases recording resources. After this function called, none of interfaces of {@link Recorder} -+ * can be used. -+ * -+ * @return Returns {@link MSERR_OK} if the recording is stopped; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t Release() = 0; -+ -+ /** -+ * Unsupported App Usage. -+ * @brief Manually splits a video. -+ * -+ * This function must be called after {@link Start}. After this function is called, the file is split based on the -+ * manual split type. After the manual split is complete, the initial split type is used. This function can be -+ * called again only after {@link RECORDER_INFO_FILE_SPLIT_FINISHED} is reported. -+ * -+ * @param type Indicates the file split type. For details, see {@link FileSplitType}. -+ * @param timestamp Indicates the file split timestamp. This parameter is not supported currently and can be set to -+ * -1. The recording module splits a file based on the call time. -+ * @param duration Indicates the duration for splitting the file. -+ * @return Returns {@link MSERR_OK} if the recording is stopped; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetFileSplitDuration(FileSplitType type, int64_t timestamp, uint32_t duration) = 0; -+ -+ /** -+ * @brief Sets an extended parameter for recording, for example, {@link RECORDER_PRE_CACHE_DURATION}. -+ * -+ * This function must be called after {@link Prepare}. -+ * -+ * @param sourceId Indicates the data source ID. The value -1 indicates all sources. -+ * @param format Indicates the string key and value. For details, see {@link Format} and -+ * {@link RECORDER_PRE_CACHE_DURATION}. -+ * @return Returns {@link MSERR_OK} if the recording is stopped; returns an error code otherwise. -+ * @since 1.0 -+ * @version 1.0 -+ */ -+ virtual int32_t SetParameter(int32_t sourceId, const Format &format) = 0; -+}; -+ -+class __attribute__((visibility("default"))) RecorderFactory { -+public: -+ static std::shared_ptr CreateRecorder(); -+private: -+ RecorderFactory() = default; -+ ~RecorderFactory() = default; -+}; -+ -+__attribute__((visibility("default"))) std::string RecorderErrorTypeToString(RecorderErrorType type); -+} // namespace Media -+} // namespace OHOS -+#endif // RECORDER_H -diff --git a/ohos_ndk_aosp/includes/multimodalinput/axis_event.h b/ohos_ndk_aosp/includes/multimodalinput/axis_event.h -new file mode 100755 -index 0000000000..bb6bd655b5 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/multimodalinput/axis_event.h -@@ -0,0 +1,57 @@ -+/* -+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef AXIS_EVENT_H -+#define AXIS_EVENT_H -+ -+#include "input_event.h" -+#include "nocopyable.h" -+ -+namespace OHOS { -+namespace MMI { -+class AxisEvent : public InputEvent { -+public: -+ static constexpr int32_t AXIS_ACTION_UNKNOWN = 0; -+ static constexpr int32_t AXIS_ACTION_CANCEL = 1; -+ -+ static constexpr int32_t AXIS_ACTION_START = 2; -+ static constexpr int32_t AXIS_ACTION_UPDATE = 3; -+ static constexpr int32_t AXIS_ACTION_END = 4; -+ -+ static constexpr int32_t AXIS_TYPE_UNKNOWN = 0; -+ -+public: -+ static std::shared_ptr from(std::shared_ptr inputEvent); -+ static std::shared_ptr Create(); -+ -+public: -+ DISALLOW_COPY_AND_MOVE(AxisEvent); -+ virtual ~AxisEvent(); -+ -+ int32_t GetAxisAction(); -+ void SetAxisAction(int32_t axisAction); -+ -+ int32_t GetAxisType() const; -+ void SetAxisType(int32_t axisType); -+ -+ int32_t GetAxisValue() const; -+ void SetAxisValue(int32_t axisValue); -+ -+protected: -+ explicit AxisEvent(int32_t eventType); -+}; -+} // namespace MMI -+} // namespace OHOS -+#endif // AXIS_EVENT_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/multimodalinput/i_input_event_consumer.h b/ohos_ndk_aosp/includes/multimodalinput/i_input_event_consumer.h -new file mode 100755 -index 0000000000..61c4cc5f14 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/multimodalinput/i_input_event_consumer.h -@@ -0,0 +1,39 @@ -+/* -+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef I_INPUT_EVENT_CONSUMER_H -+#define I_INPUT_EVENT_CONSUMER_H -+ -+#include -+ -+#include "key_event.h" -+#include "pointer_event.h" -+#include "axis_event.h" -+ -+namespace OHOS { -+namespace MMI { -+struct IInputEventConsumer { -+public: -+ IInputEventConsumer() = default; -+ virtual ~IInputEventConsumer() = default; -+ -+ virtual void OnInputEvent(std::shared_ptr keyEvent) const; -+ virtual void OnInputEvent(std::shared_ptr pointerEvent) const; -+ virtual void OnInputEvent(std::shared_ptr axisEvent) const; -+}; -+} // namespace MMI -+} // namespace OHOS -+ -+#endif // I_INPUT_EVENT_CONSUMER_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/multimodalinput/i_input_event_handler.h b/ohos_ndk_aosp/includes/multimodalinput/i_input_event_handler.h -new file mode 100755 -index 0000000000..12829453b0 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/multimodalinput/i_input_event_handler.h -@@ -0,0 +1,35 @@ -+/* -+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef I_INPUT_EVENT_HANDLER_H -+#define I_INPUT_EVENT_HANDLER_H -+ -+#include -+#include "key_event.h" -+#include "pointer_event.h" -+#include "uds_session.h" -+ -+namespace OHOS { -+namespace MMI { -+struct IInputEventHandler { -+ static constexpr int32_t DEFAULT_INTERCEPTOR = 10; -+ static constexpr int32_t DEFAULT_MONITOR = 20; -+ virtual int32_t GetPriority() const = 0; -+ virtual bool HandleEvent(std::shared_ptr KeyEvent) = 0; -+ virtual bool HandleEvent(std::shared_ptr PointerEvent) = 0; -+}; -+} // namespace MMI -+} // namespace OHOS -+#endif // I_INPUT_EVENT_HANDLER_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/multimodalinput/if_mmi_client.h b/ohos_ndk_aosp/includes/multimodalinput/if_mmi_client.h -new file mode 100755 -index 0000000000..eea97feb7d ---- /dev/null -+++ b/ohos_ndk_aosp/includes/multimodalinput/if_mmi_client.h -@@ -0,0 +1,37 @@ -+/* -+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+#ifndef IF_MMI_CLIENT_H -+#define IF_MMI_CLIENT_H -+#include -+#include -+#include "if_client_msg_handler.h" -+ -+namespace OHOS { -+namespace MMI { -+class NetPacket; -+class IfMMIClient; -+typedef std::function ConnectCallback; -+class IfMMIClient { -+public: -+ virtual bool GetCurrentConnectedStatus() const = 0; -+ virtual bool Start(IClientMsgHandlerPtr msgHdl, bool detachMode) = 0; -+ virtual bool SendMessage(const NetPacket& pkt) const = 0; -+ virtual void RegisterConnectedFunction(ConnectCallback fun) = 0; -+ virtual void RegisterDisconnectedFunction(ConnectCallback fun) = 0; -+}; -+using MMIClientPtr = std::shared_ptr; -+} // namespace MMI -+} // namespace OHOS -+#endif // IF_MMI_CLIENT_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/multimodalinput/input_event.h b/ohos_ndk_aosp/includes/multimodalinput/input_event.h -new file mode 100755 -index 0000000000..e9c15e12f3 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/multimodalinput/input_event.h -@@ -0,0 +1,167 @@ -+/* -+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef INPUT_EVENT_H -+#define INPUT_EVENT_H -+ -+#include -+#include -+#include -+#include "nocopyable.h" -+#include "parcel.h" -+ -+namespace OHOS { -+namespace MMI { -+class InputEvent { -+public: -+ // Unknown action. Usually used to indicate the initial value of the input event action -+ static constexpr int32_t ACTION_UNKNOWN = 0; -+ // Cancel the action. Used to indicate that a continuous input event is cancelled -+ static constexpr int32_t ACTION_CANCEL = 1; -+ -+ // The actual type of the current input event is the basic type (InputEvent type) -+ static constexpr int32_t EVENT_TYPE_BASE = 0X00000000; -+ // The actual type of the current input event is the KeyEvent type or its derived class -+ static constexpr int32_t EVENT_TYPE_KEY = 0X00010000; -+ // The actual type of the current input event is the PointerEvent type or its derived class -+ static constexpr int32_t EVENT_TYPE_POINTER = 0X00020000; -+ // The actual type of the current input event is the AxisEvent type or its derived class -+ static constexpr int32_t EVENT_TYPE_AXIS = 0X00030000; -+ -+ static constexpr uint32_t EVENT_FLAG_NONE = 0x00000000; -+ static constexpr uint32_t EVENT_FLAG_NO_INTERCEPT = 0x00000001; -+ static constexpr uint32_t EVENT_FLAG_NO_MONITOR = 0x00000002; -+ -+ static constexpr int32_t DEFALUTID = -1; -+ -+public: -+ InputEvent(const InputEvent& other); -+ virtual ~InputEvent(); -+ virtual InputEvent& operator=(const InputEvent& other) = delete; -+ DISALLOW_MOVE(InputEvent); -+ static std::shared_ptr Create(); -+ -+ void Reset(); -+ /* -+ * Get or set the unique identifier of the input event, -+ * which is globally unique after being processed by the input service -+ * Under normal circumstances, do not need to set -+ */ -+ int32_t GetId() const; -+ void SetId(int32_t id); -+ -+ /* * -+ * Get or set the time when the current action occurred. -+ * The default value is the object creation time -+ * Under normal circumstances, do not need to set -+ */ -+ int64_t GetActionTime() const; -+ void SetActionTime(int64_t actionTime); -+ -+ /* -+ * Get or set the current action -+ */ -+ int32_t GetAction() const; -+ void SetAction(int32_t action); -+ -+ /* -+ * Action start time. -+ * For instantaneous actions, it is consistent with the time when the action occurred. -+ * For continuous actions, it indicates the start time of the continuous action -+ */ -+ int64_t GetActionStartTime() const; -+ void SetActionStartTime(int64_t time); -+ -+ /* -+ * Get or set the unique identifier of the input device that reports the input event -+ * The default value is 0, which means that the non-real device reports -+ */ -+ int32_t GetDeviceId() const; -+ void SetDeviceId(int32_t deviceId); -+ -+ /* -+ * Gets or sets the target display ID of the input event. -+ * The default is -1, which means that it is dynamically determined by the input service -+ */ -+ int32_t GetTargetDisplayId() const; -+ void SetTargetDisplayId(int32_t displayId); -+ -+ /* -+ * Gets or sets the description window id of the input event. -+ * The default value is -1, and the target window is determined by the input service. -+ */ -+ int32_t GetTargetWindowId() const; -+ void SetTargetWindowId(int32_t windowId); -+ -+ /* -+ * Gets or sets the id of the input event agent window. -+ * The input event originally sent to the target window will be sent to the proxy window. -+ * The default value is -1. Indicates determined by the input service. External users should not set this value. -+ */ -+ int32_t GetAgentWindowId() const; -+ void SetAgentWindowId(int32_t windowId); -+ -+ /* -+ * The actual type of the current input event. -+ * Valid values are EVENT_TYPE_BASE, EVENT_TYPE_KEY, EVENT_TYPE_POINTER, EVENT_TYPE_AXIS -+ */ -+ int32_t GetEventType() const; -+ const char* DumpEventType() const; -+ -+ uint32_t GetFlag() const; -+ -+ bool HasFlag(uint32_t flag); -+ -+ void AddFlag(uint32_t flag); -+ -+ void ClearFlag(); -+ -+ void UpdateId(); -+ -+ /* -+ * Mark input event processing completed. -+ * This method can only be called once. -+ */ -+ void MarkProcessed(); -+ -+ /* -+ * Set the callback function when the input event is processed. -+ * External users should not call this interface -+ */ -+ void SetProcessedCallback(std::function callback); -+ -+public: -+ bool WriteToParcel(Parcel &out) const; -+ bool ReadFromParcel(Parcel &in); -+ -+protected: -+ explicit InputEvent(int32_t eventType); -+ -+protected: -+ int32_t eventType_; -+ int32_t id_; -+ int64_t actionTime_; -+ int32_t action_; -+ int64_t actionStartTime_; -+ int32_t deviceId_; -+ int32_t targetDisplayId_; -+ int32_t targetWindowId_; -+ int32_t agentWindowId_; -+ uint32_t bitwise_; -+ std::function processedCallback_; -+}; -+} // namespace MMI -+} // namespace OHOS -+#endif // INPUT_EVENT_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/multimodalinput/input_handler_type.h b/ohos_ndk_aosp/includes/multimodalinput/input_handler_type.h -new file mode 100755 -index 0000000000..75fccc2e66 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/multimodalinput/input_handler_type.h -@@ -0,0 +1,48 @@ -+/* -+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef INPUT_HANDLER_TYPE_H -+#define INPUT_HANDLER_TYPE_H -+#include -+ -+namespace OHOS { -+namespace MMI { -+namespace { -+ constexpr size_t MAX_N_INPUT_HANDLERS { 16 }; -+ constexpr size_t MAX_N_INPUT_MONITORS { MAX_N_INPUT_HANDLERS }; -+ constexpr size_t MAX_N_INPUT_INTERCEPTORS { MAX_N_INPUT_HANDLERS }; -+ constexpr int32_t MIN_HANDLER_ID { 1 }; -+ constexpr int32_t INVALID_HANDLER_ID { -1 }; -+} -+ -+enum InputHandlerType : int32_t { -+ NONE, -+ INTERCEPTOR, -+ MONITOR, -+}; -+ -+inline bool IsValidHandlerType(InputHandlerType handlerType) -+{ -+ return ((handlerType == InputHandlerType::INTERCEPTOR) || -+ (handlerType == InputHandlerType::MONITOR)); -+} -+ -+inline bool IsValidHandlerId(int32_t handlerId) -+{ -+ return ((handlerId >= MIN_HANDLER_ID) && (handlerId < std::numeric_limits::max())); -+} -+} // namespace MMI -+} // namespace OHOS -+#endif // INPUT_HANDLER_TYPE_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/multimodalinput/key_event.h b/ohos_ndk_aosp/includes/multimodalinput/key_event.h -new file mode 100755 -index 0000000000..ff70c81a2d ---- /dev/null -+++ b/ohos_ndk_aosp/includes/multimodalinput/key_event.h -@@ -0,0 +1,1518 @@ -+/* -+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+#ifndef KEY_EVENT_H -+#define KEY_EVENT_H -+#include -+#include -+#include "nocopyable.h" -+#include "parcel.h" -+#include "input_event.h" -+ -+namespace OHOS { -+namespace MMI { -+class KeyEvent : public InputEvent { -+public: -+ // KEYCODE -+ static const int32_t KEYCODE_FN; -+ /* * -+ * Keycode constant: unknown keycode -+ *

The keycode is unknown. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_UNKNOWN; -+ -+ /* * -+ * Keycode constant: Home key -+ *

This key is processed by the framework and will never be sent to the application. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_HOME; -+ -+ /* * -+ * Keycode constant: Back key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_BACK; -+ -+ /* * -+ * Keycode constant: Call key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_CALL; -+ -+ /* * -+ * Keycode constant: End Call key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_ENDCALL; -+ -+ /* * -+ * Keycode constant: Clear key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_CLEAR; -+ -+ /* * -+ * Keycode constant: Headset Hook key -+ *

The key is used to end a call and stop media. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_HEADSETHOOK; -+ -+ /* * -+ * Keycode constant: Camera Focus key -+ *

This key is used to enable focus for the camera. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_FOCUS; -+ -+ /* * -+ * Keycode constant: Notification key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NOTIFICATION; -+ -+ /* * -+ * Keycode constant: Search key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_SEARCH; -+ -+ /* * -+ * Keycode constant: Play/Pause media key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_MEDIA_PLAY_PAUSE; -+ -+ /* * -+ * Keycode constant: Stop media key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_MEDIA_STOP; -+ -+ /* * -+ * Keycode constant: Play Next media key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_MEDIA_NEXT; -+ -+ /* * -+ * Keycode constant: Play Previous media key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_MEDIA_PREVIOUS; -+ -+ /* * -+ * Keycode constant: Rewind media key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_MEDIA_REWIND; -+ -+ /* * -+ * Keycode constant: Fast Forward media key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_MEDIA_FAST_FORWARD; -+ -+ /* * -+ * Turns up the volume. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_VOLUME_UP; -+ -+ /* * -+ * Turns down the volume. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_VOLUME_DOWN; -+ -+ /* * -+ * Presses the power button. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_POWER; -+ -+ /* * -+ * Presses the camera key. -+ *

It is used to start the camera or take photos. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_CAMERA; -+ -+ /* * -+ * Voice Assistant key -+ *

This key is used to wake up the voice assistant. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_VOICE_ASSISTANT; -+ -+ /* * -+ * Custom key 1 -+ *

The actions mapping to the custom keys are user-defined. Key values 521-529 are reserved for custom keys. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_CUSTOM1; -+ -+ static const int32_t KEYCODE_VOLUME_MUTE; -+ static const int32_t KEYCODE_MUTE; -+ -+ /* * -+ * Brightness UP key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_BRIGHTNESS_UP; -+ -+ /* * -+ * Brightness Down key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_BRIGHTNESS_DOWN; -+ -+ /* * -+ * Indicates general-purpose key 1 on the wearables -+ * -+ * @since 3 -+ */ -+ static const int32_t KEYCODE_WEAR_1; -+ -+ /* * -+ * Keycode constant: '0' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_0; -+ -+ /* * -+ * Keycode constant: '1' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_1; -+ -+ /* * -+ * Keycode constant: '2' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_2; -+ -+ /* * -+ * Keycode constant: '3' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_3; -+ -+ /* * -+ * Keycode constant: '4' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_4; -+ -+ /* * -+ * Keycode constant: '5' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_5; -+ -+ /* * -+ * Keycode constant: '6' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_6; -+ -+ /* * -+ * Keycode constant: '7' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_7; -+ -+ /* * -+ * Keycode constant: '8' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_8; -+ -+ /* * -+ * Keycode constant: '9' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_9; -+ -+ /* * -+ * Keycode constant: '*' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_STAR; -+ -+ /* * -+ * Keycode constant: '#' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_POUND; -+ -+ /* * -+ * Keycode constant: Directional Pad Up key -+ *

The key may also be synthesized from trackball motions. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_DPAD_UP; -+ -+ /* * -+ * Keycode constant: Directional Pad Down key -+ *

The key may also be synthesized from trackball motions. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_DPAD_DOWN; -+ -+ /* * -+ * Keycode constant: Directional Pad Left key -+ *

The key may also be synthesized from trackball motions. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_DPAD_LEFT; -+ -+ /* * -+ * Keycode constant: Directional Pad Right key -+ *

The key may also be synthesized from trackball motions. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_DPAD_RIGHT; -+ -+ /* * -+ * Keycode constant: Directional Pad Center key -+ *

The key may also be synthesized from trackball motions. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_DPAD_CENTER; -+ -+ /* * -+ * Keycode constant: 'A' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_A; -+ -+ /* * -+ * Keycode constant: 'B' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_B; -+ -+ /* * -+ * Keycode constant: 'C' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_C; -+ -+ /* * -+ * Keycode constant: 'D' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_D; -+ -+ /* * -+ * Keycode constant: 'E' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_E; -+ -+ /* * -+ * Keycode constant: 'F' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_F; -+ -+ /* * -+ * Keycode constant: 'G' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_G; -+ -+ /* * -+ * Keycode constant: 'H' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_H; -+ -+ /* * -+ * Keycode constant: 'I' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_I; -+ -+ /* * -+ * Keycode constant: 'J' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_J; -+ -+ /* * -+ * Keycode constant: 'K' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_K; -+ -+ /* * -+ * Keycode constant: 'L' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_L; -+ -+ /* * -+ * Keycode constant: 'M' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_M; -+ -+ /* * -+ * Keycode constant: 'N' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_N; -+ -+ /* * -+ * Keycode constant: 'O' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_O; -+ -+ /* * -+ * Keycode constant: 'P' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_P; -+ -+ /* * -+ * Keycode constant: 'Q' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_Q; -+ -+ /* * -+ * Keycode constant: 'R' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_R; -+ -+ /* * -+ * Keycode constant: 'S' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_S; -+ -+ /* * -+ * Keycode constant: 'T' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_T; -+ -+ /* * -+ * Keycode constant: 'U' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_U; -+ -+ /* * -+ * Keycode constant: 'V' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_V; -+ -+ /* * -+ * Keycode constant: 'W' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_W; -+ -+ /* * -+ * Keycode constant: 'X' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_X; -+ -+ /* * -+ * Keycode constant: 'Y' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_Y; -+ -+ /* * -+ * Keycode constant: 'Z' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_Z; -+ -+ /* * -+ * Keycode constant: ';' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_COMMA; -+ -+ /* * -+ * Keycode constant: '.' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_PERIOD; -+ -+ /* * -+ * Keycode constant: Left Alt modifier key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_ALT_LEFT; -+ -+ /* * -+ * Keycode constant: Right Alt modifier key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_ALT_RIGHT; -+ -+ /* * -+ * Keycode constant: Left Shift modifier key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_SHIFT_LEFT; -+ -+ /* * -+ * Keycode constant: Right Shift modifier key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_SHIFT_RIGHT; -+ -+ /* * -+ * Keycode constant: Tab key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_TAB; -+ -+ /* * -+ * Keycode constant: Space key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_SPACE; -+ -+ /* * -+ * Keycode constant: Symbol modifier key -+ *

The key is used to input alternate symbols. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_SYM; -+ -+ /* * -+ * Keycode constant: Explorer function key -+ *

This key is used to launch a browser application. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_EXPLORER; -+ -+ /* * -+ * Keycode constant: Email function key -+ *

This key is used to launch an email application. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_ENVELOPE; -+ -+ /* * -+ * Keycode constant: Enter key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_ENTER; -+ -+ /* * -+ * Keycode constant: Backspace key -+ *

Unlike {@link #static const int32_t KEYCODE_FORWARD_DEL}; this key is used to delete characters before the -+ * insertion point. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_DEL; -+ -+ /* * -+ * Keycode constant: '`' key (backtick key) -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_GRAVE; -+ -+ /* * -+ * Keycode constant: '-' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_MINUS; -+ -+ /* * -+ * Keycode constant: '=' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_EQUALS; -+ -+ /* * -+ * Keycode constant: '[' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_LEFT_BRACKET; -+ -+ /* * -+ * Keycode constant: ']' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_RIGHT_BRACKET; -+ -+ /* * -+ * Keycode constant: '\' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_BACKSLASH; -+ -+ /* * -+ * Keycode constant: ';' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_SEMICOLON; -+ -+ /* * -+ * Keycode constant: ''' key (apostrophe key) -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_APOSTROPHE; -+ -+ /* * -+ * Keycode constant: '/' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_SLASH; -+ -+ /* * -+ * Keycode constant: '{@literal @}' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_AT; -+ -+ /* * -+ * Keycode constant: '+' key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_PLUS; -+ -+ /* * -+ * Keycode constant: Menu key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_MENU; -+ -+ /* * -+ * Keycode constant: Page Up key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_PAGE_UP; -+ -+ /* * -+ * Keycode constant: Page Down key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_PAGE_DOWN; -+ -+ /* * -+ * Keycode constant: Escape key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_ESCAPE; -+ -+ /* * -+ * Keycode constant: Forward Delete key -+ *

Unlike {@link #static const int32_t KEYCODE_DEL}; this key is used to delete characters ahead of the insertion -+ * point. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_FORWARD_DEL; -+ -+ /* * -+ * Keycode constant: Left Control modifier key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_CTRL_LEFT; -+ -+ /* * -+ * Keycode constant: Right Control modifier key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_CTRL_RIGHT; -+ -+ /* * -+ * Keycode constant: Caps Lock key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_CAPS_LOCK; -+ -+ /* * -+ * Keycode constant: Scroll Lock key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_SCROLL_LOCK; -+ -+ /* * -+ * Keycode constant: Left Meta modifier key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_META_LEFT; -+ -+ /* * -+ * Keycode constant: Right Meta modifier key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_META_RIGHT; -+ -+ /* * -+ * Keycode constant: Function modifier key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_FUNCTION; -+ -+ /* * -+ * Keycode constant: System Request/Print Screen key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_SYSRQ; -+ -+ /* * -+ * Keycode constant: Break/Pause key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_BREAK; -+ -+ /* * -+ * Keycode constant: Home Movement key -+ *

This key is used to scroll or move the cursor around to the start of a line or to the -+ * top of a list. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_MOVE_HOME; -+ -+ /* * -+ * Keycode constant: End Movement key -+ *

This key is used to scroll or move the cursor around to the end of a line or to the -+ * bottom of a list. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_MOVE_END; -+ -+ /* * -+ * Keycode constant: Insert key -+ *

This key is used to toggle the insert or overwrite edit mode. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_INSERT; -+ -+ /* * -+ * Keycode constant: Forward key -+ *

This key is used to navigate forward in the history stack. It is a complement of -+ * {@link #static const int32_t KEYCODE_BACK}. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_FORWARD; -+ -+ /* * -+ * Keycode constant: Play media key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_MEDIA_PLAY; -+ -+ /* * -+ * Keycode constant: Pause media key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_MEDIA_PAUSE; -+ -+ /* * -+ * Keycode constant: Close media key -+ *

This key can be used to close a CD tray; for example. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_MEDIA_CLOSE; -+ -+ /* * -+ * Keycode constant: Eject media key -+ *

This key can be used to eject a CD tray; for example. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_MEDIA_EJECT; -+ -+ /* * -+ * Keycode constant: Record media key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_MEDIA_RECORD; -+ -+ /* * -+ * Keycode constant: F1 key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_F1; -+ -+ /* * -+ * Keycode constant: F2 key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_F2; -+ -+ /* * -+ * Keycode constant: F3 key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_F3; -+ -+ /* * -+ * Keycode constant: F4 key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_F4; -+ -+ /* * -+ * Keycode constant: F5 key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_F5; -+ -+ /* * -+ * Keycode constant: F6 key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_F6; -+ -+ /* * -+ * Keycode constant: F7 key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_F7; -+ -+ /* * -+ * Keycode constant: F8 key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_F8; -+ -+ /* * -+ * Keycode constant: F9 key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_F9; -+ -+ /* * -+ * Keycode constant: F10 key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_F10; -+ -+ /* * -+ * Keycode constant: F11 key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_F11; -+ -+ /* * -+ * Keycode constant: F12 key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_F12; -+ -+ /* * -+ * Keycode constant: Num Lock key -+ *

This key is used to alter the behavior of other keys on the numeric keypad. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUM_LOCK; -+ -+ /* * -+ * Keycode constant: '0' key on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_0; -+ -+ /* * -+ * Keycode constant: '1' key on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_1; -+ -+ /* * -+ * Keycode constant: '2' key on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_2; -+ -+ /* * -+ * Keycode constant: '3' key on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_3; -+ -+ /* * -+ * Keycode constant: '4' key on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_4; -+ -+ /* * -+ * Keycode constant: '5' key on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_5; -+ -+ /* * -+ * Keycode constant: '6' key on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_6; -+ -+ /* * -+ * Keycode constant: '7' key on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_7; -+ -+ /* * -+ * Keycode constant: '8' key on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_8; -+ -+ /* * -+ * Keycode constant: '9' key on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_9; -+ -+ /* * -+ * Keycode constant: '/' key (for division) on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_DIVIDE; -+ -+ /* * -+ * Keycode constant: '*' key (for multiplication) on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_MULTIPLY; -+ -+ /* * -+ * Keycode constant: '-' key (for subtraction) on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_SUBTRACT; -+ -+ /* * -+ * Keycode constant: '+' key (for addition) on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_ADD; -+ -+ /* * -+ * Key code constant: '.' key (for decimals or digit grouping) on the -+ * numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_DOT; -+ -+ /* * -+ * Key code constant: ';' key (for decimals or digit grouping) on the -+ * numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_COMMA; -+ -+ /* * -+ * Keycode constant: Enter key on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_ENTER; -+ -+ /* * -+ * Keycode constant: '=' key on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_EQUALS; -+ -+ /* * -+ * Keycode constant: '(' key on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_LEFT_PAREN; -+ -+ /* * -+ * Keycode constant: ')' key on the numeric keypad -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_NUMPAD_RIGHT_PAREN; -+ -+ /* * -+ * Key code: The virtual multitask key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_VIRTUAL_MULTITASK; -+ -+ /* * -+ * Key code: The handle button key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_BUTTON_A; -+ static const int32_t KEYCODE_BUTTON_B; -+ static const int32_t KEYCODE_BUTTON_C; -+ static const int32_t KEYCODE_BUTTON_X; -+ static const int32_t KEYCODE_BUTTON_Y; -+ static const int32_t KEYCODE_BUTTON_Z; -+ static const int32_t KEYCODE_BUTTON_L1; -+ static const int32_t KEYCODE_BUTTON_R1; -+ static const int32_t KEYCODE_BUTTON_L2; -+ static const int32_t KEYCODE_BUTTON_R2; -+ static const int32_t KEYCODE_BUTTON_SELECT; -+ static const int32_t KEYCODE_BUTTON_START; -+ static const int32_t KEYCODE_BUTTON_MODE; -+ static const int32_t KEYCODE_BUTTON_THUMBL; -+ static const int32_t KEYCODE_BUTTON_THUMBR; -+ -+ /* * -+ * Key code: The joystick button key -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_BUTTON_TRIGGER; -+ static const int32_t KEYCODE_BUTTON_THUMB; -+ static const int32_t KEYCODE_BUTTON_THUMB2; -+ static const int32_t KEYCODE_BUTTON_TOP; -+ static const int32_t KEYCODE_BUTTON_TOP2; -+ static const int32_t KEYCODE_BUTTON_PINKIE; -+ static const int32_t KEYCODE_BUTTON_BASE1; -+ static const int32_t KEYCODE_BUTTON_BASE2; -+ static const int32_t KEYCODE_BUTTON_BASE3; -+ static const int32_t KEYCODE_BUTTON_BASE4; -+ static const int32_t KEYCODE_BUTTON_BASE5; -+ static const int32_t KEYCODE_BUTTON_BASE6; -+ static const int32_t KEYCODE_BUTTON_BASE7; -+ static const int32_t KEYCODE_BUTTON_BASE8; -+ static const int32_t KEYCODE_BUTTON_BASE9; -+ static const int32_t KEYCODE_BUTTON_DEAD; -+ -+ static const int32_t KEYCODE_SLEEP; -+ static const int32_t KEYCODE_ZENKAKU_HANKAKU; -+ static const int32_t KEYCODE_102ND; -+ static const int32_t KEYCODE_RO; -+ static const int32_t KEYCODE_KATAKANA; -+ static const int32_t KEYCODE_HIRAGANA; -+ static const int32_t KEYCODE_HENKAN; -+ static const int32_t KEYCODE_KATAKANA_HIRAGANA; -+ static const int32_t KEYCODE_MUHENKAN; -+ static const int32_t KEYCODE_LINEFEED; -+ static const int32_t KEYCODE_MACRO; -+ static const int32_t KEYCODE_NUMPAD_PLUSMINUS; -+ static const int32_t KEYCODE_SCALE; -+ static const int32_t KEYCODE_HANGUEL; -+ static const int32_t KEYCODE_HANJA; -+ static const int32_t KEYCODE_YEN; -+ static const int32_t KEYCODE_STOP; -+ static const int32_t KEYCODE_AGAIN; -+ static const int32_t KEYCODE_PROPS; -+ static const int32_t KEYCODE_UNDO; -+ static const int32_t KEYCODE_COPY; -+ static const int32_t KEYCODE_OPEN; -+ static const int32_t KEYCODE_PASTE; -+ static const int32_t KEYCODE_FIND; -+ static const int32_t KEYCODE_CUT; -+ static const int32_t KEYCODE_HELP; -+ static const int32_t KEYCODE_CALC; -+ static const int32_t KEYCODE_FILE; -+ static const int32_t KEYCODE_BOOKMARKS; -+ static const int32_t KEYCODE_NEXT; -+ static const int32_t KEYCODE_PLAYPAUSE; -+ static const int32_t KEYCODE_PREVIOUS; -+ static const int32_t KEYCODE_STOPCD; -+ static const int32_t KEYCODE_CONFIG; -+ static const int32_t KEYCODE_REFRESH; -+ static const int32_t KEYCODE_EXIT; -+ static const int32_t KEYCODE_EDIT; -+ static const int32_t KEYCODE_SCROLLUP; -+ static const int32_t KEYCODE_SCROLLDOWN; -+ static const int32_t KEYCODE_NEW; -+ static const int32_t KEYCODE_REDO; -+ static const int32_t KEYCODE_CLOSE; -+ static const int32_t KEYCODE_PLAY; -+ static const int32_t KEYCODE_BASSBOOST; -+ static const int32_t KEYCODE_PRINT; -+ static const int32_t KEYCODE_CHAT; -+ static const int32_t KEYCODE_FINANCE; -+ static const int32_t KEYCODE_CANCEL; -+ static const int32_t KEYCODE_KBDILLUM_TOGGLE; -+ static const int32_t KEYCODE_KBDILLUM_DOWN; -+ static const int32_t KEYCODE_KBDILLUM_UP; -+ static const int32_t KEYCODE_SEND; -+ static const int32_t KEYCODE_REPLY; -+ static const int32_t KEYCODE_FORWARDMAIL; -+ static const int32_t KEYCODE_SAVE; -+ static const int32_t KEYCODE_DOCUMENTS; -+ static const int32_t KEYCODE_VIDEO_NEXT; -+ static const int32_t KEYCODE_VIDEO_PREV; -+ static const int32_t KEYCODE_BRIGHTNESS_CYCLE; -+ static const int32_t KEYCODE_BRIGHTNESS_ZERO; -+ static const int32_t KEYCODE_DISPLAY_OFF; -+ static const int32_t KEYCODE_BTN_MISC; -+ static const int32_t KEYCODE_GOTO; -+ static const int32_t KEYCODE_INFO; -+ static const int32_t KEYCODE_PROGRAM; -+ static const int32_t KEYCODE_PVR; -+ static const int32_t KEYCODE_SUBTITLE; -+ static const int32_t KEYCODE_FULL_SCREEN; -+ static const int32_t KEYCODE_KEYBOARD; -+ static const int32_t KEYCODE_ASPECT_RATIO; -+ static const int32_t KEYCODE_PC; -+ static const int32_t KEYCODE_TV; -+ static const int32_t KEYCODE_TV2; -+ static const int32_t KEYCODE_VCR; -+ static const int32_t KEYCODE_VCR2; -+ static const int32_t KEYCODE_SAT; -+ static const int32_t KEYCODE_CD; -+ static const int32_t KEYCODE_TAPE; -+ static const int32_t KEYCODE_TUNER; -+ static const int32_t KEYCODE_PLAYER; -+ static const int32_t KEYCODE_DVD; -+ static const int32_t KEYCODE_AUDIO; -+ static const int32_t KEYCODE_VIDEO; -+ static const int32_t KEYCODE_MEMO; -+ static const int32_t KEYCODE_CALENDAR; -+ static const int32_t KEYCODE_RED; -+ static const int32_t KEYCODE_GREEN; -+ static const int32_t KEYCODE_YELLOW; -+ static const int32_t KEYCODE_BLUE; -+ static const int32_t KEYCODE_CHANNELUP; -+ static const int32_t KEYCODE_CHANNELDOWN; -+ static const int32_t KEYCODE_LAST; -+ static const int32_t KEYCODE_RESTART; -+ static const int32_t KEYCODE_SLOW; -+ static const int32_t KEYCODE_SHUFFLE; -+ static const int32_t KEYCODE_VIDEOPHONE; -+ static const int32_t KEYCODE_GAMES; -+ static const int32_t KEYCODE_ZOOMIN; -+ static const int32_t KEYCODE_ZOOMOUT; -+ static const int32_t KEYCODE_ZOOMRESET; -+ static const int32_t KEYCODE_WORDPROCESSOR; -+ static const int32_t KEYCODE_EDITOR; -+ static const int32_t KEYCODE_SPREADSHEET; -+ static const int32_t KEYCODE_GRAPHICSEDITOR; -+ static const int32_t KEYCODE_PRESENTATION; -+ static const int32_t KEYCODE_DATABASE; -+ static const int32_t KEYCODE_NEWS; -+ static const int32_t KEYCODE_VOICEMAIL; -+ static const int32_t KEYCODE_ADDRESSBOOK; -+ static const int32_t KEYCODE_MESSENGER; -+ static const int32_t KEYCODE_BRIGHTNESS_TOGGLE; -+ static const int32_t KEYCODE_SPELLCHECK; -+ static const int32_t KEYCODE_COFFEE; -+ static const int32_t KEYCODE_MEDIA_REPEAT; -+ static const int32_t KEYCODE_IMAGES; -+ static const int32_t KEYCODE_BUTTONCONFIG; -+ static const int32_t KEYCODE_TASKMANAGER; -+ static const int32_t KEYCODE_JOURNAL; -+ static const int32_t KEYCODE_CONTROLPANEL; -+ static const int32_t KEYCODE_APPSELECT; -+ static const int32_t KEYCODE_SCREENSAVER; -+ static const int32_t KEYCODE_ASSISTANT; -+ static const int32_t KEYCODE_KBD_LAYOUT_NEXT; -+ static const int32_t KEYCODE_BRIGHTNESS_MIN; -+ static const int32_t KEYCODE_BRIGHTNESS_MAX; -+ static const int32_t KEYCODE_KBDINPUTASSIST_PREV; -+ static const int32_t KEYCODE_KBDINPUTASSIST_NEXT; -+ static const int32_t KEYCODE_KBDINPUTASSIST_PREVGROUP; -+ static const int32_t KEYCODE_KBDINPUTASSIST_NEXTGROUP; -+ static const int32_t KEYCODE_KBDINPUTASSIST_ACCEPT; -+ static const int32_t KEYCODE_KBDINPUTASSIST_CANCEL; -+ -+ static const int32_t KEYCODE_FRONT; -+ static const int32_t KEYCODE_SETUP; -+ static const int32_t KEYCODE_WAKEUP; -+ static const int32_t KEYCODE_SENDFILE; -+ static const int32_t KEYCODE_DELETEFILE; -+ static const int32_t KEYCODE_XFER; -+ static const int32_t KEYCODE_PROG1; -+ static const int32_t KEYCODE_PROG2; -+ static const int32_t KEYCODE_MSDOS; -+ static const int32_t KEYCODE_SCREENLOCK; -+ static const int32_t KEYCODE_DIRECTION_ROTATE_DISPLAY; -+ static const int32_t KEYCODE_CYCLEWINDOWS; -+ static const int32_t KEYCODE_COMPUTER; -+ static const int32_t KEYCODE_EJECTCLOSECD; -+ static const int32_t KEYCODE_ISO; -+ static const int32_t KEYCODE_MOVE; -+ static const int32_t KEYCODE_F13; -+ static const int32_t KEYCODE_F14; -+ static const int32_t KEYCODE_F15; -+ static const int32_t KEYCODE_F16; -+ static const int32_t KEYCODE_F17; -+ static const int32_t KEYCODE_F18; -+ static const int32_t KEYCODE_F19; -+ static const int32_t KEYCODE_F20; -+ static const int32_t KEYCODE_F21; -+ static const int32_t KEYCODE_F22; -+ static const int32_t KEYCODE_F23; -+ static const int32_t KEYCODE_F24; -+ static const int32_t KEYCODE_PROG3; -+ static const int32_t KEYCODE_PROG4; -+ static const int32_t KEYCODE_DASHBOARD; -+ static const int32_t KEYCODE_SUSPEND; -+ static const int32_t KEYCODE_HP; -+ static const int32_t KEYCODE_SOUND; -+ static const int32_t KEYCODE_QUESTION; -+ static const int32_t KEYCODE_CONNECT; -+ static const int32_t KEYCODE_SPORT; -+ static const int32_t KEYCODE_SHOP; -+ static const int32_t KEYCODE_ALTERASE; -+ static const int32_t KEYCODE_SWITCHVIDEOMODE; -+ static const int32_t KEYCODE_BATTERY; -+ static const int32_t KEYCODE_BLUETOOTH; -+ static const int32_t KEYCODE_WLAN; -+ static const int32_t KEYCODE_UWB; -+ static const int32_t KEYCODE_WWAN_WIMAX; -+ static const int32_t KEYCODE_RFKILL; -+ -+ static const int32_t KEYCODE_CHANNEL; -+ static const int32_t KEYCODE_BTN_0; -+ static const int32_t KEYCODE_BTN_1; -+ static const int32_t KEYCODE_BTN_2; -+ static const int32_t KEYCODE_BTN_3; -+ static const int32_t KEYCODE_BTN_4; -+ static const int32_t KEYCODE_BTN_5; -+ static const int32_t KEYCODE_BTN_6; -+ static const int32_t KEYCODE_BTN_7; -+ static const int32_t KEYCODE_BTN_8; -+ static const int32_t KEYCODE_BTN_9; -+ -+ static const int32_t KEYCODE_BRL_DOT1; -+ static const int32_t KEYCODE_BRL_DOT2; -+ static const int32_t KEYCODE_BRL_DOT3; -+ static const int32_t KEYCODE_BRL_DOT4; -+ static const int32_t KEYCODE_BRL_DOT5; -+ static const int32_t KEYCODE_BRL_DOT6; -+ static const int32_t KEYCODE_BRL_DOT7; -+ static const int32_t KEYCODE_BRL_DOT8; -+ static const int32_t KEYCODE_BRL_DOT9; -+ static const int32_t KEYCODE_BRL_DOT10; -+ -+ /* * -+ * Left Knob roll-up -+ *

In contrast to {@link #static const int32_t KEYCODE_LEFT_KNOB_ROLL_DOWN}; it means rolling -+ * the left knob upwards. The knob functionis scenario-specific; for example; -+ * increasing the volume or air conditioner temperature. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_LEFT_KNOB_ROLL_UP; -+ /* * -+ * Left Knob roll-down -+ *

In contrast to {@link #static const int32_t KEYCODE_LEFT_KNOB_ROLL_UP}; -+ * it means rolling the left knob downwards. The knob function is -+ * scenario-specific; for example; reducing the volume or air -+ * conditioner temperature. -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_LEFT_KNOB_ROLL_DOWN; -+ -+ /* * -+ * Left Knob -+ *

Pressing the knob will activate its adjustment function. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_LEFT_KNOB; -+ /* * -+ * Right Knob roll-up -+ *

In contrast to {@link #static const int32_t KEYCODE_RIGHT_KNOB_ROLL_DOWN}; it means rolling -+ * the right knob upwards. The knobfunction is scenario-specific; for example; -+ * increasing the volume or air conditioner temperature. -+ * -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_RIGHT_KNOB_ROLL_UP; -+ /* * -+ * Right Knob roll-down -+ *

In contrast to {@link #static const int32_t KEYCODE_RIGHT_KNOB_ROLL_UP}; it means rolling -+ * the right knob downwards. The knobfunction is scenario-specific; -+ * for example; reducing the volume or air conditioner temperature. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_RIGHT_KNOB_ROLL_DOWN; -+ /* * -+ * Right Knob -+ *

Pressing the knob will activate its adjustment function. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_RIGHT_KNOB; -+ /* * -+ * Audio Source Switch button -+ *

Pressing this button will enable the audio source. Depending on the -+ * actual scenario; it may also indicate that the Bluetooth call control -+ * button is pressed. -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_VOICE_SOURCE_SWITCH; -+ /* * -+ * Menu key -+ *

Pressing this key will display the launcher page. -+ * -+ * @since 1 -+ */ -+ static const int32_t KEYCODE_LAUNCHER_MENU; -+ -+ // Unknown key action. Usually used to indicate the initial invalid value -+ static const int32_t KEY_ACTION_UNKNOWN; -+ // Indicates cancel action. -+ // When the button is pressed, and the lifting action cannot be reported normally, report the key event of this -+ // action -+ static const int32_t KEY_ACTION_CANCEL; -+ -+ // Indicates key press action -+ static const int32_t KEY_ACTION_DOWN; -+ // Indicates key release action -+ static const int32_t KEY_ACTION_UP; -+ -+public: -+ class KeyItem { -+ public: -+ KeyItem(); -+ virtual ~KeyItem(); -+ -+ // Get or set the key code. -+ // The key code is the number that identifies the key -+ int32_t GetKeyCode() const; -+ void SetKeyCode(int32_t keyCode); -+ -+ // Get or set the key press time -+ int64_t GetDownTime() const; -+ void SetDownTime(int64_t downTime); -+ -+ // Get or set the unique identifier of the device reporting this button. i -+ // The default value is 0, which means that the non-real device reports. -+ int32_t GetDeviceId() const; -+ void SetDeviceId(int32_t deviceId); -+ -+ // Gets or sets whether the key is currently pressed. -+ // The default value is true, which means it is in a pressed state. -+ bool IsPressed() const; -+ void SetPressed(bool pressed); -+ public: -+ bool WriteToParcel(Parcel &out) const; -+ bool ReadFromParcel(Parcel &in); -+ -+ private: -+ bool pressed_ = false; -+ int32_t deviceId_ = DEFALUTID; -+ int32_t keyCode_ = -1; -+ int64_t downTime_ = 0; -+ }; -+ -+public: -+ // Try to convert the InputEvent object into a KeyEvent object. -+ // Returning an empty smart pointer object indicates that the conversion failed -+ static std::shared_ptr from(std::shared_ptr inputEvent); -+ -+ static const char* ActionToString(int32_t action); -+ static const char* KeyCodeToString(int32_t keyCode); -+ static std::shared_ptr Clone(std::shared_ptr keyEvent); -+ -+public: -+ KeyEvent(const KeyEvent& other); -+ KeyEvent& operator=(const KeyEvent& other) = delete; -+ DISALLOW_MOVE(KeyEvent); -+ virtual ~KeyEvent(); -+ -+ static std::shared_ptr Create(); -+ // Get or change the key code of the device. -+ // Only one key will change in an event report -+ int32_t GetKeyCode() const; -+ void SetKeyCode(int32_t keyCode); -+ -+ // Get or set the key action. The default value is the state of the current key code. -+ int32_t GetKeyAction() const; -+ void SetKeyAction(int32_t keyAction); -+ -+ // Get the list of keys currently in the pressed state -+ std::vector GetPressedKeys() const; -+ void AddKeyItem(const KeyItem& keyItem); -+ std::vector GetKeyItems(); -+ void AddPressedKeyItems(const KeyItem& keyItem); -+ void RemoveReleasedKeyItems(const KeyItem& keyItem); -+ -+ const KeyItem* GetKeyItem() const; -+ const KeyItem* GetKeyItem(int32_t keyCode) const; -+ bool IsValid() const; -+public: -+ bool WriteToParcel(Parcel &out) const; -+ bool ReadFromParcel(Parcel &in); -+ -+protected: -+ explicit KeyEvent(int32_t eventType); -+ -+private: -+ bool IsValidKeyItem() const; -+ -+private: -+ int32_t keyCode_ = -1; -+ std::vector keys_; -+ int32_t keyAction_ = 0; -+}; -+} // namespace MMI -+} // namespace OHOS -+#endif // KEY_EVENT_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/multimodalinput/key_option.h b/ohos_ndk_aosp/includes/multimodalinput/key_option.h -new file mode 100755 -index 0000000000..6363ef9794 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/multimodalinput/key_option.h -@@ -0,0 +1,50 @@ -+/* -+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef KEY_OPTION_H -+#define KEY_OPTION_H -+ -+#include -+#include "nocopyable.h" -+ -+namespace OHOS { -+namespace MMI { -+class KeyOption { -+public: -+ KeyOption() = default; -+ DISALLOW_COPY_AND_MOVE(KeyOption); -+ -+public: -+ std::set GetPreKeys() const; -+ void SetPreKeys(const std::set& preKeys); -+ int32_t GetFinalKey() const; -+ void SetFinalKey(int32_t finalKey); -+ -+ bool IsFinalKeyDown() const; -+ void SetFinalKeyDown(bool pressed); -+ -+ int32_t GetFinalKeyDownDuration() const; -+ void SetFinalKeyDownDuration(int32_t duration); -+ -+private: -+ std::set preKeys_ {}; -+ int32_t finalKey_ { -1 }; -+ bool isFinalKeyDown_ { false }; -+ int32_t finalKeyDownDuration_ { 0 }; -+}; -+} // namespace MMI -+} // namespace OHOS -+ -+#endif // KEY_OPTION_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/multimodalinput/pointer_event.h b/ohos_ndk_aosp/includes/multimodalinput/pointer_event.h -new file mode 100755 -index 0000000000..b6e0235205 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/multimodalinput/pointer_event.h -@@ -0,0 +1,676 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef POINTER_EVENT_H -+#define POINTER_EVENT_H -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include "parcel.h" -+#include "input_event.h" -+#include "nocopyable.h" -+ -+namespace OHOS { -+namespace MMI { -+class PointerEvent : public InputEvent { -+public: -+ /** -+ * Indicates an unknown pointer action. It is usually used as initial value. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t POINTER_ACTION_UNKNOWN = 0; -+ -+ /** -+ * Indicates a pointer action that has been canceled. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t POINTER_ACTION_CANCEL = 1; -+ -+ /** -+ * Indicates a pointer action representing that a funger is pressed on a touchscreen or touchpad. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t POINTER_ACTION_DOWN = 2; -+ -+ /** -+ * Indicates a pointer action representing that a funger moves on a touchscreen or touchpad or a mouse pointer moves. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t POINTER_ACTION_MOVE = 3; -+ -+ /** -+ * Indicates a pointer action representing that a funger leaves the touchscreen or touchpad. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t POINTER_ACTION_UP = 4; -+ -+ /** -+ * Indicates the start action of the axis event related to the pointer. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t POINTER_ACTION_AXIS_BEGIN = 5; -+ -+ /** -+ * Indicates the update action of the axis event related to the pointer. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t POINTER_ACTION_AXIS_UPDATE = 6; -+ -+ /** -+ * Indicates the end action of the axis event related to the pointer. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t POINTER_ACTION_AXIS_END = 7; -+ -+ /** -+ * Indicates a pointer action representing that a button is pressed. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t POINTER_ACTION_BUTTON_DOWN = 8; -+ -+ /** -+ * Indicates a pointer action representing that a button is released. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t POINTER_ACTION_BUTTON_UP = 9; -+ -+ enum AxisType { -+ /** -+ * Indicates an unknown axis type. It is generally used as the initial value. -+ * -+ * @since 8 -+ */ -+ AXIS_TYPE_UNKNOWN, -+ -+ /** -+ * Indicates the vertical scroll axis. When you scrall the mouse wheel or make certain gestures on the touchpad, the status of the vertical scroll axis changes. -+ * -+ * @since 8 -+ */ -+ AXIS_TYPE_SCROLL_VERTICAL, -+ -+ /** -+ * Indicates the horizontal scroll axis. When you scrall the mouse wheel or make certain gestures on the touchpad, the status of the horizontal scroll axis changes. -+ * -+ * @since 8 -+ */ -+ AXIS_TYPE_SCROLL_HORIZONTAL, -+ -+ /** -+ * Indicates the pinch axis, which is used to describe a pinch gesture on the touchscreen or touchpad. -+ * -+ * @since 8 -+ */ -+ AXIS_TYPE_PINCH, -+ -+ /** -+ * Indicates the maximum number of defined axis types. -+ * -+ * @since 8 -+ */ -+ AXIS_TYPE_MAX -+ }; -+ -+ /** -+ * Indicates an unknown input source type. It is usually used as the initial value. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t SOURCE_TYPE_UNKNOWN = 0; -+ -+ /** -+ * Indicates that the input source generates events similar to mouse cursor movement, button press and release, and wheel scrolling. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t SOURCE_TYPE_MOUSE = 1; -+ -+ /** -+ * Indicates that the input source generates a touchscreen multi-touch event. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t SOURCE_TYPE_TOUCHSCREEN = 2; -+ -+ /** -+ * Indicates that the input source generates a touchpad multi-touch event. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t SOURCE_TYPE_TOUCHPAD = 3; -+ -+ /** -+ * Indicates an invalid button ID. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t BUTTON_NONE = -1; -+ -+ /** -+ * Indicates the left button on a mouse. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t MOUSE_BUTTON_LEFT = 0; -+ -+ /** -+ * Indicates the right button on a mouse. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t MOUSE_BUTTON_RIGHT = 1; -+ -+ /** -+ * Indicates the middle button on a mouse. -+ * -+ * @since 8 -+ */ -+ static constexpr int32_t MOUSE_BUTTON_MIDDLE = 2; -+ -+public: -+ static std::shared_ptr from(std::shared_ptr inputEvent); -+ -+public: -+ class PointerItem { -+ public: -+ PointerItem(); -+ ~PointerItem(); -+ -+ public: -+ /** -+ * @brief Obtains the ID of the pointer in this event. -+ * @return Returns the pointer ID. -+ * @since 8 -+ */ -+ int32_t GetPointerId() const; -+ -+ /** -+ * @brief Sets the ID of the pointer in this event. -+ * @param pointerId Indicates the pointer ID to set. -+ * @return void -+ * @since 8 -+ */ -+ void SetPointerId(int32_t pointerId); -+ -+ /** -+ * @brief Obtains the time when the pointer is pressed. -+ * @return Returns the time. -+ * @since 8 -+ */ -+ int64_t GetDownTime() const; -+ -+ /** -+ * @brief Sets the time when the pointer is pressed. -+ * @param downTime Indicates the time to set. -+ * @return void -+ * @since 8 -+ */ -+ void SetDownTime(int64_t downTime); -+ -+ /** -+ * @brief Checks whether the pointer is pressed. -+ * @return Returns true if the pointer is pressed; returns false otherwise. -+ * @since 8 -+ */ -+ bool IsPressed() const; -+ -+ /** -+ * @brief Sets whether to enable the pressed state for the pointer. -+ * @param pressed Specifies whether to set the pressed state for the pointer. The value true means to set the pressed state for the pointer, and the false means the opposite. -+ * @return void -+ * @since 8 -+ */ -+ void SetPressed(bool pressed); -+ -+ /** -+ * @brief Obtains the x coordinate relative to the upper left corner of the screen. -+ * For a touchpad input event, the value is the absolute x coordinate on the touchpad. For other pointer input events, the value is the x coordinate on the target screen. -+ * @return Returns the x coordinate. -+ * @since 8 -+ */ -+ int32_t GetGlobalX() const; -+ -+ /** -+ * @brief Sets the x coordinate relative to the upper left corner of the screen. -+ * @param globalX Indicates the x coordinate to set. -+ * @return void -+ * @since 8 -+ */ -+ void SetGlobalX(int32_t globalX); -+ -+ /** -+ * @brief Obtains the y coordinate relative to the upper left corner of the screen. -+ * For a touchpad input event, the value is the absolute y coordinate on the touchpad. For other pointer input events, the value is the y coordinate on the target screen. -+ * @return Returns the y coordinate. -+ * @since 8 -+ */ -+ int32_t GetGlobalY() const; -+ -+ /** -+ * @brief Sets the y coordinate relative to the upper left corner of the screen. -+ * @param globalY Indicates the y coordinate to set. -+ * @return void -+ * @since 8 -+ */ -+ void SetGlobalY(int32_t globalY); -+ -+ /** -+ * @brief Obtains the x coordinate of the active window. -+ * @return Returns the x coordinate. -+ * @since 8 -+ */ -+ int32_t GetLocalX() const; -+ -+ /** -+ * @brief Sets the x coordinate of the active window. -+ * @param x Indicates the x coordinate to set. -+ * @return void -+ * @since 8 -+ */ -+ void SetLocalX(int32_t x); -+ -+ /** -+ * @brief Obtains the y coordinate of the active window. -+ * @return Returns the y coordinate. -+ * @since 8 -+ */ -+ int32_t GetLocalY() const; -+ -+ /** -+ * @brief Sets the y coordinate of the active window. -+ * @param y Indicates the y coordinate to set. -+ * @return void -+ * @since 8 -+ */ -+ void SetLocalY(int32_t y); -+ -+ /** -+ * @brief Obtains the width of the pressed area. -+ * @return Returns the width. -+ * @since 8 -+ */ -+ int32_t GetWidth() const; -+ -+ /** -+ * @brief Sets the width of the pressed area. -+ * @param width Indicates the width to set. -+ * @return void -+ * @since 8 -+ */ -+ void SetWidth(int32_t width); -+ -+ /** -+ * @brief Obtains the height of the pressed area. -+ * @return Returns the height. -+ * @since 8 -+ */ -+ int32_t GetHeight() const; -+ -+ /** -+ * @brief Sets the height of the pressed area. -+ * @param height Indicates the height to set. -+ * @return void -+ * @since 8 -+ */ -+ void SetHeight(int32_t height); -+ -+ /** -+ * @brief Obtains the pressure in this event. -+ * @return Returns the pressure. -+ * @since 8 -+ */ -+ int32_t GetPressure() const; -+ -+ /** -+ * @brief Sets the pressure for this event. -+ * @param pressure Indicates the pressure to set. -+ * @return void -+ * @since 8 -+ */ -+ void SetPressure(int32_t pressure); -+ -+ /** -+ * @brief Obtains the ID of the current device. -+ * @return Returns the device ID. -+ * @since 8 -+ */ -+ int32_t GetDeviceId() const; -+ -+ /** -+ * @brief Sets the ID for the current device. -+ * @param deviceId Indicates the device ID to set. -+ * @return void -+ * @since 8 -+ */ -+ void SetDeviceId(int32_t deviceId); -+ public: -+ /** -+ * @brief Writes data to a Parcel obejct. -+ * @param out Indicates the object into which data will be written. -+ * @return Returns true if the data is successfully written; returns false otherwise. -+ * @since 8 -+ */ -+ bool WriteToParcel(Parcel &out) const; -+ -+ /** -+ * @brief Reads data from a Parcel obejct. -+ * @param in Indicates the object from which data will be read. -+ * @return Returns true if the data is successfully read; returns false otherwise. -+ * @since 8 -+ */ -+ bool ReadFromParcel(Parcel &in); -+ -+ private: -+ int32_t pointerId_ { 0 }; -+ bool pressed_ { false }; -+ int32_t globalX_ { 0 }; -+ int32_t globalY_ { 0 }; -+ int32_t localX_ { 0 }; -+ int32_t localY_ { 0 }; -+ int32_t width_ { 0 }; -+ int32_t height_ { 0 }; -+ int32_t pressure_ { 0 }; -+ int32_t deviceId_ { 0 }; -+ int64_t downTime_ { 0 }; -+ }; -+ -+public: -+ PointerEvent(const PointerEvent& other); -+ virtual ~PointerEvent(); -+ PointerEvent& operator=(const PointerEvent& other) = delete; -+ DISALLOW_MOVE(PointerEvent); -+ -+ static std::shared_ptr Create(); -+ -+ /** -+ * @brief Obtains the pointer action in this event. -+ * @return Returns the pointer action. -+ * @since 8 -+ */ -+ int32_t GetPointerAction() const; -+ -+ /** -+ * @brief Sets a pointer action for this event. -+ * @param pointerAction Indicates the pointer action to set. -+ * @return void -+ * @since 8 -+ */ -+ void SetPointerAction(int32_t pointerAction); -+ -+ /** -+ * @brief Dumps the action of this pointer input event as a string. -+ * @return Returns the pointer to the string. -+ * @since 8 -+ */ -+ const char* DumpPointerAction() const; -+ -+ /** -+ * @brief Obtains the pointer ID in this event. -+ * @return Returns the pointer ID. -+ * @since 8 -+ */ -+ int32_t GetPointerId() const; -+ -+ /** -+ * @brief Sets an ID for the pointer in this event. -+ * @param pointerId Indicates the pointer ID to set. -+ * @return void -+ * @since 8 -+ */ -+ void SetPointerId(int32_t pointerId); -+ -+ /** -+ * @brief Obtains the pointer item of a specified pointer ID. -+ * @param pointerId Indicates the pointer ID. -+ * @param pointerItem Indicates the item used to receive the data of the pointer. -+ * @return Returns true if the data of the pointer with the specified ID exists; returns false otherwise. -+ * @since 8 -+ */ -+ bool GetPointerItem(int32_t pointerId, PointerItem &pointerItem); -+ -+ /** -+ * @brief Adds a pointer item. -+ * @param pointerItem Indicates the pointer item to add. -+ * @return void -+ * @since 8 -+ */ -+ void AddPointerItem(PointerItem &pointerItem); -+ -+ /** -+ * @brief Removes a pointer item based on the pointer ID. -+ * @param pointerId Indicates the ID of the pointer from which the pointer item is to be removed. -+ * @return void -+ * @since 8 -+ */ -+ void RemovePointerItem(int32_t pointerId); -+ -+ /** -+ * @brief Updates a pointer item based on the pointer ID. -+ * @param pointerId Indicates the ID of the pointer from which the pointer item is to be updated. -+ * @param pointerItem Indicates the pointer item to update. -+ * @return void -+ * @since 8 -+ */ -+ void UpdatePointerItem(int32_t pointerId, PointerItem &pointerItem); -+ -+ /** -+ * @brief Obtains the set of pressed buttons. -+ * @return Returns the pressed buttons. -+ * @since 8 -+ */ -+ std::set GetPressedButtons() const; -+ -+ /** -+ * @brief Checks whether a specified button is being pressed. -+ * @param buttonId Indicates the button ID. -+ * @return Returns true if the button is being pressed; returns false otherwise. -+ * @since 8 -+ */ -+ bool IsButtonPressed(int32_t buttonId) const; -+ -+ /** -+ * @brief Sets the pressed state for a button. -+ * @param buttonId Indicates the button ID of the button to be set in the pressed state. -+ * @return void -+ * @since 8 -+ */ -+ void SetButtonPressed(int32_t buttonId); -+ -+ /** -+ * @brief Deletes a released button. -+ * @param buttonId Indicates the button ID of the button. -+ * @return void -+ * @since 8 -+ */ -+ void DeleteReleaseButton(int32_t buttonId); -+ -+ /** -+ * @brief Clears the button in the pressed state. -+ * @return void -+ * @since 8 -+ */ -+ void ClearButtonPressed(); -+ -+ /** -+ * @brief Obtains all pointers in this event. -+ * @return Returns all the pointer IDs. -+ * @since 8 -+ */ -+ std::vector GetPointersIdList() const; -+ -+ /** -+ * @brief Obtains the source type of this event. -+ * @return Returns the source type. -+ * @since 8 -+ */ -+ int32_t GetSourceType() const; -+ -+ /** -+ * @brief Sets the source type for this event. -+ * @param sourceType Indicates the source type to set. -+ * @return void -+ * @since 8 -+ */ -+ void SetSourceType(int32_t sourceType); -+ -+ /** -+ * @brief Dumps the source type of this pointer input event as a string. -+ * @return Returns the pointer to the string. -+ * @since 8 -+ */ -+ const char* DumpSourceType() const; -+ -+ /** -+ * @brief Obtains the button ID in this event. -+ * @return Returns the button ID. -+ * @since 8 -+ */ -+ int32_t GetButtonId() const; -+ -+ /** -+ * @brief Sets the button ID for this event. -+ * @param buttonId Indicates the button ID to set. -+ * @return void -+ * @since 8 -+ */ -+ void SetButtonId(int32_t buttonId); -+ -+ /** -+ * @brief Obtains the axis value. -+ * @param axis Indicates the axis type. -+ * @return Returns the axis value. -+ * @since 8 -+ */ -+ double GetAxisValue(AxisType axis) const; -+ -+ /** -+ * @brief Sets the axis value. -+ * @param axis Indicates the axis type. -+ * @param axisValue Indicates the axis value to set. -+ * @return void -+ * @since 8 -+ */ -+ void SetAxisValue(AxisType axis, double axisValue); -+ -+ /** -+ * @brief Checks whether this event contains a specified axis type. -+ * @param axis Indicates the axis type. -+ * @return Returns true if the event contains the specified axis type; returns false otherwise. -+ * @since 8 -+ */ -+ bool HasAxis(AxisType axis) const; -+ -+ /** -+ * @brief Obtains all axis of this event. -+ * @return Returns all the axis, Each bit indicates an axis. -+ * @since 8 -+ */ -+ int32_t GetAxes() const; -+ -+ /** -+ * @brief Set the front keys in the key combination. -+ * @param pressedKeys Indicates the front keys to set. -+ * @return void. -+ * @since 8 -+ */ -+ void SetPressedKeys(const std::vector pressedKeys); -+ -+ /** -+ * @brief Obtains the set of pressed keys. -+ * @return Returns the pressed keys. -+ * @since 8 -+ */ -+ std::vector GetPressedKeys() const; -+ -+ /** -+ * @brief Checks whether this input event is valid. -+ * @return Returns true if the input event is valid; returns false otherwise. -+ * @since 8 -+ */ -+ bool IsValid() const; -+public: -+ /** -+ * @brief Checks whether the axes set represented by axes contains a specified type of axis. -+ * @param axes Indicates the set of axes. Each bit indicates an axis. -+ * @param axis Indicates the type of the axis to check. -+ * @return Returns true if the axes set contains the specified axis type; returns false otherwise. -+ * @since 8 -+ */ -+ static bool HasAxis(int32_t axes, AxisType axis); -+ -+public: -+ /** -+ * @brief Writes data to a Parcel obejct. -+ * @param out Indicates the object into which data will be written. -+ * @return Returns true if the data is successfully written; returns false otherwise. -+ * @since 8 -+ */ -+ bool WriteToParcel(Parcel &out) const; -+ -+ /** -+ * @brief Reads data from a Parcel obejct. -+ * @param in Indicates the object from which data will be read. -+ * @return Returns true if the data is successfully read; returns false otherwise. -+ * @since 8 -+ */ -+ bool ReadFromParcel(Parcel &in); -+ -+protected: -+ explicit PointerEvent(int32_t eventType); -+ -+private: -+ bool IsValidCheckMouseFunc() const; -+ bool IsValidCheckMouse() const; -+ bool IsValidCheckTouchFunc() const; -+ bool IsValidCheckTouch() const; -+ -+private: -+ int32_t pointerId_ { 0 }; -+ std::list pointers_; -+ std::set pressedButtons_; -+ int32_t sourceType_ { 0 }; -+ int32_t pointerAction_ { 0 }; -+ int32_t buttonId_ { -1 }; -+ uint32_t axes_ { 0 }; -+ std::array axisValues_ { }; -+ std::vector pressedKeys_; -+}; -+ -+inline bool PointerEvent::HasAxis(AxisType axis) const -+{ -+ return HasAxis(axes_, axis); -+} -+ -+inline int32_t PointerEvent::GetAxes() const -+{ -+ return axes_; -+} -+} // namespace MMI -+} // namespace OHOS -+#endif // POINTER_EVENT_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/multimodalinput/standardized_event_manager.h b/ohos_ndk_aosp/includes/multimodalinput/standardized_event_manager.h -new file mode 100755 -index 0000000000..8667dcecbc ---- /dev/null -+++ b/ohos_ndk_aosp/includes/multimodalinput/standardized_event_manager.h -@@ -0,0 +1,53 @@ -+/* -+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+#ifndef STANDARDIZED_EVENT_MANAGER_H -+#define STANDARDIZED_EVENT_MANAGER_H -+ -+#include -+#include "if_mmi_client.h" -+#include "iremote_object.h" -+#include "key_event_input_subscribe_manager.h" -+#include "nocopyable.h" -+#include "pointer_event.h" -+#include "singleton.h" -+ -+namespace OHOS { -+namespace MMI { -+class NetPacket; -+class StandardizedEventManager { -+public: -+ StandardizedEventManager(); -+ ~StandardizedEventManager(); -+ DISALLOW_COPY_AND_MOVE(StandardizedEventManager); -+ -+ void SetClientHandle(MMIClientPtr client); -+ const std::set *GetRegisterEvent(); -+ int32_t InjectionVirtual(bool isPressed, int32_t keyCode, int64_t keyDownDuration, int32_t maxKeyCode); -+ int32_t InjectEvent(const std::shared_ptr keyEventPtr); -+ int32_t InjectPointerEvent(std::shared_ptr pointerEvent); -+ int32_t GetDevice(int32_t userData, int32_t deviceId); -+ int32_t GetDeviceIds(int32_t userData); -+ int32_t SubscribeKeyEvent(const KeyEventInputSubscribeManager::SubscribeKeyEventInfo& subscribeInfo); -+ int32_t UnSubscribeKeyEvent(int32_t subscribeId); -+protected: -+ bool SendMsg(NetPacket& pkt) const; -+ -+protected: -+ MMIClientPtr client_ = nullptr; -+}; -+} // namespace MMI -+} // namespace OHOS -+#define EventManager OHOS::Singleton::GetInstance() -+#endif // STANDARDIZED_EVENT_MANAGER_H -diff --git a/ohos_ndk_aosp/includes/peripheral/BUILD.gn b/ohos_ndk_aosp/includes/peripheral/BUILD.gn -new file mode 100644 -index 0000000000..fc840b4a75 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/peripheral/BUILD.gn -@@ -0,0 +1,22 @@ -+# Copyright (c) 2021 Huawei Device Co., Ltd. -+# Licensed under the Apache License, Version 2.0 (the "License"); -+# you may not use this file except in compliance with the License. -+# You may obtain a copy of the License at -+# -+# http://www.apache.org/licenses/LICENSE-2.0 -+# -+# Unless required by applicable law or agreed to in writing, software -+# distributed under the License is distributed on an "AS IS" BASIS, -+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+# See the License for the specific language governing permissions and -+# limitations under the License. -+ -+import("//build/ohos.gni") -+ -+ohos_prebuilt_etc("hdf_peripheral.rc") { -+ source = "hdf_peripheral.cfg" -+ relative_install_dir = "init" -+ install_images = [ chipset_base_dir ] -+ subsystem_name = "hdf" -+ part_name = "device_driver_framework" -+} -diff --git a/ohos_ndk_aosp/includes/peripheral/buffer_handle.h b/ohos_ndk_aosp/includes/peripheral/buffer_handle.h -new file mode 100644 -index 0000000000..6b352819a5 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/peripheral/buffer_handle.h -@@ -0,0 +1,45 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef INCLUDE_BUFFER_HANDLE_H -+#define INCLUDE_BUFFER_HANDLE_H -+ -+#include -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+typedef struct { -+ int32_t fd; /**< buffer fd, -1 if not supported */ -+ int32_t width; /**< the width of memory */ -+ int32_t stride; /**< the stride of memory */ -+ int32_t height; /**< the heigh of memory */ -+ int32_t size; /* < size of memory */ -+ int32_t format; /**< the format of memory */ -+ uint64_t usage; /**< the usage of memory */ -+ void *virAddr; /**< Virtual address of memory */ -+ uint64_t phyAddr; /**< Physical address */ -+ int32_t key; /**< Shared memory key */ -+ uint32_t reserveFds; /**< the number of reserved fd value */ -+ uint32_t reserveInts; /**< the number of reserved integer value */ -+ int32_t reserve[0]; /**< the data */ -+} BufferHandle; -+ -+#ifdef __cplusplus -+} -+#endif -+ -+#endif // INCLUDE_BUFFER_HANDLE_H -diff --git a/ohos_ndk_aosp/includes/peripheral/hdf_peripheral.cfg b/ohos_ndk_aosp/includes/peripheral/hdf_peripheral.cfg -new file mode 100644 -index 0000000000..9fb35c1878 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/peripheral/hdf_peripheral.cfg -@@ -0,0 +1,25 @@ -+{ -+ "jobs" : [{ -+ "name" : "post-fs-data", -+ "cmds" : [ -+ "chown system system /dev/dev_mgr", -+ "chown system system /dev/hdf_disp", -+ "chown system system /dev/hdf_input_host", -+ "chown system system /dev/hdf_input_event1", -+ "chown system system /dev/hdf_input_event2", -+ "chown system system /dev/hdf_input_event3", -+ "chown system system /dev/hdf_input_event4", -+ "chown system system /dev/hdf_input_event5", -+ "chown system system /dev/hdf_input_event6", -+ "chown system system /dev/hdf_sensor_manager_ap", -+ "chown system system /dev/hdf_misc_vibrator", -+ "chown system system /dev/hdf_audio_render", -+ "chown system system /dev/hdf_audio_capture", -+ "chown system system /dev/hdf_audio_control", -+ "chown system system /dev/hdf_audio_codec_dev0", -+ "chown system system /dev/hdf_audio_smartpa_dev0", -+ "chown system system /dev/hdf_dsoftbus" -+ ] -+ } -+ ] -+} -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/peripheral/hdf_peripheral.rc b/ohos_ndk_aosp/includes/peripheral/hdf_peripheral.rc -new file mode 100644 -index 0000000000..bf94724b17 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/peripheral/hdf_peripheral.rc -@@ -0,0 +1,30 @@ -+# Copyright (c) 2021 Huawei Device Co., Ltd. -+# Licensed under the Apache License, Version 2.0 (the "License"); -+# you may not use this file except in compliance with the License. -+# You may obtain a copy of the License at -+# -+# http://www.apache.org/licenses/LICENSE-2.0 -+# -+# Unless required by applicable law or agreed to in writing, software -+# distributed under the License is distributed on an "AS IS" BASIS, -+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+# See the License for the specific language governing permissions and -+# limitations under the License. -+ -+on post-fs-data -+ chown system system /dev/hdf_disp -+ chown system system /dev/hdf_input_host -+ chown system system /dev/hdf_input_event1 -+ chown system system /dev/hdf_input_event2 -+ chown system system /dev/hdf_input_event3 -+ chown system system /dev/hdf_input_event4 -+ chown system system /dev/hdf_input_event5 -+ chown system system /dev/hdf_input_event6 -+ chown system system /dev/hdf_audio_render -+ chown system system /dev/hdf_audio_capture -+ chown system system /dev/hdf_audio_control -+ chown system system /dev/hdf_audio_codec_dev0 -+ chown system system /dev/hdf_audio_smartpa_dev0 -+ chown system system /dev/hdf_sensor_manager_ap -+ chown system system /dev/hdf_misc_vibrator -+ chown system system /dev/dev_mgr -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/surface/buffer_extra_data.h b/ohos_ndk_aosp/includes/surface/buffer_extra_data.h -new file mode 100644 -index 0000000000..799df0cc65 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/surface/buffer_extra_data.h -@@ -0,0 +1,40 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef INTERFACES_INNERKITS_SURFACE_BUFFER_EXTRA_DATA_H -+#define INTERFACES_INNERKITS_SURFACE_BUFFER_EXTRA_DATA_H -+ -+#include -+ -+#include "surface_type.h" -+ -+namespace OHOS { -+class MessageParcel; -+class BufferExtraData { -+public: -+ virtual GSError ReadFromParcel(MessageParcel &parcel) = 0; -+ virtual GSError WriteToParcel(MessageParcel &parcel) = 0; -+ virtual GSError ExtraGet(std::string &key, int32_t &value) const = 0; -+ virtual GSError ExtraGet(std::string &key, int64_t &value) const = 0; -+ virtual GSError ExtraGet(std::string &key, double &value) const = 0; -+ virtual GSError ExtraGet(std::string &key, std::string &value) const = 0; -+ virtual GSError ExtraSet(std::string &key, int32_t value) = 0; -+ virtual GSError ExtraSet(std::string &key, int64_t value) = 0; -+ virtual GSError ExtraSet(std::string &key, double value) = 0; -+ virtual GSError ExtraSet(std::string &key, std::string value) = 0; -+}; -+} // namespace OHOS -+ -+#endif // INTERFACES_INNERKITS_SURFACE_BUFFER_EXTRA_DATA_H -diff --git a/ohos_ndk_aosp/includes/surface/egl_data.h b/ohos_ndk_aosp/includes/surface/egl_data.h -new file mode 100644 -index 0000000000..a5290e79f0 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/surface/egl_data.h -@@ -0,0 +1,31 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef INTERFACES_INNERKITS_SURFACE_EGL_DATA_H -+#define INTERFACES_INNERKITS_SURFACE_EGL_DATA_H -+ -+#include -+ -+namespace OHOS { -+class EglData : public RefBase { -+public: -+ virtual ~EglData() = default; -+ -+ virtual uint32_t GetFrameBufferObj() const = 0; -+ virtual uint32_t GetTexture() const = 0; -+}; -+} // namespace OHOS -+ -+#endif // INTERFACES_INNERKITS_SURFACE_EGL_DATA_H -diff --git a/ohos_ndk_aosp/includes/surface/egl_surface.h b/ohos_ndk_aosp/includes/surface/egl_surface.h -new file mode 100644 -index 0000000000..4bd8f9a18a ---- /dev/null -+++ b/ohos_ndk_aosp/includes/surface/egl_surface.h -@@ -0,0 +1,46 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef INTERFACES_INNERKITS_SURFACE_EGL_RENDER_SURFACE_H -+#define INTERFACES_INNERKITS_SURFACE_EGL_RENDER_SURFACE_H -+ -+#include -+ -+#include -+#include -+#include "ibuffer_producer.h" -+#include "surface_type.h" -+ -+namespace OHOS { -+class EglSurface : public RefBase { -+public: -+ static sptr CreateEglSurfaceAsProducer(sptr& producer); -+ virtual ~EglSurface() = default; -+ -+ virtual GSError InitContext(EGLContext context = EGL_NO_CONTEXT) = 0; -+ virtual EGLDisplay GetEglDisplay() const = 0; -+ virtual EGLContext GetEglContext() const = 0; -+ virtual EGLSurface GetEglSurface() const = 0; -+ virtual GLuint GetEglFbo() const = 0; -+ virtual GSError SwapBuffers() = 0; -+ virtual GSError SetWidthAndHeight(int32_t width, int32_t height) = 0; -+ -+protected: -+ EglSurface() = default; -+}; -+typedef EglSurface EglRenderSurface; -+} // namespace OHOS -+ -+#endif // INTERFACES_INNERKITS_SURFACE_EGL_RENDER_SURFACE_H -diff --git a/ohos_ndk_aosp/includes/surface/external_window.h b/ohos_ndk_aosp/includes/surface/external_window.h -new file mode 100644 -index 0000000000..82839cd153 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/surface/external_window.h -@@ -0,0 +1,189 @@ -+/* -+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef NDK_INCLUDE_EXTERNAL_NATIVE_WINDOW_H_ -+#define NDK_INCLUDE_EXTERNAL_NATIVE_WINDOW_H_ -+ -+/** -+ * @addtogroup NativeWindow -+ * @{ -+ * -+ * @brief Provides NativeWindow functions -+ * -+ * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow -+ * @since 8 -+ * @version 1.0 -+ */ -+ -+/** -+ * @file external_window.h -+ * -+ * @brief API for accessing a native window -+ * -+ * @since 8 -+ * @version 1.0 -+ */ -+ -+#include "window.h" -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+/** -+ * @brief Create a NativeWindow from producer surface, Each call will generates a new NativeWindow -+ * -+ * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow -+ * @param pSurface Indicates producer surface -+ * @return NativeWindow -+ * @since 8 -+ * @version 1.0 -+ */ -+struct NativeWindow* OH_NativeWindow_CreateNativeWindowFromSurface(void* pSurface); -+ -+/** -+ * @brief Unreference NativeWindow object, When the reference count == 0, destroy the NativeWindow -+ * -+ * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow -+ * @param window Indicates NativeWindow -+ * @since 8 -+ * @version 1.0 -+ */ -+void OH_NativeWindow_DestroyNativeWindow(struct NativeWindow* window); -+ -+/** -+ * @brief Create a NativeWindowBuffer from producer surface buffer -+ * -+ * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow -+ * @param pSurfaceBuffer Indicates producer surface buffer -+ * @return NativeWindowBuffer -+ * @since 8 -+ * @version 1.0 -+ */ -+struct NativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(void* pSurfaceBuffer); -+ -+/** -+ * @brief Unreference NativeWindowBuffer object, when the reference count == 0, destroy a NativeWindow buffer -+ * -+ * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow -+ * @param buffer Indicates NativeWindow buffer -+ * @since 8 -+ * @version 1.0 -+ */ -+void OH_NativeWindow_DestroyNativeWindowBuffer(struct NativeWindowBuffer* buffer); -+ -+/** -+ * @brief Dequeue a buffer from NativeWindow -+ * -+ * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow -+ * @param window Indicates NativeWindow -+ * @param buffer Indicates [out] get NativeWindowBuffer -+ * @param fenceFd Indicates [out] get release fence -+ * @return GSError -+ * @since 8 -+ * @version 1.0 -+ */ -+int32_t OH_NativeWindow_NativeWindowRequestBuffer(struct NativeWindow *window, -+ struct NativeWindowBuffer **buffer, int *fenceFd); -+ -+/** -+ * @brief Queue a buffer to NativeWindow -+ * -+ * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow -+ * @param window Indicates NativeWindow -+ * @param buffer Indicates NativeWindowBuffer -+ * @param fenceFd Indicates acquire fence -+ * @param region Indicates the Buffer dirty size -+ * @return GSError -+ * @since 8 -+ * @version 1.0 -+ */ -+int32_t OH_NativeWindow_NativeWindowFlushBuffer(struct NativeWindow *window, struct NativeWindowBuffer *buffer, -+ int fenceFd, Region region); -+ -+/** -+ * @brief Cancel the NativeWindowBuffer to be queued -+ * -+ * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow -+ * @param window Indicates NativeWindow -+ * @param buffer Indicates NativeWindowBuffer -+ * @return GSError -+ * @since 8 -+ * @version 1.0 -+ */ -+int32_t OH_NativeWindow_NativeWindowCancelBuffer(struct NativeWindow *window, struct NativeWindowBuffer *buffer); -+ -+/** -+ * @brief Handle the NativeWindowOperation of the NativeWindow -+ * -+ * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow -+ * @param window Indicates NativeWindow -+ * @param code Indicates NativeWindowOperation -+ * @return GSError -+ * @since 8 -+ * @version 1.0 -+ */ -+int32_t OH_NativeWindow_NativeWindowHandleOpt(struct NativeWindow *window, int code, ...); -+ -+/** -+ * @brief Get the BufferHandle from the NativeWindowBuffer -+ * -+ * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow -+ * @param buffer Indicates NativeWindowBuffer -+ * @return BufferHandle -+ * @since 8 -+ * @version 1.0 -+ */ -+BufferHandle *OH_NativeWindow_GetBufferHandleFromNative(struct NativeWindowBuffer *buffer); -+ -+/** -+ * @brief Increase the reference count of the NativeObject -+ * -+ * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow -+ * @param obj Indicates NativeWindow or NativeWindowBuffer -+ * @return GSError -+ * @since 8 -+ * @version 1.0 -+ */ -+int32_t OH_NativeWindow_NativeObjectReference(void *obj); -+ -+/** -+ * @brief decrease the reference count of the NativeObject -+ * -+ * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow -+ * @param obj Indicates NativeWindow or NativeWindowBuffer -+ * @return GSError -+ * @since 8 -+ * @version 1.0 -+ */ -+int32_t OH_NativeWindow_NativeObjectUnreference(void *obj); -+ -+/** -+ * @brief Get the MagicId of the NativeObject -+ * -+ * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow -+ * @param obj Indicates NativeWindow or NativeWindowBuffer -+ * @return MagicId -+ * @since 8 -+ * @version 1.0 -+ */ -+int32_t OH_NativeWindow_GetNativeObjectMagic(void *obj); -+ -+#ifdef __cplusplus -+} -+#endif -+ -+/** @} */ -+#endif -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/surface/ibuffer_consumer_listener.h b/ohos_ndk_aosp/includes/surface/ibuffer_consumer_listener.h -new file mode 100644 -index 0000000000..18bb04f6b9 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/surface/ibuffer_consumer_listener.h -@@ -0,0 +1,36 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef INTERFACES_INNERKITS_SURFACE_IBUFFER_CONSUMER_LISTENER_H -+#define INTERFACES_INNERKITS_SURFACE_IBUFFER_CONSUMER_LISTENER_H -+ -+#include -+#include "surface_type.h" -+ -+namespace OHOS { -+class IBufferConsumerListener : public RefBase { -+public: -+ virtual ~IBufferConsumerListener() = default; -+ virtual void OnBufferAvailable() = 0; -+}; -+ -+class IBufferConsumerListenerClazz { -+public: -+ virtual ~IBufferConsumerListenerClazz() = default; -+ virtual void OnBufferAvailable() = 0; -+}; -+} // namespace OHOS -+ -+#endif // INTERFACES_INNERKITS_SURFACE_IBUFFER_CONSUMER_LISTENER_H -diff --git a/ohos_ndk_aosp/includes/surface/ibuffer_producer.h b/ohos_ndk_aosp/includes/surface/ibuffer_producer.h -new file mode 100644 -index 0000000000..72a0b40538 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/surface/ibuffer_producer.h -@@ -0,0 +1,84 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef INTERFACES_INNERKITS_SURFACE_IBUFFER_PRODUCER_H -+#define INTERFACES_INNERKITS_SURFACE_IBUFFER_PRODUCER_H -+ -+#include -+#include -+ -+#include -+ -+#include "buffer_extra_data.h" -+#include "surface_buffer.h" -+#include "surface_type.h" -+ -+namespace OHOS { -+class IBufferProducer : public IRemoteBroker { -+public: -+ struct RequestBufferReturnValue { -+ int32_t sequence; -+ sptr buffer; -+ int32_t fence; -+ std::vector deletingBuffers; -+ }; -+ virtual GSError RequestBuffer(const BufferRequestConfig &config, BufferExtraData &bedata, -+ RequestBufferReturnValue &retval) = 0; -+ -+ virtual GSError CancelBuffer(int32_t sequence, BufferExtraData &bedata) = 0; -+ -+ virtual GSError FlushBuffer(int32_t sequence, BufferExtraData &bedata, -+ int32_t fence, BufferFlushConfig &config) = 0; -+ -+ virtual GSError AttachBuffer(sptr& buffer) = 0; -+ virtual GSError DetachBuffer(sptr& buffer) = 0; -+ -+ virtual uint32_t GetQueueSize() = 0; -+ virtual GSError SetQueueSize(uint32_t queueSize) = 0; -+ -+ virtual GSError GetName(std::string &name) = 0; -+ -+ virtual int32_t GetDefaultWidth() = 0; -+ virtual int32_t GetDefaultHeight() = 0; -+ virtual uint32_t GetDefaultUsage() = 0; -+ -+ virtual uint64_t GetUniqueId() = 0; -+ virtual GSError CleanCache() = 0; -+ -+ virtual GSError RegisterReleaseListener(OnReleaseFunc func) = 0; -+ -+ DECLARE_INTERFACE_DESCRIPTOR(u"surf.IBufferProducer"); -+ -+protected: -+ enum { -+ BUFFER_PRODUCER_REQUEST_BUFFER = 0, -+ BUFFER_PRODUCER_CANCEL_BUFFER = 1, -+ BUFFER_PRODUCER_FLUSH_BUFFER = 2, -+ BUFFER_PRODUCER_GET_QUEUE_SIZE = 3, -+ BUFFER_PRODUCER_SET_QUEUE_SIZE = 4, -+ BUFFER_PRODUCER_GET_NAME = 5, -+ BUFFER_PRODUCER_GET_DEFAULT_WIDTH = 6, -+ BUFFER_PRODUCER_GET_DEFAULT_HEIGHT = 7, -+ BUFFER_PRODUCER_GET_DEFAULT_USAGE = 8, -+ BUFFER_PRODUCER_CLEAN_CACHE = 9, -+ BUFFER_PRODUCER_ATTACH_BUFFER = 10, -+ BUFFER_PRODUCER_DETACH_BUFFER = 11, -+ BUFFER_PRODUCER_REGISTER_RELEASE_LISTENER = 12, -+ BUFFER_PRODUCER_GET_UNIQUE_ID = 13, -+ }; -+}; -+} // namespace OHOS -+ -+#endif // INTERFACES_INNERKITS_SURFACE_IBUFFER_PRODUCER_H -diff --git a/ohos_ndk_aosp/includes/surface/surface.h b/ohos_ndk_aosp/includes/surface/surface.h -new file mode 100644 -index 0000000000..e8858bf036 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/surface/surface.h -@@ -0,0 +1,84 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef INTERFACES_INNERKITS_SURFACE_SURFACE_H -+#define INTERFACES_INNERKITS_SURFACE_SURFACE_H -+ -+#include -+ -+#include "ibuffer_consumer_listener.h" -+#include "ibuffer_producer.h" -+#include "surface_buffer.h" -+#include "surface_type.h" -+ -+namespace OHOS { -+class Surface : public RefBase { -+public: -+ static sptr CreateSurfaceAsConsumer(std::string name = "noname", bool isShared = false); -+ static sptr CreateSurfaceAsProducer(sptr& producer); -+ static sptr CreateEglSurfaceAsConsumer(std::string name = "noname", bool isShared = false); -+ -+ virtual ~Surface() = default; -+ -+ virtual bool IsConsumer() const = 0; -+ virtual sptr GetProducer() const = 0; -+ -+ virtual GSError RequestBuffer(sptr& buffer, -+ int32_t &fence, BufferRequestConfig &config) = 0; -+ -+ virtual GSError CancelBuffer(sptr& buffer) = 0; -+ -+ virtual GSError FlushBuffer(sptr& buffer, -+ int32_t fence, BufferFlushConfig &config) = 0; -+ -+ virtual GSError AcquireBuffer(sptr& buffer, int32_t &fence, -+ int64_t ×tamp, Rect &damage) = 0; -+ virtual GSError ReleaseBuffer(sptr& buffer, int32_t fence) = 0; -+ -+ virtual GSError AttachBuffer(sptr& buffer) = 0; -+ -+ virtual GSError DetachBuffer(sptr& buffer) = 0; -+ -+ virtual uint32_t GetQueueSize() = 0; -+ virtual GSError SetQueueSize(uint32_t queueSize) = 0; -+ -+ virtual GSError SetDefaultWidthAndHeight(int32_t width, int32_t height) = 0; -+ virtual int32_t GetDefaultWidth() = 0; -+ virtual int32_t GetDefaultHeight() = 0; -+ -+ virtual GSError SetDefaultUsage(uint32_t usage) = 0; -+ virtual uint32_t GetDefaultUsage() = 0; -+ -+ virtual GSError SetUserData(const std::string &key, const std::string &val) = 0; -+ virtual std::string GetUserData(const std::string &key) = 0; -+ -+ virtual GSError GetName(std::string &name) = 0; -+ -+ virtual GSError RegisterConsumerListener(sptr& listener) = 0; -+ virtual GSError RegisterConsumerListener(IBufferConsumerListenerClazz *listener) = 0; -+ virtual GSError RegisterReleaseListener(OnReleaseFunc func) = 0; -+ virtual GSError UnregisterConsumerListener() = 0; -+ -+ virtual uint64_t GetUniqueId() const = 0; -+ -+ virtual void Dump(std::string &result) const = 0; -+ -+ virtual GSError CleanCache() = 0; -+protected: -+ Surface() = default; -+}; -+} // namespace OHOS -+ -+#endif // INTERFACES_INNERKITS_SURFACE_SURFACE_H -diff --git a/ohos_ndk_aosp/includes/surface/surface_buffer.h b/ohos_ndk_aosp/includes/surface/surface_buffer.h -new file mode 100644 -index 0000000000..c29965a9c1 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/surface/surface_buffer.h -@@ -0,0 +1,71 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef INTERFACES_INNERKITS_SURFACE_SURFACE_BUFFER_H -+#define INTERFACES_INNERKITS_SURFACE_SURFACE_BUFFER_H -+ -+#include -+ -+#include -+ -+#include "buffer_handle_utils.h" -+#include "surface_type.h" -+#include "egl_data.h" -+ -+namespace OHOS { -+class SurfaceBuffer : public RefBase { -+public: -+ virtual BufferHandle *GetBufferHandle() const = 0; -+ virtual int32_t GetWidth() const = 0; -+ virtual int32_t GetHeight() const = 0; -+ virtual int32_t GetStride() const = 0; -+ virtual int32_t GetSurfaceBufferWidth() const = 0; -+ virtual int32_t GetSurfaceBufferHeight() const = 0; -+ virtual SurfaceColorGamut GetSurfaceBufferColorGamut() const = 0; -+ virtual GSError SetSurfaceBufferWidth(int32_t width) = 0; -+ virtual GSError SetSurfaceBufferHeight(int32_t height) = 0; -+ virtual GSError SetSurfaceBufferColorGamut(SurfaceColorGamut colorGamut) = 0; -+ virtual int32_t GetFormat() const = 0; -+ virtual int64_t GetUsage() const = 0; -+ virtual uint64_t GetPhyAddr() const = 0; -+ virtual int32_t GetKey() const = 0; -+ virtual void *GetVirAddr() const = 0; -+ virtual int GetFileDescriptor() const = 0; -+ virtual uint32_t GetSize() const = 0; -+ virtual GSError SetInt32(uint32_t key, int32_t value) = 0; -+ virtual GSError GetInt32(uint32_t key, int32_t &value) = 0; -+ virtual GSError SetInt64(uint32_t key, int64_t value) = 0; -+ virtual GSError GetInt64(uint32_t key, int64_t &value) = 0; -+ virtual sptr GetEglData() const = 0; -+ -+ // support ipc data -+ virtual GSError ExtraGet(std::string key, int32_t &value) const = 0; -+ virtual GSError ExtraGet(std::string key, int64_t &value) const = 0; -+ virtual GSError ExtraGet(std::string key, double &value) const = 0; -+ virtual GSError ExtraGet(std::string key, std::string &value) const = 0; -+ virtual GSError ExtraSet(std::string key, int32_t value) = 0; -+ virtual GSError ExtraSet(std::string key, int64_t value) = 0; -+ virtual GSError ExtraSet(std::string key, double value) = 0; -+ virtual GSError ExtraSet(std::string key, std::string value) = 0; -+ -+protected: -+ SurfaceBuffer(){} -+ virtual ~SurfaceBuffer(){} -+}; -+ -+using OnReleaseFunc = std::function &)>; -+} // namespace OHOS -+ -+#endif // INTERFACES_INNERKITS_SURFACE_SURFACE_BUFFER_H -diff --git a/ohos_ndk_aosp/includes/surface/surface_type.h b/ohos_ndk_aosp/includes/surface/surface_type.h -new file mode 100644 -index 0000000000..f7a4a05c6f ---- /dev/null -+++ b/ohos_ndk_aosp/includes/surface/surface_type.h -@@ -0,0 +1,84 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef INTERFACES_INNERKITS_SURFACE_SURFACE_TYPE_H -+#define INTERFACES_INNERKITS_SURFACE_SURFACE_TYPE_H -+ -+#include -+#include -+ -+#include -+ -+namespace OHOS { -+#define SURFACE_MAX_USER_DATA_COUNT 1000 -+#define SURFACE_MAX_QUEUE_SIZE 10 -+#define SURFACE_DEFAULT_QUEUE_SIZE 3 -+#define SURFACE_MAX_STRIDE_ALIGNMENT 32 -+#define SURFACE_MIN_STRIDE_ALIGNMENT 4 -+#define SURFACE_DEFAULT_STRIDE_ALIGNMENT 4 -+#define SURFACE_MAX_SIZE 58982400 // 8K * 8K -+ -+using Rect = struct Rect { -+ int32_t x; -+ int32_t y; -+ int32_t w; -+ int32_t h; -+}; -+ -+typedef enum { -+ COLOR_GAMUT_INVALID = -1, -+ COLOR_GAMUT_NATIVE = 0, -+ COLOR_GAMUT_SATNDARD_BT601 = 1, -+ COLOR_GAMUT_STANDARD_BT709 = 2, -+ COLOR_GAMUT_DCI_P3 = 3, -+ COLOR_GAMUT_SRGB = 4, -+ COLOR_GAMUT_ADOBE_RGB = 5, -+ COLOR_GAMUT_DISPLAY_P3 = 6, -+ COLOR_GAMUT_BT2020 = 7, -+ COLOR_GAMUT_BT2100_PQ = 8, -+ COLOR_GAMUT_BT2100_HLG = 9, -+ COLOR_GAMUT_DISPLAY_BT2020 = 10, -+} SurfaceColorGamut; -+ -+using BufferRequestConfig = struct BufferRequestConfig { -+ int32_t width; -+ int32_t height; -+ int32_t strideAlignment; -+ int32_t format; // PixelFormat -+ int32_t usage; -+ int32_t timeout; -+ SurfaceColorGamut colorGamut = SurfaceColorGamut::COLOR_GAMUT_SRGB; -+ bool operator ==(const struct BufferRequestConfig &config) const -+ { -+ return width == config.width && -+ height == config.height && -+ strideAlignment == config.strideAlignment && -+ format == config.format && -+ usage == config.usage && -+ colorGamut == config.colorGamut; -+ } -+ bool operator != (const struct BufferRequestConfig &config) const -+ { -+ return !(*this == config); -+ } -+}; -+ -+using BufferFlushConfig = struct BufferFlushConfig { -+ Rect damage; -+ int64_t timestamp; -+}; -+} // namespace OHOS -+ -+#endif // INTERFACES_INNERKITS_SURFACE_SURFACE_TYPE_H -diff --git a/ohos_ndk_aosp/includes/surface/surface_utils.h b/ohos_ndk_aosp/includes/surface/surface_utils.h -new file mode 100644 -index 0000000000..f33a4c3ee1 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/surface/surface_utils.h -@@ -0,0 +1,44 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef INTERFACES_INNERKITS_SURFACE_SURFACE_UTILS_H -+#define INTERFACES_INNERKITS_SURFACE_SURFACE_UTILS_H -+ -+#include -+#include -+#include "surface.h" -+ -+namespace OHOS { -+class SurfaceUtils { -+public: -+ static SurfaceUtils* GetInstance(); -+ -+ // get surface by uniqueId. -+ sptr GetSurface(uint64_t uniqueId); -+ // maintenance map with uniqueId and surface. -+ SurfaceError Add(uint64_t uniqueId, const sptr &surface); -+ // remove surface by uniqueId. -+ SurfaceError Remove(uint64_t uniqueId); -+ -+private: -+ SurfaceUtils() = default; -+ virtual ~SurfaceUtils(); -+ -+ std::unordered_map> surfaceCache_; -+ std::mutex mutex_; -+}; -+} // namespace OHOS -+ -+#endif // INTERFACES_INNERKITS_SURFACE_SURFACE_UTILS_H -diff --git a/ohos_ndk_aosp/includes/surface/window.h b/ohos_ndk_aosp/includes/surface/window.h -new file mode 100644 -index 0000000000..97910e4913 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/surface/window.h -@@ -0,0 +1,94 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef NDK_INCLUDE_NATIVE_WINDOW_H_ -+#define NDK_INCLUDE_NATIVE_WINDOW_H_ -+ -+#include -+#include -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+struct NativeWindow; -+struct NativeWindowBuffer; -+ -+#define MKMAGIC(a, b, c, d) (((a) << 24) + ((b) << 16) + ((c) << 8) + ((d) << 0)) -+ -+enum NativeObjectMagic { -+ NATIVE_OBJECT_MAGIC_WINDOW = MKMAGIC('W', 'I', 'N', 'D'), -+ NATIVE_OBJECT_MAGIC_WINDOW_BUFFER = MKMAGIC('W', 'B', 'U', 'F'), -+}; -+ -+enum NativeObjectType { -+ NATIVE_OBJECT_WINDOW, -+ NATIVE_OBJECT_WINDOW_BUFFER, -+}; -+ -+struct Region { -+ struct Rect { -+ int32_t x; -+ int32_t y; -+ uint32_t w; -+ uint32_t h; -+ } *rects; // if nullptr, fill the Buffer dirty size by defualt -+ int32_t rectNumber; // if rectNumber is 0, fill the Buffer dirty size by defualt -+}; -+ -+enum NativeWindowOperation { -+ SET_BUFFER_GEOMETRY, // ([in] int32_t height, [in] int32_t width) -+ GET_BUFFER_GEOMETRY, // ([out] int32_t *height, [out] int32_t *width) -+ GET_FORMAT, // ([out] int32_t *format) -+ SET_FORMAT, // ([in] int32_t format) -+ GET_USAGE, // ([out] int32_t *usage) -+ SET_USAGE, // ([in] int32_t usage) -+ SET_STRIDE, // ([in] int32_t stride) -+ GET_STRIDE, // ([out] int32_t *stride) -+ SET_SWAP_INTERVAL, // ([in] int32_t interval) -+ GET_SWAP_INTERVAL, -+ SET_COLOR_GAMUT, // ([in] int32_t colorGamut) -+ GET_COLOR_GAMUT, // ([out int32_t *colorGamut]) -+}; -+ -+// pSurface type is OHOS::sptr* -+struct NativeWindow* CreateNativeWindowFromSurface(void* pSurface); -+void DestoryNativeWindow(struct NativeWindow* window); -+ -+// pSurfaceBuffer type is OHOS::sptr* -+struct NativeWindowBuffer* CreateNativeWindowBufferFromSurfaceBuffer(void* pSurfaceBuffer); -+void DestoryNativeWindowBuffer(struct NativeWindowBuffer* buffer); -+ -+int32_t NativeWindowRequestBuffer(struct NativeWindow *window, /* [out] */ struct NativeWindowBuffer **buffer, -+ /* [out] get release fence */ int *fenceFd); -+int32_t NativeWindowFlushBuffer(struct NativeWindow *window, struct NativeWindowBuffer *buffer, -+ int fenceFd, Region region); -+int32_t NativeWindowCancelBuffer(struct NativeWindow *window, struct NativeWindowBuffer *buffer); -+ -+// The meaning and quantity of parameters vary according to the code type. -+// For details, see the NativeWindowOperation comment. -+int32_t NativeWindowHandleOpt(struct NativeWindow *window, int code, ...); -+BufferHandle *GetBufferHandleFromNative(struct NativeWindowBuffer *buffer); -+ -+// NativeObject: NativeWindow, NativeWindowBuffer -+int32_t NativeObjectReference(void *obj); -+int32_t NativeObjectUnreference(void *obj); -+int32_t GetNativeObjectMagic(void *obj); -+ -+#ifdef __cplusplus -+} -+#endif -+ -+#endif -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/system_ability/if_system_ability_manager.h b/ohos_ndk_aosp/includes/system_ability/if_system_ability_manager.h -new file mode 100644 -index 0000000000..827b992f96 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/system_ability/if_system_ability_manager.h -@@ -0,0 +1,132 @@ -+/* -+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef INTERFACES_INNERKITS_SAMGR_INCLUDE_IF_SYSTEM_ABILITY_MANAGER_H_ -+#define INTERFACES_INNERKITS_SAMGR_INCLUDE_IF_SYSTEM_ABILITY_MANAGER_H_ -+ -+#include -+#include -+ -+#include "iremote_broker.h" -+#include "iremote_object.h" -+#include "iremote_proxy.h" -+#include "isystem_ability_load_callback.h" -+#include "isystem_ability_status_change.h" -+ -+namespace OHOS { -+class ISystemAbilityManager : public IRemoteBroker { -+public: -+ // Return list of all existing abilities. -+ virtual std::vector ListSystemAbilities(unsigned int dumpFlags = DUMP_FLAG_PRIORITY_ALL) = 0; -+ -+ enum { -+ SHEEFT_CRITICAL = 0, -+ SHEEFT_HIGH, -+ SHEEFT_NORMAL, -+ SHEEFT_DEFAULT, -+ SHEEFT_PROTO, -+ }; -+ -+ static const unsigned int DUMP_FLAG_PRIORITY_CRITICAL = 1 << SHEEFT_CRITICAL; -+ static const unsigned int DUMP_FLAG_PRIORITY_HIGH = 1 << SHEEFT_HIGH; -+ static const unsigned int DUMP_FLAG_PRIORITY_NORMAL = 1 << SHEEFT_NORMAL; -+ -+ static const unsigned int DUMP_FLAG_PRIORITY_DEFAULT = 1 << SHEEFT_DEFAULT; -+ static const unsigned int DUMP_FLAG_PRIORITY_ALL = DUMP_FLAG_PRIORITY_CRITICAL | -+ DUMP_FLAG_PRIORITY_HIGH | DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PRIORITY_DEFAULT; -+ static const unsigned int DUMP_FLAG_PROTO = 1 << SHEEFT_PROTO; -+ -+ enum { -+ GET_SYSTEM_ABILITY_TRANSACTION = 1, -+ CHECK_SYSTEM_ABILITY_TRANSACTION = 2, -+ ADD_SYSTEM_ABILITY_TRANSACTION = 3, -+ REMOVE_SYSTEM_ABILITY_TRANSACTION = 4, -+ LIST_SYSTEM_ABILITY_TRANSACTION = 5, -+ SUBSCRIBE_SYSTEM_ABILITY_TRANSACTION = 6, -+ LOAD_SYSTEM_ABILITY_TRANSACTION = 7, -+ CHECK_REMOTE_SYSTEM_ABILITY_TRANSACTION = 9, -+ ADD_ONDEMAND_SYSTEM_ABILITY_TRANSACTION = 10, -+ CHECK_SYSTEM_ABILITY_IMMEDIATELY_TRANSACTION = 12, -+ CHECK_ONDEMAND_SYSTEM_ABILITY_TRANSACTION = 15, -+ GET_SYSTEM_ABILITYINFOLIST_TRANSACTION = 17, -+ UNSUBSCRIBE_SYSTEM_ABILITY_TRANSACTION = 18, -+ ADD_SYSTEM_PROCESS_TRANSACTION = 20 -+ }; -+ -+ // Retrieve an existing ability, blocking for a few seconds if it doesn't ye exist. -+ virtual sptr GetSystemAbility(int32_t systemAbilityId) = 0; -+ -+ // Retrieve an existing ability, no-blocking. -+ virtual sptr CheckSystemAbility(int32_t systemAbilityId) = 0; -+ -+ // Remove an ability. -+ virtual int32_t RemoveSystemAbility(int32_t systemAbilityId) = 0; -+ -+ virtual int32_t SubscribeSystemAbility(int32_t systemAbilityId, -+ const sptr& listener) = 0; -+ virtual int32_t UnSubscribeSystemAbility(int32_t systemAbilityId, -+ const sptr& listener) = 0; -+ -+ // Retrieve an existing ability, blocking for a few seconds if it doesn't ye exist. -+ virtual sptr GetSystemAbility(int32_t systemAbilityId, const std::string& deviceId) = 0; -+ -+ // Retrieve an existing ability, no-blocking -+ virtual sptr CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId) = 0; -+ -+ // Add ondemand ability info. -+ virtual int32_t AddOnDemandSystemAbilityInfo(int32_t systemAbilityId, -+ const std::u16string& localAbilityManagerName) = 0; -+ -+ // Retrieve an ability, no-blocking. -+ virtual sptr CheckSystemAbility(int32_t systemAbilityId, bool& isExist) = 0; -+ -+ struct SAExtraProp { -+ SAExtraProp() = default; -+ SAExtraProp(bool isDistributed, unsigned int dumpFlags, const std::u16string& capability, -+ const std::u16string& permission) -+ { -+ this->isDistributed = isDistributed; -+ this->dumpFlags = dumpFlags; -+ this->capability = capability; -+ this->permission = permission; -+ } -+ -+ bool isDistributed = false; -+ unsigned int dumpFlags = DUMP_FLAG_PRIORITY_DEFAULT; -+ std::u16string capability; -+ std::u16string permission; -+ }; -+ virtual int32_t AddSystemAbility(int32_t systemAbilityId, const sptr& ability, -+ const SAExtraProp& extraProp = SAExtraProp(false, DUMP_FLAG_PRIORITY_DEFAULT, u"", u"")) = 0; -+ -+ virtual int32_t AddSystemProcess(const std::u16string& procName, const sptr& procObject) = 0; -+ virtual int32_t LoadSystemAbility(int32_t systemAbilityId, const sptr& callback) = 0; -+public: -+ DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISystemAbilityManager"); -+protected: -+ static constexpr int32_t FIRST_SYS_ABILITY_ID = 0x00000001; -+ static constexpr int32_t LAST_SYS_ABILITY_ID = 0x00ffffff; -+ bool CheckInputSysAbilityId(int32_t sysAbilityId) const -+ { -+ if (sysAbilityId >= FIRST_SYS_ABILITY_ID && sysAbilityId <= LAST_SYS_ABILITY_ID) { -+ return true; -+ } -+ return false; -+ } -+ static inline const std::u16string SAMANAGER_INTERFACE_TOKEN = u"ohos.samgr.accessToken"; -+}; -+} // namespace OHOS -+ -+#endif // !defined(INTERFACES_INNERKITS_SAMGR_INCLUDE_IF_SYSTEM_ABILITY_MANAGER_H_ ) -diff --git a/ohos_ndk_aosp/includes/system_ability/iservice_registry.h b/ohos_ndk_aosp/includes/system_ability/iservice_registry.h -new file mode 100755 -index 0000000000..a5c3f1ddea ---- /dev/null -+++ b/ohos_ndk_aosp/includes/system_ability/iservice_registry.h -@@ -0,0 +1,93 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef SERVICE_REGISTRY_INCLUDE_H -+#define SERVICE_REGISTRY_INCLUDE_H -+ -+#include "ipc_types.h" -+#include -+#include "ipc_object_stub.h" -+#include "iremote_proxy.h" -+#include "if_system_ability_manager.h" -+ -+namespace OHOS { -+class IServiceRegistry : public IRemoteBroker { -+public: -+ /** -+ * Retrieve an existing service, blocking for a few seconds -+ * if it doesn't yet exist. -+ */ -+ virtual sptr GetService(const std::u16string& name) = 0; -+ -+ /** -+ * Retrieve an existing service, non-blocking. -+ */ -+ virtual sptr CheckService(const std::u16string& name) = 0; -+ -+ /** -+ * Register a service. -+ */ -+ virtual int AddService(const std::u16string& name, const sptr &service, -+ bool allowIsolated = false, int dumpsysFlags = 0) = 0; -+ -+ enum { -+ GET_SERVICE_TRANSACTION = FIRST_CALL_TRANSACTION, -+ CHECK_SERVICE_TRANSACTION, -+ ADD_SERVICE_TRANSACTION, -+ }; -+public: -+ DECLARE_INTERFACE_DESCRIPTOR(u""); -+}; -+ -+class ServiceRegistry { -+public: -+ /** -+ * get Service registry instance. -+ */ -+ static sptr GetInstance(); -+ -+private: -+ static std::mutex serviceRegistryLock_; -+}; -+ -+class SystemAbilityManagerClient { -+public: -+ static SystemAbilityManagerClient& GetInstance(); -+ -+ /** -+ * get system ability manager. -+ */ -+ sptr GetSystemAbilityManager(); -+ -+ /** -+ * get remote object of samgr. -+ */ -+ sptr GetRegistryRemoteObject(); -+ -+ /** -+ * destroy remote object of samgr. -+ */ -+ void DestroySystemAbilityManagerObject(); -+ -+private: -+ SystemAbilityManagerClient() = default; -+ ~SystemAbilityManagerClient() = default; -+ -+ sptr systemAbilityManager_; -+ std::mutex systemAbilityManagerLock_; -+}; -+} // namespace OHOS -+ -+#endif // ZIPC_SERVICE_REGISTRY_INCLUDE_H -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/system_ability/isystem_ability_load_callback.h b/ohos_ndk_aosp/includes/system_ability/isystem_ability_load_callback.h -new file mode 100755 -index 0000000000..01d55cacf6 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/system_ability/isystem_ability_load_callback.h -@@ -0,0 +1,37 @@ -+/* -+ * Copyright (c) 2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_ISYSTEM_ABILITY_LOAD_CALLBACK_H -+#define SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_ISYSTEM_ABILITY_LOAD_CALLBACK_H -+ -+#include "iremote_broker.h" -+#include "iremote_object.h" -+#include "iremote_proxy.h" -+ -+namespace OHOS { -+class ISystemAbilityLoadCallback : public IRemoteBroker { -+public: -+ virtual ~ISystemAbilityLoadCallback() = default; -+ virtual void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr& remoteObject) = 0; -+ virtual void OnLoadSystemAbilityFail(int32_t systemAbilityId) = 0; -+ DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISystemAbilityLoadCallback"); -+protected: -+ enum { -+ ON_LOAD_SYSTEM_ABILITY_SUCCESS = 1, -+ ON_LOAD_SYSTEM_ABILITY_FAIL = 2, -+ }; -+}; -+} -+#endif /* SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_ISYSTEM_ABILITY_LOAD_CALLBACK_H */ -diff --git a/ohos_ndk_aosp/includes/system_ability/isystem_ability_status_change.h b/ohos_ndk_aosp/includes/system_ability/isystem_ability_status_change.h -new file mode 100755 -index 0000000000..ace87cb10c ---- /dev/null -+++ b/ohos_ndk_aosp/includes/system_ability/isystem_ability_status_change.h -@@ -0,0 +1,36 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_IF_SYSTEM_ABILITY_STATUS_CHANGE_H -+#define SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_IF_SYSTEM_ABILITY_STATUS_CHANGE_H -+ -+#include "iremote_broker.h" -+#include "iremote_object.h" -+#include "iremote_proxy.h" -+ -+namespace OHOS { -+class ISystemAbilityStatusChange : public IRemoteBroker { -+public: -+ virtual ~ISystemAbilityStatusChange() = default; -+ virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) = 0; -+ virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) = 0; -+ DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISystemAbilityStatusChange"); -+ enum { -+ ON_ADD_SYSTEM_ABILITY = 1, -+ ON_REMOVE_SYSTEM_ABILITY = 2, -+ }; -+}; -+} -+#endif /* SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_IF_SYSTEM_ABILITY_STATUS_CHANGE_H */ -diff --git a/ohos_ndk_aosp/includes/system_ability/sam_log.h b/ohos_ndk_aosp/includes/system_ability/sam_log.h -new file mode 100644 -index 0000000000..f8b202ac14 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/system_ability/sam_log.h -@@ -0,0 +1,55 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef SERVICES_SAMGR_NATIVE_INCLUDE_SAM_LOG_H_ -+#define SERVICES_SAMGR_NATIVE_INCLUDE_SAM_LOG_H_ -+ -+#include "hilog/log.h" -+ -+namespace OHOS { -+static constexpr OHOS::HiviewDFX::HiLogLabel SYSTEM_ABLILITY_MGR_LABEL = { -+ LOG_CORE, -+ 0xD001800, -+ "SAMGR" -+}; -+ -+#ifdef HILOGF -+#undef HILOGF -+#endif -+ -+#ifdef HILOGE -+#undef HILOGE -+#endif -+ -+#ifdef HILOGW -+#undef HILOGW -+#endif -+ -+#ifdef HILOGI -+#undef HILOGI -+#endif -+ -+#ifdef HILOGD -+#undef HILOGD -+#endif -+ -+#define HILOGF(...) (void)OHOS::HiviewDFX::HiLog::Fatal(SYSTEM_ABLILITY_MGR_LABEL, __VA_ARGS__) -+#define HILOGE(...) (void)OHOS::HiviewDFX::HiLog::Error(SYSTEM_ABLILITY_MGR_LABEL, __VA_ARGS__) -+#define HILOGW(...) (void)OHOS::HiviewDFX::HiLog::Warn(SYSTEM_ABLILITY_MGR_LABEL, __VA_ARGS__) -+#define HILOGI(...) (void)OHOS::HiviewDFX::HiLog::Info(SYSTEM_ABLILITY_MGR_LABEL, __VA_ARGS__) -+#define HILOGD(...) (void)OHOS::HiviewDFX::HiLog::Debug(SYSTEM_ABLILITY_MGR_LABEL, __VA_ARGS__) -+} // namespace OHOS -+ -+#endif // #ifndef SERVICES_SAMGR_NATIVE_INCLUDE_SAM_LOG_H_ -diff --git a/ohos_ndk_aosp/includes/system_ability/system_ability_definition.h b/ohos_ndk_aosp/includes/system_ability/system_ability_definition.h -new file mode 100755 -index 0000000000..93e2c2b9b9 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/system_ability/system_ability_definition.h -@@ -0,0 +1,295 @@ -+/* -+ * Copyright (c) 2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_SYSTEM_ABILITY_DEFINITION_H -+#define UTILS_SYSTEM_ABILITY_DEFINITION_H -+ -+#include -+#include -+ -+namespace OHOS { -+// system ability definition should be a number between FIRST_SYS_ABILITY_ID and LAST_SYS_ABILITY_ID -+enum { -+ FIRST_SYS_ABILITY_ID = 0x00000001, -+ SUBSYS_COMMON_SYS_ABILITY_ID_BEGIN = 1, -+ RENDER_SERVICE = 10, -+ SUBSYS_AAFWK_SYS_ABILITY_ID_BEGIN = 100, -+ ABILITY_TOOLS_SERVICE_ID = 116, -+ ABILITY_TEST_SERVICE_ID = 179, -+ ABILITY_MGR_SERVICE_ID = 180, -+ ABILITY_MST_SERVICE_ID = 181, -+ DATAOBS_MGR_SERVICE_SA_ID = 182, -+ URI_PERMISSION_MGR_SERVICE_ID = 183, -+ SUBSYS_AAFWK_SYS_ABILITY_ID_END = 199, -+ SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN = 200, -+ SUBSYS_AI_SYS_ABILITY_ID_BEGIN = 300, -+ SUBSYS_AI_DS_SYS_ABILITY_ID = 310, -+ SUBSYS_APPEXECFWK_SYS_ABILITY_ID_BEGIN = 400, -+ BUNDLE_MGR_SERVICE_SYS_ABILITY_ID = 401, -+ DISTRIBUTED_BUNDLE_MGR_SERVICE_SYS_ABILITY_ID = 402, -+ FORM_MGR_SERVICE_ID = 403, -+ SUBSYS_APPLICATIONS_SYS_ABILITY_ID_BEGIN = 500, -+ APP_MGR_SERVICE_ID = 501, -+ INSTALLD_SERVICE_ID = 511, -+ SUBSYS_ARVR_SYS_ABILITY_ID_BEGIN = 600, -+ SUBSYS_ARVRHARDWARE_SYS_ABILITY_ID_BEGIN = 700, -+ SUBSYS_BARRIERFREE_SYS_ABILITY_ID_BEGIN = 800, -+ ACCESSIBILITY_MANAGER_SERVICE_ID = 801, -+ SUBSYS_BARRIERFREE_SYS_ABILITY_ID_END = 899, -+ SUBSYS_USERIAM_SYS_ABILITY_ID_BEGIN = 900, -+ SUBSYS_USERIAM_SYS_ABILITY_USERIDM = 901, -+ SUBSYS_USERIAM_SYS_ABILITY_USERAUTH = 921, -+ SUBSYS_USERIAM_SYS_ABILITY_AUTHEXECUTORMGR = 931, -+ SUBSYS_USERIAM_SYS_ABILITY_PINAUTH = 941, -+ SUBSYS_USERIAM_SYS_ABILITY_FACEAUTH = 942, -+ SUBSYS_CCRUNTIME_SYS_ABILITY_ID_BEGIN = 1000, -+ SUBSYS_COMMUNICATION_SYS_ABILITY_ID_BEGIN = 1100, -+ RPC_UNREGISTERED_TEST_SERVICE = 1108, -+ RPC_TEST_SERVICE = 1109, -+ RPC_TEST_SERVICE2 = 1110, -+ IPC_MSG_SEV = 1114, -+ IPC_MSG_UNREGISTERED_SERVER = 1115, -+ IPC_MSG_REPEAT_SERVER = 1116, -+ IPC_MSG_SERVER = 1117, -+ IPC_TEST_SERVICE = 1118, -+ IPC_EXTRA_TEST_SERVICE = 1119, -+ WIFI_DEVICE_SYS_ABILITY_ID = 1120, -+ WIFI_HOTSPOT_SYS_ABILITY_ID = 1121, -+ WIFI_ENHANCER_SYS_ABILITY_ID = 1122, -+ WIFI_P2P_SYS_ABILITY_ID = 1123, -+ BLUETOOTH_HOST_SYS_ABILITY_ID = 1130, -+ NFC_MANAGER_SYS_ABILITY_ID = 1140, -+ DISCOVER_SYS_ABILITY_ID = 1160, -+ DNET_SYS_ABILITY_ID = 1170, -+ NET_MANAGER_SYS_ABILITY_ID = 1150, -+ COMM_NET_CONN_MANAGER_SYS_ABILITY_ID = 1151, -+ COMM_NET_POLICY_MANAGER_SYS_ABILITY_ID = 1152, -+ COMM_NET_STATS_MANAGER_SYS_ABILITY_ID = 1153, -+ COMM_NET_TETHERING_MANAGER_SYS_ABILITY_ID = 1154, -+ COMM_VPN_MANAGER_SYS_ABILITY_ID = 1155, -+ COMM_DNS_MANAGER_SYS_ABILITY_ID = 1156, -+ COMM_ETHERNET_MANAGER_SYS_ABILITY_ID = 1157, -+ COMM_NETSYS_NATIVE_SYS_ABILITY_ID = 1158, -+ SMART_COMM_SYS_ABILITY_ID = 1180, -+ SUBSYS_DFX_SYS_ABILITY_ID_BEGIN = 1200, -+ DFX_SYS_HIVIEW_ABILITY_ID = 1201, -+ DFX_SYS_EVENT_SERVICE_ABILITY_ID = 1203, -+ SUBSYS_DISTRIBUTEDDATAMNG_SYS_ABILITY_ID_BEGIN = 1300, -+ DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID = 1301, -+ DISTRIBUTED_FS_DAEMON_SERVICE_ID = 1302, -+ DISTRIBUTED_FS_META_SERVICE_ID = 1303, -+ DISTRIBUTED_FS_STORAGE_SERVICE_ID = 1304, -+ SUBSYS_DISTRIBUTEDSCHEDULE_SYS_ABILITY_ID_BEGIN = 1400, -+ DISTRIBUTED_SCHED_SA_ID = 1401, -+ DISTRIBUTED_SCHED_ADAPTER_SA_ID = 1402, -+ DISTRIBUTED_SCENARIO_MGR_SA_ID = 1403, -+ DISTRIBUTED_SCHED_TEST_SO_ID = 1490, -+ DISTRIBUTED_SCHED_TEST_OS_ID = 1491, -+ DISTRIBUTED_SCHED_TEST_OOS_ID = 1492, -+ DISTRIBUTED_SCHED_TEST_TT_ID = 1493, -+ DISTRIBUTED_SCHED_TEST_LISTEN_ID = 1494, -+ DISTRIBUTED_SCHED_TEST_CONNECTION_ID = 1495, -+ DISTRIBUTED_SCHED_TEST_INCOMPLETE_ID = 1496, -+ DISTRIBUTED_SCHED_TEST_ONDEMAND_ID = 1497, -+ DISTRIBUTED_SCHED_TEST_AUDIO_ID = 1498, -+ DISTRIBUTED_SCHED_TEST_MEDIA_ID = 1499, -+ SUBSYS_DRIVERS_SYS_ABILITY_ID_BEGIN = 1500, -+ SUBSYS_GLOBAL_SYS_ABILITY_ID_BEGIN = 1600, -+ ENTERPRISE_DEVICE_MANAGER_SA_ID = 1601, -+ SUBSYS_GRAPHIC_SYS_ABILITY_ID_BEGIN = 1700, -+ SUBSYS_HBS_SYS_ABILITY_ID_BEGIN = 1800, -+ SUBSYS_IAWARE_SYS_ABILITY_ID_BEGIN = 1900, -+ RES_SCHED_SYS_ABILITY_ID = 1901, -+ RESSCHEDD_SA_ID = 1902, -+ BACKGROUND_TASK_MANAGER_SERVICE_ID = 1903, -+ WORK_SCHEDULE_SERVICE_ID = 1904, -+ SOC_PERF_SERVICE_SA_ID = 1906, -+ DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID = 1907, -+ MEMORY_MANAGER_SA_ID = 1909, -+ SUBSYS_IDE_SYS_ABILITY_ID_BEGIN = 2000, -+ SUBSYS_INTELLIACCESSORIES_SYS_ABILITY_ID_BEGIN = 2100, -+ SUBSYS_INTELLISPEAKER_SYS_ABILITY_ID_BEGIN = 2200, -+ SUBSYS_INTELLITV_SYS_ABILITY_ID_BEGIN = 2300, -+ SUBSYS_IOT_SYS_ABILITY_ID_BEGIN = 2400, -+ SUBSYS_IOTHARDWARE_SYS_ABILITY_ID_BEGIN = 2500, -+ SUBSYS_IVIHARDWARE_SYS_ABILITY_ID_BEGIN = 2600, -+ IVIHARDWARE_MANAGER_SA_ID = 2601, -+ IVIHARDWARE_ADAS_SA_ID = 2602, -+ IVIHARDWARE_TBOX_SA_ID = 2603, -+ IVIHARDWARE_CLUSTER_SA_ID = 2604, -+ SUBSYS_KERNEL_SYS_ABILITY_ID_BEGIN = 2700, -+ SUBSYS_LOCATION_SYS_ABILITY_ID_BEGIN = 2800, -+ LOCATION_GEO_CONVERT_SA_ID = 2801, -+ LOCATION_LOCATOR_SA_ID = 2802, -+ LOCATION_GNSS_SA_ID = 2803, -+ LOCATION_NETWORK_LOCATING_SA_ID = 2804, -+ LOCATION_NOPOWER_LOCATING_SA_ID = 2805, -+ LOCATION_NOTIFICATION_SA_ID = 2806, -+ SUBSYS_MSDP_SYS_ABILITY_ID_BEGIN = 2900, -+ MSDP_MOTION_SERVICE_ID = 2901, -+ MSDP_DEVICESTATUS_SERVICE_ID = 2902, -+ MSDP_MOVEMENT_SERVICE_ID = 2903, -+ MSDP_SPATIAL_AWARENESS_SERVICE_ID = 2904, -+ MSDP_GEOFENCE_SERVICE_ID = 2905, -+ MSDP_TIMELINE_SERVICE_ID = 2906, -+ SUBSYS_MULTIMEDIA_SYS_ABILITY_ID_BEGIN = 3000, -+ AUDIO_DISTRIBUTED_SERVICE_ID = 3001, -+ PLAYER_DISTRIBUTED_SERVICE_ID = 3002, -+ RADIO_IVI_SERVICE_ID = 3003, -+ AUDIO_SWIFT_SERVICE_ID = 3004, -+ UPDATE_DISTRIBUTED_SERVICE_ID = 3006, -+ MEDIA_LIBRARY_SERVICE_ID = 3007, -+ CAMERA_SERVICE_ID = 3008, -+ AUDIO_POLICY_SERVICE_ID = 3009, -+ SUBSYS_MULTIMODAINPUT_SYS_ABILITY_ID_BEGIN = 3100, -+ MULTIMODAL_INPUT_SERVICE_ID = 3101, -+ MULTIMODAL_CHANNEL_SERVICE_ID = 3102, -+ SUBSYS_NOTIFICATION_SYS_ABILITY_ID_BEGIN = 3200, -+ EVENT_MANAGER_SERVICE_ID = 3201, -+ COMMON_EVENT_SERVICE_ABILITY_ID = 3202, -+ ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID = 3203, -+ COMMON_EVENT_SERVICE_ID = 3299, -+ SUBSYS_POWERMNG_SYS_ABILITY_ID_BEGIN = 3300, -+ POWER_MANAGER_SERVICE_ID = 3301, -+ POWER_MANAGER_BATT_SERVICE_ID = 3302, -+ POWER_MANAGER_THERMAL_SERVICE_ID = 3303, -+ POWER_MANAGER_BATT_STATS_SERVICE_ID = 3304, -+ DISPLAY_MANAGER_SERVICE_ID = 3308, -+ IVIPOWER_ENHANCED_SERVICE_ID = 3309, -+ SUBSYS_ROUTER_SYS_ABILITY_ID_BEGIN = 3400, -+ SUBSYS_SECURITY_SYS_ABILITY_ID_BEGIN = 3500, -+ DEVICE_SECURITY_LEVEL_MANAGER_SA_ID = 3511, -+ SUBSYS_SENSORS_SYS_ABILITY_ID_BEGIN = 3600, -+ SENSOR_SERVICE_ABILITY_ID = 3601, -+ MISCDEVICE_SERVICE_ABILITY_ID = 3602, -+ EXTSHB_SERVICE_ABILITY_ID = 3603, -+ SUBSYS_SMALLSERVICES_SYS_ABILITY_ID_BEGIN = 3700, -+ PASTEBOARD_SERVICE_ID = 3701, -+ TIME_SERVICE_ID = 3702, -+ INPUT_METHOD_SYSTEM_ABILITY_ID = 3703, -+ SCREENLOCK_SERVICE_ID = 3704, -+ WALLPAPER_MANAGER_SERVICE_ID = 3705, -+ DOWNLOAD_SERVICE_ID = 3706, -+ SUBSYS_SOURCECODETRANSFORMER_SYS_ABILITY_ID_BEGIN = 3800, -+ SUBSYS_STARTUP_SYS_ABILITY_ID_BEGIN = 3900, -+ PARAM_WATCHER_DISTRIBUTED_SERVICE_ID = 3901, -+ SYSPARAM_DEVICE_SERVICE_ID = 3902, -+ SUBSYS_TELEPONY_SYS_ABILITY_ID_BEGIN = 4000, -+ TELEPHONY_SYS_ABILITY_ID = 4001, -+ DCALL_SYS_ABILITY_ID = 4002, -+ TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID = 4005, -+ TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID = 4006, -+ TELEPHONY_CELLULAR_DATA_SYS_ABILITY_ID = 4007, -+ TELEPHONY_SMS_MMS_SYS_ABILITY_ID = 4008, -+ TELEPHONY_STATE_REGISTRY_SYS_ABILITY_ID = 4009, -+ TELEPHONY_CORE_SERVICE_SYS_ABILITY_ID = 4010, -+ TELEPHONY_DATA_STORAGE_SYS_ABILITY_ID = 4012, -+ SUBSYS_UPDATE_SYS_ABILITY_ID_BEGIN = 4100, -+ SUBSYS_USB_SYS_ABILITY_ID_BEGIN = 4200, -+ USB_SYSTEM_ABILITY_ID = 4201, -+ SUBSYS_WEARABLE_SYS_ABILITY_ID_BEGIN = 4300, -+ SUBSYS_WEARABLEHARDWARE_SYS_ABILITY_ID_BEGIN = 4400, -+ SUBSYS_IVI_SYS_ABILITY_ID_BEGIN = 4500, -+ IVI_DRIVINGSAFETY_SA_ID = 4501, -+ IVI_CONFIGMANAGER_SA_ID = 4502, -+ IVI_COCKPITMONITOR_SA_ID = 4503, -+ WINDOW_MANAGER_ID = 4600, -+ VSYNC_MANAGER_ID = 4601, -+ VSYNC_MANAGER_TEST_ID = 4602, -+ GRAPHIC_DUMPER_SERVICE_SA_ID = 4603, -+ GRAPHIC_DUMPER_COMMAND_SA_ID = 4604, -+ ANIMATION_SERVER_SA_ID = 4605, -+ WINDOW_MANAGER_SERVICE_ID = 4606, -+ DISPLAY_MANAGER_SERVICE_SA_ID = 4607, -+ SOFTBUS_SERVER_SA_ID = 4700, -+ DEVICE_AUTH_SERVICE_ID = 4701, -+ SUBSYS_DISTRIBUTED_HARDWARE_SYS_ABILITY_ID_BEGIN = 4800, -+ DISTRIBUTED_HARDWARE_SA_ID = 4801, -+ DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID = 4802, -+ DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID = 4803, -+ DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID = 4804, -+ SUBSYS_STORAGE_SYS_ABILITY_ID_BEGIN = 4900, -+ STORAGE_DISTRIBUTED_FILE_DAEMON_SA_ID = 4901, -+ STORAGE_DISTRIBUTED_FILE_SERVICE_SA_ID = 4902, -+ DEVICE_STORAGE_MANAGER_SERVICE_ID = 5000, -+ STORAGE_SERVICE_ID = 5001, -+ STORAGE_MANAGER_DAEMON_ID = 5002, -+ STORAGE_MANAGER_MANAGER_ID = 5003, -+ FILE_MANAGER_SERVICE_ID = 5010, -+ DEVICE_SERVICE_MANAGER_SA_ID = 5100, -+ DISTRIBUTED_DEVICE_PROFILE_SA_ID = 6001, -+ SUBSYS_ACE_SYS_ABILITY_ID_BEGIN = 7001, -+ CA_DAEMON_ID = 8001, -+ LAST_SYS_ABILITY_ID = 0x00ffffff, // 16777215 -+}; -+ -+static const std::map saNameMap_ = { -+ { 200, "AccountMgr" }, -+ { 301, "AIEngine" }, -+ { BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, "BundleMgr" }, -+ { FORM_MGR_SERVICE_ID, "FormMgr" }, -+ { WIFI_DEVICE_SYS_ABILITY_ID, "WifiDevice" }, -+ { WIFI_HOTSPOT_SYS_ABILITY_ID, "WifiHotspot" }, -+ { WIFI_ENHANCER_SYS_ABILITY_ID, "WifiEnhancer" }, -+ { WIFI_P2P_SYS_ABILITY_ID, "WifiP2p" }, -+ { BLUETOOTH_HOST_SYS_ABILITY_ID, "BluetoothHost" }, -+ { NFC_MANAGER_SYS_ABILITY_ID, "NfcManager" }, -+ { NET_MANAGER_SYS_ABILITY_ID, "NetManager" }, -+ { DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID, "DistributedKvData" }, -+ { DISTRIBUTED_SCHED_SA_ID, "DistributedSched" }, -+ { DISTRIBUTED_SCHED_ADAPTER_SA_ID, "DistributedSchedAdapter" }, -+ { DISTRIBUTED_SCENARIO_MGR_SA_ID, "DistributedScenarioMgr" }, -+ { RES_SCHED_SYS_ABILITY_ID, "ResourceSched" }, -+ { RESSCHEDD_SA_ID, "ResourceSchedDamon" }, -+ { BACKGROUND_TASK_MANAGER_SERVICE_ID, "BackgroundTaskManager" }, -+ { WORK_SCHEDULE_SERVICE_ID, "WorkSchedule" }, -+ { LOCATION_GEO_CONVERT_SA_ID, "LocationGeoConvert" }, -+ { LOCATION_LOCATOR_SA_ID, "LocationLocator" }, -+ { LOCATION_GNSS_SA_ID, "LocationGnss" }, -+ { LOCATION_NETWORK_LOCATING_SA_ID, "LocationNetworkLocating" }, -+ { LOCATION_NOPOWER_LOCATING_SA_ID, "LocationNopowerLocating" }, -+ { AUDIO_DISTRIBUTED_SERVICE_ID, "AudioDistributed" }, -+ { COMMON_EVENT_SERVICE_ABILITY_ID, "CommonEventService" }, -+ { ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID, "AdvancedNotificationService" }, -+ { POWER_MANAGER_SERVICE_ID, "PowerManagerService" }, -+ { POWER_MANAGER_BATT_SERVICE_ID, "PowerManagerBatt" }, -+ { POWER_MANAGER_BATT_STATS_SERVICE_ID, "BatteryStatsService" }, -+ { 3502, "DpmsService" }, -+ { 3510, "KeystoreService" }, -+ { DEVICE_SECURITY_LEVEL_MANAGER_SA_ID, "DslmService" }, -+ { SENSOR_SERVICE_ABILITY_ID, "SensorService" }, -+ { MISCDEVICE_SERVICE_ABILITY_ID, "MiscDeviceService" }, -+ { PASTEBOARD_SERVICE_ID, "DPasteboardService" }, -+ { TELEPHONY_SYS_ABILITY_ID, "Telephony" }, -+ { DCALL_SYS_ABILITY_ID, "DistributedCallMgr" }, -+ { DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID, "DeviceManagerService" }, -+ { USB_SYSTEM_ABILITY_ID, "UsbService" }, -+ { DEVICE_SERVICE_MANAGER_SA_ID, "HdfDeviceServiceManager" }, -+ { DISTRIBUTED_DEVICE_PROFILE_SA_ID, "DistributedDeviceProfile" }, -+ { WINDOW_MANAGER_SERVICE_ID, "WindowManagerService" }, -+ { DISPLAY_MANAGER_SERVICE_SA_ID, "DisplayManagerService" }, -+ { WINDOW_MANAGER_ID, "WindowManager" }, -+ { VSYNC_MANAGER_ID, "VsyncManager" }, -+ { VSYNC_MANAGER_TEST_ID, "VsyncManagerTest" }, -+ { GRAPHIC_DUMPER_SERVICE_SA_ID, "GraphicDumperService" }, -+ { GRAPHIC_DUMPER_COMMAND_SA_ID, "GraphicDumperCommand" }, -+ { ANIMATION_SERVER_SA_ID, "AnimationServer" }, -+ { CA_DAEMON_ID, "CaDaemon"}, -+ { ACCESSIBILITY_MANAGER_SERVICE_ID, "AccessibilityManagerService"}, -+ { MEMORY_MANAGER_SA_ID, "MemoryManagerService" }, -+}; -+} // namespace OHOS -+ -+#endif -diff --git a/ohos_ndk_aosp/includes/system_ability/system_ability_load_callback_stub.h b/ohos_ndk_aosp/includes/system_ability/system_ability_load_callback_stub.h -new file mode 100755 -index 0000000000..9bf201f127 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/system_ability/system_ability_load_callback_stub.h -@@ -0,0 +1,35 @@ -+/* -+ * Copyright (c) 2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_SYSTEM_ABILITY_LOAD_CALLBACK_STUB_H -+#define SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_SYSTEM_ABILITY_LOAD_CALLBACK_STUB_H -+ -+#include "iremote_stub.h" -+#include "isystem_ability_load_callback.h" -+ -+namespace OHOS { -+class SystemAbilityLoadCallbackStub : public IRemoteStub { -+public: -+ int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; -+ -+private: -+ static bool CheckInputSystemAbilityId(int32_t systemAbilityId); -+ static bool EnforceInterceToken(MessageParcel& data); -+ -+ int32_t OnLoadSystemAbilitySuccessInner(MessageParcel& data, MessageParcel& reply); -+ int32_t OnLoadSystemAbilityFailInner(MessageParcel& data, MessageParcel& reply); -+}; -+} -+#endif /* SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_SYSTEM_ABILITY_LOAD_CALLBACK_STUB_H */ -diff --git a/ohos_ndk_aosp/includes/system_ability/system_ability_manager_proxy.h b/ohos_ndk_aosp/includes/system_ability/system_ability_manager_proxy.h -new file mode 100755 -index 0000000000..93304fa70d ---- /dev/null -+++ b/ohos_ndk_aosp/includes/system_ability/system_ability_manager_proxy.h -@@ -0,0 +1,59 @@ -+/* -+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+ -+#ifndef INTERFACES_INNERKITS_SAMGR_INCLUDE_SYSTEM_ABILITY_MANAGER_PROXY_H_ -+#define INTERFACES_INNERKITS_SAMGR_INCLUDE_SYSTEM_ABILITY_MANAGER_PROXY_H_ -+ -+#include -+#include "if_system_ability_manager.h" -+ -+namespace OHOS { -+class SystemAbilityManagerProxy : public IRemoteProxy { -+public: -+ explicit SystemAbilityManagerProxy(const sptr& impl) -+ : IRemoteProxy(impl) {} -+ ~SystemAbilityManagerProxy() = default; -+ std::vector ListSystemAbilities(unsigned int dumpFlags) override; -+ -+ // IntToString adapter interface -+ sptr GetSystemAbility(int32_t systemAbilityId) override; -+ sptr CheckSystemAbility(int32_t systemAbilityId) override; -+ int32_t RemoveSystemAbility(int32_t systemAbilityId) override; -+ int32_t SubscribeSystemAbility(int32_t systemAbilityId, const sptr& listener) override; -+ int32_t UnSubscribeSystemAbility(int32_t systemAbilityId, -+ const sptr &listener) override; -+ sptr GetSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; -+ sptr CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; -+ int32_t AddOnDemandSystemAbilityInfo(int32_t systemAbilityId, -+ const std::u16string& localAbilityManagerName) override; -+ sptr CheckSystemAbility(int32_t systemAbilityId, bool& isExist) override; -+ int32_t AddSystemAbility(int32_t systemAbilityId, const sptr& ability, -+ const SAExtraProp& extraProp) override; -+ -+ int32_t AddSystemProcess(const std::u16string& procName, const sptr& procObject) override; -+ int32_t LoadSystemAbility(int32_t systemAbilityId, const sptr& callback) override; -+private: -+ sptr GetSystemAbilityWrapper(int32_t systemAbilityId, const std::string& deviceId = ""); -+ sptr CheckSystemAbilityWrapper(int32_t code, MessageParcel& data); -+ int32_t MarshalSAExtraProp(const SAExtraProp& extraProp, MessageParcel& data) const; -+ int32_t AddSystemAbilityWrapper(int32_t code, MessageParcel& data); -+ int32_t RemoveSystemAbilityWrapper(int32_t code, MessageParcel& data); -+private: -+ static inline BrokerDelegator delegator_; -+}; -+} // namespace OHOS -+ -+#endif // !defined(INTERFACES_INNERKITS_SAMGR_INCLUDE_SYSTEM_ABILITY_MANAGER_PROXY_H_) -diff --git a/ohos_ndk_aosp/includes/system_ability/system_ability_status_change_stub.h b/ohos_ndk_aosp/includes/system_ability/system_ability_status_change_stub.h -new file mode 100755 -index 0000000000..e2205eef95 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/system_ability/system_ability_status_change_stub.h -@@ -0,0 +1,44 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_SYSTEM_ABILITY_STATUS_CHANGE_STUB_H_ -+#define SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_SYSTEM_ABILITY_STATUS_CHANGE_STUB_H_ -+ -+#include -+#include "iremote_stub.h" -+#include "isystem_ability_status_change.h" -+ -+namespace OHOS { -+class SystemAbilityStatusChangeStub : public IRemoteStub { -+public: -+ SystemAbilityStatusChangeStub(); -+ ~SystemAbilityStatusChangeStub() = default; -+ int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; -+ -+protected: -+ static bool CheckInputSysAbilityId(int32_t systemAbilityId); -+ -+private: -+ int32_t OnAddSystemAbilityInner(MessageParcel& data, MessageParcel& reply); -+ int32_t OnRemoveSystemAbilityInner(MessageParcel& data, MessageParcel& reply); -+ static bool CanRequest(); -+ static bool EnforceInterceToken(MessageParcel& data); -+ -+ using SystemAbilityStatusChangeStubFunc = -+ int32_t (SystemAbilityStatusChangeStub::*)(MessageParcel& data, MessageParcel& reply); -+ std::map memberFuncMap_; -+}; -+} -+#endif /* SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_SYSTEM_ABILITY_STATUS_CHANGE_STUB_H_ */ -diff --git a/ohos_ndk_aosp/includes/utils/ashmem.h b/ohos_ndk_aosp/includes/utils/ashmem.h -new file mode 100755 -index 0000000000..82a57000d9 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/ashmem.h -@@ -0,0 +1,56 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_BASE_ASHMEM_H -+#define UTILS_BASE_ASHMEM_H -+ -+#include -+#include -+#include "refbase.h" -+#include "parcel.h" -+ -+namespace OHOS { -+int AshmemCreate(const char *name, size_t size); -+int AshmemSetProt(int fd, int prot); -+int AshmemGetSize(int fd); -+ -+class Ashmem : public virtual RefBase { -+public: -+ static sptr CreateAshmem(const char *name, int32_t size); -+ void CloseAshmem(); -+ bool MapAshmem(int mapType); -+ bool MapReadAndWriteAshmem(); -+ bool MapReadOnlyAshmem(); -+ void UnmapAshmem(); -+ bool SetProtection(int protectionType); -+ int GetProtection(); -+ int32_t GetAshmemSize(); -+ bool WriteToAshmem(const void *data, int32_t size, int32_t offset); -+ const void *ReadFromAshmem(int32_t size, int32_t offset); -+ Ashmem(int fd, int32_t size); -+ ~Ashmem(); -+ int GetAshmemFd() const -+ { -+ return memoryFd_; -+ }; -+private: -+ int memoryFd_; -+ int32_t memorySize_; -+ int flag_; -+ void *startAddr_; -+ bool CheckValid(int32_t size, int32_t offset, int cmd); -+}; -+} // namespace OHOS -+#endif -diff --git a/ohos_ndk_aosp/includes/utils/common_errors.h b/ohos_ndk_aosp/includes/utils/common_errors.h -new file mode 100755 -index 0000000000..cf0634d829 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/common_errors.h -@@ -0,0 +1,43 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_COMMON_ERRORS_H -+#define UTILS_COMMON_ERRORS_H -+ -+namespace OHOS { -+namespace Utils { -+ -+/** -+ * ErrCode layout -+ * -+ * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ -+ * | Bit |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00| -+ * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ -+ * |Field|Reserved| Subsystem | Module | Code | -+ * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ -+ * -+ * In this file, subsystem is "SUBSYS_COMMON". -+ */ -+ -+enum { -+ MODULE_DEFAULT = 0, -+ MODULE_TIMER = 1 -+ // new module -+}; -+ -+} // Utils -+} // OHOS -+ -+#endif -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/utils/common_timer_errors.h b/ohos_ndk_aosp/includes/utils/common_timer_errors.h -new file mode 100755 -index 0000000000..768ed99589 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/common_timer_errors.h -@@ -0,0 +1,53 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_COMMON_TIMER_ERRORS_H -+#define UTILS_COMMON_TIMER_ERRORS_H -+ -+#include -+#include "errors.h" -+#include "common_errors.h" -+ -+namespace OHOS { -+namespace Utils { -+ -+/** -+ * ErrCode layout -+ * -+ * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ -+ * | Bit |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00| -+ * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ -+ * |Field|Reserved| Subsystem | Module | Code | -+ * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ -+ * -+ * In this file, subsystem is "SUBSYS_COMMON" and module is "MODULE_TIMER". -+ */ -+ -+using ErrCode = int; -+ -+// offset of timer module error, only be used in this file. -+constexpr ErrCode COMMON_TIMER_ERR_OFFSET = ErrCodeOffset(SUBSYS_COMMON, MODULE_TIMER); -+ -+enum { -+ TIMER_ERR_OK = 0, -+ TIMER_ERR_DEAL_FAILED = COMMON_TIMER_ERR_OFFSET + EAGAIN, -+ TIMER_ERR_BADF = COMMON_TIMER_ERR_OFFSET + EBADF, -+ TIMER_ERR_INVALID_VALUE = COMMON_TIMER_ERR_OFFSET + EINVAL -+}; -+ -+} // Utils -+} // OHOS -+ -+#endif -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/utils/datetime_ex.h b/ohos_ndk_aosp/includes/utils/datetime_ex.h -new file mode 100755 -index 0000000000..e37cc9aa46 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/datetime_ex.h -@@ -0,0 +1,105 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef DATETIME_EX_H -+#define DATETIME_EX_H -+ -+#include -+#include -+namespace OHOS { -+ -+constexpr int64_t SEC_TO_NANOSEC = 1000000000; -+constexpr int64_t SEC_TO_MICROSEC = 1000000; -+constexpr int64_t SEC_TO_MILLISEC = 1000; -+constexpr int64_t MILLISEC_TO_NANOSEC = 1000000; -+constexpr int64_t MICROSEC_TO_NANOSEC = 1000; -+ -+constexpr int SECONDS_PER_HOUR = 3600; // 60 * 60 -+constexpr int SECONDS_PER_DAY = 86400; // 60 * 60 * 24 -+ -+static constexpr inline int64_t SecToNanosec(int64_t sec) -+{ -+ return sec * SEC_TO_NANOSEC; -+} -+ -+static constexpr inline int64_t MillisecToNanosec(int64_t millise) -+{ -+ return millise * MILLISEC_TO_NANOSEC; -+} -+ -+static constexpr inline int64_t MicrosecToNanosec(int64_t microsec) -+{ -+ return microsec * MICROSEC_TO_NANOSEC; -+} -+ -+static constexpr inline int64_t NanosecToSec(int64_t nanosec) -+{ -+ return nanosec / SEC_TO_NANOSEC; -+} -+ -+static constexpr inline int64_t NanosecToMillisec(int64_t nanosec) -+{ -+ return nanosec / MILLISEC_TO_NANOSEC; -+} -+ -+static constexpr inline int64_t NanosecToMicrosec(int64_t nanosec) -+{ -+ return nanosec / MICROSEC_TO_NANOSEC; -+} -+ -+/** -+ * The GetSecondsSince1970ToNow function get seconds from 1970 to now -+ */ -+int64_t GetSecondsSince1970ToNow(); -+ -+/** -+ * The GetSecondsSince1970ToPointTime function get seconds from 1970 to inputtime -+ */ -+int64_t GetSecondsSince1970ToPointTime(struct tm inputTm); -+ -+/** -+ * The GetSecondsBetween function get seconds between inputTm1 and inputTm2. -+ */ -+int64_t GetSecondsBetween(struct tm inputTm1, struct tm inputTm2); -+ -+/** -+ * The GetDaysSince1970ToNow function get days from 1970 to now. -+ */ -+int64_t GetDaysSince1970ToNow(); -+ -+/** -+ * The GetLocalTimeZone function get current timezone, -+ * return true if get success, else false. -+ */ -+bool GetLocalTimeZone(int& timezone); -+ -+/** -+* The GetSystemCurrentTime function get current time, -+* return true if get success, else false. -+*/ -+bool GetSystemCurrentTime(struct tm* curTime); -+ -+/** -+* The GetTickCount function get current milliseconds since the system was started. -+*/ -+int64_t GetTickCount(); -+ -+/** -+* The GetMicroTickCount function get current microseconds since the system was started. -+*/ -+int64_t GetMicroTickCount(); -+} -+ -+#endif -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/utils/directory_ex.h b/ohos_ndk_aosp/includes/utils/directory_ex.h -new file mode 100755 -index 0000000000..3721cb6fa2 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/directory_ex.h -@@ -0,0 +1,114 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef DIRECTORY_EX_H -+#define DIRECTORY_EX_H -+ -+#include -+#include -+#include -+ -+namespace OHOS { -+ -+/** -+ * The GetCurrentProcFullFileName function get the current process exe name. -+ */ -+std::string GetCurrentProcFullFileName(); -+ -+/** -+ * The GetCurrentProcPath function get the current process exe path. -+ */ -+std::string GetCurrentProcPath(); -+ -+/** -+ * The ExtractFilePath function extract the input file path. -+ */ -+std::string ExtractFilePath(const std::string& fileFullName); -+ -+/** -+ * The ExtractFilePath function extract the input file name. -+ */ -+std::string ExtractFileName(const std::string& fileFullName); -+ -+/** -+ * The ExtractFileExt function extract the input file name type. -+ */ -+std::string ExtractFileExt(const std::string& fileName); -+ -+/** -+ * The ExcludeTrailingPathDelimiter function exclude the end '/' from the strPath, -+ * return the path without the end '/'. -+ */ -+std::string ExcludeTrailingPathDelimiter(const std::string& path); -+ -+/** -+ * The IncludeTrailingPathDelimiter function include the end '/' from the strPath, -+ * return the path with the end '/'. -+ */ -+std::string IncludeTrailingPathDelimiter(const std::string& path); -+ -+/** -+ * The GetDirFiles function get all files in the path. -+ */ -+void GetDirFiles(const std::string& path, std::vector& files); -+ -+/** -+ * The IsEmptyFolder function judge the path is empty, -+ * return true if is empty, else false. -+ */ -+bool IsEmptyFolder(const std::string& path); -+ -+/** -+ * The ForceCreateDirectory function is force create the dir with subdir, -+ * return true if create succ, else false. -+ */ -+bool ForceCreateDirectory(const std::string& path); -+ -+/** -+ * The ForceRemoveDirectory function is force delete the dir with subdir and files, -+ * return true if remove succ, else false. -+ */ -+bool ForceRemoveDirectory(const std::string& path); -+ -+/** -+ * The RemoveFile function is remove the input strFileName, -+ * return true if remove succ, else false. -+ */ -+bool RemoveFile(const std::string& fileName); -+ -+/** -+ * The GetFolderSize function is get the folder size(bytes). -+ */ -+uint64_t GetFolderSize(const std::string& path); -+ -+/** -+ * The ChangeModeFile function is change the input file authority, -+ * return true if change succ, else false. -+ */ -+bool ChangeModeFile(const std::string& fileName, const mode_t& mode); -+ -+/** -+ * The ChangeModeDirectory function is change the input Directory authority, include subdir, -+ * return true if change succ, else false. -+ */ -+bool ChangeModeDirectory(const std::string& path, const mode_t& mode); -+ -+/** -+* The PathToRealPath function is get real path from relative path, -+* return true if change succ, else false. -+*/ -+bool PathToRealPath(const std::string& path, std::string& realPath); -+} // OHOS -+#endif -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/utils/errors.h b/ohos_ndk_aosp/includes/utils/errors.h -new file mode 100755 -index 0000000000..305bb10c05 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/errors.h -@@ -0,0 +1,119 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_BASE_ERRORS_H -+#define UTILS_BASE_ERRORS_H -+ -+#include -+ -+namespace OHOS { -+ -+/** -+ * ErrCode layout -+ * -+ * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ -+ * | Bit |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00| -+ * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ -+ * |Field|Reserved| Subsystem | Module | Code | -+ * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ -+ */ -+ -+using ErrCode = int; -+ -+enum { -+ SUBSYS_COMMON = 0, -+ SUBSYS_AAFWK = 1, -+ SUBSYS_ACCOUNT = 2, -+ SUBSYS_AI = 3, -+ SUBSYS_APPEXECFWK = 4, -+ SUBSYS_APPLICATIONS = 5, -+ SUBSYS_ARVR = 6, -+ SUBSYS_ARVRHARDWARE = 7, -+ SUBSYS_BARRIERFREE = 8, -+ SUBSYS_BIOMETRICS = 9, -+ SUBSYS_CCRUNTIME = 10, -+ SUBSYS_COMMUNICATION = 11, -+ SUBSYS_DFX = 12, -+ SUBSYS_DISTRIBUTEDDATAMNG = 13, -+ SUBSYS_DISTRIBUTEDSCHEDULE = 14, -+ SUBSYS_DRIVERS = 15, -+ SUBSYS_GLOBAL = 16, -+ SUBSYS_GRAPHIC = 17, -+ SUBSYS_HBS = 18, -+ SUBSYS_IAWARE = 19, -+ SUBSYS_IDE = 20, -+ SUBSYS_INTELLIACCESSORIES = 21, -+ SUBSYS_INTELLISPEAKER = 22, -+ SUBSYS_INTELLITV = 23, -+ SUBSYS_IOT = 24, -+ SUBSYS_IOTHARDWARE = 25, -+ SUBSYS_IVIHARDWARE = 26, -+ SUBSYS_KERNEL = 27, -+ SUBSYS_LOCATION = 28, -+ SUBSYS_MSDP = 29, -+ SUBSYS_MULTIMEDIA = 30, -+ SUBSYS_MULTIMODAINPUT = 31, -+ SUBSYS_NOTIFICATION = 32, -+ SUBSYS_POWERMNG = 33, -+ SUBSYS_ROUTER = 34, -+ SUBSYS_SECURITY = 35, -+ SUBSYS_SENSORS = 36, -+ SUBSYS_SMALLSERVICES = 37, -+ SUBSYS_SOURCECODETRANSFORMER = 38, -+ SUBSYS_STARTUP = 39, -+ SUBSYS_TELEPONY = 40, -+ SUBSYS_UPDATE = 41, -+ SUBSYS_USB = 42, -+ SUBSYS_WEARABLE = 43, -+ SUBSYS_WEARABLEHARDWARE = 44, -+ SUBSYS_IVI = 45, -+ SUBSYS_DISTRIBUTEDHARDWARE = 46, -+ SUBSYS_DEVICEPROFILE = 47 -+ // new type -+}; -+ -+// be used to init the subsystem errorno. -+constexpr ErrCode ErrCodeOffset(unsigned int subsystem, unsigned int module = 0) -+{ -+ constexpr int SUBSYSTEM_BIT_NUM = 21; -+ constexpr int MODULE_BIT_NUM = 16; -+ return (subsystem << SUBSYSTEM_BIT_NUM) | (module << MODULE_BIT_NUM); -+} -+ -+// offset of common error, only be used in this file. -+constexpr ErrCode BASE_ERR_OFFSET = ErrCodeOffset(SUBSYS_COMMON); -+ -+enum { -+ ERR_OK = 0, -+ ERR_NO_MEMORY = BASE_ERR_OFFSET + ENOMEM, -+ ERR_INVALID_OPERATION = BASE_ERR_OFFSET + ENOSYS, -+ ERR_INVALID_VALUE = BASE_ERR_OFFSET + EINVAL, -+ ERR_NAME_NOT_FOUND = BASE_ERR_OFFSET + ENOENT, -+ ERR_PERMISSION_DENIED = BASE_ERR_OFFSET + EPERM, -+ ERR_NO_INIT = BASE_ERR_OFFSET + ENODEV, -+ ERR_ALREADY_EXISTS = BASE_ERR_OFFSET + EEXIST, -+ ERR_DEAD_OBJECT = BASE_ERR_OFFSET + EPIPE, -+ ERR_OVERFLOW = BASE_ERR_OFFSET + EOVERFLOW, -+ ERR_ENOUGH_DATA = BASE_ERR_OFFSET + ENODATA, -+ ERR_WOULD_BLOCK = BASE_ERR_OFFSET + EWOULDBLOCK, -+ ERR_TIMED_OUT = BASE_ERR_OFFSET + ETIMEDOUT -+}; -+ -+#define SUCCEEDED(errCode) ((errCode) == ERR_OK) -+#define FAILED(errCode) ((errCode) != ERR_OK) -+ -+} -+ -+#endif -diff --git a/ohos_ndk_aosp/includes/utils/file_ex.h b/ohos_ndk_aosp/includes/utils/file_ex.h -new file mode 100644 -index 0000000000..d9de3077e1 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/file_ex.h -@@ -0,0 +1,36 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_BASE_FILE_EX_H -+#define UTILS_BASE_FILE_EX_H -+ -+#include -+#include -+ -+namespace OHOS { -+ -+bool LoadStringFromFile(const std::string& filePath, std::string& content); -+bool SaveStringToFile(const std::string& filePath, const std::string& content, bool truncated = true); -+bool LoadStringFromFd(int fd, std::string& content); -+bool SaveStringToFd(int fd, const std::string& content); -+bool LoadBufferFromFile(const std::string& filePath, std::vector& content); -+bool SaveBufferToFile(const std::string& filePath, const std::vector& content, bool truncated = true); -+bool FileExists(const std::string& fileName); -+bool StringExistsInFile(const std::string& fileName, const std::string& subStr, bool caseSensitive = true); -+int CountStrInFile(const std::string& fileName, const std::string& subStr, bool caseSensitive = true); -+ -+} -+ -+#endif -diff --git a/ohos_ndk_aosp/includes/utils/flat_obj.h b/ohos_ndk_aosp/includes/utils/flat_obj.h -new file mode 100755 -index 0000000000..771a7c236e ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/flat_obj.h -@@ -0,0 +1,43 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_BASE_FLAT_OBJ_H -+#define UTILS_BASE_FLAT_OBJ_H -+ -+#include -+#include -+ -+#ifdef BINDER_IPC_32BIT -+ typedef __u32 binder_size_t; -+ typedef __u32 binder_uintptr_t; -+#else -+ typedef __u64 binder_size_t; -+ typedef __u64 binder_uintptr_t; -+#endif -+ -+struct parcel_binder_object_header { -+ __u32 type; -+}; -+struct parcel_flat_binder_object { -+ struct parcel_binder_object_header hdr; -+ __u32 flags; -+ union { -+ binder_uintptr_t binder; -+ __u32 handle; -+ }; -+ binder_uintptr_t cookie; -+}; -+ -+#endif -\ No newline at end of file -diff --git a/ohos_ndk_aosp/includes/utils/nocopyable.h b/ohos_ndk_aosp/includes/utils/nocopyable.h -new file mode 100644 -index 0000000000..626451aa57 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/nocopyable.h -@@ -0,0 +1,45 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_BASE_NOCOPYABLE_H -+#define UTILS_BASE_NOCOPYABLE_H -+ -+namespace OHOS { -+ -+#define DISALLOW_COPY_AND_MOVE(className)\ -+ DISALLOW_COPY(className);\ -+ DISALLOW_MOVE(className) -+ -+#define DISALLOW_COPY(className)\ -+ className(const className&) = delete;\ -+ className& operator= (const className&) = delete -+ -+#define DISALLOW_MOVE(className)\ -+ className(className&&) = delete;\ -+ className& operator= (className&&) = delete -+ -+ -+class NoCopyable { -+protected: -+ NoCopyable() {}; -+ virtual ~NoCopyable() {}; -+ -+private: -+ DISALLOW_COPY_AND_MOVE(NoCopyable); -+}; -+ -+} -+ -+#endif -diff --git a/ohos_ndk_aosp/includes/utils/observer.h b/ohos_ndk_aosp/includes/utils/observer.h -new file mode 100644 -index 0000000000..13e66830fe ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/observer.h -@@ -0,0 +1,66 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_BASE_OBSERVER_H -+#define UTILS_BASE_OBSERVER_H -+ -+#include -+#include -+#include -+#include -+ -+namespace OHOS { -+ -+ -+struct ObserverArg { -+public: -+ virtual ~ObserverArg() = default; -+}; -+ -+class Observer; -+class Observable { -+public: -+ virtual ~Observable() = default; -+ void AddObserver(const std::shared_ptr& o); -+ void RemoveObserver(const std::shared_ptr& o); -+ void RemoveAllObservers(); -+ void NotifyObservers(); -+ void NotifyObservers(const ObserverArg* arg); -+ int GetObserversCount(); -+ -+protected: -+ bool HasChanged(); -+ void SetChanged(); -+ void ClearChanged(); -+ -+protected: -+ std::set> obs; -+ std::mutex mutex_; -+ -+private: -+ bool changed_ = false; -+}; -+ -+class Observer { -+public: -+ virtual ~Observer() = default; -+ virtual void Update(const Observable* o, const ObserverArg* arg) = 0; -+}; -+ -+ -+} -+ -+#endif -+ -diff --git a/ohos_ndk_aosp/includes/utils/parcel.h b/ohos_ndk_aosp/includes/utils/parcel.h -new file mode 100755 -index 0000000000..3f752d548a ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/parcel.h -@@ -0,0 +1,393 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef OHOS_UTILS_PARCEL_H -+#define OHOS_UTILS_PARCEL_H -+ -+#include -+#include -+#include "nocopyable.h" -+#include "refbase.h" -+#include "flat_obj.h" -+ -+namespace OHOS { -+ -+class Parcel; -+ -+class Parcelable : public virtual RefBase { -+public: -+ virtual ~Parcelable() = default; -+ -+ Parcelable(); -+ explicit Parcelable(bool asRemote); -+ -+ // Write a parcelable object to the given parcel. -+ // The object position is saved into Parcel if set asRemote_ to -+ // true, and this intends to use in kernel data transaction. -+ // Returns true being written on success or false if any error occur. -+ virtual bool Marshalling(Parcel &parcel) const = 0; -+ -+ // NOTICE! A static Unmarshalling function must also be implemented, so -+ // that you can get data from the given parcel into this parcelable object. -+ // See "static TestParcelable *Unmarshalling(Parcel &parcel)" as an example. -+ -+ enum BehaviorFlag { IPC = 0x01, RPC = 0x02, HOLD_OBJECT = 0x10 }; -+ -+ inline void SetBehavior(BehaviorFlag b) const -+ { -+ behavior_ |= static_cast(b); -+ } -+ -+ inline void ClearBehavior(BehaviorFlag b) const -+ { -+ behavior_ &= ~(static_cast(b)); -+ } -+ -+ inline bool TestBehavior(BehaviorFlag b) const -+ { -+ return behavior_ & (static_cast(b)); -+ } -+ -+public: -+ bool asRemote_; -+ mutable uint8_t behavior_; -+}; -+ -+class Allocator { -+public: -+ virtual ~Allocator() = default; -+ -+ virtual void *Realloc(void *data, size_t newSize) = 0; -+ -+ virtual void *Alloc(size_t size) = 0; -+ -+ virtual void Dealloc(void *data) = 0; -+}; -+ -+class DefaultAllocator : public Allocator { -+public: -+ virtual void *Alloc(size_t size) override; -+ -+ virtual void Dealloc(void *data) override; -+private: -+ virtual void *Realloc(void *data, size_t newSize) override; -+}; -+ -+class Parcel { -+public: -+ Parcel(); -+ explicit Parcel(Allocator *allocator); -+ -+ virtual ~Parcel(); -+ -+ size_t GetDataSize() const; -+ -+ uintptr_t GetData() const; -+ -+ binder_size_t GetObjectOffsets() const; -+ -+ size_t GetOffsetsSize() const; -+ -+ size_t GetWritableBytes() const; -+ -+ size_t GetReadableBytes() const; -+ -+ size_t GetDataCapacity() const; -+ -+ bool SetDataCapacity(size_t newCapacity); -+ -+ bool SetDataSize(size_t dataSize); -+ -+ bool SetMaxCapacity(size_t maxCapacity); -+ -+ bool WriteBool(bool value); -+ -+ bool WriteInt8(int8_t value); -+ -+ bool WriteInt16(int16_t value); -+ -+ bool WriteInt32(int32_t value); -+ -+ bool WriteInt64(int64_t value); -+ -+ bool WriteUint8(uint8_t value); -+ -+ bool WriteUint16(uint16_t value); -+ -+ bool WriteUint32(uint32_t value); -+ -+ bool WriteUint64(uint64_t value); -+ -+ bool WriteFloat(float value); -+ -+ bool WriteDouble(double value); -+ -+ bool WritePointer(uintptr_t value); -+ -+ bool WriteBuffer(const void *data, size_t size); -+ -+ bool WriteBufferAddTerminator(const void *data, size_t size, size_t typeSize); -+ -+ bool WriteUnpadBuffer(const void *data, size_t size); -+ -+ bool WriteCString(const char *value); -+ -+ bool WriteString(const std::string &value); -+ -+ bool WriteString16(const std::u16string &value); -+ -+ bool WriteString16WithLength(const char16_t *value, size_t len); -+ -+ bool WriteString8WithLength(const char *value, size_t len); -+ -+ bool WriteParcelable(const Parcelable *object); -+ -+ bool WriteStrongParcelable(const sptr &object); -+ -+ bool WriteRemoteObject(const Parcelable *object); -+ -+ template -+ bool WriteObject(const sptr &object); -+ -+ bool ParseFrom(uintptr_t data, size_t size); -+ -+ bool ReadBool(); -+ -+ int8_t ReadInt8(); -+ -+ int16_t ReadInt16(); -+ -+ int32_t ReadInt32(); -+ -+ int64_t ReadInt64(); -+ -+ uint8_t ReadUint8(); -+ -+ uint16_t ReadUint16(); -+ -+ uint32_t ReadUint32(); -+ -+ uint64_t ReadUint64(); -+ -+ float ReadFloat(); -+ -+ double ReadDouble(); -+ -+ uintptr_t ReadPointer(); -+ -+ bool ReadBool(bool &value); -+ -+ bool ReadInt8(int8_t &value); -+ -+ bool ReadInt16(int16_t &value); -+ -+ bool ReadInt32(int32_t &value); -+ -+ bool ReadInt64(int64_t &value); -+ -+ bool ReadUint8(uint8_t &value); -+ -+ bool ReadUint16(uint16_t &value); -+ -+ bool ReadUint32(uint32_t &value); -+ -+ bool ReadUint64(uint64_t &value); -+ -+ bool ReadFloat(float &value); -+ -+ bool ReadDouble(double &value); -+ -+ const uint8_t *ReadBuffer(size_t length); -+ -+ const uint8_t *ReadUnpadBuffer(size_t length); -+ -+ void SkipBytes(size_t bytes); -+ -+ const char *ReadCString(); -+ -+ const std::string ReadString(); -+ -+ bool ReadString(std::string &value); -+ -+ const std::u16string ReadString16(); -+ -+ bool ReadString16(std::u16string &value); -+ -+ const std::u16string ReadString16WithLength(int32_t &len); -+ -+ const std::string ReadString8WithLength(int32_t &len); -+ -+ bool RewindRead(size_t newPosition); -+ -+ bool RewindWrite(size_t offsets); -+ -+ size_t GetReadPosition(); -+ -+ size_t GetWritePosition(); -+ -+ template -+ T *ReadParcelable(); -+ -+ template -+ sptr ReadStrongParcelable(); -+ -+ bool CheckOffsets(); -+ -+ template -+ sptr ReadObject(); -+ -+ bool SetAllocator(Allocator *allocator); -+ -+ void InjectOffsets(binder_size_t offsets, size_t offsetSize); -+ -+ void FlushBuffer(); -+ -+ template -+ bool WriteVector(const std::vector &val, bool (Parcel::*Write)(T2)); -+ bool WriteBoolVector(const std::vector &val); -+ bool WriteInt8Vector(const std::vector &val); -+ bool WriteInt16Vector(const std::vector &val); -+ bool WriteInt32Vector(const std::vector &val); -+ bool WriteInt64Vector(const std::vector &val); -+ bool WriteUInt8Vector(const std::vector &val); -+ bool WriteUInt16Vector(const std::vector &val); -+ bool WriteUInt32Vector(const std::vector &val); -+ bool WriteUInt64Vector(const std::vector &val); -+ bool WriteFloatVector(const std::vector &val); -+ bool WriteDoubleVector(const std::vector &val); -+ bool WriteStringVector(const std::vector &val); -+ bool WriteString16Vector(const std::vector &val); -+ -+ template -+ bool ReadVector(std::vector *val, bool (Parcel::*Read)(T &)); -+ bool ReadBoolVector(std::vector *val); -+ bool ReadInt8Vector(std::vector *val); -+ bool ReadInt16Vector(std::vector *val); -+ bool ReadInt32Vector(std::vector *val); -+ bool ReadInt64Vector(std::vector *val); -+ bool ReadUInt8Vector(std::vector *val); -+ bool ReadUInt16Vector(std::vector *val); -+ bool ReadUInt32Vector(std::vector *val); -+ bool ReadUInt64Vector(std::vector *val); -+ bool ReadFloatVector(std::vector *val); -+ bool ReadDoubleVector(std::vector *val); -+ bool ReadStringVector(std::vector *val); -+ bool ReadString16Vector(std::vector *val); -+ -+ bool WriteBoolUnaligned(bool value); -+ bool WriteInt8Unaligned(int8_t value); -+ bool WriteInt16Unaligned(int16_t value); -+ bool WriteUint8Unaligned(uint8_t value); -+ bool WriteUint16Unaligned(uint16_t value); -+ -+ bool ReadBoolUnaligned(); -+ bool ReadInt8Unaligned(int8_t &value); -+ bool ReadInt16Unaligned(int16_t &value); -+ bool ReadUint8Unaligned(uint8_t &value); -+ bool ReadUint16Unaligned(uint16_t &value); -+ -+private: -+ DISALLOW_COPY_AND_MOVE(Parcel); -+ template -+ bool Write(T value); -+ -+ template -+ bool Read(T &value); -+ -+ template -+ T Read(); -+ -+ template -+ bool ReadPadded(T &value); -+ -+ inline size_t GetPadSize(size_t size) -+ { -+ const int SIZE_OFFSET = 3; -+ return (((size + SIZE_OFFSET) & (~SIZE_OFFSET)) - size); -+ } -+ -+ bool WriteObjectOffset(binder_size_t offset); -+ -+ size_t CalcNewCapacity(size_t minCapacity); -+ -+ bool WriteDataBytes(const void *data, size_t size); -+ -+ void WritePadBytes(size_t padded); -+ -+ bool EnsureWritableCapacity(size_t desireCapacity); -+ -+ bool EnsureObjectsCapacity(); -+ -+ bool WriteParcelableOffset(size_t offset); -+ -+private: -+ uint8_t *data_; -+ size_t readCursor_; -+ size_t writeCursor_; -+ size_t dataSize_; -+ size_t dataCapacity_; -+ size_t maxDataCapacity_; -+ binder_size_t *objectOffsets_; -+ size_t objectCursor_; -+ size_t objectsCapacity_; -+ Allocator *allocator_; -+ std::vector> objectHolder_; -+ bool writable_ = true; -+}; -+ -+template -+bool Parcel::WriteObject(const sptr &object) -+{ -+ if (object == nullptr) { -+ return T::Marshalling(*this, object); -+ } -+ return WriteRemoteObject(object.GetRefPtr()); -+} -+ -+template -+sptr Parcel::ReadObject() -+{ -+ if (!this->CheckOffsets()) { -+ return nullptr; -+ } -+ return T::Unmarshalling(*this); -+} -+ -+// Read data from the given parcel into this parcelable object. -+template -+T *Parcel::ReadParcelable() -+{ -+ int32_t size = this->ReadInt32(); -+ if (size == 0) { -+ return nullptr; -+ } -+ -+ return T::Unmarshalling(*this); -+} -+ -+// Read data from the given parcel into this parcelable object, return sptr. -+template -+sptr Parcel::ReadStrongParcelable() -+{ -+ int32_t size = this->ReadInt32(); -+ if (size == 0) { -+ return nullptr; -+ } -+ -+ return T::Unmarshalling(*this); -+} -+ -+} // namespace OHOS -+#endif -diff --git a/ohos_ndk_aosp/includes/utils/pubdef.h b/ohos_ndk_aosp/includes/utils/pubdef.h -new file mode 100755 -index 0000000000..ebfdcab8b4 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/pubdef.h -@@ -0,0 +1,54 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_BASE_PUBDEF_H -+#define UTILS_BASE_PUBDEF_H -+ -+namespace OHOS { -+ -+#define B_TO_M(b) ((b) / 1024 / 1024) -+#define M_TO_B(m) ((m) * 1024 * 1024) -+#define B_TO_K(b) ((b) / 1024) -+#define K_TO_B(m) ((m) * 1024) -+ -+#define HOUR_TO_SECOND(h) ((h) * 3600) -+#define SECOND_TO_HOUR(s) ((s) / 3600) -+ -+#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a[0]))) -+ -+#define FREE_AND_NIL(p) do { if (p) { delete (p); (p) = nullptr; } } while(0) -+#define FREE_AND_NIL_ARRAY(p) do { if (p) { delete[] (p); (p) = nullptr; } } while(0) -+ -+#define MAX(x, y) (((x) > (y)) ? (x) : (y)) -+#define MIN(x, y) (((x) < (y)) ? (x) : (y)) -+ -+#define EPS (1e-8) -+#define EQUAL_TO_ZERO(x) (fabs(x) <= (EPS)) -+ -+// Used to retry syscalls that can return EINTR. -+#ifndef TEMP_FAILURE_RETRY -+#define TEMP_FAILURE_RETRY(exp) \ -+ ({ \ -+ decltype(exp) _rc; \ -+ do { \ -+ _rc = (exp); \ -+ } while ((_rc == -1) && (errno == EINTR)); \ -+ _rc; \ -+ }) -+#endif -+} -+ -+#endif -+ -diff --git a/ohos_ndk_aosp/includes/utils/refbase.h b/ohos_ndk_aosp/includes/utils/refbase.h -new file mode 100755 -index 0000000000..4c4c24b3cf ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/refbase.h -@@ -0,0 +1,704 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_BASE_REFBASE_H -+#define UTILS_BASE_REFBASE_H -+ -+#include -+#include -+ -+namespace OHOS { -+ -+#define INITIAL_PRIMARY_VALUE (1 << 28) -+ -+class RefBase; -+ -+class RefCounter { -+public: -+ using RefPtrCallback = std::function; -+ friend class RefBase; -+ -+ RefCounter(); -+ -+ explicit RefCounter(RefCounter *counter); -+ -+ RefCounter &operator=(const RefCounter &counter); -+ -+ virtual ~RefCounter(); -+ -+ void SetCallback(const RefPtrCallback& callback); -+ -+ void RemoveCallback(); -+ -+ int GetRefCount(); -+ -+ void IncRefCount(); -+ -+ void DecRefCount(); -+ -+ bool IsRefPtrValid(); -+ -+ int IncStrongRefCount(const void *objectId); -+ -+ int DecStrongRefCount(const void *objectId); -+ -+ int GetStrongRefCount(); -+ -+ int IncWeakRefCount(const void *objectId); -+ -+ int DecWeakRefCount(const void *objectId); -+ -+ int GetWeakRefCount(); -+ -+ void SetAttemptAcquire(); -+ -+ bool IsAttemptAcquireSet(); -+ -+ void ClearAttemptAcquire(); -+ -+ bool AttemptIncStrongRef(const void *objectId, int &outCount); -+ -+ bool IsLifeTimeExtended(); -+ -+ void ExtendObjectLifetime(); -+ -+private: -+ std::atomic atomicStrong_; -+ std::atomic atomicWeak_; -+ std::atomic atomicRefCount_; -+ std::atomic atomicFlags_; -+ std::atomic atomicAttempt_; -+ RefPtrCallback callback_ = nullptr; -+ static constexpr unsigned int FLAG_EXTEND_LIFE_TIME = 0x00000002; -+}; -+ -+class WeakRefCounter { -+public: -+ WeakRefCounter(RefCounter *base, void *cookie); -+ -+ virtual ~WeakRefCounter(); -+ -+ void *GetRefPtr(); -+ -+ void IncWeakRefCount(const void *objectId); -+ -+ void DecWeakRefCount(const void *objectId); -+ -+ bool AttemptIncStrongRef(const void *objectId); -+ -+private: -+ std::atomic atomicWeak_; -+ RefCounter *refCounter_ = nullptr; -+ void *cookie_ = nullptr; -+}; -+ -+class RefBase { -+public: -+ RefBase(); -+ -+ RefBase(const RefBase &refbase); -+ -+ RefBase &operator=(const RefBase &refbase); -+ -+ RefBase(RefBase &&refbase) noexcept; -+ -+ RefBase &operator=(RefBase &&refbase) noexcept; -+ -+ virtual ~RefBase(); -+ -+ virtual void RefPtrCallback(); -+ -+ void ExtendObjectLifetime(); -+ -+ void IncStrongRef(const void *objectId); -+ -+ void DecStrongRef(const void *objectId); -+ -+ int GetSptrRefCount(); -+ -+ WeakRefCounter *CreateWeakRef(void *cookie); -+ -+ void IncWeakRef(const void *objectId); -+ -+ void DecWeakRef(const void *objectId); -+ -+ int GetWptrRefCount(); -+ -+ bool AttemptAcquire(const void *objectId); -+ -+ bool AttemptIncStrongRef(const void *objectId); -+ -+ bool IsAttemptAcquireSet(); -+ -+ bool IsExtendLifeTimeSet(); -+ -+ virtual void OnFirstStrongRef(const void *objectId); -+ -+ virtual void OnLastStrongRef(const void *objectId); -+ -+ virtual void OnLastWeakRef(const void *objectId); -+ -+ virtual bool OnAttemptPromoted(const void *objectId); -+ -+private: -+ RefCounter *refs_ = nullptr; -+}; -+ -+template -+class wptr; -+ -+template -+ -+class sptr { -+ friend class wptr; -+ -+public: -+ sptr(); -+ -+ ~sptr(); -+ -+ sptr(T *other); -+ -+ sptr(const sptr &other); -+ -+ sptr(sptr &&other); -+ -+ sptr &operator=(sptr &&other); -+ -+ template -+ sptr(const sptr &other); -+ -+ inline sptr(WeakRefCounter *p, bool force); -+ -+ inline T *GetRefPtr() const -+ { -+ return refs_; -+ } -+ -+ inline void ForceSetRefPtr(T *other); -+ -+ void clear(); -+ -+ inline operator T *() const -+ { -+ return refs_; -+ } -+ -+ inline T &operator*() const -+ { -+ return *refs_; -+ } -+ -+ inline T *operator->() const -+ { -+ return refs_; -+ } -+ -+ inline bool operator!() const -+ { -+ return refs_ == nullptr; -+ } -+ -+ sptr &operator=(T *other); -+ -+ sptr &operator=(const sptr &other); -+ -+ sptr &operator=(const wptr &other); -+ -+ template -+ sptr &operator=(const sptr &other); -+ -+ bool operator==(const T *other) const; -+ -+ inline bool operator!=(const T *other) const -+ { -+ return !operator==(other); -+ } -+ -+ bool operator==(const wptr &other) const; -+ -+ inline bool operator!=(const wptr &other) const -+ { -+ return !operator==(other); -+ } -+ -+ bool operator==(const sptr &other) const; -+ -+ inline bool operator!=(const sptr &other) const -+ { -+ return !operator==(other); -+ } -+ -+private: -+ T *refs_ = nullptr; -+}; -+ -+template -+inline void sptr::ForceSetRefPtr(T *other) -+{ -+ refs_ = other; -+} -+ -+template -+inline sptr::sptr() -+{ -+ refs_ = nullptr; -+} -+ -+template -+inline sptr::sptr(T *other) -+{ -+ refs_ = other; -+ if (refs_ != nullptr) { -+ refs_->IncStrongRef(this); -+ } -+} -+ -+template -+inline sptr::sptr(const sptr &other) -+{ -+ refs_ = other.GetRefPtr(); -+ if (refs_ != nullptr) { -+ refs_->IncStrongRef(this); -+ } -+} -+ -+template -+sptr::sptr(sptr &&other) -+{ -+ refs_ = other.GetRefPtr(); -+ other.ForceSetRefPtr(nullptr); -+} -+ -+template -+sptr &sptr::operator=(sptr &&other) -+{ -+ if (refs_ != nullptr) { -+ refs_->DecStrongRef(this); -+ } -+ refs_ = other.GetRefPtr(); -+ other.ForceSetRefPtr(nullptr); -+ return *this; -+} -+ -+template -+template -+sptr::sptr(const sptr &other) : refs_(other.GetRefPtr()) -+{ -+ if (refs_ != nullptr) { -+ refs_->IncStrongRef(this); -+ } -+} -+ -+template -+inline sptr &sptr::operator=(T *other) -+{ -+ if (other != nullptr) { -+ other->IncStrongRef(this); -+ } -+ -+ if (refs_ != nullptr) { -+ refs_->DecStrongRef(this); -+ } -+ -+ refs_ = other; -+ return *this; -+} -+ -+template -+inline sptr &sptr::operator=(const sptr &other) -+{ -+ T *otherRef(other.GetRefPtr()); -+ if (otherRef != nullptr) { -+ otherRef->IncStrongRef(this); -+ } -+ -+ if (refs_ != nullptr) { -+ refs_->DecStrongRef(this); -+ } -+ -+ refs_ = otherRef; -+ return *this; -+} -+ -+template -+inline sptr &sptr::operator=(const wptr &other) -+{ -+ if (refs_ != nullptr) { -+ refs_->DecStrongRef(this); -+ } -+ if ((other != nullptr) && other.AttemptIncStrongRef(this)) { -+ refs_ = other.GetRefPtr(); -+ } else { -+ refs_ = nullptr; -+ } -+ -+ return *this; -+} -+ -+template -+template -+sptr &sptr::operator=(const sptr &other) -+{ -+ T *otherRef(other.GetRefPtr()); -+ if (otherRef != nullptr) { -+ otherRef->IncStrongRef(this); -+ } -+ -+ if (refs_ != nullptr) { -+ refs_->DecStrongRef(this); -+ } -+ -+ refs_ = otherRef; -+ return *this; -+} -+ -+template -+inline bool sptr::operator==(const T *other) const -+{ -+ return other == refs_; -+} -+ -+template -+inline bool sptr::operator==(const wptr &other) const -+{ -+ return refs_ == other.GetRefPtr(); -+} -+ -+template -+inline bool sptr::operator==(const sptr &other) const -+{ -+ return refs_ == other.GetRefPtr(); -+} -+ -+template -+void sptr::clear() -+{ -+ if (refs_) { -+ refs_->DecStrongRef(this); -+ refs_ = 0; -+ } -+} -+ -+template -+inline sptr::~sptr() -+{ -+ if (refs_ != nullptr) { -+ refs_->DecStrongRef(this); -+ } -+} -+ -+template -+inline sptr::sptr(WeakRefCounter *p, bool /* force */) -+{ -+ if ((p != nullptr) && p->AttemptIncStrongRef(this)) { -+ refs_ = reinterpret_cast(p->GetRefPtr()); -+ } else { -+ refs_ = nullptr; -+ } -+} -+ -+template -+class wptr { -+ template -+ friend class wptr; -+ -+public: -+ wptr(); -+ -+ wptr(T *other); -+ -+ wptr(const wptr &other); -+ -+ wptr(const sptr &other); -+ -+ template -+ wptr(const wptr &other); -+ -+ template -+ wptr(const sptr &other); -+ -+ wptr &operator=(T *other); -+ -+ template -+ wptr &operator=(O *other); -+ -+ wptr &operator=(const wptr &other); -+ -+ wptr &operator=(const sptr &other); -+ -+ template -+ wptr &operator=(const wptr &other); -+ -+ template -+ wptr &operator=(const sptr &other); -+ -+ inline T *operator*() const -+ { -+ return *refs_; -+ } -+ inline T *operator->() const -+ { -+ return reinterpret_cast(refs_->GetRefPtr()); -+ } -+ -+ bool operator==(const T *other) const; -+ -+ inline bool operator!=(const T *other) const -+ { -+ return !operator==(other); -+ }; -+ -+ bool operator==(const wptr &other) const; -+ -+ inline bool operator!=(const wptr &other) const -+ { -+ return !operator==(other); -+ } -+ -+ bool operator==(const sptr &other) const; -+ -+ inline bool operator!=(const sptr &other) const -+ { -+ return !operator==(other); -+ } -+ -+ T *GetRefPtr() const; -+ -+ inline bool AttemptIncStrongRef(const void *objectId) const -+ { -+ return refs_->AttemptIncStrongRef(objectId); -+ } -+ -+ const sptr promote() const; -+ -+ ~wptr(); -+ -+private: -+ WeakRefCounter *refs_ = nullptr; -+}; -+ -+template -+inline T *wptr::GetRefPtr() const -+{ -+ return (refs_ != nullptr) ? reinterpret_cast(refs_->GetRefPtr()) : nullptr; -+} -+ -+template -+wptr::wptr() -+{ -+ refs_ = nullptr; -+} -+ -+template -+wptr::wptr(T *other) -+{ -+ if (other != nullptr) { -+ refs_ = other->CreateWeakRef(other); -+ if (refs_ != nullptr) { -+ refs_->IncWeakRefCount(this); -+ } -+ } else { -+ refs_ = nullptr; -+ } -+} -+ -+template -+wptr::wptr(const wptr &other) -+{ -+ refs_ = other.refs_; -+ if (refs_ != nullptr) { -+ refs_->IncWeakRefCount(this); -+ } -+} -+ -+template -+wptr::wptr(const sptr &other) -+{ -+ if (other.GetRefPtr() != nullptr) { -+ refs_ = other->CreateWeakRef(other.GetRefPtr()); -+ if (refs_ != nullptr) { -+ refs_->IncWeakRefCount(this); -+ } -+ } -+} -+ -+template -+template -+wptr::wptr(const wptr &other) -+{ -+ refs_ = other.refs_; -+ if (refs_ != nullptr) { -+ refs_->IncWeakRefCount(this); -+ } -+} -+ -+template -+template -+wptr::wptr(const sptr &other) -+{ -+ if (other.GetRefPtr() != nullptr) { -+ refs_ = other->CreateWeakRef(other.GetRefPtr()); -+ if (refs_ != nullptr) { -+ refs_->IncWeakRefCount(this); -+ } -+ } -+} -+ -+template -+wptr &wptr::operator=(T *other) -+{ -+ WeakRefCounter *newWeakRef = nullptr; -+ if (other != nullptr) { -+ newWeakRef = other->CreateWeakRef(other); -+ if (newWeakRef != nullptr) { -+ newWeakRef->IncWeakRefCount(this); -+ } -+ } -+ -+ if (refs_ != nullptr) { -+ refs_->DecWeakRefCount(this); -+ } -+ -+ refs_ = newWeakRef; -+ return *this; -+} -+ -+template -+template -+wptr &wptr::operator=(O *other) -+{ -+ T *object = reinterpret_cast(other); -+ WeakRefCounter *newWeakRef = nullptr; -+ if (object != nullptr) { -+ newWeakRef = object->CreateWeakRef(object); -+ if (newWeakRef != nullptr) { -+ newWeakRef->IncWeakRefCount(this); -+ } -+ } -+ -+ if (refs_ != nullptr) { -+ refs_->DecWeakRefCount(this); -+ } -+ -+ refs_ = newWeakRef; -+ return *this; -+} -+ -+template -+inline wptr &wptr::operator=(const wptr &other) -+{ -+ if (other.refs_ != nullptr) { -+ other.refs_->IncWeakRefCount(this); -+ } -+ -+ if (refs_ != nullptr) { -+ refs_->DecWeakRefCount(this); -+ } -+ -+ refs_ = other.refs_; -+ return *this; -+} -+ -+template -+inline wptr &wptr::operator=(const sptr &other) -+{ -+ WeakRefCounter *newWeakRef = nullptr; -+ if (other.GetRefPtr() != nullptr) { -+ newWeakRef = other->CreateWeakRef(other.GetRefPtr()); -+ if (newWeakRef != nullptr) { -+ newWeakRef->IncWeakRefCount(this); -+ } -+ } -+ -+ if (refs_ != nullptr) { -+ refs_->DecWeakRefCount(this); -+ } -+ -+ refs_ = newWeakRef; -+ return *this; -+} -+ -+template -+template -+wptr &wptr::operator=(const wptr &other) -+{ -+ if (other.refs_ != nullptr) { -+ other.refs_->IncWeakRefCount(this); -+ } -+ -+ if (refs_ != nullptr) { -+ refs_->DecWeakRefCount(this); -+ } -+ -+ refs_ = other.refs_; -+ return *this; -+} -+ -+template -+template -+wptr &wptr::operator=(const sptr &other) -+{ -+ WeakRefCounter *newWeakRef = nullptr; -+ if (other.GetRefPtr() != nullptr) { -+ newWeakRef = other->CreateWeakRef(other->GetRefPtr()); -+ if (newWeakRef != nullptr) { -+ newWeakRef->IncWeakRefCount(this); -+ } -+ } -+ -+ if (refs_ != nullptr) { -+ refs_->DecWeakRefCount(this); -+ } -+ -+ refs_ = newWeakRef; -+ return *this; -+} -+ -+template -+inline bool wptr::operator==(const T *other) const -+{ -+ return GetRefPtr() == other; -+} -+ -+template -+inline bool wptr::operator==(const wptr &other) const -+{ -+ return GetRefPtr() == other.GetRefPtr(); -+} -+ -+template -+inline bool wptr::operator==(const sptr &other) const -+{ -+ return GetRefPtr() == other.GetRefPtr(); -+} -+ -+template -+inline const sptr wptr::promote() const -+{ -+ return sptr(refs_, true); -+} -+ -+template -+inline wptr::~wptr() -+{ -+ if (refs_ != nullptr) { -+ refs_->DecWeakRefCount(this); -+ } -+} -+ -+} // namespace OHOS -+ -+#endif -diff --git a/ohos_ndk_aosp/includes/utils/rwlock.h b/ohos_ndk_aosp/includes/utils/rwlock.h -new file mode 100755 -index 0000000000..b53b8637e9 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/rwlock.h -@@ -0,0 +1,101 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_RWLOCK_H -+#define UTILS_RWLOCK_H -+ -+#include -+#include -+ -+#include "nocopyable.h" -+ -+namespace OHOS { -+namespace Utils { -+ -+class RWLock : NoCopyable { -+public: -+ enum LockStatus { -+ LOCK_STATUS_WRITE = -1, -+ LOCK_STATUS_FREE = 0, -+ }; -+ -+ RWLock() : RWLock(true) {} -+ explicit RWLock(bool writeFirst); -+ virtual ~RWLock() {} -+ -+ void LockRead(); -+ void UnLockRead(); -+ -+ void LockWrite(); -+ void UnLockWrite(); -+ -+private: -+ bool writeFirst_; -+ std::thread::id writeThreadID_; -+ -+ // Resource lock counter, -1 is write state, 0 is free state, and greater than 0 is shared read state -+ std::atomic_int lockCount_; -+ -+ // Thread counter waiting for write lock -+ std::atomic_uint writeWaitCount_; -+}; -+ -+template -+class UniqueWriteGuard : NoCopyable { -+public: -+ explicit UniqueWriteGuard(RWLockable &rwLockable) -+ : rwLockable_(rwLockable) -+ { -+ rwLockable_.LockWrite(); -+ } -+ -+ ~UniqueWriteGuard() -+ { -+ rwLockable_.UnLockWrite(); -+ } -+ -+private: -+ UniqueWriteGuard() = delete; -+ -+private: -+ RWLockable &rwLockable_; -+}; -+ -+ -+template -+class UniqueReadGuard : NoCopyable { -+public: -+ explicit UniqueReadGuard(RWLockable &rwLockable) -+ : rwLockable_(rwLockable) -+ { -+ rwLockable_.LockRead(); -+ } -+ -+ ~UniqueReadGuard() -+ { -+ rwLockable_.UnLockRead(); -+ } -+ -+private: -+ UniqueReadGuard() = delete; -+ -+private: -+ RWLockable &rwLockable_; -+}; -+ -+} // namespace Utils -+} // namespace OHOS -+#endif -+ -diff --git a/ohos_ndk_aosp/includes/utils/safe_block_queue.h b/ohos_ndk_aosp/includes/utils/safe_block_queue.h -new file mode 100755 -index 0000000000..f026169fc1 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/safe_block_queue.h -@@ -0,0 +1,194 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_BASE_BLOCK_QUEUE_H -+#define UTILS_BASE_BLOCK_QUEUE_H -+ -+#include -+#include -+#include -+#include -+#include -+ -+namespace OHOS { -+ -+template -+class SafeBlockQueue { -+public: -+ SafeBlockQueue(int capacity) : maxSize_(capacity) -+ { -+ } -+ -+ virtual void Push(T const& elem) -+ { -+ std::unique_lock lock(mutexLock_); -+ while (queueT_.size() >= maxSize_) { -+ // queue full , waiting for jobs to be taken -+ cvNotFull_.wait(lock, [&]() { return (queueT_.size() < maxSize_); }); -+ } -+ -+ // here means not full we can push in -+ queueT_.push(elem); -+ cvNotEmpty_.notify_one(); -+ } -+ -+ T Pop() -+ { -+ std::unique_lock lock(mutexLock_); -+ -+ while (queueT_.empty()) { -+ // queue empty, waiting for tasks to be Push -+ cvNotEmpty_.wait(lock, [&] { return !queueT_.empty(); }); -+ } -+ -+ T elem = queueT_.front(); -+ queueT_.pop(); -+ cvNotFull_.notify_one(); -+ return elem; -+ } -+ -+ virtual bool PushNoWait(T const& elem) -+ { -+ std::unique_lock lock(mutexLock_); -+ if (queueT_.size() >= maxSize_) { -+ return false; -+ } -+ // here means not full we can push in -+ queueT_.push(elem); -+ cvNotEmpty_.notify_one(); -+ return true; -+ } -+ -+ bool PopNotWait(T& outtask) -+ { -+ std::unique_lock lock(mutexLock_); -+ if (queueT_.empty()) { -+ return false; -+ } -+ outtask = queueT_.front(); -+ queueT_.pop(); -+ -+ cvNotFull_.notify_one(); -+ -+ return true; -+ } -+ -+ unsigned int Size() -+ { -+ std::unique_lock lock(mutexLock_); -+ return queueT_.size(); -+ } -+ -+ bool IsEmpty() -+ { -+ std::unique_lock lock(mutexLock_); -+ return queueT_.empty(); -+ } -+ -+ bool IsFull() -+ { -+ std::unique_lock lock(mutexLock_); -+ return queueT_.size() == maxSize_; -+ } -+ -+ virtual ~SafeBlockQueue() {}; -+ -+protected: -+ unsigned long maxSize_; -+ std::mutex mutexLock_; -+ std::condition_variable cvNotEmpty_; -+ std::condition_variable cvNotFull_; -+ std::queue queueT_; -+}; -+ -+template -+class SafeBlockQueueTracking : public SafeBlockQueue { -+public: -+ SafeBlockQueueTracking(int capacity) : SafeBlockQueue(capacity) -+ { -+ unfinishedTaskCount_ = 0; -+ } -+ -+ virtual ~SafeBlockQueueTracking() {}; -+ -+ virtual void Push(T const& elem) -+ { -+ unfinishedTaskCount_++; -+ std::unique_lock lock(mutexLock_); -+ while (queueT_.size() >= maxSize_) { -+ // queue full , waiting for jobs to be taken -+ cvNotFull_.wait(lock, [&]() { return (queueT_.size() < maxSize_); }); -+ } -+ -+ // here means not full we can push in -+ queueT_.push(elem); -+ -+ cvNotEmpty_.notify_one(); -+ } -+ -+ virtual bool PushNoWait(T const& elem) -+ { -+ std::unique_lock lock(mutexLock_); -+ if (queueT_.size() >= maxSize_) { -+ return false; -+ } -+ // here means not full we can push in -+ queueT_.push(elem); -+ unfinishedTaskCount_++; -+ cvNotEmpty_.notify_one(); -+ return true; -+ } -+ -+ bool OneTaskDone() -+ { -+ std::unique_lock lock(mutexLock_); -+ int unfinished = unfinishedTaskCount_ - 1; -+ -+ if (unfinished <= 0) { -+ if (unfinished < 0) { -+ return false; // false mean call elem done too many times -+ } -+ cvAllTasksDone_.notify_all(); -+ } -+ -+ unfinishedTaskCount_ = unfinished; -+ return true; -+ } -+ -+ void Join() -+ { -+ std::unique_lock lock(mutexLock_); -+ cvAllTasksDone_.wait(lock, [&] { return unfinishedTaskCount_ == 0; }); -+ } -+ -+ int GetUnfinishTaskNum() -+ { -+ return unfinishedTaskCount_; -+ } -+ -+protected: -+ using SafeBlockQueue::maxSize_; -+ using SafeBlockQueue::mutexLock_; -+ using SafeBlockQueue::cvNotEmpty_; -+ using SafeBlockQueue::cvNotFull_; -+ using SafeBlockQueue::queueT_; -+ -+ std::atomic unfinishedTaskCount_; -+ std::condition_variable cvAllTasksDone_; -+}; -+ -+} // namespace OHOS -+ -+#endif -diff --git a/ohos_ndk_aosp/includes/utils/safe_map.h b/ohos_ndk_aosp/includes/utils/safe_map.h -new file mode 100755 -index 0000000000..f32a647399 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/safe_map.h -@@ -0,0 +1,134 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_BASE_SAFE_MAP_H -+#define UTILS_BASE_SAFE_MAP_H -+ -+#include -+#include -+ -+namespace OHOS { -+ -+template -+class SafeMap { -+public: -+ SafeMap() {} -+ -+ ~SafeMap() {} -+ -+ SafeMap(const SafeMap& rhs) -+ { -+ map_ = rhs.map_; -+ } -+ -+ SafeMap& operator=(const SafeMap& rhs) -+ { -+ if (&rhs != this) { -+ map_ = rhs.map_; -+ } -+ -+ return *this; -+ } -+ -+ V& operator[](const K& key) -+ { -+ return map_[key]; -+ } -+ -+ // when multithread calling size() return a tmp status, some threads may insert just after size() call -+ int Size() -+ { -+ std::lock_guard lock(mutex_); -+ return map_.size(); -+ } -+ -+ // when multithread calling Empty() return a tmp status, some threads may insert just after Empty() call -+ bool IsEmpty() -+ { -+ std::lock_guard lock(mutex_); -+ return map_.empty(); -+ } -+ -+ bool Insert(const K& key, const V& value) -+ { -+ std::lock_guard lock(mutex_); -+ auto ret = map_.insert(std::pair(key, value)); -+ return ret.second; -+ } -+ -+ void EnsureInsert(const K& key, const V& value) -+ { -+ std::lock_guard lock(mutex_); -+ auto ret = map_.insert(std::pair(key, value)); -+ // find key and cannot insert -+ if (!ret.second) { -+ map_.erase(ret.first); -+ map_.insert(std::pair(key, value)); -+ return; -+ } -+ return; -+ } -+ -+ bool Find(const K& key, V& value) -+ { -+ bool ret = false; -+ std::lock_guard lock(mutex_); -+ -+ auto iter = map_.find(key); -+ if (iter != map_.end()) { -+ value = iter->second; -+ ret = true; -+ } -+ -+ return ret; -+ } -+ -+ bool FindOldAndSetNew(const K& key, V& oldValue, const V& newValue) -+ { -+ bool ret = false; -+ std::lock_guard lock(mutex_); -+ if (map_.size() > 0) { -+ auto iter = map_.find(key); -+ if (iter != map_.end()) { -+ oldValue = iter->second; -+ map_.erase(iter); -+ map_.insert(std::pair(key, newValue)); -+ ret = true; -+ } -+ } -+ -+ return ret; -+ } -+ -+ void Erase(const K& key) -+ { -+ std::lock_guard lock(mutex_); -+ map_.erase(key); -+ } -+ -+ void Clear() -+ { -+ std::lock_guard lock(mutex_); -+ map_.clear(); -+ return; -+ } -+ -+private: -+ std::mutex mutex_; -+ std::map map_; -+}; -+ -+} // namespace OHOS -+#endif -diff --git a/ohos_ndk_aosp/includes/utils/safe_queue.h b/ohos_ndk_aosp/includes/utils/safe_queue.h -new file mode 100755 -index 0000000000..d96004119a ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/safe_queue.h -@@ -0,0 +1,134 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_BASE_SAFE_QUEUE_H -+#define UTILS_BASE_SAFE_QUEUE_H -+ -+#include -+#include -+ -+namespace OHOS { -+ -+template -+class SafeQueueInner { -+ -+public: -+ SafeQueueInner() {} -+ -+ virtual ~SafeQueueInner() -+ { -+ if (!deque_.empty()) { -+ deque_.clear(); -+ } -+ } -+ -+ void Erase(T& Object) -+ { -+ std::lock_guard lock(mutex_); -+ deque_.remove(Object); -+ } -+ -+ bool Empty() -+ { -+ std::lock_guard lock(mutex_); -+ return deque_.empty(); -+ } -+ -+ void Push(const T& pt) -+ { -+ std::lock_guard lock(mutex_); -+ return DoPush(pt); -+ } -+ -+ void Clear() -+ { -+ std::lock_guard lock(mutex_); -+ if (!deque_.empty()) { -+ deque_.clear(); -+ } -+ -+ return; -+ } -+ -+ int Size() -+ { -+ std::lock_guard lock(mutex_); -+ return deque_.size(); -+ } -+ -+ bool Pop(T& pt) -+ { -+ std::lock_guard lock(mutex_); -+ return DoPop(pt); -+ } -+ -+protected: -+ virtual void DoPush(const T& pt) = 0; -+ virtual bool DoPop(T& pt) = 0; -+ -+ std::deque deque_; -+ std::mutex mutex_; -+}; -+ -+template -+class SafeQueue : public SafeQueueInner { -+ -+protected: -+ using SafeQueueInner::deque_; -+ using SafeQueueInner::mutex_; -+ -+ virtual void DoPush(const T& pt) override -+ { -+ deque_.push_back(pt); -+ } -+ -+ virtual bool DoPop(T& pt) override -+ { -+ if (deque_.size() > 0) { -+ pt = deque_.front(); -+ deque_.pop_front(); -+ return true; -+ } -+ -+ return false; -+ } -+}; -+ -+template -+class SafeStack : public SafeQueueInner { -+ -+protected: -+ using SafeQueueInner::deque_; -+ using SafeQueueInner::mutex_; -+ -+ virtual void DoPush(const T& pt) override -+ { -+ deque_.push_back(pt); -+ } -+ -+ virtual bool DoPop(T& pt) override -+ { -+ if (deque_.size() > 0) { -+ pt = deque_.back(); -+ deque_.pop_back(); -+ return true; -+ } -+ -+ return false; -+ } -+}; -+ -+} // namespace OHOS -+#endif -diff --git a/ohos_ndk_aosp/includes/utils/securec.h b/ohos_ndk_aosp/includes/utils/securec.h -new file mode 100755 -index 0000000000..553eaf49b1 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/securec.h -@@ -0,0 +1,538 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27 -+#define __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27 -+ -+/* Compile in kernel under macro control */ -+#ifndef SECUREC_IN_KERNEL -+#ifdef __KERNEL__ -+#define SECUREC_IN_KERNEL 1 -+#else -+#define SECUREC_IN_KERNEL 0 -+#endif -+#endif -+ -+/* If you need high performance, enable the SECUREC_WITH_PERFORMANCE_ADDONS macro, default is enable . -+ * The macro is automatically closed on the windows platform in securectyp.h. -+ */ -+#ifndef SECUREC_WITH_PERFORMANCE_ADDONS -+#if SECUREC_IN_KERNEL -+#define SECUREC_WITH_PERFORMANCE_ADDONS 0 -+#else -+#define SECUREC_WITH_PERFORMANCE_ADDONS 1 -+#endif -+#endif -+ -+#include "securectype.h" -+#include -+ -+#ifndef SECUREC_HAVE_ERRNO_H -+#if SECUREC_IN_KERNEL -+#define SECUREC_HAVE_ERRNO_H 0 -+#else -+#define SECUREC_HAVE_ERRNO_H 1 -+#endif -+#endif -+ -+/* EINVAL ERANGE may defined in errno.h */ -+#if SECUREC_HAVE_ERRNO_H -+#include -+#endif -+ -+/* If stack size on some embedded platform is limited, you can define the following macro -+ * which will put some variables on heap instead of stack. -+ * SECUREC_STACK_SIZE_LESS_THAN_1K -+ */ -+ -+/* define error code */ -+#if !defined(__STDC_WANT_LIB_EXT1__) || (defined(__STDC_WANT_LIB_EXT1__) && (__STDC_WANT_LIB_EXT1__ == 0)) -+#ifndef SECUREC_DEFINED_ERRNO_TYPE -+#define SECUREC_DEFINED_ERRNO_TYPE -+/* just check whether macrodefinition exists. */ -+#ifndef errno_t -+typedef int errno_t; -+#endif -+#endif -+#endif -+ -+/* success */ -+#ifndef EOK -+#define EOK (0) -+#endif -+ -+#ifndef EINVAL -+/* The src buffer is not correct and destination buffer can't not be reset */ -+#define EINVAL (22) -+#endif -+ -+#ifndef EINVAL_AND_RESET -+/* Once the error is detected, the dest buffer must be rest! */ -+#define EINVAL_AND_RESET (22 | 128) -+#endif -+ -+#ifndef ERANGE -+/* The destination buffer is not long enough and destination buffer can not be reset */ -+#define ERANGE (34) -+#endif -+ -+#ifndef ERANGE_AND_RESET -+/* Once the error is detected, the dest buffer must be rest! */ -+#define ERANGE_AND_RESET (34 | 128) -+#endif -+ -+#ifndef EOVERLAP_AND_RESET -+/* Once the buffer overlap is detected, the dest buffer must be rest! */ -+#define EOVERLAP_AND_RESET (54 | 128) -+#endif -+ -+/* if you need export the function of this library in Win32 dll, use __declspec(dllexport) */ -+#ifdef SECUREC_IS_DLL_LIBRARY -+#ifdef SECUREC_DLL_EXPORT -+#define SECUREC_API __declspec(dllexport) -+#else -+#define SECUREC_API __declspec(dllimport) -+#endif -+#else -+/* Standardized function declaration . If a security function is declared in the your code, -+ * it may cause a compilation alarm,Please delete the security function you declared -+ */ -+#define SECUREC_API extern -+#endif -+ -+#ifndef SECUREC_SNPRINTF_TRUNCATED -+#define SECUREC_SNPRINTF_TRUNCATED 1 -+#endif -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+ /** -+ * @Description:The memset_s function copies the value of c (converted to an unsigned char) into each of the first count characters of the object pointed to by dest. -+ * @param dest - destination address -+ * @param destMax -The maximum length of destination buffer -+ * @param c - the value to be copied -+ * @param count -copies first count characters of dest -+ * @return EOK if there was no runtime-constraint violation -+ */ -+ SECUREC_API errno_t memset_s(void *dest, size_t destMax, int c, size_t count); -+ -+ /* The memset_s security function is not provided in Windows system, but other security functions are provided. In this case, can only use the memset_s function */ -+#ifndef SECUREC_ONLY_DECLARE_MEMSET -+ -+ /** -+ * @Description:The wmemcpy_s function copies n successive wide characters from the object pointed to by src into the object pointed to by dest. -+ * @param dest - destination address -+ * @param destMax -The maximum length of destination buffer -+ * @param src -source address -+ * @param count -copies count wide characters from the src -+ * @return EOK if there was no runtime-constraint violation -+ */ -+#if SECUREC_IN_KERNEL == 0 -+ SECUREC_API errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count); -+#endif -+ /** -+ * @Description:The memmove_s function copies n characters from the object pointed to by src into the object pointed to by dest. -+ * @param dest - destination address -+ * @param destMax -The maximum length of destination buffer -+ * @param src -source address -+ * @param count -copies count wide characters from the src -+ * @return EOK if there was no runtime-constraint violation -+ */ -+ SECUREC_API errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count); -+#if SECUREC_IN_KERNEL == 0 -+ /** -+ * @Description:The wmemmove_s function copies n successive wide characters from the object pointed to by src into the object pointed to by dest. -+ * @param dest - destination address -+ * @param destMax -The maximum length of destination buffer -+ * @param src -source address -+ * @param count -copies count wide characters from the src -+ * @return EOK if there was no runtime-constraint violation -+ */ -+ SECUREC_API errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count); -+ -+ /** -+ * @Description:The wcscpy_s function copies the wide string pointed to by strSrc (including theterminating null wide character) into the array pointed to by strDest -+ * @param strDest - destination address -+ * @param destMax -The maximum length of destination buffer -+ * @param strSrc -source address -+ * @return EOK if there was no runtime-constraint violation -+ */ -+ SECUREC_API errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc); -+ -+ /** -+ * @Description:The wcsncpy_s function copies not more than n successive wide characters (not including the terminating null wide character) -+ * from the array pointed to by strSrc to the array pointed to by strDest -+ * @param strDest - destination address -+ * @param destMax -The maximum length of destination buffer(including the terminating wide character) -+ * @param strSrc -source address -+ * @param count -copies count wide characters from the src -+ * @return EOK if there was no runtime-constraint violation -+ */ -+ SECUREC_API errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count); -+ -+ /** -+ * @Description:The wcscat_s function appends a copy of the wide string pointed to by strSrc (including the terminating null wide character) -+ * to the end of the wide string pointed to by strDest -+ * @param strDest - destination address -+ * @param destMax -The maximum length of destination buffer(including the terminating wide character) -+ * @param strSrc -source address -+ * @return EOK if there was no runtime-constraint violation -+ */ -+ SECUREC_API errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc); -+ -+ /** -+ * @Description:The wcsncat_s function appends not more than n successive wide characters (not including the terminating null wide character) -+ * from the array pointed to by strSrc to the end of the wide string pointed to by strDest. -+ * @param strDest - destination address -+ * @param destMax -The maximum length of destination buffer(including the terminating wide character) -+ * @param strSrc -source address -+ * @param count -copies count wide characters from the src -+ * @return EOK if there was no runtime-constraint violation -+ */ -+ SECUREC_API errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count); -+ -+ /** -+ * @Description: The strtok_s function parses a string into a sequence of tokens,On the first call to strtok_s the string to be parsed should be specified in strToken. -+ * In each subsequent call that should parse the same string, strToken should be NULL -+ * @param strToken - the string to be delimited -+ * @param strDelimit -specifies a set of characters that delimit the tokens in the parsed string -+ * @param context -is a pointer to a char * variable that is used internally by strtok_s function -+ * @return:returns a pointer to the first character of a token, or a null pointer if there is no token or there is a runtime-constraint violation. -+ */ -+ SECUREC_API char *strtok_s(char *strToken, const char *strDelimit, char **context); -+ -+ /** -+ * @Description: The wcstok_s function is the wide-character equivalent of the strtok_s function -+ * @param strToken - the string to be delimited -+ * @param strDelimit -specifies a set of characters that delimit the tokens in the parsed string -+ * @param context -is a pointer to a char * variable that is used internally by strtok_s function -+ * @return:returns a pointer to the first character of a token, or a null pointer if there is no token or there is a runtime-constraint violation. -+ */ -+ SECUREC_API wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context); -+ -+ /** -+ * @Description: The sprintf_s function is equivalent to the sprintf function except for the parameter destMax and the explicit runtime-constraints violation -+ * @param strDest - produce output according to a format ,write to the character string strDest -+ * @param destMax - The maximum length of destination buffer(including the terminating null byte ('\0')) -+ * @param format - format string -+ * @return:success the number of characters printed(not including the terminating null byte ('\0')), If an error occurred return -1. -+ */ -+ SECUREC_API int sprintf_s(char *strDest, size_t destMax, const char *format, ...) SECUREC_ATTRIBUTE(3, 4); -+ -+ /** -+ * @Description: The swprintf_s function is the wide-character equivalent of the sprintf_s function -+ * @param strDest - produce output according to a format ,write to the character string strDest -+ * @param destMax - The maximum length of destination buffer(including the terminating null ) -+ * @param format - format string -+ * @return:success the number of characters printed(not including the terminating null wide characte), If an error occurred return -1. -+ */ -+ SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...); -+ -+ /** -+ * @Description: The vsprintf_s function is equivalent to the vsprintf function except for the parameter destMax and the explicit runtime-constraints violation -+ * @param strDest - produce output according to a format ,write to the character string strDest -+ * @param destMax - The maximum length of destination buffer(including the terminating null wide characte) -+ * @param format - format string -+ * @param arglist - instead of a variable number of arguments -+ * @return:return the number of characters printed(not including the terminating null byte ('\0')), If an error occurred return -1. -+ */ -+ SECUREC_API int vsprintf_s(char *strDest, size_t destMax, const char *format, -+ va_list arglist) SECUREC_ATTRIBUTE(3, 0); -+ -+ /** -+ * @Description: The vswprintf_s function is the wide-character equivalent of the vsprintf_s function -+ * @param strDest - produce output according to a format ,write to the character string strDest -+ * @param destMax - The maximum length of destination buffer(including the terminating null ) -+ * @param format - format string -+ * @param arglist - instead of a variable number of arguments -+ * @return:return the number of characters printed(not including the terminating null wide characte), If an error occurred return -1. -+ */ -+ SECUREC_API int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list arglist); -+ -+ /** -+ * @Description: The vsnprintf_s function is equivalent to the vsnprintf function except for the parameter destMax/count and the explicit runtime-constraints violation -+ * @param strDest - produce output according to a format ,write to the character string strDest -+ * @param destMax - The maximum length of destination buffer(including the terminating null byte ('\0')) -+ * @param count - do not write more than count bytes to strDest(not including the terminating null byte ('\0')) -+ * @param format - format string -+ * @param arglist - instead of a variable number of arguments -+ * @return:return the number of characters printed(not including the terminating null byte ('\0')), If an error occurred return -1.Pay special attention to returning -1 when truncation occurs -+ */ -+ SECUREC_API int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format, -+ va_list arglist) SECUREC_ATTRIBUTE(4, 0); -+ -+ /** -+ * @Description: The snprintf_s function is equivalent to the snprintf function except for the parameter destMax/count and the explicit runtime-constraints violation -+ * @param strDest - produce output according to a format ,write to the character string strDest -+ * @param destMax - The maximum length of destination buffer(including the terminating null byte ('\0')) -+ * @param count - do not write more than count bytes to strDest(not including the terminating null byte ('\0')) -+ * @param format - format string -+ * @return:return the number of characters printed(not including the terminating null byte ('\0')), If an error occurred return -1.Pay special attention to returning -1 when truncation occurs -+ */ -+ SECUREC_API int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format, -+ ...) SECUREC_ATTRIBUTE(4, 5); -+ -+#if SECUREC_SNPRINTF_TRUNCATED -+ /** -+ * @Description: The vsnprintf_truncated_s function is equivalent to the vsnprintf_s function except no count parameter and return value -+ * @param strDest - produce output according to a format ,write to the character string strDest -+ * @param destMax - The maximum length of destination buffer(including the terminating null byte ('\0')) -+ * @param format - format string -+ * @param arglist - instead of a variable number of arguments -+ * @return:return the number of characters printed(not including the terminating null byte ('\0')), If an error occurred return -1.Pay special attention to returning destMax - 1 when truncation occurs -+ */ -+ SECUREC_API int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format, -+ va_list arglist) SECUREC_ATTRIBUTE(3, 0); -+ -+ /** -+ * @Description: The snprintf_truncated_s function is equivalent to the snprintf_2 function except no count parameter and return value -+ * @param strDest - produce output according to a format ,write to the character string strDest -+ * @param destMax - The maximum length of destination buffer(including the terminating null byte ('\0')) -+ * @param format - format string -+ * @return:return the number of characters printed(not including the terminating null byte ('\0')), If an error occurred return -1.Pay special attention to returning destMax - 1 when truncation occurs -+ */ -+ SECUREC_API int snprintf_truncated_s(char *strDest, size_t destMax, const char *format, ...) SECUREC_ATTRIBUTE(3, 4); -+#endif -+ /** -+ * @Description: The scanf_s function is equivalent to fscanf_s with the argument stdin interposed before the arguments to scanf_s -+ * @param format - format string -+ * @return:returns the number of input items assigned, If an error occurred return -1. -+ */ -+ SECUREC_API int scanf_s(const char *format, ...); -+ -+ /** -+ * @Description: The wscanf_s function is the wide-character equivalent of the scanf_s function -+ * @param format - format string -+ * @return:returns the number of input items assigned, If an error occurred return -1. -+ */ -+ SECUREC_API int wscanf_s(const wchar_t *format, ...); -+ -+ /** -+ * @Description: The vscanf_s function is equivalent to scanf_s, with the variable argument list replaced by arglist -+ * @param format - format string -+ * @param arglist - instead of a variable number of arguments -+ * @return:returns the number of input items assigned, If an error occurred return -1. -+ */ -+ SECUREC_API int vscanf_s(const char *format, va_list arglist); -+ -+ /** -+ * @Description: The vwscanf_s function is the wide-character equivalent of the vscanf_s function -+ * @param format - format string -+ * @param arglist - instead of a variable number of arguments -+ * @return:returns the number of input items assigned, If an error occurred return -1. -+ */ -+ SECUREC_API int vwscanf_s(const wchar_t *format, va_list arglist); -+ -+ /** -+ * @Description: The fscanf_s function is equivalent to fscanf except that the c, s, and [ conversion specifiers apply to a pair of arguments (unless assignment suppression is indicated by a*) -+ * @param stream - stdio file stream -+ * @param format - format string -+ * @return:returns the number of input items assigned, If an error occurred return -1. -+ */ -+ SECUREC_API int fscanf_s(FILE *stream, const char *format, ...); -+ -+ /** -+ * @Description: The fwscanf_s function is the wide-character equivalent of the fscanf_s function -+ * @param stream - stdio file stream -+ * @param format - format string -+ * @return:returns the number of input items assigned, If an error occurred return -1. -+ */ -+ SECUREC_API int fwscanf_s(FILE *stream, const wchar_t *format, ...); -+ -+ /** -+ * @Description: The vfscanf_s function is equivalent to fscanf_s, with the variable argument list replaced by arglist -+ * @param stream - stdio file stream -+ * @param format - format string -+ * @param arglist - instead of a variable number of arguments -+ * @return:returns the number of input items assigned, If an error occurred return -1. -+ */ -+ SECUREC_API int vfscanf_s(FILE *stream, const char *format, va_list arglist); -+ -+ /** -+ * @Description: The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function -+ * @param stream - stdio file stream -+ * @param format - format string -+ * @param arglist - instead of a variable number of arguments -+ * @return:returns the number of input items assigned, If an error occurred return -1. -+ */ -+ SECUREC_API int vfwscanf_s(FILE *stream, const wchar_t *format, va_list arglist); -+ -+ /** -+ * @Description: The sscanf_s function is equivalent to fscanf_s, except that input is obtained from a string (specified by the argument buffer) rather than from a stream -+ * @param buffer - read character from buffer -+ * @param format - format string -+ * @return:returns the number of input items assigned, If an error occurred return -1. -+ */ -+ SECUREC_API int sscanf_s(const char *buffer, const char *format, ...); -+ -+ /** -+ * @Description: The swscanf_s function is the wide-character equivalent of the sscanf_s function -+ * @param buffer - read character from buffer -+ * @param format - format string -+ * @return:returns the number of input items assigned, If an error occurred return -1. -+ */ -+ SECUREC_API int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...); -+ -+ /** -+ * @Description: The vsscanf_s function is equivalent to sscanf_s, with the variable argument list replaced by arglist -+ * @param buffer - read character from buffer -+ * @param format - format string -+ * @param arglist - instead of a variable number of arguments -+ * @return:returns the number of input items assigned, If an error occurred return -1. -+ */ -+ SECUREC_API int vsscanf_s(const char *buffer, const char *format, va_list arglist); -+ -+ /** -+ * @Description: The vswscanf_s function is the wide-character equivalent of the vsscanf_s function -+ * @param buffer - read character from buffer -+ * @param format - format string -+ * @param arglist - instead of a variable number of arguments -+ * @return:returns the number of input items assigned, If an error occurred return -1. -+ */ -+ SECUREC_API int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list arglist); -+ -+ /** -+ * @Description:The gets_s function reads at most one less than the number of characters specified by destMax from the stream pointed to by stdin, into the array pointed to by buffer -+ * @param buffer - destination address -+ * @param destMax -The maximum length of destination buffer(including the terminating null character) -+ * @return buffer if there was no runtime-constraint violation,If an error occurred return NULL. -+ */ -+ SECUREC_API char *gets_s(char *buffer, size_t destMax); -+#endif -+ -+ /** -+ * @Description:The memcpy_s function copies n characters from the object pointed to by src into the object pointed to by dest. -+ * @param dest - destination address -+ * @param destMax -The maximum length of destination buffer -+ * @param src -source address -+ * @param count -copies count characters from the src -+ * @return EOK if there was no runtime-constraint violation -+ */ -+ SECUREC_API errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count); -+ -+ /** -+ * @Description:The strcpy_s function copies the string pointed to by strSrc (including the terminating null character) into the array pointed to by strDest -+ * @param strDest - destination address -+ * @param destMax -The maximum length of destination buffer(including the terminating null character) -+ * @param strSrc -source address -+ * @return EOK if there was no runtime-constraint violation -+ */ -+ SECUREC_API errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc); -+ -+ /** -+ * @Description:The strncpy_s function copies not more than n successive characters (not including the terminating null character) -+ * from the array pointed to by strSrc to the array pointed to by strDest -+ * @param strDest - destination address -+ * @param destMax -The maximum length of destination buffer(including the terminating null character) -+ * @param strSrc -source address -+ * @param count -copies count characters from the src -+ * @return EOK if there was no runtime-constraint violation -+ */ -+ SECUREC_API errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count); -+ -+ /** -+ * @Description:The strcat_s function appends a copy of the string pointed to by strSrc (including the terminating null character) -+ * to the end of the string pointed to by strDest -+ * @param strDest - destination address -+ * @param destMax -The maximum length of destination buffer(including the terminating null wide character) -+ * @param strSrc -source address -+ * @return EOK if there was no runtime-constraint violation -+ */ -+ SECUREC_API errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc); -+ -+ /** -+ * @Description:The strncat_s function appends not more than n successive characters (not including the terminating null character) -+ * from the array pointed to by strSrc to the end of the string pointed to by strDest. -+ * @param strDest - destination address -+ * @param destMax -The maximum length of destination buffer(including the terminating null character) -+ * @param strSrc -source address -+ * @param count -copies count characters from the src -+ * @return EOK if there was no runtime-constraint violation -+ */ -+ SECUREC_API errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count); -+#if SECUREC_IN_KERNEL == 0 -+ /* those functions are used by macro ,must declare hare , also for without function declaration warning */ -+ extern errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t count); -+ extern errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc); -+#endif -+#endif -+ -+#if SECUREC_WITH_PERFORMANCE_ADDONS -+ /* those functions are used by macro */ -+ extern errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count); -+ extern errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count); -+ extern errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, size_t count); -+ extern errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, size_t count); -+ -+/* strcpy_sp is a macro, NOT a function in performance optimization mode. */ -+#define strcpy_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \ -+ __builtin_constant_p((src))) ? \ -+ SECUREC_STRCPY_SM((dest), (destMax), (src)) : \ -+ strcpy_s((dest), (destMax), (src))) -+ -+/* strncpy_sp is a macro, NOT a function in performance optimization mode. */ -+#define strncpy_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \ -+ __builtin_constant_p((destMax)) && \ -+ __builtin_constant_p((src))) ? \ -+ SECUREC_STRNCPY_SM((dest), (destMax), (src), (count)) : \ -+ strncpy_s((dest), (destMax), (src), (count))) -+ -+/* strcat_sp is a macro, NOT a function in performance optimization mode. */ -+#define strcat_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \ -+ __builtin_constant_p((src))) ? \ -+ SECUREC_STRCAT_SM((dest), (destMax), (src)) : \ -+ strcat_s((dest), (destMax), (src))) -+ -+ /* strncat_sp is a macro, NOT a function in performance optimization mode. */ -+#define strncat_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \ -+ __builtin_constant_p((destMax)) && \ -+ __builtin_constant_p((src))) ? \ -+ SECUREC_STRNCAT_SM((dest), (destMax), (src), (count)) : \ -+ strncat_s((dest), (destMax), (src), (count))) -+ -+/* memcpy_sp is a macro, NOT a function in performance optimization mode. */ -+#define memcpy_sp(dest, destMax, src, count) (__builtin_constant_p((count)) ? \ -+ (SECUREC_MEMCPY_SM((dest), (destMax), (src), (count))) : \ -+ (__builtin_constant_p((destMax)) ? \ -+ (((size_t)(destMax) > 0 && \ -+ (((unsigned long long)(destMax) & \ -+ (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \ -+ memcpy_sOptTc((dest), (destMax), (src), (count)) : ERANGE ) : \ -+ memcpy_sOptAsm((dest), (destMax), (src), (count)))) -+ -+/* memset_sp is a macro, NOT a function in performance optimization mode. */ -+#define memset_sp(dest, destMax, c, count) (__builtin_constant_p((count)) ? \ -+ (SECUREC_MEMSET_SM((dest), (destMax), (c), (count))) : \ -+ (__builtin_constant_p((destMax)) ? \ -+ (((size_t)(destMax) > 0 && \ -+ (((unsigned long long)(destMax) & \ -+ (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \ -+ memset_sOptTc((dest), (destMax), (c), (count)) : ERANGE ) : \ -+ memset_sOptAsm((dest), (destMax), (c), (count)))) -+#else -+#define strcpy_sp strcpy_s -+#define strncpy_sp strncpy_s -+#define strcat_sp strcat_s -+#define strncat_sp strncat_s -+#define memcpy_sp memcpy_s -+#define memset_sp memset_s -+#endif -+ -+#ifdef __cplusplus -+} -+#endif /* __cplusplus */ -+#endif /* __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27 */ -diff --git a/ohos_ndk_aosp/includes/utils/securec_p.h b/ohos_ndk_aosp/includes/utils/securec_p.h -new file mode 100755 -index 0000000000..03cd7d573c ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/securec_p.h -@@ -0,0 +1,42 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef __SECUREC_P_H__ -+#define __SECUREC_P_H__ -+ -+#include "securec.h" -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+ /** -+ * @Description: The vsnprintfp_s function is equivalent to the vsnprintf function except for the parameter destMax/count -+ * and the explicit runtime-constraints violation -+ * @param strDest - produce output according to a format ,write to the character string strDest -+ * @param destMax - The maximum length of destination buffer(including the terminating null byte ('\0')) -+ * @param count - do not write more than count bytes to strDest(not including the terminating null byte ('\0')) -+ * @param priv_on - if true, any not %{public} prefix formatter arguments will be printed as "" -+ * @param format - format string -+ * @param arglist - instead of a variable number of arguments -+ * @return:return the number of characters printed(not including the terminating null byte ('\0')), -+ * If an error occurred return -1.Pay special attention to returning -1 when truncation occurs -+ */ -+ SECUREC_API int vsnprintfp_s(char *strDest, size_t destMax, size_t count, int priv, const char *format, -+ va_list arglist) SECUREC_ATTRIBUTE(5, 0); -+#ifdef __cplusplus -+} -+#endif /* __cplusplus */ -+#endif /* __SECUREC_P_H__ */ -diff --git a/ohos_ndk_aosp/includes/utils/securectype.h b/ohos_ndk_aosp/includes/utils/securectype.h -new file mode 100755 -index 0000000000..564c9f4741 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/securectype.h -@@ -0,0 +1,279 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+/* [Standardize-exceptions]: Performance-sensitive -+ * [reason]: Strict parameter verification has been done before use -+ */ -+ -+#ifndef __SECURECTYPE_H__A7BBB686_AADA_451B_B9F9_44DACDAE18A7 -+#define __SECURECTYPE_H__A7BBB686_AADA_451B_B9F9_44DACDAE18A7 -+ -+#ifndef SECUREC_ONLY_DECLARE_MEMSET -+/* Shielding VC symbol redefinition warning */ -+#if defined(_MSC_VER) && (_MSC_VER >= 1400) -+#ifdef __STDC_WANT_SECURE_LIB__ -+#undef __STDC_WANT_SECURE_LIB__ -+#endif -+#define __STDC_WANT_SECURE_LIB__ 0 -+#ifdef _CRTIMP_ALTERNATIVE -+#undef _CRTIMP_ALTERNATIVE -+#endif -+#define _CRTIMP_ALTERNATIVE //comment microsoft *_s function -+#endif -+#endif -+ -+#if SECUREC_IN_KERNEL -+#include -+#include -+#else -+#include -+#include -+#include -+#endif -+ -+/* if enable SECUREC_COMPATIBLE_WIN_FORMAT, the output format will be compatible to Windows. */ -+#if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)) -+#define SECUREC_COMPATIBLE_WIN_FORMAT -+#endif -+ -+#if defined(SECUREC_COMPATIBLE_WIN_FORMAT) -+/* in windows platform, can't use optimized function for there is no __builtin_constant_p like function */ -+/* If need optimized macro, can define this: define __builtin_constant_p(x) 0 */ -+#ifdef SECUREC_WITH_PERFORMANCE_ADDONS -+#undef SECUREC_WITH_PERFORMANCE_ADDONS -+#define SECUREC_WITH_PERFORMANCE_ADDONS 0 -+#endif -+#endif -+ -+#if defined(__VXWORKS__) || defined(__vxworks) || defined(__VXWORKS) || defined(_VXWORKS_PLATFORM_) || \ -+ defined(SECUREC_VXWORKS_VERSION_5_4) -+#if !defined(SECUREC_VXWORKS_PLATFORM) -+#define SECUREC_VXWORKS_PLATFORM -+#endif -+#endif -+ -+/* if enable SECUREC_COMPATIBLE_LINUX_FORMAT, the output format will be compatible to Linux. */ -+#if !(defined(SECUREC_COMPATIBLE_WIN_FORMAT) || defined(SECUREC_VXWORKS_PLATFORM)) -+#define SECUREC_COMPATIBLE_LINUX_FORMAT -+#endif -+#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT -+#include -+#endif -+ -+/* add the -DSECUREC_SUPPORT_FORMAT_WARNING compiler option to supoort -Wformat. -+ * default does not check the format is that the same data type in the actual code -+ * in the product is different in the original data type definition of VxWorks and Linux. -+ */ -+#ifndef SECUREC_SUPPORT_FORMAT_WARNING -+#define SECUREC_SUPPORT_FORMAT_WARNING 0 -+#endif -+ -+/* SECUREC_PCLINT for tool do not recognize __attribute__ just for pclint */ -+#if SECUREC_SUPPORT_FORMAT_WARNING && !defined(SECUREC_PCLINT) -+#define SECUREC_ATTRIBUTE(x,y) __attribute__((format(printf, (x), (y)))) -+#else -+#define SECUREC_ATTRIBUTE(x,y) -+#endif -+ -+/* SECUREC_PCLINT for tool do not recognize __builtin_expect ,just for pclint */ -+#if defined(__GNUC__) && \ -+ ((__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3 /* above 3.4 */ ))) && \ -+ !defined(SECUREC_PCLINT) -+/* This is a built-in function that can be used without a declaration, if you encounter an undeclared compilation alarm, -+ * you can add -DSECUREC_NEED_BUILTIN_EXPECT_DECLARE to compiler options -+ */ -+#if defined(SECUREC_NEED_BUILTIN_EXPECT_DECLARE) -+long __builtin_expect(long exp, long c); -+#endif -+#define SECUREC_LIKELY(x) __builtin_expect(!!(x), 1) -+#define SECUREC_UNLIKELY(x) __builtin_expect(!!(x), 0) -+#else -+#define SECUREC_LIKELY(x) (x) -+#define SECUREC_UNLIKELY(x) (x) -+#endif -+ -+/* define the max length of the string */ -+#define SECUREC_STRING_MAX_LEN (0x7fffffffUL) -+#define SECUREC_WCHAR_STRING_MAX_LEN (SECUREC_STRING_MAX_LEN / sizeof(wchar_t)) -+ -+/* add SECUREC_MEM_MAX_LEN for memcpy and memmove */ -+#define SECUREC_MEM_MAX_LEN (0x7fffffffUL) -+#define SECUREC_WCHAR_MEM_MAX_LEN (SECUREC_MEM_MAX_LEN / sizeof(wchar_t)) -+ -+#if SECUREC_STRING_MAX_LEN > 0x7fffffff -+#error "max string is 2G" -+#endif -+ -+#if (defined(__GNUC__ ) && defined(__SIZEOF_POINTER__ )) -+#if (__SIZEOF_POINTER__ != 4) && (__SIZEOF_POINTER__ != 8) -+#error "unsupported system" -+#endif -+#endif -+ -+#ifndef SECUREC_MALLOC -+#define SECUREC_MALLOC(x) malloc((size_t)(x)) -+#endif -+ -+#ifndef SECUREC_FREE -+#define SECUREC_FREE(x) free((void *)(x)) -+#endif -+ -+#if defined(_WIN64) || defined(WIN64) || defined(__LP64__) || defined(_LP64) -+#define SECUREC_ON_64BITS -+#endif -+ -+#if (!defined(SECUREC_ON_64BITS) && defined(__GNUC__ ) && defined(__SIZEOF_POINTER__ )) -+#if __SIZEOF_POINTER__ == 8 -+#define SECUREC_ON_64BITS -+#endif -+#endif -+ -+#if defined(__SVR4) || defined(__svr4__) -+#define SECUREC_ON_SOLARIS -+#endif -+ -+#if (defined(__hpux) || defined(_AIX) || defined(SECUREC_ON_SOLARIS)) -+#define SECUREC_ON_UNIX -+#endif -+ -+/* codes should run under the macro SECUREC_COMPATIBLE_LINUX_FORMAT in unknown system on default, -+ * and strtold. The function -+ * strtold is referenced first at ISO9899:1999(C99), and some old compilers can -+ * not support these functions. Here provides a macro to open these functions: -+ * SECUREC_SUPPORT_STRTOLD -- if defined, strtold will be used -+ */ -+#ifndef SECUREC_SUPPORT_STRTOLD -+#define SECUREC_SUPPORT_STRTOLD 0 -+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT)) -+#if defined(__USE_ISOC99) || \ -+ (defined(_AIX) && defined(_ISOC99_SOURCE)) || \ -+ (defined(__hpux) && defined(__ia64)) || \ -+ (defined(SECUREC_ON_SOLARIS) && (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ -+ defined(_STDC_C99) || defined(__EXTENSIONS__)) -+#undef SECUREC_SUPPORT_STRTOLD -+#define SECUREC_SUPPORT_STRTOLD 1 -+#endif -+#endif -+#if ((defined(SECUREC_WRLINUX_BELOW4) || defined(_WRLINUX_BELOW4_))) -+#undef SECUREC_SUPPORT_STRTOLD -+#define SECUREC_SUPPORT_STRTOLD 0 -+#endif -+#endif -+ -+#if SECUREC_WITH_PERFORMANCE_ADDONS -+ -+#ifndef SECUREC_TWO_MIN -+#define SECUREC_TWO_MIN(a, b) ((a) < (b) ? (a) : (b)) -+#endif -+ -+/* for strncpy_s performance optimization */ -+#define SECUREC_STRNCPY_SM(dest, destMax, src, count) \ -+ (((void *)dest != NULL && (void *)src != NULL && (size_t)destMax >0 && \ -+ (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \ -+ (SECUREC_TWO_MIN(count , strlen(src)) + 1) <= (size_t)destMax ) ? \ -+ ((count < strlen(src))? (memcpy(dest, src, count), *((char *)dest + count) = '\0', EOK): \ -+ (memcpy(dest, src, strlen(src) + 1), EOK ) ) :(strncpy_error(dest, destMax, src, count))) -+ -+#define SECUREC_STRCPY_SM(dest, destMax, src) \ -+ (((void *)dest != NULL && (void *)src != NULL && (size_t)destMax >0 && \ -+ (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \ -+ (strlen(src) + 1) <= (size_t)destMax )? (memcpy(dest, src, strlen(src) + 1), EOK): \ -+ (strcpy_error(dest, destMax, src))) -+ -+/* for strcat_s performance optimization */ -+#if defined(__GNUC__) -+#define SECUREC_STRCAT_SM(dest, destMax, src) \ -+ ({ \ -+ int catRet = EOK; \ -+ if ((void *)dest != NULL && (void *)src != NULL && (size_t)(destMax) >0 && \ -+ (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \ -+ char *catTmpDst = (dest); \ -+ size_t catRestSize = (destMax); \ -+ while(catRestSize > 0 && *catTmpDst) { \ -+ ++catTmpDst; \ -+ --catRestSize; \ -+ } \ -+ if (catRestSize == 0) { \ -+ catRet = EINVAL; \ -+ } else if ((strlen(src) + 1) <= catRestSize) { \ -+ memcpy(catTmpDst, (src), strlen(src) + 1); \ -+ catRet = EOK; \ -+ } else { \ -+ catRet = ERANGE; \ -+ } \ -+ if (catRet != EOK) { \ -+ catRet = strcat_s((dest), (destMax), (src)); \ -+ } \ -+ } else { \ -+ catRet = strcat_s((dest), (destMax), (src)); \ -+ } \ -+ catRet; \ -+ }) -+#else -+#define SECUREC_STRCAT_SM(dest, destMax, src) strcat_s(dest, destMax, src) -+#endif -+ -+/* for strncat_s performance optimization */ -+#if defined(__GNUC__) -+#define SECUREC_STRNCAT_SM(dest, destMax, src, count) \ -+ ({ \ -+ int ncatRet = EOK; \ -+ if ((void *)dest != NULL && (void *)src != NULL && (size_t)destMax > 0 && \ -+ (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \ -+ (((unsigned long long)(count) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \ -+ char *ncatTmpDest = (dest); \ -+ size_t ncatRestSize = (destMax); \ -+ while(ncatRestSize > 0 && *ncatTmpDest) { \ -+ ++ncatTmpDest; \ -+ --ncatRestSize; \ -+ } \ -+ if (ncatRestSize == 0) { \ -+ ncatRet = EINVAL; \ -+ } else if ((SECUREC_TWO_MIN((count) , strlen(src)) + 1) <= ncatRestSize ) { \ -+ if ((count) < strlen(src)) { \ -+ memcpy(ncatTmpDest, (src), (count)); \ -+ *(ncatTmpDest + (count)) = '\0'; \ -+ } else { \ -+ memcpy(ncatTmpDest, (src), strlen(src) + 1); \ -+ } \ -+ } else { \ -+ ncatRet = ERANGE; \ -+ } \ -+ if (ncatRet != EOK) { \ -+ ncatRet = strncat_s((dest), (destMax), (src), (count)); \ -+ } \ -+ } else { \ -+ ncatRet = strncat_s((dest), (destMax), (src), (count)); \ -+ } \ -+ ncatRet; \ -+ }) -+#else -+#define SECUREC_STRNCAT_SM(dest, destMax, src, count) strncat_s(dest, destMax, src, count) -+#endif -+ -+/* SECUREC_MEMCPY_SM do NOT check buffer overlap by default */ -+#define SECUREC_MEMCPY_SM(dest, destMax, src, count) \ -+ (!(((size_t)destMax == 0 )||(((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \ -+ ((size_t)count > (size_t)destMax) || ((void *)dest) == NULL || ((void *)src == NULL))? \ -+ (memcpy(dest, src, count), EOK) : \ -+ (memcpy_s(dest, destMax, src, count))) -+ -+#define SECUREC_MEMSET_SM(dest, destMax, c, count) \ -+ (!(((size_t)destMax == 0 ) || (((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \ -+ ((void *)dest == NULL) || ((size_t)count > (size_t)destMax)) ? \ -+ (memset(dest, c, count), EOK) : \ -+ ( memset_s(dest, destMax, c, count))) -+ -+#endif -+#endif /* __SECURECTYPE_H__A7BBB686_AADA_451B_B9F9_44DACDAE18A7 */ -diff --git a/ohos_ndk_aosp/includes/utils/semaphore_ex.h b/ohos_ndk_aosp/includes/utils/semaphore_ex.h -new file mode 100755 -index 0000000000..f44eabc770 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/semaphore_ex.h -@@ -0,0 +1,74 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+#ifndef SEMAPHORE_EX_H -+#define SEMAPHORE_EX_H -+ -+#include "nocopyable.h" -+ -+#include -+#include -+#include -+#include -+#include -+#include // timespec since c11 -+ -+namespace OHOS { -+ -+const int INVALID_SEMA_VALUE = -1; -+ -+class NamedSemaphore : public NoCopyable { -+public: -+ NamedSemaphore(size_t); -+ NamedSemaphore(const std::string&, size_t); -+ ~NamedSemaphore(); -+ -+ bool Create(); -+ bool Unlink(); -+ -+ bool Open(); -+ bool Close(); -+ -+ bool Wait(); -+ bool TryWait(); -+ bool TimedWait(const struct timespec& ts); -+ bool Post(); -+ -+ int GetValue() const; -+ -+private: -+ std::string name_; -+ int maxCount_; -+ void* sema_; -+ bool named_; -+}; -+ -+class Semaphore : public NoCopyable { -+public: -+ Semaphore(int value = 1) : count_(value) {} -+ ~Semaphore() = default; -+ -+ void Wait(); -+ void Post(); -+ -+private: -+ int count_; -+ std::mutex mutex_; -+ std::condition_variable cv_; -+}; -+ -+} // OHOS -+ -+#endif -+ -diff --git a/ohos_ndk_aosp/includes/utils/singleton.h b/ohos_ndk_aosp/includes/utils/singleton.h -new file mode 100755 -index 0000000000..b831f9032d ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/singleton.h -@@ -0,0 +1,133 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_BASE_SINGLETON_H -+#define UTILS_BASE_SINGLETON_H -+ -+#include "nocopyable.h" -+#include -+#include -+ -+namespace OHOS { -+ -+#define DECLARE_DELAYED_SINGLETON(MyClass)\ -+public:\ -+ ~MyClass();\ -+private:\ -+ friend DelayedSingleton;\ -+ MyClass(); -+ -+#define DECLARE_DELAYED_REF_SINGLETON(MyClass)\ -+private:\ -+ friend DelayedRefSingleton;\ -+ ~MyClass();\ -+ MyClass(); -+ -+ -+#define DECLARE_SINGLETON(MyClass)\ -+private:\ -+ friend Singleton;\ -+ MyClass& operator=(const MyClass&) = delete;\ -+ MyClass(const MyClass&) = delete;\ -+ MyClass();\ -+ ~MyClass(); -+ -+ -+template -+class DelayedSingleton : public NoCopyable { -+public: -+ static std::shared_ptr GetInstance(); -+ static void DestroyInstance(); -+ -+private: -+ static std::shared_ptr instance_; -+ static std::mutex mutex_; -+}; -+ -+template -+std::shared_ptr DelayedSingleton::instance_ = nullptr; -+ -+template -+std::mutex DelayedSingleton::mutex_; -+ -+template -+std::shared_ptr DelayedSingleton::GetInstance() -+{ -+ if (instance_ == nullptr) { -+ std::lock_guard lock(mutex_); -+ if (instance_ == nullptr) { -+ std::shared_ptr temp(new T); -+ instance_ = temp; -+ } -+ } -+ -+ return instance_; -+} -+ -+template -+void DelayedSingleton::DestroyInstance() -+{ -+ std::lock_guard lock(mutex_); -+ if (instance_ != nullptr) { -+ instance_.reset(); -+ instance_ = nullptr; -+ } -+} -+ -+ -+ -+template -+class DelayedRefSingleton : public NoCopyable { -+public: -+ static T& GetInstance(); -+ -+private: -+ static T* instance_; -+ static std::mutex mutex_; -+}; -+ -+template -+T* DelayedRefSingleton::instance_ = nullptr; -+ -+template -+std::mutex DelayedRefSingleton::mutex_; -+ -+template -+T& DelayedRefSingleton::GetInstance() -+{ -+ if (instance_ == nullptr) { -+ std::lock_guard lock(mutex_); -+ if (instance_ == nullptr) { -+ instance_ = new T(); -+ } -+ } -+ -+ return *instance_; -+} -+ -+template -+class Singleton : public NoCopyable { -+public: -+ static T& GetInstance() { return instance_; } -+ -+private: -+ static T instance_; -+}; -+ -+template -+T Singleton::instance_; -+} // namespace OHOS -+ -+#endif -diff --git a/ohos_ndk_aosp/includes/utils/sorted_vector.h b/ohos_ndk_aosp/includes/utils/sorted_vector.h -new file mode 100755 -index 0000000000..2877445bd0 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/sorted_vector.h -@@ -0,0 +1,259 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_BASE_SORTED_VECTOR_H -+#define UTILS_BASE_SORTED_VECTOR_H -+ -+#include -+#include -+#include -+#include -+#include -+ -+namespace OHOS { -+ -+template -+class SortedVector { -+ -+public: -+ using value_type = TYPE; -+ using size_type = std::size_t; -+ using iterator = typename std::vector::iterator; -+ using const_iterator = typename std::vector::const_iterator; -+ -+ // cont and dest -+ -+ SortedVector(); -+ -+ SortedVector(const SortedVector& rhs); -+ -+ SortedVector(const SortedVector& rhs); -+ -+ SortedVector(const std::vector& orivect); -+ -+ virtual ~SortedVector() {}; -+ // copy operator -+ SortedVector& operator=(const SortedVector& rhs); -+ SortedVector& operator=(const SortedVector& rhs); -+ -+ inline void Clear() { vec_.clear(); } -+ inline size_t Size() const { return vec_.size(); } -+ inline bool IsEmpty() const { return vec_.empty(); } -+ inline size_t Capacity() const { return vec_.capacity(); } -+ -+ ssize_t SetCapcity(size_t size) -+ { -+ if (size < vec_.capacity()) { -+ return CAPCITY_NOT_CHANGED; -+ } -+ -+ vec_.reserve(size); -+ return size; -+ } -+ -+ // Cstyle access -+ // when use it , you should make sure it sorted~! -+ inline const TYPE* Array() const { return vec_.data(); }; -+ TYPE* EditArray() { return vec_.data(); }; -+ -+ ssize_t IndexOf(const TYPE& item) const; -+ size_t OrderOf(const TYPE& item) const; -+ -+ // accessors -+ inline const TYPE& operator[](size_t index) const { return vec_[index]; } -+ -+ const TYPE& Back() const { return vec_.back(); } -+ const TYPE& Front() const { return vec_.front(); } -+ void PopBack() { return vec_.pop_back(); } -+ -+ const TYPE& MirrorItemAt(ssize_t index) const -+ { -+ if (index < 0) { -+ return *(vec_.end() + index); -+ } -+ return *(vec_.begin() + index); -+ }; -+ -+ // modify the array -+ ssize_t Add(const TYPE& item); -+ TYPE& EditItemAt(size_t index) -+ { -+ return vec_[index]; -+ } -+ -+ // merge a vector into this one -+ size_t Merge(const std::vector& invec); -+ size_t Merge(const SortedVector& sortedVector); -+ -+ // erase an item at index -+ iterator Erase(size_t index) -+ { -+ if (index >= vec_.size()) { -+ return vec_.end(); -+ } -+ return vec_.erase(vec_.begin() + index); -+ } -+ -+ iterator Begin() -+ { -+ return vec_.begin(); -+ } -+ -+ const_iterator Begin() const -+ { -+ return vec_.begin(); -+ } -+ -+ iterator End() -+ { -+ return vec_.end(); -+ } -+ -+ const_iterator End() const -+ { -+ return vec_.end(); -+ } -+ -+ static const ssize_t NOT_FOUND = -1; -+ static const ssize_t ADD_FAIL = -1; -+ static const ssize_t CAPCITY_NOT_CHANGED = -1; -+ -+private: -+ std::vector vec_; -+}; -+ -+template -+inline SortedVector::SortedVector() -+ : vec_() {} -+ -+template -+SortedVector::SortedVector(const SortedVector& rhs) -+{ -+ // this class: AllowDuplicate or Not AllowDuplicate same type -+ std::copy(rhs.Begin(), rhs.End(), std::back_inserter(vec_)); -+} -+ -+template -+SortedVector::SortedVector(const SortedVector& rhs) -+{ -+ -+ if (AllowDuplicate) { -+ std::copy(rhs.Begin(), rhs.End(), std::back_inserter(vec_)); -+ } else { -+ // AllowDuplicate to Not AllowDuplicate -+ std::unique_copy(rhs.Begin(), rhs.End(), std::back_inserter(vec_)); -+ } -+} -+ -+// copy operator -+template -+SortedVector& SortedVector::operator=(const SortedVector& rhs) -+{ -+ // this class: AllowDuplicate or Not AllowDuplicate same type -+ vec_.clear(); -+ std::copy(rhs.Begin(), rhs.End(), std::back_inserter(vec_)); -+ return *this; -+} -+ -+// copy operator -+template -+SortedVector& SortedVector::operator=(const SortedVector& rhs) -+{ -+ vec_.clear(); -+ -+ if (AllowDuplicate) { -+ std::copy(rhs.Begin(), rhs.End(), std::back_inserter(vec_)); -+ } else { -+ // AllowDuplicate to Not AllowDuplicate -+ std::unique_copy(rhs.Begin(), rhs.End(), std::back_inserter(vec_)); -+ } -+ -+ return *this; -+} -+ -+template -+ssize_t SortedVector::IndexOf(const TYPE& item) const -+{ -+ if (vec_.empty()) { -+ return NOT_FOUND; -+ } -+ -+ auto it = std::lower_bound(std::begin(vec_), std::end(vec_), item); -+ if (it == vec_.end() || !(*it == item)) { -+ return NOT_FOUND; -+ } -+ return it - vec_.begin(); -+} -+ -+template -+size_t SortedVector::OrderOf(const TYPE& item) const -+{ -+ auto it = std::upper_bound(vec_.begin(), vec_.end(), item); -+ return it - vec_.begin(); -+} -+ -+template -+ssize_t SortedVector::Add(const TYPE& item) -+{ -+ ssize_t index = IndexOf(item); -+ if (index != NOT_FOUND && !AllowDuplicate) { -+ return ADD_FAIL; -+ } -+ -+ auto it = std::upper_bound(vec_.begin(), vec_.end(), item); -+ it = vec_.insert(it, item); -+ return it - vec_.begin(); -+} -+ -+template -+SortedVector::SortedVector(const std::vector& invec) -+{ -+ if (invec.empty()) { -+ return; -+ } -+ -+ std::vector newvector(invec); -+ std::sort(newvector.begin(), newvector.end()); -+ if (AllowDuplicate) { -+ vec_.swap(newvector); -+ } else { -+ std::unique_copy(newvector.begin(), newvector.end(), std::back_inserter(vec_)); -+ } -+} -+ -+template -+size_t SortedVector::Merge(const std::vector& invec) -+{ -+ SortedVector sortedVector(invec); -+ Merge(sortedVector); -+ return vec_.size(); -+} -+ -+template -+size_t SortedVector::Merge(const SortedVector& sortedVector) -+{ -+ std::vector newVec; -+ std::merge(vec_.begin(), vec_.end(), sortedVector.Begin(), sortedVector.End(), std::back_inserter(newVec)); -+ if (!AllowDuplicate) { -+ vec_.clear(); -+ std::unique_copy(newVec.begin(), newVec.end(), std::back_inserter(vec_)); -+ } else { -+ vec_.swap(newVec); -+ } -+ return vec_.size(); -+} -+ -+} // namespace OHOS -+#endif -diff --git a/ohos_ndk_aosp/includes/utils/string_ex.h b/ohos_ndk_aosp/includes/utils/string_ex.h -new file mode 100755 -index 0000000000..41be2adcd3 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/string_ex.h -@@ -0,0 +1,132 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+#ifndef STRING_EX_H -+#define STRING_EX_H -+ -+#include -+#include -+ -+namespace OHOS { -+ -+/** -+ * The UpperStr function convert all letters of str to uppercase. -+ */ -+std::string UpperStr(const std::string& str); -+ -+/** -+ * The LowerStr function convert all letters of str to lowercase. -+ */ -+std::string LowerStr(const std::string& str); -+ -+/** -+ * The ReplaceStr function will replace src with dst int base. -+ */ -+std::string ReplaceStr(const std::string& str, const std::string& src, const std::string& dst); -+ -+/** -+ * The TrimStr function will trim str by cTrim front and end. -+ */ -+std::string TrimStr(const std::string& str, const char cTrim = ' '); -+ -+/** -+ * The DexToHexString function convert decimal to hexadecimal string. -+ */ -+std::string DexToHexString(int value, bool upper = true); -+ -+/** -+ * The SplitStr function will split str by strSep. -+ */ -+void SplitStr(const std::string& str, const std::string& sep, std::vector& strs, -+ bool canEmpty = false, bool needTrim = true); -+ -+/** -+ * The ToString function convert int and double and so on to str. -+ */ -+template -+inline std::string ToString(T iValue) -+{ -+ return std::to_string(iValue); -+} -+ -+/** -+ * The StrToInt function convert str to int. -+ */ -+bool StrToInt(const std::string& str, int& value); -+ -+/** -+ * The IsNumericStr function judge all characters of the string are numbers, -+ * return true if all are numbers, else false. -+ */ -+bool IsNumericStr(const std::string& str); -+ -+/** -+ * The IsAlphaStr function judge all characters of the string are alphabet, -+ * return true if all are alphabet, else false. -+ */ -+bool IsAlphaStr(const std::string& str); -+ -+/** -+ * The IsUpperStr function judge all characters of the string are uppercase, -+ * return true if all are uppercase, else false. -+ */ -+bool IsUpperStr(const std::string& str); -+ -+/** -+ * The IsLowerStr function judge all characters of the string are lowercase, -+ * return true if all are lowercase, else false. -+ */ -+bool IsLowerStr(const std::string& str); -+ -+/** -+ * The IsSubStr function judge the sub in str, -+ * return true if sub in str, else false. -+ */ -+bool IsSubStr(const std::string& str, const std::string& sub); -+ -+/** -+ * The GetFirstSubStrBetween function get the first sub_str between left and right -+ * return the rightstr pos, if failed return string::npos. -+ */ -+std::string::size_type GetFirstSubStrBetween(const std::string& str, const std::string& left, -+ const std::string& right, std::string& sub); -+ -+/** -+ * The GetSubStrBetween function get the sub strings between left and right. -+ */ -+void GetSubStrBetween(const std::string& str, const std::string& left, -+ const std::string& right, std::vector& sub); -+ -+/** -+ * The IsSameTextStr function judge the first's letter is same with second, -+ * return true if same, else false. -+ */ -+bool IsSameTextStr(const std::string& first, const std::string& second); -+ -+bool IsAsciiString(const std::string& str); -+ -+/** -+ * The str16ToStr8 function convert string16 to string8. -+ * If convert failed, return an empty string. -+ */ -+std::string Str16ToStr8(const std::u16string& str16); -+ -+/** -+ * The Str8ToStr16 function convert string8 to string16. -+ * If convert failed, return an empty u16string. -+ */ -+std::u16string Str8ToStr16(const std::string& str); -+} // namespace OHOS -+ -+#endif // STRING_EX_H -diff --git a/ohos_ndk_aosp/includes/utils/thread_ex.h b/ohos_ndk_aosp/includes/utils/thread_ex.h -new file mode 100755 -index 0000000000..7bc0e8a639 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/thread_ex.h -@@ -0,0 +1,77 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+#ifndef UTILS_THREAD_EX_H -+#define UTILS_THREAD_EX_H -+ -+#include -+#include -+#include -+#include -+ -+namespace OHOS { -+ -+enum class ThreadStatus { -+ OK, -+ WOULD_BLOCK, -+ INVALID_OPERATION, -+ UNKNOWN_ERROR, -+}; -+ -+enum ThreadPrio { -+ THREAD_PROI_NORMAL = 0, -+ THREAD_PROI_LOW = 10, -+ THREAD_PROI_LOWEST = 19, -+}; -+ -+constexpr int INVALID_PTHREAD_T = -1; -+constexpr int MAX_THREAD_NAME_LEN = 15; -+ -+class Thread { -+public: -+ Thread(); -+ virtual ~Thread(); -+ -+ ThreadStatus Start(const std::string& name, int32_t priority = THREAD_PROI_NORMAL, size_t stack = 0); -+ -+ ThreadStatus NotifyExitSync(); -+ virtual void NotifyExitAsync(); -+ -+ virtual bool ReadyToWork(); -+ -+ bool IsExitPending() const; -+ bool IsRunning() const; -+ -+ pthread_t GetThread() const { return thread_; } -+protected: -+ virtual bool Run() = 0; // Derived class must implement Run() -+ -+private: -+ Thread& operator=(const Thread&) = delete; -+ static int ThreadStart(void* args); -+ ThreadStatus Join(); // pthread created as detached -+ -+private: -+ pthread_t thread_; -+ mutable std::mutex lock_; -+ std::condition_variable cvThreadExited_; -+ ThreadStatus status_; -+ volatile bool exitPending_; -+ volatile bool running_; -+}; -+ -+} // namespace OHOS -+ -+#endif -+ -diff --git a/ohos_ndk_aosp/includes/utils/thread_pool.h b/ohos_ndk_aosp/includes/utils/thread_pool.h -new file mode 100755 -index 0000000000..7bea3b688c ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/thread_pool.h -@@ -0,0 +1,70 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+#ifndef THREAD_POOL_H -+#define THREAD_POOL_H -+ -+#include "nocopyable.h" -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+namespace OHOS { -+ -+const int INVALID_SEMA_VALUE = -1; -+ -+class ThreadPool : public NoCopyable { -+public: -+ typedef std::function Task; -+ -+ explicit ThreadPool(const std::string &name = std::string()); -+ ~ThreadPool(); -+ -+ uint32_t Start(int threadsNum); -+ void Stop(); -+ void AddTask(const Task& f); -+ void SetMaxTaskNum(int maxSize) { maxTaskNum_ = maxSize; } -+ -+ // for testability -+ size_t GetMaxTaskNum() const { return maxTaskNum_; } -+ size_t GetCurTaskNum(); -+ size_t GetThreadsNum() const { return threads_.size(); } -+ std::string GetName() const { return myName_; } -+ -+private: -+ // tasks in the queue reach the maximum set by maxQueueSize, means thread pool is full load. -+ bool Overloaded() const; -+ void WorkInThread(); // main function in each thread. -+ Task ScheduleTask(); // fetch a task from the queue and execute -+ -+private: -+ std::string myName_; -+ std::mutex mutex_; -+ std::condition_variable hasTaskToDo_; -+ std::condition_variable acceptNewTask_; -+ std::vector threads_; -+ std::deque tasks_; -+ size_t maxTaskNum_; -+ bool running_; -+}; -+ -+} // namespace OHOS -+ -+#endif -+ -diff --git a/ohos_ndk_aosp/includes/utils/timer.h b/ohos_ndk_aosp/includes/utils/timer.h -new file mode 100755 -index 0000000000..8b09ee4c15 ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/timer.h -@@ -0,0 +1,100 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UTILS_TIMER_H -+#define UTILS_TIMER_H -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#include "../src/event_reactor.h" -+ -+namespace OHOS { -+namespace Utils { -+ -+class Timer { -+public: -+ using TimerCallback = std::function; -+ using TimerCallbackPtr = std::shared_ptr; -+ using TimerListCallback = std::function; -+ -+public: -+ /* -+ * if performance-sensitive, change "timeout" larger before Setup -+ * default-value(1000ms), performance-estimate: occupy fixed-100us in every default-value(1000ms) -+ * timeout: range [-1, INT32MAX], but [-1,0] is not recommended -+ * -1: wait for ever(until event-trigger); -+ * 0: no wait, occupy too much cpu time; -+ * others: wait(until event-trigger) -+ */ -+ explicit Timer(const std::string& name, int timeoutMs = 1000); -+ virtual ~Timer() {} -+ -+ virtual uint32_t Setup(); -+ -+ /* -+ * useJoin true: use std::thread::join(default) -+ * false: use std::thread::detach(not recommended) -+ * if timeoutMs = -1 and no valid event-trigger in epoll_wait: -+ * use std::thread::detach inside to avoid deadloop -+ */ -+ virtual void Shutdown(bool useJoin = true); -+ -+ uint32_t Register(const TimerCallback& callback, uint32_t interval /* ms */, bool once = false); -+ void Unregister(uint32_t timerId); -+ -+private: -+ void MainLoop(); -+ void OnTimer(int timerFd); -+ virtual uint32_t DoRegister(const TimerListCallback& callback, uint32_t interval, bool once, int &timerFd); -+ virtual void DoUnregister(uint32_t interval); -+ void DoTimerListCallback(const TimerListCallback& callback, int timerFd); -+ uint32_t GetValidId(uint32_t timerId) const; -+ int GetTimerFd(uint32_t interval /* ms */); -+ void EraseUnusedTimerId(uint32_t interval, const std::vector& unusedIds); -+ -+private: -+ struct TimerEntry { -+ uint32_t timerId; // unique id -+ uint32_t interval; // million second -+ TimerCallback callback; -+ bool once; -+ int timerFd; -+ }; -+ -+ using TimerEntryPtr = std::shared_ptr; -+ using TimerEntryList = std::list; -+ -+ std::map intervalToTimers_; // interval to TimerEntryList -+ std::map timerToEntries_; // timer_id to TimerEntry -+ -+ std::string name_; -+ int timeoutMs_; -+ std::thread thread_; -+ std::unique_ptr reactor_; -+ std::map timers_; // timer_fd to interval -+ std::mutex mutex_; -+}; -+ -+} // namespace Utils -+} // namespace OHOS -+#endif -+ -diff --git a/ohos_ndk_aosp/includes/utils/unique_fd.h b/ohos_ndk_aosp/includes/utils/unique_fd.h -new file mode 100755 -index 0000000000..24a00dedce ---- /dev/null -+++ b/ohos_ndk_aosp/includes/utils/unique_fd.h -@@ -0,0 +1,186 @@ -+/* -+ * Copyright (c) 2021 Huawei Device Co., Ltd. -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#ifndef UNIQUE_FD_H -+#define UNIQUE_FD_H -+ -+#include -+ -+namespace OHOS { -+class DefaultDeleter { -+public: -+ static void Close(int fd) -+ { -+ if (fd >= 0) { -+ close(fd); -+ } -+ } -+}; -+ -+template -+class UniqueFdAddDeletor; -+template -+bool operator==(const int& lhs, const UniqueFdAddDeletor& rhs); -+template -+bool operator!=(const int& lhs, const UniqueFdAddDeletor& rhs); -+template -+bool operator>=(const int& lhs, const UniqueFdAddDeletor& rhs); -+template -+bool operator>(const int& lhs, const UniqueFdAddDeletor& rhs); -+template -+bool operator<=(const int& lhs, const UniqueFdAddDeletor& rhs); -+template -+bool operator<(const int& lhs, const UniqueFdAddDeletor& rhs); -+ -+template -+class UniqueFdAddDeletor final { -+ -+ friend bool operator==(const int& lhs, const UniqueFdAddDeletor& rhs); -+ -+ friend bool operator!=(const int& lhs, const UniqueFdAddDeletor& rhs); -+ -+ friend bool operator>=(const int& lhs, const UniqueFdAddDeletor& rhs); -+ -+ friend bool operator>(const int& lhs, const UniqueFdAddDeletor& rhs); -+ -+ friend bool operator<=(const int& lhs, const UniqueFdAddDeletor& rhs); -+ -+ friend bool operator< (const int& lhs, const UniqueFdAddDeletor& rhs); -+ -+public: -+ explicit UniqueFdAddDeletor(const int& value) -+ : fd_(value) -+ { -+ } -+ UniqueFdAddDeletor() -+ : fd_(-1) -+ { -+ } -+ ~UniqueFdAddDeletor() { Reset(-1); } -+ -+ // get fd out -+ int Release() -+ { -+ int tmp = fd_; -+ fd_ = -1; -+ return tmp; -+ } -+ -+ // this is dangerous, when you use it , you should know it, donot operator on the ret -+ operator int() const { return Get(); } // NOLINT -+ // this is dangerous, when you use it , you should know it, donot operator on the ret -+ int Get() const -+ { -+ return fd_; -+ } -+ -+ // we need move fd from one to another -+ UniqueFdAddDeletor(UniqueFdAddDeletor&& rhs) -+ { -+ int rhsfd = rhs.Release(); -+ fd_ = rhsfd; -+ } -+ -+ UniqueFdAddDeletor& operator=(UniqueFdAddDeletor&& rhs) -+ { -+ int rhsfd = rhs.Release(); -+ Reset(rhsfd); -+ return *this; -+ } -+ -+ bool operator==(const int& rhs) const -+ { -+ return fd_ == rhs; -+ } -+ -+ bool operator!=(const int& rhs) const -+ { -+ return !(fd_ == rhs); -+ } -+ bool operator>=(const int& rhs) const -+ { -+ return fd_ >= rhs; -+ } -+ -+ bool operator>(const int& rhs) const -+ { -+ return fd_ > rhs; -+ } -+ -+ bool operator<=(const int& rhs) const -+ { -+ return fd_ <= rhs; -+ } -+ -+ bool operator<(const int& rhs) const -+ { -+ return fd_ < rhs; -+ } -+ -+private: -+ int fd_ = -1; -+ -+ void Reset(int newValue) -+ { -+ if (fd_ >= 0) { -+ Deleter::Close(fd_); -+ } -+ fd_ = newValue; -+ } -+ -+ // disallow copy ctor and copy assign -+ UniqueFdAddDeletor(const UniqueFdAddDeletor& rhs) = delete; -+ UniqueFdAddDeletor& operator=(const UniqueFdAddDeletor& rhs) = delete; -+}; -+ -+template -+bool operator==(const int& lhs, const UniqueFdAddDeletor& uniqueFd) -+{ -+ return lhs == uniqueFd.fd_; -+} -+ -+template -+bool operator!=(const int& lhs, const UniqueFdAddDeletor& uniqueFd) -+{ -+ return !(lhs == uniqueFd.fd_); -+} -+ -+template -+bool operator>=(const int& lhs, const UniqueFdAddDeletor& uniqueFd) -+{ -+ return lhs >= uniqueFd.fd_; -+} -+ -+template -+bool operator>(const int& lhs, const UniqueFdAddDeletor& uniqueFd) -+{ -+ return lhs > uniqueFd.fd_; -+} -+ -+template -+bool operator<=(const int& lhs, const UniqueFdAddDeletor& uniqueFd) -+{ -+ return lhs <= uniqueFd.fd_; -+} -+ -+template -+bool operator<(const int& lhs, const UniqueFdAddDeletor& uniqueFd) -+{ -+ return lhs < uniqueFd.fd_; -+} -+ -+using UniqueFd = UniqueFdAddDeletor; -+} // namespace OHOS -+#endif -diff --git a/ohos_ndk_aosp/libs/libeventhandler.z.so b/ohos_ndk_aosp/libs/libeventhandler.z.so -new file mode 100755 -index 0000000000..c618342622 -Binary files /dev/null and b/ohos_ndk_aosp/libs/libeventhandler.z.so differ -diff --git a/ohos_ndk_aosp/libs/libhilog.so b/ohos_ndk_aosp/libs/libhilog.so -new file mode 100755 -index 0000000000..5dc858e6e4 -Binary files /dev/null and b/ohos_ndk_aosp/libs/libhilog.so differ -diff --git a/ohos_ndk_aosp/libs/libinputmethod_ability.z.so b/ohos_ndk_aosp/libs/libinputmethod_ability.z.so -new file mode 100755 -index 0000000000..83ccbab51f -Binary files /dev/null and b/ohos_ndk_aosp/libs/libinputmethod_ability.z.so differ -diff --git a/ohos_ndk_aosp/libs/libinputmethod_client.z.so b/ohos_ndk_aosp/libs/libinputmethod_client.z.so -new file mode 100755 -index 0000000000..0e3d497f79 -Binary files /dev/null and b/ohos_ndk_aosp/libs/libinputmethod_client.z.so differ -diff --git a/ohos_ndk_aosp/libs/libipc_core.z.so b/ohos_ndk_aosp/libs/libipc_core.z.so -new file mode 100755 -index 0000000000..c5007c7ff9 -Binary files /dev/null and b/ohos_ndk_aosp/libs/libipc_core.z.so differ -diff --git a/ohos_ndk_aosp/libs/libmedia_client.z.so b/ohos_ndk_aosp/libs/libmedia_client.z.so -new file mode 100755 -index 0000000000..f6596871fa -Binary files /dev/null and b/ohos_ndk_aosp/libs/libmedia_client.z.so differ -diff --git a/ohos_ndk_aosp/libs/libsurface.z.so b/ohos_ndk_aosp/libs/libsurface.z.so -new file mode 100755 -index 0000000000..cc223000ff -Binary files /dev/null and b/ohos_ndk_aosp/libs/libsurface.z.so differ -diff --git a/ohos_ndk_aosp/libs/libutils.z.so b/ohos_ndk_aosp/libs/libutils.z.so -new file mode 100755 -index 0000000000..f737ea3319 -Binary files /dev/null and b/ohos_ndk_aosp/libs/libutils.z.so differ diff --git a/ohos_nweb/BUILD.gn b/ohos_nweb/BUILD.gn index c87c2a462f..aa77be3230 100644 --- a/ohos_nweb/BUILD.gn -- Gitee