• Home
Name Date Size #Lines LOC

..--

figures/07-Sep-2024-

frameworks/07-Sep-2024-14,31911,630

interfaces/07-Sep-2024-6,8401,507

sa_profile/07-Sep-2024-3633

services/07-Sep-2024-28,01022,737

test/07-Sep-2024-23,17118,413

utils/07-Sep-2024-1,7811,474

BUILD.gnD07-Sep-20245.9 KiB167156

LICENSED07-Sep-20249.9 KiB177150

OAT.xmlD07-Sep-20245.7 KiB8332

README.mdD07-Sep-202423.5 KiB363319

README_zh.mdD07-Sep-202419.7 KiB347281

bundle.jsonD07-Sep-20242.4 KiB8381

README.md

1# SMS and MMS<a name="EN-US_TOPIC_0000001105544742"></a>
2
3
4## Introduction<a name="section117mcpsimp"></a>
5
6The 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.
7
8**Figure  1**  Architecture of the SMS and MMS module<a name="fig420553511549"></a>
9![](figures/en-us_architecture-of-the-sms-and-mms-module.png)
10
11The SMS and MMS module consists of the following parts:
12
13-   SmsInterfaceManager: provides external APIs for sending SMS messages and managing SIM SMS records. It can be used to create  **SmsSendManager**  and  **SmsReceiveManager**  objects.
14-   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.
15-   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.
16-   MmsPduProcessor: encodes and decodes MMS PDUs.
17-   ImsSmsClient: sends IMS SMS messages, and sets and obtains IMS SMS configuration information.
18
19## Directory Structure<a name="section125mcpsimp"></a>
20
21```
22/base/telephony/sms_mms
23├─ common                       # Common code
24├─ figures                      # Figures of readme files
25├─ frameworks                   # Frameworks
26│  ├─ js                        # JS code
27│  └─ native                    # Native code
28├─ interfaces                   # APIs
29│  ├─ innerkits                 # Internal APIs
30│  │ └─  ims                    # IMS SMS service APIs
31│  └─ kits                      # External APIs (such as JS APIs)
32├─ sa_profile                   # SA profile
33├─ services                     # IMS service code (for SMS and MMS)
34│  ├─ ims_service_interaction   # IMS service interaction (for SMS and MMS)
35│  ├─ include                   # Header files
36│  ├─ cdma                      # CDMA-specific source files
37│  └─ gsm                       # GSM-specific source files
38├─ test                         # Unit test code
39│  ├─ fuzztest                  # Fuzzy test
40│  ├─ gtest                     # Automated test
41│  └─ unittest                  # Unit test
42└─ utils                        # Utilities
43```
44
45## Constraints<a name="section129mcpsimp"></a>
46
47-   Programming language: JavaScript
48-   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).
49-   In terms of hardware, the accommodating device must be equipped with a modem and a SIM card capable of independent cellular communication.
50
51## Available APIs<a name="section134mcpsimp"></a>
52
53**Table  1**  External APIs provided by the SMS and MMS module
54
55<a name="table136mcpsimp"></a>
56<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>
57</th>
58<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>
59</th>
60<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>
61</th>
62</tr>
63</thead>
64<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>
65</td>
66<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>
67</td>
68<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>
69</td>
70</tr>
71<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>
72</td>
73<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>
74</td>
75<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>
76</td>
77</tr>
78</tbody>
79</table>
80
81**Table  2**  Parameter description of SendMessageOptions
82
83<a name="table137771821149"></a>
84<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>
85</th>
86<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>
87</th>
88<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>
89</th>
90<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>
91</th>
92</tr>
93</thead>
94<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>
95</td>
96<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>
97</td>
98<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>
99</td>
100<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>
101</td>
102</tr>
103<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>
104</td>
105<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>
106</td>
107<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>
108</td>
109<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>
110</td>
111</tr>
112<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>
113</td>
114<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>
115</td>
116<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>
117</td>
118<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>
119</td>
120</tr>
121<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>
122</td>
123<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>
124</td>
125<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>
126</td>
127<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>
128</td>
129</tr>
130<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>
131</td>
132<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>
133</td>
134<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>
135</td>
136<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>
137</td>
138</tr>
139<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>
140</td>
141<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>
142</td>
143<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>
144</td>
145<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>
146</td>
147</tr>
148<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>
149</td>
150<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>
151</td>
152<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>
153</td>
154<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>
155</td>
156</tr>
157</tbody>
158</table>
159
160**Table  3**  Description of ISendShortMessageCallback types
161
162<a name="table6490122972417"></a>
163<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>
164</th>
165<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>
166</th>
167<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>
168</th>
169</tr>
170</thead>
171<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>
172</td>
173<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>
174</td>
175<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>
176</td>
177</tr>
178<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>
179</td>
180<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>
181</td>
182<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>
183</td>
184</tr>
185<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>
186</td>
187<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>
188</td>
189<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>
190</td>
191</tr>
192</tbody>
193</table>
194
195**Table  4**  Description of SendSmsResult enum values
196
197<a name="table2375639122617"></a>
198<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>
199</th>
200<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>
201</th>
202<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>
203</th>
204</tr>
205</thead>
206<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>
207</td>
208<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>
209</td>
210<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>
211</td>
212</tr>
213<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>
214</td>
215<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>
216</td>
217<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>
218</td>
219</tr>
220<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>
221</td>
222<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>
223</td>
224<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>
225</td>
226</tr>
227<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>
228</td>
229<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>
230</td>
231<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>
232</td>
233</tr>
234</tbody>
235</table>
236
237**Table  5**  Description of IDeliveryShortMessageCallback types
238
239<a name="table13234515285"></a>
240<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>
241</th>
242<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>
243</th>
244<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>
245</th>
246</tr>
247</thead>
248<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>
249</td>
250<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>
251</td>
252<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>
253</td>
254</tr>
255</tbody>
256</table>
257
258**Table  6**  Parameters of the createMessage API
259
260<a name="table12931820163016"></a>
261<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>
262</th>
263<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>
264</th>
265<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>
266</th>
267</tr>
268</thead>
269<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>
270</td>
271<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>
272</td>
273<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>
274</td>
275</tr>
276<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>
277</td>
278<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>
279</td>
280<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>
281</td>
282</tr>
283</tbody>
284</table>
285
286## Usage Guidelines<a name="section170mcpsimp"></a>
287
288### Sending SMS Messages<a name="section172mcpsimp"></a>
289
290The function of sending a common SMS message is used as an example. The process is as follows:
291
2921.  Construct a  **SendMessageOptions**  object with required parameters. If the sending result or delivery report is expected, pass the  **sendCallback**  or  **deliveryCallback**  object.
2932.  Call the  **sendMessage**  API in callback or Promise mode.
2943.  Obtain the sending result. The  **sendMessage**  API works in asynchronous mode. The sending result is returned through the callback.
295
296    ```
297    import sms from "@ohos.telephony.sms";
298
299    let msg: SendMessageOptions = {
300      slotId: 1,
301      destinationHost: '12312312312',
302      content: 'This is an SMS message',
303      sendCallback: (err, data) => {
304        if (err) {
305        // If the API call failed, err is not empty.
306          console.error(`failed to send message because ${err.message}`);
307          return;
308        }
309      // If the API call succeeded, err is empty.
310        console.log(`success to send message: ${data.result}`);
311      }
312    }
313
314    // Call the sendMessage API.
315    sms.sendMessage(msg);
316    ```
317
318
319### Creating a ShortMessage Object<a name="section181mcpsimp"></a>
320
321The function of creating a  **ShortMessage**  object with a 3GPP PDU is used as an example. The process is as follows:
322
3231.  Construct the PDU of the SMS message, with the protocol type set to  **3GPP**  or  **3GPP2**.
3242.  Call the  **createMessage**  API in callback or Promise mode.
3253.  The  **createMessage**  API works in asynchronous mode. After the API is called successfully, parse the  **ShortMessage**  object to obtain the SMS message content.
326
327    ```
328    import sms from "@ohos.telephony.sms";
329
330    let pdu = [80, 80, 80]; // The array indicates the PDU of the SMS message other than a real SMS message.
331    let specification = "3gpp";
332
333    // Call the API in callback mode.
334    sms.createMessage(pdu, specification, (err, value) => {
335      if (err) {
336        // If the API call failed, err is not empty.
337        console.error(`failed to createMessage because ${err.message}`);
338        return;
339      }
340      // If the API call succeeded, err is empty.
341      console.log(`success to createMessage: ${value}`);
342    });
343
344    // Call the API in Promise mode.
345    let promise = sms.createMessage(pdu, specification);
346    promise.then((value) => {
347      // The API call succeeded.
348      console.log(`success to createMessage: ${value}`);
349    }).catch((err) => {
350      // The API call failed.
351      console.error(`failed to createMessage because ${err.message}`);
352    });
353    ```
354
355
356## Repositories Involved<a name="section189mcpsimp"></a>
357
358[Telephony](https://gitee.com/openharmony/docs/blob/master/en/readme/telephony.md)
359
360**telephony_sms_mms**
361
362[telephony_core_service](https://gitee.com/openharmony/telephony_core_service/blob/master/README.md)
363

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-   IMS短信管理类:ImsSmsClient 负责IMS短信发送,及设置/获取IMS短信配置信息。
28
29## 目录<a name="section125mcpsimp"></a>
30
31```
32/base/telephony/sms_mms
33├─ common                       # 内部公共代码
34├─ figures                      # Readme资源文件
35├─ frameworks                   # 短彩信内部框架接口层
36│  ├─ js                        # js相关代码
37│  └─ native                    # native相关代码
38├─ interfaces                   # 接口目录
39│  ├─ innerkits                 # 部件间的内部接口
40│  │ └─  ims                    # IMS短信接口定义
41│  └─ kits                      # 对应用提供的接口(例如JS接口)
42├─ sa_profile                   # 短信服务的启动文件目录
43├─ services                     # 短彩信服务实现代码
44│  ├─ ims_service_interaction   # IMS短信服务交互层
45│  ├─ include                   # 头文件目录
46│  ├─ cdma                      # CDMA制式源文件
47│  └─ gsm                       # GSM制式源文件
48├─ test                         # 单元测试目录
49│  ├─ fuzztest                  # 模糊测试相关代码
50│  ├─ gtest                     # 自动化测试相关代码
51│  └─ unittest                  # 单元测试相关代码
52└─ utils                        # 通用工具相关
53```
54
55## 约束<a name="section129mcpsimp"></a>
56
57-   开发语言:JavaScript。
58-   软件约束,需要与以下服务配合使用:Telephony核心服务(core\_service);依赖[glib](https://gitlab.gnome.org/GNOME/glib)库。
59-   硬件约束,需要搭载的设备支持以下硬件:可以进行独立蜂窝通信的Modem以及SIM卡。
60
61## 接口说明<a name="section134mcpsimp"></a>
62
63**表 1**  短彩信对外提供的接口
64
65| 接口名称                                                     | 接口描述                                                     | 所需权限                            |
66| ------------------------------------------------------------ | ------------------------------------------------------------ | ----------------------------------- |
67| function sendMessage(options: SendMessageOptions): void;     | 发送短信,通过callback异步获取短信发送结果。                 | SystemPermission.SEND_MESSAGES      |
68| function createMessage(pdu: Array\<number>, specification: string, callback: AsyncCallback、\<ShortMessage>): void; | 根据协议数据单元(PDU)和指定的短信协议创建短信实例,使用callback方式异步返回创建的短信实例。 | 无                                  |
69| function createMessage(pdu: Array\<number>, specification: string): Promise\<ShortMessage> | 根据协议数据单元(PDU)和指定的短信协议创建短信实例,使用Promise方式异步返回创建的短信实例。 | 无                                  |
70| function getDefaultSmsSlotId(callback: AsyncCallback\<number>): void | 获取发送短信的默认SIM卡槽,使用callback方式异步返回默认SIM卡槽。 | 无                                  |
71| function getDefaultSmsSlotId():Promise\<number>              | 获取发送短信的默认SIM卡,使用Promise方式异步返回默认SIM卡槽。 | 无                                  |
72| function getDefaultSmsSimId(callback: AsyncCallback\<number>): void | 获取发送短信的默认SIM卡ID,使用callback方式异步返回默认SIM卡槽。 | 无                                  |
73| function getDefaultSmsSimId():Promise\<number>              | 获取发送短信的默认SIM卡ID,使用Promise方式异步返回默认SIM卡槽。 | 无                                  |
74| function setSmscAddr(slotId: number, smscAddr: string, callback: AsyncCallback\<void>): void | 设置短信服务中心地址,使用callback方式异步返回undefined。    | ohos.permission.SET_TELEPHONY_STATE |
75| function setSmscAddr(slotId: number, smscAddr: string): Promise\<void> | 设置短信服务中心地址,使用Promise方式异步返回undefined。     | ohos.permission.SET_TELEPHONY_STATE |
76| function getSmscAddr(slotId: number, callback: AsyncCallback\<string>): void | 获取短信服务中心地址,使用callback方式异步返回短信服务中心地址。 | ohos.permission.GET_TELEPHONY_STATE |
77| function getSmscAddr(slotId: number): Promise\<string>       | 获取短信服务中心地址,使用Promise方式异步返回短信服务中心地址。 | ohos.permission.GET_TELEPHONY_STATE |
78
79**表 2**  发送短信接口参数SendMessageOptions说明
80
81| 参数             | 类型                                          | 描述             | 是否必填         |
82| ---------------- | --------------------------------------------- | ---------------- | ---------------- |
83| slotId           | number                                        | 卡槽id           | 是               |
84| destinationHost  | string                                        | 接收端的电话号码 | 是               |
85| serviceCenter    | string                                        | 短信中心服务地址 | 否               |
86| content          | content \| Array\<number>                     | 短信内容         | 是               |
87| destinationPort  | number                                        | 接收端端口号     | 发送数据短信必填 |
88| sendCallback     | AsyncCallback\<ISendShortMessageCallback>     | 发送结果回调     | 是               |
89| deliveryCallback | AsyncCallback\<IDeliveryShortMessageCallback> | 送达报告回调     | 是               |
90
91**表 3**  ISendShortMessageCallback类型说明
92
93| 参数       | 类型          | 描述               |
94| ---------- | ------------- | ------------------ |
95| result     | SendSmsResult | 发送结果           |
96| url        | string        | URL地址            |
97| isLastPart | boolean       | 是否是最后一条短信 |
98
99**表 4**  SendSmsResult枚举值
100
101| 名称                                 | 值   | 描述                     |
102| ------------------------------------ | ---- | ------------------------ |
103| SEND_SMS_SUCCESS                     | 0    | 发送成功                 |
104| SEND_SMS_FAILURE_UNKNOWN             | 1    | 发送失败,原因未知       |
105| SEND_SMS_FAILURE_RADIO_OFF           | 2    | 发送失败,因为Modem关闭  |
106| SEND_SMS_FAILURE_SERVICE_UNAVAILABLE | 3    | 发送失败,因为网络不可用 |
107
108**表 5**  IDeliveryShortMessageCallback类型说明
109
110| 参数 | 类型           | 描述                                        |
111| ---- | -------------- | ------------------------------------------- |
112| pdu  | Array\<number> | PDU(Protocol data unit,协议数据单元)数组 |
113
114**表 6**  createMessage接口参数说明
115
116| 参数          | 类型           | 描述                                        |
117| ------------- | -------------- | ------------------------------------------- |
118| pdu           | Array\<number> | PDU(Protocol data unit,协议数据单元)数组 |
119| specification | string         | 协议类型(3gpp或3gpp2)                     |
120
121**表 7**  getDefaultSmsSlotId接口参数说明
122
123| 参数     | 类型                   | 描述                      |
124| -------- | ---------------------- | ------------------------- |
125| callback | AsyncCallback\<number> | 回调函数。0:卡槽1:卡槽2 |
126
127**表 8**  setSmscAddr接口参数说明
128
129| 参数名   | 类型                 | 必填 | 说明                       |
130| -------- | -------------------- | ---- | -------------------------- |
131| slotId   | number               | 是   | SIM卡槽ID:0:卡槽1:卡槽2 |
132| smscAddr | string               | 是   | 短信服务中心(SMSC)地址。 |
133| callback | AsyncCallback\<void> | 是   | 回调函数。                 |
134
135**表 9**  getSmscAddr接口参数说明
136
137| 参数名   | 类型                   | 必填 | 说明                       |
138| -------- | ---------------------- | ---- | -------------------------- |
139| slotId   | number                 | 是   | SIM卡槽ID:0:卡槽1:卡槽2 |
140| callback | AsyncCallback\<string> | 是   | 回调函数。                 |
141
142**表 10**  创建短信异步回调ShortMessage说明
143
144| 变量                     | 类型                                                         | 说明                                                         |
145| ------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
146| emailAddress             | string                                                       | 电子邮件地址。                                               |
147| emailMessageBody         | string                                                       | 电子邮件正文。                                               |
148| hasReplyPath             | boolean                                                      | 收到的短信是否包含“TP-回复路径”,默认为false。“TP-回复路径”:移动电话可循发送SMS消息的短消息中心进行回复。 |
149| isEmailMessage           | boolean                                                      | 收到的短信是否为电子邮件。                                   |
150| isReplaceMessage         | boolean                                                      | 收到的短信是否为“替换短信”,默认为false。“替换短信”有关详细信息,参见 “3GPP TS 23.040 9.2.3.9”。 |
151| isSmsStatusReportMessage | boolean                                                      | 当前消息是否为“短信状态报告”,默认为false。“短信状态报告”是一种特定格式的短信,被用来从Service Center到Mobile Station传送状态报告。 |
152| messageClass             | [ShortMessageClass](https://gitee.com/openharmony/telephony_sms_mms#section141712166453) | 短信类型。                                                   |
153| pdu                      | Array\<number>                                               | SMS消息中的协议数据单元 (PDU)。                            |
154| protocolId               | number                                                       | 发送短信时使用的协议标识。                                   |
155| scAddress                | string                                                       | 短信服务中心(SMSC)地址。                                   |
156| scTimestamp              | number                                                       | SMSC时间戳。                                                 |
157| status                   | number                                                       | SMS-STATUS-REPORT消息中的短信状态指示短信服务中心(SMSC)发送的短信状态。 |
158| userRawData              | Array\<number>                                               | 除协议头部的用户数据,即未解码的短信内容。                   |
159| visibleMessageBody       | string                                                       | 短信正文。                                                   |
160| visibleRawAddress        | string                                                       | 发送者地址。                                                 |
161
162**表 11**  getDefaultSmsSimId接口参数说明
163
164| 参数     | 类型                   | 描述                      |
165| -------- | ---------------------- | ------------------------- |
166| callback | AsyncCallback\<number> | 回调函数。 |
167
168完整的JS API说明以及实例代码请参考:[收发短信](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-sms.md)
169
170## 使用说明<a name="section170mcpsimp"></a>
171
172### 发送短信<a name="section172mcpsimp"></a>
173
174以发送普通文本短信为例,主要步骤和代码如下:
175
1761.  构造SendMessageOptions对象,传入必要的参数;若关注发送结果或送达报告,需要传入sendCallback或deliveryCallback对象。
1772.  可以通过callback或者Promise的方式调用sendMessage接口。
1783.  该接口为异步接口,相关执行结果会从callback中返回。
179
180    ```
181    import sms from "@ohos.telephony.sms";
182
183    let msg: SendMessageOptions = {
184      slotId: 0,
185      destinationHost: '123xxxxxxxx',
186      content: '这是一封短信',
187      sendCallback: (err, data) => {
188        if (err) {
189          // 接口调用失败,err非空
190          console.error(`failed to send message because ${err.message}`);
191          return;
192        }
193        // 接口调用成功,err为空
194        console.log(`success to send message: ${data.result}`);
195      }
196    }
197
198    // 调用接口
199    sms.sendMessage(msg);
200    ```
201
202
203### 创建ShortMessage对象<a name="section181mcpsimp"></a>
204
205以解析3gpp类型的PDU,调用createMessage为例,主要步骤和代码如下:
206
2071.  构造短信的PDU,指定协议类型为3gpp或者3gpp2。
2082.  可以通过callback或者Promise的方式调用createMessage接口。
2093.  该接口为异步接口,成功后获取ShortMessage 对象属性来得到解析后的短信息数据。
210
211    ```
212    import sms from "@ohos.telephony.sms";
213
214    let pdu = [80, 80, 80]; // 这里只是表示是短信PDU,并非真实短信
215    let specification = "3gpp";
216
217    // 调用接口【callback方式】
218    sms.createMessage(pdu, specification, (err, value) => {
219      if (err) {
220        // 接口调用失败,err非空
221        console.error(`failed to createMessage because ${err.message}`);
222        return;
223      }
224      // 接口调用成功,err为空
225      console.log(`success to createMessage: ${value}`);
226    });
227
228    // 调用接口【Promise方式】
229    let promise = sms.createMessage(pdu, specification);
230    promise.then((value) => {
231      // 接口调用成功,此处可以实现成功场景分支代码。
232      console.log(`success to createMessage: ${value}`);
233    }).catch((err) => {
234      // 接口调用失败,此处可以实现失败场景分支代码。
235      console.error(`failed to createMessage because ${err.message}`);
236    });
237    ```
238
239### 发送彩信<a name="section172mcpsimp"></a>
240
241以中国联通SIM卡发送彩信为例,主要步骤和代码如下:
242
2431.  发送彩信,需要先编码再发送。
2442.  编码:将多媒体文件编码成彩信pdu。app将多媒体文件放入沙箱,调用编码接口encodeMms,app传入必要参数,返回的彩信pdu需要app写入沙箱
2453.  发送:将彩信pdu发送到对端手机。调用发送接口sendMms,app需传入必要参数,彩信中心需和运营商卡匹配。
2464.  可以通过callback或者Promise的方式调用sendMessage接口。
2475.  该接口为异步接口,相关执行结果会从callback中返回。
248
249    ```
250    import mms from "@ohos.telephony.sms";
251
252    // 获取MmsType,输入本机号码,目的手机号码
253    async function getMmstype(tid){
254      return {
255        from : {address: '+86xxxxxxxxxxx/TYPE=PLMN', charset: mms.UTF_8},
256        to: [{address: '+86xxxxxxxxxxx/TYPE=PLMN', charset: mms.UTF_8}],
257        contentType: "application/vnd.wap.multipart.related",
258        transactionId: tid,
259        version: mms.MMS_VERSION_1_2,
260        subject: "Test mms"
261      };
262    }
263    let MMSTYPE = await getMmstype("1");
264
265    // 只包括图片附件,图片名字picture.gif
266    const ATTACHMENT_PICTURE = [
267      {path: sandPath + 'picture.gif',
268        fileName: 'picture.gif',
269        contentId:'<picture.gif>',
270        contentLocation:'picture.gif',
271        contentDisposition: mms.ATTACHMENT,
272        contentTransferEncoding: 'binary',
273        contentType:'image/gif',
274        isSmil: false,
275        inBuff: [],
276        charset: mms.UTF_8
277      }
278    ];
279
280    // 编码彩信pdu
281    const wrapperStepForEncodeMms = async function (mmsType, attachment) {
282      try {
283        // 调用编码接口
284        const encodeData = await mms.encodeMms({messageType: mms.TYPE_MMS_SEND_REQ, mmsType, attachment});
285        console.log(`encodeMms Success, data length:${encodeData.length}`);
286        await writefd(casename, encodeData);
287      } catch (error) {
288        throw error;
289      }
290    };
291
292    // 进行彩信pdu编码,编码前将图片放入沙箱
293    try {
294      await wrapperStepForEncodeMms(MMSTYPE, ATTACHMENT_PICTURE);
295      console.log(`wrapperStepForEncodeMms success.`);
296    } catch (error) {
297      console.log(`wrapperStepForEncodeMms fail, error: ${toString(error)}`);
298      return;
299    }
300
301    const sandBoxPath = '/data/storage/el2/base/files/';
302    let filePath  = sandBoxPath + 'SendReq.mms';
303    // 彩信pdu写入沙箱
304    async function writefd(array){
305      let data = new Uint8Array(array).buffer;
306      try {
307        let fd = await fileio.open(filePath , 0o102, 0o666);
308        console.log(`fd: ${toString(fd)}`);
309        const number = await fileio.write(fd, data);
310        console.log(`write data to file success number: ${toString(number)}`);
311        await fileio.close(fd);
312      } catch (error) {
313        console.log(`write data to file failed with error: ${toString(error)}`);
314      }
315    }
316
317    // 彩信用户代理、用户代理描述配置。根据运营商要求配置,默认ua,uaprof
318    let mmsCfg = {
319      userAgent:'ua',
320      userAgentProfile: 'uaprof'
321    };
322
323    // 发送彩信参数
324    let mmsParams = {
325      slotId : DEFAULT_SLOTID,
326      mmsc: 'http://mmsc.myuni.com.cn',
327      data: filePath,
328      mmsConfig: mmsCfg
329    };
330    // 调用发送接口
331    mms.sendMms(globalThis.context, mmsParams, async(err) =>{
332      if (err) {
333        console.log(`sendMms fail, err : ${toString(err)}`);
334        return;
335      }
336      console.log(`sendMms Success`);
337    }
338    ```
339
340## 相关仓<a name="section189mcpsimp"></a>
341
342[电话服务子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/电话服务子系统.md)
343
344**telephony_sms_mms**
345
346[telephony_core_service](https://gitee.com/openharmony/telephony_core_service/blob/master/README_zh.md)
347