• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 android.app.appsearch;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 
22 /**
23  * The callback interface to return {@link AppSearchBatchResult}.
24  *
25  * @param <KeyType> The type of the keys for {@link AppSearchBatchResult#getSuccesses} and
26  * {@link AppSearchBatchResult#getFailures}.
27  * @param <ValueType> The type of result objects associated with the keys.
28  */
29 public interface BatchResultCallback<KeyType, ValueType> {
30 
31     /**
32      * Called when {@link AppSearchBatchResult} results are ready.
33      *
34      * @param result The result of the executed request.
35      */
onResult(@onNull AppSearchBatchResult<KeyType, ValueType> result)36     void onResult(@NonNull AppSearchBatchResult<KeyType, ValueType> result);
37 
38     /**
39      * Called when a system error occurs.
40      *
41      * <p>This method is only called the infrastructure is fundamentally broken or unavailable, such
42      * that none of the requests could be started. For example, it will be called if the AppSearch
43      * service unexpectedly fails to initialize and can't be recovered by any means, or if
44      * communicating to the server over Binder fails (e.g. system service crashed or device is
45      * rebooting).
46      *
47      * <p>The error is not expected to be recoverable and there is no specific recommended action
48      * other than displaying a permanent message to the user.
49      *
50      * <p>Normal errors that are caused by invalid inputs or recoverable/retriable situations
51      * are reported associated with the input that caused them via the {@link #onResult} method.
52      *
53      * @param throwable an exception describing the system error
54      */
onSystemError(@ullable Throwable throwable)55     default void onSystemError(@Nullable Throwable throwable) {
56         throw new RuntimeException("Unrecoverable system error", throwable);
57     }
58 }
59