• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { AsyncCallback, ErrorCallback } from './basic';
17import { WantAgent } from './@ohos.wantAgent';
18
19/**
20 * Provides js api for systemTimer
21 *
22 * @syscap SystemCapability.MiscServices.Time
23 * @systemapi Hide this for inner system use.
24 * @since 7
25 */
26declare namespace systemTimer {
27  /**
28   * Indicates the timing policy the timer use, which can be REALTIME or UTC.
29   *
30   * @constant
31   * @syscap SystemCapability.MiscServices.Time
32   * @systemapi Hide this for inner system use.
33   * @since 7
34   */
35  const TIMER_TYPE_REALTIME: number;
36
37  /**
38   * Describes whether a timer will wake the device up.
39   *
40   * @constant
41   * @syscap SystemCapability.MiscServices.Time
42   * @systemapi Hide this for inner system use.
43   * @since 7
44   */
45  const TIMER_TYPE_WAKEUP: number;
46
47  /**
48   * Describes whether a timer will be delivered precisely at a scheduled time.
49   *
50   * @constant
51   * @syscap SystemCapability.MiscServices.Time
52   * @systemapi Hide this for inner system use.
53   * @since 7
54   */
55  const TIMER_TYPE_EXACT: number;
56
57  /**
58   * Indicates whether the timer waking up the system is supported in low-power mode.
59   *
60   * @constant
61   * @syscap SystemCapability.MiscServices.Time
62   * @systemapi Hide this for inner system use.
63   * @since 7
64   */
65  const TIMER_TYPE_IDLE: number;
66
67  /**
68   * Creates a timer.
69   *
70   * @param options Indicates the timer options.
71   * @param { TimerOptions } options - The necessary configuration information.
72   * @param { AsyncCallback<number> } callback - {number} is the timer ID.
73   * @throws { BusinessError } 202 - permission denied.
74   * @throws { BusinessError } 401 - if the parameter type is incorrect.
75   * @syscap SystemCapability.MiscServices.Time
76   * @systemapi Hide this for inner system use.
77   * @since 7
78   */
79  function createTimer(options: TimerOptions, callback: AsyncCallback<number>): void;
80
81  /**
82   * Creates a timer.
83   *
84   * @param options Indicates the timer options.
85   * @param { TimerOptions } options - The necessary configuration information.
86   * @returns { Promise<number> } the timer ID.
87   * @throws { BusinessError } 202 - permission denied.
88   * @throws { BusinessError } 401 - if the parameter type is incorrect.
89   * @syscap SystemCapability.MiscServices.Time
90   * @systemapi Hide this for inner system use.
91   * @since 7
92   */
93  function createTimer(options: TimerOptions): Promise<number>;
94
95  /**
96   * Starts a timer.
97   *
98   * @param { number } timer - The timer ID.
99   * @param { number } triggerTime - Indicates the time at which the timer is triggered for the first time, in milliseconds.
100   *                   The time will be automatically set to 5000 milliseconds after the current time if the passed
101   *                   value is smaller than the current time plus 5000 milliseconds.
102   * @param { AsyncCallback<void> } callback - The callback function.
103   * @throws { BusinessError } 202 - permission denied.
104   * @throws { BusinessError } 401 - if the parameter type is incorrect.
105   * @syscap SystemCapability.MiscServices.Time
106   * @systemapi Hide this for inner system use.
107   * @since 7
108   */
109  function startTimer(timer: number, triggerTime: number, callback: AsyncCallback<void>): void;
110
111  /**
112   * Starts a timer.
113   *
114   * @param { number } timer - The timer ID.
115   * @param { number } triggerTime - Indicates the time at which the timer is triggered for the first time, in milliseconds.
116   *                   The time will be automatically set to 5000 milliseconds after the current time if the passed
117   *                   value is smaller than the current time plus 5000 milliseconds.
118   * @returns { Promise<void> } return a promise object.
119   * @throws { BusinessError } 202 - permission denied.
120   * @throws { BusinessError } 401 - if the parameter type is incorrect.
121   * @syscap SystemCapability.MiscServices.Time
122   * @systemapi Hide this for inner system use.
123   * @since 7
124   */
125  function startTimer(timer: number, triggerTime: number): Promise<void>;
126
127  /**
128   * Stops a timer.
129   *
130   * @param { number } timer - The timer ID.
131   * @param { AsyncCallback<void> } callback - The callback function.
132   * @throws { BusinessError } 202 - permission denied.
133   * @throws { BusinessError } 401 - if the parameter type is incorrect.
134   * @syscap SystemCapability.MiscServices.Time
135   * @systemapi Hide this for inner system use.
136   * @since 7
137   */
138  function stopTimer(timer: number, callback: AsyncCallback<void>): void;
139
140  /**
141   * Stops a timer.
142   *
143   * @param { number } timer - The timer ID.
144   * @returns { Promise<void> } return a promise object.
145   * @throws { BusinessError } 202 - permission denied.
146   * @throws { BusinessError } 401 - if the parameter type is incorrect.
147   * @syscap SystemCapability.MiscServices.Time
148   * @systemapi Hide this for inner system use.
149   * @since 7
150   */
151  function stopTimer(timer: number): Promise<void>;
152
153  /**
154   * Destroy a timer.
155   *
156   * @param { number } timer - The timer ID.
157   * @param { AsyncCallback<void> } callback - The callback function.
158   * @throws { BusinessError } 202 - permission denied.
159   * @throws { BusinessError } 401 - if the parameter type is incorrect.
160   * @syscap SystemCapability.MiscServices.Time
161   * @systemapi Hide this for inner system use.
162   * @since 7
163   */
164  function destroyTimer(timer: number, callback: AsyncCallback<void>): void;
165
166  /**
167   * Destroy a timer.
168   *
169   * @param { number } timer - The timer ID.
170   * @returns { Promise<void> } return a promise object.
171   * @throws { BusinessError } 202 - permission denied.
172   * @throws { BusinessError } 401 - if the parameter type is incorrect.
173   * @syscap SystemCapability.MiscServices.Time
174   * @systemapi Hide this for inner system use.
175   * @since 7
176   */
177  function destroyTimer(timer: number): Promise<void>;
178
179  /**
180   * When the repeat is false,the interval is not needed, choose one of wantAgent and callback.
181   * When the repeat is true,the interval is required, the wantAgent is required, and the callback can be left blank.
182   *
183   * @syscap SystemCapability.MiscServices.Time
184   * @systemapi Hide this for inner system use.
185   * @since 7
186   */
187  interface TimerOptions {
188    /**
189     * The timer type.
190     *
191     * @syscap SystemCapability.MiscServices.Time
192     * @systemapi Hide this for inner system use.
193     * @since 7
194     */
195    type: number;
196
197    /**
198     * Indicates a repeating timer
199     *
200     * @syscap SystemCapability.MiscServices.Time
201     * @systemapi Hide this for inner system use.
202     * @since 7
203     */
204    repeat: boolean;
205
206    /**
207     * Indicates the interval between two consecutive triggers, in milliseconds.
208     * The interval will be set to 5000 milliseconds automatically if the passed value is smaller than 5000.
209     *
210     * @syscap SystemCapability.MiscServices.Time
211     * @systemapi Hide this for inner system use.
212     * @since 7
213     */
214    interval?: number;
215
216    /**
217     * Indicates the intent to send when the timer goes off.
218     *
219     * @syscap SystemCapability.MiscServices.Time
220     * @systemapi Hide this for inner system use.
221     * @since 7
222     */
223    wantAgent?: WantAgent;
224
225    /**
226     * Called back when the timer goes off.
227     *
228     * @syscap SystemCapability.MiscServices.Time
229     * @systemapi Hide this for inner system use.
230     * @since 7
231     */
232    callback?: () => void;
233  }
234}
235
236export default systemTimer;