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

Commit bd8f0b50 authored by Amit Mahajan's avatar Amit Mahajan
Browse files

Run ImsSmsListener callbacks as self.

Earlier there was an implicit assumption that IMS (caller of the
callbacks) runs under the same uid, but that may not always be
true now.

Test: atest SmsManagerTest
Bug: 162487575
Merged-in: Ic0bb62c3b960fda8708e7bebefb1154a2380fd4f
Change-Id: Ic0bb62c3b960fda8708e7bebefb1154a2380fd4f
parent 183fb8ea
Loading
Loading
Loading
Loading
+114 −98
Original line number Diff line number Diff line
@@ -118,6 +118,8 @@ public class ImsSmsDispatcher extends SMSDispatcher {
        @Override
        public void onSendSmsResult(int token, int messageRef, @SendStatusResult int status,
                int reason, int networkReasonCode) {
            final long identity = Binder.clearCallingIdentity();
            try {
                logd("onSendSmsResult token=" + token + " messageRef=" + messageRef
                        + " status=" + status + " reason=" + reason + " networkReasonCode="
                        + networkReasonCode);
@@ -152,11 +154,16 @@ public class ImsSmsDispatcher extends SMSDispatcher {
                        break;
                    default:
                }
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }

        @Override
        public void onSmsStatusReportReceived(int token, String format, byte[] pdu)
                throws RemoteException {
            final long identity = Binder.clearCallingIdentity();
            try {
                logd("Status report received.");
                android.telephony.SmsMessage message =
                        android.telephony.SmsMessage.createFromPdu(pdu, format);
@@ -195,10 +202,15 @@ public class ImsSmsDispatcher extends SMSDispatcher {
                if (result.second) {
                    mTrackers.remove(key);
                }
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }

        @Override
        public void onSmsReceived(int token, String format, byte[] pdu) {
            final long identity = Binder.clearCallingIdentity();
            try {
                logd("SMS received.");
                android.telephony.SmsMessage message =
                        android.telephony.SmsMessage.createFromPdu(pdu, format);
@@ -213,7 +225,8 @@ public class ImsSmsDispatcher extends SMSDispatcher {
                            mappedResult = ImsSmsImplBase.DELIVER_STATUS_ERROR_NO_MEMORY;
                            break;
                        case Intents.RESULT_SMS_UNSUPPORTED:
                        mappedResult = ImsSmsImplBase.DELIVER_STATUS_ERROR_REQUEST_NOT_SUPPORTED;
                            mappedResult =
                                    ImsSmsImplBase.DELIVER_STATUS_ERROR_REQUEST_NOT_SUPPORTED;
                            break;
                        default:
                            mappedResult = ImsSmsImplBase.DELIVER_STATUS_ERROR_GENERIC;
@@ -231,6 +244,9 @@ public class ImsSmsDispatcher extends SMSDispatcher {
                        loge("Failed to acknowledgeSms(). Error: " + e.getMessage());
                    }
                }, true);
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }
    };