• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package android.app.appsearch.testutil;
18 
19 import com.android.server.appsearch.AppSearchConfig;
20 
21 import java.util.concurrent.atomic.AtomicBoolean;
22 
23 /**
24  * An instance of {@link AppSearchConfig} which does not read from any flag system, but simply
25  * returns the defaults for each key.
26  *
27  * <p>This class is thread safe.
28  *
29  * @hide
30  */
31 public final class FakeAppSearchConfig implements AppSearchConfig {
32     private final AtomicBoolean mIsClosed = new AtomicBoolean();
33 
34     @Override
close()35     public void close() {
36         mIsClosed.set(true);
37     }
38 
39     @Override
getCachedMinTimeIntervalBetweenSamplesMillis()40     public long getCachedMinTimeIntervalBetweenSamplesMillis() {
41         throwIfClosed();
42         return DEFAULT_MIN_TIME_INTERVAL_BETWEEN_SAMPLES_MILLIS;
43     }
44 
45     @Override
getCachedSamplingIntervalDefault()46     public int getCachedSamplingIntervalDefault() {
47         throwIfClosed();
48         return DEFAULT_SAMPLING_INTERVAL;
49     }
50 
51     @Override
getCachedSamplingIntervalForBatchCallStats()52     public int getCachedSamplingIntervalForBatchCallStats() {
53         throwIfClosed();
54         return getCachedSamplingIntervalDefault();
55     }
56 
57     @Override
getCachedSamplingIntervalForPutDocumentStats()58     public int getCachedSamplingIntervalForPutDocumentStats() {
59         throwIfClosed();
60         return getCachedSamplingIntervalDefault();
61     }
62 
63     @Override
getCachedSamplingIntervalForInitializeStats()64     public int getCachedSamplingIntervalForInitializeStats() {
65             throwIfClosed();
66             return getCachedSamplingIntervalDefault();
67     }
68 
69     @Override
getCachedSamplingIntervalForSearchStats()70     public int getCachedSamplingIntervalForSearchStats() {
71             throwIfClosed();
72             return getCachedSamplingIntervalDefault();
73     }
74 
75     @Override
getCachedSamplingIntervalForGlobalSearchStats()76     public int getCachedSamplingIntervalForGlobalSearchStats() {
77         throwIfClosed();
78         return getCachedSamplingIntervalDefault();
79     }
80 
81     @Override
getCachedSamplingIntervalForOptimizeStats()82     public int getCachedSamplingIntervalForOptimizeStats() {
83         throwIfClosed();
84         return getCachedSamplingIntervalDefault();
85     }
86 
87     @Override
getCachedLimitConfigMaxDocumentSizeBytes()88     public int getCachedLimitConfigMaxDocumentSizeBytes() {
89         throwIfClosed();
90         return DEFAULT_LIMIT_CONFIG_MAX_DOCUMENT_SIZE_BYTES;
91     }
92 
93     @Override
getCachedLimitConfigMaxDocumentCount()94     public int getCachedLimitConfigMaxDocumentCount() {
95         throwIfClosed();
96         return DEFAULT_LIMIT_CONFIG_MAX_DOCUMENT_COUNT;
97     }
98 
99     @Override
getCachedBytesOptimizeThreshold()100     public int getCachedBytesOptimizeThreshold() {
101         throwIfClosed();
102         return DEFAULT_BYTES_OPTIMIZE_THRESHOLD;
103     }
104 
105     @Override
getCachedTimeOptimizeThresholdMs()106     public int getCachedTimeOptimizeThresholdMs() {
107         throwIfClosed();
108         return DEFAULT_TIME_OPTIMIZE_THRESHOLD_MILLIS;
109     }
110 
111     @Override
getCachedDocCountOptimizeThreshold()112     public int getCachedDocCountOptimizeThreshold() {
113         throwIfClosed();
114         return DEFAULT_DOC_COUNT_OPTIMIZE_THRESHOLD;
115     }
116 
throwIfClosed()117     private void throwIfClosed() {
118         if (mIsClosed.get()) {
119             throw new IllegalStateException("Trying to use a closed AppSearchConfig instance.");
120         }
121     }
122 }
123