161847f8eSopenharmony_ci/* 261847f8eSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 461847f8eSopenharmony_ci * you may not use this file except in compliance with the License. 561847f8eSopenharmony_ci * You may obtain a copy of the License at 661847f8eSopenharmony_ci * 761847f8eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 861847f8eSopenharmony_ci * 961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and 1361847f8eSopenharmony_ci * limitations under the License. 1461847f8eSopenharmony_ci */ 1561847f8eSopenharmony_ci 1661847f8eSopenharmony_ci/** 1761847f8eSopenharmony_ci * @file 1861847f8eSopenharmony_ci * @kit BasicServicesKit 1961847f8eSopenharmony_ci */ 2061847f8eSopenharmony_ci 2161847f8eSopenharmony_ciimport { AsyncCallback } from './@ohos.base'; 2261847f8eSopenharmony_ciimport { WantAgent } from './@ohos.app.ability.wantAgent'; 2361847f8eSopenharmony_ci 2461847f8eSopenharmony_ci/** 2561847f8eSopenharmony_ci * Provides js api for systemTimer 2661847f8eSopenharmony_ci * 2761847f8eSopenharmony_ci * @namespace systemTimer 2861847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 2961847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 3061847f8eSopenharmony_ci * @since 7 3161847f8eSopenharmony_ci */ 3261847f8eSopenharmony_cideclare namespace systemTimer { 3361847f8eSopenharmony_ci /** 3461847f8eSopenharmony_ci * Indicates the timing policy the timer use, which can be REALTIME or UTC. 3561847f8eSopenharmony_ci * 3661847f8eSopenharmony_ci * @constant 3761847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 3861847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 3961847f8eSopenharmony_ci * @since 7 4061847f8eSopenharmony_ci */ 4161847f8eSopenharmony_ci const TIMER_TYPE_REALTIME: number; 4261847f8eSopenharmony_ci 4361847f8eSopenharmony_ci /** 4461847f8eSopenharmony_ci * Describes whether a timer will wake the device up. 4561847f8eSopenharmony_ci * 4661847f8eSopenharmony_ci * @constant 4761847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 4861847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 4961847f8eSopenharmony_ci * @since 7 5061847f8eSopenharmony_ci */ 5161847f8eSopenharmony_ci const TIMER_TYPE_WAKEUP: number; 5261847f8eSopenharmony_ci 5361847f8eSopenharmony_ci /** 5461847f8eSopenharmony_ci * Describes whether a timer will be delivered precisely at a scheduled time. 5561847f8eSopenharmony_ci * 5661847f8eSopenharmony_ci * @constant 5761847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 5861847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 5961847f8eSopenharmony_ci * @since 7 6061847f8eSopenharmony_ci */ 6161847f8eSopenharmony_ci const TIMER_TYPE_EXACT: number; 6261847f8eSopenharmony_ci 6361847f8eSopenharmony_ci /** 6461847f8eSopenharmony_ci * Indicates whether the timer waking up the system is supported in low-power mode. 6561847f8eSopenharmony_ci * 6661847f8eSopenharmony_ci * @constant 6761847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 6861847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 6961847f8eSopenharmony_ci * @since 7 7061847f8eSopenharmony_ci */ 7161847f8eSopenharmony_ci const TIMER_TYPE_IDLE: number; 7261847f8eSopenharmony_ci 7361847f8eSopenharmony_ci /** 7461847f8eSopenharmony_ci * Creates a timer. 7561847f8eSopenharmony_ci * 7661847f8eSopenharmony_ci * @param { TimerOptions } options - The timer options. 7761847f8eSopenharmony_ci * @param { AsyncCallback<number> } callback - {number} is the timer ID. 7861847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 7961847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 8061847f8eSopenharmony_ci * 3.Parameter verification failed. 8161847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 8261847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 8361847f8eSopenharmony_ci * @since 7 8461847f8eSopenharmony_ci */ 8561847f8eSopenharmony_ci function createTimer(options: TimerOptions, callback: AsyncCallback<number>): void; 8661847f8eSopenharmony_ci 8761847f8eSopenharmony_ci /** 8861847f8eSopenharmony_ci * Creates a timer. 8961847f8eSopenharmony_ci * 9061847f8eSopenharmony_ci * @param { TimerOptions } options - The timer options. 9161847f8eSopenharmony_ci * @returns { Promise<number> } the timer ID. 9261847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 9361847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 9461847f8eSopenharmony_ci * 3.Parameter verification failed. 9561847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 9661847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 9761847f8eSopenharmony_ci * @since 7 9861847f8eSopenharmony_ci */ 9961847f8eSopenharmony_ci function createTimer(options: TimerOptions): Promise<number>; 10061847f8eSopenharmony_ci 10161847f8eSopenharmony_ci /** 10261847f8eSopenharmony_ci * Starts a timer. 10361847f8eSopenharmony_ci * 10461847f8eSopenharmony_ci * @param { number } timer - The timer ID. 10561847f8eSopenharmony_ci * @param { number } triggerTime - Indicates the time at which the timer is triggered for the first time, in milliseconds. 10661847f8eSopenharmony_ci * The time will be automatically set to 5000 milliseconds after the current time if the passed 10761847f8eSopenharmony_ci * value is smaller than the current time plus 5000 milliseconds. 10861847f8eSopenharmony_ci * @param { AsyncCallback<void> } callback - The callback function. 10961847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 11061847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. 11161847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 11261847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 11361847f8eSopenharmony_ci * @since 7 11461847f8eSopenharmony_ci */ 11561847f8eSopenharmony_ci function startTimer(timer: number, triggerTime: number, callback: AsyncCallback<void>): void; 11661847f8eSopenharmony_ci 11761847f8eSopenharmony_ci /** 11861847f8eSopenharmony_ci * Starts a timer. 11961847f8eSopenharmony_ci * 12061847f8eSopenharmony_ci * @param { number } timer - The timer ID. 12161847f8eSopenharmony_ci * @param { number } triggerTime - Indicates the time at which the timer is triggered for the first time, in milliseconds. 12261847f8eSopenharmony_ci * The time will be automatically set to 5000 milliseconds after the current time if the passed 12361847f8eSopenharmony_ci * value is smaller than the current time plus 5000 milliseconds. 12461847f8eSopenharmony_ci * @returns { Promise<void> } return a promise object. 12561847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 12661847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. 12761847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 12861847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 12961847f8eSopenharmony_ci * @since 7 13061847f8eSopenharmony_ci */ 13161847f8eSopenharmony_ci function startTimer(timer: number, triggerTime: number): Promise<void>; 13261847f8eSopenharmony_ci 13361847f8eSopenharmony_ci /** 13461847f8eSopenharmony_ci * Stops a timer. 13561847f8eSopenharmony_ci * 13661847f8eSopenharmony_ci * @param { number } timer - The timer ID. 13761847f8eSopenharmony_ci * @param { AsyncCallback<void> } callback - The callback function. 13861847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 13961847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. 14061847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 14161847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 14261847f8eSopenharmony_ci * @since 7 14361847f8eSopenharmony_ci */ 14461847f8eSopenharmony_ci function stopTimer(timer: number, callback: AsyncCallback<void>): void; 14561847f8eSopenharmony_ci 14661847f8eSopenharmony_ci /** 14761847f8eSopenharmony_ci * Stops a timer. 14861847f8eSopenharmony_ci * 14961847f8eSopenharmony_ci * @param { number } timer - The timer ID. 15061847f8eSopenharmony_ci * @returns { Promise<void> } return a promise object. 15161847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 15261847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. 15361847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 15461847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 15561847f8eSopenharmony_ci * @since 7 15661847f8eSopenharmony_ci */ 15761847f8eSopenharmony_ci function stopTimer(timer: number): Promise<void>; 15861847f8eSopenharmony_ci 15961847f8eSopenharmony_ci /** 16061847f8eSopenharmony_ci * Destroy a timer. 16161847f8eSopenharmony_ci * 16261847f8eSopenharmony_ci * @param { number } timer - The timer ID. 16361847f8eSopenharmony_ci * @param { AsyncCallback<void> } callback - The callback function. 16461847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 16561847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. 16661847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 16761847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 16861847f8eSopenharmony_ci * @since 7 16961847f8eSopenharmony_ci */ 17061847f8eSopenharmony_ci function destroyTimer(timer: number, callback: AsyncCallback<void>): void; 17161847f8eSopenharmony_ci 17261847f8eSopenharmony_ci /** 17361847f8eSopenharmony_ci * Destroy a timer. 17461847f8eSopenharmony_ci * 17561847f8eSopenharmony_ci * @param { number } timer - The timer ID. 17661847f8eSopenharmony_ci * @returns { Promise<void> } return a promise object. 17761847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 17861847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. 17961847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 18061847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 18161847f8eSopenharmony_ci * @since 7 18261847f8eSopenharmony_ci */ 18361847f8eSopenharmony_ci function destroyTimer(timer: number): Promise<void>; 18461847f8eSopenharmony_ci 18561847f8eSopenharmony_ci /** 18661847f8eSopenharmony_ci * When the repeat is false,the interval is not needed, choose one of wantAgent and callback. 18761847f8eSopenharmony_ci * When the repeat is true,the interval is required, the wantAgent is required, and the callback can be left blank. 18861847f8eSopenharmony_ci * 18961847f8eSopenharmony_ci * @interface TimerOptions 19061847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 19161847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 19261847f8eSopenharmony_ci * @since 7 19361847f8eSopenharmony_ci */ 19461847f8eSopenharmony_ci interface TimerOptions { 19561847f8eSopenharmony_ci /** 19661847f8eSopenharmony_ci * The timer type. 19761847f8eSopenharmony_ci * 19861847f8eSopenharmony_ci * @type { number } 19961847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 20061847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 20161847f8eSopenharmony_ci * @since 7 20261847f8eSopenharmony_ci */ 20361847f8eSopenharmony_ci type: number; 20461847f8eSopenharmony_ci 20561847f8eSopenharmony_ci /** 20661847f8eSopenharmony_ci * Indicates a repeating timer 20761847f8eSopenharmony_ci * 20861847f8eSopenharmony_ci * @type { boolean } 20961847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 21061847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 21161847f8eSopenharmony_ci * @since 7 21261847f8eSopenharmony_ci */ 21361847f8eSopenharmony_ci repeat: boolean; 21461847f8eSopenharmony_ci 21561847f8eSopenharmony_ci /** 21661847f8eSopenharmony_ci * Indicates the interval between two consecutive triggers, in milliseconds. 21761847f8eSopenharmony_ci * The interval will be set to 5000 milliseconds automatically if the passed value is smaller than 5000. 21861847f8eSopenharmony_ci * 21961847f8eSopenharmony_ci * @type { ?number } 22061847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 22161847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 22261847f8eSopenharmony_ci * @since 7 22361847f8eSopenharmony_ci */ 22461847f8eSopenharmony_ci interval?: number; 22561847f8eSopenharmony_ci 22661847f8eSopenharmony_ci /** 22761847f8eSopenharmony_ci * Indicates the intent to send when the timer goes off. 22861847f8eSopenharmony_ci * 22961847f8eSopenharmony_ci * @type { ?WantAgent } 23061847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 23161847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 23261847f8eSopenharmony_ci * @since 7 23361847f8eSopenharmony_ci */ 23461847f8eSopenharmony_ci wantAgent?: WantAgent; 23561847f8eSopenharmony_ci 23661847f8eSopenharmony_ci /** 23761847f8eSopenharmony_ci * Called back when the timer goes off. 23861847f8eSopenharmony_ci * 23961847f8eSopenharmony_ci * @type { ?function } 24061847f8eSopenharmony_ci * @syscap SystemCapability.MiscServices.Time 24161847f8eSopenharmony_ci * @systemapi Hide this for inner system use. 24261847f8eSopenharmony_ci * @since 7 24361847f8eSopenharmony_ci */ 24461847f8eSopenharmony_ci callback?: () => void; 24561847f8eSopenharmony_ci } 24661847f8eSopenharmony_ci} 24761847f8eSopenharmony_ci 24861847f8eSopenharmony_ciexport default systemTimer;