Merge frontend changes from Jetpack into Framework.
Includes new APIs to comply with MissingGetterForSetter.
Bug: 162450968
Test: AppSearchManagerTest
Change-Id: I14fb2c815f2393968a06155c326f68562d066361
diff --git a/service/java/com/android/server/appsearch/AppSearchManagerService.java b/service/java/com/android/server/appsearch/AppSearchManagerService.java
index 7cd6ee2..f2830e5 100644
--- a/service/java/com/android/server/appsearch/AppSearchManagerService.java
+++ b/service/java/com/android/server/appsearch/AppSearchManagerService.java
@@ -33,11 +33,11 @@
import com.android.internal.infra.AndroidFuture;
import com.android.internal.util.Preconditions;
import com.android.server.SystemService;
-import com.android.server.appsearch.external.localbackend.AppSearchImpl;
-import com.android.server.appsearch.external.localbackend.converter.GenericDocumentToProtoConverter;
-import com.android.server.appsearch.external.localbackend.converter.SchemaToProtoConverter;
-import com.android.server.appsearch.external.localbackend.converter.SearchResultToProtoConverter;
-import com.android.server.appsearch.external.localbackend.converter.SearchSpecToProtoConverter;
+import com.android.server.appsearch.external.localstorage.AppSearchImpl;
+import com.android.server.appsearch.external.localstorage.converter.GenericDocumentToProtoConverter;
+import com.android.server.appsearch.external.localstorage.converter.SchemaToProtoConverter;
+import com.android.server.appsearch.external.localstorage.converter.SearchResultToProtoConverter;
+import com.android.server.appsearch.external.localstorage.converter.SearchSpecToProtoConverter;
import com.google.android.icing.proto.DocumentProto;
import com.google.android.icing.proto.SchemaProto;
@@ -46,6 +46,7 @@
import com.google.android.icing.proto.SearchSpecProto;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -193,7 +194,12 @@
SearchSpecToProtoConverter.toResultSpecProto(searchSpec),
SearchSpecToProtoConverter.toScoringSpecProto(searchSpec));
List<SearchResult> searchResultList =
- SearchResultToProtoConverter.convert(searchResultProto);
+ new ArrayList<>(searchResultProto.getResultsCount());
+ for (int i = 0; i < searchResultProto.getResultsCount(); i++) {
+ SearchResult result = SearchResultToProtoConverter.convertSearchResult(
+ searchResultProto.getResults(i));
+ searchResultList.add(result);
+ }
SearchResults searchResults =
new SearchResults(searchResultList, searchResultProto.getNextPageToken());
callback.complete(AppSearchResult.newSuccessfulResult(searchResults));
diff --git a/service/java/com/android/server/appsearch/ImplInstanceManager.java b/service/java/com/android/server/appsearch/ImplInstanceManager.java
index 60f7005..2871eb6 100644
--- a/service/java/com/android/server/appsearch/ImplInstanceManager.java
+++ b/service/java/com/android/server/appsearch/ImplInstanceManager.java
@@ -24,7 +24,7 @@
import android.os.storage.StorageManager;
import android.util.SparseArray;
-import com.android.server.appsearch.external.localbackend.AppSearchImpl;
+import com.android.server.appsearch.external.localstorage.AppSearchImpl;
import java.io.File;
diff --git a/service/java/com/android/server/appsearch/external/localbackend/AppSearchImpl.java b/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java
similarity index 99%
rename from service/java/com/android/server/appsearch/external/localbackend/AppSearchImpl.java
rename to service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java
index 642378d..b1a79f8 100644
--- a/service/java/com/android/server/appsearch/external/localbackend/AppSearchImpl.java
+++ b/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.server.appsearch.external.localbackend;
+package com.android.server.appsearch.external.localstorage;
import android.util.Log;
diff --git a/service/java/com/android/server/appsearch/external/localbackend/converter/GenericDocumentToProtoConverter.java b/service/java/com/android/server/appsearch/external/localstorage/converter/GenericDocumentToProtoConverter.java
similarity index 69%
rename from service/java/com/android/server/appsearch/external/localbackend/converter/GenericDocumentToProtoConverter.java
rename to service/java/com/android/server/appsearch/external/localstorage/converter/GenericDocumentToProtoConverter.java
index fdeb90d..60684f0 100644
--- a/service/java/com/android/server/appsearch/external/localbackend/converter/GenericDocumentToProtoConverter.java
+++ b/service/java/com/android/server/appsearch/external/localstorage/converter/GenericDocumentToProtoConverter.java
@@ -14,9 +14,7 @@
* limitations under the License.
*/
-package com.android.server.appsearch.external.localbackend.converter;
-
-import android.os.Bundle;
+package com.android.server.appsearch.external.localstorage.converter;
import android.annotation.NonNull;
@@ -43,7 +41,6 @@
@SuppressWarnings("unchecked")
public static DocumentProto convert(@NonNull GenericDocument document) {
Preconditions.checkNotNull(document);
- Bundle properties = document.getBundle().getBundle(GenericDocument.PROPERTIES_FIELD);
DocumentProto.Builder mProtoBuilder = DocumentProto.newBuilder();
mProtoBuilder.setUri(document.getUri())
.setSchema(document.getSchemaType())
@@ -51,42 +48,45 @@
.setScore(document.getScore())
.setTtlMs(document.getTtlMillis())
.setCreationTimestampMs(document.getCreationTimestampMillis());
- ArrayList<String> keys = new ArrayList<>(properties.keySet());
+ ArrayList<String> keys = new ArrayList<>(document.getPropertyNames());
Collections.sort(keys);
for (int i = 0; i < keys.size(); i++) {
String name = keys.get(i);
- Object values = properties.get(name);
PropertyProto.Builder propertyProto = PropertyProto.newBuilder().setName(name);
- if (values instanceof boolean[]) {
- for (boolean value : (boolean[]) values) {
- propertyProto.addBooleanValues(value);
+ String[] stringValues = document.getPropertyStringArray(name);
+ long[] longValues = document.getPropertyLongArray(name);
+ double[] doubleValues = document.getPropertyDoubleArray(name);
+ boolean[] booleanValues = document.getPropertyBooleanArray(name);
+ byte[][] bytesValues = document.getPropertyBytesArray(name);
+ GenericDocument[] documentValues = document.getPropertyDocumentArray(name);
+ if (stringValues != null) {
+ for (int j = 0; j < stringValues.length; j++) {
+ propertyProto.addStringValues(stringValues[j]);
}
- } else if (values instanceof long[]) {
- for (long value : (long[]) values) {
- propertyProto.addInt64Values(value);
+ } else if (longValues != null) {
+ for (int j = 0; j < longValues.length; j++) {
+ propertyProto.addInt64Values(longValues[j]);
}
- } else if (values instanceof double[]) {
- for (double value : (double[]) values) {
- propertyProto.addDoubleValues(value);
+ } else if (doubleValues != null) {
+ for (int j = 0; j < doubleValues.length; j++) {
+ propertyProto.addDoubleValues(doubleValues[j]);
}
- } else if (values instanceof String[]) {
- for (String value : (String[]) values) {
- propertyProto.addStringValues(value);
+ } else if (booleanValues != null) {
+ for (int j = 0; j < booleanValues.length; j++) {
+ propertyProto.addBooleanValues(booleanValues[j]);
}
- } else if (values instanceof ArrayList) {
- for (Bundle bundle : (ArrayList<Bundle>) values) {
- byte[] value = bundle.getByteArray(GenericDocument.BYTE_ARRAY_FIELD);
- propertyProto.addBytesValues(ByteString.copyFrom(value));
+ } else if (bytesValues != null) {
+ for (int j = 0; j < bytesValues.length; j++) {
+ propertyProto.addBytesValues(ByteString.copyFrom(bytesValues[j]));
}
- } else if (values instanceof Bundle[]) {
- for (Bundle bundle : (Bundle[]) values) {
- GenericDocument value = new GenericDocument(bundle);
- propertyProto.addDocumentValues(convert(value));
+ } else if (documentValues != null) {
+ for (int j = 0; j < documentValues.length; j++) {
+ DocumentProto proto = convert(documentValues[j]);
+ propertyProto.addDocumentValues(proto);
}
} else {
throw new IllegalStateException(
- "Property \"" + name + "\" has unsupported value type \""
- + values.getClass().getSimpleName() + "\"");
+ "Property \"" + name + "\" has unsupported value type");
}
mProtoBuilder.addProperties(propertyProto);
}
@@ -107,42 +107,42 @@
for (int i = 0; i < proto.getPropertiesCount(); i++) {
PropertyProto property = proto.getProperties(i);
String name = property.getName();
- if (property.getBooleanValuesCount() > 0) {
- boolean[] values = new boolean[property.getBooleanValuesCount()];
+ if (property.getStringValuesCount() > 0) {
+ String[] values = new String[property.getStringValuesCount()];
for (int j = 0; j < values.length; j++) {
- values[j] = property.getBooleanValues(j);
+ values[j] = property.getStringValues(j);
}
- documentBuilder.setProperty(name, values);
+ documentBuilder.setPropertyString(name, values);
} else if (property.getInt64ValuesCount() > 0) {
long[] values = new long[property.getInt64ValuesCount()];
for (int j = 0; j < values.length; j++) {
values[j] = property.getInt64Values(j);
}
- documentBuilder.setProperty(name, values);
+ documentBuilder.setPropertyLong(name, values);
} else if (property.getDoubleValuesCount() > 0) {
double[] values = new double[property.getDoubleValuesCount()];
for (int j = 0; j < values.length; j++) {
values[j] = property.getDoubleValues(j);
}
- documentBuilder.setProperty(name, values);
- } else if (property.getStringValuesCount() > 0) {
- String[] values = new String[property.getStringValuesCount()];
+ documentBuilder.setPropertyDouble(name, values);
+ } else if (property.getBooleanValuesCount() > 0) {
+ boolean[] values = new boolean[property.getBooleanValuesCount()];
for (int j = 0; j < values.length; j++) {
- values[j] = property.getStringValues(j);
+ values[j] = property.getBooleanValues(j);
}
- documentBuilder.setProperty(name, values);
+ documentBuilder.setPropertyBoolean(name, values);
} else if (property.getBytesValuesCount() > 0) {
byte[][] values = new byte[property.getBytesValuesCount()][];
for (int j = 0; j < values.length; j++) {
values[j] = property.getBytesValues(j).toByteArray();
}
- documentBuilder.setProperty(name, values);
+ documentBuilder.setPropertyBytes(name, values);
} else if (property.getDocumentValuesCount() > 0) {
GenericDocument[] values = new GenericDocument[property.getDocumentValuesCount()];
for (int j = 0; j < values.length; j++) {
values[j] = convert(property.getDocumentValues(j));
}
- documentBuilder.setProperty(name, values);
+ documentBuilder.setPropertyDocument(name, values);
} else {
throw new IllegalStateException("Unknown type of value: " + name);
}
diff --git a/service/java/com/android/server/appsearch/external/localbackend/converter/SchemaToProtoConverter.java b/service/java/com/android/server/appsearch/external/localstorage/converter/SchemaToProtoConverter.java
similarity index 73%
rename from service/java/com/android/server/appsearch/external/localbackend/converter/SchemaToProtoConverter.java
rename to service/java/com/android/server/appsearch/external/localstorage/converter/SchemaToProtoConverter.java
index ca0d2ee..403711f 100644
--- a/service/java/com/android/server/appsearch/external/localbackend/converter/SchemaToProtoConverter.java
+++ b/service/java/com/android/server/appsearch/external/localstorage/converter/SchemaToProtoConverter.java
@@ -14,9 +14,7 @@
* limitations under the License.
*/
-package com.android.server.appsearch.external.localbackend.converter;
-
-import android.os.Bundle;
+package com.android.server.appsearch.external.localstorage.converter;
import android.annotation.NonNull;
@@ -28,7 +26,7 @@
import com.google.android.icing.proto.SchemaTypeConfigProto;
import com.google.android.icing.proto.TermMatchType;
-import java.util.ArrayList;
+import java.util.List;
/**
* Translates an {@link AppSearchSchema} into a {@link SchemaTypeConfigProto}.
@@ -45,31 +43,26 @@
@NonNull
public static SchemaTypeConfigProto convert(@NonNull AppSearchSchema schema) {
Preconditions.checkNotNull(schema);
- Bundle bundle = schema.getBundle();
SchemaTypeConfigProto.Builder protoBuilder =
- SchemaTypeConfigProto.newBuilder()
- .setSchemaType(bundle.getString(AppSearchSchema.SCHEMA_TYPE_FIELD, ""));
- ArrayList<Bundle> properties =
- bundle.getParcelableArrayList(AppSearchSchema.PROPERTIES_FIELD);
- if (properties != null) {
- for (int i = 0; i < properties.size(); i++) {
- PropertyConfigProto propertyProto = convertProperty(properties.get(i));
- protoBuilder.addProperties(propertyProto);
- }
+ SchemaTypeConfigProto.newBuilder().setSchemaType(schema.getSchemaTypeName());
+ List<AppSearchSchema.PropertyConfig> properties = schema.getProperties();
+ for (int i = 0; i < properties.size(); i++) {
+ PropertyConfigProto propertyProto = convertProperty(properties.get(i));
+ protoBuilder.addProperties(propertyProto);
}
return protoBuilder.build();
}
@NonNull
- private static PropertyConfigProto convertProperty(@NonNull Bundle bundle) {
- Preconditions.checkNotNull(bundle);
+ private static PropertyConfigProto convertProperty(
+ @NonNull AppSearchSchema.PropertyConfig property) {
+ Preconditions.checkNotNull(property);
PropertyConfigProto.Builder propertyConfigProto = PropertyConfigProto.newBuilder()
- .setPropertyName(bundle.getString(AppSearchSchema.PropertyConfig.NAME_FIELD, ""));
+ .setPropertyName(property.getName());
IndexingConfig.Builder indexingConfig = IndexingConfig.newBuilder();
// Set dataType
- @AppSearchSchema.PropertyConfig.DataType int dataType =
- bundle.getInt(AppSearchSchema.PropertyConfig.DATA_TYPE_FIELD);
+ @AppSearchSchema.PropertyConfig.DataType int dataType = property.getDataType();
PropertyConfigProto.DataType.Code dataTypeProto =
PropertyConfigProto.DataType.Code.forNumber(dataType);
if (dataTypeProto == null) {
@@ -78,12 +71,13 @@
propertyConfigProto.setDataType(dataTypeProto);
// Set schemaType
- propertyConfigProto.setSchemaType(
- bundle.getString(AppSearchSchema.PropertyConfig.SCHEMA_TYPE_FIELD, ""));
+ String schemaType = property.getSchemaType();
+ if (schemaType != null) {
+ propertyConfigProto.setSchemaType(schemaType);
+ }
// Set cardinality
- @AppSearchSchema.PropertyConfig.Cardinality int cardinality =
- bundle.getInt(AppSearchSchema.PropertyConfig.CARDINALITY_FIELD);
+ @AppSearchSchema.PropertyConfig.Cardinality int cardinality = property.getCardinality();
PropertyConfigProto.Cardinality.Code cardinalityProto =
PropertyConfigProto.Cardinality.Code.forNumber(cardinality);
if (cardinalityProto == null) {
@@ -92,8 +86,7 @@
propertyConfigProto.setCardinality(cardinalityProto);
// Set indexingType
- @AppSearchSchema.PropertyConfig.IndexingType int indexingType =
- bundle.getInt(AppSearchSchema.PropertyConfig.INDEXING_TYPE_FIELD);
+ @AppSearchSchema.PropertyConfig.IndexingType int indexingType = property.getIndexingType();
TermMatchType.Code termMatchTypeProto;
switch (indexingType) {
case AppSearchSchema.PropertyConfig.INDEXING_TYPE_NONE:
@@ -112,7 +105,7 @@
// Set tokenizerType
@AppSearchSchema.PropertyConfig.TokenizerType int tokenizerType =
- bundle.getInt(AppSearchSchema.PropertyConfig.TOKENIZER_TYPE_FIELD);
+ property.getTokenizerType();
IndexingConfig.TokenizerType.Code tokenizerTypeProto =
IndexingConfig.TokenizerType.Code.forNumber(tokenizerType);
if (tokenizerTypeProto == null) {
diff --git a/service/java/com/android/server/appsearch/external/localbackend/converter/SearchResultToProtoConverter.java b/service/java/com/android/server/appsearch/external/localstorage/converter/SearchResultToProtoConverter.java
similarity index 79%
rename from service/java/com/android/server/appsearch/external/localbackend/converter/SearchResultToProtoConverter.java
rename to service/java/com/android/server/appsearch/external/localstorage/converter/SearchResultToProtoConverter.java
index 524c80d..9f7c696 100644
--- a/service/java/com/android/server/appsearch/external/localbackend/converter/SearchResultToProtoConverter.java
+++ b/service/java/com/android/server/appsearch/external/localstorage/converter/SearchResultToProtoConverter.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.server.appsearch.external.localbackend.converter;
+package com.android.server.appsearch.external.localstorage.converter;
import android.os.Bundle;
@@ -22,43 +22,32 @@
import android.app.appsearch.GenericDocument;
import android.app.appsearch.SearchResult;
-import android.app.appsearch.SearchResults;
import com.google.android.icing.proto.SearchResultProto;
import com.google.android.icing.proto.SnippetMatchProto;
import com.google.android.icing.proto.SnippetProto;
import java.util.ArrayList;
-import java.util.List;
/**
- * Translates a {@link SearchResultProto} into {@link SearchResults}.
+ * Translates a {@link SearchResultProto} into {@link SearchResult}s.
+ *
* @hide
*/
public class SearchResultToProtoConverter {
private SearchResultToProtoConverter() {}
- /** Translates a {@link SearchResultProto} into a list of {@link SearchResult}. */
- @NonNull
- public static List<SearchResult> convert(@NonNull SearchResultProto searchResultProto) {
- List<SearchResult> results = new ArrayList<>(searchResultProto.getResultsCount());
- for (int i = 0; i < searchResultProto.getResultsCount(); i++) {
- results.add(convertSearchResult(searchResultProto.getResults(i)));
- }
- return results;
- }
-
/** Translate a {@link SearchResultProto.ResultProto} into {@link SearchResult}. */
@NonNull
- static SearchResult convertSearchResult(@NonNull SearchResultProto.ResultProto proto) {
+ public static SearchResult convertSearchResult(
+ @NonNull SearchResultProto.ResultProtoOrBuilder proto) {
Bundle bundle = new Bundle();
GenericDocument document = GenericDocumentToProtoConverter.convert(proto.getDocument());
bundle.putBundle(SearchResult.DOCUMENT_FIELD, document.getBundle());
- ArrayList<Bundle> matchList = null;
+ ArrayList<Bundle> matchList = new ArrayList<>();
if (proto.hasSnippet()) {
- matchList = new ArrayList<>();
for (int i = 0; i < proto.getSnippet().getEntriesCount(); i++) {
SnippetProto.EntryProto entry = proto.getSnippet().getEntries(i);
for (int j = 0; j < entry.getSnippetMatchesCount(); j++) {
diff --git a/service/java/com/android/server/appsearch/external/localbackend/converter/SearchSpecToProtoConverter.java b/service/java/com/android/server/appsearch/external/localstorage/converter/SearchSpecToProtoConverter.java
similarity index 67%
rename from service/java/com/android/server/appsearch/external/localbackend/converter/SearchSpecToProtoConverter.java
rename to service/java/com/android/server/appsearch/external/localstorage/converter/SearchSpecToProtoConverter.java
index a5d913a..14822dc 100644
--- a/service/java/com/android/server/appsearch/external/localbackend/converter/SearchSpecToProtoConverter.java
+++ b/service/java/com/android/server/appsearch/external/localstorage/converter/SearchSpecToProtoConverter.java
@@ -14,9 +14,7 @@
* limitations under the License.
*/
-package com.android.server.appsearch.external.localbackend.converter;
-
-import android.os.Bundle;
+package com.android.server.appsearch.external.localstorage.converter;
import android.annotation.NonNull;
@@ -28,8 +26,6 @@
import com.google.android.icing.proto.SearchSpecProto;
import com.google.android.icing.proto.TermMatchType;
-import java.util.Arrays;
-
/**
* Translates a {@link SearchSpec} into icing search protos.
* @hide
@@ -42,25 +38,17 @@
@NonNull
public static SearchSpecProto toSearchSpecProto(@NonNull SearchSpec spec) {
Preconditions.checkNotNull(spec);
- Bundle bundle = spec.getBundle();
- SearchSpecProto.Builder protoBuilder = SearchSpecProto.newBuilder();
+ SearchSpecProto.Builder protoBuilder = SearchSpecProto.newBuilder()
+ .addAllSchemaTypeFilters(spec.getSchemas())
+ .addAllNamespaceFilters(spec.getNamespaces());
- @SearchSpec.TermMatchCode int termMatchCode =
- bundle.getInt(SearchSpec.TERM_MATCH_TYPE_FIELD);
+ @SearchSpec.TermMatch int termMatchCode = spec.getTermMatch();
TermMatchType.Code termMatchCodeProto = TermMatchType.Code.forNumber(termMatchCode);
if (termMatchCodeProto == null || termMatchCodeProto.equals(TermMatchType.Code.UNKNOWN)) {
throw new IllegalArgumentException("Invalid term match type: " + termMatchCode);
}
protoBuilder.setTermMatchType(termMatchCodeProto);
- String[] schemaTypes = bundle.getStringArray(SearchSpec.SCHEMA_TYPES_FIELD);
- if (schemaTypes != null) {
- protoBuilder.addAllSchemaTypeFilters(Arrays.asList(schemaTypes));
- }
- String[] namespaces = bundle.getStringArray(SearchSpec.NAMESPACE_FIELD);
- if (namespaces != null) {
- protoBuilder.addAllNamespaceFilters(Arrays.asList(namespaces));
- }
return protoBuilder.build();
}
@@ -68,27 +56,23 @@
@NonNull
public static ResultSpecProto toResultSpecProto(@NonNull SearchSpec spec) {
Preconditions.checkNotNull(spec);
- Bundle bundle = spec.getBundle();
return ResultSpecProto.newBuilder()
- .setNumPerPage(bundle.getInt(
- SearchSpec.NUM_PER_PAGE_FIELD, SearchSpec.DEFAULT_NUM_PER_PAGE))
- .setSnippetSpec(ResultSpecProto.SnippetSpecProto.newBuilder()
- .setNumToSnippet(bundle.getInt(SearchSpec.SNIPPET_COUNT_FIELD))
- .setNumMatchesPerProperty(
- bundle.getInt(SearchSpec.SNIPPET_COUNT_PER_PROPERTY_FIELD))
- .setMaxWindowBytes(bundle.getInt(SearchSpec.MAX_SNIPPET_FIELD)))
+ .setNumPerPage(spec.getNumPerPage())
+ .setSnippetSpec(
+ ResultSpecProto.SnippetSpecProto.newBuilder()
+ .setNumToSnippet(spec.getSnippetCount())
+ .setNumMatchesPerProperty(spec.getSnippetCountPerProperty())
+ .setMaxWindowBytes(spec.getMaxSnippetSize()))
.build();
-
}
/** Extracts {@link ScoringSpecProto} information from a {@link SearchSpec}. */
@NonNull
public static ScoringSpecProto toScoringSpecProto(@NonNull SearchSpec spec) {
Preconditions.checkNotNull(spec);
- Bundle bundle = spec.getBundle();
ScoringSpecProto.Builder protoBuilder = ScoringSpecProto.newBuilder();
- @SearchSpec.OrderCode int orderCode = bundle.getInt(SearchSpec.ORDER_FIELD);
+ @SearchSpec.Order int orderCode = spec.getOrder();
ScoringSpecProto.Order.Code orderCodeProto =
ScoringSpecProto.Order.Code.forNumber(orderCode);
if (orderCodeProto == null) {
@@ -96,8 +80,7 @@
}
protoBuilder.setOrderBy(orderCodeProto);
- @SearchSpec.RankingStrategyCode int rankingStrategyCode =
- bundle.getInt(SearchSpec.RANKING_STRATEGY_FIELD);
+ @SearchSpec.RankingStrategy int rankingStrategyCode = spec.getRankingStrategy();
ScoringSpecProto.RankingStrategy.Code rankingStrategyCodeProto =
ScoringSpecProto.RankingStrategy.Code.forNumber(rankingStrategyCode);
if (rankingStrategyCodeProto == null) {