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

Commit 3e3baa0b authored by Taesu Lee's avatar Taesu Lee
Browse files

Ignore invalid time stamp in SMS PDUs



Catch a DateTimeException so that we don't lose SMS PDUs even if they
have invalid time stamp caused by SMSC problems.

Bug: 160200121
Test: Received SMS having invalid time stamp

Signed-off-by: default avatarTaesu Lee <taesu82.lee@samsung.com>
Change-Id: I80ef1c134f49d6a23e87a77125f54f4f66d62023
parent 2f3b72b8
Loading
Loading
Loading
Loading
+19 −13
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import com.android.internal.telephony.uicc.IccUtils;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.time.DateTimeException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Arrays;
@@ -173,7 +174,7 @@ public final class SmsCbEtwsInfo implements Parcelable {
    /**
     * Returns the Warning-Security-Information timestamp (GSM primary notifications only).
     * As of Release 10, 3GPP TS 23.041 states that the UE shall ignore this value if received.
     * @return a UTC timestamp in System.currentTimeMillis() format, or 0 if not present
     * @return a UTC timestamp in System.currentTimeMillis() format, or 0 if not present or invalid.
     */
    public long getPrimaryNotificationTimestamp() {
        if (mWarningSecurityInformation == null || mWarningSecurityInformation.length < 7) {
@@ -201,6 +202,7 @@ public final class SmsCbEtwsInfo implements Parcelable {
        // timezoneOffset is in quarter hours.
        int timeZoneOffsetSeconds = timezoneOffset * 15 * 60;

        try {
            LocalDateTime localDateTime = LocalDateTime.of(
                    // We only need to support years above 2000.
                    year + 2000,
@@ -213,6 +215,10 @@ public final class SmsCbEtwsInfo implements Parcelable {
            long epochSeconds = localDateTime.toEpochSecond(ZoneOffset.UTC) - timeZoneOffsetSeconds;
            // Convert to milliseconds, ignore overflow.
            return epochSeconds * 1000;
        } catch (DateTimeException ex) {
            // No-op
        }
        return 0;
    }

    /**
+11 −4
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.internal.util.BitwiseOutputStream;
import com.android.telephony.Rlog;

import java.io.ByteArrayOutputStream;
import java.time.DateTimeException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
@@ -315,10 +316,16 @@ public final class BearerData {
        }

        public long toMillis() {
            try {
                LocalDateTime localDateTime =
                        LocalDateTime.of(year, monthOrdinal, monthDay, hour, minute, second);
            Instant instant = localDateTime.toInstant(mZoneId.getRules().getOffset(localDateTime));
                Instant instant =
                        localDateTime.toInstant(mZoneId.getRules().getOffset(localDateTime));
                return instant.toEpochMilli();
            } catch (DateTimeException ex) {
                Rlog.e(LOG_TAG, "Invalid timestamp", ex);
            }
            return 0;
        }


+21 −13
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import com.android.telephony.Rlog;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.time.DateTimeException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
@@ -888,10 +889,9 @@ public class SmsMessage extends SmsMessageBase {
        }

        /**
         * Parses an SC timestamp and returns a currentTimeMillis()-style
         * timestamp
         * Parses an SC timestamp and returns a currentTimeMillis()-style timestamp, or 0 if
         * invalid.
         */

        long getSCTimestampMillis() {
            // TP-Service-Centre-Time-Stamp
            int year = IccUtils.gsmBcdByteToInt(mPdu[mCur++]);
@@ -917,6 +917,7 @@ public class SmsMessage extends SmsMessageBase {

            // It's 2006.  Should I really support years < 2000?
            int fullYear = year >= 90 ? year + 1900 : year + 2000;
            try {
                LocalDateTime localDateTime = LocalDateTime.of(
                        fullYear,
                        month /* 1-12 */,
@@ -924,9 +925,14 @@ public class SmsMessage extends SmsMessageBase {
                        hour,
                        minute,
                        second);
            long epochSeconds = localDateTime.toEpochSecond(ZoneOffset.UTC) - timeZoneOffsetSeconds;
                long epochSeconds =
                        localDateTime.toEpochSecond(ZoneOffset.UTC) - timeZoneOffsetSeconds;
                // Convert to milliseconds.
                return epochSeconds * 1000;
            } catch (DateTimeException ex) {
                Rlog.e(LOG_TAG, "Invalid timestamp", ex);
            }
            return 0;
        }

        /**
@@ -1277,6 +1283,7 @@ public class SmsMessage extends SmsMessageBase {
        mRecipientAddress = p.getAddress();
        // TP-Service-Centre-Time-Stamp
        mScTimeMillis = p.getSCTimestampMillis();
        // TP-Discharge-Time
        p.getSCTimestampMillis();
        // TP-Status
        mStatus = p.getByte();
@@ -1335,6 +1342,7 @@ public class SmsMessage extends SmsMessageBase {
                    + " data coding scheme: " + mDataCodingScheme);
        }

        // TP-Service-Centre-Time-Stamp
        mScTimeMillis = p.getSCTimestampMillis();

        if (VDBG) Rlog.d(LOG_TAG, "SMS SC timestamp: " + mScTimeMillis);