From b8802c1fab0c0abdbe6dec2d044ed5e6acb20c9d Mon Sep 17 00:00:00 2001 From: yinhuiling Date: Tue, 30 Jan 2024 20:54:59 +0800 Subject: [PATCH] Add LoopObserver file and errorManager interface Signed-off-by: peterhuangyu --- api/@ohos.app.ability.errorManager.d.ts | 36 +++++++++++++++++++++++++ api/application/LoopObserver.d.ts | 34 +++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 api/application/LoopObserver.d.ts diff --git a/api/@ohos.app.ability.errorManager.d.ts b/api/@ohos.app.ability.errorManager.d.ts index 73ff6fc1d8..2514510295 100644 --- a/api/@ohos.app.ability.errorManager.d.ts +++ b/api/@ohos.app.ability.errorManager.d.ts @@ -20,6 +20,7 @@ import { AsyncCallback } from './@ohos.base'; import * as _ErrorObserver from './application/ErrorObserver'; +import * as _LoopObserver from './application/LoopObserver'; /** * This module provides the function of error manager. @@ -112,6 +113,33 @@ declare namespace errorManager { */ function off(type: 'error', observerId: number): Promise; + /** + * Register loop observer. This function can only by called from main thread, + * and if call this function multiple times, the last + * modification will overwrite the previous one. + * + * @param { 'loopObserver' } type - loopObserver. + * @param { number } timeout - Indicates timeout(ms) value of loop observer. + * @param { LoopObserver } observer - The loop observer. + * @throws { BusinessError } 401 - If the input parameter is not valid parameter. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @atomicservice + * @since 12 + */ + function on(type: 'loopObserver', timeout: number, observer: LoopObserver): void; + + /** + * Unregister loop observer. This function can only by called from main thread. + * + * @param { 'loopObserver' } type - loopObserver. + * @param { LoopObserver } observer - The loop observer. + * @throws { BusinessError } 401 - If the input parameter is not valid parameter. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @atomicservice + * @since 12 + */ + function off(type: 'loopObserver', observer?: LoopObserver): void; + /** * The observer will be called by system when an error occurs. * @@ -126,6 +154,14 @@ declare namespace errorManager { * @since 11 */ export type ErrorObserver = _ErrorObserver.default; + /** + * The observer will be called when application main thread execute timeout. + * + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @atomicservice + * @since 12 + */ + export type LoopObserver = _LoopObserver.default; } export default errorManager; diff --git a/api/application/LoopObserver.d.ts b/api/application/LoopObserver.d.ts new file mode 100644 index 0000000000..00c6910111 --- /dev/null +++ b/api/application/LoopObserver.d.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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. + */ + +/** + * The observer will be called by system when application main thread loop + * execute timeout + * @interface LoopObserver + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @atomicservice + * @since 12 + */ +export interface LoopObserver { + /** + * Will be called when the application main thread loop execute timeout. + * + * @param { number } timeout - the actual executing time of loop event. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @atomicservice + * @since 12 + */ + onLoopTimeOut?(timeout: number): void; +} -- Gitee