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

Commit e7a94085 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Send messages to the correct SMS handler." into sc-dev

parents 297a1ffa e5277067
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -245,11 +245,11 @@ public class CarrierServicesSmsFilter {
            mSmsFilterCallback = smsFilterCallback;
            if (!mCarrierMessagingServiceWrapper.bindToCarrierMessagingService(
                    mContext, mPackageName, runnable -> runnable.run(), ()-> onServiceReady())) {
                loge("CarrierSmsFilter::filterSms: bindService() for failed for " + mPackageName);
                loge("CarrierSmsFilter::filterSms: bindService() failed for " + mPackageName);
                smsFilterCallback.onReceiveSmsComplete(
                        CarrierMessagingService.RECEIVE_OPTIONS_DEFAULT);
            } else {
                logv("CarrierSmsFilter::filterSms: bindService() for succeeded for "
                logv("CarrierSmsFilter::filterSms: bindService() succeeded for "
                        + mPackageName);
            }
        }
+5 −0
Original line number Diff line number Diff line
@@ -4680,4 +4680,9 @@ public class GsmCdmaPhone extends Phone {
                && imsManager.isNonTtyOrTtyOnVolteEnabled());
        return imsUseEnabled;
    }

    @Override
    public InboundSmsHandler getInboundSmsHandler(boolean is3gpp2) {
        return mIccSmsInterfaceManager.getInboundSmsHandler(is3gpp2);
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -1497,6 +1497,13 @@ public class IccSmsInterfaceManager {
        }
    }

    /**
     * Get InboundSmsHandler for the phone.
     */
    public InboundSmsHandler getInboundSmsHandler(boolean is3gpp2) {
        return mDispatchersController.getInboundSmsHandler(is3gpp2);
    }

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("Enabled GSM channels: " + mCellBroadcastRangeManager);
        pw.println("Enabled CDMA channels: " + mCdmaBroadcastRangeManager);
+7 −0
Original line number Diff line number Diff line
@@ -4797,6 +4797,13 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        mCi.getSlicingConfig(response);
    }

    /**
     * Returns the InboundSmsHandler object for this phone
     */
    public InboundSmsHandler getInboundSmsHandler(boolean is3gpp2) {
        return null;
    }

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("Phone: subId=" + getSubId());
        pw.println(" mPhoneId=" + mPhoneId);
+25 −42
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.internal.telephony;

