• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import {AsyncCallback} from "./basic";
17
18/**
19 * Provides the capabilities and methods for obtaining Short Message Service (SMS) management objects.
20 *
21 * @since 6
22 * @syscap SystemCapability.Telephony.SmsMms
23 */
24declare namespace sms {
25  /**
26   * Splits a long SMS message into multiple fragments.
27   *
28   * <p>If the length of an SMS message exceeds the maximum length allowed (140 bytes),
29   *     the SMS message is split into multiple segments for processing.
30   *
31   * @param content Indicates the short message content, which cannot be {@code null}.
32   * @param callback Returns a list of split segments, which can be combined into a complete SMS message;
33   *     returns an empty string if no permission is granted or the short message content is {@code null}.
34   * @permission ohos.permission.SEND_MESSAGES
35   * @systemapi Hide this for inner system use.
36   * @since 8
37   */
38  function splitMessage(content: string, callback: AsyncCallback<Array<string>>): void;
39  function splitMessage(content: string): Promise<Array<string>>;
40
41  /**
42   * Creates an SMS message instance based on the protocol data unit (PDU) and the specified SMS protocol.
43   *
44   * <p>After receiving the original PDU data, the system creates an SMS message instance according to the specified
45   * SMS protocol.
46   *
47   * @param pdu Indicates the original data, which is obtained from the received SMS.
48   * @param specification Indicates the SMS protocol type. The value {@code 3gpp} indicates GSM/UMTS/LTE SMS,
49   *     and the value {@code 3gpp2} indicates CDMA/LTE SMS.
50   * @param callback Returns an SMS message instance; returns {@code null} if {@code pdu} is empty or
51   *     {@code specification} is not supported.
52   */
53  function createMessage(pdu: Array<number>, specification: string, callback: AsyncCallback<ShortMessage>): void;
54  function createMessage(pdu: Array<number>, specification: string): Promise<ShortMessage>;
55
56  /**
57   * Sends a text or data SMS message.
58   *
59   * <p>This method checks whether the length of an SMS message exceeds the maximum length. If the
60   * maximum length is exceeded, the SMS message is split into multiple parts and sent separately.
61   *
62   * @param options Indicates the parameters and callback for sending the SMS message.
63   * @permission ohos.permission.SEND_MESSAGES
64   */
65  function sendMessage(options: SendMessageOptions): void;
66
67  /**
68   * Sets the default SIM card for sending SMS messages. You can obtain the default SIM card by
69   * using {@code getDefaultSmsSlotId}.
70   *
71   * @param slotId Indicates the default SIM card for sending SMS messages. The value {@code 0} indicates card slot 1,
72   *     and the value {@code 1} indicates card slot 2.
73   * @permission ohos.permission.SET_TELEPHONY_STATE
74   * @systemapi Hide this for inner system use.
75   * @since 7
76   */
77  function setDefaultSmsSlotId(slotId: number, callback: AsyncCallback<void>): void;
78  function setDefaultSmsSlotId(slotId: number): Promise<void>;
79
80  /**
81   * Obtains the default SIM card for sending SMS messages.
82   *
83   * @param callback Returns {@code 0} if the default SIM card for sending SMS messages is in card slot 1;
84   *     returns {@code 1} if the default SIM card for sending SMS messages is in card slot 2.
85   * @since 7
86   */
87  function getDefaultSmsSlotId(callback: AsyncCallback<number>): void;
88  function getDefaultSmsSlotId(): Promise<number>;
89
90  /**
91   * Sets the address for the Short Message Service Center (SMSC) based on a specified slot ID.
92   *
93   * @param slotId Indicates the ID of the slot holding the SIM card for sending SMS messages.
94   * @param smscAddr Indicates the SMSC address.
95   * @permission ohos.permission.SET_TELEPHONY_STATE
96   * @systemapi Hide this for inner system use.
97   * @since 7
98   */
99  function setSmscAddr(slotId: number, smscAddr: string, callback: AsyncCallback<void>): void;
100  function setSmscAddr(slotId: number, smscAddr: string): Promise<void>;
101
102  /**
103   * Obtains the SMSC address based on a specified slot ID.
104   *
105   * @param slotId Indicates the ID of the slot holding the SIM card for sending SMS messages.
106   * @param callback Returns the SMSC address.
107   * @permission ohos.permission.GET_TELEPHONY_STATE
108   * @systemapi Hide this for inner system use.
109   * @since 7
110   */
111  function getSmscAddr(slotId: number, callback: AsyncCallback<string>): void;
112  function getSmscAddr(slotId: number): Promise<string>;
113
114  /**
115   * Returns whether a device is capable of sending and receiving SMS messages.
116   *
117   * @return Returns {@code true} if the device is capable of sending and receiving SMS messages;
118   *     returns {@code false} otherwise.
119   * @since 7
120   */
121  function hasSmsCapability(): boolean;
122
123  /**
124   * @permission ohos.permission.RECEIVE_SMS and ohos.permission.SEND_MESSAGES
125   * @systemapi Hide this for inner system use.
126   * @since 7
127   */
128  function addSimMessage(options: SimMessageOptions, callback: AsyncCallback<void>): void;
129  function addSimMessage(options: SimMessageOptions): Promise<void>;
130
131  /**
132   * @permission ohos.permission.RECEIVE_SMS and ohos.permission.SEND_MESSAGES
133   * @systemapi Hide this for inner system use.
134   * @since 7
135   */
136  function delSimMessage(slotId: number, msgIndex: number, callback: AsyncCallback<void>): void;
137  function delSimMessage(slotId: number, msgIndex: number): Promise<void>;
138
139  /**
140   * @permission ohos.permission.RECEIVE_SMS and ohos.permission.SEND_MESSAGES
141   * @systemapi Hide this for inner system use.
142   * @since 7
143   */
144  function updateSimMessage(options: UpdateSimMessageOptions, callback: AsyncCallback<void>): void;
145  function updateSimMessage(options: UpdateSimMessageOptions): Promise<void>;
146
147  /**
148   * @permission ohos.permission.RECEIVE_SMS
149   * @systemapi Hide this for inner system use.
150   * @since 7
151   */
152  function getAllSimMessages(slotId: number, callback: AsyncCallback<Array<SimShortMessage>>): void;
153  function getAllSimMessages(slotId: number): Promise<Array<SimShortMessage>>;
154
155  /**
156   * @permission ohos.permission.RECEIVE_SMS
157   * @systemapi Hide this for inner system use.
158   * @since 7
159   */
160  function setCBConfig(options: CBConfigOptions, callback: AsyncCallback<void>): void;
161  function setCBConfig(options: CBConfigOptions): Promise<void>;
162
163  /**
164   * @systemapi Hide this for inner system use.
165   * @since 8
166   */
167  function getSmsSegmentsInfo(slotId: number, message: string, force7bit: boolean, callback: AsyncCallback<SmsSegmentsInfo>): void;
168  function getSmsSegmentsInfo(slotId: number, message: string, force7bit: boolean): Promise<SmsSegmentsInfo>;
169
170  /**
171   * SMS over IMS is supported if IMS is registered and SMS is supported on IMS.
172   *
173   * @param callback Returns true if SMS over IMS is supported, false otherwise.
174   * @systemapi Hide this for inner system use.
175   * @since 8
176   */
177  function isImsSmsSupported(callback: AsyncCallback<boolean>): void;
178  function isImsSmsSupported(): Promise<boolean>;
179
180  /**
181   * Gets SMS format supported on IMS. SMS over IMS format is either 3GPP or 3GPP2.
182   *
183   * @param callback Returns format, 3gpp, 3gpp2 or unknown.
184   * @systemapi Hide this for inner system use.
185   * @since 8
186   */
187  function getImsShortMessageFormat(callback: AsyncCallback<string>): void;
188  function getImsShortMessageFormat(): Promise<string>;
189
190  /**
191   * @systemapi Hide this for inner system use.
192   * @since 8
193   */
194  function decodeMms(mmsFilePathName: string | Array<number>, callback: AsyncCallback<MmsInformation>): void;
195  function decodeMms(mmsFilePathName: string | Array<number>): Promise<MmsInformation>;
196
197  /**
198   * @systemapi Hide this for inner system use.
199   * @since 8
200   */
201  function encodeMms(mms: MmsInformation, callback: AsyncCallback<Array<number>>): void;
202  function encodeMms(mms: MmsInformation): Promise<Array<number>>;
203
204  /**
205   * @systemapi Hide this for inner system use.
206   * @since 8
207   */
208  export interface MmsInformation {
209    messageType: MessageType;
210    mmsType: MmsSendReq | MmsSendConf | MmsNotificationInd | MmsRespInd | MmsRetrieveConf | MmsAcknowledgeInd | MmsDeliveryInd | MmsReadOrigInd | MmsReadRecInd;
211    attachment?: Array<MmsAttachment>;
212  }
213
214  /**
215   * @systemapi Hide this for inner system use.
216   * @since 8
217   */
218  export interface MmsSendReq {
219    from: MmsAddress;
220    transactionId: string;
221    contentType: string;
222    version: MmsVersionType;
223    to?: Array<MmsAddress>;
224    date?: number;
225    cc?: Array<MmsAddress>;
226    bcc?: Array<MmsAddress>;
227    subject?: string;
228    messageClass?: number;
229    expiry?: number;
230    priority?: MmsPriorityType;
231    senderVisibility?: number;
232    deliveryReport?: number;
233    readReport?: number;
234  }
235
236  /**
237   * @systemapi Hide this for inner system use.
238   * @since 8
239   */
240  export interface MmsSendConf {
241    responseState: number;
242    transactionId: string;
243    version: MmsVersionType;
244    messageId?: string;
245  }
246
247  /**
248   * @systemapi Hide this for inner system use.
249   * @since 8
250   */
251  export interface MmsNotificationInd {
252    transactionId: string;
253    messageClass: number;
254    messageSize: number;
255    expiry: number;
256    contentLocation: string;
257    version: MmsVersionType;
258    from?: MmsAddress;
259    subject?: string;
260    deliveryReport?: number;
261    contentClass?: number;
262  }
263
264  /**
265   * @systemapi Hide this for inner system use.
266   * @since 8
267   */
268  export interface MmsRespInd {
269    transactionId: string;
270    status: number;
271    version: MmsVersionType;
272    reportAllowed?: ReportType;
273  }
274
275  /**
276   * @systemapi Hide this for inner system use.
277   * @since 8
278   */
279  export interface MmsRetrieveConf {
280    transactionId: string;
281    messageId: string;
282    date: number;
283    contentType: string;
284    to: Array<MmsAddress>;
285    version: MmsVersionType;
286    from?: MmsAddress;
287    cc?: Array<MmsAddress>;
288    subject?: string;
289    priority?: MmsPriorityType;
290    deliveryReport?: number;
291    readReport?: number;
292    retrieveStatus?: number;
293    retrieveText?: string;
294  }
295
296  /**
297   * @systemapi Hide this for inner system use.
298   * @since 8
299   */
300  export interface MmsAcknowledgeInd {
301    transactionId: string;
302    version: MmsVersionType;
303    reportAllowed?: ReportType;
304  }
305
306  /**
307   * @systemapi Hide this for inner system use.
308   * @since 8
309   */
310  export interface MmsDeliveryInd {
311    messageId: string;
312    date: number;
313    to: Array<MmsAddress>;
314    status: number;
315    version: MmsVersionType;
316  }
317
318  /**
319   * @systemapi Hide this for inner system use.
320   * @since 8
321   */
322  export interface MmsReadOrigInd {
323    version: MmsVersionType;
324    messageId: string;
325    to: Array<MmsAddress>;
326    from: MmsAddress;
327    date: number;
328    readStatus: number;
329  }
330
331  /**
332   * @systemapi Hide this for inner system use.
333   * @since 8
334   */
335  export interface MmsReadRecInd {
336    version: MmsVersionType;
337    messageId: string;
338    to: Array<MmsAddress>;
339    from: MmsAddress;
340    readStatus: number;
341    date?: number;
342  }
343
344  /**
345   * @systemapi Hide this for inner system use.
346   * @since 8
347   */
348  export interface MmsAttachment {
349    contentId: string;
350    contentLocation: string;
351    contentDisposition: DispositionType;
352    contentTransferEncoding: string;
353    contentType: string;
354    isSmil: boolean;
355    path?: string;
356    inBuff?: Array<number>;
357    fileName?: string;
358    charset?: MmsCharSets;
359  }
360
361  /**
362   * @systemapi Hide this for inner system use.
363   * @since 8
364   */
365  export interface MmsAddress {
366    address: string;
367    charset: MmsCharSets;
368  }
369
370  /**
371   * @systemapi Hide this for inner system use.
372   * @since 8
373   */
374  export enum MessageType {
375    TYPE_MMS_SEND_REQ = 128,
376    TYPE_MMS_SEND_CONF,
377    TYPE_MMS_NOTIFICATION_IND,
378    TYPE_MMS_RESP_IND,
379    TYPE_MMS_RETRIEVE_CONF,
380    TYPE_MMS_ACKNOWLEDGE_IND,
381    TYPE_MMS_DELIVERY_IND,
382    TYPE_MMS_READ_REC_IND,
383    TYPE_MMS_READ_ORIG_IND,
384  }
385
386  /**
387   * @systemapi Hide this for inner system use.
388   * @since 8
389   */
390  export enum MmsPriorityType {
391    MMS_LOW = 128,
392    MMS_NORMAL,
393    MMS_HIGH,
394  }
395
396  /**
397   * @systemapi Hide this for inner system use.
398   * @since 8
399   */
400  export enum MmsVersionType {
401    MMS_VERSION_1_0 = 0x10,
402    MMS_VERSION_1_1,
403    MMS_VERSION_1_2,
404    MMS_VERSION_1_3,
405  }
406
407  /**
408   * @systemapi Hide this for inner system use.
409   * @since 8
410   */
411  export enum MmsCharSets {
412    BIG5 = 0X07EA,
413    ISO_10646_UCS_2 = 0X03E8,
414    ISO_8859_1 = 0X04,
415    ISO_8859_2,
416    ISO_8859_3,
417    ISO_8859_4,
418    ISO_8859_5,
419    ISO_8859_6,
420    ISO_8859_7,
421    ISO_8859_8,
422    ISO_8859_9,
423    SHIFT_JIS = 0X11,
424    US_ASCII = 0X03,
425    UTF_8 = 0X6A,
426  }
427
428  /**
429   * @systemapi Hide this for inner system use.
430   * @since 8
431   */
432  export enum DispositionType {
433    FROM_DATA = 0,
434    ATTACHMENT,
435    INLINE,
436  }
437
438  /**
439   * @systemapi Hide this for inner system use.
440   * @since 8
441   */
442  export enum ReportType {
443    MMS_YES = 128,
444    MMS_NO,
445  }
446
447  /**
448   * @systemapi Hide this for inner system use.
449   * @since 7
450   */
451  export interface CBConfigOptions {
452    slotId: number;
453    enable: boolean;
454    startMessageId: number;
455    endMessageId: number;
456    ranType: RanType;
457  }
458
459  /**
460   * @systemapi Hide this for inner system use.
461   * @since 7
462   */
463  export interface SimMessageOptions {
464    slotId: number;
465    smsc: string;
466    pdu: string;
467    status: SimMessageStatus;
468  }
469
470  /**
471   * @systemapi Hide this for inner system use.
472   * @since 7
473   */
474  export interface UpdateSimMessageOptions {
475    slotId: number;
476    msgIndex: number;
477    newStatus: SimMessageStatus;
478    pdu: string;
479    smsc: string;
480  }
481
482  export interface ShortMessage {
483    /** Indicates the SMS message body. */
484    visibleMessageBody: string;
485    /** Indicates the address of the sender, which is to be displayed on the UI. */
486    visibleRawAddress: string;
487    /** Indicates the SMS type. */
488    messageClass: ShortMessageClass;
489    /** Indicates the protocol identifier. */
490    protocolId: number;
491    /** Indicates the short message service center (SMSC) address. */
492    scAddress: string;
493    /** Indicates the SMSC timestamp. */
494    scTimestamp: number;
495    /** Indicates whether the received SMS is a "replace short message". */
496    isReplaceMessage: boolean;
497    /** Indicates whether the received SMS contains "TP-Reply-Path". */
498    hasReplyPath: boolean;
499    /** Indicates Protocol Data Units (PDUs) from an SMS message. */
500    pdu: Array<number>;
501    /**
502     * Indicates the SMS message status from the SMS-STATUS-REPORT message sent by the
503     * Short Message Service Center (SMSC).
504     */
505    status: number;
506    /** Indicates whether the current message is SMS-STATUS-REPORT. */
507    isSmsStatusReportMessage: boolean;
508  }
509
510  /**
511   * @systemapi Hide this for inner system use.
512   * @since 7
513   */
514  export interface SimShortMessage {
515    shortMessage: ShortMessage;
516
517    /** Indicates the storage status of SMS messages in the SIM */
518    simMessageStatus: SimMessageStatus;
519    /** Indicates the index of SMS messages in the SIM */
520    indexOnSim: number;
521  }
522
523  /**
524   * @systemapi Hide this for inner system use.
525   * @since 7
526   */
527  export enum SimMessageStatus {
528    /** status free space ON SIM */
529    SIM_MESSAGE_STATUS_FREE = 0,
530    /** REC READ received read message */
531    SIM_MESSAGE_STATUS_READ = 1,
532    /** REC UNREAD received unread message */
533    SIM_MESSAGE_STATUS_UNREAD = 3,
534    /** STO SENT stored sent message (only applicable to SMs) */
535    SIM_MESSAGE_STATUS_SENT = 5,
536    /** STO UNSENT stored unsent message (only applicable to SMs) */
537    SIM_MESSAGE_STATUS_UNSENT = 7,
538  }
539
540  export enum ShortMessageClass {
541    /** Indicates an unknown type. */
542    UNKNOWN,
543    /** Indicates an instant message, which is displayed immediately after being received. */
544    INSTANT_MESSAGE,
545    /** Indicates an SMS message that can be stored on the device or SIM card based on the storage status. */
546    OPTIONAL_MESSAGE,
547    /** Indicates an SMS message containing SIM card information, which is to be stored in a SIM card. */
548    SIM_MESSAGE,
549    /** Indicates an SMS message to be forwarded to another device. */
550    FORWARD_MESSAGE
551  }
552
553  export interface SendMessageOptions {
554    /** Indicates the ID of the SIM card slot used for sending the SMS message. */
555    slotId: number;
556    /** Indicates the address to which the SMS message is sent. */
557    destinationHost: string;
558    /** Indicates the SMSC address. If the value is {@code null}, the default SMSC address of the SIM card*/
559    serviceCenter?: string;
560    /** If the content is a string, this is a short message. If the content is a byte array, this is a data message. */
561    content: string | Array<number>;
562    /** If send data message, destinationPort is mandatory. Otherwise is optional. */
563    destinationPort?: number;
564    /** Indicates the callback invoked after the SMS message is sent. */
565    sendCallback?: AsyncCallback<ISendShortMessageCallback>;
566    /** Indicates the callback invoked after the SMS message is delivered. */
567    deliveryCallback?: AsyncCallback<IDeliveryShortMessageCallback>;
568  }
569
570  export interface ISendShortMessageCallback {
571    /** Indicates the SMS message sending result. */
572    result: SendSmsResult;
573    /** Indicates the URI to store the sent SMS message. */
574    url: string;
575    /** Specifies whether this is the last part of a multi-part SMS message. */
576    isLastPart: boolean;
577  }
578
579  export interface IDeliveryShortMessageCallback {
580    /** Indicates the SMS delivery report. */
581    pdu: Array<number>;
582  }
583
584  export enum SendSmsResult {
585    /**
586     * Indicates that the SMS message is successfully sent.
587     */
588    SEND_SMS_SUCCESS = 0,
589
590    /**
591     * Indicates that sending the SMS message fails due to an unknown reason.
592     */
593    SEND_SMS_FAILURE_UNKNOWN = 1,
594
595    /**
596     * Indicates that sending the SMS fails because the modem is powered off.
597     */
598    SEND_SMS_FAILURE_RADIO_OFF = 2,
599
600    /**
601     * Indicates that sending the SMS message fails because the network is unavailable
602     * or does not support sending or reception of SMS messages.
603     */
604    SEND_SMS_FAILURE_SERVICE_UNAVAILABLE = 3
605  }
606
607  /**
608   * @systemapi Hide this for inner system use.
609   * @since 7
610   */
611  export enum RanType {
612    TYPE_GSM = 1, // GSM
613    TYPE_CDMA = 2, // CDMA
614  }
615
616  /**
617   * @systemapi Hide this for inner system use.
618   * @since 8
619   */
620  export interface SmsSegmentsInfo {
621    splitCount: number;
622    encodeCount: number;
623    encodeCountRemaining: number;
624    scheme: SmsEncodingScheme;
625  }
626
627  /**
628   * @systemapi Hide this for inner system use.
629   * @since 8
630   */
631  export enum SmsEncodingScheme {
632    SMS_ENCODING_UNKNOWN = 0,
633    SMS_ENCODING_7BIT,
634    SMS_ENCODING_8BIT,
635    SMS_ENCODING_16BIT,
636  }
637}
638
639export default sms;