1/* 2 * Copyright (C) 2022-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 16import { AsyncCallback, Callback } from './@ohos.base'; 17 18/** 19 * Provides filesystem statistics APIs. 20 * 21 * @namespace storageStatistics 22 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 23 * @since 8 24 */ 25declare namespace storageStatistics { 26 /** 27 * Get the total size of volume. 28 * 29 * @permission ohos.permission.STORAGE_MANAGER 30 * @param { string } volumeUuid - The uuid of the volume 31 * @param { AsyncCallback<number> } callback - callback 32 * @throws { BusinessError } 201 - Permission verification failed. 33 * @throws { BusinessError } 202 - The caller is not a system application. 34 * @throws { BusinessError } 401 - The input parameter is invalid. 35 * @throws { BusinessError } 13600001 - IPC error. 36 * @throws { BusinessError } 13600008 - No such object. 37 * @throws { BusinessError } 13900042 - Unknown error. 38 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 39 * @systemapi 40 * @since 8 41 */ 42 function getTotalSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void; 43 44 /** 45 * Get the total size of volume. 46 * 47 * @permission ohos.permission.STORAGE_MANAGER 48 * @param { string } volumeUuid - The uuid of the volume 49 * @returns { Promise<number> } return Promise 50 * @throws { BusinessError } 201 - Permission verification failed. 51 * @throws { BusinessError } 202 - The caller is not a system application. 52 * @throws { BusinessError } 401 - The input parameter is invalid. 53 * @throws { BusinessError } 13600001 - IPC error. 54 * @throws { BusinessError } 13600008 - No such object. 55 * @throws { BusinessError } 13900042 - Unknown error. 56 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 57 * @systemapi 58 * @since 8 59 */ 60 function getTotalSizeOfVolume(volumeUuid: string): Promise<number>; 61 /** 62 * Get the free size of volume. 63 * 64 * @permission ohos.permission.STORAGE_MANAGER 65 * @param { string } volumeUuid - The uuid of the volume 66 * @param { AsyncCallback<number> } callback - callback 67 * @throws { BusinessError } 201 - Permission verification failed. 68 * @throws { BusinessError } 202 - The caller is not a system application. 69 * @throws { BusinessError } 401 - The input parameter is invalid. 70 * @throws { BusinessError } 13600001 - IPC error. 71 * @throws { BusinessError } 13600008 - No such object. 72 * @throws { BusinessError } 13900042 - Unknown error. 73 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 74 * @systemapi 75 * @since 8 76 */ 77 function getFreeSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void; 78 79 /** 80 * Get the free size of volume. 81 * 82 * @permission ohos.permission.STORAGE_MANAGER 83 * @param { string } volumeUuid - The uuid of the volume 84 * @returns { Promise<number> } return Promise 85 * @throws { BusinessError } 201 - Permission verification failed. 86 * @throws { BusinessError } 202 - The caller is not a system application. 87 * @throws { BusinessError } 401 - The input parameter is invalid. 88 * @throws { BusinessError } 13600001 - IPC error. 89 * @throws { BusinessError } 13600008 - No such object. 90 * @throws { BusinessError } 13900042 - Unknown error. 91 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 92 * @systemapi 93 * @since 8 94 */ 95 function getFreeSizeOfVolume(volumeUuid: string): Promise<number>; 96 97 /** 98 * Get the bundle statistics. 99 * 100 * @interface BundleStats 101 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 102 * @since 9 103 */ 104 export interface BundleStats { 105 /** 106 * The size of application installation data. 107 * 108 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 109 * @since 9 110 */ 111 appSize: number; 112 113 /** 114 * The size of application cache data. 115 * 116 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 117 * @since 9 118 */ 119 cacheSize: number; 120 121 /** 122 * The size of application local data, distributed data and database data. 123 * 124 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 125 * @since 9 126 */ 127 dataSize: number; 128 } 129 /** 130 * Get the bundle statistics. 131 * 132 * @permission ohos.permission.STORAGE_MANAGER 133 * @param { string } packageName - The name of the application 134 * @param { AsyncCallback<BundleStats> } callback - callback 135 * @throws { BusinessError } 201 - Permission verification failed. 136 * @throws { BusinessError } 202 - The caller is not a system application. 137 * @throws { BusinessError } 401 - The input parameter is invalid. 138 * @throws { BusinessError } 13600001 - IPC error. 139 * @throws { BusinessError } 13600008 - No such object. 140 * @throws { BusinessError } 13900042 - Unknown error. 141 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 142 * @systemapi 143 * @since 9 144 */ 145 function getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>): void; 146 147 /** 148 * Get the bundle statistics. 149 * 150 * @permission ohos.permission.STORAGE_MANAGER 151 * @param { string } packageName - The name of the application 152 * @returns { Promise<BundleStats> } return Promise 153 * @throws { BusinessError } 201 - Permission verification failed. 154 * @throws { BusinessError } 202 - The caller is not a system application. 155 * @throws { BusinessError } 401 - The input parameter is invalid. 156 * @throws { BusinessError } 13600001 - IPC error. 157 * @throws { BusinessError } 13600008 - No such object. 158 * @throws { BusinessError } 13900042 - Unknown error. 159 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 160 * @systemapi 161 * @since 9 162 */ 163 function getBundleStats(packageName: string): Promise<BundleStats>; 164 165 /** 166 * Get the current bundle statistics. 167 * 168 * @param { AsyncCallback<BundleStats> } callback - callback 169 * @throws { BusinessError } 401 - The input parameter is invalid. 170 * @throws { BusinessError } 13600001 - IPC error. 171 * @throws { BusinessError } 13900042 - Unknown error. 172 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 173 * @since 9 174 */ 175 function getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void; 176 177 /** 178 * Get the current bundle statistics. 179 * 180 * @returns { Promise<BundleStats> } return Promise 181 * @throws { BusinessError } 401 - The input parameter is invalid. 182 * @throws { BusinessError } 13600001 - IPC error. 183 * @throws { BusinessError } 13900042 - Unknown error. 184 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 185 * @since 9 186 */ 187 function getCurrentBundleStats(): Promise<BundleStats>; 188 189 /** 190 * Get the system size. 191 * 192 * @permission ohos.permission.STORAGE_MANAGER 193 * @param { AsyncCallback<number> } callback - callback 194 * @throws { BusinessError } 201 - Permission verification failed. 195 * @throws { BusinessError } 202 - The caller is not a system application. 196 * @throws { BusinessError } 401 - The input parameter is invalid. 197 * @throws { BusinessError } 13600001 - IPC error. 198 * @throws { BusinessError } 13900042 - Unknown error. 199 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 200 * @systemapi 201 * @since 9 202 */ 203 function getSystemSize(callback: AsyncCallback<number>): void; 204 205 /** 206 * Get the system size. 207 * 208 * @permission ohos.permission.STORAGE_MANAGER 209 * @returns { Promise<number> } return Promise 210 * @throws { BusinessError } 201 - Permission verification failed. 211 * @throws { BusinessError } 202 - The caller is not a system application. 212 * @throws { BusinessError } 401 - The input parameter is invalid. 213 * @throws { BusinessError } 13600001 - IPC error. 214 * @throws { BusinessError } 13900042 - Unknown error. 215 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 216 * @systemapi 217 * @since 9 218 */ 219 function getSystemSize(): Promise<number>; 220 221 /** 222 * Get the user storage statistics. 223 * 224 * @interface StorageStats 225 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 226 * @systemapi 227 * @since 9 228 */ 229 export interface StorageStats { 230 /** 231 * The total size of device. 232 * 233 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 234 * @systemapi 235 * @since 9 236 */ 237 total: number; 238 239 /** 240 * The size of audio file. 241 * 242 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 243 * @systemapi 244 * @since 9 245 */ 246 audio: number; 247 248 /** 249 * The size of video file. 250 * 251 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 252 * @systemapi 253 * @since 9 254 */ 255 video: number; 256 257 /** 258 * The size of image file. 259 * 260 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 261 * @systemapi 262 * @since 9 263 */ 264 image: number; 265 266 /** 267 * The size of other file. 268 * 269 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 270 * @systemapi 271 * @since 9 272 */ 273 file: number; 274 275 /** 276 * The size of application. 277 * 278 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 279 * @systemapi 280 * @since 9 281 */ 282 app: number; 283 } 284 285 /** 286 * Get the user storage statistics. 287 * 288 * @permission ohos.permission.STORAGE_MANAGER 289 * @returns { Promise<StorageStats> } return Promise 290 * @throws { BusinessError } 201 - Permission verification failed. 291 * @throws { BusinessError } 202 - The caller is not a system application. 292 * @throws { BusinessError } 401 - The input parameter is invalid. 293 * @throws { BusinessError } 13600001 - IPC error. 294 * @throws { BusinessError } 13900042 - Unknown error. 295 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 296 * @systemapi 297 * @since 9 298 */ 299 function getUserStorageStats(): Promise<StorageStats>; 300 301 /** 302 * Get the user storage statistics. 303 * 304 * @permission ohos.permission.STORAGE_MANAGER 305 * @param { AsyncCallback<StorageStats> } callback - callback 306 * @throws { BusinessError } 201 - Permission verification failed. 307 * @throws { BusinessError } 202 - The caller is not a system application. 308 * @throws { BusinessError } 401 - The input parameter is invalid. 309 * @throws { BusinessError } 13600001 - IPC error. 310 * @throws { BusinessError } 13900042 - Unknown error. 311 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 312 * @systemapi 313 * @since 9 314 */ 315 function getUserStorageStats(callback: AsyncCallback<StorageStats>): void; 316 317 /** 318 * Get the user storage statistics. 319 * 320 * @permission ohos.permission.STORAGE_MANAGER 321 * @param { number } userId - The id of the user 322 * @returns { Promise<StorageStats> } return Promise 323 * @throws { BusinessError } 201 - Permission verification failed. 324 * @throws { BusinessError } 202 - The caller is not a system application. 325 * @throws { BusinessError } 401 - The input parameter is invalid. 326 * @throws { BusinessError } 13600001 - IPC error. 327 * @throws { BusinessError } 13600009 - User if out of range. 328 * @throws { BusinessError } 13900042 - Unknown error. 329 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 330 * @systemapi 331 * @since 9 332 */ 333 function getUserStorageStats(userId: number): Promise<StorageStats>; 334 335 /** 336 * Get the user storage statistics. 337 * 338 * @permission ohos.permission.STORAGE_MANAGER 339 * @param { number } userId - The id of the user 340 * @param { AsyncCallback<StorageStats> } callback - callback 341 * @throws { BusinessError } 201 - Permission verification failed. 342 * @throws { BusinessError } 202 - The caller is not a system application. 343 * @throws { BusinessError } 401 - The input parameter is invalid. 344 * @throws { BusinessError } 13600001 - IPC error. 345 * @throws { BusinessError } 13600009 - User if out of range. 346 * @throws { BusinessError } 13900042 - Unknown error. 347 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 348 * @systemapi 349 * @since 9 350 */ 351 function getUserStorageStats(userId: number, callback: AsyncCallback<StorageStats>): void; 352 353 /** 354 * Get the total size. 355 * 356 * @permission ohos.permission.STORAGE_MANAGER 357 * @param { AsyncCallback<number> } callback - callback 358 * @throws { BusinessError } 201 - Permission verification failed. 359 * @throws { BusinessError } 202 - The caller is not a system application. 360 * @throws { BusinessError } 401 - The input parameter is invalid. 361 * @throws { BusinessError } 13600001 - IPC error. 362 * @throws { BusinessError } 13900042 - Unknown error. 363 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 364 * @systemapi 365 * @since 9 366 */ 367 function getTotalSize(callback: AsyncCallback<number>): void; 368 369 /** 370 * Get the total size. 371 * 372 * @permission ohos.permission.STORAGE_MANAGER 373 * @returns { Promise<number> } return Promise 374 * @throws { BusinessError } 201 - Permission verification failed. 375 * @throws { BusinessError } 202 - The caller is not a system application. 376 * @throws { BusinessError } 401 - The input parameter is invalid. 377 * @throws { BusinessError } 13600001 - IPC error. 378 * @throws { BusinessError } 13900042 - Unknown error. 379 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 380 * @systemapi 381 * @since 9 382 */ 383 function getTotalSize(): Promise<number>; 384 385 /** 386 * Get the total size with sync interface 387 * 388 * @permission ohos.permission.STORAGE_MANAGER 389 * @returns { number } return the total size 390 * @throws { BusinessError } 201 - Permission verification failed. 391 * @throws { BusinessError } 202 - The caller is not a system application. 392 * @throws { BusinessError } 401 - The input parameter is invalid. 393 * @throws { BusinessError } 13600001 - IPC error. 394 * @throws { BusinessError } 13900042 - Unknown error. 395 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 396 * @systemapi 397 * @since 10 398 */ 399 function getTotalSizeSync(): number; 400 401 /** 402 * Get the free size. 403 * 404 * @permission ohos.permission.STORAGE_MANAGER 405 * @param { AsyncCallback<number> } callback - callback 406 * @throws { BusinessError } 201 - Permission verification failed. 407 * @throws { BusinessError } 202 - The caller is not a system application. 408 * @throws { BusinessError } 401 - The input parameter is invalid. 409 * @throws { BusinessError } 13600001 - IPC error. 410 * @throws { BusinessError } 13900042 - Unknown error. 411 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 412 * @systemapi 413 * @since 9 414 */ 415 function getFreeSize(callback: AsyncCallback<number>): void; 416 417 /** 418 * Get the free size. 419 * 420 * @permission ohos.permission.STORAGE_MANAGER 421 * @returns { Promise<number> } return Promise 422 * @throws { BusinessError } 201 - Permission verification failed. 423 * @throws { BusinessError } 202 - The caller is not a system application. 424 * @throws { BusinessError } 401 - The input parameter is invalid. 425 * @throws { BusinessError } 13600001 - IPC error. 426 * @throws { BusinessError } 13900042 - Unknown error. 427 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 428 * @systemapi 429 * @since 9 430 */ 431 function getFreeSize(): Promise<number>; 432 433 /** 434 * Get the free size with sync interface. 435 * 436 * @permission ohos.permission.STORAGE_MANAGER 437 * @returns { number } return the free size 438 * @throws { BusinessError } 201 - Permission verification failed. 439 * @throws { BusinessError } 202 - The caller is not a system application. 440 * @throws { BusinessError } 401 - The input parameter is invalid. 441 * @throws { BusinessError } 13600001 - IPC error. 442 * @throws { BusinessError } 13900042 - Unknown error. 443 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 444 * @systemapi 445 * @since 10 446 */ 447 function getFreeSizeSync(): number; 448} 449 450export default storageStatistics; 451