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

Commit e12ae91a authored by sqian's avatar sqian
Browse files

Add new error code handling for sending short code message

Design doc: https://docs.google.com/a/google.com/document/d
/1YPTNoM2Atjz8oISGAsRYlFVSA1NcYP8MbqYQIzLcJ9E/edit?usp=sharing

Test: compile/flash code; test locally
Bug: 34773406
Change-Id: Idb85d6e9d9387616d6ad88d5799cebc07df746f8
Merged-In: Idb85d6e9d9387616d6ad88d5799cebc07df746f8
parent 4dc2c73a
Loading
Loading
Loading
Loading
+44 −7
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import static android.telephony.SmsManager.RESULT_ERROR_LIMIT_EXCEEDED;
import static android.telephony.SmsManager.RESULT_ERROR_NO_SERVICE;
import static android.telephony.SmsManager.RESULT_ERROR_NULL_PDU;
import static android.telephony.SmsManager.RESULT_ERROR_RADIO_OFF;
import static android.telephony.SmsManager.RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED;
import static android.telephony.SmsManager.RESULT_ERROR_SHORT_CODE_NOT_ALLOWED;

import android.annotation.Nullable;
import android.annotation.UserIdInt;
@@ -313,7 +315,25 @@ public abstract class SMSDispatcher extends Handler {
        case EVENT_STOP_SENDING:
        {
            SmsTracker tracker = (SmsTracker) msg.obj;
            if (msg.arg1 == ConfirmDialogListener.SHORT_CODE_MSG) {
                if (msg.arg2 == ConfirmDialogListener.NEVER_ALLOW) {
                    tracker.onFailed(mContext,
                            RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED, 0/*errorCode*/);
                    Rlog.d(TAG, "SMSDispatcher: EVENT_STOP_SENDING - "
                            + "sending SHORT_CODE_NEVER_ALLOWED error code.");
                } else {
                    tracker.onFailed(mContext,
                            RESULT_ERROR_SHORT_CODE_NOT_ALLOWED, 0/*errorCode*/);
                    Rlog.d(TAG, "SMSDispatcher: EVENT_STOP_SENDING - "
                            + "sending SHORT_CODE_NOT_ALLOWED error code.");
                }
            } else if (msg.arg1 == ConfirmDialogListener.RATE_LIMIT) {
                tracker.onFailed(mContext, RESULT_ERROR_LIMIT_EXCEEDED, 0/*errorCode*/);
                Rlog.d(TAG, "SMSDispatcher: EVENT_STOP_SENDING - "
                        + "sending LIMIT_EXCEEDED error code.");
            } else {
                Rlog.e(TAG, "SMSDispatcher: EVENT_STOP_SENDING - unexpected cases.");
            }
            mPendingTrackerCount--;
            break;
        }
@@ -1068,7 +1088,10 @@ public abstract class SMSDispatcher extends Handler {

                case SmsUsageMonitor.PREMIUM_SMS_PERMISSION_NEVER_ALLOW:
                    Rlog.w(TAG, "User denied this app from sending to premium SMS");
                    sendMessage(obtainMessage(EVENT_STOP_SENDING, tracker));
                    Message msg = obtainMessage(EVENT_STOP_SENDING, tracker);
                    msg.arg1 = ConfirmDialogListener.SHORT_CODE_MSG;
                    msg.arg2 = ConfirmDialogListener.NEVER_ALLOW;
                    sendMessage(msg);
                    return false;   // reject this message

                case SmsUsageMonitor.PREMIUM_SMS_PERMISSION_ASK_USER:
@@ -1131,7 +1154,9 @@ public abstract class SMSDispatcher extends Handler {
        Resources r = Resources.getSystem();
        Spanned messageText = Html.fromHtml(r.getString(R.string.sms_control_message, appLabel));

        ConfirmDialogListener listener = new ConfirmDialogListener(tracker, null);
        // Construct ConfirmDialogListenter for Rate Limit handling
        ConfirmDialogListener listener = new ConfirmDialogListener(tracker, null,
                ConfirmDialogListener.RATE_LIMIT);

        AlertDialog d = new AlertDialog.Builder(mContext)
                .setTitle(R.string.sms_control_title)
@@ -1172,8 +1197,10 @@ public abstract class SMSDispatcher extends Handler {
                Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.sms_short_code_confirmation_dialog, null);

        // Construct ConfirmDialogListenter for short code message sending
        ConfirmDialogListener listener = new ConfirmDialogListener(tracker,
                (TextView)layout.findViewById(R.id.sms_short_code_remember_undo_instruction));
                (TextView) layout.findViewById(R.id.sms_short_code_remember_undo_instruction),
                ConfirmDialogListener.SHORT_CODE_MSG);


        TextView messageView = (TextView) layout.findViewById(R.id.sms_short_code_confirm_message);
@@ -1634,10 +1661,15 @@ public abstract class SMSDispatcher extends Handler {
        private Button mNegativeButton;
        private boolean mRememberChoice;    // default is unchecked
        private final TextView mRememberUndoInstruction;
        private int mConfirmationType;  // 0 - Short Code Msg Sending; 1 - Rate Limit Exceeded
        private static final int SHORT_CODE_MSG = 0; // Short Code Msg
        private static final int RATE_LIMIT = 1; // Rate Limit Exceeded
        private static final int NEVER_ALLOW = 1; // Never Allow

        ConfirmDialogListener(SmsTracker tracker, TextView textView) {
        ConfirmDialogListener(SmsTracker tracker, TextView textView, int confirmationType) {
            mTracker = tracker;
            mRememberUndoInstruction = textView;
            mConfirmationType = confirmationType;
        }

        void setPositiveButton(Button button) {
@@ -1670,10 +1702,13 @@ public abstract class SMSDispatcher extends Handler {
                EventLog.writeEvent(EventLogTags.EXP_DET_SMS_DENIED_BY_USER,
                                    mTracker.mAppInfo.applicationInfo == null ?
                                    -1 :  mTracker.mAppInfo.applicationInfo.uid);
                sendMessage(obtainMessage(EVENT_STOP_SENDING, mTracker));
                Message msg = obtainMessage(EVENT_STOP_SENDING, mTracker);
                msg.arg1 = mConfirmationType;
                if (mRememberChoice) {
                    newSmsPermission = SmsUsageMonitor.PREMIUM_SMS_PERMISSION_NEVER_ALLOW;
                    msg.arg2 = ConfirmDialogListener.NEVER_ALLOW;
                }
                sendMessage(msg);
            }
            setPremiumSmsPermission(mTracker.mAppInfo.packageName, newSmsPermission);
        }
@@ -1681,7 +1716,9 @@ public abstract class SMSDispatcher extends Handler {
        @Override
        public void onCancel(DialogInterface dialog) {
            Rlog.d(TAG, "dialog dismissed: don't send SMS");
            sendMessage(obtainMessage(EVENT_STOP_SENDING, mTracker));
            Message msg = obtainMessage(EVENT_STOP_SENDING, mTracker);
            msg.arg1 = mConfirmationType;
            sendMessage(msg);
        }

        @Override