/* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.telephony; import android.app.ActivityThread; import android.app.PendingIntent; import android.content.ActivityNotFoundException; import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.BaseBundle; import android.os.Bundle; import android.os.RemoteException; import android.os.ServiceManager; import android.text.TextUtils; import android.util.ArrayMap; import android.util.Log; import com.android.internal.telephony.IMms; import com.android.internal.telephony.ISms; import com.android.internal.telephony.SmsRawData; import com.android.internal.telephony.uicc.IccConstants; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; /* * TODO(code review): Curious question... Why are a lot of these * methods not declared as static, since they do not seem to require * any local object state? Presumably this cannot be changed without * interfering with the API... */ /** * Manages SMS operations such as sending data, text, and pdu SMS messages. * Get this object by calling the static method {@link #getDefault()}. * *
For information about how to behave as the default SMS app on Android 4.4 (API level 19)
* and higher, see {@link android.provider.Telephony}.
*/
public final class SmsManager {
private static final String TAG = "SmsManager";
/**
* A psuedo-subId that represents the default subId at any given time. The actual subId it
* represents changes as the default subId is changed.
*/
private static final int DEFAULT_SUBSCRIPTION_ID = -1002;
/** Singleton object constructed during class initialization. */
private static final SmsManager sInstance = new SmsManager(DEFAULT_SUBSCRIPTION_ID);
private static final Object sLockObject = new Object();
/** @hide */
public static final int CELL_BROADCAST_RAN_TYPE_GSM = 0;
/** @hide */
public static final int CELL_BROADCAST_RAN_TYPE_CDMA = 1;
private static final Map Note: Using this method requires that your app has the
* {@link android.Manifest.permission#SEND_SMS} permission. Note: Beginning with Android 4.4 (API level 19), if
* and only if an app is not selected as the default SMS app, the system automatically
* writes messages sent using this method to the SMS Provider (the default SMS app is always
* responsible for writing its sent messages to the SMS Provider). For information about
* how to behave as the default SMS app, see {@link android.provider.Telephony}. Only the carrier app can call this method. Note: Using this method requires that your app has the
* {@link android.Manifest.permission#SEND_SMS} permission. Note: Beginning with Android 4.4 (API level 19), if
* and only if an app is not selected as the default SMS app, the system automatically
* writes messages sent using this method to the SMS Provider (the default SMS app is always
* responsible for writing its sent messages to the SMS Provider). For information about
* how to behave as the default SMS app, see {@link android.provider.Telephony}. Only the carrier app can call this method. Note: Using this method requires that your app has the
* {@link android.Manifest.permission#SEND_SMS} permission.PendingIntent
is
* broadcast when the message is successfully sent, or failed.
* The result code will be Activity.RESULT_OK
for success,
* or one of these errors:
* RESULT_ERROR_GENERIC_FAILURE
* RESULT_ERROR_RADIO_OFF
* RESULT_ERROR_NULL_PDU
* For RESULT_ERROR_GENERIC_FAILURE
the sentIntent may include
* the extra "errorCode" containing a radio technology specific value,
* generally only useful for troubleshooting.
* The per-application based SMS control checks sentIntent. If sentIntent
* is NULL the caller will be checked against all unknown applications,
* which cause smaller number of SMS to be sent in checking period.
* @param deliveryIntent if not NULL this PendingIntent
is
* broadcast when the message is delivered to the recipient. The
* raw pdu of the status report is in the extended data ("pdu").
*
* @throws IllegalArgumentException if destinationAddress or text are empty
*/
public void sendTextMessage(
String destinationAddress, String scAddress, String text,
PendingIntent sentIntent, PendingIntent deliveryIntent) {
sendTextMessageInternal(destinationAddress, scAddress, text,
sentIntent, deliveryIntent, true /* persistMessageForCarrierApp*/);
}
private void sendTextMessageInternal(String destinationAddress, String scAddress,
String text, PendingIntent sentIntent, PendingIntent deliveryIntent,
boolean persistMessageForCarrierApp) {
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (TextUtils.isEmpty(text)) {
throw new IllegalArgumentException("Invalid message body");
}
try {
ISms iccISms = getISmsServiceOrThrow();
iccISms.sendTextForSubscriber(getSubscriptionId(), ActivityThread.currentPackageName(),
destinationAddress,
scAddress, text, sentIntent, deliveryIntent,
persistMessageForCarrierApp);
} catch (RemoteException ex) {
// ignore it
}
}
/**
* Send a text based SMS without writing it into the SMS Provider.
*
* PendingIntent
is
* broadcast when the message is successfully received by the
* android application framework, or failed. This intent is broadcasted at
* the same time an SMS received from radio is acknowledged back.
* The result code will be RESULT_SMS_HANDLED
for success, or
* RESULT_SMS_GENERIC_ERROR
for error.
*
* @throws IllegalArgumentException if format is not one of 3gpp and 3gpp2.
*/
public void injectSmsPdu(byte[] pdu, String format, PendingIntent receivedIntent) {
if (!format.equals(SmsMessage.FORMAT_3GPP) && !format.equals(SmsMessage.FORMAT_3GPP2)) {
// Format must be either 3gpp or 3gpp2.
throw new IllegalArgumentException(
"Invalid pdu format. format must be either 3gpp or 3gpp2");
}
try {
ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (iccISms != null) {
iccISms.injectSmsPduForSubscriber(
getSubscriptionId(), pdu, format, receivedIntent);
}
} catch (RemoteException ex) {
// ignore it
}
}
/**
* Divide a message text into several fragments, none bigger than
* the maximum SMS message size.
*
* @param text the original message. Must not be null.
* @return an ArrayList
of strings that, in order,
* comprise the original message
*
* @throws IllegalArgumentException if text is null
*/
public ArrayListdivideMessage
.
*
* ArrayList
of strings that, in order,
* comprise the original message
* @param sentIntents if not null, an ArrayList
of
* PendingIntent
s (one for each message part) that is
* broadcast when the corresponding message part has been sent.
* The result code will be Activity.RESULT_OK
for success,
* or one of these errors:
* RESULT_ERROR_GENERIC_FAILURE
* RESULT_ERROR_RADIO_OFF
* RESULT_ERROR_NULL_PDU
* For RESULT_ERROR_GENERIC_FAILURE
each sentIntent may include
* the extra "errorCode" containing a radio technology specific value,
* generally only useful for troubleshooting.
* The per-application based SMS control checks sentIntent. If sentIntent
* is NULL the caller will be checked against all unknown applications,
* which cause smaller number of SMS to be sent in checking period.
* @param deliveryIntents if not null, an ArrayList
of
* PendingIntent
s (one for each message part) that is
* broadcast when the corresponding message part has been delivered
* to the recipient. The raw pdu of the status report is in the
* extended data ("pdu").
*
* @throws IllegalArgumentException if destinationAddress or data are empty
*/
public void sendMultipartTextMessage(
String destinationAddress, String scAddress, ArrayListPendingIntent
is
* broadcast when the message is successfully sent, or failed.
* The result code will be Activity.RESULT_OK
for success,
* or one of these errors:
* RESULT_ERROR_GENERIC_FAILURE
* RESULT_ERROR_RADIO_OFF
* RESULT_ERROR_NULL_PDU
* For RESULT_ERROR_GENERIC_FAILURE
the sentIntent may include
* the extra "errorCode" containing a radio technology specific value,
* generally only useful for troubleshooting.
* The per-application based SMS control checks sentIntent. If sentIntent
* is NULL the caller will be checked against all unknown applications,
* which cause smaller number of SMS to be sent in checking period.
* @param deliveryIntent if not NULL this PendingIntent
is
* broadcast when the message is delivered to the recipient. The
* raw pdu of the status report is in the extended data ("pdu").
*
* @throws IllegalArgumentException if destinationAddress or data are empty
*/
public void sendDataMessage(
String destinationAddress, String scAddress, short destinationPort,
byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) {
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (data == null || data.length == 0) {
throw new IllegalArgumentException("Invalid message data");
}
try {
ISms iccISms = getISmsServiceOrThrow();
iccISms.sendDataForSubscriber(getSubscriptionId(), ActivityThread.currentPackageName(),
destinationAddress, scAddress, destinationPort & 0xFFFF,
data, sentIntent, deliveryIntent);
} catch (RemoteException ex) {
// ignore it
}
}
/**
* A variant of {@link SmsManager#sendDataMessage} that allows self to be the caller. This is
* for internal use only.
*
* @hide
*/
public void sendDataMessageWithSelfPermissions(
String destinationAddress, String scAddress, short destinationPort,
byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) {
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (data == null || data.length == 0) {
throw new IllegalArgumentException("Invalid message data");
}
try {
ISms iccISms = getISmsServiceOrThrow();
iccISms.sendDataForSubscriberWithSelfPermissions(getSubscriptionId(),
ActivityThread.currentPackageName(), destinationAddress, scAddress,
destinationPort & 0xFFFF, data, sentIntent, deliveryIntent);
} catch (RemoteException ex) {
// ignore it
}
}
/**
* Get the SmsManager associated with the default subscription id. The instance will always be
* associated with the default subscription id, even if the default subscription id is changed.
*
* @return the SmsManager associated with the default subscription id
*/
public static SmsManager getDefault() {
return sInstance;
}
/**
* Get the the instance of the SmsManager associated with a particular subscription id
*
* @param subId an SMS subscription id, typically accessed using
* {@link android.telephony.SubscriptionManager}
* @return the instance of the SmsManager associated with subId
*/
public static SmsManager getSmsManagerForSubscriptionId(int subId) {
// TODO(shri): Add javadoc link once SubscriptionManager is made public api
synchronized(sLockObject) {
SmsManager smsManager = sSubInstances.get(subId);
if (smsManager == null) {
smsManager = new SmsManager(subId);
sSubInstances.put(subId, smsManager);
}
return smsManager;
}
}
private SmsManager(int subId) {
mSubId = subId;
}
/**
* Get the associated subscription id. If the instance was returned by {@link #getDefault()},
* then this method may return different values at different points in time (if the user
* changes the default subscription id). It will return < 0 if the default subscription id
* cannot be determined.
*
* Additionally, to support legacy applications that are not multi-SIM aware,
* if the following are true:
* - We are using a multi-SIM device
* - A default SMS SIM has not been selected
* - At least one SIM subscription is available
* then ask the user to set the default SMS SIM.
*
* @return associated subscription id
*/
public int getSubscriptionId() {
final int subId = (mSubId == DEFAULT_SUBSCRIPTION_ID)
? getDefaultSmsSubscriptionId() : mSubId;
boolean isSmsSimPickActivityNeeded = false;
final Context context = ActivityThread.currentApplication().getApplicationContext();
try {
ISms iccISms = getISmsService();
if (iccISms != null) {
isSmsSimPickActivityNeeded = iccISms.isSmsSimPickActivityNeeded(subId);
}
} catch (RemoteException ex) {
Log.e(TAG, "Exception in getSubscriptionId");
}
if (isSmsSimPickActivityNeeded) {
Log.d(TAG, "getSubscriptionId isSmsSimPickActivityNeeded is true");
// ask the user for a default SMS SIM.
Intent intent = new Intent();
intent.setClassName("com.android.settings",
"com.android.settings.sim.SimDialogActivity");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(DIALOG_TYPE_KEY, SMS_PICK);
try {
context.startActivity(intent);
} catch (ActivityNotFoundException anfe) {
// If Settings is not installed, only log the error as we do not want to break
// legacy applications.
Log.e(TAG, "Unable to launch Settings application.");
}
}
return subId;
}
/**
* Returns the ISms service, or throws an UnsupportedOperationException if
* the service does not exist.
*/
private static ISms getISmsServiceOrThrow() {
ISms iccISms = getISmsService();
if (iccISms == null) {
throw new UnsupportedOperationException("Sms is not supported");
}
return iccISms;
}
private static ISms getISmsService() {
return ISms.Stub.asInterface(ServiceManager.getService("isms"));
}
/**
* Copy a raw SMS PDU to the ICC.
* ICC (Integrated Circuit Card) is the card of the device.
* For example, this can be the SIM or USIM for GSM.
*
* @param smsc the SMSC for this message, or NULL for the default SMSC
* @param pdu the raw PDU to store
* @param status message status (STATUS_ON_ICC_READ, STATUS_ON_ICC_UNREAD,
* STATUS_ON_ICC_SENT, STATUS_ON_ICC_UNSENT)
* @return true for success
*
* @throws IllegalArgumentException if pdu is NULL
* {@hide}
*/
public boolean copyMessageToIcc(byte[] smsc, byte[] pdu,int status) {
boolean success = false;
if (null == pdu) {
throw new IllegalArgumentException("pdu is NULL");
}
try {
ISms iccISms = getISmsService();
if (iccISms != null) {
success = iccISms.copyMessageToIccEfForSubscriber(getSubscriptionId(),
ActivityThread.currentPackageName(),
status, pdu, smsc);
}
} catch (RemoteException ex) {
// ignore it
}
return success;
}
/**
* Delete the specified message from the ICC.
* ICC (Integrated Circuit Card) is the card of the device.
* For example, this can be the SIM or USIM for GSM.
*
* @param messageIndex is the record index of the message on ICC
* @return true for success
*
* {@hide}
*/
public boolean
deleteMessageFromIcc(int messageIndex) {
boolean success = false;
byte[] pdu = new byte[IccConstants.SMS_RECORD_LENGTH-1];
Arrays.fill(pdu, (byte)0xff);
try {
ISms iccISms = getISmsService();
if (iccISms != null) {
success = iccISms.updateMessageOnIccEfForSubscriber(getSubscriptionId(),
ActivityThread.currentPackageName(),
messageIndex, STATUS_ON_ICC_FREE, pdu);
}
} catch (RemoteException ex) {
// ignore it
}
return success;
}
/**
* Update the specified message on the ICC.
* ICC (Integrated Circuit Card) is the card of the device.
* For example, this can be the SIM or USIM for GSM.
*
* @param messageIndex record index of message to update
* @param newStatus new message status (STATUS_ON_ICC_READ,
* STATUS_ON_ICC_UNREAD, STATUS_ON_ICC_SENT,
* STATUS_ON_ICC_UNSENT, STATUS_ON_ICC_FREE)
* @param pdu the raw PDU to store
* @return true for success
*
* {@hide}
*/
public boolean updateMessageOnIcc(int messageIndex, int newStatus, byte[] pdu) {
boolean success = false;
try {
ISms iccISms = getISmsService();
if (iccISms != null) {
success = iccISms.updateMessageOnIccEfForSubscriber(getSubscriptionId(),
ActivityThread.currentPackageName(),
messageIndex, newStatus, pdu);
}
} catch (RemoteException ex) {
// ignore it
}
return success;
}
/**
* Retrieves all messages currently stored on ICC.
* ICC (Integrated Circuit Card) is the card of the device.
* For example, this can be the SIM or USIM for GSM.
*
* @return ArrayList
of SmsMessage
objects
*
* {@hide}
*/
public ArrayListSmsMessage
s from a list of RawSmsData
* records returned by getAllMessagesFromIcc()
*
* @param records SMS EF records, returned by
* getAllMessagesFromIcc
* @return ArrayList
of SmsMessage
objects.
*/
private static ArrayListPendingIntent
is
* broadcast when the message is successfully sent, or failed
* @throws IllegalArgumentException if contentUri is empty
*/
public void sendMultimediaMessage(Context context, Uri contentUri, String locationUrl,
Bundle configOverrides, PendingIntent sentIntent) {
if (contentUri == null) {
throw new IllegalArgumentException("Uri contentUri null");
}
try {
final IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
if (iMms == null) {
return;
}
iMms.sendMessage(getSubscriptionId(), ActivityThread.currentPackageName(), contentUri,
locationUrl, configOverrides, sentIntent);
} catch (RemoteException e) {
// Ignore it
}
}
/**
* Download an MMS message from carrier by a given location URL
*
* @param context application context
* @param locationUrl the location URL of the MMS message to be downloaded, usually obtained
* from the MMS WAP push notification
* @param contentUri the content uri to which the downloaded pdu will be written
* @param configOverrides the carrier-specific messaging configuration values to override for
* downloading the message.
* @param downloadedIntent if not NULL this PendingIntent
is
* broadcast when the message is downloaded, or the download is failed
* @throws IllegalArgumentException if locationUrl or contentUri is empty
*/
public void downloadMultimediaMessage(Context context, String locationUrl, Uri contentUri,
Bundle configOverrides, PendingIntent downloadedIntent) {
if (TextUtils.isEmpty(locationUrl)) {
throw new IllegalArgumentException("Empty MMS location URL");
}
if (contentUri == null) {
throw new IllegalArgumentException("Uri contentUri null");
}
try {
final IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
if (iMms == null) {
return;
}
iMms.downloadMessage(
getSubscriptionId(), ActivityThread.currentPackageName(), locationUrl,
contentUri, configOverrides, downloadedIntent);
} catch (RemoteException e) {
// Ignore it
}
}
// MMS send/download failure result codes
public static final int MMS_ERROR_UNSPECIFIED = 1;
public static final int MMS_ERROR_INVALID_APN = 2;
public static final int MMS_ERROR_UNABLE_CONNECT_MMS = 3;
public static final int MMS_ERROR_HTTP_FAILURE = 4;
public static final int MMS_ERROR_IO_ERROR = 5;
public static final int MMS_ERROR_RETRY = 6;
public static final int MMS_ERROR_CONFIGURATION_ERROR = 7;
public static final int MMS_ERROR_NO_DATA_NETWORK = 8;
/** Intent extra name for MMS sending result data in byte array type */
public static final String EXTRA_MMS_DATA = "android.telephony.extra.MMS_DATA";
/** Intent extra name for HTTP status code for MMS HTTP failure in integer type */
public static final String EXTRA_MMS_HTTP_STATUS = "android.telephony.extra.MMS_HTTP_STATUS";
/**
* Import a text message into system's SMS store
*
* Only default SMS apps can import SMS
*
* @param address the destination(source) address of the sent(received) message
* @param type the type of the message
* @param text the message text
* @param timestampMillis the message timestamp in milliseconds
* @param seen if the message is seen
* @param read if the message is read
* @return the message URI, null if failed
* @hide
*/
public Uri importTextMessage(String address, int type, String text, long timestampMillis,
boolean seen, boolean read) {
try {
IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
if (iMms != null) {
return iMms.importTextMessage(ActivityThread.currentPackageName(),
address, type, text, timestampMillis, seen, read);
}
} catch (RemoteException ex) {
// ignore it
}
return null;
}
/** Represents the received SMS message for importing {@hide} */
public static final int SMS_TYPE_INCOMING = 0;
/** Represents the sent SMS message for importing {@hide} */
public static final int SMS_TYPE_OUTGOING = 1;
/**
* Import a multimedia message into system's MMS store. Only the following PDU type is
* supported: Retrieve.conf, Send.req, Notification.ind, Delivery.ind, Read-Orig.ind
*
* Only default SMS apps can import MMS
*
* @param contentUri the content uri from which to read the PDU of the message to import
* @param messageId the optional message id. Use null if not specifying
* @param timestampSecs the optional message timestamp. Use -1 if not specifying
* @param seen if the message is seen
* @param read if the message is read
* @return the message URI, null if failed
* @throws IllegalArgumentException if pdu is empty
* {@hide}
*/
public Uri importMultimediaMessage(Uri contentUri, String messageId, long timestampSecs,
boolean seen, boolean read) {
if (contentUri == null) {
throw new IllegalArgumentException("Uri contentUri null");
}
try {
IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
if (iMms != null) {
return iMms.importMultimediaMessage(ActivityThread.currentPackageName(),
contentUri, messageId, timestampSecs, seen, read);
}
} catch (RemoteException ex) {
// ignore it
}
return null;
}
/**
* Delete a system stored SMS or MMS message
*
* Only default SMS apps can delete system stored SMS and MMS messages
*
* @param messageUri the URI of the stored message
* @return true if deletion is successful, false otherwise
* @throws IllegalArgumentException if messageUri is empty
* {@hide}
*/
public boolean deleteStoredMessage(Uri messageUri) {
if (messageUri == null) {
throw new IllegalArgumentException("Empty message URI");
}
try {
IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
if (iMms != null) {
return iMms.deleteStoredMessage(ActivityThread.currentPackageName(), messageUri);
}
} catch (RemoteException ex) {
// ignore it
}
return false;
}
/**
* Delete a system stored SMS or MMS thread
*
* Only default SMS apps can delete system stored SMS and MMS conversations
*
* @param conversationId the ID of the message conversation
* @return true if deletion is successful, false otherwise
* {@hide}
*/
public boolean deleteStoredConversation(long conversationId) {
try {
IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
if (iMms != null) {
return iMms.deleteStoredConversation(
ActivityThread.currentPackageName(), conversationId);
}
} catch (RemoteException ex) {
// ignore it
}
return false;
}
/**
* Update the status properties of a system stored SMS or MMS message, e.g.
* the read status of a message, etc.
*
* @param messageUri the URI of the stored message
* @param statusValues a list of status properties in key-value pairs to update
* @return true if update is successful, false otherwise
* @throws IllegalArgumentException if messageUri is empty
* {@hide}
*/
public boolean updateStoredMessageStatus(Uri messageUri, ContentValues statusValues) {
if (messageUri == null) {
throw new IllegalArgumentException("Empty message URI");
}
try {
IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
if (iMms != null) {
return iMms.updateStoredMessageStatus(ActivityThread.currentPackageName(),
messageUri, statusValues);
}
} catch (RemoteException ex) {
// ignore it
}
return false;
}
/** Message status property: whether the message has been seen. 1 means seen, 0 not {@hide} */
public static final String MESSAGE_STATUS_SEEN = "seen";
/** Message status property: whether the message has been read. 1 means read, 0 not {@hide} */
public static final String MESSAGE_STATUS_READ = "read";
/**
* Archive or unarchive a stored conversation
*
* @param conversationId the ID of the message conversation
* @param archived true to archive the conversation, false to unarchive
* @return true if update is successful, false otherwise
* {@hide}
*/
public boolean archiveStoredConversation(long conversationId, boolean archived) {
try {
IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
if (iMms != null) {
return iMms.archiveStoredConversation(ActivityThread.currentPackageName(),
conversationId, archived);
}
} catch (RemoteException ex) {
// ignore it
}
return false;
}
/**
* Add a text message draft to system SMS store
*
* Only default SMS apps can add SMS draft
*
* @param address the destination address of message
* @param text the body of the message to send
* @return the URI of the stored draft message
* {@hide}
*/
public Uri addTextMessageDraft(String address, String text) {
try {
IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
if (iMms != null) {
return iMms.addTextMessageDraft(ActivityThread.currentPackageName(), address, text);
}
} catch (RemoteException ex) {
// ignore it
}
return null;
}
/**
* Add a multimedia message draft to system MMS store
*
* Only default SMS apps can add MMS draft
*
* @param contentUri the content uri from which to read the PDU data of the draft MMS
* @return the URI of the stored draft message
* @throws IllegalArgumentException if pdu is empty
* {@hide}
*/
public Uri addMultimediaMessageDraft(Uri contentUri) {
if (contentUri == null) {
throw new IllegalArgumentException("Uri contentUri null");
}
try {
IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
if (iMms != null) {
return iMms.addMultimediaMessageDraft(ActivityThread.currentPackageName(),
contentUri);
}
} catch (RemoteException ex) {
// ignore it
}
return null;
}
/**
* Send a system stored text message.
*
* You can only send a failed text message or a draft text message.
*
* @param messageUri the URI of the stored message
* @param scAddress is the service center address or null to use the current default SMSC
* @param sentIntent if not NULL this PendingIntent
is
* broadcast when the message is successfully sent, or failed.
* The result code will be Activity.RESULT_OK
for success,
* or one of these errors:
* RESULT_ERROR_GENERIC_FAILURE
* RESULT_ERROR_RADIO_OFF
* RESULT_ERROR_NULL_PDU
* For RESULT_ERROR_GENERIC_FAILURE
the sentIntent may include
* the extra "errorCode" containing a radio technology specific value,
* generally only useful for troubleshooting.
* The per-application based SMS control checks sentIntent. If sentIntent
* is NULL the caller will be checked against all unknown applications,
* which cause smaller number of SMS to be sent in checking period.
* @param deliveryIntent if not NULL this PendingIntent
is
* broadcast when the message is delivered to the recipient. The
* raw pdu of the status report is in the extended data ("pdu").
*
* @throws IllegalArgumentException if messageUri is empty
* {@hide}
*/
public void sendStoredTextMessage(Uri messageUri, String scAddress, PendingIntent sentIntent,
PendingIntent deliveryIntent) {
if (messageUri == null) {
throw new IllegalArgumentException("Empty message URI");
}
try {
ISms iccISms = getISmsServiceOrThrow();
iccISms.sendStoredText(
getSubscriptionId(), ActivityThread.currentPackageName(), messageUri,
scAddress, sentIntent, deliveryIntent);
} catch (RemoteException ex) {
// ignore it
}
}
/**
* Send a system stored multi-part text message.
*
* You can only send a failed text message or a draft text message.
* The provided PendingIntent
lists should match the part number of the
* divided text of the stored message by using divideMessage
*
* @param messageUri the URI of the stored message
* @param scAddress is the service center address or null to use
* the current default SMSC
* @param sentIntents if not null, an ArrayList
of
* PendingIntent
s (one for each message part) that is
* broadcast when the corresponding message part has been sent.
* The result code will be Activity.RESULT_OK
for success,
* or one of these errors:
* RESULT_ERROR_GENERIC_FAILURE
* RESULT_ERROR_RADIO_OFF
* RESULT_ERROR_NULL_PDU
* For RESULT_ERROR_GENERIC_FAILURE
each sentIntent may include
* the extra "errorCode" containing a radio technology specific value,
* generally only useful for troubleshooting.
* The per-application based SMS control checks sentIntent. If sentIntent
* is NULL the caller will be checked against all unknown applications,
* which cause smaller number of SMS to be sent in checking period.
* @param deliveryIntents if not null, an ArrayList
of
* PendingIntent
s (one for each message part) that is
* broadcast when the corresponding message part has been delivered
* to the recipient. The raw pdu of the status report is in the
* extended data ("pdu").
*
* @throws IllegalArgumentException if messageUri is empty
* {@hide}
*/
public void sendStoredMultipartTextMessage(Uri messageUri, String scAddress,
ArrayListPendingIntent
is
* broadcast when the message is successfully sent, or failed
* @throws IllegalArgumentException if messageUri is empty
* {@hide}
*/
public void sendStoredMultimediaMessage(Uri messageUri, Bundle configOverrides,
PendingIntent sentIntent) {
if (messageUri == null) {
throw new IllegalArgumentException("Empty message URI");
}
try {
IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
if (iMms != null) {
iMms.sendStoredMessage(
getSubscriptionId(), ActivityThread.currentPackageName(), messageUri,
configOverrides, sentIntent);
}
} catch (RemoteException ex) {
// ignore it
}
}
/**
* Turns on/off the flag to automatically write sent/received SMS/MMS messages into system
*
* When this flag is on, all SMS/MMS sent/received are stored by system automatically
* When this flag is off, only SMS/MMS sent by non-default SMS apps are stored by system
* automatically
*
* This flag can only be changed by default SMS apps
*
* @param enabled Whether to enable message auto persisting
* {@hide}
*/
public void setAutoPersisting(boolean enabled) {
try {
IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
if (iMms != null) {
iMms.setAutoPersisting(ActivityThread.currentPackageName(), enabled);
}
} catch (RemoteException ex) {
// ignore it
}
}
/**
* Get the value of the flag to automatically write sent/received SMS/MMS messages into system
*
* When this flag is on, all SMS/MMS sent/received are stored by system automatically
* When this flag is off, only SMS/MMS sent by non-default SMS apps are stored by system
* automatically
*
* @return the current value of the auto persist flag
* {@hide}
*/
public boolean getAutoPersisting() {
try {
IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
if (iMms != null) {
return iMms.getAutoPersisting();
}
} catch (RemoteException ex) {
// ignore it
}
return false;
}
/**
* Get carrier-dependent configuration values.
*
* @return bundle key/values pairs of configuration values
*/
public Bundle getCarrierConfigValues() {
try {
IMms iMms = IMms.Stub.asInterface(ServiceManager.getService("imms"));
if (iMms != null) {
return iMms.getCarrierConfigValues(getSubscriptionId());
}
} catch (RemoteException ex) {
// ignore it
}
return null;
}
/**
* Filters a bundle to only contain MMS config variables.
*
* This is for use with bundles returned by {@link CarrierConfigManager} which contain MMS
* config and unrelated config. It is assumed that all MMS_CONFIG_* keys are present in the
* supplied bundle.
*
* @param config a Bundle that contains MMS config variables and possibly more.
* @return a new Bundle that only contains the MMS_CONFIG_* keys defined above.
* @hide
*/
public static Bundle getMmsConfig(BaseBundle config) {
Bundle filtered = new Bundle();
filtered.putBoolean(MMS_CONFIG_APPEND_TRANSACTION_ID,
config.getBoolean(MMS_CONFIG_APPEND_TRANSACTION_ID));
filtered.putBoolean(MMS_CONFIG_MMS_ENABLED, config.getBoolean(MMS_CONFIG_MMS_ENABLED));
filtered.putBoolean(MMS_CONFIG_GROUP_MMS_ENABLED,
config.getBoolean(MMS_CONFIG_GROUP_MMS_ENABLED));
filtered.putBoolean(MMS_CONFIG_NOTIFY_WAP_MMSC_ENABLED,
config.getBoolean(MMS_CONFIG_NOTIFY_WAP_MMSC_ENABLED));
filtered.putBoolean(MMS_CONFIG_ALIAS_ENABLED, config.getBoolean(MMS_CONFIG_ALIAS_ENABLED));
filtered.putBoolean(MMS_CONFIG_ALLOW_ATTACH_AUDIO,
config.getBoolean(MMS_CONFIG_ALLOW_ATTACH_AUDIO));
filtered.putBoolean(MMS_CONFIG_MULTIPART_SMS_ENABLED,
config.getBoolean(MMS_CONFIG_MULTIPART_SMS_ENABLED));
filtered.putBoolean(MMS_CONFIG_SMS_DELIVERY_REPORT_ENABLED,
config.getBoolean(MMS_CONFIG_SMS_DELIVERY_REPORT_ENABLED));
filtered.putBoolean(MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION,
config.getBoolean(MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION));
filtered.putBoolean(MMS_CONFIG_SEND_MULTIPART_SMS_AS_SEPARATE_MESSAGES,
config.getBoolean(MMS_CONFIG_SEND_MULTIPART_SMS_AS_SEPARATE_MESSAGES));
filtered.putBoolean(MMS_CONFIG_MMS_READ_REPORT_ENABLED,
config.getBoolean(MMS_CONFIG_MMS_READ_REPORT_ENABLED));
filtered.putBoolean(MMS_CONFIG_MMS_DELIVERY_REPORT_ENABLED,
config.getBoolean(MMS_CONFIG_MMS_DELIVERY_REPORT_ENABLED));
filtered.putBoolean(MMS_CONFIG_CLOSE_CONNECTION,
config.getBoolean(MMS_CONFIG_CLOSE_CONNECTION));
filtered.putInt(MMS_CONFIG_MAX_MESSAGE_SIZE, config.getInt(MMS_CONFIG_MAX_MESSAGE_SIZE));
filtered.putInt(MMS_CONFIG_MAX_IMAGE_WIDTH, config.getInt(MMS_CONFIG_MAX_IMAGE_WIDTH));
filtered.putInt(MMS_CONFIG_MAX_IMAGE_HEIGHT, config.getInt(MMS_CONFIG_MAX_IMAGE_HEIGHT));
filtered.putInt(MMS_CONFIG_RECIPIENT_LIMIT, config.getInt(MMS_CONFIG_RECIPIENT_LIMIT));
filtered.putInt(MMS_CONFIG_ALIAS_MIN_CHARS, config.getInt(MMS_CONFIG_ALIAS_MIN_CHARS));
filtered.putInt(MMS_CONFIG_ALIAS_MAX_CHARS, config.getInt(MMS_CONFIG_ALIAS_MAX_CHARS));
filtered.putInt(MMS_CONFIG_SMS_TO_MMS_TEXT_THRESHOLD,
config.getInt(MMS_CONFIG_SMS_TO_MMS_TEXT_THRESHOLD));
filtered.putInt(MMS_CONFIG_SMS_TO_MMS_TEXT_LENGTH_THRESHOLD,
config.getInt(MMS_CONFIG_SMS_TO_MMS_TEXT_LENGTH_THRESHOLD));
filtered.putInt(MMS_CONFIG_MESSAGE_TEXT_MAX_SIZE,
config.getInt(MMS_CONFIG_MESSAGE_TEXT_MAX_SIZE));
filtered.putInt(MMS_CONFIG_SUBJECT_MAX_LENGTH,
config.getInt(MMS_CONFIG_SUBJECT_MAX_LENGTH));
filtered.putInt(MMS_CONFIG_HTTP_SOCKET_TIMEOUT,
config.getInt(MMS_CONFIG_HTTP_SOCKET_TIMEOUT));
filtered.putString(MMS_CONFIG_UA_PROF_TAG_NAME,
config.getString(MMS_CONFIG_UA_PROF_TAG_NAME));
filtered.putString(MMS_CONFIG_USER_AGENT, config.getString(MMS_CONFIG_USER_AGENT));
filtered.putString(MMS_CONFIG_UA_PROF_URL, config.getString(MMS_CONFIG_UA_PROF_URL));
filtered.putString(MMS_CONFIG_HTTP_PARAMS, config.getString(MMS_CONFIG_HTTP_PARAMS));
filtered.putString(MMS_CONFIG_EMAIL_GATEWAY_NUMBER,
config.getString(MMS_CONFIG_EMAIL_GATEWAY_NUMBER));
filtered.putString(MMS_CONFIG_NAI_SUFFIX, config.getString(MMS_CONFIG_NAI_SUFFIX));
filtered.putBoolean(MMS_CONFIG_SHOW_CELL_BROADCAST_APP_LINKS,
config.getBoolean(MMS_CONFIG_SHOW_CELL_BROADCAST_APP_LINKS));
filtered.putBoolean(MMS_CONFIG_SUPPORT_HTTP_CHARSET_HEADER,
config.getBoolean(MMS_CONFIG_SUPPORT_HTTP_CHARSET_HEADER));
return filtered;
}
}