• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.enterprise.telephonyManager (Telephony Management)
2
3The **telephonyManager** module provides the telephony management capability.
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 20. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9> - The APIs of this module can be used only in the stage model.
10>
11> - The APIs of this module can be called only by a device administrator application that is enabled. For details, see [MDM Kit Development](../../mdm/mdm-kit-guide.md).
12>
13> - The global restriction policy is provided by **restrictions**. To disable telephony globally, see [@ohos.enterprise.restrictions (Restrictions)](js-apis-enterprise-restrictions.md).
14
15## Modules to Import
16
17```ts
18import { telephonyManager } from '@kit.MDMKit';
19```
20
21## telephonyManager.setSimDisabled
22setSimDisabled(admin: Want, slotId: number): void
23
24Disables the SIM card in a specified slot.
25
26**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_TELEPHONY
27
28**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
29
30
31**Parameters**
32
33| Name      | Type                                                   | Mandatory| Description                                                        |
34| ------------ | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
35| admin        | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | EnterpriseAdminExtensionAbility.|
36| slotId | number                     | Yes  | Slot ID. Currently, only single-slot and dual-slot devices are supported. The value can be **0** or **1**, where **0** indicates slot 1 and **1** indicates slot 2.|
37
38**Error codes**
39
40For details, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
41
42| ID| Error Message                                                    |
43| -------- | ------------------------------------------------------------ |
44| 9200001  | The application is not an administrator application of the device. |
45| 9200002  | The administrator application does not have permission to manage the device. |                      |
46| 201      | Permission verification failed. The application does not have the permission required to call the API. |
47
48**Example**
49
50```ts
51import { Want } from '@kit.AbilityKit';
52import { telephonyManager } from '@kit.MDMKit';
53
54let wantTemp: Want = {
55  // Replace it as required.
56  bundleName: 'com.example.myapplication',
57  abilityName: 'EntryAbility'
58};
59try {
60  let slotId: number = 0;
61  telephonyManager.setSimDisabled(wantTemp, slotId);
62  console.info(`Succeeded in setting slotId: ${slotId} disabled.`);
63} catch (err) {
64  console.error(`Failed to set slotId disabled. Code: ${err.code}, message: ${err.message}`);
65}
66```
67
68## telephonyManager.setSimEnabled
69
70setSimEnabled(admin: Want, slotId: number): void
71
72Enables the SIM card in a specified slot.
73
74**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_TELEPHONY
75
76**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
77
78
79**Parameters**
80
81| Name      | Type                                                   | Mandatory| Description                                                        |
82| ------------ | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
83| admin        | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | EnterpriseAdminExtensionAbility.|
84| slotId | number                     | Yes  |Slot ID. Currently, only single-slot and dual-slot devices are supported. The value can be **0** or **1**, where **0** indicates slot 1 and **1** indicates slot 2. |
85
86**Error codes**
87
88For details, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
89
90| ID| Error Message                                                    |
91| -------- | ------------------------------------------------------------ |
92| 9200001  | The application is not an administrator application of the device. |
93| 9200002  | The administrator application does not have permission to manage the device. |
94| 201      | Permission verification failed. The application does not have the permission required to call the API. |
95
96**Example**
97
98```ts
99import { Want } from '@kit.AbilityKit';
100import { telephonyManager } from '@kit.MDMKit';
101
102let wantTemp: Want = {
103  // Replace it as required.
104  bundleName: 'com.example.myapplication',
105  abilityName: 'EntryAbility'
106};
107try {
108  let slotId: number = 0;
109  telephonyManager.setSimEnabled(wantTemp, slotId);
110  console.info(`Succeeded in setting slotId: ${slotId} enabled.`);
111} catch (err) {
112  console.error(`Failed to set slotId enabled. Code: ${err.code}, message: ${err.message}`);
113}
114```
115
116## telephonyManager.isSimDisabled
117
118isSimDisabled(admin: Want, slotId: number): boolean
119
120Checks whether the SIM card in a specified slot is disabled.
121
122**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_TELEPHONY
123
124**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
125
126
127**Parameters**
128
129| Name| Type                                                   | Mandatory| Description                                  |
130| ------ | ------------------------------------------------------- | ---- | -------------------------------------- |
131| admin        | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | EnterpriseAdminExtensionAbility.|
132| slotId | number                     | Yes  |Slot ID. Currently, only single-slot and dual-slot devices are supported. The value can be **0** or **1**, where **0** indicates slot 1 and **1** indicates slot 2. |
133
134**Return value**
135
136| Type                              | Description                     |
137| ---------------------------------- | ------------------------- |
138| boolean | A Boolean value indicating the SIM card status in the specified slot. The value **true** means the SIM card in the specified slot is disabled; the value **false** means the opposite.|
139
140**Error codes**
141
142For details, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
143
144| ID| Error Message                                                    |
145| -------- | ------------------------------------------------------------ |
146| 9200001  | The application is not an administrator application of the device. |
147| 9200002  | The administrator application does not have permission to manage the device. |
148| 201      | Permission verification failed. The application does not have the permission required to call the API. |
149
150**Example**
151
152```ts
153import { Want } from '@kit.AbilityKit';
154import { telephonyManager } from '@kit.MDMKit';
155
156let wantTemp: Want = {
157  // Replace it as required.
158  bundleName: 'com.example.myapplication',
159  abilityName: 'EntryAbility'
160};
161try {
162  let slotId: number = 0;
163  let result: boolean = telephonyManager.isSimDisabled(wantTemp, slotId);
164  console.info(`Succeeded in querying slotId: ${slotId} is disabled or not, result: ${result}`);
165} catch (err) {
166  console.error(`Failed to query sim is disabled or not. Code: ${err.code}, message: ${err.message}`);
167}
168```
169