1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.service.carrier; 18 19 import android.annotation.FlaggedApi; 20 import android.annotation.IntDef; 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.annotation.SdkConstant; 24 import android.app.Service; 25 import android.content.Intent; 26 import android.net.Uri; 27 import android.os.IBinder; 28 import android.os.RemoteException; 29 30 import com.android.internal.telephony.flags.Flags; 31 32 import java.lang.annotation.Retention; 33 import java.lang.annotation.RetentionPolicy; 34 import java.util.List; 35 36 /** 37 * A service that receives calls from the system when new SMS and MMS are 38 * sent or received. 39 * <p>To extend this class, you must declare the service in your manifest file with 40 * the {@link android.Manifest.permission#BIND_CARRIER_SERVICES} permission 41 * and include an intent filter with the {@link #SERVICE_INTERFACE} action. For example:</p> 42 * <pre> 43 * <service android:name=".MyMessagingService" 44 * android:label="@string/service_name" 45 * android:permission="android.permission.BIND_CARRIER_SERVICES"> 46 * <intent-filter> 47 * <action android:name="android.service.carrier.CarrierMessagingService" /> 48 * </intent-filter> 49 * </service></pre> 50 */ 51 public abstract class CarrierMessagingService extends Service { 52 /** 53 * The {@link android.content.Intent} that must be declared as handled by the service. 54 */ 55 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) 56 public static final String SERVICE_INTERFACE 57 = "android.service.carrier.CarrierMessagingService"; 58 59 /** 60 * The default bitmask value passed to the callback of {@link #onReceiveTextSms} with all 61 * {@code RECEIVE_OPTIONS_x} flags cleared to indicate that the message should be kept and a 62 * new message notification should be shown. 63 * 64 * @see #RECEIVE_OPTIONS_DROP 65 * @see #RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_PROTECTED_STORAGE_UNAVAILABLE 66 */ 67 public static final int RECEIVE_OPTIONS_DEFAULT = 0; 68 69 /** 70 * Used to set the flag in the bitmask passed to the callback of {@link #onReceiveTextSms} to 71 * indicate that the inbound SMS should be dropped. 72 */ 73 public static final int RECEIVE_OPTIONS_DROP = 0x1; 74 75 /** 76 * Used to set the flag in the bitmask passed to the callback of {@link #onReceiveTextSms} to 77 * indicate that a new message notification should not be shown to the user when the 78 * credential-encrypted storage of the device is not available before the user unlocks the 79 * phone. It is only applicable to devices that support file-based encryption. 80 */ 81 public static final int RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_PROTECTED_STORAGE_UNAVAILABLE = 0x2; 82 83 /** @hide */ 84 @IntDef(flag = true, prefix = { "RECEIVE_OPTIONS_" }, value = { 85 RECEIVE_OPTIONS_DEFAULT, 86 RECEIVE_OPTIONS_DROP, 87 RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_PROTECTED_STORAGE_UNAVAILABLE 88 }) 89 @Retention(RetentionPolicy.SOURCE) 90 public @interface FilterCompleteResult{} 91 92 /** 93 * Indicates that an SMS or MMS message was successfully sent. 94 */ 95 public static final int SEND_STATUS_OK = 0; 96 97 /** 98 * SMS/MMS sending failed. We should retry via the carrier network. 99 */ 100 public static final int SEND_STATUS_RETRY_ON_CARRIER_NETWORK = 1; 101 102 /** 103 * SMS/MMS sending failed due to an unspecified issue. Sending will not be retried via the 104 * carrier network. 105 * 106 * <p>Maps to SmsManager.RESULT_RIL_GENERIC_FAILURE for SMS and SmsManager.MMS_ERROR_UNSPECIFIED 107 * for MMS. 108 */ 109 public static final int SEND_STATUS_ERROR = 2; 110 111 /** 112 * More precise error reasons for outbound SMS send requests. These will not be retried on the 113 * carrier network. 114 * 115 * <p>Each code maps directly to an SmsManager code (e.g. SEND_STATS_RESULT_ERROR_NULL_PDU maps 116 * to SmsManager.RESULT_ERROR_NULL_PDU). 117 */ 118 119 /** 120 * Generic failure cause. 121 * 122 * @see android.telephony.SmsManager.RESULT_ERROR_GENERIC_FAILURE 123 */ 124 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 125 public static final int SEND_STATUS_RESULT_ERROR_GENERIC_FAILURE = 200; 126 127 /** 128 * Failed because no pdu provided. 129 * 130 * @see android.telephony.SmsManager.RESULT_ERROR_NULL_PDU 131 */ 132 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 133 public static final int SEND_STATUS_RESULT_ERROR_NULL_PDU = 201; 134 135 /** 136 * Failed because service is currently unavailable. 137 * 138 * @see android.telephony.SmsManager.RESULT_ERROR_NO_SERVICE 139 */ 140 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 141 public static final int SEND_STATUS_RESULT_ERROR_NO_SERVICE = 202; 142 143 /** 144 * Failed because we reached the sending queue limit. 145 * 146 * @see android.telephony.SmsManager.RESULT_ERROR_LIMIT_EXCEEDED 147 */ 148 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 149 public static final int SEND_STATUS_RESULT_ERROR_LIMIT_EXCEEDED = 203; 150 151 /** 152 * Failed because FDN is enabled. 153 * 154 * @see android.telephony.SmsManager.RESULT_ERROR_FDN_CHECK_FAILURE 155 */ 156 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 157 public static final int SEND_STATUS_RESULT_ERROR_FDN_CHECK_FAILURE = 204; 158 159 /** 160 * Failed because user denied the sending of this short code. 161 * 162 * @see android.telephony.SmsManager.RESULT_ERROR_SHORT_CODE_NOT_ALLOWED 163 */ 164 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 165 public static final int SEND_STATUS_RESULT_ERROR_SHORT_CODE_NOT_ALLOWED = 205; 166 167 /** 168 * Failed because the user has denied this app ever send premium short codes. 169 * 170 * @see android.telephony.SmsManager.RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED 171 */ 172 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 173 public static final int SEND_STATUS_RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED = 206; 174 175 /** 176 * Failed because of network rejection. 177 * 178 * @see android.telephony.SmsManager.RESULT_NETWORK_REJECT 179 */ 180 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 181 public static final int SEND_STATUS_RESULT_NETWORK_REJECT = 207; 182 183 /** 184 * Failed because of invalid arguments. 185 * 186 * @see android.telephony.SmsManager.RESULT_INVALID_ARGUMENTS 187 */ 188 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 189 public static final int SEND_STATUS_RESULT_INVALID_ARGUMENTS = 208; 190 191 /** 192 * Failed because of an invalid state. 193 * 194 * @see android.telephony.SmsManager.RESULT_INVALID_STATE 195 */ 196 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 197 public static final int SEND_STATUS_RESULT_INVALID_STATE = 209; 198 199 /** 200 * Failed because the sms format is not valid. 201 * 202 * @see android.telephony.SmsManager.RESULT_INVALID_SMS_FORMAT 203 */ 204 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 205 public static final int SEND_STATUS_RESULT_INVALID_SMS_FORMAT = 210; 206 207 /** 208 * Failed because of a network error. 209 * 210 * @see android.telephony.SmsManager.RESULT_NETWORK_ERROR 211 */ 212 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 213 public static final int SEND_STATUS_RESULT_NETWORK_ERROR = 211; 214 215 /** 216 * Failed because of an encoding error. 217 * 218 * @see android.telephony.SmsManager.RESULT_ENCODING_ERROR 219 */ 220 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 221 public static final int SEND_STATUS_RESULT_ENCODING_ERROR = 212; 222 223 /** 224 * Failed because of an invalid smsc address 225 * 226 * @see android.telephony.SmsManager.RESULT_INVALID_SMSC_ADDRESS 227 */ 228 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 229 public static final int SEND_STATUS_RESULT_INVALID_SMSC_ADDRESS = 213; 230 231 /** 232 * Failed because the operation is not allowed. 233 * 234 * @see android.telephony.SmsManager.RESULT_OPERATION_NOT_ALLOWED 235 */ 236 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 237 public static final int SEND_STATUS_RESULT_OPERATION_NOT_ALLOWED = 214; 238 239 /** 240 * Failed because the operation was cancelled. 241 * 242 * @see android.telephony.SmsManager.RESULT_CANCELLED 243 */ 244 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 245 public static final int SEND_STATUS_RESULT_CANCELLED = 215; 246 247 /** 248 * Failed because the request is not supported. 249 * 250 * @see android.telephony.SmsManager.RESULT_REQUEST_NOT_SUPPORTED 251 */ 252 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 253 public static final int SEND_STATUS_RESULT_REQUEST_NOT_SUPPORTED = 216; 254 255 /** 256 * Failed sending during an emergency call. 257 * 258 * @see android.telephony.SmsManager.RESULT_SMS_BLOCKED_DURING_EMERGENCY 259 */ 260 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 261 public static final int SEND_STATUS_RESULT_SMS_BLOCKED_DURING_EMERGENCY = 217; 262 263 /** 264 * Failed to send an sms retry. 265 * 266 * @see android.telephony.SmsManager.RESULT_SMS_SEND_RETRY_FAILED 267 */ 268 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 269 public static final int SEND_STATUS_RESULT_SMS_SEND_RETRY_FAILED = 218; 270 271 /** 272 * More precise error reasons for outbound MMS send requests. These will not be retried on the 273 * carrier network. 274 * 275 * <p>Each code maps directly to an SmsManager code (e.g. 276 * SEND_STATUS_MMS_ERROR_UNABLE_CONNECT_MMS maps to SmsManager.MMS_ERROR_UNABLE_CONNECT_MMS). 277 */ 278 279 /** 280 * Unspecific MMS error occurred during send. 281 * 282 * @see android.telephony.SmsManager.MMS_ERROR_UNSPECIFIED 283 */ 284 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 285 public static final int SEND_STATUS_MMS_ERROR_UNSPECIFIED = 400; 286 287 /** 288 * ApnException occurred during MMS network setup. 289 * 290 * @see android.telephony.SmsManager.MMS_ERROR_INVALID_APN 291 */ 292 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 293 public static final int SEND_STATUS_MMS_ERROR_INVALID_APN = 401; 294 295 /** 296 * An error occurred during the MMS connection setup. 297 * 298 * @see android.telephony.SmsManager.MMS_ERROR_UNABLE_CONNECT_MMS 299 */ 300 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 301 public static final int SEND_STATUS_MMS_ERROR_UNABLE_CONNECT_MMS = 402; 302 303 /** 304 * An error occurred during the HTTP client setup. 305 * 306 * @see android.telephony.SmsManager.MMS_ERROR_HTTP_FAILURE 307 */ 308 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 309 public static final int SEND_STATUS_MMS_ERROR_HTTP_FAILURE = 403; 310 311 /** 312 * An I/O error occurred reading the PDU. 313 * 314 * @see android.telephony.SmsManager.MMS_ERROR_IO_ERROR 315 */ 316 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 317 public static final int SEND_STATUS_MMS_ERROR_IO_ERROR = 404; 318 319 /** 320 * An error occurred while retrying sending the MMS. 321 * 322 * @see android.telephony.SmsManager.MMS_ERROR_RETRY 323 */ 324 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 325 public static final int SEND_STATUS_MMS_ERROR_RETRY = 405; 326 327 /** 328 * The carrier-dependent configuration values could not be loaded. 329 * 330 * @see android.telephony.SmsManager.MMS_ERROR_CONFIGURATION_ERROR 331 */ 332 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 333 public static final int SEND_STATUS_MMS_ERROR_CONFIGURATION_ERROR = 406; 334 335 /** 336 * There is neither Wi-Fi nor mobile data network. 337 * 338 * @see android.telephony.SmsManager.MMS_ERROR_NO_DATA_NETWORK 339 */ 340 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 341 public static final int SEND_STATUS_MMS_ERROR_NO_DATA_NETWORK = 407; 342 343 /** 344 * The subscription id for the send is invalid. 345 * 346 * @see android.telephony.SmsManager.MMS_ERROR_INVALID_SUBSCRIPTION_ID 347 */ 348 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 349 public static final int SEND_STATUS_MMS_ERROR_INVALID_SUBSCRIPTION_ID = 408; 350 351 /** 352 * The subscription id for the send is inactive. 353 * 354 * @see android.telephony.SmsManager.MMS_ERROR_INACTIVE_SUBSCRIPTION 355 */ 356 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 357 public static final int SEND_STATUS_MMS_ERROR_INACTIVE_SUBSCRIPTION = 409; 358 359 /** 360 * Data is disabled for the MMS APN. 361 * 362 * @see android.telephony.SmsManager.MMS_ERROR_DATA_DISABLED 363 */ 364 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 365 public static final int SEND_STATUS_MMS_ERROR_DATA_DISABLED = 410; 366 367 /** 368 * MMS is disabled by a carrier. 369 * 370 * @see android.telephony.SmsManager.MMS_ERROR_MMS_DISABLED_BY_CARRIER 371 */ 372 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 373 public static final int SEND_STATUS_MMS_ERROR_MMS_DISABLED_BY_CARRIER = 411; 374 375 /** @hide */ 376 @IntDef( 377 prefix = {"SEND_STATUS_"}, 378 value = { 379 SEND_STATUS_OK, 380 SEND_STATUS_RETRY_ON_CARRIER_NETWORK, 381 SEND_STATUS_ERROR, 382 SEND_STATUS_RESULT_ERROR_GENERIC_FAILURE, 383 SEND_STATUS_RESULT_ERROR_NULL_PDU, 384 SEND_STATUS_RESULT_ERROR_NO_SERVICE, 385 SEND_STATUS_RESULT_ERROR_LIMIT_EXCEEDED, 386 SEND_STATUS_RESULT_ERROR_FDN_CHECK_FAILURE, 387 SEND_STATUS_RESULT_ERROR_SHORT_CODE_NOT_ALLOWED, 388 SEND_STATUS_RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED, 389 SEND_STATUS_RESULT_NETWORK_REJECT, 390 SEND_STATUS_RESULT_INVALID_ARGUMENTS, 391 SEND_STATUS_RESULT_INVALID_STATE, 392 SEND_STATUS_RESULT_INVALID_SMS_FORMAT, 393 SEND_STATUS_RESULT_NETWORK_ERROR, 394 SEND_STATUS_RESULT_ENCODING_ERROR, 395 SEND_STATUS_RESULT_INVALID_SMSC_ADDRESS, 396 SEND_STATUS_RESULT_OPERATION_NOT_ALLOWED, 397 SEND_STATUS_RESULT_CANCELLED, 398 SEND_STATUS_RESULT_REQUEST_NOT_SUPPORTED, 399 SEND_STATUS_RESULT_SMS_BLOCKED_DURING_EMERGENCY, 400 SEND_STATUS_RESULT_SMS_SEND_RETRY_FAILED, 401 SEND_STATUS_MMS_ERROR_UNSPECIFIED, 402 SEND_STATUS_MMS_ERROR_INVALID_APN, 403 SEND_STATUS_MMS_ERROR_UNABLE_CONNECT_MMS, 404 SEND_STATUS_MMS_ERROR_HTTP_FAILURE, 405 SEND_STATUS_MMS_ERROR_IO_ERROR, 406 SEND_STATUS_MMS_ERROR_RETRY, 407 SEND_STATUS_MMS_ERROR_CONFIGURATION_ERROR, 408 SEND_STATUS_MMS_ERROR_NO_DATA_NETWORK, 409 SEND_STATUS_MMS_ERROR_INVALID_SUBSCRIPTION_ID, 410 SEND_STATUS_MMS_ERROR_INACTIVE_SUBSCRIPTION, 411 SEND_STATUS_MMS_ERROR_DATA_DISABLED, 412 SEND_STATUS_MMS_ERROR_MMS_DISABLED_BY_CARRIER 413 }) 414 @Retention(RetentionPolicy.SOURCE) 415 public @interface SendResult {} 416 417 /** 418 * Successfully downloaded an MMS message. 419 */ 420 public static final int DOWNLOAD_STATUS_OK = 0; 421 422 /** 423 * MMS downloading failed. We should retry via the carrier network. 424 */ 425 public static final int DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK = 1; 426 427 /** 428 * MMS downloading failed due to an unspecified issue. Downloading will not be retried via the 429 * carrier network. 430 * 431 * <p>Maps to SmsManager.MMR_ERROR_UNSPECIFIED. 432 */ 433 public static final int DOWNLOAD_STATUS_ERROR = 2; 434 435 /** 436 * More precise error reasons for inbound MMS download requests. These will not be retried on 437 * the carrier network. 438 * 439 * <p>Each code maps directly to an SmsManager code (e.g. 440 * DOWNLOAD_STATUS_MMS_ERROR_UNABLE_CONNECT_MMS maps to 441 * SmsManager.MMS_ERROR_UNABLE_CONNECT_MMS). 442 */ 443 444 /** 445 * Unspecific MMS error occurred during download. 446 * 447 * @see android.telephony.SmsManager.MMS_ERROR_UNSPECIFIED 448 */ 449 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 450 public static final int DOWNLOAD_STATUS_MMS_ERROR_UNSPECIFIED = 600; 451 452 /** 453 * ApnException occurred during MMS network setup. 454 * 455 * @see android.telephony.SmsManager.MMS_ERROR_INVALID_APN 456 */ 457 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 458 public static final int DOWNLOAD_STATUS_MMS_ERROR_INVALID_APN = 601; 459 460 /** 461 * An error occurred during the MMS connection setup. 462 * 463 * @see android.telephony.SmsManager.MMS_ERROR_UNABLE_CONNECT_MMS 464 */ 465 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 466 public static final int DOWNLOAD_STATUS_MMS_ERROR_UNABLE_CONNECT_MMS = 602; 467 468 /** 469 * An error occurred during the HTTP client setup. 470 * 471 * @see android.telephony.SmsManager.MMS_ERROR_HTTP_FAILURE 472 */ 473 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 474 public static final int DOWNLOAD_STATUS_MMS_ERROR_HTTP_FAILURE = 603; 475 476 /** 477 * An I/O error occurred reading the PDU. 478 * 479 * @see android.telephony.SmsManager.MMS_ERROR_IO_ERROR 480 */ 481 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 482 public static final int DOWNLOAD_STATUS_MMS_ERROR_IO_ERROR = 604; 483 484 /** 485 * An error occurred while retrying downloading the MMS. 486 * 487 * @see android.telephony.SmsManager.MMS_ERROR_RETRY 488 */ 489 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 490 public static final int DOWNLOAD_STATUS_MMS_ERROR_RETRY = 605; 491 492 /** 493 * The carrier-dependent configuration values could not be loaded. 494 * 495 * @see android.telephony.SmsManager.MMS_ERROR_CONFIGURATION_ERROR 496 */ 497 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 498 public static final int DOWNLOAD_STATUS_MMS_ERROR_CONFIGURATION_ERROR = 606; 499 500 /** 501 * There is neither Wi-Fi nor mobile data network. 502 * 503 * @see android.telephony.SmsManager.MMS_ERROR_NO_DATA_NETWORK 504 */ 505 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 506 public static final int DOWNLOAD_STATUS_MMS_ERROR_NO_DATA_NETWORK = 607; 507 508 /** 509 * The subscription id for the download is invalid. 510 * 511 * @see android.telephony.SmsManager.MMS_ERROR_INVALID_SUBSCRIPTION_ID 512 */ 513 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 514 public static final int DOWNLOAD_STATUS_MMS_ERROR_INVALID_SUBSCRIPTION_ID = 608; 515 516 /** 517 * The subscription id for the download is inactive. 518 * 519 * @see android.telephony.SmsManager.MMS_ERROR_INACTIVE_SUBSCRIPTION 520 */ 521 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 522 public static final int DOWNLOAD_STATUS_MMS_ERROR_INACTIVE_SUBSCRIPTION = 609; 523 524 /** 525 * Data is disabled for the MMS APN. 526 * 527 * @see android.telephony.SmsManager.MMS_ERROR_DATA_DISABLED 528 */ 529 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 530 public static final int DOWNLOAD_STATUS_MMS_ERROR_DATA_DISABLED = 610; 531 532 /** 533 * MMS is disabled by a carrier. 534 * 535 * @see android.telephony.SmsManager.MMS_ERROR_MMS_DISABLED_BY_CARRIER 536 */ 537 @FlaggedApi(Flags.FLAG_TEMPORARY_FAILURES_IN_CARRIER_MESSAGING_SERVICE) 538 public static final int DOWNLOAD_STATUS_MMS_ERROR_MMS_DISABLED_BY_CARRIER = 611; 539 540 /** @hide */ 541 @IntDef( 542 prefix = {"DOWNLOAD_STATUS_"}, 543 value = { 544 DOWNLOAD_STATUS_OK, 545 DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK, 546 DOWNLOAD_STATUS_ERROR, 547 DOWNLOAD_STATUS_MMS_ERROR_UNSPECIFIED, 548 DOWNLOAD_STATUS_MMS_ERROR_INVALID_APN, 549 DOWNLOAD_STATUS_MMS_ERROR_UNABLE_CONNECT_MMS, 550 DOWNLOAD_STATUS_MMS_ERROR_HTTP_FAILURE, 551 DOWNLOAD_STATUS_MMS_ERROR_IO_ERROR, 552 DOWNLOAD_STATUS_MMS_ERROR_RETRY, 553 DOWNLOAD_STATUS_MMS_ERROR_CONFIGURATION_ERROR, 554 DOWNLOAD_STATUS_MMS_ERROR_NO_DATA_NETWORK, 555 DOWNLOAD_STATUS_MMS_ERROR_INVALID_SUBSCRIPTION_ID, 556 DOWNLOAD_STATUS_MMS_ERROR_INACTIVE_SUBSCRIPTION, 557 DOWNLOAD_STATUS_MMS_ERROR_DATA_DISABLED, 558 DOWNLOAD_STATUS_MMS_ERROR_MMS_DISABLED_BY_CARRIER 559 }) 560 @Retention(RetentionPolicy.SOURCE) 561 public @interface DownloadResult {} 562 563 /** 564 * Flag to request SMS delivery status report. 565 */ 566 public static final int SEND_FLAG_REQUEST_DELIVERY_STATUS = 0x1; 567 568 /** @hide */ 569 @IntDef(flag = true, prefix = { "SEND_FLAG_" }, value = { 570 SEND_FLAG_REQUEST_DELIVERY_STATUS 571 }) 572 @Retention(RetentionPolicy.SOURCE) 573 public @interface SendRequest {} 574 575 private final ICarrierMessagingWrapper mWrapper = new ICarrierMessagingWrapper(); 576 577 /** 578 * Override this method to filter inbound SMS messages. 579 * 580 * @param pdu the PDUs of the message 581 * @param format the format of the PDUs, typically "3gpp" or "3gpp2" 582 * @param destPort the destination port of a binary SMS, this will be -1 for text SMS 583 * @param subId SMS subscription ID of the SIM 584 * @param callback result callback. Call with {@code true} to keep an inbound SMS message and 585 * deliver to SMS apps, and {@code false} to drop the message. 586 * @deprecated Use {@link #onReceiveTextSms} instead. 587 */ 588 @Deprecated onFilterSms(@onNull MessagePdu pdu, @NonNull String format, int destPort, int subId, @NonNull ResultCallback<Boolean> callback)589 public void onFilterSms(@NonNull MessagePdu pdu, @NonNull String format, int destPort, 590 int subId, @NonNull ResultCallback<Boolean> callback) { 591 // optional 592 try { 593 callback.onReceiveResult(true); 594 } catch (RemoteException ex) { 595 } 596 } 597 598 /** 599 * Override this method to filter inbound SMS messages. 600 * 601 * <p>This method will be called once for every incoming text SMS. You can invoke the callback 602 * with a bitmask to tell the platform how to handle the SMS. For a SMS received on a 603 * file-based encryption capable device while the credential-encrypted storage is not available, 604 * this method will be called for the second time when the credential-encrypted storage becomes 605 * available after the user unlocks the phone, if the bit {@link #RECEIVE_OPTIONS_DROP} is not 606 * set when invoking the callback. 607 * 608 * @param pdu the PDUs of the message 609 * @param format the format of the PDUs, typically "3gpp" or "3gpp2" 610 * @param destPort the destination port of a binary SMS, this will be -1 for text SMS 611 * @param subId SMS subscription ID of the SIM 612 * @param callback result callback. Call with a bitmask integer to indicate how the incoming 613 * text SMS should be handled by the platform. Use {@link #RECEIVE_OPTIONS_DROP} and 614 * {@link #RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_PROTECTED_STORAGE_UNAVAILABLE} 615 * to set the flags in the bitmask. 616 */ onReceiveTextSms(@onNull MessagePdu pdu, @NonNull String format, int destPort, int subId, @NonNull final ResultCallback<Integer> callback)617 public void onReceiveTextSms(@NonNull MessagePdu pdu, @NonNull String format, 618 int destPort, int subId, @NonNull final ResultCallback<Integer> callback) { 619 onFilterSms(pdu, format, destPort, subId, new ResultCallback<Boolean>() { 620 @Override 621 public void onReceiveResult(Boolean result) throws RemoteException { 622 callback.onReceiveResult(result ? RECEIVE_OPTIONS_DEFAULT : RECEIVE_OPTIONS_DROP 623 | RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_PROTECTED_STORAGE_UNAVAILABLE); 624 } 625 }); 626 } 627 628 /** 629 * Override this method to intercept text SMSs sent from the device. 630 * @deprecated Override {@link #onSendTextSms} below instead. 631 * 632 * @param text the text to send 633 * @param subId SMS subscription ID of the SIM 634 * @param destAddress phone number of the recipient of the message 635 * @param callback result callback. Call with a {@link SendSmsResult}. 636 */ 637 @Deprecated onSendTextSms( @onNull String text, int subId, @NonNull String destAddress, @NonNull ResultCallback<SendSmsResult> callback)638 public void onSendTextSms( 639 @NonNull String text, int subId, @NonNull String destAddress, 640 @NonNull ResultCallback<SendSmsResult> callback) { 641 // optional 642 try { 643 callback.onReceiveResult(new SendSmsResult(SEND_STATUS_RETRY_ON_CARRIER_NETWORK, 0)); 644 } catch (RemoteException ex) { 645 } 646 } 647 648 /** 649 * Override this method to intercept text SMSs sent from the device. 650 * 651 * @param text the text to send 652 * @param subId SMS subscription ID of the SIM 653 * @param destAddress phone number of the recipient of the message 654 * @param sendSmsFlag Flag for sending SMS. Acceptable values are 0 and 655 * {@link #SEND_FLAG_REQUEST_DELIVERY_STATUS}. 656 * @param callback result callback. Call with a {@link SendSmsResult}. 657 */ onSendTextSms( @onNull String text, int subId, @NonNull String destAddress, int sendSmsFlag, @NonNull ResultCallback<SendSmsResult> callback)658 public void onSendTextSms( 659 @NonNull String text, int subId, @NonNull String destAddress, 660 int sendSmsFlag, @NonNull ResultCallback<SendSmsResult> callback) { 661 // optional 662 onSendTextSms(text, subId, destAddress, callback); 663 } 664 665 /** 666 * Override this method to intercept binary SMSs sent from the device. 667 * @deprecated Override {@link #onSendDataSms} below instead. 668 * 669 * @param data the binary content 670 * @param subId SMS subscription ID of the SIM 671 * @param destAddress phone number of the recipient of the message 672 * @param destPort the destination port 673 * @param callback result callback. Call with a {@link SendSmsResult}. 674 */ 675 @Deprecated onSendDataSms(@onNull byte[] data, int subId, @NonNull String destAddress, int destPort, @NonNull ResultCallback<SendSmsResult> callback)676 public void onSendDataSms(@NonNull byte[] data, int subId, 677 @NonNull String destAddress, int destPort, 678 @NonNull ResultCallback<SendSmsResult> callback) { 679 // optional 680 try { 681 callback.onReceiveResult(new SendSmsResult(SEND_STATUS_RETRY_ON_CARRIER_NETWORK, 0)); 682 } catch (RemoteException ex) { 683 } 684 } 685 686 /** 687 * Override this method to intercept binary SMSs sent from the device. 688 * 689 * @param data the binary content 690 * @param subId SMS subscription ID of the SIM 691 * @param destAddress phone number of the recipient of the message 692 * @param destPort the destination port 693 * @param sendSmsFlag Flag for sending SMS. Acceptable values are 0 and 694 * {@link #SEND_FLAG_REQUEST_DELIVERY_STATUS}. 695 * @param callback result callback. Call with a {@link SendSmsResult}. 696 */ onSendDataSms(@onNull byte[] data, int subId, @NonNull String destAddress, int destPort, int sendSmsFlag, @NonNull ResultCallback<SendSmsResult> callback)697 public void onSendDataSms(@NonNull byte[] data, int subId, 698 @NonNull String destAddress, int destPort, int sendSmsFlag, 699 @NonNull ResultCallback<SendSmsResult> callback) { 700 // optional 701 onSendDataSms(data, subId, destAddress, destPort, callback); 702 } 703 704 /** 705 * Override this method to intercept long SMSs sent from the device. 706 * @deprecated Override {@link #onSendMultipartTextSms} below instead. 707 * 708 * @param parts a {@link List} of the message parts 709 * @param subId SMS subscription ID of the SIM 710 * @param destAddress phone number of the recipient of the message 711 * @param callback result callback. Call with a {@link SendMultipartSmsResult}. 712 */ 713 @Deprecated onSendMultipartTextSms(@onNull List<String> parts, int subId, @NonNull String destAddress, @NonNull ResultCallback<SendMultipartSmsResult> callback)714 public void onSendMultipartTextSms(@NonNull List<String> parts, 715 int subId, @NonNull String destAddress, 716 @NonNull ResultCallback<SendMultipartSmsResult> callback) { 717 // optional 718 try { 719 callback.onReceiveResult( 720 new SendMultipartSmsResult(SEND_STATUS_RETRY_ON_CARRIER_NETWORK, null)); 721 } catch (RemoteException ex) { 722 } 723 } 724 725 /** 726 * Override this method to intercept long SMSs sent from the device. 727 * 728 * @param parts a {@link List} of the message parts 729 * @param subId SMS subscription ID of the SIM 730 * @param destAddress phone number of the recipient of the message 731 * @param sendSmsFlag Flag for sending SMS. Acceptable values are 0 and 732 * {@link #SEND_FLAG_REQUEST_DELIVERY_STATUS}. 733 * @param callback result callback. Call with a {@link SendMultipartSmsResult}. 734 */ onSendMultipartTextSms(@onNull List<String> parts, int subId, @NonNull String destAddress, int sendSmsFlag, @NonNull ResultCallback<SendMultipartSmsResult> callback)735 public void onSendMultipartTextSms(@NonNull List<String> parts, 736 int subId, @NonNull String destAddress, int sendSmsFlag, 737 @NonNull ResultCallback<SendMultipartSmsResult> callback) { 738 // optional 739 onSendMultipartTextSms(parts, subId, destAddress, callback); 740 } 741 742 /** 743 * Override this method to intercept MMSs sent from the device. 744 * 745 * @param pduUri the content provider URI of the PDU to send 746 * @param subId SMS subscription ID of the SIM 747 * @param location the optional URI to send this MMS PDU. If this is {code null}, 748 * the PDU should be sent to the default MMSC URL. 749 * @param callback result callback. Call with a {@link SendMmsResult}. 750 */ onSendMms(@onNull Uri pduUri, int subId, @Nullable Uri location, @NonNull ResultCallback<SendMmsResult> callback)751 public void onSendMms(@NonNull Uri pduUri, int subId, 752 @Nullable Uri location, @NonNull ResultCallback<SendMmsResult> callback) { 753 // optional 754 try { 755 callback.onReceiveResult(new SendMmsResult(SEND_STATUS_RETRY_ON_CARRIER_NETWORK, null)); 756 } catch (RemoteException ex) { 757 } 758 } 759 760 /** 761 * Override this method to download MMSs received. 762 * 763 * @param contentUri the content provider URI of the PDU to be downloaded. 764 * @param subId SMS subscription ID of the SIM 765 * @param location the URI of the message to be downloaded. 766 * @param callback result callback. Call with a status code which is one of 767 * {@link #DOWNLOAD_STATUS_OK}, 768 * {@link #DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK}, or {@link #DOWNLOAD_STATUS_ERROR}. 769 */ onDownloadMms(@onNull Uri contentUri, int subId, @NonNull Uri location, @NonNull ResultCallback<Integer> callback)770 public void onDownloadMms(@NonNull Uri contentUri, int subId, @NonNull Uri location, 771 @NonNull ResultCallback<Integer> callback) { 772 // optional 773 try { 774 callback.onReceiveResult(DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK); 775 } catch (RemoteException ex) { 776 } 777 } 778 779 @Override onBind(@onNull Intent intent)780 public @Nullable IBinder onBind(@NonNull Intent intent) { 781 if (!SERVICE_INTERFACE.equals(intent.getAction())) { 782 return null; 783 } 784 return mWrapper; 785 } 786 787 /** 788 * The result of sending an MMS. 789 */ 790 public static final class SendMmsResult { 791 private int mSendStatus; 792 private byte[] mSendConfPdu; 793 794 /** 795 * Constructs a SendMmsResult with the MMS send result, and the SendConf PDU. 796 * 797 * @param sendStatus send status, one of {@link #SEND_STATUS_OK}, 798 * {@link #SEND_STATUS_RETRY_ON_CARRIER_NETWORK}, and 799 * {@link #SEND_STATUS_ERROR} 800 * @param sendConfPdu a possibly {code null} SendConf PDU, which confirms that the message 801 * was sent. sendConfPdu is ignored if the {@code result} is not 802 * {@link #SEND_STATUS_OK}. 803 */ SendMmsResult(int sendStatus, @Nullable byte[] sendConfPdu)804 public SendMmsResult(int sendStatus, @Nullable byte[] sendConfPdu) { 805 mSendStatus = sendStatus; 806 mSendConfPdu = sendConfPdu; 807 } 808 809 /** 810 * Returns the send status of the just-sent MMS. 811 * 812 * @return the send status which is one of {@link #SEND_STATUS_OK}, 813 * {@link #SEND_STATUS_RETRY_ON_CARRIER_NETWORK}, and {@link #SEND_STATUS_ERROR} 814 */ getSendStatus()815 public int getSendStatus() { 816 return mSendStatus; 817 } 818 819 /** 820 * Returns the SendConf PDU, which confirms that the message was sent. 821 * 822 * @return the SendConf PDU 823 */ getSendConfPdu()824 public @Nullable byte[] getSendConfPdu() { 825 return mSendConfPdu; 826 } 827 } 828 829 /** 830 * The result of sending an SMS. 831 */ 832 public static final class SendSmsResult { 833 private final int mSendStatus; 834 private final int mMessageRef; 835 836 /** 837 * Constructs a SendSmsResult with the send status and message reference for the 838 * just-sent SMS. 839 * 840 * @param sendStatus send status, one of {@link #SEND_STATUS_OK}, 841 * {@link #SEND_STATUS_RETRY_ON_CARRIER_NETWORK}, and {@link #SEND_STATUS_ERROR}. 842 * @param messageRef message reference of the just-sent SMS. This field is applicable only 843 * if send status is {@link #SEND_STATUS_OK}. 844 */ SendSmsResult(int sendStatus, int messageRef)845 public SendSmsResult(int sendStatus, int messageRef) { 846 mSendStatus = sendStatus; 847 mMessageRef = messageRef; 848 } 849 850 /** 851 * Returns the message reference of the just-sent SMS. 852 * 853 * @return the message reference 854 */ getMessageRef()855 public int getMessageRef() { 856 return mMessageRef; 857 } 858 859 /** 860 * Returns the send status of the just-sent SMS. 861 * 862 * @return the send status 863 */ getSendStatus()864 public int getSendStatus() { 865 return mSendStatus; 866 } 867 } 868 869 /** 870 * The result of sending a multipart SMS. 871 */ 872 public static final class SendMultipartSmsResult { 873 private final int mSendStatus; 874 private final int[] mMessageRefs; 875 876 /** 877 * Constructs a SendMultipartSmsResult with the send status and message references for the 878 * just-sent multipart SMS. 879 * 880 * @param sendStatus send status, one of {@link #SEND_STATUS_OK}, 881 * {@link #SEND_STATUS_RETRY_ON_CARRIER_NETWORK}, and {@link #SEND_STATUS_ERROR}. 882 * @param messageRefs an array of message references, one for each part of the 883 * multipart SMS. This field is applicable only if send status is 884 * {@link #SEND_STATUS_OK}. 885 */ SendMultipartSmsResult(int sendStatus, @Nullable int[] messageRefs)886 public SendMultipartSmsResult(int sendStatus, @Nullable int[] messageRefs) { 887 mSendStatus = sendStatus; 888 mMessageRefs = messageRefs; 889 } 890 891 /** 892 * Returns the message references of the just-sent multipart SMS. 893 * 894 * @return the message references, one for each part of the multipart SMS 895 */ getMessageRefs()896 public @Nullable int[] getMessageRefs() { 897 return mMessageRefs; 898 } 899 900 /** 901 * Returns the send status of the just-sent SMS. 902 * 903 * @return the send status 904 */ getSendStatus()905 public int getSendStatus() { 906 return mSendStatus; 907 } 908 } 909 910 /** 911 * A callback interface used to provide results asynchronously. 912 */ 913 public interface ResultCallback<T> { 914 /** 915 * Invoked when the result is available. 916 * 917 * @param result the result 918 */ onReceiveResult(@onNull T result)919 public void onReceiveResult(@NonNull T result) throws RemoteException; 920 }; 921 922 /** 923 * A wrapper around ICarrierMessagingService to enable the carrier messaging app to implement 924 * methods it cares about in the {@link ICarrierMessagingService} interface. 925 */ 926 private class ICarrierMessagingWrapper extends ICarrierMessagingService.Stub { 927 @Override filterSms(MessagePdu pdu, String format, int destPort, int subId, final ICarrierMessagingCallback callback)928 public void filterSms(MessagePdu pdu, String format, int destPort, 929 int subId, final ICarrierMessagingCallback callback) { 930 onReceiveTextSms(pdu, format, destPort, subId, 931 new ResultCallback<Integer>() { 932 @Override 933 public void onReceiveResult(Integer options) throws RemoteException { 934 callback.onFilterComplete(options); 935 } 936 }); 937 } 938 939 @Override sendTextSms(String text, int subId, String destAddress, int sendSmsFlag, final ICarrierMessagingCallback callback)940 public void sendTextSms(String text, int subId, String destAddress, 941 int sendSmsFlag, final ICarrierMessagingCallback callback) { 942 onSendTextSms(text, subId, destAddress, sendSmsFlag, 943 new ResultCallback<SendSmsResult>() { 944 @Override 945 public void onReceiveResult(final SendSmsResult result) throws RemoteException { 946 callback.onSendSmsComplete(result.getSendStatus(), result.getMessageRef()); 947 } 948 }); 949 } 950 951 @Override sendDataSms(byte[] data, int subId, String destAddress, int destPort, int sendSmsFlag, final ICarrierMessagingCallback callback)952 public void sendDataSms(byte[] data, int subId, String destAddress, int destPort, 953 int sendSmsFlag, final ICarrierMessagingCallback callback) { 954 onSendDataSms(data, subId, destAddress, destPort, sendSmsFlag, 955 new ResultCallback<SendSmsResult>() { 956 @Override 957 public void onReceiveResult(final SendSmsResult result) throws RemoteException { 958 callback.onSendSmsComplete(result.getSendStatus(), result.getMessageRef()); 959 } 960 }); 961 } 962 963 @Override sendMultipartTextSms(List<String> parts, int subId, String destAddress, int sendSmsFlag, final ICarrierMessagingCallback callback)964 public void sendMultipartTextSms(List<String> parts, int subId, String destAddress, 965 int sendSmsFlag, final ICarrierMessagingCallback callback) { 966 onSendMultipartTextSms(parts, subId, destAddress, sendSmsFlag, 967 new ResultCallback<SendMultipartSmsResult>() { 968 @Override 969 public void onReceiveResult(final SendMultipartSmsResult result) 970 throws RemoteException { 971 callback.onSendMultipartSmsComplete( 972 result.getSendStatus(), result.getMessageRefs()); 973 } 974 }); 975 } 976 977 @Override sendMms(Uri pduUri, int subId, Uri location, final ICarrierMessagingCallback callback)978 public void sendMms(Uri pduUri, int subId, Uri location, 979 final ICarrierMessagingCallback callback) { 980 onSendMms(pduUri, subId, location, new ResultCallback<SendMmsResult>() { 981 @Override 982 public void onReceiveResult(final SendMmsResult result) throws RemoteException { 983 callback.onSendMmsComplete(result.getSendStatus(), result.getSendConfPdu()); 984 } 985 }); 986 } 987 988 @Override downloadMms(Uri pduUri, int subId, Uri location, final ICarrierMessagingCallback callback)989 public void downloadMms(Uri pduUri, int subId, Uri location, 990 final ICarrierMessagingCallback callback) { 991 onDownloadMms(pduUri, subId, location, new ResultCallback<Integer>() { 992 @Override 993 public void onReceiveResult(Integer result) throws RemoteException { 994 callback.onDownloadMmsComplete(result); 995 } 996 }); 997 } 998 } 999 } 1000