js-apis-enterprise-device-manager.md 18.2 KB
Newer Older
E
add doc  
ester.zhou 已提交
1 2
# Enterprise Device Management

3
> **NOTE**<br>
E
add doc  
ester.zhou 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.


## Modules to Import

```
import enterpriseDeviceManager from '@ohos.enterpriseDeviceManager';
```


## enterpriseDeviceManager.activateAdmin

activateAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, callback: AsyncCallback\<boolean>): void

Activates a device administrator application based on the specified bundle name and class name. This API uses an asynchronous callback to return the result.

**Required permissions**
E
ester.zhou 已提交
21

E
add doc  
ester.zhou 已提交
22 23 24
ohos.permission.MANAGE_ADMIN

**System capability**
E
ester.zhou 已提交
25

E
add doc  
ester.zhou 已提交
26 27 28 29
SystemCapability.Customation.EnterpriseDeviceManager

**Parameters**

30 31 32 33 34 35
 | Name | Type | Mandatory | Description |
 | -------- | -------- | -------- | -------- |
 | admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
 | enterpriseInfo | [EnterpriseInfo](#EnterpriseInfo) | Yes | Enterprise information of the device administrator application. |
 | type | [AdminType](#AdminType) | Yes | Type of the device administrator to activate. |
 | callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. |
E
add doc  
ester.zhou 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

**Example**

```
let wantTemp = {
	bundleName: "com.example.myapplication",
	abilityName: "com.example.myapplication.MainAbility",
};
let enterpriseInfo = {
	name: "enterprise name",
	description: "enterprise description"
}
enterpriseDeviceManager.activateAdmin(wantTemp, enterpriseInfo, enterpriseDeviceManager.AdminType.ADMIN_TYPE_NORMAL, (error, result) => {
    if (error != null) {
        console.log("error occurs" + error);
        return; 
    }
    console.log(result);
});
```

## enterpriseDeviceManager.activateAdmin

activateAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType): Promise\<boolean>

Activates a device administrator application based on the specified bundle name and class name. This API uses a promise to return the result.

**Required permissions**
E
ester.zhou 已提交
64

E
add doc  
ester.zhou 已提交
65 66 67
ohos.permission.MANAGE_ADMIN

**System capability**
E
ester.zhou 已提交
68

E
add doc  
ester.zhou 已提交
69 70 71 72
SystemCapability.Customation.EnterpriseDeviceManager

**Parameters**

73 74 75 76 77
 | Name | Type | Mandatory | Description |
 | -------------- | ---------------------------------------------- | ---- | ------------------------ |
 | admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
 | enterpriseInfo | [EnterpriseInfo](#EnterpriseInfo) | Yes | Enterprise information of the device administrator application. |
 | type | [AdminType](#AdminType) | Yes | Type of the device administrator to activate. |
E
add doc  
ester.zhou 已提交
78 79 80

**Return value**

81 82 83
 | Type | Description |
 | ----------------- | --------------------------- |
 | Promise\<boolean> | Promise used to return the result. |
E
add doc  
ester.zhou 已提交
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110

**Example**

```
let wantTemp = {
	bundleName: "com.example.myapplication",
	abilityName: "com.example.myapplication.MainAbility",
};
let enterpriseInfo = {
	name: "enterprise name",
	description: "enterprise description"
}
enterpriseDeviceManager.activateAdmin(wantTemp, enterpriseInfo, enterpriseDeviceManager.AdminType.ADMIN_TYPE_NORMAL)
.then((result) => {
	console.log(result);
}).catch(error => {
	console.log("error occurs" + error);
});
```

## enterpriseDeviceManager.deactivateAdmin

deactivateAdmin(admin: Want, callback: AsyncCallback\<boolean>): void

Deactivates a device common administrator application based on the specified bundle name and class name. This API uses an asynchronous callback to return the result.

**Required permissions**
E
ester.zhou 已提交
111

E
add doc  
ester.zhou 已提交
112 113 114
ohos.permission.MANAGE_ADMIN

**System capability**
E
ester.zhou 已提交
115

E
add doc  
ester.zhou 已提交
116 117 118 119
SystemCapability.Customation.EnterpriseDeviceManager

**Parameters**

120 121 122 123
 | Name | Type | Mandatory | Description |
 | -------- | ---------------------------------------------- | ---- | ------------------------------ |
 | admin | [Want](js-apis-application-Want.md) | Yes | Device common administrator application. |
 | callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. |
E
add doc  
ester.zhou 已提交
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149

**Example**

```
let wantTemp = {
	bundleName: elementName.bundleName,
	abilityName: elementName.abilityName,
};
enterpriseDeviceManager.deactivateAdmin(wantTemp, (error, result) => {
    if (error != null) {
        console.log("error occurs" + error);
        return; 
    }
    console.log(result);
});
```



## enterpriseDeviceManager.deactivateAdmin

deactivateAdmin(admin: Want): Promise\<boolean>

Deactivates a device common administrator application based on the specified bundle name and class name. This API uses a promise to return the result.

**Required permissions**
E
ester.zhou 已提交
150

E
add doc  
ester.zhou 已提交
151 152 153
ohos.permission.MANAGE_ADMIN

**System capability**
E
ester.zhou 已提交
154

E
add doc  
ester.zhou 已提交
155 156 157 158
SystemCapability.Customation.EnterpriseDeviceManager

**Parameters**

159 160 161
 | Name | Type | Mandatory | Description |
 | ------ | ---------------------------------------------- | ---- | ------------------ |
 | admin | [Want](js-apis-application-Want.md) | Yes | Device common administrator application. |
E
add doc  
ester.zhou 已提交
162 163 164

**Return value**

165 166 167
 | Type | Description |
 | ----------------- | --------------------------- |
 | Promise\<boolean> | Promise used to return the result. |
E
add doc  
ester.zhou 已提交
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189

**Example**

```
let wantTemp = {
	bundleName: "bundleName",
	abilityName: "abilityName",
};
enterpriseDeviceManager.deactivateAdmin(wantTemp).then((result) => {
	console.log(result);
}).catch(error => {
	console.log("error occurs" + error);
});
```

## enterpriseDeviceManager.deactivateSuperAdmin

deactivateSuperAdmin(bundleName: String, callback: AsyncCallback\<boolean>): void

Deactivates a device super administrator application based on the specified bundle name. This API uses an asynchronous callback to return the result.

**System capability**
E
ester.zhou 已提交
190

E
add doc  
ester.zhou 已提交
191 192 193 194
SystemCapability.Customation.EnterpriseDeviceManager

**Parameters**

195 196 197 198
 | Name | Type | Mandatory | Description |
 | ---------- | ----------------------- | ---- | ------------------------------ |
 | bundleName | String | Yes | Bundle name of a device super administrator application. |
 | callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. |
E
add doc  
ester.zhou 已提交
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219

**Example**

```
let bundleName = "com.example.myapplication";
enterpriseDeviceManager.deactivateSuperAdmin(bundleName, (error, result) => {
    if (error != null) {
        console.log("error occurs" + error);
        return; 
    }
    console.log(result);
});
```

## enterpriseDeviceManager.deactivateSuperAdmin

deactivateSuperAdmin(bundleName: String): Promise\<boolean>

Deactivates a device super administrator application based on the specified bundle name. This API uses a promise to return the result.

**System capability**
E
ester.zhou 已提交
220

E
add doc  
ester.zhou 已提交
221 222 223 224
SystemCapability.Customation.EnterpriseDeviceManager

**Parameters**

225 226 227
 | Name | Type | Mandatory | Description |
 | ---------- | ------ | ---- | ------------------------ |
 | bundleName | String | Yes | Bundle name of a device super administrator application. |
E
add doc  
ester.zhou 已提交
228 229 230

**Return value**

231 232 233
 | Type | Description |
 | ----------------- | --------------------------- |
 | Promise\<boolean> | Promise used to return the result. |
E
add doc  
ester.zhou 已提交
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252

**Example**

```
let bundleName = "com.example.myapplication";
enterpriseDeviceManager.deactivateSuperAdmin(bundleName).then((result) => {
	console.log(result);
}).catch(error => {
	console.log("error occurs" + error);
});
```

## enterpriseDeviceManager.isAdminAppActive

isAdminAppActive(admin: Want, callback: AsyncCallback\<boolean>): void

Checks whether a device administrator application is activated based on the specified bundle name and class name. This API uses an asynchronous callback to return the result.

**System capability**
E
ester.zhou 已提交
253

E
add doc  
ester.zhou 已提交
254 255 256 257
SystemCapability.Customation.EnterpriseDeviceManager

**Parameters**

258 259 260 261
 | Name | Type | Mandatory | Description |
 | -------- | ---------------------------------------------- | ---- | -------------------------------- |
 | admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
 | callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. |
E
add doc  
ester.zhou 已提交
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287

**Example**

```
let wantTemp = {
	bundleName: elementName.bundleName,
	abilityName: elementName.abilityName,
};
enterpriseDeviceManager.isAdminAppActive(wantTemp, (error, result) => {
    if (error != null) {
        console.log("error occurs" + error);
        return; 
    }
    console.log(result);
});
```



## enterpriseDeviceManager.isAdminAppActive

isAdminAppActive(admin: Want): Promise\<boolean>

Checks whether a device administrator application is activated based on the specified bundle name and class name. This API uses a promise to return the result.

**System capability**
E
ester.zhou 已提交
288

E
add doc  
ester.zhou 已提交
289 290 291 292
SystemCapability.Customation.EnterpriseDeviceManager

**Parameters**

293 294 295
 | Name | Type | Mandatory | Description |
 | ------ | ---------------------------------------------- | ---- | -------------- |
 | admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
E
add doc  
ester.zhou 已提交
296 297 298

**Return value**

299 300 301
 | Type | Description |
 | ----------------- | ------------------------------- |
 | Promise\<boolean> | Promise used to return the result. |
E
add doc  
ester.zhou 已提交
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323

**Example**

```
let wantTemp = {
	bundleName: "bundleName",
	abilityName: "abilityName",
};
enterpriseDeviceManager.isAdminAppActive(wantTemp).then((result) => {
	console.log(result);
}).catch(error => {
	console.log("error occurs" + error);
});
```

## enterpriseDeviceManager.isSuperAdmin

isSuperAdmin(bundleName: String, callback: AsyncCallback\<boolean>): void

Checks whether a device super administrator application is activated based on the specified bundle name. This API uses an asynchronous callback to return the result.

**System capability**
E
ester.zhou 已提交
324

E
add doc  
ester.zhou 已提交
325 326 327 328
SystemCapability.Customation.EnterpriseDeviceManager

**Parameters**

329 330 331 332
 | Name | Type | Mandatory | Description |
 | ---------- | ----------------------- | ---- | -------------------------------- |
 | bundleName | String | Yes | Bundle name of a device super administrator application. |
 | callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. |
E
add doc  
ester.zhou 已提交
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355

**Example**

```
let bundleName = "com.example.myapplication";
enterpriseDeviceManager.isSuperAdmin(bundleName, (error, result) => {
    if (error != null) {
        console.log("error occurs" + error);
        return; 
    }
    console.log(result);
});
```



## enterpriseDeviceManager.isSuperAdmin

isSuperAdmin(bundleName: String): Promise\<boolean>

Checks whether a device super administrator application is activated based on the specified bundle name. This API uses a promise to return the result.

**System capability**
E
ester.zhou 已提交
356

E
add doc  
ester.zhou 已提交
357 358 359 360
SystemCapability.Customation.EnterpriseDeviceManager

**Parameters**

361 362 363
 | Name | Type | Mandatory | Description |
 | ---------- | ------ | ---- | ------------------ |
 | bundleName | String | Yes | Bundle name of a device super administrator application. |
E
add doc  
ester.zhou 已提交
364 365 366

**Return value**

367 368 369
 | Type | Description |
 | ----------------- | ------------------------------- |
 | Promise\<boolean> | Promise used to return the result. |
E
add doc  
ester.zhou 已提交
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388

**Example**

```
let bundleName = "com.example.myapplication";
enterpriseDeviceManager.isSuperAdmin(bundleName).then((result) => {
	console.log(result);
}).catch(error => {
	console.log("error occurs" + error);
});
```

## enterpriseDeviceManager.getDeviceSettingsManager

getDeviceSettingsManager(callback: AsyncCallback&lt;DeviceSettingsManager&gt;): void

Obtains a **DeviceSettingsManager** object. This API uses an asynchronous callback to return the result.

**System capability**
E
ester.zhou 已提交
389

E
add doc  
ester.zhou 已提交
390 391 392 393
SystemCapability.Customation.EnterpriseDeviceManager

**Parameters**

394 395 396
 | Name | Type | Mandatory | Description |
 | -------- | -------- | -------- | -------- |
 | callback | AsyncCallback<DeviceSettingsManager&gt; | Yes | Callback used to return the **DeviceSettingsManager** object obtained. |
E
add doc  
ester.zhou 已提交
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427

**Example**

```
let wantTemp = {
	bundleName: "bundleName",
	abilityName: "abilityName",
};
enterpriseDeviceManager.getDeviceSettingsManager((error, mgr) => {
    if (error != null) {
        console.log("error occurs" + error);
        return; 
    }
    mgr.setDateTime(wantTemp, 1526003846000, (error, value) => { 
        if (error != null) {
            console.log(error);
        } else {
            console.log(value);
        }
    });
});
```


## enterpriseDeviceManager.getDeviceSettingsManager

getDeviceSettingsManager(): Promise&lt;DeviceSettingsManager&gt;

Obtains a **DeviceSettingsManager** object. This API uses a promise to return the result.

**System capability**
E
ester.zhou 已提交
428

E
add doc  
ester.zhou 已提交
429 430 431 432
SystemCapability.Customation.EnterpriseDeviceManager

**Return value**

433 434 435
 | Type | Description |
 | -------- | -------- |
 | Promise&lt;DeviceSettingsManager&gt; | Promise used to return the **DeviceSettingsManager** object obtained. |
E
add doc  
ester.zhou 已提交
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461

**Example**

```
let wantTemp = {
	bundleName: "bundleName",
	abilityName: "abilityName",
};
mgr.getDeviceSettingsManager().then((mgr) => {
    mgr.setDateTime(wantTemp, 1526003846000).then((value) => {
        console.log(value);
    }).catch((error) => {
        console.log(error);
    })
}).catch((error) => {
    console.log(error);
})
```

## enterpriseDeviceManager.setEnterpriseInfo

setEnterpriseInfo(admin: Want, enterpriseInfo: EnterpriseInfo, callback: AsyncCallback&lt;boolean&gt;): void

Sets the enterprise information of a device administrator application. This API uses an asynchronous callback to return the result.

**System capability**
E
ester.zhou 已提交
462

E
add doc  
ester.zhou 已提交
463 464 465 466
SystemCapability.Customation.EnterpriseDeviceManager

**Parameters**

467 468 469 470 471
 | Name | Type | Mandatory | Description |
 | -------------- | ---------------------------------------------- | ---- | ------------------------------------ |
 | admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
 | enterpriseInfo | [EnterpriseInfo](#EnterpriseInfo) | Yes | Enterprise information of the device administrator application. |
 | callback | AsyncCallback\<boolean&gt; | Yes | Callback used to return the result. |
E
add doc  
ester.zhou 已提交
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499

**Example**

```
let wantTemp = {
	bundleName: "com.example.myapplication",
	abilityName: "com.example.myapplication.MainAbility",
};
let enterpriseInfo = {
	name: "enterprise name",
	description: "enterprise description"
}
enterpriseDeviceManager.setEnterpriseInfo(wantTemp, enterpriseInfo)
.then((result) => {
	console.log(result);
}).catch(error => {
	console.log("error occurs" + error);
});
```


## enterpriseDeviceManager.setEnterpriseInfo

setEnterpriseInfo(admin: Want, enterpriseInfo: EnterpriseInfo): Promise&lt;boolean&gt;

Sets the enterprise information of a device administrator application. This API uses a promise to return the result.

**System capability**
E
ester.zhou 已提交
500

E
add doc  
ester.zhou 已提交
501 502 503 504
SystemCapability.Customation.EnterpriseDeviceManager

**Parameters**

505 506 507 508
 | Name | Type | Mandatory | Description |
 | -------------- | ---------------------------------------------- | ---- | ------------------------ |
 | admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
 | enterpriseInfo | [EnterpriseInfo](#EnterpriseInfo) | Yes | Enterprise information of the device administrator application. |
E
add doc  
ester.zhou 已提交
509 510 511

**Return value**

512 513 514
 | Type | Description |
 | ------------------ | ----------------------------------- |
 | Promise\<boolean>; | Callback used to return the result. |
E
add doc  
ester.zhou 已提交
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541

**Example**

```
let wantTemp = {
	bundleName: "com.example.myapplication",
	abilityName: "com.example.myapplication.MainAbility",
};
let enterpriseInfo = {
	name: "enterprise name",
	description: "enterprise description"
}
enterpriseDeviceManager.setEnterpriseInfo(wantTemp, enterpriseInfo)
.then((result) => {
	console.log(result);
}).catch(error => {
	console.log("error occurs" + error);
});
```

## enterpriseDeviceManager.getEnterpriseInfo

getEnterpriseInfo(admin: Want, callback: AsyncCallback&lt;EnterpriseInfo&gt;): void

Obtains the enterprise information of a device administrator application. This API uses an asynchronous callback to return the result.

**System capability**
E
ester.zhou 已提交
542

E
add doc  
ester.zhou 已提交
543 544 545 546
SystemCapability.Customation.EnterpriseDeviceManager

**Parameters**

547 548 549 550
 | Name | Type  | Mandatory | Description |
 | -------- | ------------------------------------------------------ | ---- | ---------------------------------------- |
 | admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
 | callback | AsyncCallback&lt;[EnterpriseInfo](#EnterpriseInfo)&gt; | Yes | Callback used to return the enterprise information of the device administrator application. |
E
add doc  
ester.zhou 已提交
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576

**Example**

```
let wantTemp = {
	bundleName: "com.example.myapplication",
	abilityName: "com.example.myapplication.MainAbility",
};
enterpriseDeviceManager.getEnterpriseInfo(wantTemp, (error, result) => {
    if (error != null) {
        console.log("error occurs" + error);
        return; 
    }
    console.log(result.name);
	console.log(result.description);
});
```


## enterpriseDeviceManager.getEnterpriseInfo

getDeviceSettingsManager(admin: Want): Promise&lt;EnterpriseInfo&gt;

Obtains the enterprise information of a device administrator application. This API uses a promise to return the result.

**System capability**
E
ester.zhou 已提交
577

E
add doc  
ester.zhou 已提交
578 579 580 581
SystemCapability.Customation.EnterpriseDeviceManager

**Parameters**

582 583 584
 | Name | Type | Mandatory | Description |
 | ------ | ---------------------------------------------- | ---- | -------------- |
 | admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
E
add doc  
ester.zhou 已提交
585 586 587

**Return value**

588 589 590
 | Type | Description |
 | ------------------------------------------------ | ------------------------------------------- |
 | Promise&lt;[EnterpriseInfo](#EnterpriseInfo)&gt; | Promise used to return the enterprise information of the device administrator application. |
E
add doc  
ester.zhou 已提交
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610

**Example**

```
let wantTemp = {
	bundleName: "com.example.myapplication",
	abilityName: "com.example.myapplication.MainAbility",
};
enterpriseDeviceManager.getEnterpriseInfo(wantTemp).then((result) => {
	console.log(result.name);
	console.log(result.description);
}).catch(error => {
	console.log("error occurs" + error);
});
```

## EnterpriseInfo

Describes the enterprise information of a device administrator application.

E
ester.zhou 已提交
611 612
**System capability**

E
add doc  
ester.zhou 已提交
613
SystemCapability.Customation.EnterpriseDeviceManager
E
ester.zhou 已提交
614

615 616 617 618
 | Name | Readable/Writable | Type | Mandatory | Description |
 | ----------- | -------- | ------ | ---- | ---------------------------------- |
 | name | Read only | string | Yes | Name of the enterprise to which the device administrator application belongs. |
 | description | Read only | string | Yes | Description of the enterprise to which the device administrator application belongs. |
E
add doc  
ester.zhou 已提交
619 620 621 622 623 624


## AdminType

Enumerates the administrator types of the device administrator application.

E
ester.zhou 已提交
625 626
**System capability**

E
add doc  
ester.zhou 已提交
627
SystemCapability.Customation.EnterpriseDeviceManager
E
ester.zhou 已提交
628

629 630 631 632
 | Name | Default Value | Description |
 | -------- | -------- | -------- |
 | ADMIN_TYPE_NORMAL | 0x00 | Common administrator. |
 | ADMIN_TYPE_SUPER | 0x01 | Super administrator. |