diff options
author | Brad Ebinger <breadley@google.com> | 2017-05-25 15:35:20 -0700 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-05-30 20:57:03 +0000 |
commit | 734d42c46acf9ba143b24e98b74c4cdf9d93d82a (patch) | |
tree | 0c3e701e820020fb98be7a760d745a24c4a79ce4 | |
parent | e0ab20106511a01d05a6cd727f887e1ee0284edd (diff) | |
download | Telecomm-734d42c46acf9ba143b24e98b74c4cdf9d93d82a.tar.gz |
Use SmsManager for reject call with SMS
Instead of starting a service to send SMS when a call is
rejected, we now use the SmsManager#sendTextMessage API.
Bug: 62048610
Test: Reject call and send SMS
Change-Id: I8d648ab5c3e35539d1387ece4d11acc1c30c8ea2
(cherry picked from commit 90660b5f9a058c452aa41478feac23f656bb206c)
-rw-r--r-- | src/com/android/server/telecom/RespondViaSmsManager.java | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/src/com/android/server/telecom/RespondViaSmsManager.java b/src/com/android/server/telecom/RespondViaSmsManager.java index f10795611..88d49198f 100644 --- a/src/com/android/server/telecom/RespondViaSmsManager.java +++ b/src/com/android/server/telecom/RespondViaSmsManager.java @@ -18,15 +18,12 @@ package com.android.server.telecom; // TODO: Needed for move to system service: import com.android.internal.R; import com.android.internal.os.SomeArgs; -import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.SmsApplication; import android.content.ComponentName; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; -import android.net.Uri; import android.os.Handler; import android.os.Looper; import android.os.Message; @@ -34,10 +31,11 @@ import android.telecom.Connection; import android.telecom.Log; import android.telecom.Response; import android.telephony.PhoneNumberUtils; +import android.telephony.SmsManager; import android.telephony.SubscriptionManager; -import android.telephony.TelephonyManager; import android.text.Spannable; import android.text.SpannableString; +import android.text.TextUtils; import android.widget.Toast; import java.util.ArrayList; @@ -177,29 +175,28 @@ public class RespondViaSmsManager extends CallsManagerListenerBase { */ private void rejectCallWithMessage(Context context, String phoneNumber, String textMessage, int subId) { - if (textMessage != null) { - final ComponentName component = - SmsApplication.getDefaultRespondViaMessageApplication(context, - true /*updateIfNeeded*/); - if (component != null) { - // Build and send the intent - final Uri uri = Uri.fromParts(Constants.SCHEME_SMSTO, phoneNumber, null); - final Intent intent = new Intent(TelephonyManager.ACTION_RESPOND_VIA_MESSAGE, uri); - intent.putExtra(Intent.EXTRA_TEXT, textMessage); - if (SubscriptionManager.isValidSubscriptionId(subId)) { - intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId); - } - // Wakeup apps for the broadcast. - // TODO: Use SmsManager instead of an intent. - intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); - - SomeArgs args = SomeArgs.obtain(); - args.arg1 = phoneNumber; - args.arg2 = context; - mHandler.obtainMessage(MSG_SHOW_SENT_TOAST, args).sendToTarget(); - intent.setComponent(component); - context.startService(intent); - } + if (TextUtils.isEmpty(textMessage)) { + Log.w(RespondViaSmsManager.this, "Couldn't send SMS message: empty text message. "); + return; + } + if (!SubscriptionManager.isValidSubscriptionId(subId)) { + Log.w(RespondViaSmsManager.this, "Couldn't send SMS message: Invalid SubId: " + + subId); + return; + } + + SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); + try { + smsManager.sendTextMessage(phoneNumber, null, textMessage, null /*sentIntent*/, + null /*deliveryIntent*/); + + SomeArgs args = SomeArgs.obtain(); + args.arg1 = phoneNumber; + args.arg2 = context; + mHandler.obtainMessage(MSG_SHOW_SENT_TOAST, args).sendToTarget(); + } catch (IllegalArgumentException e) { + Log.w(RespondViaSmsManager.this, "Couldn't send SMS message: " + + e.getMessage()); } } } |