• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 com.android.server.appsearch;
18 
19 /**
20  * An interface which exposes config flags to AppSearch.
21  *
22  * <p>This interface provides an abstraction for the platform's flag mechanism and implements
23  * caching to avoid expensive lookups.
24  *
25  * <p>Implementations of this interface must be thread-safe.
26  *
27  * @hide
28  */
29 public interface AppSearchConfig extends AutoCloseable {
30     /**
31      * Default min time interval between samples in millis if there is no value set for
32      * {@link #getCachedMinTimeIntervalBetweenSamplesMillis()} in the flag system.
33      */
34     long DEFAULT_MIN_TIME_INTERVAL_BETWEEN_SAMPLES_MILLIS = 50;
35 
36     /**
37      * Default sampling interval if there is no value set for
38      * {@link #getCachedSamplingIntervalDefault()} in the flag system.
39      */
40     int DEFAULT_SAMPLING_INTERVAL = 10;
41 
42     int DEFAULT_LIMIT_CONFIG_MAX_DOCUMENT_SIZE_BYTES = 512 * 1024; // 512KiB
43     int DEFAULT_LIMIT_CONFIG_MAX_DOCUMENT_COUNT = 20_000;
44     int DEFAULT_BYTES_OPTIMIZE_THRESHOLD = 1 * 1024 * 1024; // 1 MiB
45     int DEFAULT_TIME_OPTIMIZE_THRESHOLD_MILLIS = Integer.MAX_VALUE;
46     int DEFAULT_DOC_COUNT_OPTIMIZE_THRESHOLD = 10_000;
47 
48     /** Returns cached value for minTimeIntervalBetweenSamplesMillis. */
getCachedMinTimeIntervalBetweenSamplesMillis()49     long getCachedMinTimeIntervalBetweenSamplesMillis();
50 
51     /**
52      * Returns cached value for default sampling interval for all the stats NOT listed in
53      * the configuration.
54      *
55      * <p>For example, sampling_interval=10 means that one out of every 10 stats was logged.
56      */
getCachedSamplingIntervalDefault()57     int getCachedSamplingIntervalDefault();
58 
59     /**
60      * Returns cached value for sampling interval for batch calls.
61      *
62      * <p>For example, sampling_interval=10 means that one out of every 10 stats was logged.
63      */
getCachedSamplingIntervalForBatchCallStats()64     int getCachedSamplingIntervalForBatchCallStats();
65 
66     /**
67      * Returns cached value for sampling interval for putDocument.
68      *
69      * <p>For example, sampling_interval=10 means that one out of every 10 stats was logged.
70      */
getCachedSamplingIntervalForPutDocumentStats()71     int getCachedSamplingIntervalForPutDocumentStats();
72 
73     /**
74      * Returns cached value for sampling interval for initialize.
75      *
76      * <p>For example, sampling_interval=10 means that one out of every 10 stats was logged.
77      */
getCachedSamplingIntervalForInitializeStats()78     int getCachedSamplingIntervalForInitializeStats();
79 
80     /**
81      * Returns cached value for sampling interval for search.
82      *
83      * <p>For example, sampling_interval=10 means that one out of every 10 stats was logged.
84      */
getCachedSamplingIntervalForSearchStats()85     int getCachedSamplingIntervalForSearchStats();
86 
87     /**
88      * Returns cached value for sampling interval for globalSearch.
89      *
90      * <p>For example, sampling_interval=10 means that one out of every 10 stats was logged.
91      */
getCachedSamplingIntervalForGlobalSearchStats()92     int getCachedSamplingIntervalForGlobalSearchStats();
93 
94     /**
95      * Returns cached value for sampling interval for optimize.
96      *
97      * <p>For example, sampling_interval=10 means that one out of every 10 stats was logged.
98      */
getCachedSamplingIntervalForOptimizeStats()99     int getCachedSamplingIntervalForOptimizeStats();
100 
101     /** Returns the maximum serialized size an indexed document can be, in bytes. */
getCachedLimitConfigMaxDocumentSizeBytes()102     int getCachedLimitConfigMaxDocumentSizeBytes();
103 
104     /** Returns the maximum number of active docs allowed per package. */
getCachedLimitConfigMaxDocumentCount()105     int getCachedLimitConfigMaxDocumentCount();
106 
107     /**
108      * Returns the cached optimize byte size threshold.
109      *
110      * An AppSearch Optimize job will be triggered if the bytes size of garbage resource exceeds
111      * this threshold.
112      */
getCachedBytesOptimizeThreshold()113     int getCachedBytesOptimizeThreshold();
114 
115     /**
116      * Returns the cached optimize time interval threshold.
117      *
118      * An AppSearch Optimize job will be triggered if the time since last optimize job exceeds
119      * this threshold.
120      */
getCachedTimeOptimizeThresholdMs()121     int getCachedTimeOptimizeThresholdMs();
122 
123     /**
124      * Returns the cached optimize document count threshold threshold.
125      *
126      * An AppSearch Optimize job will be triggered if the number of document of garbage resource
127      * exceeds this threshold.
128      */
getCachedDocCountOptimizeThreshold()129     int getCachedDocCountOptimizeThreshold();
130 
131     /**
132      * Closes this {@link AppSearchConfig}.
133      *
134      * <p>This close() operation does not throw an exception.
135      */
136     @Override
close()137     void close();
138 }
139