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

Commit 862f1047 authored by Amit Mahajan's avatar Amit Mahajan Committed by android-build-merger
Browse files

Merge "Allow Class 0 messages to allow starting background activity." into qt-dev

am: 51f7b95a

Change-Id: I463e58cd3b0d7abe21869df7fb7f2c42762885fc
parents 5424a5c8 51f7b95a
Loading
Loading
Loading
Loading
+27 −13
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import android.util.Pair;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.SmsConstants.MessageClass;
import com.android.internal.telephony.metrics.TelephonyMetrics;
import com.android.internal.telephony.util.NotificationChannelController;
import com.android.internal.util.HexDump;
@@ -757,7 +758,7 @@ public abstract class InboundSmsHandler extends StateMachine {
                    .makeInboundSmsTracker(sms.getPdu(),
                    sms.getTimestampMillis(), destPort, is3gpp2(), false,
                    sms.getOriginatingAddress(), sms.getDisplayOriginatingAddress(),
                    sms.getMessageBody());
                    sms.getMessageBody(), sms.getMessageClass() == MessageClass.CLASS_0);
        } else {
            // Create a tracker for this message segment.
            SmsHeader.ConcatRef concatRef = smsHeader.concatRef;
@@ -768,7 +769,8 @@ public abstract class InboundSmsHandler extends StateMachine {
                    .makeInboundSmsTracker(sms.getPdu(),
                    sms.getTimestampMillis(), destPort, is3gpp2(), sms.getOriginatingAddress(),
                    sms.getDisplayOriginatingAddress(), concatRef.refNumber, concatRef.seqNumber,
                    concatRef.msgCount, false, sms.getMessageBody());
                    concatRef.msgCount, false, sms.getMessageBody(),
                    sms.getMessageClass() == MessageClass.CLASS_0);
        }

        if (VDBG) log("created tracker: " + tracker);
@@ -987,7 +989,8 @@ public abstract class InboundSmsHandler extends StateMachine {
            pdus, destPort, tracker, resultReceiver, true /* userUnlocked */);

        if (!filterInvoked) {
            dispatchSmsDeliveryIntent(pdus, tracker.getFormat(), destPort, resultReceiver);
            dispatchSmsDeliveryIntent(pdus, tracker.getFormat(), destPort, resultReceiver,
                    tracker.isClass0());
        }

        return true;
@@ -1081,7 +1084,8 @@ public abstract class InboundSmsHandler extends StateMachine {
        InboundSmsTracker tracker, SmsBroadcastReceiver resultReceiver, boolean userUnlocked) {
        CarrierServicesSmsFilterCallback filterCallback =
                new CarrierServicesSmsFilterCallback(
                        pdus, destPort, tracker.getFormat(), resultReceiver, userUnlocked);
                        pdus, destPort, tracker.getFormat(), resultReceiver, userUnlocked,
                        tracker.isClass0());
        CarrierServicesSmsFilter carrierServicesFilter = new CarrierServicesSmsFilter(
                mContext, mPhone, pdus, destPort, tracker.getFormat(),
                filterCallback, getName(), mLocalLog);
