Merge "Ignore invalid time stamp in SMS PDUs" am: a19cd20f01 am: 43887910a2 am: 2d017866f1 am: e8589e5764

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1354342

Change-Id: Ie4724fed257be0bbcf13ac1e0b58bb6405b3fe11
This commit is contained in:
Treehugger Robot
2020-07-13 09:11:36 +00:00
committed by Automerger Merge Worker
3 changed files with 50 additions and 29 deletions

View File

@@ -27,6 +27,7 @@ import com.android.internal.telephony.uicc.IccUtils;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.time.DateTimeException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.util.Arrays; import java.util.Arrays;
@@ -173,7 +174,7 @@ public final class SmsCbEtwsInfo implements Parcelable {
/** /**
* Returns the Warning-Security-Information timestamp (GSM primary notifications only). * 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. * 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() { public long getPrimaryNotificationTimestamp() {
if (mWarningSecurityInformation == null || mWarningSecurityInformation.length < 7) { if (mWarningSecurityInformation == null || mWarningSecurityInformation.length < 7) {
@@ -201,18 +202,23 @@ public final class SmsCbEtwsInfo implements Parcelable {
// timezoneOffset is in quarter hours. // timezoneOffset is in quarter hours.
int timeZoneOffsetSeconds = timezoneOffset * 15 * 60; int timeZoneOffsetSeconds = timezoneOffset * 15 * 60;
LocalDateTime localDateTime = LocalDateTime.of( try {
// We only need to support years above 2000. LocalDateTime localDateTime = LocalDateTime.of(
year + 2000, // We only need to support years above 2000.
month /* 1-12 */, year + 2000,
day, month /* 1-12 */,
hour, day,
minute, hour,
second); minute,
second);
long epochSeconds = localDateTime.toEpochSecond(ZoneOffset.UTC) - timeZoneOffsetSeconds; long epochSeconds = localDateTime.toEpochSecond(ZoneOffset.UTC) - timeZoneOffsetSeconds;
// Convert to milliseconds, ignore overflow. // Convert to milliseconds, ignore overflow.
return epochSeconds * 1000; return epochSeconds * 1000;
} catch (DateTimeException ex) {
// No-op
}
return 0;
} }
/** /**

View File

@@ -35,6 +35,7 @@ import com.android.internal.util.BitwiseOutputStream;
import com.android.telephony.Rlog; import com.android.telephony.Rlog;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.time.DateTimeException;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
@@ -315,10 +316,16 @@ public final class BearerData {
} }
public long toMillis() { public long toMillis() {
LocalDateTime localDateTime = try {
LocalDateTime.of(year, monthOrdinal, monthDay, hour, minute, second); LocalDateTime localDateTime =
Instant instant = localDateTime.toInstant(mZoneId.getRules().getOffset(localDateTime)); LocalDateTime.of(year, monthOrdinal, monthDay, hour, minute, second);
return instant.toEpochMilli(); Instant instant =
localDateTime.toInstant(mZoneId.getRules().getOffset(localDateTime));
return instant.toEpochMilli();
} catch (DateTimeException ex) {
Rlog.e(LOG_TAG, "Invalid timestamp", ex);
}
return 0;
} }

View File

@@ -43,6 +43,7 @@ import com.android.telephony.Rlog;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.text.ParseException; import java.text.ParseException;
import java.time.DateTimeException;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
@@ -855,10 +856,9 @@ public class SmsMessage extends SmsMessageBase {
} }
/** /**
* Parses an SC timestamp and returns a currentTimeMillis()-style * Parses an SC timestamp and returns a currentTimeMillis()-style timestamp, or 0 if
* timestamp * invalid.
*/ */
long getSCTimestampMillis() { long getSCTimestampMillis() {
// TP-Service-Centre-Time-Stamp // TP-Service-Centre-Time-Stamp
int year = IccUtils.gsmBcdByteToInt(mPdu[mCur++]); int year = IccUtils.gsmBcdByteToInt(mPdu[mCur++]);
@@ -884,16 +884,22 @@ public class SmsMessage extends SmsMessageBase {
// It's 2006. Should I really support years < 2000? // It's 2006. Should I really support years < 2000?
int fullYear = year >= 90 ? year + 1900 : year + 2000; int fullYear = year >= 90 ? year + 1900 : year + 2000;
LocalDateTime localDateTime = LocalDateTime.of( try {
fullYear, LocalDateTime localDateTime = LocalDateTime.of(
month /* 1-12 */, fullYear,
day, month /* 1-12 */,
hour, day,
minute, hour,
second); minute,
long epochSeconds = localDateTime.toEpochSecond(ZoneOffset.UTC) - timeZoneOffsetSeconds; second);
// Convert to milliseconds. long epochSeconds =
return epochSeconds * 1000; 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(); mRecipientAddress = p.getAddress();
// TP-Service-Centre-Time-Stamp // TP-Service-Centre-Time-Stamp
mScTimeMillis = p.getSCTimestampMillis(); mScTimeMillis = p.getSCTimestampMillis();
// TP-Discharge-Time
p.getSCTimestampMillis(); p.getSCTimestampMillis();
// TP-Status // TP-Status
mStatus = p.getByte(); mStatus = p.getByte();
@@ -1302,6 +1309,7 @@ public class SmsMessage extends SmsMessageBase {
+ " data coding scheme: " + mDataCodingScheme); + " data coding scheme: " + mDataCodingScheme);
} }
// TP-Service-Centre-Time-Stamp
mScTimeMillis = p.getSCTimestampMillis(); mScTimeMillis = p.getSCTimestampMillis();
if (VDBG) Rlog.d(LOG_TAG, "SMS SC timestamp: " + mScTimeMillis); if (VDBG) Rlog.d(LOG_TAG, "SMS SC timestamp: " + mScTimeMillis);