1/* 2 * Copyright (c) 2021-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, Callback} from './basic' 17import { Permissions } from './permissions' 18 19/** 20 * @syscap SystemCapability.Security.AccessToken 21 */ 22 declare namespace privacyManager { 23 /** 24 * Adds access record of sensitive permission. 25 * @param tokenID The tokenId of specified application. 26 * @param permissionName The permission name to be added. 27 * @param successCount Access count. 28 * @param failCount Reject count. 29 * @returns { void | Promise<void> } No callback return Promise otherwise return void. 30 * @throws { BusinessError } 401 - The parameter check failed. 31 * @throws { BusinessError } 201 - Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". 32 * @throws { BusinessError } 12100001 - The parameter is invalid. The tokenID is 0, or the string size of permissionName is larger than 256, or the count value is invalid. 33 * @throws { BusinessError } 12100002 - The specified tokenID does not exist or it does not refer to an application process. 34 * @throws { BusinessError } 12100003 - The specified permission does not exist or it is not an user_grant permission. 35 * @throws { BusinessError } 12100007 - Service is abnormal. 36 * @throws { BusinessError } 12100008 - Out of memory. 37 * @permission ohos.permission.PERMISSION_USED_STATS 38 * @systemapi 39 * @since 9 40 */ 41 function addPermissionUsedRecord(tokenID: number, permissionName: Permissions, successCount: number, failCount: number): Promise<void>; 42 function addPermissionUsedRecord(tokenID: number, permissionName: Permissions, successCount: number, failCount: number, callback: AsyncCallback<void>): void; 43 44 /** 45 * Queries the access records of sensitive permission. 46 * @param request The request of permission used records. 47 * @returns Return the response of permission used records. 48 * @throws { BusinessError } 401 - The parameter check failed. 49 * @throws { BusinessError } 201 - Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". 50 * @throws { BusinessError } 12100001 - The parameter is invalid. the value of flag in request is invalid. 51 * @throws { BusinessError } 12100002 - The specified tokenID does not exist or it does not refer to an application process. 52 * @throws { BusinessError } 12100003 - The specified permission does not exist or it is not an user_grant permission. 53 * @throws { BusinessError } 12100007 - Service is abnormal. 54 * @throws { BusinessError } 12100008 - Out of memory. 55 * @permission ohos.permission.PERMISSION_USED_STATS 56 * @systemapi 57 * @since 9 58 */ 59 function getPermissionUsedRecord(request: PermissionUsedRequest): Promise<PermissionUsedResponse>; 60 function getPermissionUsedRecord(request: PermissionUsedRequest, callback: AsyncCallback<PermissionUsedResponse>): void; 61 62 /** 63 * Start using sensitive permission. 64 * @param tokenID The tokenId of specified application. 65 * @param permissionName The permission name to be started. 66 * @returns { void | Promise<void> } No callback return Promise otherwise return void. 67 * @throws { BusinessError } 401 - The parameter check failed. 68 * @throws { BusinessError } 201 - Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". 69 * @throws { BusinessError } 12100001 - The parameter is invalid. The tokenID is 0, or the string size of permissionName is larger than 256. 70 * @throws { BusinessError } 12100002 - The specified tokenID does not exist or it does not refer to an application process. 71 * @throws { BusinessError } 12100003 - The specified permission does not exist or it is not an user_grant permission. 72 * @throws { BusinessError } 12100004 - The interface is called repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. 73 * @throws { BusinessError } 12100007 - Service is abnormal. 74 * @throws { BusinessError } 12100008 - Out of memory. 75 * @permission ohos.permission.PERMISSION_USED_STATS 76 * @systemapi 77 * @since 9 78 */ 79 function startUsingPermission(tokenID: number, permissionName: Permissions): Promise<void>; 80 function startUsingPermission(tokenID: number, permissionName: Permissions, callback: AsyncCallback<void>): void; 81 82 /** 83 * Stop using sensitive permission. 84 * @param tokenID The tokenId of specified application. 85 * @param permissionName The permission name to be stopped. 86 * @returns { void | Promise<void> } No callback return Promise otherwise return void. 87 * @throws { BusinessError } 401 - The parameter check failed. 88 * @throws { BusinessError } 201 - Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". 89 * @throws { BusinessError } 12100001 - The parameter is invalid. The tokenID is 0, or the string size of permissionName is larger than 256. 90 * @throws { BusinessError } 12100002 - The specified tokenID does not exist or it does not refer to an application process. 91 * @throws { BusinessError } 12100003 - The specified permission does not exist or it is not an user_grant permission. 92 * @throws { BusinessError } 12100004 - The interface is not used with "startUsingPermission". 93 * @throws { BusinessError } 12100007 - Service is abnormal. 94 * @throws { BusinessError } 12100008 - Out of memory. 95 * @permission ohos.permission.PERMISSION_USED_STATS 96 * @systemapi 97 * @since 9 98 */ 99 function stopUsingPermission(tokenID: number, permissionName: Permissions): Promise<void>; 100 function stopUsingPermission(tokenID: number, permissionName: Permissions, callback: AsyncCallback<void>): void; 101 102 /** 103 * Subscribes to the change of active state of the specified permission. 104 * @param permissionList Indicates the permission list, which are specified. 105 * @throws { BusinessError } 401 - The parameter check failed. 106 * @throws { BusinessError } 201 - Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". 107 * @throws { BusinessError } 12100001 - The parameter is invalid. The tokenID is 0, or the string size of permissionName is larger than 256. 108 * @throws { BusinessError } 12100004 - The interface is called repeatedly with the same input. 109 * @throws { BusinessError } 12100005 - The registration time has exceeded the limitation. 110 * @throws { BusinessError } 12100007 - Service is abnormal. 111 * @throws { BusinessError } 12100008 - Out of memory. 112 * @permission ohos.permission.PERMISSION_USED_STATS 113 * @systemapi 114 * @since 9 115 */ 116 function on(type: 'activeStateChange', permissionList: Array<Permissions>, callback: Callback<ActiveChangeResponse>): void; 117 118 /** 119 * Unsubscribes to the change of active state of the specified permission. 120 * @param permissionList Indicates the permission list, which are specified. 121 * @throws { BusinessError } 401 - The parameter check failed. 122 * @throws { BusinessError } 201 - Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". 123 * @throws { BusinessError } 12100001 - The parameter is invalid. The permissionName in list is all invalid or the list size is larger than 1024. 124 * @throws { BusinessError } 12100004 - The interface is not used together with "on". 125 * @throws { BusinessError } 12100007 - Service is abnormal. 126 * @throws { BusinessError } 12100008 - Out of memory. 127 * @permission ohos.permission.PERMISSION_USED_STATS 128 * @systemapi 129 * @since 9 130 */ 131 function off(type: 'activeStateChange', permissionList: Array<Permissions>, callback?: Callback<ActiveChangeResponse>): void; 132 133 /** 134 * Enum for permission for status. 135 * @systemapi 136 * @since 9 137 */ 138 enum PermissionActiveStatus { 139 /** 140 * permission is not used yet. 141 */ 142 PERM_INACTIVE = 0, 143 144 /** 145 * permission is used in front_end. 146 */ 147 PERM_ACTIVE_IN_FOREGROUND = 1, 148 149 /** 150 * permission is used in back_end. 151 */ 152 PERM_ACTIVE_IN_BACKGROUND = 2, 153 } 154 155 /** 156 * Indicates the response of permission active status. 157 * @systemapi 158 * @since 9 159 */ 160 interface ActiveChangeResponse { 161 /** 162 * AccessTokenID 163 */ 164 tokenId: number; 165 166 /** 167 * The permission name 168 */ 169 permissionName: Permissions; 170 171 /** 172 * The device id 173 */ 174 deviceId: string; 175 /** 176 * The active status name 177 */ 178 activeStatus: PermissionActiveStatus; 179 } 180 181 /** 182 * PermissionUsageFlag. 183 * @systemapi 184 * @since 9 185 */ 186 enum PermissionUsageFlag { 187 /** 188 * permission used summary 189 */ 190 FLAG_PERMISSION_USAGE_SUMMARY = 0, 191 /** 192 * permission used detail 193 */ 194 FLAG_PERMISSION_USAGE_DETAIL = 1, 195 } 196 197 /** 198 * Provides request of querying permission used records. 199 * @systemapi 200 * @since 9 201 */ 202 interface PermissionUsedRequest { 203 /** 204 * AccessTokenID 205 */ 206 tokenId: number; 207 208 /** 209 * Distribute flag 210 */ 211 isRemote: boolean; 212 213 /** 214 * The device id 215 */ 216 deviceId: string; 217 218 /** 219 * The bundle name 220 */ 221 bundleName: string; 222 223 /** 224 * The list of permission name 225 */ 226 permissionNames: Array<Permissions>; 227 228 /** 229 * The begin time, in milliseconds 230 */ 231 beginTime: number; 232 233 /** 234 * The end time, in milliseconds 235 */ 236 endTime: number; 237 238 /** 239 * The permission usage flag 240 */ 241 flag: PermissionUsageFlag; 242 } 243 244 /** 245 * Provides response of querying permission used records. 246 * @systemapi 247 * @since 9 248 */ 249 interface PermissionUsedResponse { 250 /** 251 * The begin time, in milliseconds 252 */ 253 beginTime: number; 254 255 /** 256 * The end time, in milliseconds 257 */ 258 endTime: number; 259 260 /** 261 * The list of permission used records of bundle 262 */ 263 bundleRecords: Array<BundleUsedRecord>; 264 } 265 266 /** 267 * BundleUsedRecord. 268 * @systemapi 269 * @since 9 270 */ 271 interface BundleUsedRecord { 272 /** 273 * AccessTokenID 274 */ 275 tokenId: number; 276 277 /** 278 * Distribute flag 279 */ 280 isRemote: boolean; 281 282 /** 283 * The device id 284 */ 285 deviceId: string; 286 287 /** 288 * The bundle name 289 */ 290 bundleName: string; 291 292 /** 293 * The list of permission used records 294 */ 295 permissionRecords: Array<PermissionUsedRecord>; 296 } 297 298 /** 299 * PermissionUsedRecord. 300 * @systemapi 301 * @since 9 302 */ 303 interface PermissionUsedRecord { 304 /** 305 * The permission name 306 */ 307 permissionName: Permissions; 308 309 /** 310 * The access counts 311 */ 312 accessCount: number; 313 314 /** 315 * The reject counts 316 */ 317 rejectCount: number; 318 319 /** 320 * The last access time, in milliseconds 321 */ 322 lastAccessTime: number; 323 324 /** 325 * The last reject time, in milliseconds 326 */ 327 lastRejectTime: number; 328 329 /** 330 * The last access duration, in milliseconds 331 */ 332 lastAccessDuration: number; 333 334 /** 335 * The list of access records of details 336 */ 337 accessRecords: Array<UsedRecordDetail>; 338 339 /** 340 * The list of reject records of details 341 */ 342 rejectRecords: Array<UsedRecordDetail>; 343 } 344 345 /** 346 * UsedRecordDetail. 347 * @systemapi 348 * @since 9 349 */ 350 interface UsedRecordDetail { 351 /** 352 * The status 353 */ 354 status: number; 355 356 /** 357 * Timestamp, in milliseconds 358 */ 359 timestamp: number; 360 361 /** 362 * Access duration, in milliseconds 363 */ 364 accessDuration: number; 365 } 366} 367 368export default privacyManager; 369export { Permissions };