@@ -1178,7 +1182,7 @@ public abstract class InboundSmsHandler extends StateMachine {
    }

    @UnsupportedAppUsage
    private Bundle handleSmsWhitelisting(ComponentName target) {
    private Bundle handleSmsWhitelisting(ComponentName target, boolean bgActivityStartAllowed) {
        String pkgName;
        String reason;
        if (target != null) {
@@ -1188,16 +1192,23 @@ public abstract class InboundSmsHandler extends StateMachine {
            pkgName = mContext.getPackageName();
            reason = "sms-broadcast";
        }
        BroadcastOptions bopts = null;
        Bundle bundle = null;
        if (bgActivityStartAllowed) {
            bopts = BroadcastOptions.makeBasic();
            bopts.setBackgroundActivityStartsAllowed(true);
            bundle = bopts.toBundle();
        }
        try {
            long duration = mDeviceIdleController.addPowerSaveTempWhitelistAppForSms(
                    pkgName, 0, reason);
            BroadcastOptions bopts = BroadcastOptions.makeBasic();
            if (bopts == null) bopts = BroadcastOptions.makeBasic();
            bopts.setTemporaryAppWhitelistDuration(duration);
            return bopts.toBundle();
            bundle = bopts.toBundle();
        } catch (RemoteException e) {
        }

        return null;
        return bundle;
    }

    /**
@@ -1210,7 +1221,7 @@ public abstract class InboundSmsHandler extends StateMachine {
     * @param resultReceiver the receiver handling the delivery result
     */
    private void dispatchSmsDeliveryIntent(byte[][] pdus, String format, int destPort,
            SmsBroadcastReceiver resultReceiver) {
            SmsBroadcastReceiver resultReceiver, boolean isClass0) {
        Intent intent = new Intent();
        intent.putExtra("pdus", pdus);
        intent.putExtra("format", format);
@@ -1256,7 +1267,7 @@ public abstract class InboundSmsHandler extends StateMachine {
            intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        }

        Bundle options = handleSmsWhitelisting(intent.getComponent());
        Bundle options = handleSmsWhitelisting(intent.getComponent(), isClass0);
        dispatchIntent(intent, android.Manifest.permission.RECEIVE_SMS,
                AppOpsManager.OP_RECEIVE_SMS, options, resultReceiver, UserHandle.SYSTEM);
    }
@@ -1440,7 +1451,7 @@ public abstract class InboundSmsHandler extends StateMachine {
                intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
                intent.setComponent(null);
                // All running users will be notified of the received sms.
                Bundle options = handleSmsWhitelisting(null);
                Bundle options = handleSmsWhitelisting(null, false /* bgActivityStartAllowed */);

                dispatchIntent(intent, android.Manifest.permission.RECEIVE_SMS,
                        AppOpsManager.OP_RECEIVE_SMS,
@@ -1508,14 +1519,17 @@ public abstract class InboundSmsHandler extends StateMachine {
        private final String mSmsFormat;
        private final SmsBroadcastReceiver mSmsBroadcastReceiver;
        private final boolean mUserUnlocked;
        private final boolean mIsClass0;

        CarrierServicesSmsFilterCallback(byte[][] pdus, int destPort, String smsFormat,
                         SmsBroadcastReceiver smsBroadcastReceiver,  boolean userUnlocked) {
                SmsBroadcastReceiver smsBroadcastReceiver,  boolean userUnlocked,
                boolean isClass0) {
            mPdus = pdus;
            mDestPort = destPort;
            mSmsFormat = smsFormat;
            mSmsBroadcastReceiver = smsBroadcastReceiver;
            mUserUnlocked = userUnlocked;
            mIsClass0 = isClass0;
        }

        @Override
@@ -1531,7 +1545,7 @@ public abstract class InboundSmsHandler extends StateMachine {

                if (mUserUnlocked) {
                    dispatchSmsDeliveryIntent(
                            mPdus, mSmsFormat, mDestPort, mSmsBroadcastReceiver);
                            mPdus, mSmsFormat, mDestPort, mSmsBroadcastReceiver, mIsClass0);
                } else {
                    // Don't do anything further, leave the message in the raw table if the
                    // credential-encrypted storage is still locked and show the new message
+13 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ public class InboundSmsTracker {
    private final boolean mIs3gpp2;
    private final boolean mIs3gpp2WapPdu;
    private final String mMessageBody;
    private final boolean mIsClass0;

    // Fields for concatenating multi-part SMS messages
    private final String mAddress;
@@ -103,7 +104,8 @@ public class InboundSmsTracker {
     *                       as originating address
     */
    public InboundSmsTracker(byte[] pdu, long timestamp, int destPort, boolean is3gpp2,
            boolean is3gpp2WapPdu, String address, String displayAddress, String messageBody) {
            boolean is3gpp2WapPdu, String address, String displayAddress, String messageBody,
            boolean isClass0) {
        mPdu = pdu;
        mTimestamp = timestamp;
        mDestPort = destPort;
@@ -112,6 +114,7 @@ public class InboundSmsTracker {
        mMessageBody = messageBody;
        mAddress = address;
        mDisplayAddress = displayAddress;
        mIsClass0 = isClass0;
        // fields for multi-part SMS
        mReferenceNumber = -1;
        mSequenceNumber = getIndexOffset();     // 0 or 1, depending on type
@@ -139,13 +142,14 @@ public class InboundSmsTracker {
     */
    public InboundSmsTracker(byte[] pdu, long timestamp, int destPort, boolean is3gpp2,
            String address, String displayAddress, int referenceNumber, int sequenceNumber,
            int messageCount, boolean is3gpp2WapPdu, String messageBody) {
            int messageCount, boolean is3gpp2WapPdu, String messageBody, boolean isClass0) {
        mPdu = pdu;
        mTimestamp = timestamp;
        mDestPort = destPort;
        mIs3gpp2 = is3gpp2;
        mIs3gpp2WapPdu = is3gpp2WapPdu;
        mMessageBody = messageBody;
        mIsClass0 = isClass0;
        // fields used for check blocking message
        mDisplayAddress = displayAddress;
        // fields for multi-part SMS
@@ -163,6 +167,9 @@ public class InboundSmsTracker {
    public InboundSmsTracker(Cursor cursor, boolean isCurrentFormat3gpp2) {
        mPdu = HexDump.hexStringToByteArray(cursor.getString(InboundSmsHandler.PDU_COLUMN));

        // TODO: add a column to raw db to store this
        mIsClass0 = false;

        if (cursor.isNull(InboundSmsHandler.DESTINATION_PORT_COLUMN)) {
            mDestPort = -1;
            mIs3gpp2 = isCurrentFormat3gpp2;
@@ -307,6 +314,10 @@ public class InboundSmsTracker {
        return mIs3gpp2;
    }

    public boolean isClass0() {
        return mIsClass0;
    }

    @UnsupportedAppUsage
    public String getFormat() {
        return mIs3gpp2 ? SmsConstants.FORMAT_3GPP2 : SmsConstants.FORMAT_3GPP;
+7 −5
Original line number Diff line number Diff line
@@ -356,19 +356,21 @@ public class TelephonyComponentFactory {
     */
    public InboundSmsTracker makeInboundSmsTracker(byte[] pdu, long timestamp, int destPort,
            boolean is3gpp2, boolean is3gpp2WapPdu, String address, String displayAddr,
            String messageBody) {
            String messageBody, boolean isClass0) {
        return new InboundSmsTracker(pdu, timestamp, destPort, is3gpp2, is3gpp2WapPdu, address,
                displayAddr, messageBody);
                displayAddr, messageBody, isClass0);
    }

    /**
     * Create a tracker for a multi-part SMS.
     */
    public InboundSmsTracker makeInboundSmsTracker(byte[] pdu, long timestamp, int destPort,
            boolean is3gpp2, String address, String displayAddr, int referenceNumber, int sequenceNumber,
            int messageCount, boolean is3gpp2WapPdu, String messageBody) {
            boolean is3gpp2, String address, String displayAddr, int referenceNumber,
            int sequenceNumber, int messageCount, boolean is3gpp2WapPdu, String messageBody,
            boolean isClass0) {
        return new InboundSmsTracker(pdu, timestamp, destPort, is3gpp2, address, displayAddr,
                referenceNumber, sequenceNumber, messageCount, is3gpp2WapPdu, messageBody);
                referenceNumber, sequenceNumber, messageCount, is3gpp2WapPdu, messageBody,
                isClass0);
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -294,7 +294,7 @@ public class CdmaInboundSmsHandler extends InboundSmsHandler {
        InboundSmsTracker tracker = TelephonyComponentFactory.getInstance()
                .inject(InboundSmsTracker.class.getName()).makeInboundSmsTracker(
                userData, timestamp, destinationPort, true, address, dispAddr, referenceNumber,
                segment, totalSegments, true, HexDump.toHexString(userData));
                segment, totalSegments, true, HexDump.toHexString(userData), false /* isClass0 */);

        // de-duping is done only for text messages
        return addTrackerToRawTableAndSendMessage(tracker, false /* don't de-dup */);
+7 −1
Original line number Diff line number Diff line
@@ -374,6 +374,7 @@ public class ContextFixture implements TestFixture<Context> {
        public void sendOrderedBroadcast(Intent intent, String receiverPermission, Bundle options,
                BroadcastReceiver resultReceiver, Handler scheduler, int initialCode,
                String initialData, Bundle initialExtras) {
            mLastBroadcastOptions = options;
            sendOrderedBroadcast(intent, receiverPermission, resultReceiver, scheduler,
                    initialCode, initialData, initialExtras);
        }
@@ -435,6 +436,7 @@ public class ContextFixture implements TestFixture<Context> {
                BroadcastReceiver resultReceiver, Handler scheduler, int initialCode,
                String initialData, Bundle initialExtras) {
            logd("sendOrderedBroadcastAsUser called for " + intent.getAction());
            mLastBroadcastOptions = options;
            sendBroadcast(intent);
            if (resultReceiver != null) {
                synchronized (mOrderedBroadcastReceivers) {
@@ -536,7 +538,7 @@ public class ContextFixture implements TestFixture<Context> {
            ArrayListMultimap.create();
    private final HashSet<String> mPermissionTable = new HashSet<>();
    private final HashSet<String> mSystemFeatures = new HashSet<>();

    private Bundle mLastBroadcastOptions;


    // The application context is the most important object this class provides to the system
@@ -720,6 +722,10 @@ public class ContextFixture implements TestFixture<Context> {
        mSystemFeatures.add(feature);
    }

    public Bundle getLastBroadcastOptions() {
        return mLastBroadcastOptions;
    }

    private static void logd(String s) {
        Log.d(TAG, s);
    }
Loading