1 /*
2  * Copyright 2020 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 import androidx.appsearch.localstorage.stats.CallStats;
21 import androidx.appsearch.localstorage.stats.InitializeStats;
22 import androidx.appsearch.localstorage.stats.OptimizeStats;
23 import androidx.appsearch.localstorage.stats.PutDocumentStats;
24 import androidx.appsearch.localstorage.stats.RemoveStats;
25 import androidx.appsearch.localstorage.stats.SearchSessionStats;
26 import androidx.appsearch.localstorage.stats.SearchStats;
27 import androidx.appsearch.localstorage.stats.SetSchemaStats;
28 import androidx.appsearch.stats.SchemaMigrationStats;
29 
30 import org.jspecify.annotations.NonNull;
31 
32 import java.util.List;
33 
34 /**
35  * An interface for implementing client-defined logging AppSearch operations stats.
36  *
37  * <p>Any implementation needs to provide general information on how to log all the stats types.
38  * (for example {@link CallStats})
39  *
40  * <p>All implementations of this interface must be thread safe.
41  *
42  * @exportToFramework:hide
43  */
44 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
45 public interface AppSearchLogger {
46     /**
47      * Logs {@link CallStats}
48      */
logStats(@onNull CallStats stats)49     default void logStats(@NonNull CallStats stats) {
50         // no-op
51     }
52 
53     /**
54      * Logs {@link PutDocumentStats}
55      */
logStats(@onNull PutDocumentStats stats)56     default void logStats(@NonNull PutDocumentStats stats) {
57         // no-op
58     }
59 
60     /**
61      * Logs {@link InitializeStats}
62      */
logStats(@onNull InitializeStats stats)63     default void logStats(@NonNull InitializeStats stats) {
64         // no-op
65     }
66 
67     /**
68      * Logs {@link SearchStats}
69      */
logStats(@onNull SearchStats stats)70     default void logStats(@NonNull SearchStats stats) {
71         // no-op
72     }
73 
74     /** Logs {@link RemoveStats} */
logStats(@onNull RemoveStats stats)75     default void logStats(@NonNull RemoveStats stats) {
76         // no-op
77     }
78 
79     /**
80      * Logs {@link OptimizeStats}
81      */
logStats(@onNull OptimizeStats stats)82     default void logStats(@NonNull OptimizeStats stats) {
83         // no-op
84     }
85 
86     /**
87      * Logs {@link SetSchemaStats}
88      */
logStats(@onNull SetSchemaStats stats)89     default void logStats(@NonNull SetSchemaStats stats) {
90         // no-op
91     }
92 
93     /**
94      * Logs {@link SchemaMigrationStats}
95      */
logStats(@onNull SchemaMigrationStats stats)96     default void logStats(@NonNull SchemaMigrationStats stats) {
97         // no-op
98     }
99 
100     /**
101      * Logs a list of {@link SearchSessionStats}.
102      *
103      * <p>Since the client app may report search intents belonging to different search sessions in a
104      * single taken action reporting request, the stats extractor will separate them into multiple
105      * search sessions. Therefore, we need a list of {@link SearchSessionStats} here.
106      *
107      * <p>For example, the client app reports the following search intent sequence:
108      *
109      * <ul>
110      *   <li>t = 1, the user searches "a" with some clicks.
111      *   <li>t = 5, the user searches "app" with some clicks.
112      *   <li>t = 10000, the user searches "email" with some clicks.
113      * </ul>
114      *
115      * The extractor will detect "email" belongs to a completely independent search session, and
116      * creates 2 {@link SearchSessionStats} with search intents ["a", "app"] and ["email"]
117      * respectively.
118      */
logStats(@onNull List<SearchSessionStats> searchSessionsStats)119     default void logStats(@NonNull List<SearchSessionStats> searchSessionsStats) {
120         // no-op
121     }
122 
123     // TODO(b/173532925) Add remaining logStats once we add all the stats.
124 }
125