1/* 2 * Copyright (c) 2023 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 16/** 17 * @file 18 * @kit BackgroundTasksKit 19 */ 20 21import { AsyncCallback } from './@ohos.base'; 22 23/** 24 * Provides methods for managing device standby, 25 * including the methods for querying standby status and exemption list. 26 * 27 * @namespace deviceStandby 28 * @since 10 29 */ 30declare namespace deviceStandby { 31 32 /** 33 * Returns the information about the specified exempted application. 34 * 35 * @permission ohos.permission.DEVICE_STANDBY_EXEMPTION 36 * @param { number } resourceTypes - the combination of {@link ResourceType} values. 37 * @param { AsyncCallback<Array<ExemptedAppInfo>> } callback - the callback of getExemptedApps. 38 * @throws { BusinessError } 201 - Permission denied. 39 * @throws { BusinessError } 202 - Not System App. 40 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. 41 * @throws { BusinessError } 9800001 - Memory operation failed. 42 * @throws { BusinessError } 9800002 - Parcel operation failed. 43 * @throws { BusinessError } 9800003 - Inner transact failed. 44 * @throws { BusinessError } 9800004 - System service operation failed. 45 * @throws { BusinessError } 18700001 - Caller information verification failed. 46 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 47 * @systemapi Hide this for inner system use. 48 * @since 10 49 */ 50 function getExemptedApps(resourceTypes: number, callback: AsyncCallback<Array<ExemptedAppInfo>>): void; 51 52 /** 53 * Returns the information about the specified exempted application. 54 * 55 * @permission ohos.permission.DEVICE_STANDBY_EXEMPTION 56 * @param { number } resourceTypes - the combination of {@link ResourceType} values. 57 * @returns { Promise<Array<ExemptedAppInfo>> } the promise returned by getExemptedApps. 58 * @throws { BusinessError } 201 - Permission denied. 59 * @throws { BusinessError } 202 - Not System App. 60 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. 61 * @throws { BusinessError } 9800001 - Memory operation failed. 62 * @throws { BusinessError } 9800002 - Parcel operation failed. 63 * @throws { BusinessError } 9800003 - Inner transact failed. 64 * @throws { BusinessError } 9800004 - System service operation failed. 65 * @throws { BusinessError } 18700001 - Caller information verification failed. 66 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 67 * @systemapi Hide this for inner system use. 68 * @since 10 69 */ 70 function getExemptedApps(resourceTypes: number): Promise<Array<ExemptedAppInfo>>; 71 72 /** 73 * Requests exemption resources. 74 * 75 * @permission ohos.permission.DEVICE_STANDBY_EXEMPTION 76 * @param { ResourceRequest } request - requesting or releasing resources. 77 * @throws { BusinessError } 201 - Permission denied. 78 * @throws { BusinessError } 202 - Not System App. 79 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. 80 * @throws { BusinessError } 9800001 - Memory operation failed. 81 * @throws { BusinessError } 9800002 - Parcel operation failed. 82 * @throws { BusinessError } 9800003 - Inner transact failed. 83 * @throws { BusinessError } 9800004 - System service operation failed. 84 * @throws { BusinessError } 18700001 - Caller information verification failed. 85 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 86 * @systemapi Hide this for inner system use. 87 * @since 10 88 */ 89 function requestExemptionResource(request: ResourceRequest): void; 90 91 /** 92 * Releases exemption resources. 93 * 94 * @permission ohos.permission.DEVICE_STANDBY_EXEMPTION 95 * @param { ResourceRequest } request - requesting or releasing resources. 96 * @throws { BusinessError } 201 - Permission denied. 97 * @throws { BusinessError } 202 - Not System App. 98 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. 99 * @throws { BusinessError } 9800001 - Memory operation failed. 100 * @throws { BusinessError } 9800002 - Parcel operation failed. 101 * @throws { BusinessError } 9800003 - Inner transact failed. 102 * @throws { BusinessError } 9800004 - System service operation failed. 103 * @throws { BusinessError } 18700001 - Caller information verification failed. 104 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 105 * @systemapi Hide this for inner system use. 106 * @since 10 107 */ 108 function releaseExemptionResource(request: ResourceRequest): void; 109 110 /** 111 * The type of exemption resources requested by the application. 112 * 113 * @enum { number } 114 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 115 * @systemapi Hide this for inner system use. 116 * @since 10 117 */ 118 export enum ResourceType { 119 /** 120 * The resource for non-standby network access. 121 * 122 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 123 * @systemapi Hide this for inner system use. 124 * @since 10 125 */ 126 NETWORK = 1, 127 128 /** 129 * The resource for non-standby cpu running-lock. 130 * 131 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 132 * @systemapi Hide this for inner system use. 133 * @since 10 134 */ 135 RUNNING_LOCK = 1 << 1, 136 137 /** 138 * The resource for non-standby timer. 139 * 140 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 141 * @systemapi Hide this for inner system use. 142 * @since 10 143 */ 144 TIMER = 1 << 2, 145 146 /** 147 * The resource for non-standby workscheduler. 148 * 149 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 150 * @systemapi Hide this for inner system use. 151 * @since 10 152 */ 153 WORK_SCHEDULER = 1 << 3, 154 155 /** 156 * The resource for non-standby automatic synchronization. 157 * 158 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 159 * @systemapi Hide this for inner system use. 160 * @since 10 161 */ 162 AUTO_SYNC = 1 << 4, 163 164 /** 165 * The resource for non-standby push-kit. 166 * 167 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 168 * @systemapi Hide this for inner system use. 169 * @since 10 170 */ 171 PUSH = 1 << 5, 172 173 /** 174 * The resource for non-standby freezing application. 175 * 176 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 177 * @systemapi Hide this for inner system use. 178 * @since 10 179 */ 180 FREEZE = 1 << 6 181 } 182 183 /** 184 * Information about an exempted application. 185 * 186 * @interface ExemptedAppInfo 187 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 188 * @systemapi Hide this for inner system use. 189 * @since 10 190 */ 191 export interface ExemptedAppInfo { 192 /** 193 * The set of resource types that an application requests. 194 * 195 * @type { number } 196 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 197 * @systemapi Hide this for inner system use. 198 * @since 10 199 */ 200 resourceTypes: number; 201 202 /** 203 * The application name. 204 * 205 * @type { string } 206 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 207 * @systemapi Hide this for inner system use. 208 * @since 10 209 */ 210 name: string; 211 212 /** 213 * The exemption duration. 214 * 215 * @type { number } 216 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 217 * @systemapi Hide this for inner system use. 218 * @since 10 219 */ 220 duration: number; 221 } 222 223 /** 224 * The request of standby resources. 225 * 226 * @interface ResourceRequest 227 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 228 * @systemapi Hide this for inner system use. 229 * @since 10 230 */ 231 export interface ResourceRequest { 232 /** 233 * The set of resource types that an application requests. 234 * 235 * @type { number } 236 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 237 * @systemapi Hide this for inner system use. 238 * @since 10 239 */ 240 resourceTypes: number; 241 242 /** 243 * The application uid. 244 * 245 * @type { number } 246 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 247 * @systemapi Hide this for inner system use. 248 * @since 10 249 */ 250 uid: number; 251 252 /** 253 * The application name. 254 * 255 * @type { string } 256 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 257 * @systemapi Hide this for inner system use. 258 * @since 10 259 */ 260 name: string; 261 262 /** 263 * The exemption duration. 264 * 265 * @type { number } 266 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 267 * @systemapi Hide this for inner system use. 268 * @since 10 269 */ 270 duration: number; 271 272 /** 273 * The reason for the request. 274 * 275 * @type { string } 276 * @syscap SystemCapability.ResourceSchedule.DeviceStandby 277 * @systemapi Hide this for inner system use. 278 * @since 10 279 */ 280 reason: string; 281 } 282} 283 284export default deviceStandby;