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