From e6de81fd25afb40590a9757e709fe835d99c7181 Mon Sep 17 00:00:00 2001 From: Brad Ebinger Date: Wed, 6 Mar 2019 14:32:28 -0800 Subject: [PATCH] Fix NPE in SmsManager and keep existing behavior The behavior of SmsManager#sendTextMessage changed, we are blocking the sending of the SMS if there were no subscriptions (i.e. no SIM scenario). This change accidently introduced a NPE scenario in some cases. Fixed NPE and removed SMS blocking code in SmsManager to keep existing functionality the same. Bug: 127338050 Test: atest GtsTelephonyTestCases Change-Id: I71eefbc8e1619701e1b1d7b12c3c080c4ef376ef --- .../java/android/telephony/SmsManager.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/telephony/java/android/telephony/SmsManager.java b/telephony/java/android/telephony/SmsManager.java index d777bf123b67d..c39f1f5613b05 100644 --- a/telephony/java/android/telephony/SmsManager.java +++ b/telephony/java/android/telephony/SmsManager.java @@ -316,6 +316,7 @@ public final class SmsManager { * 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.
@@ -365,19 +366,12 @@ public final class SmsManager { if (DBG) { Log.d(TAG, "for subId: " + subId + ", subscription-info: " + info); } - if (info == null) { - // There is no subscription for the given subId. That can only mean one thing: - // the caller is using a SmsManager instance with an obsolete subscription id. - // That is most probably because caller didn't invalidate SmsManager instance - // for an already deleted subscription id. - Log.e(TAG, "subId: " + subId + " for this SmsManager instance is obsolete."); - sendErrorInPendingIntent(sentIntent, SmsManager.RESULT_ERROR_NO_SERVICE); - } /* If the Subscription associated with this SmsManager instance belongs to a remote-sim, * then send the message thru the remote-sim subscription. */ - if (info.getSubscriptionType() == SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM) { + if (info != null + && info.getSubscriptionType() == SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM) { if (DBG) Log.d(TAG, "sending message thru bluetooth"); sendTextMessageBluetooth(destinationAddress, scAddress, text, sentIntent, deliveryIntent, info); @@ -385,8 +379,10 @@ public final class SmsManager { } try { + // If the subscription is invalid or default, we will use the default phone to send the + // SMS and possibly fail later in the SMS sending process. ISms iccISms = getISmsServiceOrThrow(); - iccISms.sendTextForSubscriber(getSubscriptionId(), ActivityThread.currentPackageName(), + iccISms.sendTextForSubscriber(subId, ActivityThread.currentPackageName(), destinationAddress, scAddress, text, sentIntent, deliveryIntent, persistMessage); @@ -459,6 +455,9 @@ public final class SmsManager { } private void sendErrorInPendingIntent(PendingIntent intent, int errorCode) { + if (intent == null) { + return; + } try { intent.send(errorCode); } catch (PendingIntent.CanceledException e) {