summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2020-07-13 08:39:07 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-07-13 08:39:07 +0000
commit2d017866f11345ec067d18f323b2714041e3fc7c (patch)
tree2192dc4d069ccc12eef78efe5ea5f1114ffb378e
parent932962ac337376e9408e008914e03e9b239c1055 (diff)
parent43887910a2e707b4a356c95d4ab73c247e474470 (diff)
Merge "Ignore invalid time stamp in SMS PDUs" am: a19cd20f01 am: 43887910a2
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1354342 Change-Id: I74bcc259c8764f969a7328ff97bec20aeeabf036
-rw-r--r--telephony/java/android/telephony/SmsCbEtwsInfo.java32
-rw-r--r--telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java15
-rw-r--r--telephony/java/com/android/internal/telephony/gsm/SmsMessage.java34
3 files changed, 51 insertions, 30 deletions
diff --git a/telephony/java/android/telephony/SmsCbEtwsInfo.java b/telephony/java/android/telephony/SmsCbEtwsInfo.java
index 2a7f7ad81e3b..a98916d715e4 100644
--- a/telephony/java/android/telephony/SmsCbEtwsInfo.java
+++ b/telephony/java/android/telephony/SmsCbEtwsInfo.java
@@ -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,18 +202,23 @@ public final class SmsCbEtwsInfo implements Parcelable {
// timezoneOffset is in quarter hours.
int timeZoneOffsetSeconds = timezoneOffset * 15 * 60;
- LocalDateTime localDateTime = LocalDateTime.of(
- // We only need to support years above 2000.
- year + 2000,
- month /* 1-12 */,
- day,
- hour,
- minute,
- second);
-
- long epochSeconds = localDateTime.toEpochSecond(ZoneOffset.UTC) - timeZoneOffsetSeconds;
- // Convert to milliseconds, ignore overflow.
- return epochSeconds * 1000;
+ try {
+ LocalDateTime localDateTime = LocalDateTime.of(
+ // We only need to support years above 2000.
+ year + 2000,
+ month /* 1-12 */,
+ day,
+ hour,
+ minute,
+ second);
+
+ long epochSeconds = localDateTime.toEpochSecond(ZoneOffset.UTC) - timeZoneOffsetSeconds;
+ // Convert to milliseconds, ignore overflow.
+ return epochSeconds * 1000;
+ } catch (DateTimeException ex) {
+ // No-op
+ }
+ return 0;
}
/**
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 4fbafb78fe3c..c7ad2bbb043f 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 e4205aaae5b6..f297ba74914e 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;
@@ -855,10 +856,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++]);
@@ -884,16 +884,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;
}
/**
@@ -1244,6 +1250,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();
@@ -1302,6 +1309,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);