• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package android.app.appsearch;
17 
18 import android.annotation.FlaggedApi;
19 import android.annotation.NonNull;
20 import android.app.appsearch.aidl.AppSearchBatchResultParcelV2;
21 import android.app.appsearch.safeparcel.AbstractSafeParcelable;
22 import android.app.appsearch.safeparcel.SafeParcelable;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 
26 import com.android.appsearch.flags.Flags;
27 
28 import java.util.Objects;
29 
30 /**
31  * The response to provide batch operation results of {@link AppSearchSession#commitBlob}.
32  *
33  * <p>This class is used to retrieve the result of a batch commit operation on a collection of blob
34  * handles.
35  */
36 @FlaggedApi(Flags.FLAG_ENABLE_BLOB_STORE)
37 // TODO(b/384721898): Switch to JSpecify annotations
38 @SuppressWarnings({"HiddenSuperclass", "JSpecifyNullness"})
39 @SafeParcelable.Class(creator = "CommitBlobResponseCreator")
40 public final class CommitBlobResponse extends AbstractSafeParcelable {
41 
42     public static final @NonNull Parcelable.Creator<CommitBlobResponse> CREATOR =
43             new CommitBlobResponseCreator();
44 
45     @Field(id = 1, getter = "getResponseParcel")
46     private final AppSearchBatchResultParcelV2<AppSearchBlobHandle, Void> mResultParcel;
47 
48     /** Creates a {@link CommitBlobResponse} with given {@link AppSearchBatchResult}. */
CommitBlobResponse(@onNull AppSearchBatchResult<AppSearchBlobHandle, Void> result)49     public CommitBlobResponse(@NonNull AppSearchBatchResult<AppSearchBlobHandle, Void> result) {
50         this(AppSearchBatchResultParcelV2.fromBlobHandleToVoid(result));
51     }
52 
53     @Constructor
CommitBlobResponse( @aramid = 1) @onNull AppSearchBatchResultParcelV2<AppSearchBlobHandle, Void> resultParcel)54     CommitBlobResponse(
55             @Param(id = 1) @NonNull
56                     AppSearchBatchResultParcelV2<AppSearchBlobHandle, Void> resultParcel) {
57         mResultParcel = Objects.requireNonNull(resultParcel);
58     }
59 
60     /**
61      * Returns the {@link AppSearchBatchResult} object containing the results of the commit
62      * operation for each {@link AppSearchBlobHandle}.
63      *
64      * @return A {@link AppSearchBatchResult} maps {@link AppSearchBlobHandle}s which is a unique
65      *     identifier for a specific blob being committed to the outcome of that commit. If the
66      *     operation was successful, the result for that handle is {@code null}; if there was an
67      *     error, the result contains an {@link AppSearchResult} with details of the failure.
68      */
getResult()69     public @NonNull AppSearchBatchResult<AppSearchBlobHandle, Void> getResult() {
70         return mResultParcel.getResult();
71     }
72 
73     /**
74      * Retrieves the underlying parcel representation of the batch result.
75      *
76      * @hide
77      */
getResponseParcel()78     public @NonNull AppSearchBatchResultParcelV2<AppSearchBlobHandle, Void> getResponseParcel() {
79         return mResultParcel;
80     }
81 
82     @Override
writeToParcel(@onNull Parcel dest, int flags)83     public void writeToParcel(@NonNull Parcel dest, int flags) {
84         CommitBlobResponseCreator.writeToParcel(this, dest, flags);
85     }
86 }
87