1 /*
2  * Copyright (C) 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 
17 package android.app.appsearch.aidl;
18 
19 import android.annotation.ElapsedRealtimeLong;
20 import android.annotation.NonNull;
21 import android.app.appsearch.RemoveByDocumentIdRequest;
22 import android.app.appsearch.safeparcel.AbstractSafeParcelable;
23 import android.app.appsearch.safeparcel.SafeParcelable;
24 import android.os.Parcel;
25 import android.os.Parcelable;
26 import android.os.UserHandle;
27 
28 import java.util.Objects;
29 
30 /**
31  * Encapsulates a request to make a binder call to remove documents by id.
32  *
33  * @hide
34  */
35 @SafeParcelable.Class(creator = "RemoveByDocumentIdAidlRequestCreator")
36 public class RemoveByDocumentIdAidlRequest extends AbstractSafeParcelable {
37     @NonNull
38     public static final Parcelable.Creator<RemoveByDocumentIdAidlRequest> CREATOR =
39             new RemoveByDocumentIdAidlRequestCreator();
40 
41     @NonNull
42     @Field(id = 1, getter = "getCallerAttributionSource")
43     private final AppSearchAttributionSource mCallerAttributionSource;
44 
45     @NonNull
46     @Field(id = 2, getter = "getDatabaseName")
47     private final String mDatabaseName;
48 
49     @NonNull
50     @Field(id = 3, getter = "getRemoveByDocumentIdRequest")
51     final RemoveByDocumentIdRequest mRemoveByDocumentIdRequest;
52 
53     @NonNull
54     @Field(id = 4, getter = "getUserHandle")
55     private final UserHandle mUserHandle;
56 
57     @Field(id = 5, getter = "getBinderCallStartTimeMillis")
58     @ElapsedRealtimeLong
59     private final long mBinderCallStartTimeMillis;
60 
61     /**
62      * Removes documents by ID.
63      *
64      * @param callerAttributionSource The permission identity of the package the document is in.
65      * @param databaseName The databaseName the document is in.
66      * @param removeByDocumentIdRequest The {@link RemoveByDocumentIdRequest} to remove document.
67      * @param userHandle Handle of the calling user
68      * @param binderCallStartTimeMillis start timestamp of binder call in Millis
69      */
70     @Constructor
RemoveByDocumentIdAidlRequest( @aramid = 1) @onNull AppSearchAttributionSource callerAttributionSource, @Param(id = 2) @NonNull String databaseName, @Param(id = 3) @NonNull RemoveByDocumentIdRequest removeByDocumentIdRequest, @Param(id = 4) @NonNull UserHandle userHandle, @Param(id = 5) @ElapsedRealtimeLong long binderCallStartTimeMillis)71     public RemoveByDocumentIdAidlRequest(
72             @Param(id = 1) @NonNull AppSearchAttributionSource callerAttributionSource,
73             @Param(id = 2) @NonNull String databaseName,
74             @Param(id = 3) @NonNull RemoveByDocumentIdRequest removeByDocumentIdRequest,
75             @Param(id = 4) @NonNull UserHandle userHandle,
76             @Param(id = 5) @ElapsedRealtimeLong long binderCallStartTimeMillis) {
77         mCallerAttributionSource = Objects.requireNonNull(callerAttributionSource);
78         mDatabaseName = Objects.requireNonNull(databaseName);
79         mRemoveByDocumentIdRequest = Objects.requireNonNull(removeByDocumentIdRequest);
80         mUserHandle = Objects.requireNonNull(userHandle);
81         mBinderCallStartTimeMillis = binderCallStartTimeMillis;
82     }
83 
84     @NonNull
getCallerAttributionSource()85     public AppSearchAttributionSource getCallerAttributionSource() {
86         return mCallerAttributionSource;
87     }
88 
89     @NonNull
getDatabaseName()90     public String getDatabaseName() {
91         return mDatabaseName;
92     }
93 
94     @NonNull
getRemoveByDocumentIdRequest()95     public RemoveByDocumentIdRequest getRemoveByDocumentIdRequest() {
96         return mRemoveByDocumentIdRequest;
97     }
98 
99     @NonNull
getUserHandle()100     public UserHandle getUserHandle() {
101         return mUserHandle;
102     }
103 
104     @ElapsedRealtimeLong
getBinderCallStartTimeMillis()105     public long getBinderCallStartTimeMillis() {
106         return mBinderCallStartTimeMillis;
107     }
108 
109     @Override
writeToParcel(@onNull Parcel dest, int flags)110     public void writeToParcel(@NonNull Parcel dest, int flags) {
111         RemoveByDocumentIdAidlRequestCreator.writeToParcel(this, dest, flags);
112     }
113 }
114