1/* 2* Copyright (C) 2021 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.Telephony 23 */ 24declare namespace sms { 25 /** 26 * Creates an SMS message instance based on the protocol data unit (PDU) and the specified SMS protocol. 27 * 28 * <p>After receiving the original PDU data, the system creates an SMS message instance according to the specified 29 * SMS protocol. 30 * 31 * @param pdu Indicates the original data, which is obtained from the received SMS. 32 * @param specification Indicates the SMS protocol type. The value {@code 3gpp} indicates GSM/UMTS/LTE SMS, 33 * and the value {@code 3gpp2} indicates CDMA/LTE SMS. 34 * @param callback Returns an SMS message instance; returns {@code null} if {@code pdu} is empty or 35 * {@code specification} is not supported. 36 */ 37 function createMessage(pdu: Array<number>, specification: string, callback: AsyncCallback<ShortMessage>): void; 38 function createMessage(pdu: Array<number>, specification: string): Promise<ShortMessage>; 39 40 /** 41 * Sends a text or data SMS message. 42 * 43 * <p>This method checks whether the length of an SMS message exceeds the maximum length. If the 44 * maximum length is exceeded, the SMS message is split into multiple parts and sent separately. 45 * <p>You need to obtain the following permission before calling this method: 46 * {@code ohos.permission.SEND_MESSAGES} 47 * 48 * @param options Indicates the parameters and callback for sending the SMS message. 49 * @permission ohos.permission.SEND_MESSAGES 50 */ 51 function sendMessage(options: SendMessageOptions): void; 52 53 /** 54 * Sets the default SIM card for sending SMS messages. You can obtain the default SIM card by 55 * using {@code getDefaultSmsSlotId}. 56 * 57 * @param slotId Indicates the default SIM card for sending SMS messages. The value {@code 0} indicates card slot 1, 58 * and the value {@code 1} indicates card slot 2. 59 * @permission ohos.permission.SET_TELEPHONY_STATE 60 * @systemapi Hide this for inner system use. 61 * @since 7 62 */ 63 function setDefaultSmsSlotId(slotId: number, callback: AsyncCallback<void>): void; 64 function setDefaultSmsSlotId(slotId: number): Promise<void>; 65 66 /** 67 * Obtains the default SIM card for sending SMS messages. 68 * 69 * @param callback Returns {@code 0} if the default SIM card for sending SMS messages is in card slot 1; 70 * returns {@code 1} if the default SIM card for sending SMS messages is in card slot 2. 71 * @since 7 72 */ 73 function getDefaultSmsSlotId(callback: AsyncCallback<number>): void; 74 function getDefaultSmsSlotId(): Promise<number>; 75 76 /** 77 * Sets the address for the Short Message Service Center (SMSC) based on a specified slot ID. 78 * 79 * <p><b>Permissions: </b>{@link ohos.security.SystemPermission#SET_TELEPHONY_STATE} 80 * 81 * @param slotId Indicates the ID of the slot holding the SIM card for sending SMS messages. 82 * @param smscAddr Indicates the SMSC address. 83 * @permission ohos.permission.SET_TELEPHONY_STATE 84 * @since 7 85 */ 86 function setSmscAddr(slotId: number, smscAddr: string, callback: AsyncCallback<void>): void; 87 function setSmscAddr(slotId: number, smscAddr: string): Promise<void>; 88 89 /** 90 * Obtains the SMSC address based on a specified slot ID. 91 * 92 * <p><b>Permissions: </b>{@link ohos.security.SystemPermission#GET_TELEPHONY_STATE} 93 * 94 * @param slotId Indicates the ID of the slot holding the SIM card for sending SMS messages. 95 * @param callback Returns the SMSC address. 96 * @permission ohos.permission.GET_TELEPHONY_STATE 97 * @since 7 98 */ 99 function getSmscAddr(slotId: number, callback: AsyncCallback<string>): void; 100 function getSmscAddr(slotId: number): Promise<string>; 101 102 /** 103 * @permission ohos.permission.RECEIVE_SMS,ohos.permission.SEND_MESSAGES 104 * @systemapi Hide this for inner system use. 105 * @since 7 106 */ 107 function addSimMessage(options: SimMessageOptions, callback: AsyncCallback<void>): void; 108 function addSimMessage(options: SimMessageOptions): Promise<void>; 109 110 /** 111 * @permission ohos.permission.RECEIVE_SMS,ohos.permission.SEND_MESSAGES 112 * @systemapi Hide this for inner system use. 113 * @since 7 114 */ 115 function delSimMessage(slotId: number, msgIndex: number, callback: AsyncCallback<void>): void; 116 function delSimMessage(slotId: number, msgIndex: number): Promise<void>; 117 118 /** 119 * @permission ohos.permission.RECEIVE_SMS,ohos.permission.SEND_MESSAGES 120 * @systemapi Hide this for inner system use. 121 * @since 7 122 */ 123 function updateSimMessage(options: UpdateSimMessageOptions, callback: AsyncCallback<void>): void; 124 function updateSimMessage(options: UpdateSimMessageOptions): Promise<void>; 125 126 /** 127 * @permission ohos.permission.RECEIVE_SMS 128 * @systemapi Hide this for inner system use. 129 * @since 7 130 */ 131 function getAllSimMessages(slotId: number, callback: AsyncCallback<Array<SimShortMessage>>): void; 132 function getAllSimMessages(slotId: number): Promise<Array<SimShortMessage>>; 133 134 /** 135 * @permission ohos.permission.RECEIVE_SMS 136 * @systemapi Hide this for inner system use. 137 * @since 7 138 */ 139 function setCBConfig(options: CBConfigOptions, callback: AsyncCallback<void>): void; 140 function setCBConfig(options: CBConfigOptions): Promise<void>; 141 142 /** 143 * @systemapi Hide this for inner system use. 144 * @since 7 145 */ 146 export interface CBConfigOptions { 147 slotId: number, 148 enable: boolean, 149 startMessageId: number, 150 endMessageId: number, 151 ranType: number 152 } 153 154 /** 155 * @systemapi Hide this for inner system use. 156 * @since 7 157 */ 158 export interface SimMessageOptions { 159 slotId: number, 160 smsc: string, 161 pdu: string, 162 status: SimMessageStatus 163 } 164 165 /** 166 * @systemapi Hide this for inner system use. 167 * @since 7 168 */ 169 export interface UpdateSimMessageOptions { 170 slotId: number, 171 msgIndex: number, 172 newStatus: SimMessageStatus, 173 pdu: string, 174 smsc: string 175 } 176 177 export interface ShortMessage { 178 /** Indicates the SMS message body. */ 179 visibleMessageBody: string; 180 /** Indicates the address of the sender, which is to be displayed on the UI. */ 181 visibleRawAddress: string; 182 /** Indicates the SMS type. */ 183 messageClass: ShortMessageClass; 184 /** Indicates the protocol identifier. */ 185 protocolId: number; 186 /** Indicates the short message service center (SMSC) address. */ 187 scAddress: string; 188 /** Indicates the SMSC timestamp. */ 189 scTimestamp: number; 190 /** Indicates whether the received SMS is a "replace short message". */ 191 isReplaceMessage: boolean; 192 /** Indicates whether the received SMS contains "TP-Reply-Path". */ 193 hasReplyPath: boolean; 194 /** Indicates Protocol Data Units (PDUs) from an SMS message. */ 195 pdu: Array<number>; 196 /** 197 * Indicates the SMS message status from the SMS-STATUS-REPORT message sent by the 198 * Short Message Service Center (SMSC). 199 */ 200 status: number; 201 /** Indicates whether the current message is SMS-STATUS-REPORT. */ 202 isSmsStatusReportMessage: boolean; 203 } 204 205 /** 206 * @systemapi Hide this for inner system use. 207 * @since 7 208 */ 209 export interface SimShortMessage { 210 shortMessage: ShortMessage; 211 212 /** Indicates the storage status of SMS messages in the SIM */ 213 simMessageStatus: SimMessageStatus; 214 /** Indicates the index of SMS messages in the SIM */ 215 indexOnSim: number; 216 } 217 218 /** 219 * @systemapi Hide this for inner system use. 220 * @since 7 221 */ 222 export enum SimMessageStatus { 223 /** status free space ON SIM */ 224 SIM_MESSAGE_STATUS_FREE = 0, 225 /** REC READ received read message */ 226 SIM_MESSAGE_STATUS_READ = 1, 227 /** REC UNREAD received unread message */ 228 SIM_MESSAGE_STATUS_UNREAD = 3, 229 /** STO SENT stored sent message (only applicable to SMs) */ 230 SIM_MESSAGE_STATUS_SENT = 5, 231 /** STO UNSENT stored unsent message (only applicable to SMs) */ 232 SIM_MESSAGE_STATUS_UNSENT = 7, 233 } 234 235 export enum ShortMessageClass { 236 /** Indicates an unknown type. */ 237 UNKNOWN, 238 /** Indicates an instant message, which is displayed immediately after being received. */ 239 INSTANT_MESSAGE, 240 /** Indicates an SMS message that can be stored on the device or SIM card based on the storage status. */ 241 OPTIONAL_MESSAGE, 242 /** Indicates an SMS message containing SIM card information, which is to be stored in a SIM card. */ 243 SIM_MESSAGE, 244 /** Indicates an SMS message to be forwarded to another device. */ 245 FORWARD_MESSAGE 246 } 247 248 export interface SendMessageOptions { 249 /** Indicates the ID of the SIM card slot used for sending the SMS message. */ 250 slotId: number; 251 /** Indicates the address to which the SMS message is sent. */ 252 destinationHost: string; 253 /** Indicates the SMSC address. If the value is {@code null}, the default SMSC address of the SIM card*/ 254 serviceCenter?: string; 255 /** If the content is a string, this is a short message. If the content is a byte array, this is a data message. */ 256 content: string | Array<number>; 257 /** If send data message, destinationPort is mandatory. Otherwise is optional. */ 258 destinationPort?: number; 259 /** Indicates the callback invoked after the SMS message is sent. */ 260 sendCallback?: AsyncCallback<ISendShortMessageCallback>; 261 /** Indicates the callback invoked after the SMS message is delivered. */ 262 deliveryCallback?: AsyncCallback<IDeliveryShortMessageCallback>; 263 } 264 265 export interface ISendShortMessageCallback { 266 /** Indicates the SMS message sending result. */ 267 result: SendSmsResult; 268 /** Indicates the URI to store the sent SMS message. */ 269 url: string; 270 /** Specifies whether this is the last part of a multi-part SMS message. */ 271 isLastPart: boolean; 272 } 273 274 export interface IDeliveryShortMessageCallback { 275 /** Indicates the SMS delivery report. */ 276 pdu: Array<number>; 277 } 278 279 export enum SendSmsResult { 280 /** 281 * Indicates that the SMS message is successfully sent. 282 */ 283 SEND_SMS_SUCCESS = 0, 284 285 /** 286 * Indicates that sending the SMS message fails due to an unknown reason. 287 */ 288 SEND_SMS_FAILURE_UNKNOWN = 1, 289 290 /** 291 * Indicates that sending the SMS fails because the modem is powered off. 292 */ 293 SEND_SMS_FAILURE_RADIO_OFF = 2, 294 295 /** 296 * Indicates that sending the SMS message fails because the network is unavailable 297 * or does not support sending or reception of SMS messages. 298 */ 299 SEND_SMS_FAILURE_SERVICE_UNAVAILABLE = 3 300 } 301} 302 303export default sms; 304