From a8c9c6c593d603a84aa164410b91e2399ceb41ce Mon Sep 17 00:00:00 2001 From: Ji Yang Date: Mon, 22 Feb 2016 16:59:37 -0800 Subject: New CarrierMessagingService API for sms filtering Add a new sms filtering method to let the carrier app tell the platform to keep the message while keep it invisible to the end user. BUG: 27292180 Change-Id: I306a7dbde6dcb9929e358b3d1bbda9807ef35943 --- api/current.txt | 6 ++- api/system-current.txt | 6 ++- api/test-current.txt | 6 ++- .../service/carrier/CarrierMessagingService.java | 63 ++++++++++++++++++++-- .../service/carrier/ICarrierMessagingCallback.aidl | 2 +- 5 files changed, 76 insertions(+), 7 deletions(-) diff --git a/api/current.txt b/api/current.txt index 55e81a3a796c..8615f0234bfe 100644 --- a/api/current.txt +++ b/api/current.txt @@ -34239,7 +34239,8 @@ package android.service.carrier { ctor public CarrierMessagingService(); method public android.os.IBinder onBind(android.content.Intent); method public void onDownloadMms(android.net.Uri, int, android.net.Uri, android.service.carrier.CarrierMessagingService.ResultCallback); - method public void onFilterSms(android.service.carrier.MessagePdu, java.lang.String, int, int, android.service.carrier.CarrierMessagingService.ResultCallback); + method public deprecated void onFilterSms(android.service.carrier.MessagePdu, java.lang.String, int, int, android.service.carrier.CarrierMessagingService.ResultCallback); + method public void onReceiveTextSms(android.service.carrier.MessagePdu, java.lang.String, int, int, android.service.carrier.CarrierMessagingService.ResultCallback); method public deprecated void onSendDataSms(byte[], int, java.lang.String, int, android.service.carrier.CarrierMessagingService.ResultCallback); method public void onSendDataSms(byte[], int, java.lang.String, int, int, android.service.carrier.CarrierMessagingService.ResultCallback); method public void onSendMms(android.net.Uri, int, android.net.Uri, android.service.carrier.CarrierMessagingService.ResultCallback); @@ -34250,6 +34251,9 @@ package android.service.carrier { field public static final int DOWNLOAD_STATUS_ERROR = 2; // 0x2 field public static final int DOWNLOAD_STATUS_OK = 0; // 0x0 field public static final int DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK = 1; // 0x1 + field public static final int RECEIVE_OPTIONS_DEFAULT = 0; // 0x0 + field public static final int RECEIVE_OPTIONS_DROP = 1; // 0x1 + field public static final int RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_ENCRYPTED_STORAGE_UNAVAILABLE = 2; // 0x2 field public static final int SEND_FLAG_REQUEST_DELIVERY_STATUS = 1; // 0x1 field public static final int SEND_STATUS_ERROR = 2; // 0x2 field public static final int SEND_STATUS_OK = 0; // 0x0 diff --git a/api/system-current.txt b/api/system-current.txt index e9d47be6545f..b0a372a315e2 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -36730,7 +36730,8 @@ package android.service.carrier { ctor public CarrierMessagingService(); method public android.os.IBinder onBind(android.content.Intent); method public void onDownloadMms(android.net.Uri, int, android.net.Uri, android.service.carrier.CarrierMessagingService.ResultCallback); - method public void onFilterSms(android.service.carrier.MessagePdu, java.lang.String, int, int, android.service.carrier.CarrierMessagingService.ResultCallback); + method public deprecated void onFilterSms(android.service.carrier.MessagePdu, java.lang.String, int, int, android.service.carrier.CarrierMessagingService.ResultCallback); + method public void onReceiveTextSms(android.service.carrier.MessagePdu, java.lang.String, int, int, android.service.carrier.CarrierMessagingService.ResultCallback); method public deprecated void onSendDataSms(byte[], int, java.lang.String, int, android.service.carrier.CarrierMessagingService.ResultCallback); method public void onSendDataSms(byte[], int, java.lang.String, int, int, android.service.carrier.CarrierMessagingService.ResultCallback); method public void onSendMms(android.net.Uri, int, android.net.Uri, android.service.carrier.CarrierMessagingService.ResultCallback); @@ -36741,6 +36742,9 @@ package android.service.carrier { field public static final int DOWNLOAD_STATUS_ERROR = 2; // 0x2 field public static final int DOWNLOAD_STATUS_OK = 0; // 0x0 field public static final int DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK = 1; // 0x1 + field public static final int RECEIVE_OPTIONS_DEFAULT = 0; // 0x0 + field public static final int RECEIVE_OPTIONS_DROP = 1; // 0x1 + field public static final int RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_ENCRYPTED_STORAGE_UNAVAILABLE = 2; // 0x2 field public static final int SEND_FLAG_REQUEST_DELIVERY_STATUS = 1; // 0x1 field public static final int SEND_STATUS_ERROR = 2; // 0x2 field public static final int SEND_STATUS_OK = 0; // 0x0 diff --git a/api/test-current.txt b/api/test-current.txt index 31fc5f78a0dd..d1be531fb229 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -34254,7 +34254,8 @@ package android.service.carrier { ctor public CarrierMessagingService(); method public android.os.IBinder onBind(android.content.Intent); method public void onDownloadMms(android.net.Uri, int, android.net.Uri, android.service.carrier.CarrierMessagingService.ResultCallback); - method public void onFilterSms(android.service.carrier.MessagePdu, java.lang.String, int, int, android.service.carrier.CarrierMessagingService.ResultCallback); + method public deprecated void onFilterSms(android.service.carrier.MessagePdu, java.lang.String, int, int, android.service.carrier.CarrierMessagingService.ResultCallback); + method public void onReceiveTextSms(android.service.carrier.MessagePdu, java.lang.String, int, int, android.service.carrier.CarrierMessagingService.ResultCallback); method public deprecated void onSendDataSms(byte[], int, java.lang.String, int, android.service.carrier.CarrierMessagingService.ResultCallback); method public void onSendDataSms(byte[], int, java.lang.String, int, int, android.service.carrier.CarrierMessagingService.ResultCallback); method public void onSendMms(android.net.Uri, int, android.net.Uri, android.service.carrier.CarrierMessagingService.ResultCallback); @@ -34265,6 +34266,9 @@ package android.service.carrier { field public static final int DOWNLOAD_STATUS_ERROR = 2; // 0x2 field public static final int DOWNLOAD_STATUS_OK = 0; // 0x0 field public static final int DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK = 1; // 0x1 + field public static final int RECEIVE_OPTIONS_DEFAULT = 0; // 0x0 + field public static final int RECEIVE_OPTIONS_DROP = 1; // 0x1 + field public static final int RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_ENCRYPTED_STORAGE_UNAVAILABLE = 2; // 0x2 field public static final int SEND_FLAG_REQUEST_DELIVERY_STATUS = 1; // 0x1 field public static final int SEND_STATUS_ERROR = 2; // 0x2 field public static final int SEND_STATUS_OK = 0; // 0x0 diff --git a/core/java/android/service/carrier/CarrierMessagingService.java b/core/java/android/service/carrier/CarrierMessagingService.java index f5396a347cf9..140341cfaece 100644 --- a/core/java/android/service/carrier/CarrierMessagingService.java +++ b/core/java/android/service/carrier/CarrierMessagingService.java @@ -50,6 +50,30 @@ public abstract class CarrierMessagingService extends Service { public static final String SERVICE_INTERFACE = "android.service.carrier.CarrierMessagingService"; + /** + * The default bitmask value passed to the callback of {@link #onReceiveTextSms} with all + * {@code RECEIVE_OPTIONS_x} flags cleared to indicate that the message should be kept and a + * new message notification should be shown. + * + * @see #RECEIVE_OPTIONS_DROP + * @see #RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_ENCRYPTED_STORAGE_UNAVAILABLE + */ + public static final int RECEIVE_OPTIONS_DEFAULT = 0; + + /** + * Used to set the flag in the bitmask passed to the callback of {@link #onReceiveTextSms} to + * indicate that the inbound SMS should be dropped. + */ + public static final int RECEIVE_OPTIONS_DROP = 0x1; + + /** + * Used to set the flag in the bitmask passed to the callback of {@link #onReceiveTextSms} to + * indicate that a new message notification should not be shown to the user when the + * credential-encrypted storage of the device is not available before the user unlocks the + * phone. It is only applicable to devices that support file-based encryption. + */ + public static final int RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_ENCRYPTED_STORAGE_UNAVAILABLE = 0x2; + /** * Indicates that an SMS or MMS message was successfully sent. */ @@ -96,7 +120,9 @@ public abstract class CarrierMessagingService extends Service { * @param subId SMS subscription ID of the SIM * @param callback result callback. Call with {@code true} to keep an inbound SMS message and * deliver to SMS apps, and {@code false} to drop the message. + * @deprecated Use {@link #onReceiveTextSms} instead. */ + @Deprecated public void onFilterSms(@NonNull MessagePdu pdu, @NonNull String format, int destPort, int subId, @NonNull ResultCallback callback) { // optional @@ -106,6 +132,36 @@ public abstract class CarrierMessagingService extends Service { } } + /** + * Override this method to filter inbound SMS messages. + * + *

This method will be called once for every incoming text SMS. You can invoke the callback + * with a bitmask to tell the platform how to handle the SMS. For a SMS received on a + * file-based encryption capable device while the credential-encrypted storage is not available, + * this method will be called for the second time when the credential-encrypted storage becomes + * available after the user unlocks the phone, if the bit {@link #RECEIVE_OPTIONS_DROP} is not + * set when invoking the callback. + * + * @param pdu the PDUs of the message + * @param format the format of the PDUs, typically "3gpp" or "3gpp2" + * @param destPort the destination port of a binary SMS, this will be -1 for text SMS + * @param subId SMS subscription ID of the SIM + * @param callback result callback. Call with a bitmask integer to indicate how the incoming + * text SMS should be handled by the platform. Use {@link #RECEIVE_OPTIONS_DROP} and + * {@link #RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_ENCRYPTED_STORAGE_UNAVAILABLE} + * to set the flags in the bitmask. + */ + public void onReceiveTextSms(@NonNull MessagePdu pdu, @NonNull String format, + int destPort, int subId, @NonNull final ResultCallback callback) { + onFilterSms(pdu, format, destPort, subId, new ResultCallback() { + @Override + public void onReceiveResult(Boolean result) throws RemoteException { + callback.onReceiveResult(result ? RECEIVE_OPTIONS_DEFAULT : RECEIVE_OPTIONS_DROP + | RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_ENCRYPTED_STORAGE_UNAVAILABLE); + } + }); + } + /** * Override this method to intercept text SMSs sent from the device. * @deprecated Override {@link #onSendTextSms} below instead. @@ -408,10 +464,11 @@ public abstract class CarrierMessagingService extends Service { @Override public void filterSms(MessagePdu pdu, String format, int destPort, int subId, final ICarrierMessagingCallback callback) { - onFilterSms(pdu, format, destPort, subId, new ResultCallback() { + onReceiveTextSms(pdu, format, destPort, subId, + new ResultCallback() { @Override - public void onReceiveResult(final Boolean result) throws RemoteException { - callback.onFilterComplete(result); + public void onReceiveResult(Integer options) throws RemoteException { + callback.onFilterComplete(options); } }); } diff --git a/core/java/android/service/carrier/ICarrierMessagingCallback.aidl b/core/java/android/service/carrier/ICarrierMessagingCallback.aidl index 6118a20ca006..2753669fae84 100644 --- a/core/java/android/service/carrier/ICarrierMessagingCallback.aidl +++ b/core/java/android/service/carrier/ICarrierMessagingCallback.aidl @@ -22,7 +22,7 @@ package android.service.carrier; * @hide */ oneway interface ICarrierMessagingCallback { - void onFilterComplete(boolean keepMessage); + void onFilterComplete(int result); void onSendSmsComplete(int result, int messageRef); void onSendMultipartSmsComplete(int result, in int[] messageRefs); void onSendMmsComplete(int result, in byte[] sendConfPdu); -- cgit v1.2.3-59-g8ed1b