From af5a9e423e78ecbbd115dcb6bcda8bdd9e729ba6 Mon Sep 17 00:00:00 2001 From: Bagwey Date: Tue, 21 Jan 2025 15:55:15 +0800 Subject: [PATCH 1/2] add background process manager API Signed-off-by: Bagwey --- ndk_targets.gni | 2 + .../background_process_manager/BUILD.gn | 27 +++++ .../background_process_manager.ndk.json | 10 ++ .../include/background_process_manager.h | 112 ++++++++++++++++++ 4 files changed, 151 insertions(+) create mode 100644 resourceschedule/background_process_manager/BUILD.gn create mode 100644 resourceschedule/background_process_manager/background_process_manager.ndk.json create mode 100644 resourceschedule/background_process_manager/include/background_process_manager.h diff --git a/ndk_targets.gni b/ndk_targets.gni index 344c73ff8..00fe912db 100644 --- a/ndk_targets.gni +++ b/ndk_targets.gni @@ -203,6 +203,8 @@ _ndk_library_targets = [ "//interface/sdk_c/sensors/sensor:sensor_ndk_header", "//interface/sdk_c/resourceschedule/qos_manager:libqos_ndk", "//interface/sdk_c/resourceschedule/qos_manager:qos_header", + "//interface/sdk_c/resourceschedule/background_process_manager:libbackground_process_manager_ndk", + "//interface/sdk_c/resourceschedule/background_process_manager:background_process_manager_header", "//interface/sdk_c/filemanagement/fileio:libohfileio", "//interface/sdk_c/filemanagement/fileio:oh_fileio_header", "//interface/sdk_c/filemanagement/environment:libohenvironment", diff --git a/resourceschedule/background_process_manager/BUILD.gn b/resourceschedule/background_process_manager/BUILD.gn new file mode 100644 index 000000000..5fc3ce1d8 --- /dev/null +++ b/resourceschedule/background_process_manager/BUILD.gn @@ -0,0 +1,27 @@ +# Copyright (c) 2025 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") +import("//build/ohos/ndk/ndk.gni") + +ohos_ndk_headers("background_process_manager_header") { + dest_dir = "$ndk_headers_out_dir/background_process_manager" + sources = [ "include/background_process_manager.h" ] +} + +ohos_ndk_library("libbackground_process_manager_ndk") { + output_name = "background_process_manager" + ndk_description_file = "./background_process_manager.ndk.json" + system_capability = "SystemCapability.Resourceschedule.BackgroundProcessManager" + system_capability_headers = [ "background_process_manager/background_process_manager.h" ] +} diff --git a/resourceschedule/background_process_manager/background_process_manager.ndk.json b/resourceschedule/background_process_manager/background_process_manager.ndk.json new file mode 100644 index 000000000..022e94975 --- /dev/null +++ b/resourceschedule/background_process_manager/background_process_manager.ndk.json @@ -0,0 +1,10 @@ +[ + { + "first_introduced": "15", + "name": "OH_BackgroundProcessManager_SetProcessPriority" + }, + { + "first_introduced": "15", + "name": "OH_BackgroundProcessManager_ResetProcessPriority" + } +] \ No newline at end of file diff --git a/resourceschedule/background_process_manager/include/background_process_manager.h b/resourceschedule/background_process_manager/include/background_process_manager.h new file mode 100644 index 000000000..c9e3c085c --- /dev/null +++ b/resourceschedule/background_process_manager/include/background_process_manager.h @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2025 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 BackgroundProcessManager + * @{ + * + * @brief BackgroundProcessManager provides APIs. + * + * @since 15 + */ + +/** + * @file background_process_manager.h + * + * @brief Declares the BackgroundProcessManager interfaces in C. + * + * BackgroundProcessManager refers to set or reset priority of process + * + * @library libbackground_process_manager.z.so + * @kit BackgroundTasksKit + * @syscap SystemCapability.Resourceschedule.BackgroundProcessManager + * @since 15 + */ + +#ifndef RESOURCESCHEDULE_BACKGROUND_PROCESS_MANAGER_H +#define RESOURCESCHEDULE_BACKGROUND_PROCESS_MANAGER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Describes the level of BackgroundProcessManager priority. + * + * @since 15 + */ +typedef enum BackgroundProcessManager_ProcessPriority { + /** + * @brief Means the process has stopped working and in the background + */ + PROCESS_BACKGROUND = 1, + + /** + * @brief Means the process is working in the background + */ + PROCESS_INACTIVE = 2, +} BackgroundProcessManager_ProcessPriority; + +/** + * @brief Enum for BackgroundProcessManager error code. + * + * @since 15 + */ +typedef enum BackgroundProcessManager_ErrorCode { + /** + * @error result is OK. + */ + ERR_BACKGROUND_PROCESS_MANAGER_SUCCESS = 0, + + /** + * @error invalid parameter. Possible causes: + * 1. priority is out of range. + */ + ERR_BACKGROUND_PROCESS_MANAGER_INVALID_PARAM = 401, + + /** + * @error remote error. Possible causes: + * 1. remote is not work. + */ + ERR_BACKGROUND_PROCESS_MANAGER_REMOTE_ERROR = 31800001, +} BackgroundProcessManager_ErrorCode; + +/** + * @brief Set the priority of process. + * + * @param pid Indicates the pid of the process to be set. + * @param priority Indicates the priority to be set. + Specific priority can be referenced {@link BackgroundProcessManager_ProcessPriority}. + * @return {@link ERR_BACKGROUND_PROCESS_MANAGER_SUCCESS} 0 - Success. + * {@link ERR_BACKGROUND_PROCESS_MANAGER_INVALID_PARAM} 401 - Parameter error. + * {@link ERR_BACKGROUND_PROCESS_MANAGER_REMOTE_ERROR} 31800001 - Remote error. + * @since 15 + */ +int OH_BackgroundProcessManager_SetProcessPriority(int pid, BackgroundProcessManager_ProcessPriority priority); + +/** + * @brief Reset the priority of process. + * + * @param pid Indicates the pid of the process to be reset. + * @return {@link ERR_BACKGROUND_PROCESS_MANAGER_SUCCESS} 0 - Success. + * {@link ERR_BACKGROUND_PROCESS_MANAGER_REMOTE_ERROR} 31800001 - Remote error. + * @since 15 + */ +int OH_BackgroundProcessManager_ResetProcessPriority(int pid); +#ifdef __cplusplus +}; +#endif +#endif // RESOURCESCHEDULE_BACKGROUND_PROCESS_MANAGER_H +/** @} */ -- Gitee From f1aec05415f81af5d2318d693c54b5c88b723ad6 Mon Sep 17 00:00:00 2001 From: Bagwey Date: Tue, 21 Jan 2025 16:51:25 +0800 Subject: [PATCH 2/2] update gn format Signed-off-by: Bagwey --- .../background_process_manager/BUILD.gn | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/resourceschedule/background_process_manager/BUILD.gn b/resourceschedule/background_process_manager/BUILD.gn index 5fc3ce1d8..e074dddca 100644 --- a/resourceschedule/background_process_manager/BUILD.gn +++ b/resourceschedule/background_process_manager/BUILD.gn @@ -15,13 +15,15 @@ import("//build/ohos.gni") import("//build/ohos/ndk/ndk.gni") ohos_ndk_headers("background_process_manager_header") { - dest_dir = "$ndk_headers_out_dir/background_process_manager" - sources = [ "include/background_process_manager.h" ] + dest_dir = "$ndk_headers_out_dir/background_process_manager" + sources = [ "include/background_process_manager.h" ] } ohos_ndk_library("libbackground_process_manager_ndk") { - output_name = "background_process_manager" - ndk_description_file = "./background_process_manager.ndk.json" - system_capability = "SystemCapability.Resourceschedule.BackgroundProcessManager" - system_capability_headers = [ "background_process_manager/background_process_manager.h" ] + output_name = "background_process_manager" + ndk_description_file = "./background_process_manager.ndk.json" + system_capability = + "SystemCapability.Resourceschedule.BackgroundProcessManager" + system_capability_headers = + [ "background_process_manager/background_process_manager.h" ] } -- Gitee