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 './basic'; 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 workId: number; 39 /** 40 * The bundle name of the current work. 41 */ 42 bundleName: string; 43 /** 44 * The ability name of the current work. 45 */ 46 abilityName: string; 47 /** 48 * Whether the current work will be saved. 49 */ 50 isPersisted?: boolean; 51 /** 52 * The network type of the current work. 53 */ 54 networkType?: NetworkType; 55 /** 56 * Whether a charging state has been set for triggering the work. 57 */ 58 isCharging?: boolean; 59 /** 60 * The charger type based on which the work is triggered. 61 */ 62 chargerType?: ChargingType; 63 /** 64 * The battery level for triggering a work. 65 */ 66 batteryLevel?: number; 67 /** 68 * The battery status for triggering a work. 69 */ 70 batteryStatus?: BatteryStatus; 71 /** 72 * Whether a storage state has been set for triggering the work. 73 */ 74 storageRequest?: StorageRequest; 75 /** 76 * The interval at which the work is repeated. 77 */ 78 repeatCycleTime?: number; 79 /** 80 * Whether the work has been set to repeat at the specified interval. 81 */ 82 isRepeat?: boolean; 83 /** 84 * The repeat of the current work. 85 */ 86 repeatCount?: number; 87 /** 88 * Whether the device deep idle state has been set for triggering the work. 89 */ 90 isDeepIdle?: boolean; 91 /** 92 * The idle wait time based on which the work is triggered. 93 */ 94 idleWaitTime?: number; 95 /** 96 * The parameters of the work. The value is only supported basic type(Number, String, Boolean). 97 */ 98 parameters?: {[key: string]: number | string | boolean}; 99 } 100 101 /** 102 * Add a work to the queue. A work can be executed only when it meets the preset triggering condition 103 * <p> and complies with the rules of work scheduler manager. </p> 104 * 105 * @param { WorkInfo } work - The info of work. 106 * @throws { BusinessError } 401 - Parameter error. 107 * @throws { BusinessError } 9700001 - Memory operation failed. 108 * @throws { BusinessError } 9700002 - Parcel operation failed. 109 * @throws { BusinessError } 9700003 - System service operation failed. 110 * @throws { BusinessError } 9700004 - Check workInfo failed. 111 * @throws { BusinessError } 9700005 - StartWork failed. 112 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 113 * @StageModelOnly 114 * @since 9 115 */ 116 function startWork(work: WorkInfo): void; 117 118 /** 119 * Stop a work. 120 * 121 * @param { WorkInfo } work - The info of work. 122 * @param { boolean } needCancel - True if need to be canceled after being stopped, otherwise false. 123 * @throws { BusinessError } 401 - Parameter error. 124 * @throws { BusinessError } 9700001 - Memory operation failed. 125 * @throws { BusinessError } 9700002 - Parcel operation failed. 126 * @throws { BusinessError } 9700003 - System service operation failed. 127 * @throws { BusinessError } 9700004 - Check workInfo failed. 128 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 129 * @StageModelOnly 130 * @since 9 131 */ 132 function stopWork(work: WorkInfo, needCancel?: boolean): void; 133 134 /** 135 * Obtains the work info of the wordId. 136 * 137 * @param { number } workId - The id of work. 138 * @param { AsyncCallback<WorkInfo> } callback - The callback of the function. 139 * @throws { BusinessError } 401 - Parameter error. 140 * @throws { BusinessError } 9700001 - Memory operation failed. 141 * @throws { BusinessError } 9700002 - Parcel operation failed. 142 * @throws { BusinessError } 9700003 - System service operation failed. 143 * @throws { BusinessError } 9700004 - Check workInfo failed. 144 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 145 * @StageModelOnly 146 * @since 9 147 */ 148 function getWorkStatus(workId: number, callback: AsyncCallback<WorkInfo>): void; 149 150 /** 151 * Obtains the work info of the wordId. 152 * 153 * @param { number } workId - The id of work. 154 * @returns { Promise<WorkInfo> } The promise returned by the function. 155 * @throws { BusinessError } 401 - Parameter error. 156 * @throws { BusinessError } 9700001 - Memory operation failed. 157 * @throws { BusinessError } 9700002 - Parcel operation failed. 158 * @throws { BusinessError } 9700003 - System service operation failed. 159 * @throws { BusinessError } 9700004 - Check workInfo failed. 160 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 161 * @StageModelOnly 162 * @since 9 163 */ 164 function getWorkStatus(workId: number): Promise<WorkInfo>; 165 166 /** 167 * Get all works of the calling application. 168 * 169 * @param { AsyncCallback<void> } callback - The callback of the function. 170 * @returns { Array<WorkInfo> } the work info list. 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 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 176 * @StageModelOnly 177 * @since 9 178 */ 179 function obtainAllWorks(callback: AsyncCallback<void>): Array<WorkInfo>; 180 181 /** 182 * Get all works of the calling application. 183 * 184 * @returns { Promise<Array<WorkInfo>> } The work info list. 185 * @throws { BusinessError } 401 - Parameter error. 186 * @throws { BusinessError } 9700001 - Memory operation failed. 187 * @throws { BusinessError } 9700002 - Parcel operation failed. 188 * @throws { BusinessError } 9700003 - System service operation failed. 189 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 190 * @StageModelOnly 191 * @since 9 192 */ 193 function obtainAllWorks(): Promise<Array<WorkInfo>>; 194 195 /** 196 * Stop all and clear all works of the calling application. 197 * 198 * @throws { BusinessError } 401 - Parameter error. 199 * @throws { BusinessError } 9700001 - Memory operation failed. 200 * @throws { BusinessError } 9700002 - Parcel operation failed. 201 * @throws { BusinessError } 9700003 - System service operation failed. 202 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 203 * @StageModelOnly 204 * @since 9 205 */ 206 function stopAndClearWorks(): void; 207 208 /** 209 * Check whether last work running is timeout. The interface is for repeating work. 210 * 211 * @param { number } workId - The id of work. 212 * @param { AsyncCallback<void> } callback - The callback of the function. 213 * @returns { boolean } true if last work running is timeout, otherwise false. 214 * @throws { BusinessError } 401 - Parameter error. 215 * @throws { BusinessError } 9700001 - Memory operation failed. 216 * @throws { BusinessError } 9700002 - Parcel operation failed. 217 * @throws { BusinessError } 9700003 - System service operation failed. 218 * @throws { BusinessError } 9700004 - Check workInfo failed. 219 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 220 * @StageModelOnly 221 * @since 9 222 */ 223 function isLastWorkTimeOut(workId: number, callback: AsyncCallback<void>): boolean; 224 225 /** 226 * Check whether last work running is timeout. The interface is for repeating work. 227 * 228 * @param { number } workId - The id of work. 229 * @returns { Promise<boolean> } True if last work running is timeout, otherwise false. 230 * @throws { BusinessError } 401 - Parameter error. 231 * @throws { BusinessError } 9700001 - Memory operation failed. 232 * @throws { BusinessError } 9700002 - Parcel operation failed. 233 * @throws { BusinessError } 9700003 - System service operation failed. 234 * @throws { BusinessError } 9700004 - Check workInfo failed. 235 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 236 * @StageModelOnly 237 * @since 9 238 */ 239 function isLastWorkTimeOut(workId: number): Promise<boolean>; 240 241 /** 242 * Describes network type. 243 * 244 * @name NetworkType 245 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 246 * @StageModelOnly 247 * @since 9 248 */ 249 export enum NetworkType { 250 /** 251 * Describes any network connection. 252 */ 253 NETWORK_TYPE_ANY = 0, 254 /** 255 * Describes a mobile network connection. 256 */ 257 NETWORK_TYPE_MOBILE, 258 /** 259 * Describes a wifi network connection. 260 */ 261 NETWORK_TYPE_WIFI, 262 /** 263 * Describes a bluetooth network connection. 264 */ 265 NETWORK_TYPE_BLUETOOTH, 266 /** 267 * Describes a wifi p2p network connection. 268 */ 269 NETWORK_TYPE_WIFI_P2P, 270 /** 271 * Describes a wifi wire network connection. 272 */ 273 NETWORK_TYPE_ETHERNET 274 } 275 276 /** 277 * Describes charging type. 278 * 279 * @name ChargingType 280 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 281 * @StageModelOnly 282 * @since 9 283 */ 284 export enum ChargingType { 285 /** 286 * Describes any charger is connected. 287 */ 288 CHARGING_PLUGGED_ANY = 0, 289 /** 290 * Describes ac charger is connected. 291 */ 292 CHARGING_PLUGGED_AC, 293 /** 294 * Describes usb charger is connected. 295 */ 296 CHARGING_PLUGGED_USB, 297 /** 298 * Describes wireless charger is connected. 299 */ 300 CHARGING_PLUGGED_WIRELESS 301 } 302 303 /** 304 * Describes the battery status. 305 * 306 * @name BatteryStatus 307 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 308 * @StageModelOnly 309 * @since 9 310 */ 311 export enum BatteryStatus { 312 /** 313 * Describes battery status is to low. 314 */ 315 BATTERY_STATUS_LOW = 0, 316 /** 317 * Describes battery status is to ok. 318 */ 319 BATTERY_STATUS_OKAY, 320 /** 321 * Describes battery status is to low or ok. 322 */ 323 BATTERY_STATUS_LOW_OR_OKAY 324 } 325 326 /** 327 * Describes the storage request. 328 * 329 * @name StorageRequest 330 * @syscap SystemCapability.ResourceSchedule.WorkScheduler 331 * @StageModelOnly 332 * @since 9 333 */ 334 export enum StorageRequest { 335 /** 336 * Describes storage is to low. 337 */ 338 STORAGE_LEVEL_LOW = 0, 339 /** 340 * Describes storage is to ok. 341 */ 342 STORAGE_LEVEL_OKAY, 343 /** 344 * Describes storage is to low or ok. 345 */ 346 STORAGE_LEVEL_LOW_OR_OKAY 347 } 348} 349export default workScheduler;