• Home
Name Date Size #Lines LOC

..--

figures/12-May-2024-

frameworks/12-May-2024-12,2289,781

interfaces/12-May-2024-2,7281,094

sa_profile/12-May-2024-4830

services/12-May-2024-17,32114,125

test/12-May-2024-3,1842,605

utils/12-May-2024-2,1181,786

BUILD.gnD12-May-20244.5 KiB122111

LICENSED12-May-20249.9 KiB177150

OAT.xmlD12-May-20246.7 KiB8126

README.mdD12-May-202423.4 KiB362317

README_zh.mdD12-May-202414.8 KiB229175

bundle.jsonD12-May-20242 KiB7270

README.md

1# SMS and MMS<a name="EN-US_TOPIC_0000001105544742"></a>
2
3- [SMS and MMS<a name="EN-US_TOPIC_0000001105544742"></a>](#sms-and-mms)
4  - [Introduction<a name="section117mcpsimp"></a>](#introduction)
5  - [Directory Structure<a name="section125mcpsimp"></a>](#directory-structure)
6  - [Constraints<a name="section129mcpsimp"></a>](#constraints)
7  - [Available APIs<a name="section134mcpsimp"></a>](#available-apis)
8  - [Usage Guidelines<a name="section170mcpsimp"></a>](#usage-guidelines)
9    - [Sending SMS Messages<a name="section172mcpsimp"></a>](#sending-sms-messages)
10    - [Creating a ShortMessage Object<a name="section181mcpsimp"></a>](#creating-a-shortmessage-object)
11  - [Repositories Involved<a name="section189mcpsimp"></a>](#repositories-involved)
12
13-   [Repositories Involved](#section189mcpsimp)
14
15## Introduction<a name="section117mcpsimp"></a>
16
17The SMS and MMS module provides the capabilities of sending and receiving short message service \(SMS\) messages and encoding and decoding multimedia messaging service \(MMS\) messages for mobile data users. Its main functions include the following: GSM/CDMA SMS message receiving and sending, SMS protocol data unit \(PDU\) encoding and decoding, WAP Push message receiving and processing, cell broadcast message receiving, MMS message notification, MMS message encoding and decoding, and SIM SMS record management.
18
19**Figure  1**  Architecture of the SMS and MMS module<a name="fig420553511549"></a>
20![](figures/en-us_architecture-of-the-sms-and-mms-module.png)
21
22The SMS and MMS module consists of four major parts:
23
24-   SmsInterfaceManager: provides external APIs for sending SMS messages and managing SIM SMS records. It can be used to create  **SmsSendManager**  and  **SmsReceiveManager**  objects.
25-   SmsSendManager: sends SMS messages and listens to IMS network status changes. It can be used to create  **GsmSmsSender**  and  **CdmaSmsSender**  objects and schedule either object based on the radio access technology \(RAT\) to send SMS messages.
26-   SmsReceiveManager: receives SMS messages and listens to new SMS messages from the RIL Adapter layer. It can be used to create  **GsmSmsReceiveHandler**  and  **CdmaSmsReceiveHandler**  objects as well as the  **SmsWapPushHandler**  and  **SmsCellBroadcastHandler**  objects.
27-   MmsPduProcessor: encodes and decodes MMS PDUs.
28
29## Directory Structure<a name="section125mcpsimp"></a>
30
31```
32/base/telephony/sms_mms
33├─ interfaces               # External APIs
34│  └─ kits
35├─ sa_profile               # SA profile
36├─ services                 # Service code
37│  ├─ include               # Header files
38│  ├─ cdma                  # CDMA source files
39│  └─ gsm                   # GSM source files
40├─ test                     # Unit test code
41└─ utils                    # Utilities
42```
43
44## Constraints<a name="section129mcpsimp"></a>
45
46-   Programming language: JavaScript
47-   In terms of software, this module needs to work with the telephony core service \(core\_service\) and depends on the  [glib](https://gitlab.gnome.org/GNOME/glib).
48-   In terms of hardware, the accommodating device must be equipped with a modem and a SIM card capable of independent cellular communication.
49
50## Available APIs<a name="section134mcpsimp"></a>
51
52**Table  1**  External APIs provided by the SMS and MMS module
53
54<a name="table136mcpsimp"></a>
55<table><thead align="left"><tr id="row142mcpsimp"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p id="entry143mcpsimpp0"><a name="entry143mcpsimpp0"></a><a name="entry143mcpsimpp0"></a>API</p>
56</th>
57<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p id="entry144mcpsimpp0"><a name="entry144mcpsimpp0"></a><a name="entry144mcpsimpp0"></a>Description</p>
58</th>
59<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p id="entry145mcpsimpp0"><a name="entry145mcpsimpp0"></a><a name="entry145mcpsimpp0"></a>Required Permission</p>
60</th>
61</tr>
62</thead>
63<tbody><tr id="row146mcpsimp"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p1011717318415"><a name="p1011717318415"></a><a name="p1011717318415"></a>function sendMessage(options: SendMessageOptions): void;</p>
64</td>
65<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="entry148mcpsimpp0"><a name="entry148mcpsimpp0"></a><a name="entry148mcpsimpp0"></a>Sends SMS messages, including long messages, common messages, and data messages.</p>
66</td>
67<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="entry149mcpsimpp0"><a name="entry149mcpsimpp0"></a><a name="entry149mcpsimpp0"></a>SystemPermission.SEND_MESSAGES</p>
68</td>
69</tr>
70<tr id="row166mcpsimp"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="entry167mcpsimpp0"><a name="entry167mcpsimpp0"></a><a name="entry167mcpsimpp0"></a>function createMessage(pdu: Array&lt;number&gt;, specification: string, callback: AsyncCallback&lt;ShortMessage&gt;): void;</p>
71</td>
72<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p43948592416"><a name="p43948592416"></a><a name="p43948592416"></a>Creates and parses <strong id="b191003398102"><a name="b191003398102"></a><a name="b191003398102"></a>ShortMessage</strong> objects based on PDUs.</p>
73</td>
74<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="entry169mcpsimpp0"><a name="entry169mcpsimpp0"></a><a name="entry169mcpsimpp0"></a>None</p>
75</td>
76</tr>
77</tbody>
78</table>
79
80**Table  2**  Parameter description of SendMessageOptions
81
82<a name="table137771821149"></a>
83<table><thead align="left"><tr id="row16777142181416"><th class="cellrowborder" valign="top" width="25%" id="mcps1.2.5.1.1"><p id="p1677762111420"><a name="p1677762111420"></a><a name="p1677762111420"></a>Parameter</p>
84</th>
85<th class="cellrowborder" valign="top" width="25%" id="mcps1.2.5.1.2"><p id="p32826484210"><a name="p32826484210"></a><a name="p32826484210"></a>Type</p>
86</th>
87<th class="cellrowborder" valign="top" width="25%" id="mcps1.2.5.1.3"><p id="p117778231415"><a name="p117778231415"></a><a name="p117778231415"></a>Description</p>
88</th>
89<th class="cellrowborder" valign="top" width="25%" id="mcps1.2.5.1.4"><p id="p1725516817152"><a name="p1725516817152"></a><a name="p1725516817152"></a>Mandatory</p>
90</th>
91</tr>
92</thead>
93<tbody><tr id="row1577719210142"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p197771201411"><a name="p197771201411"></a><a name="p197771201411"></a>slotId</p>
94</td>
95<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p16282184822111"><a name="p16282184822111"></a><a name="p16282184822111"></a>number</p>
96</td>
97<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p07777221417"><a name="p07777221417"></a><a name="p07777221417"></a>SIM card slot ID</p>
98</td>
99<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p22552080151"><a name="p22552080151"></a><a name="p22552080151"></a>Yes</p>
100</td>
101</tr>
102<tr id="row177779231416"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p12777928146"><a name="p12777928146"></a><a name="p12777928146"></a>destinationHost</p>
103</td>
104<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p19282948182112"><a name="p19282948182112"></a><a name="p19282948182112"></a>string</p>
105</td>
106<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p157771125144"><a name="p157771125144"></a><a name="p157771125144"></a>Phone number of the recipient</p>
107</td>
108<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p192550811156"><a name="p192550811156"></a><a name="p192550811156"></a>Yes</p>
109</td>
110</tr>
111<tr id="row20777162111419"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p1777814218147"><a name="p1777814218147"></a><a name="p1777814218147"></a>serviceCenter</p>
112</td>
113<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p0282348112110"><a name="p0282348112110"></a><a name="p0282348112110"></a>string</p>
114</td>
115<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p137781826141"><a name="p137781826141"></a><a name="p137781826141"></a>SMC address</p>
116</td>
117<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p1025511815152"><a name="p1025511815152"></a><a name="p1025511815152"></a>No</p>
118</td>
119</tr>
120<tr id="row187781529145"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p1377810211419"><a name="p1377810211419"></a><a name="p1377810211419"></a>content</p>
121</td>
122<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p6282648152118"><a name="p6282648152118"></a><a name="p6282648152118"></a>content | Array&lt;number&gt;</p>
123</td>
124<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p47789219147"><a name="p47789219147"></a><a name="p47789219147"></a>SMS content</p>
125</td>
126<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p325517891510"><a name="p325517891510"></a><a name="p325517891510"></a>Yes</p>
127</td>
128</tr>
129<tr id="row37780215141"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p37784221410"><a name="p37784221410"></a><a name="p37784221410"></a>destinationPort</p>
130</td>
131<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p1428274815211"><a name="p1428274815211"></a><a name="p1428274815211"></a>number</p>
132</td>
133<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p87781524149"><a name="p87781524149"></a><a name="p87781524149"></a>Port number for receiving messages</p>
134</td>
135<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p7255386157"><a name="p7255386157"></a><a name="p7255386157"></a>Yes (for sending of data messages)</p>
136</td>
137</tr>
138<tr id="row14778152151417"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p1877814231418"><a name="p1877814231418"></a><a name="p1877814231418"></a>sendCallback</p>
139</td>
140<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p3283448172111"><a name="p3283448172111"></a><a name="p3283448172111"></a>AsyncCallback&lt;ISendShortMessageCallback&gt;</p>
141</td>
142<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p16778182121416"><a name="p16778182121416"></a><a name="p16778182121416"></a>Callback of the sending result</p>
143</td>
144<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p7255108141513"><a name="p7255108141513"></a><a name="p7255108141513"></a>Yes</p>
145</td>
146</tr>
147<tr id="row107782241418"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p147781321142"><a name="p147781321142"></a><a name="p147781321142"></a>deliveryCallback</p>
148</td>
149<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p172835481214"><a name="p172835481214"></a><a name="p172835481214"></a>AsyncCallback&lt;IDeliveryShortMessageCallback&gt;</p>
150</td>
151<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p5778624149"><a name="p5778624149"></a><a name="p5778624149"></a>Callback of the delivery report</p>
152</td>
153<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p172553821519"><a name="p172553821519"></a><a name="p172553821519"></a>Yes</p>
154</td>
155</tr>
156</tbody>
157</table>
158
159**Table  3**  Description of ISendShortMessageCallback types
160
161<a name="table6490122972417"></a>
162<table><thead align="left"><tr id="row194901529162416"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p id="p849172910245"><a name="p849172910245"></a><a name="p849172910245"></a>Parameter</p>
163</th>
164<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p id="p849182916242"><a name="p849182916242"></a><a name="p849182916242"></a>Type</p>
165</th>
166<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p id="p144911029162413"><a name="p144911029162413"></a><a name="p144911029162413"></a>Description</p>
167</th>
168</tr>
169</thead>
170<tbody><tr id="row16491142916241"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p549162942410"><a name="p549162942410"></a><a name="p549162942410"></a>result</p>
171</td>
172<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p144911129112418"><a name="p144911129112418"></a><a name="p144911129112418"></a>SendSmsResult</p>
173</td>
174<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p14491129172419"><a name="p14491129172419"></a><a name="p14491129172419"></a>Sending result</p>
175</td>
176</tr>
177<tr id="row204911029112418"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p4491172917241"><a name="p4491172917241"></a><a name="p4491172917241"></a>url</p>
178</td>
179<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p1549132914244"><a name="p1549132914244"></a><a name="p1549132914244"></a>string</p>
180</td>
181<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p349115291248"><a name="p349115291248"></a><a name="p349115291248"></a>URL</p>
182</td>
183</tr>
184<tr id="row19491172912247"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p54911329122419"><a name="p54911329122419"></a><a name="p54911329122419"></a>isLastPart</p>
185</td>
186<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p154918290248"><a name="p154918290248"></a><a name="p154918290248"></a>boolean</p>
187</td>
188<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p104913290240"><a name="p104913290240"></a><a name="p104913290240"></a>Whether the SMS message is the last one</p>
189</td>
190</tr>
191</tbody>
192</table>
193
194**Table  4**  Description of SendSmsResult enum values
195
196<a name="table2375639122617"></a>
197<table><thead align="left"><tr id="row1376123932614"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p id="p2376339102616"><a name="p2376339102616"></a><a name="p2376339102616"></a>Name</p>
198</th>
199<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p id="p153769391263"><a name="p153769391263"></a><a name="p153769391263"></a>Value</p>
200</th>
201<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p id="p6376193918267"><a name="p6376193918267"></a><a name="p6376193918267"></a>Description</p>
202</th>
203</tr>
204</thead>
205<tbody><tr id="row1376103912610"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p0376113932616"><a name="p0376113932616"></a><a name="p0376113932616"></a>SEND_SMS_SUCCESS</p>
206</td>
207<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p3376193932611"><a name="p3376193932611"></a><a name="p3376193932611"></a>0</p>
208</td>
209<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p1737613982617"><a name="p1737613982617"></a><a name="p1737613982617"></a>Sending succeeded.</p>
210</td>
211</tr>
212<tr id="row20376143917261"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p2037653913260"><a name="p2037653913260"></a><a name="p2037653913260"></a>SEND_SMS_FAILURE_UNKNOWN</p>
213</td>
214<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p4376139182611"><a name="p4376139182611"></a><a name="p4376139182611"></a>1</p>
215</td>
216<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p153761539102611"><a name="p153761539102611"></a><a name="p153761539102611"></a>Sending failed due to an unknown reason.</p>
217</td>
218</tr>
219<tr id="row163766391268"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p1376239112618"><a name="p1376239112618"></a><a name="p1376239112618"></a>SEND_SMS_FAILURE_RADIO_OFF</p>
220</td>
221<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p1737683972619"><a name="p1737683972619"></a><a name="p1737683972619"></a>2</p>
222</td>
223<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p17376103942619"><a name="p17376103942619"></a><a name="p17376103942619"></a>Sending failed due to modem shutdown.</p>
224</td>
225</tr>
226<tr id="row837613915269"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p143761039162613"><a name="p143761039162613"></a><a name="p143761039162613"></a>SEND_SMS_FAILURE_SERVICE_UNAVAILABLE</p>
227</td>
228<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p1237793992616"><a name="p1237793992616"></a><a name="p1237793992616"></a>3</p>
229</td>
230<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p537743910267"><a name="p537743910267"></a><a name="p537743910267"></a>Sending failed due to unavailable network.</p>
231</td>
232</tr>
233</tbody>
234</table>
235
236**Table  5**  Description of IDeliveryShortMessageCallback types
237
238<a name="table13234515285"></a>
239<table><thead align="left"><tr id="row1432445122815"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p id="p1232134532811"><a name="p1232134532811"></a><a name="p1232134532811"></a>Parameter</p>
240</th>
241<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p id="p1432114502811"><a name="p1432114502811"></a><a name="p1432114502811"></a>Type</p>
242</th>
243<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p id="p123224515283"><a name="p123224515283"></a><a name="p123224515283"></a>Description</p>
244</th>
245</tr>
246</thead>
247<tbody><tr id="row183254532810"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p9331453286"><a name="p9331453286"></a><a name="p9331453286"></a>pdu</p>
248</td>
249<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p333114542810"><a name="p333114542810"></a><a name="p333114542810"></a>Array&lt;number&gt;</p>
250</td>
251<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p1559582618298"><a name="p1559582618298"></a><a name="p1559582618298"></a>PDU array</p>
252</td>
253</tr>
254</tbody>
255</table>
256
257**Table  6**  Parameters of the createMessage API
258
259<a name="table12931820163016"></a>
260<table><thead align="left"><tr id="row8293152043010"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p id="p72931220133012"><a name="p72931220133012"></a><a name="p72931220133012"></a>Parameter</p>
261</th>
262<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p id="p13293172053015"><a name="p13293172053015"></a><a name="p13293172053015"></a>Type</p>
263</th>
264<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p id="p16293162014301"><a name="p16293162014301"></a><a name="p16293162014301"></a>Description</p>
265</th>
266</tr>
267</thead>
268<tbody><tr id="row112937206307"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p13293320193019"><a name="p13293320193019"></a><a name="p13293320193019"></a>pdu</p>
269</td>
270<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p429315201307"><a name="p429315201307"></a><a name="p429315201307"></a>Array&lt;number&gt;</p>
271</td>
272<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p12293102014308"><a name="p12293102014308"></a><a name="p12293102014308"></a>PDU array</p>
273</td>
274</tr>
275<tr id="row6293182012308"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p2293820143020"><a name="p2293820143020"></a><a name="p2293820143020"></a>specification</p>
276</td>
277<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p14293152012301"><a name="p14293152012301"></a><a name="p14293152012301"></a>string</p>
278</td>
279<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p1293420163019"><a name="p1293420163019"></a><a name="p1293420163019"></a>Protocol type (3GPP or 3GPP2)</p>
280</td>
281</tr>
282</tbody>
283</table>
284
285## Usage Guidelines<a name="section170mcpsimp"></a>
286
287### Sending SMS Messages<a name="section172mcpsimp"></a>
288
289The function of sending a common SMS message is used as an example. The process is as follows:
290
2911.  Construct a  **SendMessageOptions**  object with required parameters. If the sending result or delivery report is expected, pass the  **sendCallback**  or  **deliveryCallback**  object.
2922.  Call the  **sendMessage**  API in callback or Promise mode.
2933.  Obtain the sending result. The  **sendMessage**  API works in asynchronous mode. The sending result is returned through the callback.
294
295    ```
296    import sms from "@ohos.telephony.sms";
297
298    let msg: SendMessageOptions = {
299      slotId: 1,
300      destinationHost: '12312312312',
301      content: 'This is an SMS message',
302      sendCallback: (err, data) => {
303        if (err) {
304        // If the API call failed, err is not empty.
305          console.error(`failed to send message because ${err.message}`);
306          return;
307        }
308      // If the API call succeeded, err is empty.
309        console.log(`success to send message: ${data.result}`);
310      }
311    }
312
313    // Call the sendMessage API.
314    sms.sendMessage(msg);
315    ```
316
317
318### Creating a ShortMessage Object<a name="section181mcpsimp"></a>
319
320The function of creating a  **ShortMessage**  object with a 3GPP PDU is used as an example. The process is as follows:
321
3221.  Construct the PDU of the SMS message, with the protocol type set to  **3GPP**  or  **3GPP2**.
3232.  Call the  **createMessage**  API in callback or Promise mode.
3243.  The  **createMessage**  API works in asynchronous mode. After the API is called successfully, parse the  **ShortMessage**  object to obtain the SMS message content.
325
326    ```
327    import sms from "@ohos.telephony.sms";
328
329    let pdu = [80, 80, 80]; // The array indicates the PDU of the SMS message other than a real SMS message.
330    let specification = "3gpp";
331
332    // Call the API in callback mode.
333    sms.createMessage(pdu, specification, (err, value) => {
334      if (err) {
335        // If the API call failed, err is not empty.
336        console.error(`failed to createMessage because ${err.message}`);
337        return;
338      }
339      // If the API call succeeded, err is empty.
340      console.log(`success to createMessage: ${value}`);
341    });
342
343    // Call the API in Promise mode.
344    let promise = sms.createMessage(pdu, specification);
345    promise.then((value) => {
346      // The API call succeeded.
347      console.log(`success to createMessage: ${value}`);
348    }).catch((err) => {
349      // The API call failed.
350      console.error(`failed to createMessage because ${err.message}`);
351    });
352    ```
353
354
355## Repositories Involved<a name="section189mcpsimp"></a>
356
357[Telephony](https://gitee.com/openharmony/docs/blob/master/en/readme/telephony.md)
358
359**telephony_sms_mms**
360
361[telephony_core_service](https://gitee.com/openharmony/telephony_core_service/blob/master/README.md)
362

README_zh.md

1# 短彩信<a name="ZH-CN_TOPIC_0000001105544742"></a>
2
3
4- [简介<a name="section117mcpsimp"></a>](#简介)
5- [目录<a name="section125mcpsimp"></a>](#目录)
6- [约束<a name="section129mcpsimp"></a>](#约束)
7- [接口说明<a name="section134mcpsimp"></a>](#接口说明)
8- [使用说明<a name="section170mcpsimp"></a>](#使用说明)
9  - [发送短信<a name="section172mcpsimp"></a>](#发送短信)
10  - [创建ShortMessage对象<a name="section181mcpsimp"></a>](#创建shortmessage对象)
11- [相关仓<a name="section189mcpsimp"></a>](#相关仓)
12
13## 简介<a name="section117mcpsimp"></a>
14
15短彩信模块为移动数据用户提供短信收发和彩信编解码功能,主要功能有GSM/CDMA短信收发、短信PDU(Protocol data unit,协议数据单元)编解码、Wap Push接收处理 、小区广播接收、彩信通知、 彩信编解码和SIM卡短信记录增删改查等。
16
17**图 1**  短彩信模块架构图<a name="fig420553511549"></a>
18![](figures/zh-cn_architecture-of-the-sms-and-mms-module.png)
19
20短彩信模块由接口管理类、短信发送管理类、短信接收管理类,和彩信编解码工具类组成。其中:
21
22-   接口管理类:SmsInterfaceManager 负责对外提供短信发送、SIM卡短信记录操作和配置相关接口,负责创建SmsSendManager 、SmsReceiveManager和smsMiscManager 对象。
23-   短信发送管理类: SmsSendManager创建GSM\(GsmSmsSender\) 、CDMA\(CdmaSmsSender\) 和网络策略管理(SmsNetworkPolicyManager)对象,并根据网络制式调度对应的GSM或CDMA对象发送短信。
24-   短信接收管理类: SmsReceiveManager 负责短信接收,监听来自RIL层的新短信信息;创建GSM\(GsmSmsReceiveHandler\) 和CDMA\(CdmaSmsReceiveHandler\) 对象;创建SmsWapPushHandler 和SmsCellBroadcastHandler 对象。
25-   彩信编解码类:负责彩信PDU的编解码处理。
26-   Misc管理类:负责Sim卡短信操作、小区广播配置、短信服务中心地址配置和默认卡槽配置等。
27
28## 目录<a name="section125mcpsimp"></a>
29
30```
31/base/telephony/sms_mms
32├─ frameworks               # 短彩信内部框架接口层
33├─ interfaces               # 对外暴露的接口
34│  ├─ innerkits
35│  └─ kits
36├─ sa_profile               # 启动配置文件
37├─ services                 # 服务内部代码
38│  ├─ include               # 头文件目录
39│  ├─ cdma                  # CDMA制式源文件
40│  └─ gsm                   # GSM制式源文件
41├─ test                     # 单元测试目录
42└─ utils                    # 通用工具相关
43```
44
45## 约束<a name="section129mcpsimp"></a>
46
47-   开发语言:JavaScript。
48-   软件约束,需要与以下服务配合使用:Telephony核心服务(core\_service);依赖[glib](https://gitlab.gnome.org/GNOME/glib)库。
49-   硬件约束,需要搭载的设备支持以下硬件:可以进行独立蜂窝通信的Modem以及SIM卡。
50
51## 接口说明<a name="section134mcpsimp"></a>
52
53**表 1**  短彩信对外提供的接口
54
55| 接口名称                                                     | 接口描述                                                     | 所需权限                            |
56| ------------------------------------------------------------ | ------------------------------------------------------------ | ----------------------------------- |
57| function sendMessage(options: SendMessageOptions): void;     | 发送短信,通过callback异步获取短信发送结果。                 | SystemPermission.SEND_MESSAGES      |
58| function createMessage(pdu: Array\<number>, specification: string, callback: AsyncCallback、\<ShortMessage>): void; | 根据协议数据单元(PDU)和指定的短信协议创建短信实例,使用callback方式异步返回创建的短信实例。 | 无                                  |
59| function createMessage(pdu: Array\<number>, specification: string): Promise\<ShortMessage> | 根据协议数据单元(PDU)和指定的短信协议创建短信实例,使用Promise方式异步返回创建的短信实例。 | 无                                  |
60| function getDefaultSmsSlotId(callback: AsyncCallback\<number>): void | 获取发送短信的默认SIM卡槽,使用callback方式异步返回默认SIM卡槽。 | 无                                  |
61| function getDefaultSmsSlotId():Promise\<number>              | 获取发送短信的默认SIM卡,使用Promise方式异步返回默认SIM卡槽。 | 无                                  |
62| function setSmscAddr(slotId: number, smscAddr: string, callback: AsyncCallback\<void>): void | 设置短信服务中心地址,使用callback方式异步返回undefined。    | ohos.permission.SET_TELEPHONY_STATE |
63| function setSmscAddr(slotId: number, smscAddr: string): Promise\<void> | 设置短信服务中心地址,使用Promise方式异步返回undefined。     | ohos.permission.SET_TELEPHONY_STATE |
64| function getSmscAddr(slotId: number, callback: AsyncCallback\<string>): void | 获取短信服务中心地址,使用callback方式异步返回短信服务中心地址。 | ohos.permission.GET_TELEPHONY_STATE |
65| function getSmscAddr(slotId: number): Promise\<string>       | 获取短信服务中心地址,使用Promise方式异步返回短信服务中心地址。 | ohos.permission.GET_TELEPHONY_STATE |
66
67**表 2**  发送短信接口参数SendMessageOptions说明
68
69| 参数             | 类型                                          | 描述             | 是否必填         |
70| ---------------- | --------------------------------------------- | ---------------- | ---------------- |
71| slotId           | number                                        | 卡槽id           | 是               |
72| destinationHost  | string                                        | 接收端的电话号码 | 是               |
73| serviceCenter    | string                                        | 短信中心服务地址 | 否               |
74| content          | content \| Array\<number>                     | 短信内容         | 是               |
75| destinationPort  | number                                        | 接收端端口号     | 发送数据短信必填 |
76| sendCallback     | AsyncCallback\<ISendShortMessageCallback>     | 发送结果回调     | 是               |
77| deliveryCallback | AsyncCallback\<IDeliveryShortMessageCallback> | 送达报告回调     | 是               |
78
79**表 3**  ISendShortMessageCallback类型说明
80
81| 参数       | 类型          | 描述               |
82| ---------- | ------------- | ------------------ |
83| result     | SendSmsResult | 发送结果           |
84| url        | string        | URL地址            |
85| isLastPart | boolean       | 是否是最后一条短信 |
86
87**表 4**  SendSmsResult枚举值
88
89| 名称                                 | 值   | 描述                     |
90| ------------------------------------ | ---- | ------------------------ |
91| SEND_SMS_SUCCESS                     | 0    | 发送成功                 |
92| SEND_SMS_FAILURE_UNKNOWN             | 1    | 发送失败,原因未知       |
93| SEND_SMS_FAILURE_RADIO_OFF           | 2    | 发送失败,因为Modem关闭  |
94| SEND_SMS_FAILURE_SERVICE_UNAVAILABLE | 3    | 发送失败,因为网络不可用 |
95
96**表 5**  IDeliveryShortMessageCallback类型说明
97
98| 参数 | 类型           | 描述                                        |
99| ---- | -------------- | ------------------------------------------- |
100| pdu  | Array\<number> | PDU(Protocol data unit,协议数据单元)数组 |
101
102**表 6**  createMessage接口参数说明
103
104| 参数          | 类型           | 描述                                        |
105| ------------- | -------------- | ------------------------------------------- |
106| pdu           | Array\<number> | PDU(Protocol data unit,协议数据单元)数组 |
107| specification | string         | 协议类型(3gpp或3gpp2)                     |
108
109**表 7**  getDefaultSmsSlotId接口参数说明
110
111| 参数     | 类型                   | 描述                      |
112| -------- | ---------------------- | ------------------------- |
113| callback | AsyncCallback\<number> | 回调函数。0:卡槽1:卡槽2 |
114
115**表 8**  setSmscAddr接口参数说明
116
117| 参数名   | 类型                 | 必填 | 说明                       |
118| -------- | -------------------- | ---- | -------------------------- |
119| slotId   | number               | 是   | SIM卡槽ID:0:卡槽1:卡槽2 |
120| smscAddr | string               | 是   | 短信服务中心(SMSC)地址。 |
121| callback | AsyncCallback\<void> | 是   | 回调函数。                 |
122
123**表 9**  getSmscAddr接口参数说明
124
125| 参数名   | 类型                   | 必填 | 说明                       |
126| -------- | ---------------------- | ---- | -------------------------- |
127| slotId   | number                 | 是   | SIM卡槽ID:0:卡槽1:卡槽2 |
128| callback | AsyncCallback\<string> | 是   | 回调函数。                 |
129
130**表 10**  创建短信异步回调ShortMessage说明
131
132| 变量                     | 类型                                                         | 说明                                                         |
133| ------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
134| emailAddress             | string                                                       | 电子邮件地址。                                               |
135| emailMessageBody         | string                                                       | 电子邮件正文。                                               |
136| hasReplyPath             | boolean                                                      | 收到的短信是否包含“TP-回复路径”,默认为false。“TP-回复路径”:移动电话可循发送SMS消息的短消息中心进行回复。 |
137| isEmailMessage           | boolean                                                      | 收到的短信是否为电子邮件。                                   |
138| isReplaceMessage         | boolean                                                      | 收到的短信是否为“替换短信”,默认为false。“替换短信”有关详细信息,参见 “3GPP TS 23.040 9.2.3.9”。 |
139| isSmsStatusReportMessage | boolean                                                      | 当前消息是否为“短信状态报告”,默认为false。“短信状态报告”是一种特定格式的短信,被用来从Service Center到Mobile Station传送状态报告。 |
140| messageClass             | [ShortMessageClass](https://gitee.com/openharmony/telephony_sms_mms#section141712166453) | 短信类型。                                                   |
141| pdu                      | Array\<number>                                               | SMS消息中的协议数据单元 (PDU)。                            |
142| protocolId               | number                                                       | 发送短信时使用的协议标识。                                   |
143| scAddress                | string                                                       | 短信服务中心(SMSC)地址。                                   |
144| scTimestamp              | number                                                       | SMSC时间戳。                                                 |
145| status                   | number                                                       | SMS-STATUS-REPORT消息中的短信状态指示短信服务中心(SMSC)发送的短信状态。 |
146| userRawData              | Array\<number>                                               | 除协议头部的用户数据,即未解码的短信内容。                   |
147| visibleMessageBody       | string                                                       | 短信正文。                                                   |
148| visibleRawAddress        | string                                                       | 发送者地址。                                                 |
149
150
151完整的JS API说明以及实例代码请参考:[收发短信](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/js-reference/apis/js-apis-sms.md)
152
153## 使用说明<a name="section170mcpsimp"></a>
154
155### 发送短信<a name="section172mcpsimp"></a>
156
157以发送普通文本短信为例,主要步骤和代码如下:
158
1591.  构造SendMessageOptions对象,传入必要的参数;若关注发送结果或送达报告,需要传入sendCallback或deliveryCallback对象。
1602.  可以通过callback或者Promise的方式调用sendMessage接口。
1613.  该接口为异步接口,相关执行结果会从callback中返回。
162
163    ```
164    import sms from "@ohos.telephony.sms";
165
166    let msg: SendMessageOptions = {
167      slotId: 0,
168      destinationHost: '123xxxxxxxx',
169      content: '这是一封短信',
170      sendCallback: (err, data) => {
171        if (err) {
172          // 接口调用失败,err非空
173          console.error(`failed to send message because ${err.message}`);
174          return;
175        }
176        // 接口调用成功,err为空
177        console.log(`success to send message: ${data.result}`);
178      }
179    }
180
181    // 调用接口
182    sms.sendMessage(msg);
183    ```
184
185
186### 创建ShortMessage对象<a name="section181mcpsimp"></a>
187
188以解析3gpp类型的PDU,调用createMessage为例,主要步骤和代码如下:
189
1901.  构造短信的PDU,指定协议类型为3gpp或者3gpp2。
1912.  可以通过callback或者Promise的方式调用createMessage接口。
1923.  该接口为异步接口,成功后获取ShortMessage 对象属性来得到解析后的短信息数据。
193
194    ```
195    import sms from "@ohos.telephony.sms";
196
197    let pdu = [80, 80, 80]; // 这里只是表示是短信PDU,并非真实短信
198    let specification = "3gpp";
199
200    // 调用接口【callback方式】
201    sms.createMessage(pdu, specification, (err, value) => {
202      if (err) {
203        // 接口调用失败,err非空
204        console.error(`failed to createMessage because ${err.message}`);
205        return;
206      }
207      // 接口调用成功,err为空
208      console.log(`success to createMessage: ${value}`);
209    });
210
211    // 调用接口【Promise方式】
212    let promise = sms.createMessage(pdu, specification);
213    promise.then((value) => {
214      // 接口调用成功,此处可以实现成功场景分支代码。
215      console.log(`success to createMessage: ${value}`);
216    }).catch((err) => {
217      // 接口调用失败,此处可以实现失败场景分支代码。
218      console.error(`failed to createMessage because ${err.message}`);
219    });
220    ```
221
222
223## 相关仓<a name="section189mcpsimp"></a>
224
225[电话服务子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E7%94%B5%E8%AF%9D%E6%9C%8D%E5%8A%A1%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
226
227**telephony_sms_mms**
228
229[telephony_core_service](https://gitee.com/openharmony/telephony_core_service/blob/master/README_zh.md)