blob: 705b4918726eaf6ff339562ad88b0483dd7a49e4 [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
Hall Liua98f58b52017-11-07 17:59:28 -080019import android.annotation.NonNull;
Tyler Gunn2ac40102014-08-18 16:23:10 -070020import android.annotation.SdkConstant;
Santos Cordona2492812015-04-15 11:05:16 -070021import android.annotation.SystemApi;
Santos Cordon2f42b112014-07-19 13:19:37 -070022import android.app.Service;
Tyler Gunn4057d4c2020-01-31 15:03:43 -080023import android.app.UiModeManager;
Hall Liua98f58b52017-11-07 17:59:28 -080024import android.bluetooth.BluetoothDevice;
Santos Cordon2f42b112014-07-19 13:19:37 -070025import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070026import android.hardware.camera2.CameraManager;
Yorke Lee32f24732015-05-12 16:18:03 -070027import android.net.Uri;
Tyler Gunn876dbfb2016-03-14 15:18:07 -070028import android.os.Bundle;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080029import android.os.Handler;
30import android.os.IBinder;
31import android.os.Looper;
32import android.os.Message;
Andrew Lee50aca232014-07-22 16:41:54 -070033import android.view.Surface;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080034
Ihab Awad2f236642014-03-10 15:33:45 -070035import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070036import com.android.internal.telecom.IInCallAdapter;
37import com.android.internal.telecom.IInCallService;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080038
Santos Cordona2492812015-04-15 11:05:16 -070039import java.util.Collections;
40import java.util.List;
Andrew Lee50aca232014-07-22 16:41:54 -070041
Sailesh Nepalab5d2822014-03-08 18:01:06 -080042/**
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -080043 * This service is implemented by an app that wishes to provide functionality for managing
44 * phone calls.
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -080045 * <h2>Becoming the Default Phone App</h2>
Tyler Gunn556d2402019-04-10 08:59:43 -070046 * 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 -080047 * in a call. It also provides the user with a means to initiate calls and see a history of calls
48 * on their device. A device is bundled with a system provided default dialer/phone app. The user
49 * may choose a single app to take over this role from the system app. An app which wishes to
50 * fulfill one this role uses the {@link android.app.role.RoleManager} to request that they fill the
51 * {@link android.app.role.RoleManager#ROLE_DIALER} role.
Tyler Gunn556d2402019-04-10 08:59:43 -070052 * <p>
Tyler Gunn4057d4c2020-01-31 15:03:43 -080053 * The default phone app provides a user interface while the device is in a call, and the device is
54 * not in car mode (i.e. {@link UiModeManager#getCurrentModeType()} is not
55 * {@link android.content.res.Configuration#UI_MODE_TYPE_CAR}).
56 * <p>
57 * In order to fill the {@link android.app.role.RoleManager#ROLE_DIALER} role, an app must meet a
58 * number of requirements:
59 * <ul>
60 * <li>It must handle the {@link Intent#ACTION_DIAL} intent. This means the app must provide
61 * a dial pad UI for the user to initiate outgoing calls.</li>
62 * <li>It must fully implement the {@link InCallService} API and provide both an incoming call
63 * UI, as well as an ongoing call UI.</li>
64 * </ul>
65 * <p>
66 * Note: If the app filling the {@link android.app.role.RoleManager#ROLE_DIALER} crashes during
67 * {@link InCallService} binding, the Telecom framework will automatically fall back to using the
68 * dialer app pre-loaded on the device. The system will display a notification to the user to let
69 * them know that the app has crashed and that their call was continued using the pre-loaded dialer
70 * app.
71 * <p>
72 * Further, the pre-loaded dialer will ALWAYS be used when the user places an emergency call.
Santos Cordonf2600eb2015-06-22 15:02:20 -070073 * <p>
74 * Below is an example manifest registration for an {@code InCallService}. The meta-data
Tyler Gunndc6e6c42018-07-03 16:08:17 -070075 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_UI} indicates that this particular
Santos Cordonf2600eb2015-06-22 15:02:20 -070076 * {@code InCallService} implementation intends to replace the built-in in-call UI.
Tyler Gunndc6e6c42018-07-03 16:08:17 -070077 * The meta-data {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} indicates that this
78 * {@link InCallService} will play the ringtone for incoming calls. See
79 * <a href="#incomingCallNotification">below</a> for more information on showing the incoming call
80 * UI and playing the ringtone in your app.
Santos Cordonf2600eb2015-06-22 15:02:20 -070081 * <pre>
82 * {@code
Neil Fuller71fbb812015-11-30 09:51:33 +000083 * <service android:name="your.package.YourInCallServiceImplementation"
Tyler Gunn84421d72021-09-03 14:05:37 -070084 * android:permission="android.permission.BIND_INCALL_SERVICE"
85 * android:exported="true">
Neil Fuller71fbb812015-11-30 09:51:33 +000086 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
Tyler Gunndc6e6c42018-07-03 16:08:17 -070087 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_RINGING"
88 * android:value="true" />
Neil Fuller71fbb812015-11-30 09:51:33 +000089 * <intent-filter>
90 * <action android:name="android.telecom.InCallService"/>
91 * </intent-filter>
92 * </service>
Santos Cordonf2600eb2015-06-22 15:02:20 -070093 * }
94 * </pre>
Tyler Gunn84421d72021-09-03 14:05:37 -070095 *
96 * <em>Note: You should NOT mark your {@link InCallService} with the attribute
97 * {@code android:exported="false"}; doing so can result in a failure to bind to your implementation
98 * during calls.</em>
Tyler Gunnfe39efa2018-02-02 13:18:02 -080099 * <p>
100 * In addition to implementing the {@link InCallService} API, you must also declare an activity in
101 * your manifest which handles the {@link Intent#ACTION_DIAL} intent. The example below illustrates
102 * how this is done:
103 * <pre>
104 * {@code
105 * <activity android:name="your.package.YourDialerActivity"
106 * android:label="@string/yourDialerActivityLabel">
107 * <intent-filter>
108 * <action android:name="android.intent.action.DIAL" />
109 * <category android:name="android.intent.category.DEFAULT" />
110 * </intent-filter>
Tyler Gunn4057d4c2020-01-31 15:03:43 -0800111 * <intent-filter>
112 * <action android:name="android.intent.action.DIAL" />
113 * <category android:name="android.intent.category.DEFAULT" />
114 * <data android:scheme="tel" />
115 * </intent-filter>
Tyler Gunnfe39efa2018-02-02 13:18:02 -0800116 * </activity>
117 * }
118 * </pre>
119 * <p>
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800120 * When a user installs your application and runs it for the first time, you should use the
121 * {@link android.app.role.RoleManager} to prompt the user to see if they would like your app to
122 * be the new default phone app.
123 * <p id="requestRole">
124 * The code below shows how your app can request to become the default phone/dialer app:
125 * <pre>
126 * {@code
127 * private static final int REQUEST_ID = 1;
128 *
129 * public void requestRole() {
130 * RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
131 * Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_DIALER);
132 * startActivityForResult(intent, REQUEST_ID);
133 * }
134 *
135 * &#64;Override
136 * public void onActivityResult(int requestCode, int resultCode, Intent data) {
137 * if (requestCode == REQUEST_ID) {
138 * if (resultCode == android.app.Activity.RESULT_OK) {
139 * // Your app is now the default dialer app
140 * } else {
141 * // Your app is not the default dialer app
142 * }
143 * }
144 * }
Tyler Gunn4057d4c2020-01-31 15:03:43 -0800145 * }
sqian7a2b7112021-02-25 20:40:12 +0000146 *
147 * </pre>
148 * <p id="companionInCallService">
149 * <h3>Access to InCallService for Wearable Devices</h3>
150 * <ol>
151 * If your app is a third-party companion app and wants to access InCallService APIs, what your
152 * app could do are:
153 * <p>
154 * <ol>
155 * <li> Declare MANAGE_ONGOING_CALLS permission in your manifest
156 * <li> Associate with a physical wearable device via the
157 * {@link android.companion.CompanionDeviceManager} API as a companion app. See:
158 * https://developer.android.com/guide/topics/connectivity/companion-device-pairing
159 * <li> Implement this InCallService with BIND_INCALL_SERVICE permission
160 * </ol>
161 * </ol>
162 * <p>
163 *
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800164 * </pre>
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700165 * <p id="incomingCallNotification">
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800166 * <h3>Showing the Incoming Call Notification</h3>
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700167 * When your app receives a new incoming call via {@link InCallService#onCallAdded(Call)}, it is
168 * responsible for displaying an incoming call UI for the incoming call. It should do this using
169 * {@link android.app.NotificationManager} APIs to post a new incoming call notification.
170 * <p>
171 * Where your app declares the meta-data {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING}, it
172 * is responsible for playing the ringtone for incoming calls. Your app should create a
173 * {@link android.app.NotificationChannel} which specifies the desired ringtone. For example:
174 * <pre><code>
175 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
176 * NotificationManager.IMPORTANCE_MAX);
177 * // other channel setup stuff goes here.
178 *
179 * // We'll use the default system ringtone for our incoming call notification channel. You can
180 * // use your own audio resource here.
181 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
182 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
183 * // Setting the AudioAttributes is important as it identifies the purpose of your
184 * // notification sound.
185 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
186 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
187 * .build());
188 *
189 * NotificationManager mgr = getSystemService(NotificationManager.class);
190 * mgr.createNotificationChannel(channel);
191 * </code></pre>
192 * <p>
193 * When your app receives a new incoming call, it creates a {@link android.app.Notification} for the
194 * incoming call and associates it with your incoming call notification channel. You can specify a
195 * {@link android.app.PendingIntent} on the notification which will launch your full screen
196 * incoming call UI. The notification manager framework will display your notification as a
197 * heads-up notification if the user is actively using the phone. When the user is not using the
198 * phone, your full-screen incoming call UI is used instead.
199 * For example:
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800200 * <pre><code>{@code
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700201 * // Create an intent which triggers your fullscreen incoming call user interface.
202 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
203 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
204 * intent.setClass(context, YourIncomingCallActivity.class);
205 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
206 *
207 * // Build the notification as an ongoing high priority item; this ensures it will show as
208 * // a heads up notification which slides down over top of the current content.
209 * final Notification.Builder builder = new Notification.Builder(context);
210 * builder.setOngoing(true);
211 * builder.setPriority(Notification.PRIORITY_HIGH);
212 *
213 * // Set notification content intent to take user to the fullscreen UI if user taps on the
214 * // notification body.
215 * builder.setContentIntent(pendingIntent);
216 * // Set full screen intent to trigger display of the fullscreen UI when the notification
217 * // manager deems it appropriate.
218 * builder.setFullScreenIntent(pendingIntent, true);
219 *
220 * // Setup notification content.
221 * builder.setSmallIcon( yourIconResourceId );
222 * builder.setContentTitle("Your notification title");
223 * builder.setContentText("Your notification content.");
224 *
225 * // Use builder.addAction(..) to add buttons to answer or reject the call.
226 *
227 * NotificationManager notificationManager = mContext.getSystemService(
228 * NotificationManager.class);
229 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, builder.build());
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800230 * }</pre>
231 * <p>
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800232 */
Santos Cordon2f42b112014-07-19 13:19:37 -0700233public abstract class InCallService extends Service {
Tyler Gunn2ac40102014-08-18 16:23:10 -0700234
235 /**
236 * The {@link Intent} that must be declared as handled by the service.
237 */
238 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700239 public static final String SERVICE_INTERFACE = "android.telecom.InCallService";
Tyler Gunn2ac40102014-08-18 16:23:10 -0700240
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800241 private static final int MSG_SET_IN_CALL_ADAPTER = 1;
242 private static final int MSG_ADD_CALL = 2;
Sailesh Nepal60437932014-04-05 16:44:55 -0700243 private static final int MSG_UPDATE_CALL = 3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700244 private static final int MSG_SET_POST_DIAL_WAIT = 4;
Yorke Lee4af59352015-05-13 14:14:54 -0700245 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 5;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700246 private static final int MSG_BRING_TO_FOREGROUND = 6;
Santos Cordon6c912b72014-11-07 16:05:09 -0800247 private static final int MSG_ON_CAN_ADD_CALL_CHANGED = 7;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800248 private static final int MSG_SILENCE_RINGER = 8;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700249 private static final int MSG_ON_CONNECTION_EVENT = 9;
Hall Liu95d55872017-01-25 17:12:49 -0800250 private static final int MSG_ON_RTT_UPGRADE_REQUEST = 10;
Hall Liu57006aa2017-02-06 10:49:48 -0800251 private static final int MSG_ON_RTT_INITIATION_FAILURE = 11;
Sanket Padawe85291f62017-12-01 13:59:27 -0800252 private static final int MSG_ON_HANDOVER_FAILED = 12;
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800253 private static final int MSG_ON_HANDOVER_COMPLETE = 13;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800254
255 /** Default Handler used to consolidate binder method calls onto a single thread. */
256 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
257 @Override
258 public void handleMessage(Message msg) {
Jay Shrauner5e6162d2014-09-22 20:47:45 -0700259 if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) {
260 return;
261 }
262
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800263 switch (msg.what) {
264 case MSG_SET_IN_CALL_ADAPTER:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800265 String callingPackage = getApplicationContext().getOpPackageName();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800266 mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj), callingPackage,
267 getApplicationContext().getApplicationInfo().targetSdkVersion);
Santos Cordona2492812015-04-15 11:05:16 -0700268 mPhone.addListener(mPhoneListener);
Ihab Awade63fadb2014-07-09 21:52:04 -0700269 onPhoneCreated(mPhone);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800270 break;
271 case MSG_ADD_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700272 mPhone.internalAddCall((ParcelableCall) msg.obj);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800273 break;
Sailesh Nepal60437932014-04-05 16:44:55 -0700274 case MSG_UPDATE_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700275 mPhone.internalUpdateCall((ParcelableCall) msg.obj);
Ihab Awad2f236642014-03-10 15:33:45 -0700276 break;
Ihab Awad2f236642014-03-10 15:33:45 -0700277 case MSG_SET_POST_DIAL_WAIT: {
278 SomeArgs args = (SomeArgs) msg.obj;
279 try {
280 String callId = (String) args.arg1;
281 String remaining = (String) args.arg2;
Ihab Awade63fadb2014-07-09 21:52:04 -0700282 mPhone.internalSetPostDialWait(callId, remaining);
Ihab Awad2f236642014-03-10 15:33:45 -0700283 } finally {
284 args.recycle();
285 }
286 break;
287 }
Yorke Lee4af59352015-05-13 14:14:54 -0700288 case MSG_ON_CALL_AUDIO_STATE_CHANGED:
289 mPhone.internalCallAudioStateChanged((CallAudioState) msg.obj);
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700290 break;
Santos Cordon3534ede2014-05-29 13:07:10 -0700291 case MSG_BRING_TO_FOREGROUND:
Ihab Awade63fadb2014-07-09 21:52:04 -0700292 mPhone.internalBringToForeground(msg.arg1 == 1);
Santos Cordon3534ede2014-05-29 13:07:10 -0700293 break;
Santos Cordon6c912b72014-11-07 16:05:09 -0800294 case MSG_ON_CAN_ADD_CALL_CHANGED:
295 mPhone.internalSetCanAddCall(msg.arg1 == 1);
296 break;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800297 case MSG_SILENCE_RINGER:
298 mPhone.internalSilenceRinger();
299 break;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700300 case MSG_ON_CONNECTION_EVENT: {
301 SomeArgs args = (SomeArgs) msg.obj;
302 try {
303 String callId = (String) args.arg1;
304 String event = (String) args.arg2;
305 Bundle extras = (Bundle) args.arg3;
306 mPhone.internalOnConnectionEvent(callId, event, extras);
307 } finally {
308 args.recycle();
309 }
310 break;
311 }
Hall Liu95d55872017-01-25 17:12:49 -0800312 case MSG_ON_RTT_UPGRADE_REQUEST: {
313 String callId = (String) msg.obj;
314 int requestId = msg.arg1;
315 mPhone.internalOnRttUpgradeRequest(callId, requestId);
316 break;
317 }
Hall Liu57006aa2017-02-06 10:49:48 -0800318 case MSG_ON_RTT_INITIATION_FAILURE: {
319 String callId = (String) msg.obj;
320 int reason = msg.arg1;
321 mPhone.internalOnRttInitiationFailure(callId, reason);
322 break;
323 }
Sanket Padawe85291f62017-12-01 13:59:27 -0800324 case MSG_ON_HANDOVER_FAILED: {
325 String callId = (String) msg.obj;
326 int error = msg.arg1;
327 mPhone.internalOnHandoverFailed(callId, error);
328 break;
329 }
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800330 case MSG_ON_HANDOVER_COMPLETE: {
331 String callId = (String) msg.obj;
332 mPhone.internalOnHandoverComplete(callId);
333 break;
334 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800335 default:
336 break;
337 }
338 }
339 };
340
341 /** Manages the binder calls so that the implementor does not need to deal with it. */
342 private final class InCallServiceBinder extends IInCallService.Stub {
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800343 @Override
344 public void setInCallAdapter(IInCallAdapter inCallAdapter) {
345 mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget();
346 }
347
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800348 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700349 public void addCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700350 mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800351 }
352
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800353 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700354 public void updateCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700355 mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
Ihab Awad2f236642014-03-10 15:33:45 -0700356 }
357
358 @Override
359 public void setPostDial(String callId, String remaining) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700360 // TODO: Unused
Ihab Awad2f236642014-03-10 15:33:45 -0700361 }
362
363 @Override
364 public void setPostDialWait(String callId, String remaining) {
365 SomeArgs args = SomeArgs.obtain();
366 args.arg1 = callId;
367 args.arg2 = remaining;
368 mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
369 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700370
371 @Override
Yorke Lee4af59352015-05-13 14:14:54 -0700372 public void onCallAudioStateChanged(CallAudioState callAudioState) {
373 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, callAudioState).sendToTarget();
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700374 }
Santos Cordon3534ede2014-05-29 13:07:10 -0700375
Santos Cordon3534ede2014-05-29 13:07:10 -0700376 @Override
377 public void bringToForeground(boolean showDialpad) {
378 mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
379 }
Santos Cordon6c912b72014-11-07 16:05:09 -0800380
381 @Override
382 public void onCanAddCallChanged(boolean canAddCall) {
383 mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0)
384 .sendToTarget();
385 }
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800386
387 @Override
388 public void silenceRinger() {
389 mHandler.obtainMessage(MSG_SILENCE_RINGER).sendToTarget();
390 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700391
392 @Override
393 public void onConnectionEvent(String callId, String event, Bundle extras) {
394 SomeArgs args = SomeArgs.obtain();
395 args.arg1 = callId;
396 args.arg2 = event;
397 args.arg3 = extras;
398 mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget();
399 }
Hall Liu95d55872017-01-25 17:12:49 -0800400
401 @Override
402 public void onRttUpgradeRequest(String callId, int id) {
403 mHandler.obtainMessage(MSG_ON_RTT_UPGRADE_REQUEST, id, 0, callId).sendToTarget();
404 }
Hall Liu57006aa2017-02-06 10:49:48 -0800405
406 @Override
407 public void onRttInitiationFailure(String callId, int reason) {
408 mHandler.obtainMessage(MSG_ON_RTT_INITIATION_FAILURE, reason, 0, callId).sendToTarget();
409 }
Sanket Padawe85291f62017-12-01 13:59:27 -0800410
411 @Override
412 public void onHandoverFailed(String callId, int error) {
413 mHandler.obtainMessage(MSG_ON_HANDOVER_FAILED, error, 0, callId).sendToTarget();
414 }
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800415
416 @Override
417 public void onHandoverComplete(String callId) {
418 mHandler.obtainMessage(MSG_ON_HANDOVER_COMPLETE, callId).sendToTarget();
419 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800420 }
421
Santos Cordona2492812015-04-15 11:05:16 -0700422 private Phone.Listener mPhoneListener = new Phone.Listener() {
423 /** ${inheritDoc} */
424 @Override
425 public void onAudioStateChanged(Phone phone, AudioState audioState) {
426 InCallService.this.onAudioStateChanged(audioState);
427 }
428
Yorke Lee4af59352015-05-13 14:14:54 -0700429 public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) {
430 InCallService.this.onCallAudioStateChanged(callAudioState);
431 };
432
Santos Cordona2492812015-04-15 11:05:16 -0700433 /** ${inheritDoc} */
434 @Override
435 public void onBringToForeground(Phone phone, boolean showDialpad) {
436 InCallService.this.onBringToForeground(showDialpad);
437 }
438
439 /** ${inheritDoc} */
440 @Override
441 public void onCallAdded(Phone phone, Call call) {
442 InCallService.this.onCallAdded(call);
443 }
444
445 /** ${inheritDoc} */
446 @Override
447 public void onCallRemoved(Phone phone, Call call) {
448 InCallService.this.onCallRemoved(call);
449 }
450
451 /** ${inheritDoc} */
452 @Override
453 public void onCanAddCallChanged(Phone phone, boolean canAddCall) {
454 InCallService.this.onCanAddCallChanged(canAddCall);
455 }
456
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800457 /** ${inheritDoc} */
458 @Override
459 public void onSilenceRinger(Phone phone) {
460 InCallService.this.onSilenceRinger();
461 }
462
Santos Cordona2492812015-04-15 11:05:16 -0700463 };
464
Ihab Awade63fadb2014-07-09 21:52:04 -0700465 private Phone mPhone;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800466
Santos Cordon2f42b112014-07-19 13:19:37 -0700467 public InCallService() {
468 }
Evan Charlton924748f2014-04-03 08:36:38 -0700469
Santos Cordon2f42b112014-07-19 13:19:37 -0700470 @Override
471 public IBinder onBind(Intent intent) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700472 return new InCallServiceBinder();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800473 }
474
Santos Cordonf30d7e92014-08-26 09:54:33 -0700475 @Override
476 public boolean onUnbind(Intent intent) {
Santos Cordon619b3c02014-09-02 17:13:45 -0700477 if (mPhone != null) {
478 Phone oldPhone = mPhone;
479 mPhone = null;
Santos Cordonf30d7e92014-08-26 09:54:33 -0700480
Santos Cordon619b3c02014-09-02 17:13:45 -0700481 oldPhone.destroy();
Santos Cordona2492812015-04-15 11:05:16 -0700482 // destroy sets all the calls to disconnected if any live ones still exist. Therefore,
483 // it is important to remove the Listener *after* the call to destroy so that
484 // InCallService.on* callbacks are appropriately called.
485 oldPhone.removeListener(mPhoneListener);
486
Santos Cordon619b3c02014-09-02 17:13:45 -0700487 onPhoneDestroyed(oldPhone);
488 }
Santos Cordona2492812015-04-15 11:05:16 -0700489
Santos Cordonf30d7e92014-08-26 09:54:33 -0700490 return false;
491 }
492
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800493 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700494 * Obtain the {@code Phone} associated with this {@code InCallService}.
495 *
496 * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null}
Santos Cordon2f42b112014-07-19 13:19:37 -0700497 * if the {@code InCallService} is not in a state where it has an associated
498 * {@code Phone}.
Santos Cordona2492812015-04-15 11:05:16 -0700499 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700500 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800501 */
Santos Cordona2492812015-04-15 11:05:16 -0700502 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700503 @Deprecated
504 public Phone getPhone() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700505 return mPhone;
Evan Charlton924748f2014-04-03 08:36:38 -0700506 }
507
508 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700509 * Obtains the current list of {@code Call}s to be displayed by this in-call service.
Santos Cordona2492812015-04-15 11:05:16 -0700510 *
511 * @return A list of the relevant {@code Call}s.
512 */
513 public final List<Call> getCalls() {
514 return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls();
515 }
516
517 /**
518 * Returns if the device can support additional calls.
519 *
520 * @return Whether the phone supports adding more calls.
521 */
522 public final boolean canAddCall() {
523 return mPhone == null ? false : mPhone.canAddCall();
524 }
525
526 /**
527 * Obtains the current phone call audio state.
528 *
529 * @return An object encapsulating the audio state. Returns null if the service is not
530 * fully initialized.
Yorke Lee4af59352015-05-13 14:14:54 -0700531 * @deprecated Use {@link #getCallAudioState()} instead.
532 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700533 */
Yorke Lee4af59352015-05-13 14:14:54 -0700534 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700535 public final AudioState getAudioState() {
536 return mPhone == null ? null : mPhone.getAudioState();
537 }
538
539 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700540 * Obtains the current phone call audio state.
541 *
542 * @return An object encapsulating the audio state. Returns null if the service is not
543 * fully initialized.
544 */
545 public final CallAudioState getCallAudioState() {
546 return mPhone == null ? null : mPhone.getCallAudioState();
547 }
548
549 /**
Santos Cordona2492812015-04-15 11:05:16 -0700550 * Sets the microphone mute state. When this request is honored, there will be change to
Yorke Lee4af59352015-05-13 14:14:54 -0700551 * the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700552 *
553 * @param state {@code true} if the microphone should be muted; {@code false} otherwise.
554 */
555 public final void setMuted(boolean state) {
556 if (mPhone != null) {
557 mPhone.setMuted(state);
558 }
559 }
560
561 /**
562 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
Yorke Lee4af59352015-05-13 14:14:54 -0700563 * be change to the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700564 *
565 * @param route The audio route to use.
566 */
567 public final void setAudioRoute(int route) {
568 if (mPhone != null) {
569 mPhone.setAudioRoute(route);
570 }
571 }
572
573 /**
Hall Liua98f58b52017-11-07 17:59:28 -0800574 * Request audio routing to a specific bluetooth device. Calling this method may result in
575 * the device routing audio to a different bluetooth device than the one specified if the
576 * bluetooth stack is unable to route audio to the requested device.
577 * A list of available devices can be obtained via
578 * {@link CallAudioState#getSupportedBluetoothDevices()}
579 *
Hall Liu15392832018-04-02 13:52:57 -0700580 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -0800581 */
Hall Liu15392832018-04-02 13:52:57 -0700582 public final void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -0800583 if (mPhone != null) {
Hall Liu15392832018-04-02 13:52:57 -0700584 mPhone.requestBluetoothAudio(bluetoothDevice.getAddress());
Hall Liua98f58b52017-11-07 17:59:28 -0800585 }
586 }
587
588 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700589 * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience
590 * to start displaying in-call information to the user. Each instance of {@code InCallService}
Santos Cordon2f42b112014-07-19 13:19:37 -0700591 * will have only one {@code Phone}, and this method will be called exactly once in the lifetime
592 * of the {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700593 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700594 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700595 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700596 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Evan Charlton924748f2014-04-03 08:36:38 -0700597 */
Santos Cordona2492812015-04-15 11:05:16 -0700598 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700599 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700600 public void onPhoneCreated(Phone phone) {
601 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800602
603 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700604 * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience
605 * to stop displaying in-call information to the user. This method will be called exactly once
606 * in the lifetime of the {@code InCallService}, and it will always be called after a previous
607 * call to {@link #onPhoneCreated(Phone)}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800608 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700609 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700610 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700611 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800612 */
Santos Cordona2492812015-04-15 11:05:16 -0700613 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700614 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700615 public void onPhoneDestroyed(Phone phone) {
616 }
Andrew Lee50aca232014-07-22 16:41:54 -0700617
618 /**
Santos Cordona2492812015-04-15 11:05:16 -0700619 * Called when the audio state changes.
620 *
621 * @param audioState The new {@link AudioState}.
Yorke Lee4af59352015-05-13 14:14:54 -0700622 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState) instead}.
623 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700624 */
Yorke Lee4af59352015-05-13 14:14:54 -0700625 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700626 public void onAudioStateChanged(AudioState audioState) {
627 }
628
629 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700630 * Called when the audio state changes.
631 *
632 * @param audioState The new {@link CallAudioState}.
633 */
634 public void onCallAudioStateChanged(CallAudioState audioState) {
635 }
636
637 /**
Santos Cordona2492812015-04-15 11:05:16 -0700638 * Called to bring the in-call screen to the foreground. The in-call experience should
639 * respond immediately by coming to the foreground to inform the user of the state of
640 * ongoing {@code Call}s.
641 *
642 * @param showDialpad If true, put up the dialpad when the screen is shown.
643 */
644 public void onBringToForeground(boolean showDialpad) {
645 }
646
647 /**
648 * Called when a {@code Call} has been added to this in-call session. The in-call user
649 * experience should add necessary state listeners to the specified {@code Call} and
650 * immediately start to show the user information about the existence
651 * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will
652 * include this {@code Call}.
653 *
654 * @param call A newly added {@code Call}.
655 */
656 public void onCallAdded(Call call) {
657 }
658
659 /**
660 * Called when a {@code Call} has been removed from this in-call session. The in-call user
661 * experience should remove any state listeners from the specified {@code Call} and
662 * immediately stop displaying any information about this {@code Call}.
663 * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}.
664 *
665 * @param call A newly removed {@code Call}.
666 */
667 public void onCallRemoved(Call call) {
668 }
669
670 /**
671 * Called when the ability to add more calls changes. If the phone cannot
672 * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it
673 * is set to {@code true}. This can be used to control the visibility of UI to add more calls.
674 *
675 * @param canAddCall Indicates whether an additional call can be added.
676 */
677 public void onCanAddCallChanged(boolean canAddCall) {
678 }
679
680 /**
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800681 * Called to silence the ringer if a ringing call exists.
682 */
683 public void onSilenceRinger() {
684 }
685
686 /**
Tyler Gunn06f3fa62016-08-25 09:26:15 -0700687 * Unused; to handle connection events issued by a {@link ConnectionService}, implement the
688 * {@link android.telecom.Call.Callback#onConnectionEvent(Call, String, Bundle)} callback.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700689 * <p>
690 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
691 *
692 * @param call The call the event is associated with.
693 * @param event The event.
694 * @param extras Any associated extras.
695 */
696 public void onConnectionEvent(Call call, String event, Bundle extras) {
697 }
698
699 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700700 * Used to issue commands to the {@link Connection.VideoProvider} associated with a
701 * {@link Call}.
Andrew Lee50aca232014-07-22 16:41:54 -0700702 */
703 public static abstract class VideoCall {
704
Andrew Lee011728f2015-04-23 15:47:06 -0700705 /** @hide */
Aurimas Liutikasd23189b2020-11-10 15:32:51 -0800706 @SuppressWarnings("HiddenAbstractMethod")
Andrew Lee011728f2015-04-23 15:47:06 -0700707 public abstract void destroy();
708
Andrew Lee50aca232014-07-22 16:41:54 -0700709 /**
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700710 * Registers a callback to receive commands and state changes for video calls.
Andrew Lee50aca232014-07-22 16:41:54 -0700711 *
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700712 * @param callback The video call callback.
Andrew Lee50aca232014-07-22 16:41:54 -0700713 */
Andrew Leeda80c872015-04-15 14:09:50 -0700714 public abstract void registerCallback(VideoCall.Callback callback);
715
716 /**
Andrew Lee011728f2015-04-23 15:47:06 -0700717 * Registers a callback to receive commands and state changes for video calls.
718 *
719 * @param callback The video call callback.
720 * @param handler A handler which commands and status changes will be delivered to.
721 */
722 public abstract void registerCallback(VideoCall.Callback callback, Handler handler);
723
724 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700725 * Clears the video call callback set via {@link #registerCallback}.
Tyler Gunn295f5d72015-06-04 11:08:54 -0700726 *
727 * @param callback The video call callback to clear.
Tyler Gunn75958422015-04-15 14:23:42 -0700728 */
Andrew Lee011728f2015-04-23 15:47:06 -0700729 public abstract void unregisterCallback(VideoCall.Callback callback);
Tyler Gunn75958422015-04-15 14:23:42 -0700730
731 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700732 * Sets the camera to be used for the outgoing video.
733 * <p>
734 * Handled by {@link Connection.VideoProvider#onSetCamera(String)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700735 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700736 * @param cameraId The id of the camera (use ids as reported by
737 * {@link CameraManager#getCameraIdList()}).
Andrew Lee50aca232014-07-22 16:41:54 -0700738 */
739 public abstract void setCamera(String cameraId);
740
741 /**
742 * Sets the surface to be used for displaying a preview of what the user's camera is
743 * currently capturing. When video transmission is enabled, this is the video signal which
744 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700745 * <p>
746 * Handled by {@link Connection.VideoProvider#onSetPreviewSurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700747 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700748 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700749 */
750 public abstract void setPreviewSurface(Surface surface);
751
752 /**
753 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700754 * <p>
755 * Handled by {@link Connection.VideoProvider#onSetDisplaySurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700756 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700757 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700758 */
759 public abstract void setDisplaySurface(Surface surface);
760
761 /**
762 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
763 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700764 * <p>
765 * Handled by {@link Connection.VideoProvider#onSetDeviceOrientation(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700766 *
767 * @param rotation The device orientation, in degrees.
768 */
769 public abstract void setDeviceOrientation(int rotation);
770
771 /**
Tyler Gunnc603b462021-06-14 17:24:40 -0700772 * Sets the camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700773 * <p>
774 * Handled by {@link Connection.VideoProvider#onSetZoom(float)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700775 *
Tyler Gunnc603b462021-06-14 17:24:40 -0700776 * @param value The camera zoom ratio; for the current camera, should be a value in the
777 * range defined by
778 * {@link android.hardware.camera2.CameraCharacteristics#CONTROL_ZOOM_RATIO_RANGE}.
Andrew Lee50aca232014-07-22 16:41:54 -0700779 */
780 public abstract void setZoom(float value);
781
782 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700783 * Issues a request to modify the properties of the current video session.
784 * <p>
785 * Example scenarios include: requesting an audio-only call to be upgraded to a
786 * bi-directional video call, turning on or off the user's camera, sending a pause signal
787 * when the {@link InCallService} is no longer the foreground application.
788 * <p>
789 * Handled by
790 * {@link Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700791 *
792 * @param requestProfile The requested call video properties.
793 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700794 public abstract void sendSessionModifyRequest(VideoProfile requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700795
796 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700797 * Provides a response to a request to change the current call video session
798 * properties. This should be called in response to a request the {@link InCallService} has
799 * received via {@link VideoCall.Callback#onSessionModifyRequestReceived}.
800 * <p>
801 * Handled by
802 * {@link Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700803 *
804 * @param responseProfile The response call video properties.
805 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700806 public abstract void sendSessionModifyResponse(VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700807
808 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700809 * Issues a request to the {@link Connection.VideoProvider} to retrieve the capabilities
810 * of the current camera. The current camera is selected using
811 * {@link VideoCall#setCamera(String)}.
812 * <p>
813 * Camera capabilities are reported to the caller via
814 * {@link VideoCall.Callback#onCameraCapabilitiesChanged(VideoProfile.CameraCapabilities)}.
815 * <p>
816 * Handled by {@link Connection.VideoProvider#onRequestCameraCapabilities()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700817 */
818 public abstract void requestCameraCapabilities();
819
820 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700821 * Issues a request to the {@link Connection.VideoProvider} to retrieve the cumulative data
822 * usage for the video component of the current call (in bytes). Data usage is reported
823 * to the caller via {@link VideoCall.Callback#onCallDataUsageChanged}.
824 * <p>
825 * Handled by {@link Connection.VideoProvider#onRequestConnectionDataUsage()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700826 */
827 public abstract void requestCallDataUsage();
828
829 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700830 * Provides the {@link Connection.VideoProvider} with the {@link Uri} of an image to be
831 * displayed to the peer device when the video signal is paused.
832 * <p>
833 * Handled by {@link Connection.VideoProvider#onSetPauseImage(Uri)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700834 *
835 * @param uri URI of image to display.
836 */
Yorke Lee32f24732015-05-12 16:18:03 -0700837 public abstract void setPauseImage(Uri uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700838
839 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700840 * The {@link InCallService} extends this class to provide a means of receiving callbacks
Tyler Gunn295f5d72015-06-04 11:08:54 -0700841 * from the {@link Connection.VideoProvider}.
842 * <p>
Tyler Gunnb702ef82015-05-29 11:51:53 -0700843 * When the {@link InCallService} receives the
844 * {@link Call.Callback#onVideoCallChanged(Call, VideoCall)} callback, it should create an
845 * instance its {@link VideoCall.Callback} implementation and set it on the
846 * {@link VideoCall} using {@link VideoCall#registerCallback(Callback)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700847 */
Andrew Leeda80c872015-04-15 14:09:50 -0700848 public static abstract class Callback {
Andrew Lee50aca232014-07-22 16:41:54 -0700849 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700850 * Called when the {@link Connection.VideoProvider} receives a session modification
Tyler Gunn295f5d72015-06-04 11:08:54 -0700851 * request from the peer device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700852 * <p>
853 * The {@link InCallService} may potentially prompt the user to confirm whether they
854 * wish to accept the request, or decide to automatically accept the request. In either
855 * case the {@link InCallService} should call
856 * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} to indicate the video
857 * profile agreed upon.
858 * <p>
859 * Callback originates from
860 * {@link Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700861 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700862 * @param videoProfile The requested video profile.
Andrew Lee50aca232014-07-22 16:41:54 -0700863 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700864 public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700865
866 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700867 * Called when the {@link Connection.VideoProvider} receives a response to a session
868 * modification request previously sent to the peer device.
869 * <p>
870 * The new video state should not be considered active by the {@link InCallService}
871 * until the {@link Call} video state changes (the
872 * {@link Call.Callback#onDetailsChanged(Call, Call.Details)} callback is triggered
873 * when the video state changes).
874 * <p>
875 * Callback originates from
876 * {@link Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
877 * VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700878 *
879 * @param status Status of the session modify request. Valid values are
Tyler Gunnb702ef82015-05-29 11:51:53 -0700880 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
881 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
882 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
883 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
884 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}.
885 * @param requestedProfile The original request which was sent to the peer device.
886 * @param responseProfile The actual profile changes made by the peer device.
Andrew Lee50aca232014-07-22 16:41:54 -0700887 */
888 public abstract void onSessionModifyResponseReceived(int status,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700889 VideoProfile requestedProfile, VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700890
891 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700892 * Handles events related to the current video session which the {@link InCallService}
893 * may wish to handle. These are separate from requested changes to the session due to
894 * the underlying protocol or connection.
895 * <p>
896 * Callback originates from
897 * {@link Connection.VideoProvider#handleCallSessionEvent(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700898 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700899 * @param event The event. Valid values are:
900 * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE},
901 * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME},
902 * {@link Connection.VideoProvider#SESSION_EVENT_TX_START},
903 * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP},
904 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800905 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY},
906 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_PERMISSION_ERROR}.
Andrew Lee50aca232014-07-22 16:41:54 -0700907 */
908 public abstract void onCallSessionEvent(int event);
909
910 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700911 * Handles a change to the video dimensions from the peer device. This could happen if,
912 * for example, the peer changes orientation of their device, or switches cameras.
913 * <p>
914 * Callback originates from
915 * {@link Connection.VideoProvider#changePeerDimensions(int, int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700916 *
917 * @param width The updated peer video width.
918 * @param height The updated peer video height.
919 */
920 public abstract void onPeerDimensionsChanged(int width, int height);
921
922 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700923 * Handles a change to the video quality.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700924 * <p>
925 * Callback originates from {@link Connection.VideoProvider#changeVideoQuality(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700926 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700927 * @param videoQuality The updated peer video quality. Valid values:
928 * {@link VideoProfile#QUALITY_HIGH},
929 * {@link VideoProfile#QUALITY_MEDIUM},
930 * {@link VideoProfile#QUALITY_LOW},
931 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700932 */
933 public abstract void onVideoQualityChanged(int videoQuality);
934
935 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700936 * Handles an update to the total data used for the current video session.
937 * <p>
938 * Used by the {@link Connection.VideoProvider} in response to
939 * {@link VideoCall#requestCallDataUsage()}. May also be called periodically by the
940 * {@link Connection.VideoProvider}.
941 * <p>
942 * Callback originates from {@link Connection.VideoProvider#setCallDataUsage(long)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700943 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700944 * @param dataUsage The updated data usage (in bytes).
Andrew Lee50aca232014-07-22 16:41:54 -0700945 */
Rekha Kumar07366812015-03-24 16:42:31 -0700946 public abstract void onCallDataUsageChanged(long dataUsage);
Andrew Lee50aca232014-07-22 16:41:54 -0700947
948 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700949 * Handles a change in the capabilities of the currently selected camera.
950 * <p>
951 * Used by the {@link Connection.VideoProvider} in response to
952 * {@link VideoCall#requestCameraCapabilities()}. The {@link Connection.VideoProvider}
953 * may also report the camera capabilities after a call to
954 * {@link VideoCall#setCamera(String)}.
955 * <p>
956 * Callback originates from
957 * {@link Connection.VideoProvider#changeCameraCapabilities(
958 * VideoProfile.CameraCapabilities)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700959 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700960 * @param cameraCapabilities The changed camera capabilities.
Andrew Lee50aca232014-07-22 16:41:54 -0700961 */
Yorke Lee400470f2015-05-12 13:31:25 -0700962 public abstract void onCameraCapabilitiesChanged(
963 VideoProfile.CameraCapabilities cameraCapabilities);
Andrew Lee50aca232014-07-22 16:41:54 -0700964 }
965 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800966}