1 /*
2  * Copyright (C) 2023 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.adservices.common;
18 
19 import android.annotation.NonNull;
20 
21 /**
22  * Callback interface intended for use when an asynchronous operation may result in a failure. Exact
23  * copy of the {@link android.os.OutcomeReceiver} class, re-defined in the AdServices package for
24  * backwards compatibility to Android R.
25  *
26  * <p>This interface may be used in cases where an asynchronous API may complete either with a value
27  * or with a {@link Throwable} that indicates an error.
28  *
29  * @param <R> The type of the result that's being sent.
30  * @param <E> The type of the {@link Throwable} that contains more information about the error.
31  */
32 public interface AdServicesOutcomeReceiver<R, E extends Throwable> {
33     /**
34      * Called when the asynchronous operation succeeds and delivers a result value.
35      *
36      * @param result The value delivered by the asynchronous operation.
37      */
onResult(R result)38     void onResult(R result);
39 
40     /**
41      * Called when the asynchronous operation fails. The mode of failure is indicated by the {@link
42      * Throwable} passed as an argument to this method.
43      *
44      * @param error A subclass of {@link Throwable} with more details about the error that occurred.
45      */
onError(@onNull E error)46     default void onError(@NonNull E error) {}
47 }
48