1# 通话管理<a name="ZH-CN_TOPIC_0000001105058232"></a>
2
3-   [简介](#section117mcpsimp)
4-   [目录](#section128mcpsimp)
5-   [约束](#section131mcpsimp)
6-   [接口说明](#section136mcpsimp)
7-   [使用说明](#section163mcpsimp)
8    -   [拨打电话接口调用流程及示例代码](#section113291522113518)
9    -   [获取VoLTE高清通话服务是否启用](#section113291522113520)
10
11-   [相关仓](#section227mcpsimp)
12
13## 简介<a name="section117mcpsimp"></a>
14
15通话管理模块主要管理CS(Circuit Switch,电路交换)、IMS(IP Multimedia Subsystem,IP多媒体子系统)和OTT(over the top,OTT解决方案)三种类型的通话,负责申请通话所需要的音视频资源,并处理多路通话时产生的各种冲突。通话管理主要分为UI交互、服务管理、系统通话管理、通话音频管理、通话视频管理和蓝牙通话管理六大模块,各模块简介如下:
16
171.  UI交互模块:负责和通话UI交互,如UI调用接口拨号,上报来电等状态给UI。
182.  服务管理模块:负责启动和初始化系统通话管理服务。
193.  系统通话管理模块:负责处理通话下行操作(如拨号、接听、挂断等)和上行状态(来电状态、呼叫等待状态等)的处理,并解决通话过程中产生的冲突。
204.  通话音频管理模块:负责通话时需要的音频资源的申请和释放,依赖多媒体子系统,需要调用多媒体子系统接口进行音频相关的操作。
215.  通话视频管理模块:负责通话时需要的视频资源的申请和释放,依赖多媒体子系统,需要调用多媒体子系统接口进行视频相关的操作。
226.  蓝牙通话管理模块:负责通话时需要的蓝牙资源的申请和释放,并处理蓝牙设备发起的通话操作,如接听和挂断等。
23
24其主要的结构及流程如下图所示:
25
26**图 1**  通话管理模块架构图<a name="fig11440121615591"></a>
27
28
29![](figures/zh-cn_architecture-of-the-call-manager-module.png)
30
31## 目录<a name="section128mcpsimp"></a>
32
33```
34/base/telephony/call_manager
35├─ figures                                 # Readme资源文件
36├─ frameworks                              # 框架层目录
37│  ├─ js                                   # js相关代码
38│  └─ native                               # native相关代码
39├─ interfaces                              # 接口目录
40│  ├─ innerkits                            # 部件间的内部接口
41│  └─ kits                                 # 对应用提供的接口(例如JS接口)
42├─ sa_profile                              # 启动配置文件
43├─ services                                # 服务内部代码
44│  ├─ audio                                # 音频管理相关代码
45│  ├─ bluetooth                            # 蓝牙通话相关代码
46│  ├─ call                                 # 通话业务相关代码
47│  ├─ call_manager_service                 # 进程服务管理相关代码
48│  ├─ call_report                          # 通话状态等信息上报相关代码
49│  ├─ call_setting                         # 通话设置相关代码
50│  ├─ telephony_interaction                # 电话核心服务交互相关代码
51│  └─ video                                # 视频管理相关代码
52├─ test                                    # 测试相关代码
53│  ├─ fuzztest                             # 模糊测试相关代码
54│  ├─ mock                                 # 模拟测试相关代码
55│  └─ unittest                             # 单元测试相关代码
56└─ utils                                   # 通用工具代码目录
57```
58
59## 约束<a name="section131mcpsimp"></a>
60
61-   开发语言:JavaScript。
62-   软件上,需要与以下子系统和服务配合使用:安全子系统,多媒体子系统,软总线基础通信子系统\(蓝牙模块\),Telephony核心服务(core\_service),蜂窝通话服务(cellular\_call)。
63-   硬件上,需要搭载的设备支持以下硬件:扬声器或听筒、麦克风。
64
65## 接口说明<a name="section136mcpsimp"></a>
66
67**表 1**  通话管理对外提供的接口
68
69<a name="table137mcpsimp"></a>
70
71<table><thead align="left"><tr id="row143mcpsimp"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p id="entry144mcpsimpp0"><a name="entry144mcpsimpp0"></a><a name="entry144mcpsimpp0"></a>接口内容</p>
72</th>
73<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p id="entry145mcpsimpp0"><a name="entry145mcpsimpp0"></a><a name="entry145mcpsimpp0"></a>接口描述</p>
74</th>
75<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p id="entry146mcpsimpp0"><a name="entry146mcpsimpp0"></a><a name="entry146mcpsimpp0"></a>所需权限</p>
76</th>
77</tr>
78</thead>
79<tbody><tr id="row147mcpsimp"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p143312519577"><a name="p143312519577"></a><a name="p143312519577"></a>function dial(phoneNumber: string, options: DialOptions, callback: AsyncCallback&lt;boolean&gt;): void;</p>
80</td>
81<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="entry149mcpsimpp0"><a name="entry149mcpsimpp0"></a><a name="entry149mcpsimpp0"></a>拨号接口,调用此接口可以进行拨号操作</p>
82</td>
83<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="entry150mcpsimpp0"><a name="entry150mcpsimpp0"></a><a name="entry150mcpsimpp0"></a>ohos.permission.PLACE_CALL</p>
84</td>
85</tr>
86</tbody>
87<tbody><tr id="row147mcpsimp"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p143312519577"><a name="p143312519577"></a><a name="p143312519577"></a>function isImsSwitchEnabledSync(slotId: number):boolean;</p>
88</td>
89<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="entry149mcpsimpp0"><a name="entry149mcpsimpp0"></a><a name="entry149mcpsimpp0"></a>获取VoLTE高清通话服务是否启用(参数slotId表示SIM卡id,0表示卡一,1表示卡二)</p>
90</td>
91<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="entry150mcpsimpp0"><a name="entry150mcpsimpp0"></a><a name="entry150mcpsimpp0"></a>ohos.permission.PLACE_CALL</p>
92</td>
93</tr>
94</tbody>
95</table>
96
97**表 2**  拨号接口参数说明
98
99<a name="table18488202215170"></a>
100<table><thead align="left"><tr id="row748952217179"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1948942271710"><a name="p1948942271710"></a><a name="p1948942271710"></a>参数</p>
101</th>
102<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p1648972215173"><a name="p1648972215173"></a><a name="p1648972215173"></a>描述</p>
103</th>
104</tr>
105</thead>
106<tbody><tr id="row749092213171"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p14901222191720"><a name="p14901222191720"></a><a name="p14901222191720"></a>phoneNumber: string</p>
107</td>
108<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p34906228170"><a name="p34906228170"></a><a name="p34906228170"></a>电话号码</p>
109</td>
110</tr>
111<tr id="row549011221176"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p44902223175"><a name="p44902223175"></a><a name="p44902223175"></a>options: DialOptions</p>
112</td>
113<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p11490162241718"><a name="p11490162241718"></a><a name="p11490162241718"></a>扩展参数(详见下表)</p>
114</td>
115</tr>
116<tr id="row149072216176"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p5490152211715"><a name="p5490152211715"></a><a name="p5490152211715"></a>callback: AsyncCallback&lt;boolean&gt;</p>
117</td>
118<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p649002291718"><a name="p649002291718"></a><a name="p649002291718"></a>异步执行结果,true表示执行成功,false表示执行失败</p>
119</td>
120</tr>
121</tbody>
122</table>
123
124**表 3**  options: DialOptions参数说明
125
126<a name="table1322739190"></a>
127<table><thead align="left"><tr id="row193221031194"><th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.1"><p id="p203224311917"><a name="p203224311917"></a><a name="p203224311917"></a>参数</p>
128</th>
129<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.2"><p id="p1639614810198"><a name="p1639614810198"></a><a name="p1639614810198"></a>类型</p>
130</th>
131<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.3"><p id="p113221730191"><a name="p113221730191"></a><a name="p113221730191"></a>描述</p>
132</th>
133<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.4"><p id="p153221330197"><a name="p153221330197"></a><a name="p153221330197"></a>是否必填</p>
134</th>
135<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.5"><p id="p632220310199"><a name="p632220310199"></a><a name="p632220310199"></a>默认值</p>
136</th>
137</tr>
138</thead>
139<tbody><tr id="row123238311920"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p932310311197"><a name="p932310311197"></a><a name="p932310311197"></a>extras</p>
140</td>
141<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p73966801911"><a name="p73966801911"></a><a name="p73966801911"></a>boolean</p>
142</td>
143<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p19821612162118"><a name="p19821612162118"></a><a name="p19821612162118"></a>false:音频 true:视频</p>
144</td>
145<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p33231931191"><a name="p33231931191"></a><a name="p33231931191"></a>否</p>
146</td>
147<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p12323232197"><a name="p12323232197"></a><a name="p12323232197"></a>false</p>
148</td>
149</tr>
150</tbody>
151</table>
152
153完整的JS API说明以及实例代码请参考:[拨打电话](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-telephony-kit/js-apis-call.md)154## 使用说明<a name="section163mcpsimp"></a>
155
156### 拨打电话接口调用流程及示例代码<a name="section113291522113518"></a>
157
1581.  构造phoneNumber和options参数;
1592.  可以通过callback或者Promise的方式调用dial接口。
160
1613.  该接口为异步接口,相关执行结果会从callback中返回。
162
163    ```
164    import call from "@ohos.telephony.call";
165
166    let phoneNumber = "12312312312";
167
168    // 调用接口【callback方式】
169    call.dial(phoneNumber, {extras: false}, (err, value) => {
170      if (err) {
171        // 接口调用失败,err非空
172        console.error(`failed to dial because ${err.message}`);
173        return;
174      }
175      // 接口调用成功,err为空
176      console.log(`success to dial: ${value}`);
177    });
178
179    // 调用接口【Promise方式】
180    let promise = call.dial(phoneNumber, {extras: false});
181    promise.then((value) => {
182      // 接口调用成功,此处可以实现成功场景分支代码。
183      console.log(`success to dial: ${value}`);
184    }).catch((err) => {
185      // 接口调用失败,此处可以实现失败场景分支代码。
186      console.error(`failed to dial because ${err.message}`);
187    });
188    ```
189
190### 获取VoLTE高清通话服务是否启用<a name="section113291522113520"></a>
191
1921. 可以通过调用isImsSwitchEnabledSync获取VoLTE高清通话服务是否启用。
193
1942. 该接口为同步接口,相关执行结果会从isImsSwitchEnabledSync中返回。
195
196   ```
197   import call from "@ohos.telephony.call";
198
199   try {
200   	// 调用接口【Sync方式】
201   	let isEnabled: boolean = data.isImsSwitchEnabledSync(0);
202   	// 调用接口成功
203       console.log(`isImsSwitchEnabledSync success : ${isEnabled}`);
204   } catch (error) {
205   	// 调用接口失败
206       console.log(`isImsSwitchEnabledSync failed`);
207   }
208   ```
209
210## 相关仓<a name="section227mcpsimp"></a>
211
212[电话服务子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/电话服务子系统.md)
213
214**telephony_call_manager**
215
216[telephony_core_service](https://gitee.com/openharmony/telephony_core_service/blob/master/README_zh.md)
217
218[telephony_cellular_call](https://gitee.com/openharmony/telephony_cellular_call/blob/master/README_zh.md)
219
220[telephony_state_registry](https://gitee.com/openharmony/telephony_state_registry/blob/master/README_zh.md)