import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
@@ -93,12 +92,6 @@ public class SmsBroadcastUndelivered {
    /** Content resolver to use to access raw table from SmsProvider. */
    private final ContentResolver mResolver;

    /** Handler for 3GPP-format messages (may be null). */
    private final GsmInboundSmsHandler mGsmInboundSmsHandler;

    /** Handler for 3GPP2-format messages (may be null). */
    private final CdmaInboundSmsHandler mCdmaInboundSmsHandler;

    /** Broadcast receiver that processes the raw table when the user unlocks the phone for the
     *  first time after reboot and the credential-encrypted storage is available.
     */
@@ -121,7 +114,7 @@ public class SmsBroadcastUndelivered {

        @Override
        public void run() {
            scanRawTable(context, mCdmaInboundSmsHandler, mGsmInboundSmsHandler,
            scanRawTable(context,
                    System.currentTimeMillis() - getUndeliveredSmsExpirationTime(context));
            InboundSmsHandler.cancelNewMessageNotification(context);
        }
@@ -130,8 +123,7 @@ public class SmsBroadcastUndelivered {
    public static void initialize(Context context, GsmInboundSmsHandler gsmInboundSmsHandler,
        CdmaInboundSmsHandler cdmaInboundSmsHandler) {
        if (instance == null) {
            instance = new SmsBroadcastUndelivered(
                context, gsmInboundSmsHandler, cdmaInboundSmsHandler);
            instance = new SmsBroadcastUndelivered(context);
        }

        // Tell handlers to start processing new messages and transit from the startup state to the
@@ -146,11 +138,8 @@ public class SmsBroadcastUndelivered {
    }

    @UnsupportedAppUsage
    private SmsBroadcastUndelivered(Context context, GsmInboundSmsHandler gsmInboundSmsHandler,
            CdmaInboundSmsHandler cdmaInboundSmsHandler) {
    private SmsBroadcastUndelivered(Context context) {
        mResolver = context.getContentResolver();
        mGsmInboundSmsHandler = gsmInboundSmsHandler;
        mCdmaInboundSmsHandler = cdmaInboundSmsHandler;

        UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);

@@ -166,8 +155,7 @@ public class SmsBroadcastUndelivered {
    /**
     * Scan the raw table for complete SMS messages to broadcast, and old PDUs to delete.
     */
    static void scanRawTable(Context context, CdmaInboundSmsHandler cdmaInboundSmsHandler,
            GsmInboundSmsHandler gsmInboundSmsHandler, long oldMessageTimestamp) {
    static void scanRawTable(Context context, long oldMessageTimestamp) {
        if (DBG) Rlog.d(TAG, "scanning raw table for undelivered messages");
        long startTime = System.nanoTime();
        ContentResolver contentResolver = context.getContentResolver();
@@ -200,7 +188,7 @@ public class SmsBroadcastUndelivered {

                if (tracker.getMessageCount() == 1) {
                    // deliver single-part message
                    broadcastSms(tracker, cdmaInboundSmsHandler, gsmInboundSmsHandler);
                    broadcastSms(tracker);
                } else {
                    SmsReferenceKey reference = new SmsReferenceKey(tracker);
                    Integer receivedCount = multiPartReceivedCount.get(reference);
@@ -217,7 +205,7 @@ public class SmsBroadcastUndelivered {
                            // looks like we've got all the pieces; send a single tracker
                            // to state machine which will find the other pieces to broadcast
                            if (DBG) Rlog.d(TAG, "found complete multi-part message");
                            broadcastSms(tracker, cdmaInboundSmsHandler, gsmInboundSmsHandler);
                            broadcastSms(tracker);
                            // don't delete this old message until after we broadcast it
                            oldMultiPartMessages.remove(reference);
                        } else {
@@ -227,9 +215,11 @@ public class SmsBroadcastUndelivered {
                }
            }
            // Retrieve the phone and phone id, required for metrics
            Phone phone = getPhone(gsmInboundSmsHandler, cdmaInboundSmsHandler);
            int phoneId = phone != null ? phone.getPhoneId()
                    : SubscriptionManager.INVALID_PHONE_INDEX;
            // TODO don't hardcode to the first phone (phoneId = 0) but this is no worse than
            //  earlier. Also phoneId for old messages may not be known (messages may be from an
            //  inactive sub)
            Phone phone = PhoneFactory.getPhone(0);
            int phoneId = 0;

            // Delete old incomplete message segments
            for (SmsReferenceKey message : oldMultiPartMessages) {
@@ -264,32 +254,25 @@ public class SmsBroadcastUndelivered {
        }
    }

    /**
     * Retrieve the phone for the GSM or CDMA Inbound SMS handler
     */
    @Nullable
    private static Phone getPhone(GsmInboundSmsHandler gsmInboundSmsHandler,
            CdmaInboundSmsHandler cdmaInboundSmsHandler) {
        if (gsmInboundSmsHandler != null) {
            return gsmInboundSmsHandler.getPhone();
        } else if (cdmaInboundSmsHandler != null) {
            return cdmaInboundSmsHandler.getPhone();
        }
        return null;
    }

    /**
     * Send tracker to appropriate (3GPP or 3GPP2) inbound SMS handler for broadcast.
     */
    private static void broadcastSms(InboundSmsTracker tracker,
            CdmaInboundSmsHandler cdmaInboundSmsHandler,
            GsmInboundSmsHandler gsmInboundSmsHandler) {
    private static void broadcastSms(InboundSmsTracker tracker) {
        InboundSmsHandler handler;
        if (tracker.is3gpp2()) {
            handler = cdmaInboundSmsHandler;
        } else {
            handler = gsmInboundSmsHandler;
        int subId = tracker.getSubId();
        // TODO consider other subs in this subId's group as well
        int phoneId = SubscriptionController.getInstance().getPhoneId(subId);
        if (!SubscriptionManager.isValidPhoneId(phoneId)) {
            Rlog.e(TAG, "broadcastSms: ignoring message; no phone found for subId " + subId);
            return;
        }
        Phone phone = PhoneFactory.getPhone(phoneId);
        if (phone == null) {
            Rlog.e(TAG, "broadcastSms: ignoring message; no phone found for subId " + subId
                    + " phoneId " + phoneId);
            return;
        }
        handler = phone.getInboundSmsHandler(tracker.is3gpp2());
        if (handler != null) {
            handler.sendMessage(InboundSmsHandler.EVENT_BROADCAST_SMS, tracker);
        } else {
Loading