1 /*
2  * Copyright (C) 2022 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.cloudsearch;
17 
18 import android.annotation.NonNull;
19 import android.annotation.Nullable;
20 import android.annotation.StringDef;
21 import android.annotation.SystemApi;
22 import android.annotation.TestApi;
23 import android.os.Bundle;
24 import android.os.Parcel;
25 import android.os.Parcelable;
26 
27 import java.lang.annotation.Retention;
28 import java.lang.annotation.RetentionPolicy;
29 
30 /**
31  * A {@link SearchRequest} is the data class having all the information passed to search providers.
32  *
33  * @hide
34  */
35 @SystemApi
36 public final class SearchRequest implements Parcelable {
37 
38     /**
39      * List of public static KEYS for the Bundle to  mSearchConstraints. mSearchConstraints
40      * contains various constraints specifying the search intent.
41      *
42      * @hide
43      */
44     @Retention(RetentionPolicy.SOURCE)
45     @StringDef(prefix = {"CONSTRAINT_"},
46             value = {CONSTRAINT_IS_PRESUBMIT_SUGGESTION,
47                     CONSTRAINT_SEARCH_PROVIDER_FILTER})
48     public @interface SearchConstraintKey {
49     }
50 
51     /**
52      * If this is a presubmit suggestion, Boolean value expected.
53      * presubmit is the input before the user finishes the entire query, i.e. push "ENTER" or
54      * "SEARCH" button. After the user finishes the entire query, the behavior is postsubmit.
55      */
56     public static final String CONSTRAINT_IS_PRESUBMIT_SUGGESTION =
57             "android.app.cloudsearch.IS_PRESUBMIT_SUGGESTION";
58     /**
59      * The target search provider list of package names(separated by ;), String value expected.
60      * If this is not provided or its value is empty, then no filter will be applied.
61      */
62     public static final String CONSTRAINT_SEARCH_PROVIDER_FILTER =
63             "android.app.cloudsearch.SEARCH_PROVIDER_FILTER";
64 
SearchRequest()65     private SearchRequest() {
66     }
67 
68     /** Returns the original query. */
69     @NonNull
getQuery()70     public String getQuery() {
71         return "";
72     }
73 
74     /** Returns the result offset. */
getResultOffset()75     public int getResultOffset() {
76         return 0;
77     }
78 
79     /** Returns the expected number of search results. */
getResultNumber()80     public int getResultNumber() {
81         return 0;
82     }
83 
84     /** Returns the maximum latency requirement. */
getMaxLatencyMillis()85     public float getMaxLatencyMillis() {
86         return 0;
87     }
88 
89     /** Returns the search constraints. */
90     @NonNull
getSearchConstraints()91     public Bundle getSearchConstraints() {
92         return Bundle.EMPTY;
93     }
94 
95     /** Gets the caller's package name. */
96     @NonNull
getCallerPackageName()97     public String getCallerPackageName() {
98         return "";
99     }
100 
101     /** Returns the search request id, which is used to identify the request. */
102     @NonNull
getRequestId()103     public String getRequestId() {
104         return "";
105     }
106 
107     /**
108      * Sets the caller, and this will be set by the system server.
109      *
110      * @hide
111      */
setCallerPackageName(@onNull String callerPackageName)112     public void setCallerPackageName(@NonNull String callerPackageName) {
113     }
114 
115     /**
116      * @see Creator
117      */
118     @NonNull
119     public static final Creator<SearchRequest> CREATOR = new Creator<SearchRequest>() {
120         @Override
121         public SearchRequest createFromParcel(Parcel p) {
122             return new SearchRequest();
123         }
124 
125         @Override
126         public SearchRequest[] newArray(int size) {
127             return new SearchRequest[size];
128         }
129     };
130 
131     @Override
writeToParcel(@onNull Parcel dest, int flags)132     public void writeToParcel(@NonNull Parcel dest, int flags) {
133     }
134 
135     @Override
describeContents()136     public int describeContents() {
137         return 0;
138     }
139 
140     @Override
equals(Object obj)141     public boolean equals(Object obj) {
142         return false;
143     }
144 
145     @Override
toString()146     public String toString() {
147         return "";
148     }
149 
150     @Override
hashCode()151     public int hashCode() {
152         return 0;
153     }
154 
155     /**
156      * The builder for {@link SearchRequest}.
157      *
158      * @hide
159      */
160     @SystemApi
161     public static final class Builder {
162         /**
163          * @param query the query for search.
164          * @hide
165          */
166         @SystemApi
Builder(@onNull String query)167         public Builder(@NonNull String query) {
168         }
169 
170         /** Sets the input query. */
171         @NonNull
setQuery(@onNull String query)172         public Builder setQuery(@NonNull String query) {
173             return this;
174         }
175 
176         /** Sets the search result offset. */
177         @NonNull
setResultOffset(int resultOffset)178         public Builder setResultOffset(int resultOffset) {
179             return this;
180         }
181 
182         /** Sets the expected number of search result. */
183         @NonNull
setResultNumber(int resultNumber)184         public Builder setResultNumber(int resultNumber) {
185             return this;
186         }
187 
188         /** Sets the maximum acceptable search latency. */
189         @NonNull
setMaxLatencyMillis(float maxLatencyMillis)190         public Builder setMaxLatencyMillis(float maxLatencyMillis) {
191             return this;
192         }
193 
194         /**
195          * Sets the search constraints, such as the user location, the search type(presubmit or
196          * postsubmit), and the target search providers.
197          */
198         @NonNull
setSearchConstraints(@ullable Bundle searchConstraints)199         public Builder setSearchConstraints(@Nullable Bundle searchConstraints) {
200             return this;
201         }
202 
203         /**
204          * Sets the caller, and this will be set by the system server.
205          *
206          * @hide
207          */
208         @NonNull
209         @TestApi
setCallerPackageName(@onNull String callerPackageName)210         public Builder setCallerPackageName(@NonNull String callerPackageName) {
211             return this;
212         }
213 
214         /** Builds a SearchRequest based-on the given params. */
215         @NonNull
build()216         public SearchRequest build() {
217             return new SearchRequest();
218         }
219     }
220 }
221