1/* 2 * Copyright (c) 2022 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 } from './@ohos.base'; 17 18/** 19 * Work scheduler interface. 20 * 21 * @namespace workScheduler 22 * @StageModelOnly 23 * @since 9 24 */ 25declare namespace workScheduler { 26 /** 27 * The info of work. 28 * 29 * @interface WorkInfo 30 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 31 * @StageModelOnly 32 * @since 9 33 */ 34 export interface WorkInfo { 35 /** 36 * The id of the current work. 37 * 38 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 39 * @since 9 40 */ 41 workId: number; 42 /** 43 * The bundle name of the current work. 44 * 45 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 46 * @since 9 47 */ 48 bundleName: string; 49 /** 50 * The ability name of the current work. 51 * 52 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 53 * @since 9 54 */ 55 abilityName: string; 56 /** 57 * Whether the current work will be saved. 58 * 59 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 60 * @since 9 61 */ 62 isPersisted?: boolean; 63 /** 64 * The network type of the current work. 65 * 66 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 67 * @since 9 68 */ 69 networkType?: NetworkType; 70 /** 71 * Whether a charging state has been set for triggering the work. 72 * 73 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 74 * @since 9 75 */ 76 isCharging?: boolean; 77 /** 78 * The charger type based on which the work is triggered. 79 * 80 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 81 * @since 9 82 */ 83 chargerType?: ChargingType; 84 /** 85 * The battery level for triggering a work. 86 * 87 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 88 * @since 9 89 */ 90 batteryLevel?: number; 91 /** 92 * The battery status for triggering a work. 93 * 94 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 95 * @since 9 96 */ 97 batteryStatus?: BatteryStatus; 98 /** 99 * Whether a storage state has been set for triggering the work. 100 * 101 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 102 * @since 9 103 */ 104 storageRequest?: StorageRequest; 105 /** 106 * The interval at which the work is repeated. 107 * 108 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 109 * @since 9 110 */ 111 repeatCycleTime?: number; 112 /** 113 * Whether the work has been set to repeat at the specified interval. 114 * 115 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 116 * @since 9 117 */ 118 isRepeat?: boolean; 119 /** 120 * The repeat of the current work. 121 * 122 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 123 * @since 9 124 */ 125 repeatCount?: number; 126 /** 127 * Whether the device deep idle state has been set for triggering the work. 128 * 129 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 130 * @since 9 131 */ 132 isDeepIdle?: boolean; 133 /** 134 * The idle wait time based on which the work is triggered. 135 * 136 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 137 * @since 9 138 */ 139 idleWaitTime?: number; 140 /** 141 * The parameters of the work. The value is only supported basic type(Number, String, Boolean). 142 * 143 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 144 * @since 9 145 */ 146 parameters?: { [key: string]: number | string | boolean }; 147 } 148 149 /** 150 * Add a work to the queue. A work can be executed only when it meets the preset triggering condition 151 * <p> and complies with the rules of work scheduler manager. </p> 152 * 153 * @param { WorkInfo } work - The info of work. 154 * @throws { BusinessError } 401 - Parameter error. 155 * @throws { BusinessError } 9700001 - Memory operation failed. 156 * @throws { BusinessError } 9700002 - Parcel operation failed. 157 * @throws { BusinessError } 9700003 - System service operation failed. 158 * @throws { BusinessError } 9700004 - Check workInfo failed. 159 * @throws { BusinessError } 9700005 - StartWork failed. 160 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 161 * @StageModelOnly 162 * @since 9 163 */ 164 function startWork(work: WorkInfo): void; 165 166 /** 167 * Stop a work. 168 * 169 * @param { WorkInfo } work - The info of work. 170 * @param { boolean } needCancel - True if need to be canceled after being stopped, otherwise false. 171 * @throws { BusinessError } 401 - Parameter error. 172 * @throws { BusinessError } 9700001 - Memory operation failed. 173 * @throws { BusinessError } 9700002 - Parcel operation failed. 174 * @throws { BusinessError } 9700003 - System service operation failed. 175 * @throws { BusinessError } 9700004 - Check workInfo failed. 176 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 177 * @StageModelOnly 178 * @since 9 179 */ 180 function stopWork(work: WorkInfo, needCancel?: boolean): void; 181 182 /** 183 * Obtains the work info of the wordId. 184 * 185 * @param { number } workId - The id of work. 186 * @param { AsyncCallback<WorkInfo> } callback - The callback of the function. 187 * @throws { BusinessError } 401 - Parameter error. 188 * @throws { BusinessError } 9700001 - Memory operation failed. 189 * @throws { BusinessError } 9700002 - Parcel operation failed. 190 * @throws { BusinessError } 9700003 - System service operation failed. 191 * @throws { BusinessError } 9700004 - Check workInfo failed. 192 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 193 * @StageModelOnly 194 * @since 9 195 */ 196 function getWorkStatus(workId: number, callback: AsyncCallback<WorkInfo>): void; 197 198 /** 199 * Obtains the work info of the wordId. 200 * 201 * @param { number } workId - The id of work. 202 * @returns { Promise<WorkInfo> } The promise returned by the function. 203 * @throws { BusinessError } 401 - Parameter error. 204 * @throws { BusinessError } 9700001 - Memory operation failed. 205 * @throws { BusinessError } 9700002 - Parcel operation failed. 206 * @throws { BusinessError } 9700003 - System service operation failed. 207 * @throws { BusinessError } 9700004 - Check workInfo failed. 208 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 209 * @StageModelOnly 210 * @since 9 211 */ 212 function getWorkStatus(workId: number): Promise<WorkInfo>; 213 214 /** 215 * Get all works of the calling application. 216 * 217 * @param { AsyncCallback<void> } callback - The callback of the function. 218 * @returns { Array<WorkInfo> } the work info list. 219 * @throws { BusinessError } 401 - Parameter error. 220 * @throws { BusinessError } 9700001 - Memory operation failed. 221 * @throws { BusinessError } 9700002 - Parcel operation failed. 222 * @throws { BusinessError } 9700003 - System service operation failed. 223 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 224 * @StageModelOnly 225 * @since 9 226 * @deprecated since 10 227 */ 228 function obtainAllWorks(callback: AsyncCallback<void>): Array<WorkInfo>; 229 230 /** 231 * Get all works of the calling application. 232 * 233 * @param { AsyncCallback<void> } callback - The callback of the function. 234 * @throws { BusinessError } 401 - Parameter error. 235 * @throws { BusinessError } 9700001 - Memory operation failed. 236 * @throws { BusinessError } 9700002 - Parcel operation failed. 237 * @throws { BusinessError } 9700003 - System service operation failed. 238 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 239 * @StageModelOnly 240 * @since 10 241 */ 242 function obtainAllWorks(callback: AsyncCallback<Array<WorkInfo>>): void; 243 244 /** 245 * Get all works of the calling application. 246 * 247 * @returns { Promise<Array<WorkInfo>> } The work info list. 248 * @throws { BusinessError } 401 - Parameter error. 249 * @throws { BusinessError } 9700001 - Memory operation failed. 250 * @throws { BusinessError } 9700002 - Parcel operation failed. 251 * @throws { BusinessError } 9700003 - System service operation failed. 252 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 253 * @StageModelOnly 254 * @since 9 255 */ 256 function obtainAllWorks(): Promise<Array<WorkInfo>>; 257 258 /** 259 * Stop all and clear all works of the calling application. 260 * 261 * @throws { BusinessError } 401 - Parameter error. 262 * @throws { BusinessError } 9700001 - Memory operation failed. 263 * @throws { BusinessError } 9700002 - Parcel operation failed. 264 * @throws { BusinessError } 9700003 - System service operation failed. 265 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 266 * @StageModelOnly 267 * @since 9 268 */ 269 function stopAndClearWorks(): void; 270 271 /** 272 * Check whether last work running is timeout. The interface is for repeating work. 273 * 274 * @param { number } workId - The id of work. 275 * @param { AsyncCallback<void> } callback - The callback of the function. 276 * @returns { boolean } true if last work running is timeout, otherwise false. 277 * @throws { BusinessError } 401 - Parameter error. 278 * @throws { BusinessError } 9700001 - Memory operation failed. 279 * @throws { BusinessError } 9700002 - Parcel operation failed. 280 * @throws { BusinessError } 9700003 - System service operation failed. 281 * @throws { BusinessError } 9700004 - Check workInfo failed. 282 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 283 * @StageModelOnly 284 * @since 9 285 * @deprecated since 10 286 */ 287 function isLastWorkTimeOut(workId: number, callback: AsyncCallback<void>): boolean; 288 289 /** 290 * Check whether last work running is timeout. The interface is for repeating work. 291 * 292 * @param { number } workId - The id of work. 293 * @param { AsyncCallback<void> } callback - The callback of the function. 294 * @throws { BusinessError } 401 - Parameter error. 295 * @throws { BusinessError } 9700001 - Memory operation failed. 296 * @throws { BusinessError } 9700002 - Parcel operation failed. 297 * @throws { BusinessError } 9700003 - System service operation failed. 298 * @throws { BusinessError } 9700004 - Check workInfo failed. 299 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 300 * @StageModelOnly 301 * @since 10 302 */ 303 function isLastWorkTimeOut(workId: number, callback: AsyncCallback<boolean>): void; 304 305 /** 306 * Check whether last work running is timeout. The interface is for repeating work. 307 * 308 * @param { number } workId - The id of work. 309 * @returns { Promise<boolean> } True if last work running is timeout, otherwise false. 310 * @throws { BusinessError } 401 - Parameter error. 311 * @throws { BusinessError } 9700001 - Memory operation failed. 312 * @throws { BusinessError } 9700002 - Parcel operation failed. 313 * @throws { BusinessError } 9700003 - System service operation failed. 314 * @throws { BusinessError } 9700004 - Check workInfo failed. 315 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 316 * @StageModelOnly 317 * @since 9 318 */ 319 function isLastWorkTimeOut(workId: number): Promise<boolean>; 320 321 /** 322 * Describes network type. 323 * 324 * @name NetworkType 325 * @enum { number } 326 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 327 * @StageModelOnly 328 * @since 9 329 */ 330 export enum NetworkType { 331 /** 332 * Describes any network connection. 333 * 334 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 335 * @since 9 336 */ 337 NETWORK_TYPE_ANY = 0, 338 /** 339 * Describes a mobile network connection. 340 * 341 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 342 * @since 9 343 */ 344 NETWORK_TYPE_MOBILE, 345 /** 346 * Describes a wifi network connection. 347 * 348 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 349 * @since 9 350 */ 351 NETWORK_TYPE_WIFI, 352 /** 353 * Describes a bluetooth network connection. 354 * 355 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 356 * @since 9 357 */ 358 NETWORK_TYPE_BLUETOOTH, 359 /** 360 * Describes a wifi p2p network connection. 361 * 362 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 363 * @since 9 364 */ 365 NETWORK_TYPE_WIFI_P2P, 366 /** 367 * Describes a wifi wire network connection. 368 * 369 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 370 * @since 9 371 */ 372 NETWORK_TYPE_ETHERNET 373 } 374 375 /** 376 * Describes charging type. 377 * 378 * @name ChargingType 379 * @enum { number } 380 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 381 * @StageModelOnly 382 * @since 9 383 */ 384 export enum ChargingType { 385 /** 386 * Describes any charger is connected. 387 * 388 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 389 * @since 9 390 */ 391 CHARGING_PLUGGED_ANY = 0, 392 /** 393 * Describes ac charger is connected. 394 * 395 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 396 * @since 9 397 */ 398 CHARGING_PLUGGED_AC, 399 /** 400 * Describes usb charger is connected. 401 * 402 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 403 * @since 9 404 */ 405 CHARGING_PLUGGED_USB, 406 /** 407 * Describes wireless charger is connected. 408 * 409 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 410 * @since 9 411 */ 412 CHARGING_PLUGGED_WIRELESS 413 } 414 415 /** 416 * Describes the battery status. 417 * 418 * @name BatteryStatus 419 * @enum { number } 420 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 421 * @StageModelOnly 422 * @since 9 423 */ 424 export enum BatteryStatus { 425 /** 426 * Describes battery status is to low. 427 * 428 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 429 * @since 9 430 */ 431 BATTERY_STATUS_LOW = 0, 432 /** 433 * Describes battery status is to ok. 434 * 435 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 436 * @since 9 437 */ 438 BATTERY_STATUS_OKAY, 439 /** 440 * Describes battery status is to low or ok. 441 * 442 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 443 * @since 9 444 */ 445 BATTERY_STATUS_LOW_OR_OKAY 446 } 447 448 /** 449 * Describes the storage request. 450 * 451 * @name StorageRequest 452 * @enum { number } 453 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 454 * @StageModelOnly 455 * @since 9 456 */ 457 export enum StorageRequest { 458 /** 459 * Describes storage is to low. 460 * 461 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 462 * @since 9 463 */ 464 STORAGE_LEVEL_LOW = 0, 465 /** 466 * Describes storage is to ok. 467 * 468 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 469 * @since 9 470 */ 471 STORAGE_LEVEL_OKAY, 472 /** 473 * Describes storage is to low or ok. 474 * 475 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 476 * @since 9 477 */ 478 STORAGE_LEVEL_LOW_OR_OKAY 479 } 480} 481export default workScheduler;