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 import com.android.server.appsearch.external.localstorage.IcingOptionsConfig; 20 import com.android.server.appsearch.external.localstorage.LimitConfig; 21 22 /** 23 * An interface which exposes config flags to AppSearch. 24 * 25 * <p>This interface provides an abstraction for the platform's flag mechanism and implements 26 * caching to avoid expensive lookups. 27 * 28 * <p>Implementations of this interface must be thread-safe. 29 * 30 * @hide 31 */ 32 public interface AppSearchConfig extends AutoCloseable, IcingOptionsConfig, LimitConfig { 33 /** 34 * Default min time interval between samples in millis if there is no value set for 35 * {@link #getCachedMinTimeIntervalBetweenSamplesMillis()} in the flag system. 36 */ 37 long DEFAULT_MIN_TIME_INTERVAL_BETWEEN_SAMPLES_MILLIS = 50; 38 39 /** 40 * Default sampling interval if there is no value set for 41 * {@link #getCachedSamplingIntervalDefault()} in the flag system. 42 */ 43 int DEFAULT_SAMPLING_INTERVAL = 10; 44 45 int DEFAULT_LIMIT_CONFIG_MAX_DOCUMENT_SIZE_BYTES = 512 * 1024; // 512KiB 46 int DEFAULT_LIMIT_CONFIG_MAX_DOCUMENT_COUNT = 20_000; 47 int DEFAULT_LIMIT_CONFIG_MAX_SUGGESTION_COUNT = 20_000; 48 int DEFAULT_BYTES_OPTIMIZE_THRESHOLD = 1 * 1024 * 1024; // 1 MiB 49 int DEFAULT_TIME_OPTIMIZE_THRESHOLD_MILLIS = Integer.MAX_VALUE; 50 int DEFAULT_DOC_COUNT_OPTIMIZE_THRESHOLD = 10_000; 51 int DEFAULT_MIN_TIME_OPTIMIZE_THRESHOLD_MILLIS = 0; 52 // Cached API Call Stats is disabled by default 53 int DEFAULT_API_CALL_STATS_LIMIT = 0; 54 boolean DEFAULT_RATE_LIMIT_ENABLED = false; 55 /** 56 * This defines the task queue's total capacity for rate limiting. 57 */ 58 int DEFAULT_RATE_LIMIT_TASK_QUEUE_TOTAL_CAPACITY = Integer.MAX_VALUE; 59 /** 60 * This defines the per-package capacity for rate limiting as a percentage of the total 61 * capacity. 62 */ 63 float DEFAULT_RATE_LIMIT_TASK_QUEUE_PER_PACKAGE_CAPACITY_PERCENTAGE = 1; 64 /** 65 * This defines API costs used for AppSearch's task queue rate limit. 66 * 67 * <p>Each entry in the string should follow the format 'api_name:integer_cost', and each entry 68 * should be separated by a semi-colon. API names should follow the string definitions in 69 * {@link com.android.server.appsearch.external.localstorage.stats.CallStats}. 70 * 71 * <p>e.g. A valid string: "localPutDocuments:5;localSearch:1;localSetSchema:10" 72 */ 73 String DEFAULT_RATE_LIMIT_API_COSTS_STRING = ""; 74 75 boolean DEFAULT_ICING_CONFIG_USE_READ_ONLY_SEARCH = true; 76 boolean DEFAULT_USE_FIXED_EXECUTOR_SERVICE = false; 77 78 /** Returns cached value for minTimeIntervalBetweenSamplesMillis. */ getCachedMinTimeIntervalBetweenSamplesMillis()79 long getCachedMinTimeIntervalBetweenSamplesMillis(); 80 81 /** 82 * Returns cached value for default sampling interval for all the stats NOT listed in 83 * the configuration. 84 * 85 * <p>For example, sampling_interval=10 means that one out of every 10 stats was logged. 86 */ getCachedSamplingIntervalDefault()87 int getCachedSamplingIntervalDefault(); 88 89 /** 90 * Returns cached value for sampling interval for batch calls. 91 * 92 * <p>For example, sampling_interval=10 means that one out of every 10 stats was logged. 93 */ getCachedSamplingIntervalForBatchCallStats()94 int getCachedSamplingIntervalForBatchCallStats(); 95 96 /** 97 * Returns cached value for sampling interval for putDocument. 98 * 99 * <p>For example, sampling_interval=10 means that one out of every 10 stats was logged. 100 */ getCachedSamplingIntervalForPutDocumentStats()101 int getCachedSamplingIntervalForPutDocumentStats(); 102 103 /** 104 * Returns cached value for sampling interval for initialize. 105 * 106 * <p>For example, sampling_interval=10 means that one out of every 10 stats was logged. 107 */ getCachedSamplingIntervalForInitializeStats()108 int getCachedSamplingIntervalForInitializeStats(); 109 110 /** 111 * Returns cached value for sampling interval for search. 112 * 113 * <p>For example, sampling_interval=10 means that one out of every 10 stats was logged. 114 */ getCachedSamplingIntervalForSearchStats()115 int getCachedSamplingIntervalForSearchStats(); 116 117 /** 118 * Returns cached value for sampling interval for globalSearch. 119 * 120 * <p>For example, sampling_interval=10 means that one out of every 10 stats was logged. 121 */ getCachedSamplingIntervalForGlobalSearchStats()122 int getCachedSamplingIntervalForGlobalSearchStats(); 123 124 /** 125 * Returns cached value for sampling interval for optimize. 126 * 127 * <p>For example, sampling_interval=10 means that one out of every 10 stats was logged. 128 */ getCachedSamplingIntervalForOptimizeStats()129 int getCachedSamplingIntervalForOptimizeStats(); 130 131 /** 132 * Returns the cached optimize byte size threshold. 133 * 134 * An AppSearch Optimize job will be triggered if the bytes size of garbage resource exceeds 135 * this threshold. 136 */ getCachedBytesOptimizeThreshold()137 int getCachedBytesOptimizeThreshold(); 138 139 /** 140 * Returns the cached optimize time interval threshold. 141 * 142 * An AppSearch Optimize job will be triggered if the time since last optimize job exceeds 143 * this threshold. 144 */ getCachedTimeOptimizeThresholdMs()145 int getCachedTimeOptimizeThresholdMs(); 146 147 /** 148 * Returns the cached optimize document count threshold. 149 * 150 * An AppSearch Optimize job will be triggered if the number of document of garbage resource 151 * exceeds this threshold. 152 */ getCachedDocCountOptimizeThreshold()153 int getCachedDocCountOptimizeThreshold(); 154 155 /** 156 * Returns the cached minimum optimize time interval threshold. 157 * 158 * An AppSearch Optimize job will only be triggered if the time since last optimize job exceeds 159 * this threshold. 160 */ getCachedMinTimeOptimizeThresholdMs()161 int getCachedMinTimeOptimizeThresholdMs(); 162 163 /** 164 * Returns the maximum number of last API calls' statistics that can be included in dumpsys. 165 */ getCachedApiCallStatsLimit()166 int getCachedApiCallStatsLimit(); 167 168 /** 169 * Returns the cached denylist. 170 */ getCachedDenylist()171 Denylist getCachedDenylist(); 172 173 /** 174 * Returns whether to enable AppSearch rate limiting. 175 */ getCachedRateLimitEnabled()176 boolean getCachedRateLimitEnabled(); 177 178 /** 179 * Returns the cached {@link AppSearchRateLimitConfig}. 180 */ getCachedRateLimitConfig()181 AppSearchRateLimitConfig getCachedRateLimitConfig(); 182 183 /** 184 * Closes this {@link AppSearchConfig}. 185 * 186 * <p>This close() operation does not throw an exception. 187 */ 188 @Override close()189 void close(); 190 } 191