blob: 13a045858ab1798bef7c5a1af24ddbb457974ffe [file] [log] [blame]
Sailesh Nepalab5d2822014-03-08 18:01:06 -08001/*
2 * Copyright (C) 2013 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
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080018
Junhoedf3d822022-11-24 09:26:37 +000019import android.annotation.CallbackExecutor;
Hall Liua98f58b52017-11-07 17:59:28 -080020import android.annotation.NonNull;
Tyler Gunn2ac40102014-08-18 16:23:10 -070021import android.annotation.SdkConstant;
Santos Cordona2492812015-04-15 11:05:16 -070022import android.annotation.SystemApi;
Santos Cordon2f42b112014-07-19 13:19:37 -070023import android.app.Service;
Tyler Gunn4057d4c2020-01-31 15:03:43 -080024import android.app.UiModeManager;
Hall Liua98f58b52017-11-07 17:59:28 -080025import android.bluetooth.BluetoothDevice;
Tyler Gunn8f360d82022-06-22 12:56:25 -070026import android.content.ComponentName;
Santos Cordon2f42b112014-07-19 13:19:37 -070027import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070028import android.hardware.camera2.CameraManager;
Yorke Lee32f24732015-05-12 16:18:03 -070029import android.net.Uri;
Tyler Gunn876dbfb2016-03-14 15:18:07 -070030import android.os.Bundle;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080031import android.os.Handler;
32import android.os.IBinder;
33import android.os.Looper;
34import android.os.Message;
Junhoedf3d822022-11-24 09:26:37 +000035import android.os.OutcomeReceiver;
Andrew Lee50aca232014-07-22 16:41:54 -070036import android.view.Surface;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080037
Ihab Awad2f236642014-03-10 15:33:45 -070038import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070039import com.android.internal.telecom.IInCallAdapter;
40import com.android.internal.telecom.IInCallService;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080041
Santos Cordona2492812015-04-15 11:05:16 -070042import java.util.Collections;
43import java.util.List;
Junhoedf3d822022-11-24 09:26:37 +000044import java.util.Objects;
45import java.util.concurrent.Executor;
Andrew Lee50aca232014-07-22 16:41:54 -070046
Sailesh Nepalab5d2822014-03-08 18:01:06 -080047/**
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -080048 * This service is implemented by an app that wishes to provide functionality for managing
49 * phone calls.
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -080050 * <h2>Becoming the Default Phone App</h2>
Tyler Gunn556d2402019-04-10 08:59:43 -070051 * The default dialer/phone app is one which provides the in-call user interface while the device is
Tyler Gunn4057d4c2020-01-31 15:03:43 -080052 * in a call. It also provides the user with a means to initiate calls and see a history of calls
53 * on their device. A device is bundled with a system provided default dialer/phone app. The user
54 * may choose a single app to take over this role from the system app. An app which wishes to
Tyler Gunn8f360d82022-06-22 12:56:25 -070055 * fulfill this role uses the {@link android.app.role.RoleManager} to request that they fill the
Tyler Gunn4057d4c2020-01-31 15:03:43 -080056 * {@link android.app.role.RoleManager#ROLE_DIALER} role.
Tyler Gunn556d2402019-04-10 08:59:43 -070057 * <p>
Tyler Gunn4057d4c2020-01-31 15:03:43 -080058 * The default phone app provides a user interface while the device is in a call, and the device is
59 * not in car mode (i.e. {@link UiModeManager#getCurrentModeType()} is not
60 * {@link android.content.res.Configuration#UI_MODE_TYPE_CAR}).
61 * <p>
62 * In order to fill the {@link android.app.role.RoleManager#ROLE_DIALER} role, an app must meet a
63 * number of requirements:
64 * <ul>
65 * <li>It must handle the {@link Intent#ACTION_DIAL} intent. This means the app must provide
66 * a dial pad UI for the user to initiate outgoing calls.</li>
67 * <li>It must fully implement the {@link InCallService} API and provide both an incoming call
68 * UI, as well as an ongoing call UI.</li>
69 * </ul>
70 * <p>
Tyler Gunn8f360d82022-06-22 12:56:25 -070071 * Note: If the app filling the {@link android.app.role.RoleManager#ROLE_DIALER} returns a
72 * {@code null} {@link InCallService} during binding, the Telecom framework will automatically fall
73 * back to using the dialer app preloaded on the device. The system will display a notification to
74 * the user to let them know that their call was continued using the preloaded dialer app. Your
75 * app should never return a {@code null} binding; doing so means it does not fulfil the
76 * requirements of {@link android.app.role.RoleManager#ROLE_DIALER}.
Tyler Gunn4057d4c2020-01-31 15:03:43 -080077 * <p>
Tyler Gunn8f360d82022-06-22 12:56:25 -070078 * Note: If your app fills {@link android.app.role.RoleManager#ROLE_DIALER} and makes changes at
79 * runtime which cause it to no longer fulfil the requirements of this role,
80 * {@link android.app.role.RoleManager} will automatically remove your app from the role and close
81 * your app. For example, if you use
82 * {@link android.content.pm.PackageManager#setComponentEnabledSetting(ComponentName, int, int)} to
83 * programmatically disable the {@link InCallService} your app declares in its manifest, your app
84 * will no longer fulfil the requirements expected of
85 * {@link android.app.role.RoleManager#ROLE_DIALER}.
86 * <p>
87 * The preloaded dialer will ALWAYS be used when the user places an emergency call, even if your
Tyler Gunn272fd212021-10-12 09:22:24 -070088 * app fills the {@link android.app.role.RoleManager#ROLE_DIALER} role. To ensure an optimal
89 * experience when placing an emergency call, the default dialer should ALWAYS use
90 * {@link android.telecom.TelecomManager#placeCall(Uri, Bundle)} to place calls (including
91 * emergency calls). This ensures that the platform is able to verify that the request came from
92 * the default dialer. If a non-preloaded dialer app uses {@link Intent#ACTION_CALL} to place an
93 * emergency call, it will be raised to the preloaded dialer app using {@link Intent#ACTION_DIAL}
94 * for confirmation; this is a suboptimal user experience.
Santos Cordonf2600eb2015-06-22 15:02:20 -070095 * <p>
96 * Below is an example manifest registration for an {@code InCallService}. The meta-data
Tyler Gunndc6e6c42018-07-03 16:08:17 -070097 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_UI} indicates that this particular
Santos Cordonf2600eb2015-06-22 15:02:20 -070098 * {@code InCallService} implementation intends to replace the built-in in-call UI.
Tyler Gunndc6e6c42018-07-03 16:08:17 -070099 * The meta-data {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} indicates that this
100 * {@link InCallService} will play the ringtone for incoming calls. See
101 * <a href="#incomingCallNotification">below</a> for more information on showing the incoming call
102 * UI and playing the ringtone in your app.
Santos Cordonf2600eb2015-06-22 15:02:20 -0700103 * <pre>
104 * {@code
Neil Fuller71fbb812015-11-30 09:51:33 +0000105 * <service android:name="your.package.YourInCallServiceImplementation"
Tyler Gunn84421d72021-09-03 14:05:37 -0700106 * android:permission="android.permission.BIND_INCALL_SERVICE"
107 * android:exported="true">
Neil Fuller71fbb812015-11-30 09:51:33 +0000108 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700109 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_RINGING"
110 * android:value="true" />
Neil Fuller71fbb812015-11-30 09:51:33 +0000111 * <intent-filter>
112 * <action android:name="android.telecom.InCallService"/>
113 * </intent-filter>
114 * </service>
Santos Cordonf2600eb2015-06-22 15:02:20 -0700115 * }
116 * </pre>
Tyler Gunn84421d72021-09-03 14:05:37 -0700117 *
118 * <em>Note: You should NOT mark your {@link InCallService} with the attribute
119 * {@code android:exported="false"}; doing so can result in a failure to bind to your implementation
120 * during calls.</em>
Tyler Gunnfe39efa2018-02-02 13:18:02 -0800121 * <p>
122 * In addition to implementing the {@link InCallService} API, you must also declare an activity in
123 * your manifest which handles the {@link Intent#ACTION_DIAL} intent. The example below illustrates
124 * how this is done:
125 * <pre>
126 * {@code
127 * <activity android:name="your.package.YourDialerActivity"
128 * android:label="@string/yourDialerActivityLabel">
129 * <intent-filter>
130 * <action android:name="android.intent.action.DIAL" />
131 * <category android:name="android.intent.category.DEFAULT" />
132 * </intent-filter>
Tyler Gunn4057d4c2020-01-31 15:03:43 -0800133 * <intent-filter>
134 * <action android:name="android.intent.action.DIAL" />
135 * <category android:name="android.intent.category.DEFAULT" />
136 * <data android:scheme="tel" />
137 * </intent-filter>
Tyler Gunnfe39efa2018-02-02 13:18:02 -0800138 * </activity>
139 * }
140 * </pre>
141 * <p>
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800142 * When a user installs your application and runs it for the first time, you should use the
143 * {@link android.app.role.RoleManager} to prompt the user to see if they would like your app to
144 * be the new default phone app.
145 * <p id="requestRole">
146 * The code below shows how your app can request to become the default phone/dialer app:
147 * <pre>
148 * {@code
149 * private static final int REQUEST_ID = 1;
150 *
151 * public void requestRole() {
152 * RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
153 * Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_DIALER);
154 * startActivityForResult(intent, REQUEST_ID);
155 * }
156 *
157 * &#64;Override
158 * public void onActivityResult(int requestCode, int resultCode, Intent data) {
159 * if (requestCode == REQUEST_ID) {
160 * if (resultCode == android.app.Activity.RESULT_OK) {
161 * // Your app is now the default dialer app
162 * } else {
163 * // Your app is not the default dialer app
164 * }
165 * }
166 * }
Tyler Gunn4057d4c2020-01-31 15:03:43 -0800167 * }
Shuo Qian93273fd2021-02-10 15:12:09 -0800168 *
169 * </pre>
170 * <p id="companionInCallService">
171 * <h3>Access to InCallService for Wearable Devices</h3>
172 * <ol>
173 * If your app is a third-party companion app and wants to access InCallService APIs, what your
174 * app could do are:
175 * <p>
176 * <ol>
177 * <li> Declare MANAGE_ONGOING_CALLS permission in your manifest
178 * <li> Associate with a physical wearable device via the
179 * {@link android.companion.CompanionDeviceManager} API as a companion app. See:
180 * https://developer.android.com/guide/topics/connectivity/companion-device-pairing
181 * <li> Implement this InCallService with BIND_INCALL_SERVICE permission
182 * </ol>
183 * </ol>
184 * <p>
185 *
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800186 * </pre>
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700187 * <p id="incomingCallNotification">
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800188 * <h3>Showing the Incoming Call Notification</h3>
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700189 * When your app receives a new incoming call via {@link InCallService#onCallAdded(Call)}, it is
190 * responsible for displaying an incoming call UI for the incoming call. It should do this using
191 * {@link android.app.NotificationManager} APIs to post a new incoming call notification.
192 * <p>
193 * Where your app declares the meta-data {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING}, it
194 * is responsible for playing the ringtone for incoming calls. Your app should create a
195 * {@link android.app.NotificationChannel} which specifies the desired ringtone. For example:
196 * <pre><code>
197 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
198 * NotificationManager.IMPORTANCE_MAX);
199 * // other channel setup stuff goes here.
200 *
201 * // We'll use the default system ringtone for our incoming call notification channel. You can
202 * // use your own audio resource here.
203 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
204 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
205 * // Setting the AudioAttributes is important as it identifies the purpose of your
206 * // notification sound.
207 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
208 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
209 * .build());
210 *
211 * NotificationManager mgr = getSystemService(NotificationManager.class);
212 * mgr.createNotificationChannel(channel);
213 * </code></pre>
214 * <p>
215 * When your app receives a new incoming call, it creates a {@link android.app.Notification} for the
216 * incoming call and associates it with your incoming call notification channel. You can specify a
217 * {@link android.app.PendingIntent} on the notification which will launch your full screen
218 * incoming call UI. The notification manager framework will display your notification as a
219 * heads-up notification if the user is actively using the phone. When the user is not using the
220 * phone, your full-screen incoming call UI is used instead.
221 * For example:
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800222 * <pre><code>{@code
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700223 * // Create an intent which triggers your fullscreen incoming call user interface.
224 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
225 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
226 * intent.setClass(context, YourIncomingCallActivity.class);
Ashwini Orugantif8191e82021-01-07 12:04:25 -0800227 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_MUTABLE_UNAUDITED);
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700228 *
229 * // Build the notification as an ongoing high priority item; this ensures it will show as
230 * // a heads up notification which slides down over top of the current content.
231 * final Notification.Builder builder = new Notification.Builder(context);
232 * builder.setOngoing(true);
233 * builder.setPriority(Notification.PRIORITY_HIGH);
234 *
235 * // Set notification content intent to take user to the fullscreen UI if user taps on the
236 * // notification body.
237 * builder.setContentIntent(pendingIntent);
238 * // Set full screen intent to trigger display of the fullscreen UI when the notification
239 * // manager deems it appropriate.
240 * builder.setFullScreenIntent(pendingIntent, true);
241 *
242 * // Setup notification content.
243 * builder.setSmallIcon( yourIconResourceId );
244 * builder.setContentTitle("Your notification title");
245 * builder.setContentText("Your notification content.");
246 *
247 * // Use builder.addAction(..) to add buttons to answer or reject the call.
248 *
249 * NotificationManager notificationManager = mContext.getSystemService(
250 * NotificationManager.class);
251 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, builder.build());
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800252 * }</pre>
253 * <p>
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800254 */
Santos Cordon2f42b112014-07-19 13:19:37 -0700255public abstract class InCallService extends Service {
Tyler Gunn2ac40102014-08-18 16:23:10 -0700256
257 /**
258 * The {@link Intent} that must be declared as handled by the service.
259 */
260 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700261 public static final String SERVICE_INTERFACE = "android.telecom.InCallService";
Tyler Gunn2ac40102014-08-18 16:23:10 -0700262
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800263 private static final int MSG_SET_IN_CALL_ADAPTER = 1;
264 private static final int MSG_ADD_CALL = 2;
Sailesh Nepal60437932014-04-05 16:44:55 -0700265 private static final int MSG_UPDATE_CALL = 3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700266 private static final int MSG_SET_POST_DIAL_WAIT = 4;
Yorke Lee4af59352015-05-13 14:14:54 -0700267 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 5;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700268 private static final int MSG_BRING_TO_FOREGROUND = 6;
Santos Cordon6c912b72014-11-07 16:05:09 -0800269 private static final int MSG_ON_CAN_ADD_CALL_CHANGED = 7;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800270 private static final int MSG_SILENCE_RINGER = 8;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700271 private static final int MSG_ON_CONNECTION_EVENT = 9;
Hall Liu95d55872017-01-25 17:12:49 -0800272 private static final int MSG_ON_RTT_UPGRADE_REQUEST = 10;
Hall Liu57006aa2017-02-06 10:49:48 -0800273 private static final int MSG_ON_RTT_INITIATION_FAILURE = 11;
Sanket Padawe85291f62017-12-01 13:59:27 -0800274 private static final int MSG_ON_HANDOVER_FAILED = 12;
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800275 private static final int MSG_ON_HANDOVER_COMPLETE = 13;
Junhoedf3d822022-11-24 09:26:37 +0000276 private static final int MSG_ON_CALL_ENDPOINT_CHANGED = 14;
277 private static final int MSG_ON_AVAILABLE_CALL_ENDPOINTS_CHANGED = 15;
278 private static final int MSG_ON_MUTE_STATE_CHANGED = 16;
279
280 private CallEndpoint mCallEndpoint;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800281
282 /** Default Handler used to consolidate binder method calls onto a single thread. */
283 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
284 @Override
285 public void handleMessage(Message msg) {
Jay Shrauner5e6162d2014-09-22 20:47:45 -0700286 if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) {
287 return;
288 }
289
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800290 switch (msg.what) {
291 case MSG_SET_IN_CALL_ADAPTER:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800292 String callingPackage = getApplicationContext().getOpPackageName();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800293 mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj), callingPackage,
294 getApplicationContext().getApplicationInfo().targetSdkVersion);
Santos Cordona2492812015-04-15 11:05:16 -0700295 mPhone.addListener(mPhoneListener);
Ihab Awade63fadb2014-07-09 21:52:04 -0700296 onPhoneCreated(mPhone);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800297 break;
298 case MSG_ADD_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700299 mPhone.internalAddCall((ParcelableCall) msg.obj);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800300 break;
Sailesh Nepal60437932014-04-05 16:44:55 -0700301 case MSG_UPDATE_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700302 mPhone.internalUpdateCall((ParcelableCall) msg.obj);
Ihab Awad2f236642014-03-10 15:33:45 -0700303 break;
Ihab Awad2f236642014-03-10 15:33:45 -0700304 case MSG_SET_POST_DIAL_WAIT: {
305 SomeArgs args = (SomeArgs) msg.obj;
306 try {
307 String callId = (String) args.arg1;
308 String remaining = (String) args.arg2;
Ihab Awade63fadb2014-07-09 21:52:04 -0700309 mPhone.internalSetPostDialWait(callId, remaining);
Ihab Awad2f236642014-03-10 15:33:45 -0700310 } finally {
311 args.recycle();
312 }
313 break;
314 }
Yorke Lee4af59352015-05-13 14:14:54 -0700315 case MSG_ON_CALL_AUDIO_STATE_CHANGED:
316 mPhone.internalCallAudioStateChanged((CallAudioState) msg.obj);
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700317 break;
Santos Cordon3534ede2014-05-29 13:07:10 -0700318 case MSG_BRING_TO_FOREGROUND:
Ihab Awade63fadb2014-07-09 21:52:04 -0700319 mPhone.internalBringToForeground(msg.arg1 == 1);
Santos Cordon3534ede2014-05-29 13:07:10 -0700320 break;
Santos Cordon6c912b72014-11-07 16:05:09 -0800321 case MSG_ON_CAN_ADD_CALL_CHANGED:
322 mPhone.internalSetCanAddCall(msg.arg1 == 1);
323 break;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800324 case MSG_SILENCE_RINGER:
325 mPhone.internalSilenceRinger();
326 break;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700327 case MSG_ON_CONNECTION_EVENT: {
328 SomeArgs args = (SomeArgs) msg.obj;
329 try {
330 String callId = (String) args.arg1;
331 String event = (String) args.arg2;
332 Bundle extras = (Bundle) args.arg3;
333 mPhone.internalOnConnectionEvent(callId, event, extras);
334 } finally {
335 args.recycle();
336 }
337 break;
338 }
Hall Liu95d55872017-01-25 17:12:49 -0800339 case MSG_ON_RTT_UPGRADE_REQUEST: {
340 String callId = (String) msg.obj;
341 int requestId = msg.arg1;
342 mPhone.internalOnRttUpgradeRequest(callId, requestId);
343 break;
344 }
Hall Liu57006aa2017-02-06 10:49:48 -0800345 case MSG_ON_RTT_INITIATION_FAILURE: {
346 String callId = (String) msg.obj;
347 int reason = msg.arg1;
348 mPhone.internalOnRttInitiationFailure(callId, reason);
349 break;
350 }
Sanket Padawe85291f62017-12-01 13:59:27 -0800351 case MSG_ON_HANDOVER_FAILED: {
352 String callId = (String) msg.obj;
353 int error = msg.arg1;
354 mPhone.internalOnHandoverFailed(callId, error);
355 break;
356 }
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800357 case MSG_ON_HANDOVER_COMPLETE: {
358 String callId = (String) msg.obj;
359 mPhone.internalOnHandoverComplete(callId);
360 break;
361 }
Junhoedf3d822022-11-24 09:26:37 +0000362 case MSG_ON_CALL_ENDPOINT_CHANGED: {
363 CallEndpoint endpoint = (CallEndpoint) msg.obj;
364 if (!Objects.equals(mCallEndpoint, endpoint)) {
365 mCallEndpoint = endpoint;
366 InCallService.this.onCallEndpointChanged(mCallEndpoint);
367 }
368 break;
369 }
370 case MSG_ON_AVAILABLE_CALL_ENDPOINTS_CHANGED: {
371 InCallService.this.onAvailableCallEndpointsChanged(
372 (List<CallEndpoint>) msg.obj);
373 break;
374 }
375 case MSG_ON_MUTE_STATE_CHANGED: {
376 InCallService.this.onMuteStateChanged((boolean) msg.obj);
377 break;
378 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800379 default:
380 break;
381 }
382 }
383 };
384
385 /** Manages the binder calls so that the implementor does not need to deal with it. */
386 private final class InCallServiceBinder extends IInCallService.Stub {
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800387 @Override
388 public void setInCallAdapter(IInCallAdapter inCallAdapter) {
389 mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget();
390 }
391
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800392 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700393 public void addCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700394 mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800395 }
396
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800397 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700398 public void updateCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700399 mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
Ihab Awad2f236642014-03-10 15:33:45 -0700400 }
401
402 @Override
403 public void setPostDial(String callId, String remaining) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700404 // TODO: Unused
Ihab Awad2f236642014-03-10 15:33:45 -0700405 }
406
407 @Override
408 public void setPostDialWait(String callId, String remaining) {
409 SomeArgs args = SomeArgs.obtain();
410 args.arg1 = callId;
411 args.arg2 = remaining;
412 mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
413 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700414
415 @Override
Yorke Lee4af59352015-05-13 14:14:54 -0700416 public void onCallAudioStateChanged(CallAudioState callAudioState) {
417 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, callAudioState).sendToTarget();
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700418 }
Santos Cordon3534ede2014-05-29 13:07:10 -0700419
Santos Cordon3534ede2014-05-29 13:07:10 -0700420 @Override
Junhoedf3d822022-11-24 09:26:37 +0000421 public void onCallEndpointChanged(CallEndpoint callEndpoint) {
422 mHandler.obtainMessage(MSG_ON_CALL_ENDPOINT_CHANGED, callEndpoint).sendToTarget();
423 }
424
425 @Override
426 public void onAvailableCallEndpointsChanged(List<CallEndpoint> availableEndpoints) {
427 mHandler.obtainMessage(MSG_ON_AVAILABLE_CALL_ENDPOINTS_CHANGED, availableEndpoints)
428 .sendToTarget();
429 }
430
431 @Override
432 public void onMuteStateChanged(boolean isMuted) {
433 mHandler.obtainMessage(MSG_ON_MUTE_STATE_CHANGED, isMuted).sendToTarget();
434 }
435
436 @Override
Santos Cordon3534ede2014-05-29 13:07:10 -0700437 public void bringToForeground(boolean showDialpad) {
438 mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
439 }
Santos Cordon6c912b72014-11-07 16:05:09 -0800440
441 @Override
442 public void onCanAddCallChanged(boolean canAddCall) {
443 mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0)
444 .sendToTarget();
445 }
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800446
447 @Override
448 public void silenceRinger() {
449 mHandler.obtainMessage(MSG_SILENCE_RINGER).sendToTarget();
450 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700451
452 @Override
453 public void onConnectionEvent(String callId, String event, Bundle extras) {
454 SomeArgs args = SomeArgs.obtain();
455 args.arg1 = callId;
456 args.arg2 = event;
457 args.arg3 = extras;
458 mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget();
459 }
Hall Liu95d55872017-01-25 17:12:49 -0800460
461 @Override
462 public void onRttUpgradeRequest(String callId, int id) {
463 mHandler.obtainMessage(MSG_ON_RTT_UPGRADE_REQUEST, id, 0, callId).sendToTarget();
464 }
Hall Liu57006aa2017-02-06 10:49:48 -0800465
466 @Override
467 public void onRttInitiationFailure(String callId, int reason) {
468 mHandler.obtainMessage(MSG_ON_RTT_INITIATION_FAILURE, reason, 0, callId).sendToTarget();
469 }
Sanket Padawe85291f62017-12-01 13:59:27 -0800470
471 @Override
472 public void onHandoverFailed(String callId, int error) {
473 mHandler.obtainMessage(MSG_ON_HANDOVER_FAILED, error, 0, callId).sendToTarget();
474 }
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800475
476 @Override
477 public void onHandoverComplete(String callId) {
478 mHandler.obtainMessage(MSG_ON_HANDOVER_COMPLETE, callId).sendToTarget();
479 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800480 }
481
Santos Cordona2492812015-04-15 11:05:16 -0700482 private Phone.Listener mPhoneListener = new Phone.Listener() {
483 /** ${inheritDoc} */
484 @Override
485 public void onAudioStateChanged(Phone phone, AudioState audioState) {
486 InCallService.this.onAudioStateChanged(audioState);
487 }
488
Yorke Lee4af59352015-05-13 14:14:54 -0700489 public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) {
490 InCallService.this.onCallAudioStateChanged(callAudioState);
491 };
492
Santos Cordona2492812015-04-15 11:05:16 -0700493 /** ${inheritDoc} */
494 @Override
495 public void onBringToForeground(Phone phone, boolean showDialpad) {
496 InCallService.this.onBringToForeground(showDialpad);
497 }
498
499 /** ${inheritDoc} */
500 @Override
501 public void onCallAdded(Phone phone, Call call) {
502 InCallService.this.onCallAdded(call);
503 }
504
505 /** ${inheritDoc} */
506 @Override
507 public void onCallRemoved(Phone phone, Call call) {
508 InCallService.this.onCallRemoved(call);
509 }
510
511 /** ${inheritDoc} */
512 @Override
513 public void onCanAddCallChanged(Phone phone, boolean canAddCall) {
514 InCallService.this.onCanAddCallChanged(canAddCall);
515 }
516
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800517 /** ${inheritDoc} */
518 @Override
519 public void onSilenceRinger(Phone phone) {
520 InCallService.this.onSilenceRinger();
521 }
522
Santos Cordona2492812015-04-15 11:05:16 -0700523 };
524
Ihab Awade63fadb2014-07-09 21:52:04 -0700525 private Phone mPhone;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800526
Santos Cordon2f42b112014-07-19 13:19:37 -0700527 public InCallService() {
528 }
Evan Charlton924748f2014-04-03 08:36:38 -0700529
Santos Cordon2f42b112014-07-19 13:19:37 -0700530 @Override
531 public IBinder onBind(Intent intent) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700532 return new InCallServiceBinder();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800533 }
534
Santos Cordonf30d7e92014-08-26 09:54:33 -0700535 @Override
536 public boolean onUnbind(Intent intent) {
Santos Cordon619b3c02014-09-02 17:13:45 -0700537 if (mPhone != null) {
538 Phone oldPhone = mPhone;
539 mPhone = null;
Santos Cordonf30d7e92014-08-26 09:54:33 -0700540
Santos Cordon619b3c02014-09-02 17:13:45 -0700541 oldPhone.destroy();
Santos Cordona2492812015-04-15 11:05:16 -0700542 // destroy sets all the calls to disconnected if any live ones still exist. Therefore,
543 // it is important to remove the Listener *after* the call to destroy so that
544 // InCallService.on* callbacks are appropriately called.
545 oldPhone.removeListener(mPhoneListener);
546
Santos Cordon619b3c02014-09-02 17:13:45 -0700547 onPhoneDestroyed(oldPhone);
548 }
Santos Cordona2492812015-04-15 11:05:16 -0700549
Santos Cordonf30d7e92014-08-26 09:54:33 -0700550 return false;
551 }
552
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800553 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700554 * Obtain the {@code Phone} associated with this {@code InCallService}.
555 *
556 * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null}
Santos Cordon2f42b112014-07-19 13:19:37 -0700557 * if the {@code InCallService} is not in a state where it has an associated
558 * {@code Phone}.
Santos Cordona2492812015-04-15 11:05:16 -0700559 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700560 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800561 */
Santos Cordona2492812015-04-15 11:05:16 -0700562 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700563 @Deprecated
564 public Phone getPhone() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700565 return mPhone;
Evan Charlton924748f2014-04-03 08:36:38 -0700566 }
567
568 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700569 * Obtains the current list of {@code Call}s to be displayed by this in-call service.
Santos Cordona2492812015-04-15 11:05:16 -0700570 *
571 * @return A list of the relevant {@code Call}s.
572 */
573 public final List<Call> getCalls() {
574 return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls();
575 }
576
577 /**
578 * Returns if the device can support additional calls.
579 *
580 * @return Whether the phone supports adding more calls.
581 */
582 public final boolean canAddCall() {
583 return mPhone == null ? false : mPhone.canAddCall();
584 }
585
586 /**
587 * Obtains the current phone call audio state.
588 *
589 * @return An object encapsulating the audio state. Returns null if the service is not
590 * fully initialized.
Yorke Lee4af59352015-05-13 14:14:54 -0700591 * @deprecated Use {@link #getCallAudioState()} instead.
592 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700593 */
Yorke Lee4af59352015-05-13 14:14:54 -0700594 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700595 public final AudioState getAudioState() {
596 return mPhone == null ? null : mPhone.getAudioState();
597 }
598
599 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700600 * Obtains the current phone call audio state.
601 *
602 * @return An object encapsulating the audio state. Returns null if the service is not
603 * fully initialized.
Junhoedf3d822022-11-24 09:26:37 +0000604 * @deprecated Use {@link #getCurrentCallEndpoint()},
605 * {@link #onAvailableCallEndpointsChanged(List)} and
606 * {@link #onMuteStateChanged(boolean)} instead.
Yorke Lee4af59352015-05-13 14:14:54 -0700607 */
Junhoedf3d822022-11-24 09:26:37 +0000608 @Deprecated
Yorke Lee4af59352015-05-13 14:14:54 -0700609 public final CallAudioState getCallAudioState() {
610 return mPhone == null ? null : mPhone.getCallAudioState();
611 }
612
613 /**
Santos Cordona2492812015-04-15 11:05:16 -0700614 * Sets the microphone mute state. When this request is honored, there will be change to
Yorke Lee4af59352015-05-13 14:14:54 -0700615 * the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700616 *
617 * @param state {@code true} if the microphone should be muted; {@code false} otherwise.
618 */
619 public final void setMuted(boolean state) {
620 if (mPhone != null) {
621 mPhone.setMuted(state);
622 }
623 }
624
625 /**
626 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
Yorke Lee4af59352015-05-13 14:14:54 -0700627 * be change to the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700628 *
629 * @param route The audio route to use.
Junhoedf3d822022-11-24 09:26:37 +0000630 * @deprecated Use {@link #requestCallEndpointChange(CallEndpoint, Executor, OutcomeReceiver)}
631 * instead.
Santos Cordona2492812015-04-15 11:05:16 -0700632 */
Junhoedf3d822022-11-24 09:26:37 +0000633 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700634 public final void setAudioRoute(int route) {
635 if (mPhone != null) {
636 mPhone.setAudioRoute(route);
637 }
638 }
639
640 /**
Hall Liua98f58b52017-11-07 17:59:28 -0800641 * Request audio routing to a specific bluetooth device. Calling this method may result in
642 * the device routing audio to a different bluetooth device than the one specified if the
643 * bluetooth stack is unable to route audio to the requested device.
644 * A list of available devices can be obtained via
645 * {@link CallAudioState#getSupportedBluetoothDevices()}
646 *
Hall Liu15392832018-04-02 13:52:57 -0700647 * @param bluetoothDevice The bluetooth device to connect to.
Junhoedf3d822022-11-24 09:26:37 +0000648 * @deprecated Use {@link #requestCallEndpointChange(CallEndpoint, Executor, OutcomeReceiver)}
649 * instead.
Hall Liua98f58b52017-11-07 17:59:28 -0800650 */
Junhoedf3d822022-11-24 09:26:37 +0000651 @Deprecated
Hall Liu15392832018-04-02 13:52:57 -0700652 public final void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -0800653 if (mPhone != null) {
Hall Liu15392832018-04-02 13:52:57 -0700654 mPhone.requestBluetoothAudio(bluetoothDevice.getAddress());
Hall Liua98f58b52017-11-07 17:59:28 -0800655 }
656 }
657
658 /**
Junhoedf3d822022-11-24 09:26:37 +0000659 * Request audio routing to a specific CallEndpoint. Clients should not define their own
660 * CallEndpoint when requesting a change. Instead, the new endpoint should be one of the valid
661 * endpoints provided by {@link #onAvailableCallEndpointsChanged(List)}.
662 * When this request is honored, there will be change to the {@link #getCurrentCallEndpoint()}.
663 *
664 * @param endpoint The call endpoint to use.
665 * @param executor The executor of where the callback will execute.
666 * @param callback The callback to notify the result of the endpoint change.
667 */
668 public final void requestCallEndpointChange(@NonNull CallEndpoint endpoint,
669 @NonNull @CallbackExecutor Executor executor,
670 @NonNull OutcomeReceiver<Void, CallEndpointException> callback) {
671 if (mPhone != null) {
672 mPhone.requestCallEndpointChange(endpoint, executor, callback);
673 }
674 }
675
676 /**
677 * Obtains the current CallEndpoint.
678 *
679 * @return An object encapsulating the CallEndpoint.
680 */
681 @NonNull
682 public final CallEndpoint getCurrentCallEndpoint() {
683 return mCallEndpoint;
684 }
685
686 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700687 * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience
688 * to start displaying in-call information to the user. Each instance of {@code InCallService}
Santos Cordon2f42b112014-07-19 13:19:37 -0700689 * will have only one {@code Phone}, and this method will be called exactly once in the lifetime
690 * of the {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700691 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700692 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700693 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700694 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Evan Charlton924748f2014-04-03 08:36:38 -0700695 */
Santos Cordona2492812015-04-15 11:05:16 -0700696 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700697 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700698 public void onPhoneCreated(Phone phone) {
699 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800700
701 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700702 * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience
703 * to stop displaying in-call information to the user. This method will be called exactly once
704 * in the lifetime of the {@code InCallService}, and it will always be called after a previous
705 * call to {@link #onPhoneCreated(Phone)}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800706 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700707 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700708 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700709 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800710 */
Santos Cordona2492812015-04-15 11:05:16 -0700711 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700712 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700713 public void onPhoneDestroyed(Phone phone) {
714 }
Andrew Lee50aca232014-07-22 16:41:54 -0700715
716 /**
Santos Cordona2492812015-04-15 11:05:16 -0700717 * Called when the audio state changes.
718 *
719 * @param audioState The new {@link AudioState}.
Yorke Lee4af59352015-05-13 14:14:54 -0700720 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState) instead}.
721 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700722 */
Yorke Lee4af59352015-05-13 14:14:54 -0700723 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700724 public void onAudioStateChanged(AudioState audioState) {
725 }
726
727 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700728 * Called when the audio state changes.
729 *
730 * @param audioState The new {@link CallAudioState}.
Junhoedf3d822022-11-24 09:26:37 +0000731 * @deprecated Use {@link #onCallEndpointChanged(CallEndpoint)},
732 * {@link #onAvailableCallEndpointsChanged(List)} and
733 * {@link #onMuteStateChanged(boolean)} instead.
Yorke Lee4af59352015-05-13 14:14:54 -0700734 */
Junhoedf3d822022-11-24 09:26:37 +0000735 @Deprecated
Yorke Lee4af59352015-05-13 14:14:54 -0700736 public void onCallAudioStateChanged(CallAudioState audioState) {
737 }
738
739 /**
Junhoedf3d822022-11-24 09:26:37 +0000740 * Called when the current CallEndpoint changes.
741 *
742 * @param callEndpoint The current CallEndpoint {@link CallEndpoint}.
743 */
744 public void onCallEndpointChanged(@NonNull CallEndpoint callEndpoint) {
745 }
746
747 /**
748 * Called when the available CallEndpoint changes.
749 *
750 * @param availableEndpoints The set of available CallEndpoint {@link CallEndpoint}.
751 */
752 public void onAvailableCallEndpointsChanged(@NonNull List<CallEndpoint> availableEndpoints) {
753 }
754
755 /**
756 * Called when the mute state changes.
757 *
758 * @param isMuted The current mute state.
759 */
760 public void onMuteStateChanged(boolean isMuted) {
761 }
762
763 /**
Santos Cordona2492812015-04-15 11:05:16 -0700764 * Called to bring the in-call screen to the foreground. The in-call experience should
765 * respond immediately by coming to the foreground to inform the user of the state of
766 * ongoing {@code Call}s.
767 *
768 * @param showDialpad If true, put up the dialpad when the screen is shown.
769 */
770 public void onBringToForeground(boolean showDialpad) {
771 }
772
773 /**
774 * Called when a {@code Call} has been added to this in-call session. The in-call user
775 * experience should add necessary state listeners to the specified {@code Call} and
776 * immediately start to show the user information about the existence
777 * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will
778 * include this {@code Call}.
779 *
780 * @param call A newly added {@code Call}.
781 */
782 public void onCallAdded(Call call) {
783 }
784
785 /**
786 * Called when a {@code Call} has been removed from this in-call session. The in-call user
787 * experience should remove any state listeners from the specified {@code Call} and
788 * immediately stop displaying any information about this {@code Call}.
789 * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}.
790 *
791 * @param call A newly removed {@code Call}.
792 */
793 public void onCallRemoved(Call call) {
794 }
795
796 /**
797 * Called when the ability to add more calls changes. If the phone cannot
798 * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it
799 * is set to {@code true}. This can be used to control the visibility of UI to add more calls.
800 *
801 * @param canAddCall Indicates whether an additional call can be added.
802 */
803 public void onCanAddCallChanged(boolean canAddCall) {
804 }
805
806 /**
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800807 * Called to silence the ringer if a ringing call exists.
808 */
809 public void onSilenceRinger() {
810 }
811
812 /**
Tyler Gunn06f3fa62016-08-25 09:26:15 -0700813 * Unused; to handle connection events issued by a {@link ConnectionService}, implement the
814 * {@link android.telecom.Call.Callback#onConnectionEvent(Call, String, Bundle)} callback.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700815 * <p>
816 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
817 *
818 * @param call The call the event is associated with.
819 * @param event The event.
820 * @param extras Any associated extras.
821 */
822 public void onConnectionEvent(Call call, String event, Bundle extras) {
823 }
824
825 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700826 * Used to issue commands to the {@link Connection.VideoProvider} associated with a
827 * {@link Call}.
Andrew Lee50aca232014-07-22 16:41:54 -0700828 */
829 public static abstract class VideoCall {
830
Andrew Lee011728f2015-04-23 15:47:06 -0700831 /** @hide */
Aurimas Liutikas796760c2020-11-10 15:32:51 -0800832 @SuppressWarnings("HiddenAbstractMethod")
Andrew Lee011728f2015-04-23 15:47:06 -0700833 public abstract void destroy();
834
Andrew Lee50aca232014-07-22 16:41:54 -0700835 /**
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700836 * Registers a callback to receive commands and state changes for video calls.
Andrew Lee50aca232014-07-22 16:41:54 -0700837 *
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700838 * @param callback The video call callback.
Andrew Lee50aca232014-07-22 16:41:54 -0700839 */
Andrew Leeda80c872015-04-15 14:09:50 -0700840 public abstract void registerCallback(VideoCall.Callback callback);
841
842 /**
Andrew Lee011728f2015-04-23 15:47:06 -0700843 * Registers a callback to receive commands and state changes for video calls.
844 *
845 * @param callback The video call callback.
846 * @param handler A handler which commands and status changes will be delivered to.
847 */
848 public abstract void registerCallback(VideoCall.Callback callback, Handler handler);
849
850 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700851 * Clears the video call callback set via {@link #registerCallback}.
Tyler Gunn295f5d72015-06-04 11:08:54 -0700852 *
853 * @param callback The video call callback to clear.
Tyler Gunn75958422015-04-15 14:23:42 -0700854 */
Andrew Lee011728f2015-04-23 15:47:06 -0700855 public abstract void unregisterCallback(VideoCall.Callback callback);
Tyler Gunn75958422015-04-15 14:23:42 -0700856
857 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700858 * Sets the camera to be used for the outgoing video.
859 * <p>
860 * Handled by {@link Connection.VideoProvider#onSetCamera(String)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700861 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700862 * @param cameraId The id of the camera (use ids as reported by
863 * {@link CameraManager#getCameraIdList()}).
Andrew Lee50aca232014-07-22 16:41:54 -0700864 */
865 public abstract void setCamera(String cameraId);
866
867 /**
868 * Sets the surface to be used for displaying a preview of what the user's camera is
869 * currently capturing. When video transmission is enabled, this is the video signal which
870 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700871 * <p>
872 * Handled by {@link Connection.VideoProvider#onSetPreviewSurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700873 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700874 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700875 */
876 public abstract void setPreviewSurface(Surface surface);
877
878 /**
879 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700880 * <p>
881 * Handled by {@link Connection.VideoProvider#onSetDisplaySurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700882 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700883 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700884 */
885 public abstract void setDisplaySurface(Surface surface);
886
887 /**
888 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
889 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700890 * <p>
891 * Handled by {@link Connection.VideoProvider#onSetDeviceOrientation(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700892 *
893 * @param rotation The device orientation, in degrees.
894 */
895 public abstract void setDeviceOrientation(int rotation);
896
897 /**
Tyler Gunnc603b462021-06-14 17:24:40 -0700898 * Sets the camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700899 * <p>
900 * Handled by {@link Connection.VideoProvider#onSetZoom(float)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700901 *
Tyler Gunnc603b462021-06-14 17:24:40 -0700902 * @param value The camera zoom ratio; for the current camera, should be a value in the
903 * range defined by
904 * {@link android.hardware.camera2.CameraCharacteristics#CONTROL_ZOOM_RATIO_RANGE}.
Andrew Lee50aca232014-07-22 16:41:54 -0700905 */
906 public abstract void setZoom(float value);
907
908 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700909 * Issues a request to modify the properties of the current video session.
910 * <p>
911 * Example scenarios include: requesting an audio-only call to be upgraded to a
912 * bi-directional video call, turning on or off the user's camera, sending a pause signal
913 * when the {@link InCallService} is no longer the foreground application.
914 * <p>
915 * Handled by
916 * {@link Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700917 *
918 * @param requestProfile The requested call video properties.
919 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700920 public abstract void sendSessionModifyRequest(VideoProfile requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700921
922 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700923 * Provides a response to a request to change the current call video session
924 * properties. This should be called in response to a request the {@link InCallService} has
925 * received via {@link VideoCall.Callback#onSessionModifyRequestReceived}.
926 * <p>
927 * Handled by
928 * {@link Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700929 *
930 * @param responseProfile The response call video properties.
931 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700932 public abstract void sendSessionModifyResponse(VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700933
934 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700935 * Issues a request to the {@link Connection.VideoProvider} to retrieve the capabilities
936 * of the current camera. The current camera is selected using
937 * {@link VideoCall#setCamera(String)}.
938 * <p>
939 * Camera capabilities are reported to the caller via
940 * {@link VideoCall.Callback#onCameraCapabilitiesChanged(VideoProfile.CameraCapabilities)}.
941 * <p>
942 * Handled by {@link Connection.VideoProvider#onRequestCameraCapabilities()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700943 */
944 public abstract void requestCameraCapabilities();
945
946 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700947 * Issues a request to the {@link Connection.VideoProvider} to retrieve the cumulative data
948 * usage for the video component of the current call (in bytes). Data usage is reported
949 * to the caller via {@link VideoCall.Callback#onCallDataUsageChanged}.
950 * <p>
951 * Handled by {@link Connection.VideoProvider#onRequestConnectionDataUsage()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700952 */
953 public abstract void requestCallDataUsage();
954
955 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700956 * Provides the {@link Connection.VideoProvider} with the {@link Uri} of an image to be
957 * displayed to the peer device when the video signal is paused.
958 * <p>
959 * Handled by {@link Connection.VideoProvider#onSetPauseImage(Uri)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700960 *
961 * @param uri URI of image to display.
962 */
Yorke Lee32f24732015-05-12 16:18:03 -0700963 public abstract void setPauseImage(Uri uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700964
965 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700966 * The {@link InCallService} extends this class to provide a means of receiving callbacks
Tyler Gunn295f5d72015-06-04 11:08:54 -0700967 * from the {@link Connection.VideoProvider}.
968 * <p>
Tyler Gunnb702ef82015-05-29 11:51:53 -0700969 * When the {@link InCallService} receives the
970 * {@link Call.Callback#onVideoCallChanged(Call, VideoCall)} callback, it should create an
971 * instance its {@link VideoCall.Callback} implementation and set it on the
972 * {@link VideoCall} using {@link VideoCall#registerCallback(Callback)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700973 */
Andrew Leeda80c872015-04-15 14:09:50 -0700974 public static abstract class Callback {
Andrew Lee50aca232014-07-22 16:41:54 -0700975 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700976 * Called when the {@link Connection.VideoProvider} receives a session modification
Tyler Gunn295f5d72015-06-04 11:08:54 -0700977 * request from the peer device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700978 * <p>
979 * The {@link InCallService} may potentially prompt the user to confirm whether they
980 * wish to accept the request, or decide to automatically accept the request. In either
981 * case the {@link InCallService} should call
982 * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} to indicate the video
983 * profile agreed upon.
984 * <p>
985 * Callback originates from
986 * {@link Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700987 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700988 * @param videoProfile The requested video profile.
Andrew Lee50aca232014-07-22 16:41:54 -0700989 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700990 public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700991
992 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700993 * Called when the {@link Connection.VideoProvider} receives a response to a session
994 * modification request previously sent to the peer device.
995 * <p>
996 * The new video state should not be considered active by the {@link InCallService}
997 * until the {@link Call} video state changes (the
998 * {@link Call.Callback#onDetailsChanged(Call, Call.Details)} callback is triggered
999 * when the video state changes).
1000 * <p>
1001 * Callback originates from
1002 * {@link Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
1003 * VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -07001004 *
1005 * @param status Status of the session modify request. Valid values are
Tyler Gunnb702ef82015-05-29 11:51:53 -07001006 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1007 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
1008 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1009 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1010 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}.
1011 * @param requestedProfile The original request which was sent to the peer device.
1012 * @param responseProfile The actual profile changes made by the peer device.
Andrew Lee50aca232014-07-22 16:41:54 -07001013 */
1014 public abstract void onSessionModifyResponseReceived(int status,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001015 VideoProfile requestedProfile, VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -07001016
1017 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001018 * Handles events related to the current video session which the {@link InCallService}
1019 * may wish to handle. These are separate from requested changes to the session due to
1020 * the underlying protocol or connection.
1021 * <p>
1022 * Callback originates from
1023 * {@link Connection.VideoProvider#handleCallSessionEvent(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -07001024 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001025 * @param event The event. Valid values are:
1026 * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE},
1027 * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME},
1028 * {@link Connection.VideoProvider#SESSION_EVENT_TX_START},
1029 * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP},
1030 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001031 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY},
1032 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_PERMISSION_ERROR}.
Andrew Lee50aca232014-07-22 16:41:54 -07001033 */
1034 public abstract void onCallSessionEvent(int event);
1035
1036 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001037 * Handles a change to the video dimensions from the peer device. This could happen if,
1038 * for example, the peer changes orientation of their device, or switches cameras.
1039 * <p>
1040 * Callback originates from
1041 * {@link Connection.VideoProvider#changePeerDimensions(int, int)}.
Andrew Lee50aca232014-07-22 16:41:54 -07001042 *
1043 * @param width The updated peer video width.
1044 * @param height The updated peer video height.
1045 */
1046 public abstract void onPeerDimensionsChanged(int width, int height);
1047
1048 /**
Rekha Kumar07366812015-03-24 16:42:31 -07001049 * Handles a change to the video quality.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001050 * <p>
1051 * Callback originates from {@link Connection.VideoProvider#changeVideoQuality(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001052 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001053 * @param videoQuality The updated peer video quality. Valid values:
1054 * {@link VideoProfile#QUALITY_HIGH},
1055 * {@link VideoProfile#QUALITY_MEDIUM},
1056 * {@link VideoProfile#QUALITY_LOW},
1057 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001058 */
1059 public abstract void onVideoQualityChanged(int videoQuality);
1060
1061 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001062 * Handles an update to the total data used for the current video session.
1063 * <p>
1064 * Used by the {@link Connection.VideoProvider} in response to
1065 * {@link VideoCall#requestCallDataUsage()}. May also be called periodically by the
1066 * {@link Connection.VideoProvider}.
1067 * <p>
1068 * Callback originates from {@link Connection.VideoProvider#setCallDataUsage(long)}.
Andrew Lee50aca232014-07-22 16:41:54 -07001069 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001070 * @param dataUsage The updated data usage (in bytes).
Andrew Lee50aca232014-07-22 16:41:54 -07001071 */
Rekha Kumar07366812015-03-24 16:42:31 -07001072 public abstract void onCallDataUsageChanged(long dataUsage);
Andrew Lee50aca232014-07-22 16:41:54 -07001073
1074 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001075 * Handles a change in the capabilities of the currently selected camera.
1076 * <p>
1077 * Used by the {@link Connection.VideoProvider} in response to
1078 * {@link VideoCall#requestCameraCapabilities()}. The {@link Connection.VideoProvider}
1079 * may also report the camera capabilities after a call to
1080 * {@link VideoCall#setCamera(String)}.
1081 * <p>
1082 * Callback originates from
1083 * {@link Connection.VideoProvider#changeCameraCapabilities(
1084 * VideoProfile.CameraCapabilities)}.
Andrew Lee50aca232014-07-22 16:41:54 -07001085 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001086 * @param cameraCapabilities The changed camera capabilities.
Andrew Lee50aca232014-07-22 16:41:54 -07001087 */
Yorke Lee400470f2015-05-12 13:31:25 -07001088 public abstract void onCameraCapabilitiesChanged(
1089 VideoProfile.CameraCapabilities cameraCapabilities);
Andrew Lee50aca232014-07-22 16:41:54 -07001090 }
1091 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -08001092}