1 /*
2  * Copyright 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 androidx.appsearch.localstorage;
18 
19 import androidx.annotation.RestrictTo;
20 
21 /**
22  * Defines limits placed on users of AppSearch and enforced by {@link AppSearchImpl}.
23  * @exportToFramework:hide
24  */
25 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
26 public interface LimitConfig {
27     /**
28      * The maximum number of bytes a single document is allowed to be.
29      *
30      * <p>Enforced at the time of serializing the document into a proto.
31      *
32      * <p>This limit has two purposes:
33      * <ol>
34      *     <li>Prevent the system service from using too much memory during indexing or querying
35      *     by capping the size of the data structures it needs to buffer
36      *     <li>Prevent apps from using a very large amount of data by storing exceptionally large
37      *     documents.
38      * </ol>
39      */
getMaxDocumentSizeBytes()40     int getMaxDocumentSizeBytes();
41 
42     /**
43      * The maximum number of documents a single app is allowed to index.
44      *
45      * <p>Enforced at indexing time.
46      *
47      * <p>This limit has two purposes:
48      * <ol>
49      *     <li>Protect icing lib's docid space from being overwhelmed by a single app. The
50      *     overall docid limit is currently 2^22 (~4 million)
51      *     <li>Prevent apps from using a very large amount of data on the system by storing too many
52      *     documents.
53      * </ol>
54      */
getPerPackageDocumentCountLimit()55     int getPerPackageDocumentCountLimit();
56 
57     /**
58      * The number of total documents in the index at which AppSearch should start rationing docid
59      * space by limiting packages to add {@link #getPerPackageDocumentCountLimit()} documents to
60      * the index.
61      */
getDocumentCountLimitStartThreshold()62     int getDocumentCountLimitStartThreshold();
63 
64     /**
65      * The maximum number of suggestion results a single app is allowed to search.
66      *
67      * <p>Enforced at searching suggestion time.
68      *
69      * <p>The purpose of this limit is to protect Android framework system resource like memory
70      * from being overwhelmed by a single app.
71      */
getMaxSuggestionCount()72     int getMaxSuggestionCount();
73 
74 
75     /**
76      * Returns the maximum number of {@link android.os.ParcelFileDescriptor} that a single app could
77      * open for read and write blob from AppSearch.
78      */
getMaxOpenBlobCount()79     int getMaxOpenBlobCount();
80 
81     /**
82      * Returns the max number of bytes we will batch and send to IcingSearchEngine during
83      * AppSearchImpl.batchPutDocuments. By default, we just use the same value as
84      * #getMaxDocumentSizeBytes().
85      */
getMaxByteLimitForBatchPut()86     int getMaxByteLimitForBatchPut();
87 }
88