Merge "Update appsearch with new upstream changes"
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -205,11 +206,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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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<String, PropertyProto.Builder> propertyProtoMap = new HashMap<>();
|
||||
propertyProtoMap.put("longKey1",
|
||||
PropertyProto.newBuilder().setName("longKey1").addInt64Values(1L));
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user