aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lin <jamescflin@google.com>2021-07-13 02:06:03 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-07-13 02:06:03 +0000
commitf2cff1a258c15c68eaeabd45dd0664b5a0bc9c5f (patch)
treeb795cc1c7942e9bc83bbcd983330d0ebbc885ca6
parent64c594f64026c6b9c5feede252d8406f4d7d2c23 (diff)
parentb4648c465d8839a617142a9fb110fc28ba30580d (diff)
downloadims-f2cff1a258c15c68eaeabd45dd0664b5a0bc9c5f.tar.gz
Merge "Use the local time instead of the timestamp which received from the network." into sc-dev am: b4648c465d
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/opt/net/ims/+/15184584 Change-Id: I43848c51f945f98c9e72478ec114ca7cacaee2de
-rw-r--r--src/java/com/android/ims/rcs/uce/presence/pidfparser/PidfParser.java39
-rw-r--r--tests/src/com/android/ims/rcs/uce/presence/pidfparser/PidfParserTest.java22
2 files changed, 39 insertions, 22 deletions
diff --git a/src/java/com/android/ims/rcs/uce/presence/pidfparser/PidfParser.java b/src/java/com/android/ims/rcs/uce/presence/pidfparser/PidfParser.java
index 2660f1d9..dc2dc045 100644
--- a/src/java/com/android/ims/rcs/uce/presence/pidfparser/PidfParser.java
+++ b/src/java/com/android/ims/rcs/uce/presence/pidfparser/PidfParser.java
@@ -36,14 +36,13 @@ import com.android.ims.rcs.uce.presence.pidfparser.pidf.PidfConstant;
import com.android.ims.rcs.uce.presence.pidfparser.pidf.Presence;
import com.android.ims.rcs.uce.presence.pidfparser.pidf.Tuple;
import com.android.ims.rcs.uce.util.UceUtils;
+import com.android.internal.annotations.VisibleForTesting;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.time.Instant;
-import java.time.format.DateTimeFormatter;
-import java.time.format.DateTimeParseException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -63,6 +62,29 @@ public class PidfParser {
private static final Pattern PIDF_PATTERN = Pattern.compile("\t|\r|\n");
/**
+ * Testing interface used to get the timestamp.
+ */
+ @VisibleForTesting
+ public interface TimestampProxy {
+ Instant getTimestamp();
+ }
+
+ // The timestamp proxy to create the local timestamp.
+ private static final TimestampProxy sLocalTimestampProxy = () -> Instant.now();
+
+ // Override timestamp proxy for testing only.
+ private static TimestampProxy sOverrideTimestampProxy;
+
+ @VisibleForTesting
+ public static void setTimestampProxy(TimestampProxy proxy) {
+ sOverrideTimestampProxy = proxy;
+ }
+
+ private static TimestampProxy getTimestampProxy() {
+ return (sOverrideTimestampProxy != null) ? sOverrideTimestampProxy : sLocalTimestampProxy;
+ }
+
+ /**
* Convert the RcsContactUceCapability to the string of pidf.
*/
public static String convertToPidf(RcsContactUceCapability capabilities) {
@@ -214,17 +236,8 @@ public class PidfParser {
builder.setContactUri(Uri.parse(contact));
}
- // Timestamp
- String timestamp = PidfParserUtils.getTupleTimestamp(tuple);
- if (!TextUtils.isEmpty(timestamp)) {
- try {
- Instant instant = DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(
- timestamp, Instant::from);
- builder.setTime(instant);
- } catch (DateTimeParseException e) {
- Log.w(LOG_TAG, "getRcsContactPresenceTuple: Parse timestamp failed " + e);
- }
- }
+ // Use local time instead to prevent we receive the incorrect timestamp from the network.
+ builder.setTime(getTimestampProxy().getTimestamp());
// Set service description
if (!TextUtils.isEmpty(serviceDescription)) {
diff --git a/tests/src/com/android/ims/rcs/uce/presence/pidfparser/PidfParserTest.java b/tests/src/com/android/ims/rcs/uce/presence/pidfparser/PidfParserTest.java
index f8038be1..be92ce36 100644
--- a/tests/src/com/android/ims/rcs/uce/presence/pidfparser/PidfParserTest.java
+++ b/tests/src/com/android/ims/rcs/uce/presence/pidfparser/PidfParserTest.java
@@ -47,14 +47,19 @@ import org.mockito.Mock;
@RunWith(AndroidJUnit4.class)
public class PidfParserTest extends ImsTestBase {
+ // The timestamp of the PIDF
+ private final Instant mPidfTimestamp = Instant.now().plusMillis(1);
+
@Before
public void setUp() throws Exception {
super.setUp();
+ PidfParser.setTimestampProxy(() -> mPidfTimestamp);
}
@After
public void tearDown() throws Exception {
super.tearDown();
+ PidfParser.setTimestampProxy(null);
}
@Test
@@ -104,7 +109,7 @@ public class PidfParserTest extends ImsTestBase {
assertEquals("1.0", presenceTuple1.getServiceVersion());
assertEquals(serviceDescription, presenceTuple1.getServiceDescription());
assertEquals(Uri.parse(contact), presenceTuple1.getContactUri());
- assertEquals("2001-01-01T01:00:00Z", presenceTuple1.getTime().toString());
+ assertEquals(mPidfTimestamp.toString(), presenceTuple1.getTime().toString());
assertTrue(presenceTuple1.getServiceCapabilities().isAudioCapable());
assertFalse(presenceTuple1.getServiceCapabilities().isVideoCapable());
}
@@ -184,7 +189,7 @@ public class PidfParserTest extends ImsTestBase {
assertEquals(expectedTuple.getStatus(), tuple.getStatus());
assertEquals(expectedTuple.getServiceVersion(), tuple.getServiceVersion());
assertEquals(expectedTuple.getServiceDescription(), tuple.getServiceDescription());
- assertEquals(expectedTuple.getTime(), tuple.getTime());
+ assertEquals(mPidfTimestamp, tuple.getTime());
assertEquals(expectedTuple.getContactUri(), tuple.getContactUri());
ServiceCapabilities expectedCap = expectedTuple.getServiceCapabilities();
@@ -243,7 +248,7 @@ public class PidfParserTest extends ImsTestBase {
assertEquals("1.0", presenceTuple1.getServiceVersion());
assertEquals(serviceDescription1, presenceTuple1.getServiceDescription());
assertEquals(Uri.parse(contact), presenceTuple1.getContactUri());
- assertEquals("2001-01-01T01:00:00Z", presenceTuple1.getTime().toString());
+ assertEquals(mPidfTimestamp.toString(), presenceTuple1.getTime().toString());
assertNull(presenceTuple1.getServiceCapabilities());
// Verify the second tuple information
@@ -254,7 +259,7 @@ public class PidfParserTest extends ImsTestBase {
assertFalse(presenceTuple2.getServiceCapabilities().isVideoCapable());
assertEquals(serviceDescription2, presenceTuple2.getServiceDescription());
assertEquals(Uri.parse(contact), presenceTuple2.getContactUri());
- assertEquals("2001-02-02T01:00:00Z", presenceTuple2.getTime().toString());
+ assertEquals(mPidfTimestamp.toString(), presenceTuple2.getTime().toString());
assertNotNull(presenceTuple2.getServiceCapabilities());
assertEquals(isAudioSupported, presenceTuple2.getServiceCapabilities().isAudioCapable());
assertEquals(isVideoSupported, presenceTuple2.getServiceCapabilities().isVideoCapable());
@@ -341,7 +346,7 @@ public class PidfParserTest extends ImsTestBase {
.append("<caps:video>").append(isVideoSupported).append("</caps:video>")
.append("</caps:servcaps>")
.append("<contact>").append(contact).append("</contact>")
- .append("<timestamp>2001-01-01T01:00:00.00Z</timestamp>")
+ .append("<timestamp>").append(mPidfTimestamp.toString()).append("</timestamp>")
.append("</tuple></presence>");
return pidfBuilder.toString();
}
@@ -444,7 +449,7 @@ public class PidfParserTest extends ImsTestBase {
+ "<op:description>" + serviceDescription1 + "</op:description>"
+ "</op:service-description>"
+ "<contact>" + contact + "</contact>"
- + "<timestamp>2001-01-01T01:00:00.00Z</timestamp>"
+ + "<timestamp>" + mPidfTimestamp.toString() + "</timestamp>"
+ "</tuple>"
// tuple 2
+ "<tuple id=\"a1\">"
@@ -462,7 +467,7 @@ public class PidfParserTest extends ImsTestBase {
+ "<caps:video>" + videoSupported + "</caps:video>"
+ "</caps:servcaps>"
+ "<contact>" + contact + "</contact>"
- + "<timestamp>2001-02-02T01:00:00.00Z</timestamp>"
+ + "<timestamp>" + mPidfTimestamp.toString() + "</timestamp>"
+ "</tuple>"
+ "</presence>";
}
@@ -475,7 +480,6 @@ public class PidfParserTest extends ImsTestBase {
final String basicStatus = RcsContactPresenceTuple.TUPLE_BASIC_STATUS_OPEN;
final String version = "1.0";
final String description = "description test";
- final Instant nowTime = Instant.now();
// init the capabilities
ServiceCapabilities.Builder servCapsBuilder =
@@ -487,7 +491,7 @@ public class PidfParserTest extends ImsTestBase {
basicStatus, RcsContactPresenceTuple.SERVICE_ID_MMTEL, version);
tupleBuilder.setContactUri(contact)
.setServiceDescription(description)
- .setTime(nowTime)
+ .setTime(mPidfTimestamp)
.setServiceCapabilities(servCapsBuilder.build());
PresenceBuilder presenceBuilder = new PresenceBuilder(contact,