diff --git a/apex/appsearch/framework/Android.bp b/apex/appsearch/framework/Android.bp index 5def55fd31ff1..5bf0b84b570d1 100644 --- a/apex/appsearch/framework/Android.bp +++ b/apex/appsearch/framework/Android.bp @@ -33,9 +33,10 @@ filegroup { java_sdk_library { name: "framework-appsearch", - srcs: [ ":framework-appsearch-sources" ], + srcs: [":framework-appsearch-sources"], sdk_version: "core_platform", // TODO(b/146218515) should be module_current impl_only_libs: ["framework-minus-apex"], // TODO(b/146218515) should be removed + libs: ["unsupportedappusage"], // TODO(b/181887768) should be removed defaults: ["framework-module-defaults"], permitted_packages: ["android.app.appsearch"], aidl: { diff --git a/apex/appsearch/framework/java/android/app/appsearch/AppSearchSession.java b/apex/appsearch/framework/java/android/app/appsearch/AppSearchSession.java index 64ac63c2b8499..c112d0efc209c 100644 --- a/apex/appsearch/framework/java/android/app/appsearch/AppSearchSession.java +++ b/apex/appsearch/framework/java/android/app/appsearch/AppSearchSession.java @@ -21,6 +21,7 @@ import android.annotation.NonNull; import android.annotation.UserIdInt; import android.app.appsearch.exceptions.AppSearchException; import android.app.appsearch.util.SchemaMigrationUtil; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Bundle; import android.os.RemoteException; import android.os.SystemClock; @@ -294,6 +295,19 @@ public final class AppSearchSession implements Closeable { } } + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + public void getByUri( + @NonNull GetByUriRequest request, + @NonNull @CallbackExecutor Executor executor, + @NonNull BatchResultCallback callback) { + getByDocumentId(request.toGetByDocumentIdRequest(), executor, callback); + } + /** * Gets {@link GenericDocument} objects by document IDs in a namespace from the {@link * AppSearchSession} database. @@ -488,6 +502,19 @@ public final class AppSearchSession implements Closeable { } } + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + public void remove( + @NonNull RemoveByUriRequest request, + @NonNull @CallbackExecutor Executor executor, + @NonNull BatchResultCallback callback) { + remove(request.toRemoveByDocumentIdRequest(), executor, callback); + } + /** * Removes {@link GenericDocument} objects by document IDs in a namespace from the {@link * AppSearchSession} database. diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/AppSearchSchema.java b/apex/appsearch/framework/java/external/android/app/appsearch/AppSearchSchema.java index 2a941fb54833c..4378a9811f124 100644 --- a/apex/appsearch/framework/java/external/android/app/appsearch/AppSearchSchema.java +++ b/apex/appsearch/framework/java/external/android/app/appsearch/AppSearchSchema.java @@ -21,6 +21,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.app.appsearch.exceptions.IllegalSchemaException; import android.app.appsearch.util.BundleUtil; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Bundle; import android.util.ArraySet; @@ -746,6 +747,31 @@ public final class AppSearchSchema { mBundle.putString(SCHEMA_TYPE_FIELD, schemaType); } + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + public Builder(@NonNull String propertyName) { + mBundle.putString(NAME_FIELD, propertyName); + mBundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_DOCUMENT); + mBundle.putInt(CARDINALITY_FIELD, CARDINALITY_OPTIONAL); + mBundle.putBoolean(INDEX_NESTED_PROPERTIES_FIELD, false); + } + + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + @NonNull + public Builder setSchemaType(@NonNull String schemaType) { + mBundle.putString(SCHEMA_TYPE_FIELD, schemaType); + return this; + } + /** * The cardinality of the property (whether it is optional, required or repeated). * @@ -777,6 +803,18 @@ public final class AppSearchSchema { return this; } + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + @NonNull + public DocumentPropertyConfig.Builder setIndexNestedProperties( + boolean indexNestedProperties) { + return setShouldIndexNestedProperties(indexNestedProperties); + } + /** * Constructs a new {@link PropertyConfig} from the contents of this builder. * diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java b/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java index 2e427497e16d6..39a48847d1c23 100644 --- a/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java +++ b/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java @@ -22,6 +22,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SuppressLint; import android.app.appsearch.util.BundleUtil; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Bundle; import android.os.Parcelable; import android.util.Log; @@ -137,6 +138,17 @@ public class GenericDocument { return mBundle; } + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + @NonNull + public String getUri() { + return getId(); + } + /** Returns the unique identifier of the {@link GenericDocument}. */ @NonNull public String getId() { diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/GetByUriRequest.java b/apex/appsearch/framework/java/external/android/app/appsearch/GetByUriRequest.java new file mode 100644 index 0000000000000..7b05eac43070e --- /dev/null +++ b/apex/appsearch/framework/java/external/android/app/appsearch/GetByUriRequest.java @@ -0,0 +1,200 @@ +/* + * Copyright 2020 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 android.app.appsearch; + +import android.annotation.NonNull; +import android.compat.annotation.UnsupportedAppUsage; +import android.util.ArrayMap; +import android.util.ArraySet; + +import com.android.internal.util.Preconditions; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +/** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ +@Deprecated +public final class GetByUriRequest { + /** + * Schema type to be used in {@link GetByUriRequest.Builder#addProjection} to apply property + * paths to all results, excepting any types that have had their own, specific property paths + * set. + */ + public static final String PROJECTION_SCHEMA_TYPE_WILDCARD = "*"; + + private final String mNamespace; + private final Set mIds; + private final Map> mTypePropertyPathsMap; + + GetByUriRequest( + @NonNull String namespace, + @NonNull Set ids, + @NonNull Map> typePropertyPathsMap) { + mNamespace = Objects.requireNonNull(namespace); + mIds = Objects.requireNonNull(ids); + mTypePropertyPathsMap = Objects.requireNonNull(typePropertyPathsMap); + } + + /** Returns the namespace attached to the request. */ + @NonNull + public String getNamespace() { + return mNamespace; + } + + /** Returns the set of document IDs attached to the request. */ + @NonNull + public Set getUris() { + return Collections.unmodifiableSet(mIds); + } + + /** + * Returns a map from schema type to property paths to be used for projection. + * + *

If the map is empty, then all properties will be retrieved for all results. + * + *

Calling this function repeatedly is inefficient. Prefer to retain the Map returned by this + * function, rather than calling it multiple times. + */ + @NonNull + public Map> getProjections() { + Map> copy = new ArrayMap<>(); + for (Map.Entry> entry : mTypePropertyPathsMap.entrySet()) { + copy.put(entry.getKey(), new ArrayList<>(entry.getValue())); + } + return copy; + } + + /** + * Returns a map from schema type to property paths to be used for projection. + * + *

If the map is empty, then all properties will be retrieved for all results. + * + *

A more efficient version of {@link #getProjections}, but it returns a modifiable map. This + * is not meant to be unhidden and should only be used by internal classes. + * + * @hide + */ + @NonNull + public Map> getProjectionsInternal() { + return mTypePropertyPathsMap; + } + + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @NonNull + public GetByDocumentIdRequest toGetByDocumentIdRequest() { + GetByDocumentIdRequest.Builder builder = + new GetByDocumentIdRequest.Builder(mNamespace).addIds(mIds); + for (Map.Entry> projection : mTypePropertyPathsMap.entrySet()) { + builder.addProjection(projection.getKey(), projection.getValue()); + } + return builder.build(); + } + + /** + * Builder for {@link GetByUriRequest} objects. + * + *

Once {@link #build} is called, the instance can no longer be used. + */ + public static final class Builder { + private final String mNamespace; + private final Set mIds = new ArraySet<>(); + private final Map> mProjectionTypePropertyPaths = new ArrayMap<>(); + private boolean mBuilt = false; + + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + public Builder(@NonNull String namespace) { + mNamespace = Objects.requireNonNull(namespace); + } + + /** + * Adds one or more document IDs to the request. + * + * @throws IllegalStateException if the builder has already been used. + */ + @NonNull + public Builder addUris(@NonNull String... ids) { + Objects.requireNonNull(ids); + return addUris(Arrays.asList(ids)); + } + + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + @NonNull + public Builder addUris(@NonNull Collection ids) { + Preconditions.checkState(!mBuilt, "Builder has already been used"); + Objects.requireNonNull(ids); + mIds.addAll(ids); + return this; + } + + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + @NonNull + public Builder addProjection( + @NonNull String schemaType, @NonNull Collection propertyPaths) { + Preconditions.checkState(!mBuilt, "Builder has already been used"); + Objects.requireNonNull(schemaType); + Objects.requireNonNull(propertyPaths); + List propertyPathsList = new ArrayList<>(propertyPaths.size()); + for (String propertyPath : propertyPaths) { + Objects.requireNonNull(propertyPath); + propertyPathsList.add(propertyPath); + } + mProjectionTypePropertyPaths.put(schemaType, propertyPathsList); + return this; + } + + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + @NonNull + public GetByUriRequest build() { + Preconditions.checkState(!mBuilt, "Builder has already been used"); + mBuilt = true; + return new GetByUriRequest(mNamespace, mIds, mProjectionTypePropertyPaths); + } + } +} diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/RemoveByUriRequest.java b/apex/appsearch/framework/java/external/android/app/appsearch/RemoveByUriRequest.java new file mode 100644 index 0000000000000..9c74966ada58c --- /dev/null +++ b/apex/appsearch/framework/java/external/android/app/appsearch/RemoveByUriRequest.java @@ -0,0 +1,125 @@ +/* + * Copyright 2020 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 android.app.appsearch; + +import android.annotation.NonNull; +import android.compat.annotation.UnsupportedAppUsage; +import android.util.ArraySet; + +import com.android.internal.util.Preconditions; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Objects; +import java.util.Set; + +/** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ +@Deprecated +public final class RemoveByUriRequest { + private final String mNamespace; + private final Set mIds; + + RemoveByUriRequest(String namespace, Set ids) { + mNamespace = namespace; + mIds = ids; + } + + /** Returns the namespace to remove documents from. */ + @NonNull + public String getNamespace() { + return mNamespace; + } + + /** Returns the set of document IDs attached to the request. */ + @NonNull + public Set getUris() { + return Collections.unmodifiableSet(mIds); + } + + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @NonNull + public RemoveByDocumentIdRequest toRemoveByDocumentIdRequest() { + return new RemoveByDocumentIdRequest.Builder(mNamespace).addIds(mIds).build(); + } + + /** + * Builder for {@link RemoveByUriRequest} objects. + * + *

Once {@link #build} is called, the instance can no longer be used. + */ + public static final class Builder { + private final String mNamespace; + private final Set mIds = new ArraySet<>(); + private boolean mBuilt = false; + + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + public Builder(@NonNull String namespace) { + mNamespace = Objects.requireNonNull(namespace); + } + + /** + * Adds one or more document IDs to the request. + * + * @throws IllegalStateException if the builder has already been used. + */ + @NonNull + public Builder addUris(@NonNull String... ids) { + Objects.requireNonNull(ids); + return addUris(Arrays.asList(ids)); + } + + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + @NonNull + public Builder addUris(@NonNull Collection ids) { + Preconditions.checkState(!mBuilt, "Builder has already been used"); + Objects.requireNonNull(ids); + mIds.addAll(ids); + return this; + } + + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + @NonNull + public RemoveByUriRequest build() { + Preconditions.checkState(!mBuilt, "Builder has already been used"); + mBuilt = true; + return new RemoveByUriRequest(mNamespace, mIds); + } + } +} diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/ReportUsageRequest.java b/apex/appsearch/framework/java/external/android/app/appsearch/ReportUsageRequest.java index 8c8ade8c52d06..5cb59b3030ee6 100644 --- a/apex/appsearch/framework/java/external/android/app/appsearch/ReportUsageRequest.java +++ b/apex/appsearch/framework/java/external/android/app/appsearch/ReportUsageRequest.java @@ -18,6 +18,7 @@ package android.app.appsearch; import android.annotation.CurrentTimeMillisLong; import android.annotation.NonNull; +import android.compat.annotation.UnsupportedAppUsage; import com.android.internal.util.Preconditions; @@ -68,7 +69,8 @@ public final class ReportUsageRequest { /** Builder for {@link ReportUsageRequest} objects. */ public static final class Builder { private final String mNamespace; - private final String mDocumentId; + // TODO(b/181887768): Make this final + private String mDocumentId; private Long mUsageTimestampMillis; private boolean mBuilt = false; @@ -78,6 +80,40 @@ public final class ReportUsageRequest { mDocumentId = Objects.requireNonNull(documentId); } + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + public Builder(@NonNull String namespace) { + mNamespace = Objects.requireNonNull(namespace); + } + + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + @NonNull + public Builder setUri(@NonNull String uri) { + mDocumentId = uri; + return this; + } + + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + @NonNull + public ReportUsageRequest.Builder setUsageTimeMillis( + @CurrentTimeMillisLong long usageTimestampMillis) { + return setUsageTimestampMillis(usageTimestampMillis); + } + /** * Sets the timestamp in milliseconds of the usage report (the time at which the document * was used). diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/SearchResult.java b/apex/appsearch/framework/java/external/android/app/appsearch/SearchResult.java index b648071a93c17..9a1796cbe94e3 100644 --- a/apex/appsearch/framework/java/external/android/app/appsearch/SearchResult.java +++ b/apex/appsearch/framework/java/external/android/app/appsearch/SearchResult.java @@ -192,7 +192,7 @@ public final class SearchResult { return this; } - /** @deprecated this method exists only for dogfooder transition and must be removed */ + /** @deprecated This method exists only for dogfooder transition and must be removed. */ @Deprecated @NonNull public Builder addMatch(@NonNull MatchInfo matchInfo) { diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/SetSchemaResponse.java b/apex/appsearch/framework/java/external/android/app/appsearch/SetSchemaResponse.java index b7bd3878d4fa3..7ad5fe877480e 100644 --- a/apex/appsearch/framework/java/external/android/app/appsearch/SetSchemaResponse.java +++ b/apex/appsearch/framework/java/external/android/app/appsearch/SetSchemaResponse.java @@ -18,6 +18,7 @@ package android.app.appsearch; import android.annotation.NonNull; import android.annotation.Nullable; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Bundle; import android.util.ArraySet; @@ -324,6 +325,17 @@ public class SetSchemaResponse { return mBundle.getString(NAMESPACE_FIELD, /*defaultValue=*/ ""); } + /** + * @deprecated TODO(b/181887768): Exists for dogfood transition; must be removed. + * @hide + */ + @Deprecated + @UnsupportedAppUsage + @NonNull + public String getUri() { + return getDocumentId(); + } + /** Returns the id of the {@link GenericDocument} that failed to be migrated. */ @NonNull public String getDocumentId() {