diff --git a/ndk_targets.gni b/ndk_targets.gni index 344c73ff8af64608f28dd403e622bfe273a946a0..00fe912db2f0b2ce5850042f501a6846124293e9 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 0000000000000000000000000000000000000000..e074dddca20d28bdbeebfecbd3df99c5d7910021 --- /dev/null +++ b/resourceschedule/background_process_manager/BUILD.gn @@ -0,0 +1,29 @@ +# 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 0000000000000000000000000000000000000000..022e9497562bd27122e3edbccbeea32394f87f61 --- /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 0000000000000000000000000000000000000000..c9e3c085c02b91e650e312fc88b457118bcbf6e8 --- /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 +/** @} */