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.SearchSpec;
22 import android.app.appsearch.safeparcel.AbstractSafeParcelable;
23 import android.app.appsearch.safeparcel.SafeParcelable;
24 import android.os.Parcel;
25 import android.os.ParcelFileDescriptor;
26 import android.os.Parcelable;
27 import android.os.UserHandle;
28 
29 import java.util.Objects;
30 
31 /**
32  * Encapsulates a request to make a binder call to search for documents based on the given
33  * specifications and save the results to the given {@link ParcelFileDescriptor}.
34  *
35  * @hide
36  */
37 @SafeParcelable.Class(creator = "WriteSearchResultsToFileAidlRequestCreator")
38 public class WriteSearchResultsToFileAidlRequest extends AbstractSafeParcelable {
39     @NonNull
40     public static final Parcelable.Creator<WriteSearchResultsToFileAidlRequest> CREATOR =
41             new WriteSearchResultsToFileAidlRequestCreator();
42 
43     @NonNull
44     @Field(id = 1, getter = "getCallerAttributionSource")
45     private final AppSearchAttributionSource mCallerAttributionSource;
46 
47     @NonNull
48     @Field(id = 2, getter = "getDatabaseName")
49     private final String mDatabaseName;
50 
51     @NonNull
52     @Field(id = 3, getter = "getParcelFileDescriptor")
53     private final ParcelFileDescriptor mParcelFileDescriptor;
54 
55     @NonNull
56     @Field(id = 4, getter = "getSearchExpression")
57     private final String mSearchExpression;
58 
59     @NonNull
60     @Field(id = 5, getter = "getSearchSpec")
61     private final SearchSpec mSearchSpec;
62 
63     @NonNull
64     @Field(id = 6, getter = "getUserHandle")
65     private final UserHandle mUserHandle;
66 
67     @Field(id = 7, getter = "getBinderCallStartTimeMillis")
68     @ElapsedRealtimeLong
69     private final long mBinderCallStartTimeMillis;
70 
71     /**
72      * Searches a document based on a given specifications.
73      *
74      * <p>Documents will be save to the given ParcelFileDescriptor
75      *
76      * @param callerAttributionSource The permission identity of the package to search over.
77      * @param databaseName The databaseName this search is for.
78      * @param parcelFileDescriptor The ParcelFileDescriptor where documents should be written to.
79      * @param searchExpression String to search for.
80      * @param searchSpec SearchSpec
81      * @param userHandle Handle of the calling user.
82      * @param binderCallStartTimeMillis start timestamp of binder call in Millis
83      */
84     @Constructor
WriteSearchResultsToFileAidlRequest( @aramid = 1) @onNull AppSearchAttributionSource callerAttributionSource, @Param(id = 2) @NonNull String databaseName, @Param(id = 3) @NonNull ParcelFileDescriptor parcelFileDescriptor, @Param(id = 4) @NonNull String searchExpression, @Param(id = 5) @NonNull SearchSpec searchSpec, @Param(id = 6) @NonNull UserHandle userHandle, @Param(id = 7) @ElapsedRealtimeLong long binderCallStartTimeMillis)85     public WriteSearchResultsToFileAidlRequest(
86             @Param(id = 1) @NonNull AppSearchAttributionSource callerAttributionSource,
87             @Param(id = 2) @NonNull String databaseName,
88             @Param(id = 3) @NonNull ParcelFileDescriptor parcelFileDescriptor,
89             @Param(id = 4) @NonNull String searchExpression,
90             @Param(id = 5) @NonNull SearchSpec searchSpec,
91             @Param(id = 6) @NonNull UserHandle userHandle,
92             @Param(id = 7) @ElapsedRealtimeLong long binderCallStartTimeMillis) {
93         mCallerAttributionSource = Objects.requireNonNull(callerAttributionSource);
94         mDatabaseName = Objects.requireNonNull(databaseName);
95         mParcelFileDescriptor = Objects.requireNonNull(parcelFileDescriptor);
96         mSearchExpression = Objects.requireNonNull(searchExpression);
97         mSearchSpec = Objects.requireNonNull(searchSpec);
98         mUserHandle = Objects.requireNonNull(userHandle);
99         mBinderCallStartTimeMillis = binderCallStartTimeMillis;
100     }
101 
102     @NonNull
getCallerAttributionSource()103     public AppSearchAttributionSource getCallerAttributionSource() {
104         return mCallerAttributionSource;
105     }
106 
107     @NonNull
getDatabaseName()108     public String getDatabaseName() {
109         return mDatabaseName;
110     }
111 
112     @NonNull
getParcelFileDescriptor()113     public ParcelFileDescriptor getParcelFileDescriptor() {
114         return mParcelFileDescriptor;
115     }
116 
117     @NonNull
getSearchExpression()118     public String getSearchExpression() {
119         return mSearchExpression;
120     }
121 
122     @NonNull
getSearchSpec()123     public SearchSpec getSearchSpec() {
124         return mSearchSpec;
125     }
126 
127     @NonNull
getUserHandle()128     public UserHandle getUserHandle() {
129         return mUserHandle;
130     }
131 
132     @ElapsedRealtimeLong
getBinderCallStartTimeMillis()133     public long getBinderCallStartTimeMillis() {
134         return mBinderCallStartTimeMillis;
135     }
136 
137     @Override
writeToParcel(@onNull Parcel dest, int flags)138     public void writeToParcel(@NonNull Parcel dest, int flags) {
139         WriteSearchResultsToFileAidlRequestCreator.writeToParcel(this, dest, flags);
140     }
141 }
142