diff options
author | Taesu Lee <taesu82.lee@samsung.com> | 2020-07-02 14:27:47 +0900 |
---|---|---|
committer | Taesu Lee <taesu82.lee@samsung.com> | 2020-07-02 16:50:08 +0900 |
commit | 3e3baa0b9d4e163869c8a6d91209cf81b10fe99b (patch) | |
tree | 9bbcccca1353204cb1eaf55ae7d8a0db7f8872e1 /telephony/java/com | |
parent | 2f3b72b8efc65769ff44387fbbc14354fcee0f8e (diff) |
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: Taesu Lee <taesu82.lee@samsung.com>
Change-Id: I80ef1c134f49d6a23e87a77125f54f4f66d62023
Diffstat (limited to 'telephony/java/com')
-rw-r--r-- | telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java | 15 | ||||
-rw-r--r-- | telephony/java/com/android/internal/telephony/gsm/SmsMessage.java | 34 |
2 files changed, 32 insertions, 17 deletions
diff --git a/telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java b/telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java index 3f85de358ea2..85b88ef2bb58 100644 --- a/telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java +++ b/telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java @@ -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() { - LocalDateTime localDateTime = - LocalDateTime.of(year, monthOrdinal, monthDay, hour, minute, second); - Instant instant = localDateTime.toInstant(mZoneId.getRules().getOffset(localDateTime)); - return instant.toEpochMilli(); + try { + LocalDateTime localDateTime = + LocalDateTime.of(year, monthOrdinal, monthDay, hour, minute, second); + Instant instant = + localDateTime.toInstant(mZoneId.getRules().getOffset(localDateTime)); + return instant.toEpochMilli(); + } catch (DateTimeException ex) { + Rlog.e(LOG_TAG, "Invalid timestamp", ex); + } + return 0; } diff --git a/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java b/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java index 122f0851cf37..6ed0f66f8834 100644 --- a/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java +++ b/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java @@ -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,16 +917,22 @@ public class SmsMessage extends SmsMessageBase { // It's 2006. Should I really support years < 2000? int fullYear = year >= 90 ? year + 1900 : year + 2000; - LocalDateTime localDateTime = LocalDateTime.of( - fullYear, - month /* 1-12 */, - day, - hour, - minute, - second); - long epochSeconds = localDateTime.toEpochSecond(ZoneOffset.UTC) - timeZoneOffsetSeconds; - // Convert to milliseconds. - return epochSeconds * 1000; + try { + LocalDateTime localDateTime = LocalDateTime.of( + fullYear, + month /* 1-12 */, + day, + hour, + minute, + second); + 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); |