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, Callback } from "./basic"; 17import Want from "./@ohos.app.ability.Want"; 18 19/** 20 * This module provides the capability to manage the administrator of the enterprise devices. 21 * @namespace adminManager 22 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 23 * @systemapi 24 * @since 9 25 */ 26declare namespace adminManager { 27 28 /** 29 * Provides the enterprise information. 30 * @typedef EnterpriseInfo 31 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 32 * @systemapi 33 * @since 9 34 */ 35 export interface EnterpriseInfo { 36 /** 37 * The name of enterprise. 38 * @type {string} 39 * @since 9 40 */ 41 name: string; 42 43 /** 44 * The description of enterprise. 45 * @type {string} 46 * @since 9 47 */ 48 description: string; 49 } 50 51 /** 52 * Enum for type of administrator. 53 * @enum {number} 54 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 55 * @systemapi 56 * @since 9 57 */ 58 export enum AdminType { 59 /** 60 * The value of normal administrator. 61 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 62 * @since 9 63 */ 64 ADMIN_TYPE_NORMAL = 0x00, 65 66 /** 67 * The value of super administrator. 68 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 69 * @since 9 70 */ 71 ADMIN_TYPE_SUPER = 0x01 72 } 73 74 /** 75 * Enum for managed event 76 * @enum {number} 77 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 78 * @systemapi 79 * @since 9 80 */ 81 export enum ManagedEvent { 82 83 /** 84 * The event of bundle added. 85 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 86 * @since 9 87 */ 88 MANAGED_EVENT_BUNDLE_ADDED = 0, 89 90 /** 91 * The event of bundle removed. 92 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 93 * @since 9 94 */ 95 MANAGED_EVENT_BUNDLE_REMOVED = 1, 96 } 97 98 /** 99 * Enables the given ability as a administrator of the device. 100 * Only apps with the ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN permission or the shell uid can call this method. 101 * @permission ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 102 * @param { Want } admin - admin indicates the administrator ability information. 103 * @param { EnterpriseInfo } enterpriseInfo - enterpriseInfo indicates the enterprise information of the calling application. 104 * @param { AdminType } type - type indicates the type of administrator to set. 105 * @param { AsyncCallback<void> } callback - the callback of enableAdmin. 106 * @throws { BusinessError } 9200003 - the administrator ability component is invalid. 107 * @throws { BusinessError } 9200004 - failed to enable the administrator application of the device. 108 * @throws { BusinessError } 9200007 - the system ability work abnormally. 109 * @throws { BusinessError } 201 - the application does not have permission to call this function. 110 * @throws { BusinessError } 401 - invalid input parameter. 111 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 112 * @systemapi 113 * @StageModelOnly 114 * @since 9 115 */ 116 function enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, callback: AsyncCallback<void>): void; 117 118 /** 119 * Enables the given ability as a administrator of the device. 120 * Only apps with the ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN permission or the shell uid can call this method. 121 * @permission ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 122 * @param { Want } admin - admin indicates the administrator ability information. 123 * @param { EnterpriseInfo } enterpriseInfo - enterpriseInfo indicates the enterprise information of the calling application. 124 * @param { AdminType } type - type indicates the type of administrator to set. 125 * @param { number } userId - userId indicates the user ID. 126 * @param { AsyncCallback<void> } callback - the callback of enableAdmin. 127 * @throws { BusinessError } 9200003 - the administrator ability component is invalid. 128 * @throws { BusinessError } 9200004 - failed to enable the administrator application of the device. 129 * @throws { BusinessError } 9200007 - the system ability work abnormally. 130 * @throws { BusinessError } 201 - the application does not have permission to call this function. 131 * @throws { BusinessError } 401 - invalid input parameter. 132 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 133 * @systemapi 134 * @StageModelOnly 135 * @since 9 136 */ 137 function enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, userId: number, callback: AsyncCallback<void>): void; 138 139 /** 140 * Enables the given ability as a administrator of the device. 141 * Only apps with the ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN permission or the shell uid can call this method. 142 * @permission ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 143 * @param { Want } admin - admin indicates the administrator ability information. 144 * @param { EnterpriseInfo } enterpriseInfo - enterpriseInfo indicates the enterprise information of the calling application. 145 * @param { AdminType } type - type indicates the type of administrator to set. 146 * @param { number } [userId] - userId indicates the user ID or do not pass user ID. 147 * @returns { Promise<void> } the promise returned by the enableAdmin. 148 * @throws { BusinessError } 9200003 - the administrator ability component is invalid. 149 * @throws { BusinessError } 9200004 - failed to enable the administrator application of the device. 150 * @throws { BusinessError } 9200007 - the system ability work abnormally. 151 * @throws { BusinessError } 201 - the application does not have permission to call this function. 152 * @throws { BusinessError } 401 - invalid input parameter. 153 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 154 * @systemapi 155 * @StageModelOnly 156 * @since 9 157 */ 158 function enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, userId?: number): Promise<void>; 159 160 /** 161 * Disables a current normal administrator ability. 162 * Only apps with the ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN permission or the shell uid can call this method. 163 * @permission ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 164 * @param { Want } admin - admin indicates the administrator ability information. 165 * @param { AsyncCallback<void> } callback - the callback of disableAdmin. 166 * @throws { BusinessError } 9200005 - failed to disable the administrator application of the device. 167 * @throws { BusinessError } 201 - the application does not have permission to call this function. 168 * @throws { BusinessError } 401 - invalid input parameter. 169 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 170 * @systemapi 171 * @StageModelOnly 172 * @since 9 173 */ 174 function disableAdmin(admin: Want, callback: AsyncCallback<void>): void; 175 176 /** 177 * Disables a current normal administrator ability. 178 * Only apps with the ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN permission or the shell uid can call this method. 179 * @permission ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 180 * @param { Want } admin - admin indicates the administrator ability information. 181 * @param { number } userId - userId indicates the user ID. 182 * @param { AsyncCallback<void> } callback - the callback of disableAdmin. 183 * @throws { BusinessError } 9200005 - failed to disable the administrator application of the device. 184 * @throws { BusinessError } 201 - the application does not have permission to call this function. 185 * @throws { BusinessError } 401 - invalid input parameter. 186 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 187 * @systemapi 188 * @StageModelOnly 189 * @since 9 190 */ 191 function disableAdmin(admin: Want, userId: number, callback: AsyncCallback<void>): void; 192 193 /** 194 * Disables a current normal administrator ability. 195 * Only apps with the ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN permission or the shell uid can call this method. 196 * @permission ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 197 * @param { Want } admin - admin indicates the administrator ability information. 198 * @param { number } [userId] - userId indicates the user ID or do not pass user ID. 199 * @returns { Promise<void> } the promise returned by the disableAdmin. 200 * @throws { BusinessError } 9200005 - failed to disable the administrator application of the device. 201 * @throws { BusinessError } 201 - the application does not have permission to call this function. 202 * @throws { BusinessError } 401 - invalid input parameter. 203 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 204 * @systemapi 205 * @StageModelOnly 206 * @since 9 207 */ 208 function disableAdmin(admin: Want, userId?: number): Promise<void>; 209 210 /** 211 * Disables a current super administrator ability. 212 * Only the administrator app or apps with the shell uid can call this method. 213 * @permission ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 214 * @param { string } bundleName - bundleName indicates the administrator bundle information. 215 * @param { AsyncCallback<void> } callback - the callback of disableSuperAdmin. 216 * @throws { BusinessError } 9200005 - failed to disable the administrator application of the device. 217 * @throws { BusinessError } 201 - the application does not have permission to call this function. 218 * @throws { BusinessError } 401 - invalid input parameter. 219 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 220 * @systemapi 221 * @StageModelOnly 222 * @since 9 223 */ 224 function disableSuperAdmin(bundleName: String, callback: AsyncCallback<void>): void; 225 226 /** 227 * Disables a current super administrator ability. 228 * Only the administrator app or apps with the shell uid can call this method. 229 * @permission ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 230 * @param { string } bundleName - bundleName indicates the administrator bundle information. 231 * @returns { Promise<void> } the promise returned by the disableSuperAdmin. 232 * @throws { BusinessError } 9200005 - failed to disable the administrator application of the device. 233 * @throws { BusinessError } 201 - the application does not have permission to call this function. 234 * @throws { BusinessError } 401 - invalid input parameter. 235 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 236 * @systemapi 237 * @StageModelOnly 238 * @since 9 239 */ 240 function disableSuperAdmin(bundleName: String): Promise<void>; 241 242 /** 243 * Get whether the ability is enabled as device administrator. 244 * @param { Want } admin - admin indicates the administrator ability information. 245 * @param { AsyncCallback<boolean> } callback - callback contained true if the administrator is enabled. 246 * @throws { BusinessError } 401 - invalid input parameter. 247 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 248 * @systemapi 249 * @StageModelOnly 250 * @since 9 251 */ 252 function isAdminEnabled(admin: Want, callback: AsyncCallback<boolean>): void; 253 254 /** 255 * Get whether the ability is enabled as device administrator. 256 * @param { Want } admin - admin indicates the administrator ability information. 257 * @param { number } userId - userId indicates the user ID. 258 * @param { AsyncCallback<boolean> } callback - callback contained true if the administrator is enabled. 259 * @throws { BusinessError } 401 - invalid input parameter. 260 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 261 * @systemapi 262 * @StageModelOnly 263 * @since 9 264 */ 265 function isAdminEnabled(admin: Want, userId: number, callback: AsyncCallback<boolean>): void; 266 267 /** 268 * Get whether the ability is enabled as device administrator. 269 * @param { Want } admin - admin indicates the administrator ability information. 270 * @param { number } [userId] - userId indicates the user ID or do not pass user ID. 271 * @returns { Promise<boolean> } promise contained true if the administrator is enabled. 272 * @throws { BusinessError } 401 - invalid input parameter. 273 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 274 * @systemapi 275 * @StageModelOnly 276 * @since 9 277 */ 278 function isAdminEnabled(admin: Want, userId?: number): Promise<boolean>; 279 280 /** 281 * Get information of the administrator's enterprise. 282 * @param { Want } admin - admin indicates the administrator ability information. 283 * @param { AsyncCallback<EnterpriseInfo> } callback - callback contained the enterprise info of administrator. 284 * @throws { BusinessError } 9200001 - the application is not an administrator of the device. 285 * @throws { BusinessError } 401 - invalid input parameter. 286 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 287 * @systemapi 288 * @StageModelOnly 289 * @since 9 290 */ 291 function getEnterpriseInfo(admin: Want, callback: AsyncCallback<EnterpriseInfo>): void; 292 293 /** 294 * Get information of the administrator's enterprise. 295 * @param { Want } admin - admin indicates the administrator ability information. 296 * @returns { Promise<EnterpriseInfo> } promise contained the enterprise info of administrator. 297 * @throws { BusinessError } 9200001 - the application is not an administrator of the device. 298 * @throws { BusinessError } 401 - invalid input parameter. 299 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 300 * @systemapi 301 * @StageModelOnly 302 * @since 9 303 */ 304 function getEnterpriseInfo(admin: Want): Promise<EnterpriseInfo>; 305 306 /** 307 * Set the information of the administrator's enterprise. 308 * Only the administrator app can call this method. 309 * @permission ohos.permission.SET_ENTERPRISE_INFO 310 * @param { Want } admin - admin indicates the administrator ability information. 311 * @param { EnterpriseInfo } enterpriseInfo - enterpriseInfo indicates the enterprise information of the calling application. 312 * @param { AsyncCallback<void> } callback - the callback of setEnterpriseInfo. 313 * @throws { BusinessError } 9200001 - the application is not an administrator of the device. 314 * @throws { BusinessError } 201 - the application does not have permission to call this function. 315 * @throws { BusinessError } 401 - invalid input parameter. 316 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 317 * @systemapi 318 * @StageModelOnly 319 * @since 9 320 */ 321 function setEnterpriseInfo(admin: Want, enterpriseInfo: EnterpriseInfo, callback: AsyncCallback<void>): void; 322 323 /** 324 * Set the information of the administrator's enterprise. 325 * Only the administrator app can call this method. 326 * @permission ohos.permission.SET_ENTERPRISE_INFO 327 * @param { Want } admin - admin indicates the administrator ability information. 328 * @param { EnterpriseInfo } enterpriseInfo - enterpriseInfo indicates the enterprise information of the calling application. 329 * @returns { Promise<void> } the promise returned by the setEnterpriseInfo. 330 * @throws { BusinessError } 9200001 - the application is not an administrator of the device. 331 * @throws { BusinessError } 201 - the application does not have permission to call this function. 332 * @throws { BusinessError } 401 - invalid input parameter. 333 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 334 * @systemapi 335 * @StageModelOnly 336 * @since 9 337 */ 338 function setEnterpriseInfo(admin: Want, enterpriseInfo: EnterpriseInfo): Promise<void>; 339 340 /** 341 * Get whether the ability is enabled as super device administrator. 342 * @param { string } bundleName - bundleName indicates the administrator bundle information. 343 * @param { AsyncCallback<boolean> } callback - callback contained true if the administrator is super administrator. 344 * @throws { BusinessError } 401 - invalid input parameter. 345 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 346 * @systemapi 347 * @StageModelOnly 348 * @since 9 349 */ 350 function isSuperAdmin(bundleName: String, callback: AsyncCallback<boolean>): void; 351 352 /** 353 * Get whether the ability is enabled as super device administrator. 354 * @param { string } bundleName - bundleName indicates the administrator bundle information. 355 * @returns { Promise<boolean> } promise contained true if the administrator is super administrator. 356 * @throws { BusinessError } 401 - invalid input parameter. 357 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 358 * @systemapi 359 * @StageModelOnly 360 * @since 9 361 */ 362 function isSuperAdmin(bundleName: String): Promise<boolean>; 363 364 /** 365 * Subscribes the managed event of admin. 366 * @permission ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 367 * @param { Want } admin - admin indicates the administrator ability information. 368 * @param { Array<ManagedEvent> } managedEvents - managedEvents indicates the managed events to subscribe. 369 * @param { AsyncCallback<void> } callback - the callback of subscribeManagedEvent. 370 * @throws { BusinessError } 9200001 - the application is not an administrator of the device. 371 * @throws { BusinessError } 9200008 - the specified system events enum is invalid. 372 * @throws { BusinessError } 201 - the application does not have permission to call this function. 373 * @throws { BusinessError } 401 - invalid input parameter. 374 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 375 * @systemapi 376 * @StageModelOnly 377 * @since 9 378 */ 379 function subscribeManagedEvent(admin: Want, managedEvents: Array<ManagedEvent>, callback: AsyncCallback<void>): void; 380 381 /** 382 * Subscribes the managed event of admin. 383 * @permission ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 384 * @param { Want } admin - admin indicates the administrator ability information. 385 * @param { Array<ManagedEvent> } managedEvents - managedEvents indicates the managed events to subscribe. 386 * @returns { Promise<void> } the promise returned by the subscribeManagedEvent. 387 * @throws { BusinessError } 9200001 - the application is not an administrator of the device. 388 * @throws { BusinessError } 9200008 - the specified system events enum is invalid. 389 * @throws { BusinessError } 201 - the application does not have permission to call this function. 390 * @throws { BusinessError } 401 - invalid input parameter. 391 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 392 * @systemapi 393 * @StageModelOnly 394 * @since 9 395 */ 396 function subscribeManagedEvent(admin: Want, managedEvents: Array<ManagedEvent>): Promise<void>; 397 398 /** 399 * Unsubscribes the managed event of admin. 400 * @permission ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 401 * @param { Want } admin - admin indicates the administrator ability information. 402 * @param { Array<ManagedEvent> } managedEvents - managedEvents indicates the managed events to subscribe. 403 * @param { AsyncCallback<void> } callback - the callback of unsubscribeManagedEvent. 404 * @throws { BusinessError } 9200001 - the application is not an administrator of the device. 405 * @throws { BusinessError } 9200008 - the specified system events enum is invalid. 406 * @throws { BusinessError } 201 - the application does not have permission to call this function. 407 * @throws { BusinessError } 401 - invalid input parameter. 408 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 409 * @systemapi 410 * @StageModelOnly 411 * @since 9 412 */ 413 function unsubscribeManagedEvent(admin: Want, managedEvents: Array<ManagedEvent>, callback: AsyncCallback<void>): void; 414 415 /** 416 * Unsubscribes the managed event of admin. 417 * @permission ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 418 * @param { Want } admin - admin indicates the administrator ability information. 419 * @param { Array<ManagedEvent> } managedEvents - managedEvents indicates the managed events to subscribe. 420 * @returns { Promise<void> } the promise returned by the unsubscribeManagedEvent. 421 * @throws { BusinessError } 9200001 - the application is not an administrator of the device. 422 * @throws { BusinessError } 9200008 - the specified system events enum is invalid. 423 * @throws { BusinessError } 201 - the application does not have permission to call this function. 424 * @throws { BusinessError } 401 - invalid input parameter. 425 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 426 * @systemapi 427 * @StageModelOnly 428 * @since 9 429 */ 430 function unsubscribeManagedEvent(admin: Want, managedEvents: Array<ManagedEvent>): Promise<void>; 431} 432 433export default adminManager;