Merge "Update framework from jetpack" into sc-dev

This commit is contained in:
Alexander Dorokhine
2021-05-18 01:17:30 +00:00
committed by Android (Google) Code Review
11 changed files with 282 additions and 26 deletions

View File

@@ -98,13 +98,13 @@ package android.app.appsearch {
method @NonNull public android.app.appsearch.AppSearchSchema.DoublePropertyConfig.Builder setCardinality(int);
}
public static final class AppSearchSchema.Int64PropertyConfig extends android.app.appsearch.AppSearchSchema.PropertyConfig {
public static final class AppSearchSchema.LongPropertyConfig extends android.app.appsearch.AppSearchSchema.PropertyConfig {
}
public static final class AppSearchSchema.Int64PropertyConfig.Builder {
ctor public AppSearchSchema.Int64PropertyConfig.Builder(@NonNull String);
method @NonNull public android.app.appsearch.AppSearchSchema.Int64PropertyConfig build();
method @NonNull public android.app.appsearch.AppSearchSchema.Int64PropertyConfig.Builder setCardinality(int);
public static final class AppSearchSchema.LongPropertyConfig.Builder {
ctor public AppSearchSchema.LongPropertyConfig.Builder(@NonNull String);
method @NonNull public android.app.appsearch.AppSearchSchema.LongPropertyConfig build();
method @NonNull public android.app.appsearch.AppSearchSchema.LongPropertyConfig.Builder setCardinality(int);
}
public abstract static class AppSearchSchema.PropertyConfig {

View File

@@ -182,7 +182,7 @@ public final class AppSearchSchema {
@IntDef(
value = {
DATA_TYPE_STRING,
DATA_TYPE_INT64,
DATA_TYPE_LONG,
DATA_TYPE_DOUBLE,
DATA_TYPE_BOOLEAN,
DATA_TYPE_BYTES,
@@ -195,7 +195,7 @@ public final class AppSearchSchema {
public static final int DATA_TYPE_STRING = 1;
/** @hide */
public static final int DATA_TYPE_INT64 = 2;
public static final int DATA_TYPE_LONG = 2;
/** @hide */
public static final int DATA_TYPE_DOUBLE = 3;
@@ -315,8 +315,8 @@ public final class AppSearchSchema {
switch (propertyBundle.getInt(PropertyConfig.DATA_TYPE_FIELD)) {
case PropertyConfig.DATA_TYPE_STRING:
return new StringPropertyConfig(propertyBundle);
case PropertyConfig.DATA_TYPE_INT64:
return new Int64PropertyConfig(propertyBundle);
case PropertyConfig.DATA_TYPE_LONG:
return new LongPropertyConfig(propertyBundle);
case PropertyConfig.DATA_TYPE_DOUBLE:
return new DoublePropertyConfig(propertyBundle);
case PropertyConfig.DATA_TYPE_BOOLEAN:
@@ -485,8 +485,13 @@ public final class AppSearchSchema {
}
}
/** Configuration for a property containing a 64-bit integer. */
public static final class Int64PropertyConfig extends PropertyConfig {
/**
* @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed.
* @hide
*/
@Deprecated
@UnsupportedAppUsage(implicitMember = "")
public static class Int64PropertyConfig extends PropertyConfig {
Int64PropertyConfig(@NonNull Bundle bundle) {
super(bundle);
}
@@ -497,6 +502,7 @@ public final class AppSearchSchema {
private @Cardinality int mCardinality = CARDINALITY_OPTIONAL;
/** Creates a new {@link Int64PropertyConfig.Builder}. */
@UnsupportedAppUsage
public Builder(@NonNull String propertyName) {
mPropertyName = Objects.requireNonNull(propertyName);
}
@@ -509,6 +515,7 @@ public final class AppSearchSchema {
*/
@SuppressWarnings("MissingGetterMatchingBuilder") // getter defined in superclass
@NonNull
@UnsupportedAppUsage
public Int64PropertyConfig.Builder setCardinality(@Cardinality int cardinality) {
Preconditions.checkArgumentInRange(
cardinality, CARDINALITY_REPEATED, CARDINALITY_REQUIRED, "cardinality");
@@ -518,16 +525,61 @@ public final class AppSearchSchema {
/** Constructs a new {@link Int64PropertyConfig} from the contents of this builder. */
@NonNull
@UnsupportedAppUsage
public Int64PropertyConfig build() {
Bundle bundle = new Bundle();
bundle.putString(NAME_FIELD, mPropertyName);
bundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_INT64);
bundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_LONG);
bundle.putInt(CARDINALITY_FIELD, mCardinality);
return new Int64PropertyConfig(bundle);
}
}
}
/** Configuration for a property containing a 64-bit integer. */
// TODO(b/181887768): This should extend directly from PropertyConfig
public static final class LongPropertyConfig extends Int64PropertyConfig {
LongPropertyConfig(@NonNull Bundle bundle) {
super(bundle);
}
/** Builder for {@link LongPropertyConfig}. */
public static final class Builder {
private final String mPropertyName;
private @Cardinality int mCardinality = CARDINALITY_OPTIONAL;
/** Creates a new {@link LongPropertyConfig.Builder}. */
public Builder(@NonNull String propertyName) {
mPropertyName = Objects.requireNonNull(propertyName);
}
/**
* The cardinality of the property (whether it is optional, required or repeated).
*
* <p>If this method is not called, the default cardinality is {@link
* PropertyConfig#CARDINALITY_OPTIONAL}.
*/
@SuppressWarnings("MissingGetterMatchingBuilder") // getter defined in superclass
@NonNull
public LongPropertyConfig.Builder setCardinality(@Cardinality int cardinality) {
Preconditions.checkArgumentInRange(
cardinality, CARDINALITY_REPEATED, CARDINALITY_REQUIRED, "cardinality");
mCardinality = cardinality;
return this;
}
/** Constructs a new {@link LongPropertyConfig} from the contents of this builder. */
@NonNull
public LongPropertyConfig build() {
Bundle bundle = new Bundle();
bundle.putString(NAME_FIELD, mPropertyName);
bundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_LONG);
bundle.putInt(CARDINALITY_FIELD, mCardinality);
return new LongPropertyConfig(bundle);
}
}
}
/** Configuration for a property containing a double-precision decimal number. */
public static final class DoublePropertyConfig extends PropertyConfig {
DoublePropertyConfig(@NonNull Bundle bundle) {

View File

@@ -103,8 +103,7 @@ public final class AppSearchLoggerHelper {
toStatsBuilder
.setNativeLatencyMillis(fromNativeStats.getLatencyMs())
.setTermCount(fromNativeStats.getNumTerms())
// TODO(b/173532925) query length missing in native
// .setNativeQueryLength(0)
.setQueryLength(fromNativeStats.getQueryLength())
.setFilteredNamespaceCount(fromNativeStats.getNumNamespacesFiltered())
.setFilteredSchemaTypeCount(fromNativeStats.getNumSchemaTypesFiltered())
.setRequestedPageSize(fromNativeStats.getRequestedPageSize())

View File

@@ -199,7 +199,7 @@ public final class GenericDocumentToProtoConverter {
case AppSearchSchema.PropertyConfig.DATA_TYPE_STRING:
documentBuilder.setPropertyString(propertyName, EMPTY_STRING_ARRAY);
break;
case AppSearchSchema.PropertyConfig.DATA_TYPE_INT64:
case AppSearchSchema.PropertyConfig.DATA_TYPE_LONG:
documentBuilder.setPropertyLong(propertyName, EMPTY_LONG_ARRAY);
break;
case AppSearchSchema.PropertyConfig.DATA_TYPE_DOUBLE:

View File

@@ -133,7 +133,7 @@ public final class SchemaToProtoConverter {
case STRING:
return toStringPropertyConfig(proto);
case INT64:
return new AppSearchSchema.Int64PropertyConfig.Builder(proto.getPropertyName())
return new AppSearchSchema.LongPropertyConfig.Builder(proto.getPropertyName())
.setCardinality(proto.getCardinality().getNumber())
.build();
case DOUBLE:

View File

@@ -0,0 +1,181 @@
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.server.appsearch.external.localstorage.stats;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.app.appsearch.AppSearchResult;
import android.app.appsearch.RemoveByDocumentIdRequest;
import android.app.appsearch.SearchSpec;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;
/**
* Class holds detailed stats for {@link
* android.app.appsearch.AppSearchSession#remove(RemoveByDocumentIdRequest)} and {@link
* android.app.appsearch.AppSearchSession#remove(String, SearchSpec)}
*
* @hide
*/
public final class RemoveStats {
@IntDef(
value = {
// It needs to be sync with DeleteType.Code in
// external/icing/proto/icing/proto/logging.proto#DeleteStatsProto
UNKNOWN,
SINGLE,
QUERY,
NAMESPACE,
SCHEMA_TYPE,
})
@Retention(RetentionPolicy.SOURCE)
public @interface DeleteType {}
/** Default. Should never be used. */
public static final int UNKNOWN = 0;
/** Delete by namespace + id. */
public static final int SINGLE = 1;
/** Delete by query. */
public static final int QUERY = 2;
/** Delete by namespace. */
public static final int NAMESPACE = 3;
/** Delete by schema type. */
public static final int SCHEMA_TYPE = 4;
@NonNull private final String mPackageName;
@NonNull private final String mDatabase;
/**
* The status code returned by {@link AppSearchResult#getResultCode()} for the call or internal
* state.
*/
@AppSearchResult.ResultCode private final int mStatusCode;
private final int mTotalLatencyMillis;
private final int mNativeLatencyMillis;
@DeleteType private final int mNativeDeleteType;
private final int mNativeNumDocumentsDeleted;
RemoveStats(@NonNull Builder builder) {
Objects.requireNonNull(builder);
mPackageName = builder.mPackageName;
mDatabase = builder.mDatabase;
mStatusCode = builder.mStatusCode;
mTotalLatencyMillis = builder.mTotalLatencyMillis;
mNativeLatencyMillis = builder.mNativeLatencyMillis;
mNativeDeleteType = builder.mNativeDeleteType;
mNativeNumDocumentsDeleted = builder.mNativeNumDocumentsDeleted;
}
/** Returns calling package name. */
@NonNull
public String getPackageName() {
return mPackageName;
}
/** Returns calling database name. */
@NonNull
public String getDatabase() {
return mDatabase;
}
/** Returns status code for this remove. */
@AppSearchResult.ResultCode
public int getStatusCode() {
return mStatusCode;
}
/** Returns total latency of this remove in millis. */
public int getTotalLatencyMillis() {
return mTotalLatencyMillis;
}
/** Returns how much time in millis spent in the native code. */
public int getNativeLatencyMillis() {
return mNativeLatencyMillis;
}
/** Returns what type of delete for this remove call. */
@DeleteType
public int getDeleteType() {
return mNativeDeleteType;
}
/** Returns how many documents get deleted in this call. */
public int getDeletedDocumentCount() {
return mNativeNumDocumentsDeleted;
}
/** Builder for {@link RemoveStats}. */
public static class Builder {
@NonNull final String mPackageName;
@NonNull final String mDatabase;
@AppSearchResult.ResultCode int mStatusCode;
int mTotalLatencyMillis;
int mNativeLatencyMillis;
@DeleteType int mNativeDeleteType;
int mNativeNumDocumentsDeleted;
/** Constructor for the {@link Builder}. */
public Builder(@NonNull String packageName, @NonNull String database) {
mPackageName = Objects.requireNonNull(packageName);
mDatabase = Objects.requireNonNull(database);
}
/** Sets the status code. */
@NonNull
public Builder setStatusCode(@AppSearchResult.ResultCode int statusCode) {
mStatusCode = statusCode;
return this;
}
/** Sets total latency in millis. */
@NonNull
public Builder setTotalLatencyMillis(int totalLatencyMillis) {
mTotalLatencyMillis = totalLatencyMillis;
return this;
}
/** Sets native latency in millis. */
@NonNull
public Builder setNativeLatencyMillis(int nativeLatencyMillis) {
mNativeLatencyMillis = nativeLatencyMillis;
return this;
}
/** Sets delete type for this call. */
@NonNull
public Builder setDeleteType(@DeleteType int nativeDeleteType) {
mNativeDeleteType = nativeDeleteType;
return this;
}
/** Sets how many documents get deleted for this call. */
@NonNull
public Builder setDeletedDocumentCount(int nativeNumDocumentsDeleted) {
mNativeNumDocumentsDeleted = nativeNumDocumentsDeleted;
return this;
}
/** Creates a {@link RemoveStats}. */
@NonNull
public RemoveStats build() {
return new RemoveStats(/* builder= */ this);
}
}
}

View File

@@ -1 +1 @@
a83c33a5a394141fea1d065ce0fab513a62d4bcf
c6630eba424d98dd54ece674e769d9b0b883e410

View File

@@ -92,7 +92,7 @@ public class AppSearchShortcutInfo extends GenericDocument {
.setIndexingType(AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_PREFIXES)
.build()
).addProperty(new AppSearchSchema.Int64PropertyConfig.Builder(KEY_SHORT_LABEL_RES_ID)
).addProperty(new AppSearchSchema.LongPropertyConfig.Builder(KEY_SHORT_LABEL_RES_ID)
.setCardinality(AppSearchSchema.PropertyConfig.CARDINALITY_OPTIONAL)
.build()
@@ -108,7 +108,7 @@ public class AppSearchShortcutInfo extends GenericDocument {
.setIndexingType(AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_PREFIXES)
.build()
).addProperty(new AppSearchSchema.Int64PropertyConfig.Builder(KEY_LONG_LABEL_RES_ID)
).addProperty(new AppSearchSchema.LongPropertyConfig.Builder(KEY_LONG_LABEL_RES_ID)
.setCardinality(AppSearchSchema.PropertyConfig.CARDINALITY_OPTIONAL)
.build()
@@ -124,7 +124,7 @@ public class AppSearchShortcutInfo extends GenericDocument {
.setIndexingType(AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_NONE)
.build()
).addProperty(new AppSearchSchema.Int64PropertyConfig.Builder(
).addProperty(new AppSearchSchema.LongPropertyConfig.Builder(
KEY_DISABLED_MESSAGE_RES_ID)
.setCardinality(AppSearchSchema.PropertyConfig.CARDINALITY_OPTIONAL)
.build()
@@ -170,7 +170,7 @@ public class AppSearchShortcutInfo extends GenericDocument {
.setIndexingType(AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_EXACT_TERMS)
.build()
).addProperty(new AppSearchSchema.Int64PropertyConfig.Builder(KEY_IMPLICIT_RANK)
).addProperty(new AppSearchSchema.LongPropertyConfig.Builder(KEY_IMPLICIT_RANK)
.setCardinality(AppSearchSchema.PropertyConfig.CARDINALITY_OPTIONAL)
.build()
@@ -184,7 +184,7 @@ public class AppSearchShortcutInfo extends GenericDocument {
.setIndexingType(AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_EXACT_TERMS)
.build()
).addProperty(new AppSearchSchema.Int64PropertyConfig.Builder(KEY_ICON_RES_ID)
).addProperty(new AppSearchSchema.LongPropertyConfig.Builder(KEY_ICON_RES_ID)
.setCardinality(AppSearchSchema.PropertyConfig.CARDINALITY_OPTIONAL)
.build()

View File

@@ -193,8 +193,7 @@ public class AppSearchLoggerTest {
public void testAppSearchLoggerHelper_testCopyNativeStats_search() {
int nativeLatencyMillis = 4;
int nativeNumTerms = 5;
// TODO(b/185804196) query length needs to be added in the native stats.
// int nativeQueryLength = 6;
int nativeQueryLength = 6;
int nativeNumNamespacesFiltered = 7;
int nativeNumSchemaTypesFiltered = 8;
int nativeRequestedPageSize = 9;
@@ -211,6 +210,7 @@ public class AppSearchLoggerTest {
QueryStatsProto.newBuilder()
.setLatencyMs(nativeLatencyMillis)
.setNumTerms(nativeNumTerms)
.setQueryLength(nativeQueryLength)
.setNumNamespacesFiltered(nativeNumNamespacesFiltered)
.setNumSchemaTypesFiltered(nativeNumSchemaTypesFiltered)
.setRequestedPageSize(nativeRequestedPageSize)
@@ -235,7 +235,7 @@ public class AppSearchLoggerTest {
SearchStats sStats = qBuilder.build();
assertThat(sStats.getNativeLatencyMillis()).isEqualTo(nativeLatencyMillis);
assertThat(sStats.getTermCount()).isEqualTo(nativeNumTerms);
// assertThat(sStats.getNativeQueryLength()).isEqualTo(nativeQueryLength);
assertThat(sStats.getQueryLength()).isEqualTo(nativeQueryLength);
assertThat(sStats.getFilteredNamespaceCount()).isEqualTo(nativeNumNamespacesFiltered);
assertThat(sStats.getFilteredSchemaTypeCount()).isEqualTo(nativeNumSchemaTypesFiltered);
assertThat(sStats.getRequestedPageSize()).isEqualTo(nativeRequestedPageSize);

View File

@@ -110,7 +110,7 @@ public class SchemaToProtoConverterTest {
.TOKENIZER_TYPE_PLAIN)
.build())
.addProperty(
new AppSearchSchema.Int64PropertyConfig.Builder("pubDate")
new AppSearchSchema.LongPropertyConfig.Builder("pubDate")
.setCardinality(
AppSearchSchema.PropertyConfig.CARDINALITY_OPTIONAL)
.build())

View File

@@ -301,4 +301,28 @@ public class AppSearchStatsTest {
assertThat(sStats.getBackwardsIncompatibleTypeChangeCount())
.isEqualTo(backwardsIncompatibleTypeChangeCount);
}
@Test
public void testAppSearchStats_RemoveStats() {
int nativeLatencyMillis = 1;
@RemoveStats.DeleteType int deleteType = 2;
int documentDeletedCount = 3;
final RemoveStats rStats =
new RemoveStats.Builder(TEST_PACKAGE_NAME, TEST_DATA_BASE)
.setStatusCode(TEST_STATUS_CODE)
.setTotalLatencyMillis(TEST_TOTAL_LATENCY_MILLIS)
.setNativeLatencyMillis(nativeLatencyMillis)
.setDeleteType(deleteType)
.setDeletedDocumentCount(documentDeletedCount)
.build();
assertThat(rStats.getPackageName()).isEqualTo(TEST_PACKAGE_NAME);
assertThat(rStats.getDatabase()).isEqualTo(TEST_DATA_BASE);
assertThat(rStats.getStatusCode()).isEqualTo(TEST_STATUS_CODE);
assertThat(rStats.getTotalLatencyMillis()).isEqualTo(TEST_TOTAL_LATENCY_MILLIS);
assertThat(rStats.getNativeLatencyMillis()).isEqualTo(nativeLatencyMillis);
assertThat(rStats.getDeleteType()).isEqualTo(deleteType);
assertThat(rStats.getDeletedDocumentCount()).isEqualTo(documentDeletedCount);
}
}