1 /*
2  * Copyright 2023 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 // @exportToFramework:skipFile()
18 package androidx.appsearch.flags;
19 
20 
21 import androidx.annotation.RestrictTo;
22 import androidx.appsearch.app.AppSearchSchema;
23 
24 import java.util.Collection;
25 
26 /**
27  * Flags to control different features.
28  *
29  * <p>In Jetpack, those values can't be changed during runtime.
30  */
31 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
32 public final class Flags {
Flags()33     private Flags() {
34     }
35 
36     // The prefix of all the flags defined for AppSearch. The prefix has
37     // "com.android.appsearch.flags", aka the package name for generated AppSearch flag classes in
38     // the framework, plus an additional trailing '.'.
39     private static final String FLAG_PREFIX =
40             "com.android.appsearch.flags.";
41 
42     // The full string values for flags defined in the framework.
43     //
44     // The values of the static variables are the names of the flag defined in the framework's
45     // aconfig files. E.g. "enable_safe_parcelable", with FLAG_PREFIX as the prefix.
46     //
47     // The name of the each static variable should be "FLAG_" + capitalized value of the flag.
48 
49     /** Enable SafeParcelable related features. */
50     public static final String FLAG_ENABLE_SAFE_PARCELABLE_2 =
51             FLAG_PREFIX + "enable_safe_parcelable_2";
52 
53     /** Enable the "hasProperty" function in list filter query expressions. */
54     public static final String FLAG_ENABLE_LIST_FILTER_HAS_PROPERTY_FUNCTION =
55             FLAG_PREFIX + "enable_list_filter_has_property_function";
56 
57     /** Enable the "matchScoreExpression" function in list filter query expressions. */
58     public static final String FLAG_ENABLE_LIST_FILTER_MATCH_SCORE_EXPRESSION_FUNCTION =
59             FLAG_PREFIX + "enable_list_filter_match_score_expression_function";
60 
61     /** Enable Schema Type Grouping related features. */
62     public static final String FLAG_ENABLE_GROUPING_TYPE_PER_SCHEMA =
63             FLAG_PREFIX + "enable_grouping_type_per_schema";
64 
65     /** Enable GenericDocument to take another GenericDocument to copy construct. */
66     public static final String FLAG_ENABLE_GENERIC_DOCUMENT_COPY_CONSTRUCTOR =
67             FLAG_PREFIX + "enable_generic_document_copy_constructor";
68 
69     /**
70      * Enable the {@link androidx.appsearch.app.SearchSpec.Builder#addFilterProperties} and
71      * {@link androidx.appsearch.app.SearchSuggestionSpec.Builder#addFilterProperties}.
72      */
73     public static final String FLAG_ENABLE_SEARCH_SPEC_FILTER_PROPERTIES =
74             FLAG_PREFIX + "enable_search_spec_filter_properties";
75     /**
76      * Enable the {@link androidx.appsearch.app.SearchSpec.Builder#setSearchSourceLogTag} method.
77      */
78     public static final String FLAG_ENABLE_SEARCH_SPEC_SET_SEARCH_SOURCE_LOG_TAG =
79             FLAG_PREFIX + "enable_search_spec_set_search_source_log_tag";
80 
81     /**
82      * Enable {@link androidx.appsearch.app.SearchSpec.Builder#addSearchStringParameters} and
83      * {@link androidx.appsearch.app.SearchSuggestionSpec.Builder#addSearchStringParameters}
84      * methods.
85      */
86     public static final String FLAG_ENABLE_SEARCH_SPEC_SEARCH_STRING_PARAMETERS =
87             FLAG_PREFIX + "enable_search_spec_search_string_parameters";
88 
89     /** Enable addTakenActions API in PutDocumentsRequest. */
90     public static final String FLAG_ENABLE_PUT_DOCUMENTS_REQUEST_ADD_TAKEN_ACTIONS =
91             FLAG_PREFIX + "enable_put_documents_request_add_taken_actions";
92 
93     /** Enable setPubliclyVisibleSchema in SetSchemaRequest. */
94     public static final String FLAG_ENABLE_SET_PUBLICLY_VISIBLE_SCHEMA = FLAG_PREFIX
95             + "enable_set_publicly_visible_schema";
96 
97     /**
98      * Enable {@link androidx.appsearch.app.GenericDocument.Builder} to use previously hidden
99      * methods.
100      */
101     public static final String FLAG_ENABLE_GENERIC_DOCUMENT_BUILDER_HIDDEN_METHODS = FLAG_PREFIX
102             + "enable_generic_document_builder_hidden_methods";
103 
104     public static final String FLAG_ENABLE_SET_SCHEMA_VISIBLE_TO_CONFIGS = FLAG_PREFIX
105             + "enable_set_schema_visible_to_configs";
106 
107     /** Enable {@link androidx.appsearch.app.EnterpriseGlobalSearchSession}. */
108     public static final String FLAG_ENABLE_ENTERPRISE_GLOBAL_SEARCH_SESSION =
109             FLAG_PREFIX + "enable_enterprise_global_search_session";
110 
111     /**
112      * Enable {@link android.appsearch.app.AppSearchSchema#getDescription} and
113      * {@link android.appsearch.app.AppSearchSchema.PropertyConfig#getDescription} and the related
114      * builders.
115      */
116     public static final String FLAG_ENABLE_SCHEMA_DESCRIPTION =
117             FLAG_PREFIX + "enable_schema_description";
118 
119     /**
120      * Enable {@link androidx.appsearch.app.AppSearchResult#RESULT_DENIED} and
121      * {@link androidx.appsearch.app.AppSearchResult#RESULT_RATE_LIMITED} which were previously
122      * hidden.
123      */
124     public static final String FLAG_ENABLE_RESULT_DENIED_AND_RESULT_RATE_LIMITED =
125             FLAG_PREFIX + "enable_result_denied_and_result_rate_limited";
126 
127     /**
128      * Enables {@link AppSearchSchema#getParentTypes()},
129      * {@link AppSearchSchema.DocumentPropertyConfig#getIndexableNestedProperties()} and variants of
130      * {@link AppSearchSchema.DocumentPropertyConfig.Builder#addIndexableNestedProperties(Collection)}}.
131      */
132     public static final String FLAG_ENABLE_GET_PARENT_TYPES_AND_INDEXABLE_NESTED_PROPERTIES =
133             FLAG_PREFIX + "enable_get_parent_types_and_indexable_nested_properties";
134 
135     /** Enables embedding search related APIs. */
136     public static final String FLAG_ENABLE_SCHEMA_EMBEDDING_PROPERTY_CONFIG =
137             FLAG_PREFIX + "enable_schema_embedding_property_config";
138 
139     /** Enables embedding quantization. */
140     public static final String FLAG_ENABLE_SCHEMA_EMBEDDING_QUANTIZATION =
141             FLAG_PREFIX + "enable_schema_embedding_quantization";
142 
143     /** Enables informational ranking expressions. */
144     public static final String FLAG_ENABLE_INFORMATIONAL_RANKING_EXPRESSIONS =
145             FLAG_PREFIX + "enable_informational_ranking_expressions";
146 
147     /** Enable {@link androidx.appsearch.app.AppSearchResult#RESULT_ALREADY_EXISTS}.     */
148     public static final String FLAG_ENABLE_RESULT_ALREADY_EXISTS =
149             FLAG_PREFIX + "enable_result_already_exists";
150 
151     /**  Enable {@link androidx.appsearch.app.AppSearchBlobHandle}.  */
152     public static final String FLAG_ENABLE_BLOB_STORE =
153             FLAG_PREFIX + "enable_blob_store";
154 
155     /**  Enable {@link androidx.appsearch.app.GenericDocument#writeToParcel}.  */
156     public static final String FLAG_ENABLE_GENERIC_DOCUMENT_OVER_IPC =
157             FLAG_PREFIX + "enable_generic_document_over_ipc";
158 
159     /** Enable empty batch result fix for enterprise GetDocuments. */
160     public static final String FLAG_ENABLE_ENTERPRISE_EMPTY_BATCH_RESULT_FIX =
161             FLAG_PREFIX + "enable_enterprise_empty_batch_result_fix";
162 
163     /** Enables abstract syntax trees to be built and used within AppSearch. */
164     public static final String FLAG_ENABLE_ABSTRACT_SYNTAX_TREES =
165             FLAG_PREFIX + "enable_abstract_syntax_trees";
166 
167     /** Enables the feature of scorable property. */
168     public static final String FLAG_ENABLE_SCORABLE_PROPERTY =
169             FLAG_PREFIX + "enable_scorable_property";
170 
171     /**
172      * Enable the {@link androidx.appsearch.app.SearchSpec.Builder#addFilterDocumentIds}.
173      */
174     public static final String FLAG_ENABLE_SEARCH_SPEC_FILTER_DOCUMENT_IDS =
175             FLAG_PREFIX + "enable_search_spec_filter_document_ids";
176 
177     /**
178      * Enables additional builder copy constructors for
179      * {@link androidx.appsearch.app.AppSearchSchema},
180      * {@link androidx.appsearch.app.SetSchemaRequest}, {@link androidx.appsearch.app.SearchSpec},
181      * {@link androidx.appsearch.app.JoinSpec}, {@link androidx.appsearch.app.AppSearchBatchResult},
182      * and {@link androidx.appsearch.app.GetSchemaResponse}.
183      */
184     public static final String FLAG_ENABLE_ADDITIONAL_BUILDER_COPY_CONSTRUCTORS =
185             FLAG_PREFIX + "enable_additional_builder_copy_constructors";
186 
187     /**
188      * Enables wrapping the parent types of a document in the corresponding
189      * {@link androidx.appsearch.app.SearchResult}, instead of in
190      * {@link androidx.appsearch.app.GenericDocument}.
191      */
192     public static final String FLAG_ENABLE_SEARCH_RESULT_PARENT_TYPES =
193             FLAG_PREFIX + "enable_search_result_parent_types";
194 
195     /** Enables delete propagation type related APIs. */
196     public static final String FLAG_ENABLE_DELETE_PROPAGATION_TYPE =
197             FLAG_PREFIX + "enable_delete_propagation_type";
198 
199     /** Enables AppSearch to manage blob files. */
200     public static final String FLAG_ENABLE_APP_SEARCH_MANAGE_BLOB_FILES =
201             FLAG_PREFIX + "enable_app_search_manage_blob_files";
202 
203     /**
204      * Enables time since last optimize to be calculated by last attempted optimize run time instead
205      * of last successful optimize run time.
206      */
207     public static final String FLAG_ENABLE_CALCULATE_TIME_SINCE_LAST_ATTEMPTED_OPTIMIZE =
208             FLAG_PREFIX + "enable_calculate_time_since_last_attempted_optimize";
209 
210     /** Enables qualified id join index v3. */
211     public static final String FLAG_ENABLE_QUALIFIED_ID_JOIN_INDEX_V3 =
212             FLAG_PREFIX + "enable_qualified_id_join_index_v3";
213 
214     /** Enables soft index restoration. */
215     public static final String FLAG_ENABLE_SOFT_INDEX_RESTORATION =
216             FLAG_PREFIX + "enable_soft_index_restoration";
217 
218     /** Enables marker file creation for Optimize API. */
219     public static final String FLAG_ENABLE_MARKER_FILE_FOR_OPTIMIZE =
220             FLAG_PREFIX + "enable_marker_file_for_optimize";
221 
222     /**
223      * Enables releasing the backup schema file instance in the schema store if the overlay schema
224      * instance exists.
225      */
226     public static final String FLAG_ENABLE_RELEASE_BACKUP_SCHEMA_FILE_IF_OVERLAY_PRESENT =
227             FLAG_PREFIX + "enable_release_backup_schema_file_if_overlay_present";
228 
229     /** Enables retrieving embedding match snippet information. This affects  */
230     public static final String FLAG_ENABLE_EMBEDDING_MATCH_INFO =
231             FLAG_PREFIX + "enable_embedding_match_info";
232 
233     /** Enables to query visibility documents rather than get.  */
234     public static final String FLAG_ENABLE_QUERY_VISIBILITY_DOCUMENTS =
235             FLAG_PREFIX + "enable_query_visibility_documents";
236 
237     /** Enables strict byte size enforcement on a result page. */
238     public static final String FLAG_ENABLE_STRICT_PAGE_BYTE_SIZE_LIMIT =
239             FLAG_PREFIX + "enable_strict_page_byte_size_limit";
240 
241     /** Enables compression threshold. */
242     public static final String FLAG_ENABLE_COMPRESSION_THRESHOLD =
243             FLAG_PREFIX + "enable_compression_threshold";
244 
245     /** Enables setting the gzip compression memlevel to 1. */
246     public static final String FLAG_ENABLE_COMPRESSION_MEM_LEVEL_ONE =
247             FLAG_PREFIX + "enable_compression_mem_level_one";
248 
249     // Whether the features should be enabled.
250     //
251     // In Jetpack, those should always return true.
252 
253     /** Whether SafeParcelable should be enabled. */
enableSafeParcelable()254     public static boolean enableSafeParcelable() {
255         return true;
256     }
257 
258     /** Whether the "hasProperty" function in list filter query expressions should be enabled. */
enableListFilterHasPropertyFunction()259     public static boolean enableListFilterHasPropertyFunction() {
260         return true;
261     }
262 
263     /**
264      * Whether the "matchScoreExpression" function in list filter query expressions should be
265      * enabled.
266      */
enableListFilterMatchScoreExpressionFunction()267     public static boolean enableListFilterMatchScoreExpressionFunction() {
268         return true;
269     }
270 
271     /** Whether Schema Type Grouping should be enabled. */
enableGroupingTypePerSchema()272     public static boolean enableGroupingTypePerSchema() {
273         return true;
274     }
275 
276     /** Whether Generic Document Copy Constructing should be enabled. */
enableGenericDocumentCopyConstructor()277     public static boolean enableGenericDocumentCopyConstructor() {
278         return true;
279     }
280 
281     /**
282      * Whether the {@link androidx.appsearch.app.SearchSpec.Builder#addFilterProperties} and
283      * {@link androidx.appsearch.app.SearchSuggestionSpec.Builder#addFilterProperties} should be
284      * enabled.
285      */
enableSearchSpecFilterProperties()286     public static boolean enableSearchSpecFilterProperties() {
287         return true;
288     }
289 
290     /**
291      * Whether the {@link androidx.appsearch.app.SearchSpec.Builder#setSearchSourceLogTag} should
292      * be enabled.
293      */
enableSearchSpecSetSearchSourceLogTag()294     public static boolean enableSearchSpecSetSearchSourceLogTag() {
295         return true;
296     }
297 
298     /** Whether addTakenActions API in PutDocumentsRequest should be enabled. */
enablePutDocumentsRequestAddTakenActions()299     public static boolean enablePutDocumentsRequestAddTakenActions() {
300         return true;
301     }
302 
303     /** Whether setPubliclyVisibleSchema in SetSchemaRequest.Builder should be enabled. */
enableSetPubliclyVisibleSchema()304     public static boolean enableSetPubliclyVisibleSchema() {
305         return true;
306     }
307 
308     /**
309      * Whether {@link androidx.appsearch.app.GenericDocument.Builder#setNamespace(String)},
310      * {@link androidx.appsearch.app.GenericDocument.Builder#setId(String)},
311      * {@link androidx.appsearch.app.GenericDocument.Builder#setSchemaType(String)}, and
312      * {@link androidx.appsearch.app.GenericDocument.Builder#clearProperty(String)}
313      * should be enabled.
314      */
enableGenericDocumentBuilderHiddenMethods()315     public static boolean enableGenericDocumentBuilderHiddenMethods() {
316         return true;
317     }
318 
319     /**
320      * Whether
321      * {@link androidx.appsearch.app.SetSchemaRequest.Builder #setSchemaTypeVisibilityForConfigs}
322      * should be enabled.
323      */
enableSetSchemaVisibleToConfigs()324     public static boolean enableSetSchemaVisibleToConfigs() {
325         return true;
326     }
327 
328     /** Whether {@link androidx.appsearch.app.EnterpriseGlobalSearchSession} should be enabled. */
enableEnterpriseGlobalSearchSession()329     public static boolean enableEnterpriseGlobalSearchSession() {
330         return true;
331     }
332 
333     /**
334      * Whether {@link androidx.appsearch.app.AppSearchResult#RESULT_DENIED} and
335      * {@link androidx.appsearch.app.AppSearchResult#RESULT_RATE_LIMITED} should be enabled.
336      */
enableResultDeniedAndResultRateLimited()337     public static boolean enableResultDeniedAndResultRateLimited() {
338         return true;
339     }
340 
341     /**
342      * Whether {@link AppSearchSchema#getParentTypes()},
343      * {@link AppSearchSchema.DocumentPropertyConfig#getIndexableNestedProperties()} and variants of
344      * {@link AppSearchSchema.DocumentPropertyConfig.Builder#addIndexableNestedProperties(Collection)}}
345      * should be enabled.
346      */
enableGetParentTypesAndIndexableNestedProperties()347     public static boolean enableGetParentTypesAndIndexableNestedProperties() {
348         return true;
349     }
350 
351     /** Whether embedding search related APIs should be enabled. */
enableSchemaEmbeddingPropertyConfig()352     public static boolean enableSchemaEmbeddingPropertyConfig() {
353         return true;
354     }
355 
356     /** Whether embedding quantization is enabled. */
enableSchemaEmbeddingQuantization()357     public static boolean enableSchemaEmbeddingQuantization() {
358         return true;
359     }
360 
361     /** Whether the search parameter APIs should be enabled. */
enableSearchSpecSearchStringParameters()362     public static boolean enableSearchSpecSearchStringParameters() {
363         return true;
364     }
365 
366     /** Whether informational ranking expressions should be enabled. */
enableInformationalRankingExpressions()367     public static boolean enableInformationalRankingExpressions() {
368         return true;
369     }
370 
371     /**
372      * Whether {@link androidx.appsearch.app.AppSearchResult#RESULT_ALREADY_EXISTS} should be
373      * enabled.
374      */
enableResultAlreadyExists()375     public static boolean enableResultAlreadyExists() {
376         return true;
377     }
378 
379     /**  Whether {@link androidx.appsearch.app.AppSearchBlobHandle} should be enabled. */
enableBlobStore()380     public static boolean enableBlobStore() {
381         return true;
382     }
383 
384     /** Whether AppSearch manages blob files. */
enableAppSearchManageBlobFiles()385     public static boolean enableAppSearchManageBlobFiles() {
386         return true;
387     }
388 
389     /** Whether empty batch result fix for enterprise GetDocuments should be enabled. */
enableEnterpriseEmptyBatchResultFix()390     public static boolean enableEnterpriseEmptyBatchResultFix() {
391         return true;
392     }
393 
394     /** Whether AppSearch can create and use abstract syntax trees. */
enableAbstractSyntaxTrees()395     public static boolean enableAbstractSyntaxTrees() {
396         return true;
397     }
398 
399     /**
400      * Whether additional builder copy constructors for
401      * {@link androidx.appsearch.app.AppSearchSchema},
402      * {@link androidx.appsearch.app.SetSchemaRequest}, {@link androidx.appsearch.app.SearchSpec},
403      * {@link androidx.appsearch.app.JoinSpec}, {@link androidx.appsearch.app.AppSearchBatchResult},
404      * and {@link androidx.appsearch.app.GetSchemaResponse} should be enabled.
405      */
enableAdditionalBuilderCopyConstructors()406     public static boolean enableAdditionalBuilderCopyConstructors() {
407         return true;
408     }
409 
410     /**
411      * Whether or not the AppSearch should keep track of replaces when calculating the document
412      * limit or should call into Icing to get the current active document count when the limit is
413      * reached.
414      */
enableDocumentLimiterReplaceTracking()415     public static boolean enableDocumentLimiterReplaceTracking() { return true; }
416 
417     /**
418      * Whether the {@link androidx.appsearch.app.SearchSpec.Builder#addFilterDocumentIds} should be
419      * enabled.
420      */
enableSearchSpecFilterDocumentIds()421     public static boolean enableSearchSpecFilterDocumentIds() {
422         return true;
423     }
424 
425     /** Whether the feature of the scorable property should be enabled. */
enableScorableProperty()426     public static boolean enableScorableProperty() {
427         return true;
428     }
429 
430     /**
431      * Whether to wrap the parent types of a document in the corresponding
432      * {@link androidx.appsearch.app.SearchResult}, instead of in
433      * {@link androidx.appsearch.app.GenericDocument}.
434      */
enableSearchResultParentTypes()435     public static boolean enableSearchResultParentTypes() {
436         return true;
437     }
438 
439     /**
440      * Whether delete propagation related APIs should be enabled.
441      *
442      * <p>Note: delete propagation depends on qualified id join index v3, so
443      * {@link #enableQualifiedIdJoinIndexV3()} should also be true.
444      *
445      */
enableDeletePropagationType()446     public static boolean enableDeletePropagationType() {
447         // TODO(b/384947619): enable this flag once expiry propagation and dependency check are
448         //   implemented.
449         return false;
450     }
451 
452     /**
453      * Whether to calculate time since last optimize using last attempted optimize run time instead
454      * of last successful optimize run time.
455      */
enableCalculateTimeSinceLastAttemptedOptimize()456     public static boolean enableCalculateTimeSinceLastAttemptedOptimize() {
457         return true;
458     }
459 
460     /** Whether qualified id join index v3 should be enabled. */
enableQualifiedIdJoinIndexV3()461     public static boolean enableQualifiedIdJoinIndexV3() {
462         return true;
463     }
464 
465     /** Whether soft index restoration should be enabled. */
enableSoftIndexRestoration()466     public static boolean enableSoftIndexRestoration() {
467         return true;
468     }
469 
470     /** Whether marker file creation for Optimize API should be enabled. */
enableMarkerFileForOptimize()471     public static boolean enableMarkerFileForOptimize() {
472         return true;
473     }
474 
475     /**
476      * Whether to release the backup schema file instance in the schema store if the overlay schema
477      * instance exists.
478      */
enableReleaseBackupSchemaFileIfOverlayPresent()479     public static boolean enableReleaseBackupSchemaFileIfOverlayPresent() {
480         return true;
481     }
482 
483     /**
484      * Whether to enable retrieving embedding match info during snippetting.
485      */
enableEmbeddingMatchInfo()486     public static boolean enableEmbeddingMatchInfo() {
487         return true;
488     }
489 
490     /**
491      * Whether to query visibility documents rather than get.
492      */
enableQueryVisibilityDocuments()493     public static boolean enableQueryVisibilityDocuments() {
494         return true;
495     }
496 
497     /** Whether to enforce page byte size limit in a stricter way. */
enableStrictPageByteSizeLimit()498     public static boolean enableStrictPageByteSizeLimit() {
499         return true;
500     }
501 
502     /**
503      * Whether to enable compression threshold.
504      */
enableCompressionThreshold()505     public static boolean enableCompressionThreshold() {
506         return true;
507     }
508 
509     /**
510      * Whether to use a compression memlevel of 1.
511      */
enableCompressionMemLevelOne()512     public static boolean enableCompressionMemLevelOne() {
513         return true;
514     }
515 }
516