/* * 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.annotation.CallbackExecutor; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SuppressAutoDoc; import android.annotation.SystemApi; import android.annotation.TestApi; import android.annotation.UnsupportedAppUsage; import android.app.ActivityThread; import android.app.PendingIntent; import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.database.CursorWindow; import android.net.Uri; import android.os.BaseBundle; import android.os.Binder; import android.os.Build; import android.os.Bundle; import android.os.RemoteException; import android.os.ServiceManager; import android.provider.Telephony; import android.text.TextUtils; import android.util.ArrayMap; import android.util.Log; import com.android.internal.telephony.IIntegerConsumer; import com.android.internal.telephony.IMms; import com.android.internal.telephony.ISms; import com.android.internal.telephony.ITelephony; import com.android.internal.telephony.SmsRawData; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.Executor; /* * 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()}. To create an instance of * {@link SmsManager} associated with a specific subscription ID, call * {@link #getSmsManagerForSubscriptionId(int)}. This is typically used for devices that support * multiple active subscriptions at once. * *
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}.
*
* @see SubscriptionManager#getActiveSubscriptionInfoList()
*/
public final class SmsManager {
private static final String TAG = "SmsManager";
/** Singleton object constructed during class initialization. */
private static final SmsManager sInstance = new SmsManager(
SubscriptionManager.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;
/** SMS record length from TS 51.011 10.5.3
* @hide
*/
public static final int SMS_RECORD_LENGTH = 176;
/** SMS record length from C.S0023 3.4.27
* @hide
*/
public static final int CDMA_SMS_RECORD_LENGTH = 255;
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}. Note: If {@link #getDefault()} is used to instantiate this
* manager on a multi-SIM device, this operation may fail sending the SMS message because no
* suitable default subscription could be found. In this case, if {@code sentIntent} is
* non-null, then the {@link PendingIntent} will be sent with an error code
* {@code RESULT_ERROR_GENERIC_FAILURE} and an extra string {@code "noDefault"} containing the
* boolean value {@code true}. See {@link #getDefault()} for more information on the conditions
* where this operation may fail.
*
* The message will be sent directly over the network and will not be visible in SMS
* applications. Intended for internal carrier use only.
* Requires Permission: Both {@link android.Manifest.permission#SEND_SMS} and
* {@link android.Manifest.permission#MODIFY_PHONE_STATE}, or that the calling app has carrier
* privileges (see {@link TelephonyManager#hasCarrierPrivileges}), or that the calling app is
* the default IMS app (see
* {@link CarrierConfigManager#KEY_CONFIG_IMS_PACKAGE_OVERRIDE_STRING}).
* Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the SMS being sent on the subscription associated with logical
* slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the SMS is sent on the
* correct subscription.
* Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the SMS being sent on the subscription associated with logical
* slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the SMS is sent on the
* correct subscription.
* Note: If {@link #getDefault()} is used to instantiate this
* manager on a multi-SIM device, this operation may fail sending the SMS message because no
* suitable default subscription could be found. In this case, if {@code sentIntent} is
* non-null, then the {@link PendingIntent} will be sent with an error code
* {@code RESULT_ERROR_GENERIC_FAILURE} and an extra string {@code "noDefault"} containing the
* boolean value {@code true}. See {@link #getDefault()} for more information on the conditions
* where this operation may fail.
* Requires Permission:
* {@link android.Manifest.permission#MODIFY_PHONE_STATE} or the calling app has carrier
* privileges.
* Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the SMS being sent on the subscription associated with logical
* slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the SMS is sent on the
* correct subscription.
* Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} or carrier
* privileges per {@link android.telephony.TelephonyManager#hasCarrierPrivileges}.
*
* Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the SMS being injected on the subscription associated with
* logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the SMS is
* delivered to the correct subscription.
* 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}. Note: If {@link #getDefault()} is used to instantiate this
* manager on a multi-SIM device, this operation may fail sending the SMS message because no
* suitable default subscription could be found. In this case, if {@code sentIntent} is
* non-null, then the {@link PendingIntent} will be sent with an error code
* {@code RESULT_ERROR_GENERIC_FAILURE} and an extra string {@code "noDefault"} containing the
* boolean value {@code true}. See {@link #getDefault()} for more information on the conditions
* where this operation may fail.
* Note: This method is intended for internal use the Telephony
* framework and will never trigger an SMS disambiguation dialog. If this method is called on a
* device that has multiple active subscriptions, this {@link SmsManager} instance has been
* created with {@link #getDefault()}, and no user-defined default subscription is defined, the
* subscription ID associated with this message will be INVALID, which will result in the SMS
* being sent on the subscription associated with logical slot 0. Use
* {@link #getSmsManagerForSubscriptionId(int)} to ensure the SMS is sent on the correct
* subscription.
*
* If this method is called on a device with multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the SMS sent on the subscription associated with slot
* 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the SMS is sent using the
* correct subscription.
* Requires Permission:
* {@link android.Manifest.permission#MODIFY_PHONE_STATE} or the calling app has carrier
* privileges.
* 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}. Note: If {@link #getDefault()} is used to instantiate this
* manager on a multi-SIM device, this operation may fail sending the SMS message because no
* suitable default subscription could be found. In this case, if {@code sentIntent} is
* non-null, then the {@link PendingIntent} will be sent with an error code
* {@code RESULT_ERROR_GENERIC_FAILURE} and an extra string {@code "noDefault"} containing the
* boolean value {@code true}. See {@link #getDefault()} for more information on the conditions
* where this operation may fail.
* Requires Permission:
* {@link android.Manifest.permission#MODIFY_PHONE_STATE} or the calling app has carrier
* privileges.
* Note: This method is intended for internal use the Telephony
* framework and will never trigger an SMS disambiguation dialog. If this method is called on a
* device that has multiple active subscriptions, this {@link SmsManager} instance has been
* created with {@link #getDefault()}, and no user-defined default subscription is defined, the
* subscription ID associated with this message will be INVALID, which will result in the SMS
* being sent on the subscription associated with logical slot 0. Use
* {@link #getSmsManagerForSubscriptionId(int)} to ensure the SMS is sent on the correct
* subscription.
* Note: Using this method requires that your app has the
* {@link android.Manifest.permission#SEND_SMS} permission. Note: If {@link #getDefault()} is used to instantiate this
* manager on a multi-SIM device, this operation may fail sending the SMS message because no
* suitable default subscription could be found. In this case, if {@code sentIntent} is
* non-null, then the {@link PendingIntent} will be sent with an error code
* {@code RESULT_ERROR_GENERIC_FAILURE} and an extra string {@code "noDefault"} containing the
* boolean value {@code true}. See {@link #getDefault()} for more information on the conditions
* where this operation may fail.
* Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the SMS being sent on the subscription associated with logical
* slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the SMS is sent on the
* correct subscription.
* Note: For devices that support multiple active subscriptions
* at a time, SmsManager will track the subscription set by the user as the default SMS
* subscription. If the user has not set a default, {@link SmsManager} may
* start an activity to kick off a subscription disambiguation dialog. Most operations will not
* complete until the user has chosen the subscription that will be associated with the
* operation. If the user cancels the dialog without choosing a subscription, one of the
* following will happen, depending on the target SDK version of the application. For
* compatibility purposes, if the target SDK level is <= 28, telephony will still send the SMS
* over the first available subscription. If the target SDK level is > 28, the operation will
* fail to complete.
* Note: If this method is used to perform an operation on a
* device that has multiple active subscriptions, the user has not set a default SMS
* subscription, and the operation is being performed while the application is not in the
* foreground, the SMS disambiguation dialog will not be shown. The result of the operation will
* conclude as if the user cancelled the disambiguation dialog and the operation will finish as
* outlined above, depending on the target SDK version of the calling application. It is safer
* to use {@link #getSmsManagerForSubscriptionId(int)} if the application will perform the
* operation while in the background because this can cause unpredictable results, such as the
* operation being sent over the wrong subscription or failing completely, depending on the
* user's default SMS subscription setting.
* Note: Constructing an {@link SmsManager} in this manner will
* never cause an SMS disambiguation dialog to appear, unlike {@link #getDefault()}.
* Note: This method used to display a disambiguation dialog to
* the user asking them to choose a default subscription to send SMS messages over if they
* haven't chosen yet. Starting in API level 29, we allow the user to not have a default set as
* a valid option for the default SMS subscription on multi-SIM devices. We no longer show the
* disambiguation dialog and return {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} if the
* device has multiple active subscriptions and no default is set.
* pendingIntents) {
if (pendingIntents != null) {
for (PendingIntent pendingIntent : pendingIntents) {
Intent errorMessage = new Intent();
errorMessage.putExtra(NO_DEFAULT_EXTRA, true);
try {
pendingIntent.send(context, RESULT_ERROR_GENERIC_FAILURE, errorMessage);
} catch (PendingIntent.CanceledException e) {
// Don't worry about it, we do not need to notify the caller if this is the
// case.
}
}
}
}
private static void notifySmsGenericError(PendingIntent pendingIntent) {
if (pendingIntent != null) {
try {
pendingIntent.send(RESULT_ERROR_GENERIC_FAILURE);
} catch (PendingIntent.CanceledException e) {
// Don't worry about it, we do not need to notify the caller if this is the case.
}
}
}
private static void notifySmsGenericError(List Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID}, which will result in the operation
* being completed on the subscription associated with logical slot 0. Use
* {@link #getSmsManagerForSubscriptionId(int)} to ensure the operation is performed on the
* correct subscription.
* Requires {@link android.Manifest.permission#RECEIVE_EMERGENCY_BROADCAST} Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Requires {@link android.Manifest.permission#RECEIVE_EMERGENCY_BROADCAST} Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Note:This returns a value different from
* {@link SubscriptionManager#getDefaultSmsSubscriptionId} if the user has not chosen a default.
* In this case it returns the active subscription id if there's only one active subscription
* available.
*
* @return the user-defined default SMS subscription id, or the active subscription id if
* there's only one active subscription available, otherwise
* {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID}.
*/
public static int getDefaultSmsSubscriptionId() {
try {
return getISmsService().getPreferredSmsSubscription();
} catch (RemoteException e) {
return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
} catch (NullPointerException e) {
return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
}
}
/**
* Get SMS prompt property, enabled or not
*
* @return true if enabled, false otherwise
* @hide
*/
@UnsupportedAppUsage
public boolean isSMSPromptEnabled() {
ISms iSms = null;
try {
iSms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
return iSms.isSMSPromptEnabled();
} catch (RemoteException ex) {
return false;
} catch (NullPointerException ex) {
return false;
}
}
// see SmsMessage.getStatusOnIcc
/** Free space (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
static public final int STATUS_ON_ICC_FREE = 0;
/** Received and read (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
static public final int STATUS_ON_ICC_READ = 1;
/** Received and unread (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
static public final int STATUS_ON_ICC_UNREAD = 3;
/** Stored and sent (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
static public final int STATUS_ON_ICC_SENT = 5;
/** Stored and unsent (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
static public final int STATUS_ON_ICC_UNSENT = 7;
// SMS send failure result codes
/**
* No error.
* @hide
*/
@SystemApi
static public final int RESULT_ERROR_NONE = 0;
/** Generic failure cause */
static public final int RESULT_ERROR_GENERIC_FAILURE = 1;
/** Failed because radio was explicitly turned off */
static public final int RESULT_ERROR_RADIO_OFF = 2;
/** Failed because no pdu provided */
static public final int RESULT_ERROR_NULL_PDU = 3;
/** Failed because service is currently unavailable */
static public final int RESULT_ERROR_NO_SERVICE = 4;
/** Failed because we reached the sending queue limit. */
static public final int RESULT_ERROR_LIMIT_EXCEEDED = 5;
/**
* Failed because FDN is enabled.
* @hide
*/
@SystemApi
static public final int RESULT_ERROR_FDN_CHECK_FAILURE = 6;
/** Failed because user denied the sending of this short code. */
static public final int RESULT_ERROR_SHORT_CODE_NOT_ALLOWED = 7;
/** Failed because the user has denied this app ever send premium short codes. */
static public final int RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED = 8;
/**
* Failed because the radio was not available
* @hide
*/
@SystemApi
static public final int RESULT_RADIO_NOT_AVAILABLE = 9;
/**
* Failed because of network rejection
* @hide
*/
@SystemApi
static public final int RESULT_NETWORK_REJECT = 10;
/**
* Failed because of invalid arguments
* @hide
*/
@SystemApi
static public final int RESULT_INVALID_ARGUMENTS = 11;
/**
* Failed because of an invalid state
* @hide
*/
@SystemApi
static public final int RESULT_INVALID_STATE = 12;
/**
* Failed because there is no memory
* @hide
*/
@SystemApi
static public final int RESULT_NO_MEMORY = 13;
/**
* Failed because the sms format is not valid
* @hide
*/
@SystemApi
static public final int RESULT_INVALID_SMS_FORMAT = 14;
/**
* Failed because of a system error
* @hide
*/
@SystemApi
static public final int RESULT_SYSTEM_ERROR = 15;
/**
* Failed because of a modem error
* @hide
*/
@SystemApi
static public final int RESULT_MODEM_ERROR = 16;
/**
* Failed because of a network error
* @hide
*/
@SystemApi
static public final int RESULT_NETWORK_ERROR = 17;
/**
* Failed because of an encoding error
* @hide
*/
@SystemApi
static public final int RESULT_ENCODING_ERROR = 18;
/**
* Failed because of an invalid smsc address
* @hide
*/
@SystemApi
static public final int RESULT_INVALID_SMSC_ADDRESS = 19;
/**
* Failed because the operation is not allowed
* @hide
*/
@SystemApi
static public final int RESULT_OPERATION_NOT_ALLOWED = 20;
/**
* Failed because of an internal error
* @hide
*/
@SystemApi
static public final int RESULT_INTERNAL_ERROR = 21;
/**
* Failed because there are no resources
* @hide
*/
@SystemApi
static public final int RESULT_NO_RESOURCES = 22;
/**
* Failed because the operation was cancelled
* @hide
*/
@SystemApi
static public final int RESULT_CANCELLED = 23;
/**
* Failed because the request is not supported
* @hide
*/
@SystemApi
static public final int RESULT_REQUEST_NOT_SUPPORTED = 24;
static private final String PHONE_PACKAGE_NAME = "com.android.phone";
/**
* Send an MMS message
*
* Note: This method will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Note: This method will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Note: If {@link #getDefault()} is used to instantiate this
* manager on a multi-SIM device, this operation may fail sending the SMS message because no
* suitable default subscription could be found. In this case, if {@code sentIntent} is
* non-null, then the {@link PendingIntent} will be sent with an error code
* {@code RESULT_ERROR_GENERIC_FAILURE} and an extra string {@code "noDefault"} containing the
* boolean value {@code true}. See {@link #getDefault()} for more information on the conditions
* where this operation may fail.
* Note: If {@link #getDefault()} is used to instantiate this
* manager on a multi-SIM device, this operation may fail sending the SMS message because no
* suitable default subscription could be found. In this case, if {@code sentIntent} is
* non-null, then the {@link PendingIntent} will be sent with an error code
* {@code RESULT_ERROR_GENERIC_FAILURE} and an extra string {@code "noDefault"} containing the
* boolean value {@code true}. See {@link #getDefault()} for more information on the conditions
* where this operation may fail.
* Note: This method will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Note: This method will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Note: This method will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Note: This method will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* Note: This method is intended for internal use by carrier
* applications or the Telephony framework and will never trigger an SMS disambiguation
* dialog. If this method is called on a device that has multiple active subscriptions, this
* {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined
* default subscription is defined, the subscription ID associated with this message will be
* INVALID, which will result in the operation being completed on the subscription associated
* with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the
* operation is performed on the correct subscription.
* 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
* RESULT_ERROR_NO_SERVICE
* 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 /* persistMessage*/, ActivityThread.currentPackageName());
}
private void sendTextMessageInternal(String destinationAddress, String scAddress,
String text, PendingIntent sentIntent, PendingIntent deliveryIntent,
boolean persistMessage, String packageName) {
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (TextUtils.isEmpty(text)) {
throw new IllegalArgumentException("Invalid message body");
}
final Context context = ActivityThread.currentApplication().getApplicationContext();
// We will only show the SMS disambiguation dialog in the case that the message is being
// persisted. This is for two reasons:
// 1) Messages that are not persisted are sent by carrier/OEM apps for a specific
// subscription and require special permissions. These messages are usually not sent by
// the device user and should not have an SMS disambiguation dialog associated with them
// because the device user did not trigger them.
// 2) The SMS disambiguation dialog ONLY checks to make sure that the user has the SEND_SMS
// permission. If we call resolveSubscriptionForOperation from a carrier/OEM app that has
// the correct MODIFY_PHONE_STATE or carrier permissions, but no SEND_SMS, it will throw
// an incorrect SecurityException.
if (persistMessage) {
resolveSubscriptionForOperation(new SubscriptionResolverResult() {
@Override
public void onSuccess(int subId) {
ISms iSms = getISmsServiceOrThrow();
try {
iSms.sendTextForSubscriber(subId, packageName,
destinationAddress, scAddress, text, sentIntent, deliveryIntent,
persistMessage);
} catch (RemoteException e) {
Log.e(TAG, "sendTextMessageInternal: Couldn't send SMS, exception - "
+ e.getMessage());
notifySmsGenericError(sentIntent);
}
}
@Override
public void onFailure() {
notifySmsErrorNoDefaultSet(context, sentIntent);
}
});
} else {
// Not persisting the message, used by sendTextMessageWithoutPersisting() and is not
// visible to the user.
ISms iSms = getISmsServiceOrThrow();
try {
iSms.sendTextForSubscriber(getSubscriptionId(), packageName,
destinationAddress, scAddress, text, sentIntent, deliveryIntent,
persistMessage);
} catch (RemoteException e) {
Log.e(TAG, "sendTextMessageInternal (no persist): Couldn't send SMS, exception - "
+ e.getMessage());
notifySmsGenericError(sentIntent);
}
}
}
/**
* Send a text based SMS without writing it into the SMS Provider.
*
* 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").
* @param priority Priority level of the message
* Refer specification See 3GPP2 C.S0015-B, v2.0, table 4.5.9-1
* ---------------------------------
* PRIORITY | Level of Priority
* ---------------------------------
* '00' | Normal
* '01' | Interactive
* '10' | Urgent
* '11' | Emergency
* ----------------------------------
* Any Other values included Negative considered as Invalid Priority Indicator of the message.
* @param expectMore is a boolean to indicate the sending messages through same link or not.
* @param validityPeriod Validity Period of the message in mins.
* Refer specification 3GPP TS 23.040 V6.8.1 section 9.2.3.12.1.
* Validity Period(Minimum) -> 5 mins
* Validity Period(Maximum) -> 635040 mins(i.e.63 weeks).
* Any Other values included Negative considered as Invalid Validity Period of the message.
*
* @throws IllegalArgumentException if destinationAddress or text are empty
* {@hide}
*/
@UnsupportedAppUsage
public void sendTextMessage(
String destinationAddress, String scAddress, String text,
PendingIntent sentIntent, PendingIntent deliveryIntent,
int priority, boolean expectMore, int validityPeriod) {
sendTextMessageInternal(destinationAddress, scAddress, text, sentIntent, deliveryIntent,
true /* persistMessage*/, priority, expectMore, validityPeriod);
}
private void sendTextMessageInternal(
String destinationAddress, String scAddress, String text,
PendingIntent sentIntent, PendingIntent deliveryIntent, boolean persistMessage,
int priority, boolean expectMore, int validityPeriod) {
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (TextUtils.isEmpty(text)) {
throw new IllegalArgumentException("Invalid message body");
}
if (priority < 0x00 || priority > 0x03) {
priority = SMS_MESSAGE_PRIORITY_NOT_SPECIFIED;
}
if (validityPeriod < 0x05 || validityPeriod > 0x09b0a0) {
validityPeriod = SMS_MESSAGE_PERIOD_NOT_SPECIFIED;
}
final int finalPriority = priority;
final int finalValidity = validityPeriod;
final Context context = ActivityThread.currentApplication().getApplicationContext();
// We will only show the SMS disambiguation dialog in the case that the message is being
// persisted. This is for two reasons:
// 1) Messages that are not persisted are sent by carrier/OEM apps for a specific
// subscription and require special permissions. These messages are usually not sent by
// the device user and should not have an SMS disambiguation dialog associated with them
// because the device user did not trigger them.
// 2) The SMS disambiguation dialog ONLY checks to make sure that the user has the SEND_SMS
// permission. If we call resolveSubscriptionForOperation from a carrier/OEM app that has
// the correct MODIFY_PHONE_STATE or carrier permissions, but no SEND_SMS, it will throw
// an incorrect SecurityException.
if (persistMessage) {
resolveSubscriptionForOperation(new SubscriptionResolverResult() {
@Override
public void onSuccess(int subId) {
try {
ISms iSms = getISmsServiceOrThrow();
if (iSms != null) {
iSms.sendTextForSubscriberWithOptions(subId,
ActivityThread.currentPackageName(), destinationAddress,
scAddress,
text, sentIntent, deliveryIntent, persistMessage, finalPriority,
expectMore, finalValidity);
}
} catch (RemoteException e) {
Log.e(TAG, "sendTextMessageInternal: Couldn't send SMS, exception - "
+ e.getMessage());
notifySmsGenericError(sentIntent);
}
}
@Override
public void onFailure() {
notifySmsErrorNoDefaultSet(context, sentIntent);
}
});
} else {
try {
ISms iSms = getISmsServiceOrThrow();
if (iSms != null) {
iSms.sendTextForSubscriberWithOptions(getSubscriptionId(),
ActivityThread.currentPackageName(), destinationAddress,
scAddress,
text, sentIntent, deliveryIntent, persistMessage, finalPriority,
expectMore, finalValidity);
}
} catch (RemoteException e) {
Log.e(TAG, "sendTextMessageInternal(no persist): Couldn't send SMS, exception - "
+ e.getMessage());
notifySmsGenericError(sentIntent);
}
}
}
/**
* 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 {@link android.provider.Telephony.Sms.Intents#RESULT_SMS_HANDLED}
* for success, or {@link android.provider.Telephony.Sms.Intents#RESULT_SMS_GENERIC_ERROR} for
* error.
*
* @throws IllegalArgumentException if the format is invalid.
*/
public void injectSmsPdu(
byte[] pdu, @SmsMessage.Format 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 iSms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (iSms != null) {
iSms.injectSmsPduForSubscriber(
getSubscriptionId(), pdu, format, receivedIntent);
}
} catch (RemoteException ex) {
try {
if (receivedIntent != null) {
receivedIntent.send(Telephony.Sms.Intents.RESULT_SMS_GENERIC_ERROR);
}
} catch (PendingIntent.CanceledException cx) {
// Don't worry about it, we do not need to notify the caller if this is the case.
}
}
}
/**
* 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
* PendingIntents (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
* PendingIntents (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, ArrayListdivideMessage.
*
* ArrayList of strings that, in order,
* comprise the original message
* @param sentIntents if not null, an ArrayList of
* PendingIntents (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
* PendingIntents (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").
* @param priority Priority level of the message
* Refer specification See 3GPP2 C.S0015-B, v2.0, table 4.5.9-1
* ---------------------------------
* PRIORITY | Level of Priority
* ---------------------------------
* '00' | Normal
* '01' | Interactive
* '10' | Urgent
* '11' | Emergency
* ----------------------------------
* Any Other values included Negative considered as Invalid Priority Indicator of the message.
* @param expectMore is a boolean to indicate the sending messages through same link or not.
* @param validityPeriod Validity Period of the message in mins.
* Refer specification 3GPP TS 23.040 V6.8.1 section 9.2.3.12.1.
* Validity Period(Minimum) -> 5 mins
* Validity Period(Maximum) -> 635040 mins(i.e.63 weeks).
* Any Other values included Negative considered as Invalid Validity Period of the message.
*
* @throws IllegalArgumentException if destinationAddress or data are empty
* {@hide}
*/
@UnsupportedAppUsage
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");
}
final Context context = ActivityThread.currentApplication().getApplicationContext();
resolveSubscriptionForOperation(new SubscriptionResolverResult() {
@Override
public void onSuccess(int subId) {
try {
ISms iSms = getISmsServiceOrThrow();
iSms.sendDataForSubscriber(subId, ActivityThread.currentPackageName(),
destinationAddress, scAddress, destinationPort & 0xFFFF, data,
sentIntent, deliveryIntent);
} catch (RemoteException e) {
Log.e(TAG, "sendDataMessage: Couldn't send SMS - Exception: " + e.getMessage());
notifySmsGenericError(sentIntent);
}
}
@Override
public void onFailure() {
notifySmsErrorNoDefaultSet(context, sentIntent);
}
});
}
/**
* A variant of {@link SmsManager#sendDataMessage} that allows self to be the caller. This is
* for internal use only.
*
* ArrayList of SmsMessage objects
*
* {@hide}
*/
@UnsupportedAppUsage
public ArrayListSmsMessages from a list of RawSmsData
* records returned by getAllMessagesFromIcc()
*
* getAllMessagesFromIcc
* @return ArrayList of SmsMessage objects.
*/
private 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
*
* 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.
*
* 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");
}
final Context context = ActivityThread.currentApplication().getApplicationContext();
resolveSubscriptionForOperation(new SubscriptionResolverResult() {
@Override
public void onSuccess(int subId) {
try {
ISms iSms = getISmsServiceOrThrow();
iSms.sendStoredText(subId, ActivityThread.currentPackageName(), messageUri,
scAddress, sentIntent, deliveryIntent);
} catch (RemoteException e) {
Log.e(TAG, "sendStoredTextMessage: Couldn't send SMS - Exception: "
+ e.getMessage());
notifySmsGenericError(sentIntent);
}
}
@Override
public void onFailure() {
notifySmsErrorNoDefaultSet(context, sentIntent);
}
});
}
/**
* 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
*
* ArrayList of
* PendingIntents (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
* PendingIntents (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.
*
*