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.net;
18 
19 import android.annotation.NonNull;
20 import android.annotation.SystemApi;
21 
22 import java.util.concurrent.Executor;
23 
24 /**
25  * Receives Qos information given a {@link Network}.  The callback is registered with
26  * {@link ConnectivityManager#registerQosCallback}.
27  *
28  * <p>
29  * <br/>
30  * The callback will no longer receive calls if any of the following takes place:
31  * <ol>
32  * <li>{@link ConnectivityManager#unregisterQosCallback(QosCallback)} is called with the same
33  * callback instance.</li>
34  * <li>{@link QosCallback#onError(QosCallbackException)} is called.</li>
35  * <li>A network specific issue occurs.  eg. Congestion on a carrier network.</li>
36  * <li>The network registered with the callback has no associated QoS providers</li>
37  * </ul>
38  * {@hide}
39  */
40 @SystemApi
41 public abstract class QosCallback {
42     /**
43      * Invoked after an error occurs on a registered callback.  Once called, the callback is
44      * automatically unregistered and the callback will no longer receive calls.
45      *
46      * <p>The underlying exception can either be a runtime exception or a custom exception made for
47      * {@link QosCallback}. see: {@link QosCallbackException}.
48      *
49      * @param exception wraps the underlying cause
50      */
51     public void onError(@NonNull final QosCallbackException exception) {
52     }
53 
54     /**
55      * Called when a Qos Session first becomes available to the callback or if its attributes have
56      * changed.
57      * <p>
58      * Note: The callback may be called multiple times with the same attributes.
59      *
60      * @param session the available session
61      * @param sessionAttributes the attributes of the session
62      */
63     public void onQosSessionAvailable(@NonNull final QosSession session,
64             @NonNull final QosSessionAttributes sessionAttributes) {
65     }
66 
67     /**
68      * Called after a Qos Session is lost.
69      * <p>
70      * At least one call to
71      * {@link QosCallback#onQosSessionAvailable(QosSession, QosSessionAttributes)}
72      * with the same {@link QosSession} will precede a call to lost.
73      *
74      * @param session the lost session
75      */
76     public void onQosSessionLost(@NonNull final QosSession session) {
77     }
78 
79     /**
80      * Thrown when there is a problem registering {@link QosCallback} with
81      * {@link ConnectivityManager#registerQosCallback(QosSocketInfo, QosCallback, Executor)}.
82      */
83     public static class QosCallbackRegistrationException extends RuntimeException {
84         /**
85          * @hide
86          */
87         public QosCallbackRegistrationException() {
88             super();
89         }
90     }
91 }
92