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.telecom;
18 
19 import android.annotation.NonNull;
20 
21 import java.util.function.Consumer;
22 
23 /**
24  * CallControlCallback relays call updates (that require a response) from the Telecom framework out
25  * to the application.This can include operations which the app must implement on a Call due to the
26  * presence of other calls on the device, requests relayed from a Bluetooth device, or from another
27  * calling surface.
28  *
29  * <p>
30  * All CallControlCallbacks are transactional, meaning that a client must
31  * complete the {@link Consumer} via {@link Consumer#accept(Object)} in order to complete the
32  * CallControlCallbacks. If a CallControlCallbacks can be completed, the
33  * {@link Consumer#accept(Object)} should be called with {@link Boolean#TRUE}. Otherwise,
34  * {@link Consumer#accept(Object)} should be called with {@link Boolean#FALSE} to represent the
35  * CallControlCallbacks cannot be completed on the client side.
36  *
37  * <p>
38  * Note: Each CallEventCallback has a timeout of 5000 milliseconds. Failing to complete the
39  * {@link Consumer} before the timeout will result in a failed transaction.
40  */
41 public interface CallControlCallback {
42     /**
43      * Telecom is informing the client to set the call active
44      *
45      * @param wasCompleted The {@link Consumer} to be completed. If the client can set the call
46      *                     active on their end, the {@link Consumer#accept(Object)} should be
47      *                     called with {@link Boolean#TRUE}.
48      *
49      *                     Otherwise, {@link Consumer#accept(Object)} should be called with
50      *                     {@link Boolean#FALSE}.  Telecom will effectively ignore the remote
51      *                     setActive request and the call will remain in whatever state it is in.
52      */
onSetActive(@onNull Consumer<Boolean> wasCompleted)53     void onSetActive(@NonNull Consumer<Boolean> wasCompleted);
54 
55     /**
56      * Telecom is informing the client to set the call inactive. This is the same as holding a call
57      * for two endpoints but can be extended to setting a meeting inactive.
58      *
59      * @param wasCompleted The {@link Consumer} to be completed. If the client can set the call
60      *                     inactive on their end, the {@link Consumer#accept(Object)} should be
61      *                     called with {@link Boolean#TRUE}.
62      *
63      *                     Otherwise, {@link Consumer#accept(Object)} should be called with
64      *                     {@link Boolean#FALSE}.  Telecom will effectively ignore the remote
65      *                     setInactive request and the call will remain in whatever state it is in.
66      */
onSetInactive(@onNull Consumer<Boolean> wasCompleted)67     void onSetInactive(@NonNull Consumer<Boolean> wasCompleted);
68 
69     /**
70      * Telecom is informing the client to answer an incoming call and set it to active.
71      *
72      * @param videoState   the video state
73      * @param wasCompleted The {@link Consumer} to be completed. If the client can answer the call
74      *                     on their end, {@link Consumer#accept(Object)} should be called with
75      *                     {@link Boolean#TRUE}.
76      *
77      *                     Otherwise,{@link Consumer#accept(Object)} should  be called with
78      *                     {@link Boolean#FALSE}. However, Telecom will still disconnect
79      *                     the call and remove it from tracking.
80      */
onAnswer(@ndroid.telecom.CallAttributes.CallType int videoState, @NonNull Consumer<Boolean> wasCompleted)81     void onAnswer(@android.telecom.CallAttributes.CallType int videoState,
82             @NonNull Consumer<Boolean> wasCompleted);
83 
84     /**
85      * Telecom is informing the client to disconnect the call
86      *
87      * @param disconnectCause represents the cause for disconnecting the call.
88      * @param wasCompleted    The {@link Consumer} to be completed. If the client can disconnect
89      *                        the call on their end, {@link Consumer#accept(Object)} should be
90      *                        called with {@link Boolean#TRUE}.
91      *
92      *                        Otherwise,{@link Consumer#accept(Object)} should  be called with
93      *                        {@link Boolean#FALSE}. However, Telecom will still disconnect
94      *                        the call and remove it from tracking.
95      */
onDisconnect(@onNull DisconnectCause disconnectCause, @NonNull Consumer<Boolean> wasCompleted)96     void onDisconnect(@NonNull DisconnectCause disconnectCause,
97             @NonNull Consumer<Boolean> wasCompleted);
98 
99     /**
100      * Telecom is informing the client to set the call in streaming.
101      *
102      * @param wasCompleted The {@link Consumer} to be completed. If the client can stream the
103      *                     call on their end, {@link Consumer#accept(Object)} should be called with
104      *                     {@link Boolean#TRUE}. Otherwise, {@link Consumer#accept(Object)}
105      *                     should be called with {@link Boolean#FALSE}.
106      */
onCallStreamingStarted(@onNull Consumer<Boolean> wasCompleted)107     void onCallStreamingStarted(@NonNull Consumer<Boolean> wasCompleted);
108 }
109