Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21241167 authored by Brad Ebinger's avatar Brad Ebinger
Browse files

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
parent 92fd1fbe
Loading
Loading
Loading
Loading
+23 −27
Original line number Diff line number Diff line
@@ -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,8 +31,8 @@ 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;
@@ -178,29 +175,28 @@ public class RespondViaSmsManager extends CallsManagerListenerBase {
     */
    private void rejectCallWithMessage(Context context, String phoneNumber, String textMessage,
            int subId, String contactName) {
        if (!TextUtils.isEmpty(textMessage)) {
            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);
        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 = !TextUtils.isEmpty(contactName) ? contactName : phoneNumber;
            args.arg2 = context;
            mHandler.obtainMessage(MSG_SHOW_SENT_TOAST, args).sendToTarget();
                intent.setComponent(component);
                context.startService(intent);
            }
        } catch (IllegalArgumentException e) {
            Log.w(RespondViaSmsManager.this, "Couldn't send SMS message: " +
                    e.getMessage());
        }
    }
}