From d70271a8396252807f6b05e817fe1937059a4702 Mon Sep 17 00:00:00 2001 From: Cassie Wang Date: Thu, 16 Jan 2020 14:58:52 -0800 Subject: [PATCH] Update appsearch with new upstream changes * Switch CreationTimestampSecs to CreationTimestampMs. * Switch SearchResult error handling Bug: 143789408 Test: atest --rebuild-module-info CtsAppSearchTestCases FrameworksCoreTests:android.app.appsearch FrameworksServicesTests:com.android.server.appsearch.impl Change-Id: Ib1381ba2714d1d0a2a2d5d4bfe1cc3a095ebcda4 --- .../java/android/app/appsearch/AppSearch.java | 25 +++++++++---------- .../app/appsearch/AppSearchManager.java | 5 ++-- .../android/app/appsearch/SearchResults.java | 2 +- .../app/appsearch/AppSearchDocumentTest.java | 12 ++++----- .../appsearch/impl/CustomerDocumentTest.java | 4 +-- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/apex/appsearch/framework/java/android/app/appsearch/AppSearch.java b/apex/appsearch/framework/java/android/app/appsearch/AppSearch.java index e779b69750c2b..5b412499ee150 100644 --- a/apex/appsearch/framework/java/android/app/appsearch/AppSearch.java +++ b/apex/appsearch/framework/java/android/app/appsearch/AppSearch.java @@ -16,7 +16,7 @@ package android.app.appsearch; -import android.annotation.CurrentTimeSecondsLong; +import android.annotation.CurrentTimeMillisLong; import android.annotation.IntRange; import android.annotation.NonNull; import android.annotation.Nullable; @@ -32,7 +32,6 @@ import com.google.android.icing.proto.PropertyProto; import java.util.ArrayList; import java.util.Collections; import java.util.Objects; -import java.util.concurrent.TimeUnit; /** * Collection of all AppSearch Document Types. @@ -150,14 +149,14 @@ public final class AppSearch { } /** - * Get the creation timestamp in seconds of the {@link Document}. + * Get the creation timestamp in milliseconds of the {@link Document}. Value will be in the + * {@link System#currentTimeMillis()} time base. * * @hide */ - // TODO(b/143789408) Change seconds to millis with Icing library. - @CurrentTimeSecondsLong - public long getCreationTimestampSecs() { - return mProto.getCreationTimestampSecs(); + @CurrentTimeMillisLong + public long getCreationTimestampMillis() { + return mProto.getCreationTimestampMs(); } /** @@ -381,8 +380,7 @@ public final class AppSearch { mBuilderTypeInstance = (BuilderType) this; mProtoBuilder.setUri(uri).setSchema(schemaType); // Set current timestamp for creation timestamp by default. - setCreationTimestampSecs( - TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())); + setCreationTimestampMillis(System.currentTimeMillis()); } /** @@ -404,14 +402,15 @@ public final class AppSearch { } /** - * Set the creation timestamp in seconds of the {@link Document}. + * Set the creation timestamp in milliseconds of the {@link Document}. Should be set + * using a value obtained from the {@link System#currentTimeMillis()} time base. * * @hide */ @NonNull - public BuilderType setCreationTimestampSecs( - @CurrentTimeSecondsLong long creationTimestampSecs) { - mProtoBuilder.setCreationTimestampSecs(creationTimestampSecs); + public BuilderType setCreationTimestampMillis( + @CurrentTimeMillisLong long creationTimestampMillis) { + mProtoBuilder.setCreationTimestampMs(creationTimestampMillis); return mBuilderTypeInstance; } diff --git a/apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java b/apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java index 0aa685d6e1bfa..894ec948d128e 100644 --- a/apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java +++ b/apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java @@ -26,6 +26,7 @@ import com.android.internal.infra.AndroidFuture; import com.google.android.icing.proto.SchemaProto; import com.google.android.icing.proto.SearchResultProto; +import com.google.android.icing.proto.StatusProto; import com.google.android.icing.protobuf.InvalidProtocolBufferException; import java.util.List; @@ -197,11 +198,11 @@ public class AppSearchManager { callback.accept(null, e); return; } - if (searchResultProto.hasError()) { + if (searchResultProto.getStatus().getCode() != StatusProto.Code.OK) { // TODO(sidchhabra): Add better exception handling. callback.accept( null, - new RuntimeException(searchResultProto.getError().getErrorMessage())); + new RuntimeException(searchResultProto.getStatus().getMessage())); return; } SearchResults searchResults = new SearchResults(searchResultProto); diff --git a/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java b/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java index ec4258d086553..d763103f12173 100644 --- a/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java +++ b/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java @@ -60,7 +60,7 @@ public final class SearchResults { public AppSearch.Document getDocument() { return AppSearch.Document.newBuilder(mResultProto.getDocument().getUri(), mResultProto.getDocument().getSchema()) - .setCreationTimestampSecs(mResultProto.getDocument().getCreationTimestampSecs()) + .setCreationTimestampMillis(mResultProto.getDocument().getCreationTimestampMs()) .setScore(mResultProto.getDocument().getScore()) .build(); } diff --git a/core/tests/coretests/src/android/app/appsearch/AppSearchDocumentTest.java b/core/tests/coretests/src/android/app/appsearch/AppSearchDocumentTest.java index 2091d556394d2..9e4440a1d57d6 100644 --- a/core/tests/coretests/src/android/app/appsearch/AppSearchDocumentTest.java +++ b/core/tests/coretests/src/android/app/appsearch/AppSearchDocumentTest.java @@ -40,14 +40,14 @@ public class AppSearchDocumentTest { @Test public void testDocumentEquals_Identical() { Document document1 = Document.newBuilder("uri1", "schemaType1") - .setCreationTimestampSecs(0L) + .setCreationTimestampMillis(0L) .setProperty("longKey1", 1L, 2L, 3L) .setProperty("doubleKey1", 1.0, 2.0, 3.0) .setProperty("booleanKey1", true, false, true) .setProperty("stringKey1", "test-value1", "test-value2", "test-value3") .build(); Document document2 = Document.newBuilder("uri1", "schemaType1") - .setCreationTimestampSecs(0L) + .setCreationTimestampMillis(0L) .setProperty("longKey1", 1L, 2L, 3L) .setProperty("doubleKey1", 1.0, 2.0, 3.0) .setProperty("booleanKey1", true, false, true) @@ -60,7 +60,7 @@ public class AppSearchDocumentTest { @Test public void testDocumentEquals_DifferentOrder() { Document document1 = Document.newBuilder("uri1", "schemaType1") - .setCreationTimestampSecs(0L) + .setCreationTimestampMillis(0L) .setProperty("longKey1", 1L, 2L, 3L) .setProperty("doubleKey1", 1.0, 2.0, 3.0) .setProperty("booleanKey1", true, false, true) @@ -69,7 +69,7 @@ public class AppSearchDocumentTest { // Create second document with same parameter but different order. Document document2 = Document.newBuilder("uri1", "schemaType1") - .setCreationTimestampSecs(0L) + .setCreationTimestampMillis(0L) .setProperty("booleanKey1", true, false, true) .setProperty("stringKey1", "test-value1", "test-value2", "test-value3") .setProperty("doubleKey1", 1.0, 2.0, 3.0) @@ -182,7 +182,7 @@ public class AppSearchDocumentTest { public void testDocumentProtoPopulation() { Document document = Document.newBuilder("uri1", "schemaType1") .setScore(1) - .setCreationTimestampSecs(0) + .setCreationTimestampMillis(0) .setProperty("longKey1", 1L) .setProperty("doubleKey1", 1.0) .setProperty("booleanKey1", true) @@ -191,7 +191,7 @@ public class AppSearchDocumentTest { // Create the Document proto. Need to sort the property order by key. DocumentProto.Builder documentProtoBuilder = DocumentProto.newBuilder() - .setUri("uri1").setSchema("schemaType1").setScore(1).setCreationTimestampSecs(0); + .setUri("uri1").setSchema("schemaType1").setScore(1).setCreationTimestampMs(0); HashMap propertyProtoMap = new HashMap<>(); propertyProtoMap.put("longKey1", PropertyProto.newBuilder().setName("longKey1").addInt64Values(1L)); diff --git a/core/tests/coretests/src/android/app/appsearch/impl/CustomerDocumentTest.java b/core/tests/coretests/src/android/app/appsearch/impl/CustomerDocumentTest.java index 4ee4aa6d527f6..c5986bb2f07b7 100644 --- a/core/tests/coretests/src/android/app/appsearch/impl/CustomerDocumentTest.java +++ b/core/tests/coretests/src/android/app/appsearch/impl/CustomerDocumentTest.java @@ -36,7 +36,7 @@ public class CustomerDocumentTest { public void testBuildCustomerDocument() { CustomerDocument customerDocument = CustomerDocument.newBuilder("uri1") .setScore(1) - .setCreationTimestampSecs(0) + .setCreationTimestampMillis(0) .setProperty("longKey1", 1L, 2L, 3L) .setProperty("doubleKey1", 1.0, 2.0, 3.0) .setProperty("booleanKey1", true, false, true) @@ -46,7 +46,7 @@ public class CustomerDocumentTest { assertThat(customerDocument.getUri()).isEqualTo("uri1"); assertThat(customerDocument.getSchemaType()).isEqualTo("customerDocument"); assertThat(customerDocument.getScore()).isEqualTo(1); - assertThat(customerDocument.getCreationTimestampSecs()).isEqualTo(0L); + assertThat(customerDocument.getCreationTimestampMillis()).isEqualTo(0L); assertThat(customerDocument.getPropertyLongArray("longKey1")).asList() .containsExactly(1L, 2L, 3L); assertThat(customerDocument.getPropertyDoubleArray("doubleKey1")).usingExactEquality()