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.SearchSuggestionSpec; 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 retrieve suggested search strings. 32 * 33 * @hide 34 */ 35 @SafeParcelable.Class(creator = "SearchSuggestionAidlRequestCreator") 36 public class SearchSuggestionAidlRequest extends AbstractSafeParcelable { 37 @NonNull 38 public static final Parcelable.Creator<SearchSuggestionAidlRequest> CREATOR = 39 new SearchSuggestionAidlRequestCreator(); 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 = "getSuggestionQueryExpression") 51 private final String mSuggestionQueryExpression; 52 53 @NonNull 54 @Field(id = 4, getter = "getSearchSuggestionSpec") 55 private final SearchSuggestionSpec mSearchSuggestionSpec; 56 57 @NonNull 58 @Field(id = 5, getter = "getUserHandle") 59 private final UserHandle mUserHandle; 60 61 @Field(id = 6, getter = "getBinderCallStartTimeMillis") 62 @ElapsedRealtimeLong 63 private final long mBinderCallStartTimeMillis; 64 65 /** 66 * Retrieves suggested Strings that could be used as {@code queryExpression} in search API. 67 * 68 * @param callerAttributionSource The permission identity of the package to suggest over. 69 * @param databaseName The databaseName this suggest is for. 70 * @param suggestionQueryExpression the non empty query string to search suggestions 71 * @param searchSuggestionSpec SearchSuggestionSpec describing what to suggest 72 * @param userHandle Handle of the calling user 73 * @param binderCallStartTimeMillis start timestamp of binder call in Millis 74 */ 75 @Constructor SearchSuggestionAidlRequest( @aramid = 1) @onNull AppSearchAttributionSource callerAttributionSource, @Param(id = 2) @NonNull String databaseName, @Param(id = 3) @NonNull String suggestionQueryExpression, @Param(id = 4) @NonNull SearchSuggestionSpec searchSuggestionSpec, @Param(id = 5) @NonNull UserHandle userHandle, @Param(id = 6) @ElapsedRealtimeLong long binderCallStartTimeMillis)76 public SearchSuggestionAidlRequest( 77 @Param(id = 1) @NonNull AppSearchAttributionSource callerAttributionSource, 78 @Param(id = 2) @NonNull String databaseName, 79 @Param(id = 3) @NonNull String suggestionQueryExpression, 80 @Param(id = 4) @NonNull SearchSuggestionSpec searchSuggestionSpec, 81 @Param(id = 5) @NonNull UserHandle userHandle, 82 @Param(id = 6) @ElapsedRealtimeLong long binderCallStartTimeMillis) { 83 mCallerAttributionSource = Objects.requireNonNull(callerAttributionSource); 84 mDatabaseName = Objects.requireNonNull(databaseName); 85 mSuggestionQueryExpression = Objects.requireNonNull(suggestionQueryExpression); 86 mSearchSuggestionSpec = Objects.requireNonNull(searchSuggestionSpec); 87 mUserHandle = Objects.requireNonNull(userHandle); 88 mBinderCallStartTimeMillis = binderCallStartTimeMillis; 89 } 90 91 @NonNull getCallerAttributionSource()92 public AppSearchAttributionSource getCallerAttributionSource() { 93 return mCallerAttributionSource; 94 } 95 96 @NonNull getDatabaseName()97 public String getDatabaseName() { 98 return mDatabaseName; 99 } 100 101 @NonNull getSuggestionQueryExpression()102 public String getSuggestionQueryExpression() { 103 return mSuggestionQueryExpression; 104 } 105 106 @NonNull getSearchSuggestionSpec()107 public SearchSuggestionSpec getSearchSuggestionSpec() { 108 return mSearchSuggestionSpec; 109 } 110 111 @NonNull getUserHandle()112 public UserHandle getUserHandle() { 113 return mUserHandle; 114 } 115 116 @ElapsedRealtimeLong getBinderCallStartTimeMillis()117 public long getBinderCallStartTimeMillis() { 118 return mBinderCallStartTimeMillis; 119 } 120 121 @Override writeToParcel(@onNull Parcel dest, int flags)122 public void writeToParcel(@NonNull Parcel dest, int flags) { 123 SearchSuggestionAidlRequestCreator.writeToParcel(this, dest, flags); 124 } 125 } 126