blob: c365648db8f85399008ea8edf571c424a2223c47 [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"
Sailesh Nepal78f3ba62015-12-28 16:20:56 -080084 * android:permission="android.permission.BIND_INCALL_SERVICE">
Neil Fuller71fbb812015-11-30 09:51:33 +000085 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
Tyler Gunndc6e6c42018-07-03 16:08:17 -070086 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_RINGING"
87 * android:value="true" />
Neil Fuller71fbb812015-11-30 09:51:33 +000088 * <intent-filter>
89 * <action android:name="android.telecom.InCallService"/>
90 * </intent-filter>
91 * </service>
Santos Cordonf2600eb2015-06-22 15:02:20 -070092 * }
93 * </pre>
Tyler Gunnfe39efa2018-02-02 13:18:02 -080094 * <p>
95 * In addition to implementing the {@link InCallService} API, you must also declare an activity in
96 * your manifest which handles the {@link Intent#ACTION_DIAL} intent. The example below illustrates
97 * how this is done:
98 * <pre>
99 * {@code
100 * <activity android:name="your.package.YourDialerActivity"
101 * android:label="@string/yourDialerActivityLabel">
102 * <intent-filter>
103 * <action android:name="android.intent.action.DIAL" />
104 * <category android:name="android.intent.category.DEFAULT" />
105 * </intent-filter>
Tyler Gunn4057d4c2020-01-31 15:03:43 -0800106 * <intent-filter>
107 * <action android:name="android.intent.action.DIAL" />
108 * <category android:name="android.intent.category.DEFAULT" />
109 * <data android:scheme="tel" />
110 * </intent-filter>
Tyler Gunnfe39efa2018-02-02 13:18:02 -0800111 * </activity>
112 * }
113 * </pre>
114 * <p>
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800115 * When a user installs your application and runs it for the first time, you should use the
116 * {@link android.app.role.RoleManager} to prompt the user to see if they would like your app to
117 * be the new default phone app.
118 * <p id="requestRole">
119 * The code below shows how your app can request to become the default phone/dialer app:
120 * <pre>
121 * {@code
122 * private static final int REQUEST_ID = 1;
123 *
124 * public void requestRole() {
125 * RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
126 * Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_DIALER);
127 * startActivityForResult(intent, REQUEST_ID);
128 * }
129 *
130 * &#64;Override
131 * public void onActivityResult(int requestCode, int resultCode, Intent data) {
132 * if (requestCode == REQUEST_ID) {
133 * if (resultCode == android.app.Activity.RESULT_OK) {
134 * // Your app is now the default dialer app
135 * } else {
136 * // Your app is not the default dialer app
137 * }
138 * }
139 * }
Tyler Gunn4057d4c2020-01-31 15:03:43 -0800140 * }
Shuo Qian93273fd2021-02-10 15:12:09 -0800141 *
142 * </pre>
143 * <p id="companionInCallService">
144 * <h3>Access to InCallService for Wearable Devices</h3>
145 * <ol>
146 * If your app is a third-party companion app and wants to access InCallService APIs, what your
147 * app could do are:
148 * <p>
149 * <ol>
150 * <li> Declare MANAGE_ONGOING_CALLS permission in your manifest
151 * <li> Associate with a physical wearable device via the
152 * {@link android.companion.CompanionDeviceManager} API as a companion app. See:
153 * https://developer.android.com/guide/topics/connectivity/companion-device-pairing
154 * <li> Implement this InCallService with BIND_INCALL_SERVICE permission
155 * </ol>
156 * </ol>
157 * <p>
158 *
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800159 * </pre>
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700160 * <p id="incomingCallNotification">
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800161 * <h3>Showing the Incoming Call Notification</h3>
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700162 * When your app receives a new incoming call via {@link InCallService#onCallAdded(Call)}, it is
163 * responsible for displaying an incoming call UI for the incoming call. It should do this using
164 * {@link android.app.NotificationManager} APIs to post a new incoming call notification.
165 * <p>
166 * Where your app declares the meta-data {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING}, it
167 * is responsible for playing the ringtone for incoming calls. Your app should create a
168 * {@link android.app.NotificationChannel} which specifies the desired ringtone. For example:
169 * <pre><code>
170 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
171 * NotificationManager.IMPORTANCE_MAX);
172 * // other channel setup stuff goes here.
173 *
174 * // We'll use the default system ringtone for our incoming call notification channel. You can
175 * // use your own audio resource here.
176 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
177 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
178 * // Setting the AudioAttributes is important as it identifies the purpose of your
179 * // notification sound.
180 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
181 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
182 * .build());
183 *
184 * NotificationManager mgr = getSystemService(NotificationManager.class);
185 * mgr.createNotificationChannel(channel);
186 * </code></pre>
187 * <p>
188 * When your app receives a new incoming call, it creates a {@link android.app.Notification} for the
189 * incoming call and associates it with your incoming call notification channel. You can specify a
190 * {@link android.app.PendingIntent} on the notification which will launch your full screen
191 * incoming call UI. The notification manager framework will display your notification as a
192 * heads-up notification if the user is actively using the phone. When the user is not using the
193 * phone, your full-screen incoming call UI is used instead.
194 * For example:
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800195 * <pre><code>{@code
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700196 * // Create an intent which triggers your fullscreen incoming call user interface.
197 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
198 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
199 * intent.setClass(context, YourIncomingCallActivity.class);
Ashwini Orugantif8191e82021-01-07 12:04:25 -0800200 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_MUTABLE_UNAUDITED);
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700201 *
202 * // Build the notification as an ongoing high priority item; this ensures it will show as
203 * // a heads up notification which slides down over top of the current content.
204 * final Notification.Builder builder = new Notification.Builder(context);
205 * builder.setOngoing(true);
206 * builder.setPriority(Notification.PRIORITY_HIGH);
207 *
208 * // Set notification content intent to take user to the fullscreen UI if user taps on the
209 * // notification body.
210 * builder.setContentIntent(pendingIntent);
211 * // Set full screen intent to trigger display of the fullscreen UI when the notification
212 * // manager deems it appropriate.
213 * builder.setFullScreenIntent(pendingIntent, true);
214 *
215 * // Setup notification content.
216 * builder.setSmallIcon( yourIconResourceId );
217 * builder.setContentTitle("Your notification title");
218 * builder.setContentText("Your notification content.");
219 *
220 * // Use builder.addAction(..) to add buttons to answer or reject the call.
221 *
222 * NotificationManager notificationManager = mContext.getSystemService(
223 * NotificationManager.class);
224 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, builder.build());
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800225 * }</pre>
226 * <p>
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800227 */
Santos Cordon2f42b112014-07-19 13:19:37 -0700228public abstract class InCallService extends Service {
Tyler Gunn2ac40102014-08-18 16:23:10 -0700229
230 /**
231 * The {@link Intent} that must be declared as handled by the service.
232 */
233 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700234 public static final String SERVICE_INTERFACE = "android.telecom.InCallService";
Tyler Gunn2ac40102014-08-18 16:23:10 -0700235
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800236 private static final int MSG_SET_IN_CALL_ADAPTER = 1;
237 private static final int MSG_ADD_CALL = 2;
Sailesh Nepal60437932014-04-05 16:44:55 -0700238 private static final int MSG_UPDATE_CALL = 3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700239 private static final int MSG_SET_POST_DIAL_WAIT = 4;
Yorke Lee4af59352015-05-13 14:14:54 -0700240 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 5;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700241 private static final int MSG_BRING_TO_FOREGROUND = 6;
Santos Cordon6c912b72014-11-07 16:05:09 -0800242 private static final int MSG_ON_CAN_ADD_CALL_CHANGED = 7;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800243 private static final int MSG_SILENCE_RINGER = 8;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700244 private static final int MSG_ON_CONNECTION_EVENT = 9;
Hall Liu95d55872017-01-25 17:12:49 -0800245 private static final int MSG_ON_RTT_UPGRADE_REQUEST = 10;
Hall Liu57006aa2017-02-06 10:49:48 -0800246 private static final int MSG_ON_RTT_INITIATION_FAILURE = 11;
Sanket Padawe85291f62017-12-01 13:59:27 -0800247 private static final int MSG_ON_HANDOVER_FAILED = 12;
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800248 private static final int MSG_ON_HANDOVER_COMPLETE = 13;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800249
250 /** Default Handler used to consolidate binder method calls onto a single thread. */
251 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
252 @Override
253 public void handleMessage(Message msg) {
Jay Shrauner5e6162d2014-09-22 20:47:45 -0700254 if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) {
255 return;
256 }
257
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800258 switch (msg.what) {
259 case MSG_SET_IN_CALL_ADAPTER:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800260 String callingPackage = getApplicationContext().getOpPackageName();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800261 mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj), callingPackage,
262 getApplicationContext().getApplicationInfo().targetSdkVersion);
Santos Cordona2492812015-04-15 11:05:16 -0700263 mPhone.addListener(mPhoneListener);
Ihab Awade63fadb2014-07-09 21:52:04 -0700264 onPhoneCreated(mPhone);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800265 break;
266 case MSG_ADD_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700267 mPhone.internalAddCall((ParcelableCall) msg.obj);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800268 break;
Sailesh Nepal60437932014-04-05 16:44:55 -0700269 case MSG_UPDATE_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700270 mPhone.internalUpdateCall((ParcelableCall) msg.obj);
Ihab Awad2f236642014-03-10 15:33:45 -0700271 break;
Ihab Awad2f236642014-03-10 15:33:45 -0700272 case MSG_SET_POST_DIAL_WAIT: {
273 SomeArgs args = (SomeArgs) msg.obj;
274 try {
275 String callId = (String) args.arg1;
276 String remaining = (String) args.arg2;
Ihab Awade63fadb2014-07-09 21:52:04 -0700277 mPhone.internalSetPostDialWait(callId, remaining);
Ihab Awad2f236642014-03-10 15:33:45 -0700278 } finally {
279 args.recycle();
280 }
281 break;
282 }
Yorke Lee4af59352015-05-13 14:14:54 -0700283 case MSG_ON_CALL_AUDIO_STATE_CHANGED:
284 mPhone.internalCallAudioStateChanged((CallAudioState) msg.obj);
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700285 break;
Santos Cordon3534ede2014-05-29 13:07:10 -0700286 case MSG_BRING_TO_FOREGROUND:
Ihab Awade63fadb2014-07-09 21:52:04 -0700287 mPhone.internalBringToForeground(msg.arg1 == 1);
Santos Cordon3534ede2014-05-29 13:07:10 -0700288 break;
Santos Cordon6c912b72014-11-07 16:05:09 -0800289 case MSG_ON_CAN_ADD_CALL_CHANGED:
290 mPhone.internalSetCanAddCall(msg.arg1 == 1);
291 break;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800292 case MSG_SILENCE_RINGER:
293 mPhone.internalSilenceRinger();
294 break;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700295 case MSG_ON_CONNECTION_EVENT: {
296 SomeArgs args = (SomeArgs) msg.obj;
297 try {
298 String callId = (String) args.arg1;
299 String event = (String) args.arg2;
300 Bundle extras = (Bundle) args.arg3;
301 mPhone.internalOnConnectionEvent(callId, event, extras);
302 } finally {
303 args.recycle();
304 }
305 break;
306 }
Hall Liu95d55872017-01-25 17:12:49 -0800307 case MSG_ON_RTT_UPGRADE_REQUEST: {
308 String callId = (String) msg.obj;
309 int requestId = msg.arg1;
310 mPhone.internalOnRttUpgradeRequest(callId, requestId);
311 break;
312 }
Hall Liu57006aa2017-02-06 10:49:48 -0800313 case MSG_ON_RTT_INITIATION_FAILURE: {
314 String callId = (String) msg.obj;
315 int reason = msg.arg1;
316 mPhone.internalOnRttInitiationFailure(callId, reason);
317 break;
318 }
Sanket Padawe85291f62017-12-01 13:59:27 -0800319 case MSG_ON_HANDOVER_FAILED: {
320 String callId = (String) msg.obj;
321 int error = msg.arg1;
322 mPhone.internalOnHandoverFailed(callId, error);
323 break;
324 }
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800325 case MSG_ON_HANDOVER_COMPLETE: {
326 String callId = (String) msg.obj;
327 mPhone.internalOnHandoverComplete(callId);
328 break;
329 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800330 default:
331 break;
332 }
333 }
334 };
335
336 /** Manages the binder calls so that the implementor does not need to deal with it. */
337 private final class InCallServiceBinder extends IInCallService.Stub {
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800338 @Override
339 public void setInCallAdapter(IInCallAdapter inCallAdapter) {
340 mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget();
341 }
342
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800343 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700344 public void addCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700345 mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800346 }
347
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800348 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700349 public void updateCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700350 mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
Ihab Awad2f236642014-03-10 15:33:45 -0700351 }
352
353 @Override
354 public void setPostDial(String callId, String remaining) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700355 // TODO: Unused
Ihab Awad2f236642014-03-10 15:33:45 -0700356 }
357
358 @Override
359 public void setPostDialWait(String callId, String remaining) {
360 SomeArgs args = SomeArgs.obtain();
361 args.arg1 = callId;
362 args.arg2 = remaining;
363 mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
364 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700365
366 @Override
Yorke Lee4af59352015-05-13 14:14:54 -0700367 public void onCallAudioStateChanged(CallAudioState callAudioState) {
368 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, callAudioState).sendToTarget();
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700369 }
Santos Cordon3534ede2014-05-29 13:07:10 -0700370
Santos Cordon3534ede2014-05-29 13:07:10 -0700371 @Override
372 public void bringToForeground(boolean showDialpad) {
373 mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
374 }
Santos Cordon6c912b72014-11-07 16:05:09 -0800375
376 @Override
377 public void onCanAddCallChanged(boolean canAddCall) {
378 mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0)
379 .sendToTarget();
380 }
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800381
382 @Override
383 public void silenceRinger() {
384 mHandler.obtainMessage(MSG_SILENCE_RINGER).sendToTarget();
385 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700386
387 @Override
388 public void onConnectionEvent(String callId, String event, Bundle extras) {
389 SomeArgs args = SomeArgs.obtain();
390 args.arg1 = callId;
391 args.arg2 = event;
392 args.arg3 = extras;
393 mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget();
394 }
Hall Liu95d55872017-01-25 17:12:49 -0800395
396 @Override
397 public void onRttUpgradeRequest(String callId, int id) {
398 mHandler.obtainMessage(MSG_ON_RTT_UPGRADE_REQUEST, id, 0, callId).sendToTarget();
399 }
Hall Liu57006aa2017-02-06 10:49:48 -0800400
401 @Override
402 public void onRttInitiationFailure(String callId, int reason) {
403 mHandler.obtainMessage(MSG_ON_RTT_INITIATION_FAILURE, reason, 0, callId).sendToTarget();
404 }
Sanket Padawe85291f62017-12-01 13:59:27 -0800405
406 @Override
407 public void onHandoverFailed(String callId, int error) {
408 mHandler.obtainMessage(MSG_ON_HANDOVER_FAILED, error, 0, callId).sendToTarget();
409 }
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800410
411 @Override
412 public void onHandoverComplete(String callId) {
413 mHandler.obtainMessage(MSG_ON_HANDOVER_COMPLETE, callId).sendToTarget();
414 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800415 }
416
Santos Cordona2492812015-04-15 11:05:16 -0700417 private Phone.Listener mPhoneListener = new Phone.Listener() {
418 /** ${inheritDoc} */
419 @Override
420 public void onAudioStateChanged(Phone phone, AudioState audioState) {
421 InCallService.this.onAudioStateChanged(audioState);
422 }
423
Yorke Lee4af59352015-05-13 14:14:54 -0700424 public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) {
425 InCallService.this.onCallAudioStateChanged(callAudioState);
426 };
427
Santos Cordona2492812015-04-15 11:05:16 -0700428 /** ${inheritDoc} */
429 @Override
430 public void onBringToForeground(Phone phone, boolean showDialpad) {
431 InCallService.this.onBringToForeground(showDialpad);
432 }
433
434 /** ${inheritDoc} */
435 @Override
436 public void onCallAdded(Phone phone, Call call) {
437 InCallService.this.onCallAdded(call);
438 }
439
440 /** ${inheritDoc} */
441 @Override
442 public void onCallRemoved(Phone phone, Call call) {
443 InCallService.this.onCallRemoved(call);
444 }
445
446 /** ${inheritDoc} */
447 @Override
448 public void onCanAddCallChanged(Phone phone, boolean canAddCall) {
449 InCallService.this.onCanAddCallChanged(canAddCall);
450 }
451
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800452 /** ${inheritDoc} */
453 @Override
454 public void onSilenceRinger(Phone phone) {
455 InCallService.this.onSilenceRinger();
456 }
457
Santos Cordona2492812015-04-15 11:05:16 -0700458 };
459
Ihab Awade63fadb2014-07-09 21:52:04 -0700460 private Phone mPhone;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800461
Santos Cordon2f42b112014-07-19 13:19:37 -0700462 public InCallService() {
463 }
Evan Charlton924748f2014-04-03 08:36:38 -0700464
Santos Cordon2f42b112014-07-19 13:19:37 -0700465 @Override
466 public IBinder onBind(Intent intent) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700467 return new InCallServiceBinder();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800468 }
469
Santos Cordonf30d7e92014-08-26 09:54:33 -0700470 @Override
471 public boolean onUnbind(Intent intent) {
Santos Cordon619b3c02014-09-02 17:13:45 -0700472 if (mPhone != null) {
473 Phone oldPhone = mPhone;
474 mPhone = null;
Santos Cordonf30d7e92014-08-26 09:54:33 -0700475
Santos Cordon619b3c02014-09-02 17:13:45 -0700476 oldPhone.destroy();
Santos Cordona2492812015-04-15 11:05:16 -0700477 // destroy sets all the calls to disconnected if any live ones still exist. Therefore,
478 // it is important to remove the Listener *after* the call to destroy so that
479 // InCallService.on* callbacks are appropriately called.
480 oldPhone.removeListener(mPhoneListener);
481
Santos Cordon619b3c02014-09-02 17:13:45 -0700482 onPhoneDestroyed(oldPhone);
483 }
Santos Cordona2492812015-04-15 11:05:16 -0700484
Santos Cordonf30d7e92014-08-26 09:54:33 -0700485 return false;
486 }
487
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800488 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700489 * Obtain the {@code Phone} associated with this {@code InCallService}.
490 *
491 * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null}
Santos Cordon2f42b112014-07-19 13:19:37 -0700492 * if the {@code InCallService} is not in a state where it has an associated
493 * {@code Phone}.
Santos Cordona2492812015-04-15 11:05:16 -0700494 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700495 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800496 */
Santos Cordona2492812015-04-15 11:05:16 -0700497 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700498 @Deprecated
499 public Phone getPhone() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700500 return mPhone;
Evan Charlton924748f2014-04-03 08:36:38 -0700501 }
502
503 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700504 * Obtains the current list of {@code Call}s to be displayed by this in-call service.
Santos Cordona2492812015-04-15 11:05:16 -0700505 *
506 * @return A list of the relevant {@code Call}s.
507 */
508 public final List<Call> getCalls() {
509 return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls();
510 }
511
512 /**
513 * Returns if the device can support additional calls.
514 *
515 * @return Whether the phone supports adding more calls.
516 */
517 public final boolean canAddCall() {
518 return mPhone == null ? false : mPhone.canAddCall();
519 }
520
521 /**
522 * Obtains the current phone call audio state.
523 *
524 * @return An object encapsulating the audio state. Returns null if the service is not
525 * fully initialized.
Yorke Lee4af59352015-05-13 14:14:54 -0700526 * @deprecated Use {@link #getCallAudioState()} instead.
527 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700528 */
Yorke Lee4af59352015-05-13 14:14:54 -0700529 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700530 public final AudioState getAudioState() {
531 return mPhone == null ? null : mPhone.getAudioState();
532 }
533
534 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700535 * Obtains the current phone call audio state.
536 *
537 * @return An object encapsulating the audio state. Returns null if the service is not
538 * fully initialized.
539 */
540 public final CallAudioState getCallAudioState() {
541 return mPhone == null ? null : mPhone.getCallAudioState();
542 }
543
544 /**
Santos Cordona2492812015-04-15 11:05:16 -0700545 * Sets the microphone mute state. When this request is honored, there will be change to
Yorke Lee4af59352015-05-13 14:14:54 -0700546 * the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700547 *
548 * @param state {@code true} if the microphone should be muted; {@code false} otherwise.
549 */
550 public final void setMuted(boolean state) {
551 if (mPhone != null) {
552 mPhone.setMuted(state);
553 }
554 }
555
556 /**
557 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
Yorke Lee4af59352015-05-13 14:14:54 -0700558 * be change to the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700559 *
560 * @param route The audio route to use.
561 */
562 public final void setAudioRoute(int route) {
563 if (mPhone != null) {
564 mPhone.setAudioRoute(route);
565 }
566 }
567
568 /**
Hall Liua98f58b52017-11-07 17:59:28 -0800569 * Request audio routing to a specific bluetooth device. Calling this method may result in
570 * the device routing audio to a different bluetooth device than the one specified if the
571 * bluetooth stack is unable to route audio to the requested device.
572 * A list of available devices can be obtained via
573 * {@link CallAudioState#getSupportedBluetoothDevices()}
574 *
Hall Liu15392832018-04-02 13:52:57 -0700575 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -0800576 */
Hall Liu15392832018-04-02 13:52:57 -0700577 public final void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -0800578 if (mPhone != null) {
Hall Liu15392832018-04-02 13:52:57 -0700579 mPhone.requestBluetoothAudio(bluetoothDevice.getAddress());
Hall Liua98f58b52017-11-07 17:59:28 -0800580 }
581 }
582
583 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700584 * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience
585 * to start displaying in-call information to the user. Each instance of {@code InCallService}
Santos Cordon2f42b112014-07-19 13:19:37 -0700586 * will have only one {@code Phone}, and this method will be called exactly once in the lifetime
587 * of the {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700588 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700589 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700590 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700591 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Evan Charlton924748f2014-04-03 08:36:38 -0700592 */
Santos Cordona2492812015-04-15 11:05:16 -0700593 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700594 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700595 public void onPhoneCreated(Phone phone) {
596 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800597
598 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700599 * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience
600 * to stop displaying in-call information to the user. This method will be called exactly once
601 * in the lifetime of the {@code InCallService}, and it will always be called after a previous
602 * call to {@link #onPhoneCreated(Phone)}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800603 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700604 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700605 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700606 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800607 */
Santos Cordona2492812015-04-15 11:05:16 -0700608 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700609 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700610 public void onPhoneDestroyed(Phone phone) {
611 }
Andrew Lee50aca232014-07-22 16:41:54 -0700612
613 /**
Santos Cordona2492812015-04-15 11:05:16 -0700614 * Called when the audio state changes.
615 *
616 * @param audioState The new {@link AudioState}.
Yorke Lee4af59352015-05-13 14:14:54 -0700617 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState) instead}.
618 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700619 */
Yorke Lee4af59352015-05-13 14:14:54 -0700620 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700621 public void onAudioStateChanged(AudioState audioState) {
622 }
623
624 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700625 * Called when the audio state changes.
626 *
627 * @param audioState The new {@link CallAudioState}.
628 */
629 public void onCallAudioStateChanged(CallAudioState audioState) {
630 }
631
632 /**
Santos Cordona2492812015-04-15 11:05:16 -0700633 * Called to bring the in-call screen to the foreground. The in-call experience should
634 * respond immediately by coming to the foreground to inform the user of the state of
635 * ongoing {@code Call}s.
636 *
637 * @param showDialpad If true, put up the dialpad when the screen is shown.
638 */
639 public void onBringToForeground(boolean showDialpad) {
640 }
641
642 /**
643 * Called when a {@code Call} has been added to this in-call session. The in-call user
644 * experience should add necessary state listeners to the specified {@code Call} and
645 * immediately start to show the user information about the existence
646 * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will
647 * include this {@code Call}.
648 *
649 * @param call A newly added {@code Call}.
650 */
651 public void onCallAdded(Call call) {
652 }
653
654 /**
655 * Called when a {@code Call} has been removed from this in-call session. The in-call user
656 * experience should remove any state listeners from the specified {@code Call} and
657 * immediately stop displaying any information about this {@code Call}.
658 * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}.
659 *
660 * @param call A newly removed {@code Call}.
661 */
662 public void onCallRemoved(Call call) {
663 }
664
665 /**
666 * Called when the ability to add more calls changes. If the phone cannot
667 * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it
668 * is set to {@code true}. This can be used to control the visibility of UI to add more calls.
669 *
670 * @param canAddCall Indicates whether an additional call can be added.
671 */
672 public void onCanAddCallChanged(boolean canAddCall) {
673 }
674
675 /**
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800676 * Called to silence the ringer if a ringing call exists.
677 */
678 public void onSilenceRinger() {
679 }
680
681 /**
Tyler Gunn06f3fa62016-08-25 09:26:15 -0700682 * Unused; to handle connection events issued by a {@link ConnectionService}, implement the
683 * {@link android.telecom.Call.Callback#onConnectionEvent(Call, String, Bundle)} callback.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700684 * <p>
685 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
686 *
687 * @param call The call the event is associated with.
688 * @param event The event.
689 * @param extras Any associated extras.
690 */
691 public void onConnectionEvent(Call call, String event, Bundle extras) {
692 }
693
694 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700695 * Used to issue commands to the {@link Connection.VideoProvider} associated with a
696 * {@link Call}.
Andrew Lee50aca232014-07-22 16:41:54 -0700697 */
698 public static abstract class VideoCall {
699
Andrew Lee011728f2015-04-23 15:47:06 -0700700 /** @hide */
Aurimas Liutikas796760c2020-11-10 15:32:51 -0800701 @SuppressWarnings("HiddenAbstractMethod")
Andrew Lee011728f2015-04-23 15:47:06 -0700702 public abstract void destroy();
703
Andrew Lee50aca232014-07-22 16:41:54 -0700704 /**
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700705 * Registers a callback to receive commands and state changes for video calls.
Andrew Lee50aca232014-07-22 16:41:54 -0700706 *
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700707 * @param callback The video call callback.
Andrew Lee50aca232014-07-22 16:41:54 -0700708 */
Andrew Leeda80c872015-04-15 14:09:50 -0700709 public abstract void registerCallback(VideoCall.Callback callback);
710
711 /**
Andrew Lee011728f2015-04-23 15:47:06 -0700712 * Registers a callback to receive commands and state changes for video calls.
713 *
714 * @param callback The video call callback.
715 * @param handler A handler which commands and status changes will be delivered to.
716 */
717 public abstract void registerCallback(VideoCall.Callback callback, Handler handler);
718
719 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700720 * Clears the video call callback set via {@link #registerCallback}.
Tyler Gunn295f5d72015-06-04 11:08:54 -0700721 *
722 * @param callback The video call callback to clear.
Tyler Gunn75958422015-04-15 14:23:42 -0700723 */
Andrew Lee011728f2015-04-23 15:47:06 -0700724 public abstract void unregisterCallback(VideoCall.Callback callback);
Tyler Gunn75958422015-04-15 14:23:42 -0700725
726 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700727 * Sets the camera to be used for the outgoing video.
728 * <p>
729 * Handled by {@link Connection.VideoProvider#onSetCamera(String)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700730 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700731 * @param cameraId The id of the camera (use ids as reported by
732 * {@link CameraManager#getCameraIdList()}).
Andrew Lee50aca232014-07-22 16:41:54 -0700733 */
734 public abstract void setCamera(String cameraId);
735
736 /**
737 * Sets the surface to be used for displaying a preview of what the user's camera is
738 * currently capturing. When video transmission is enabled, this is the video signal which
739 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700740 * <p>
741 * Handled by {@link Connection.VideoProvider#onSetPreviewSurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700742 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700743 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700744 */
745 public abstract void setPreviewSurface(Surface surface);
746
747 /**
748 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700749 * <p>
750 * Handled by {@link Connection.VideoProvider#onSetDisplaySurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700751 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700752 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700753 */
754 public abstract void setDisplaySurface(Surface surface);
755
756 /**
757 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
758 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700759 * <p>
760 * Handled by {@link Connection.VideoProvider#onSetDeviceOrientation(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700761 *
762 * @param rotation The device orientation, in degrees.
763 */
764 public abstract void setDeviceOrientation(int rotation);
765
766 /**
Tyler Gunnc603b462021-06-14 17:24:40 -0700767 * Sets the camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700768 * <p>
769 * Handled by {@link Connection.VideoProvider#onSetZoom(float)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700770 *
Tyler Gunnc603b462021-06-14 17:24:40 -0700771 * @param value The camera zoom ratio; for the current camera, should be a value in the
772 * range defined by
773 * {@link android.hardware.camera2.CameraCharacteristics#CONTROL_ZOOM_RATIO_RANGE}.
Andrew Lee50aca232014-07-22 16:41:54 -0700774 */
775 public abstract void setZoom(float value);
776
777 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700778 * Issues a request to modify the properties of the current video session.
779 * <p>
780 * Example scenarios include: requesting an audio-only call to be upgraded to a
781 * bi-directional video call, turning on or off the user's camera, sending a pause signal
782 * when the {@link InCallService} is no longer the foreground application.
783 * <p>
784 * Handled by
785 * {@link Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700786 *
787 * @param requestProfile The requested call video properties.
788 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700789 public abstract void sendSessionModifyRequest(VideoProfile requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700790
791 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700792 * Provides a response to a request to change the current call video session
793 * properties. This should be called in response to a request the {@link InCallService} has
794 * received via {@link VideoCall.Callback#onSessionModifyRequestReceived}.
795 * <p>
796 * Handled by
797 * {@link Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700798 *
799 * @param responseProfile The response call video properties.
800 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700801 public abstract void sendSessionModifyResponse(VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700802
803 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700804 * Issues a request to the {@link Connection.VideoProvider} to retrieve the capabilities
805 * of the current camera. The current camera is selected using
806 * {@link VideoCall#setCamera(String)}.
807 * <p>
808 * Camera capabilities are reported to the caller via
809 * {@link VideoCall.Callback#onCameraCapabilitiesChanged(VideoProfile.CameraCapabilities)}.
810 * <p>
811 * Handled by {@link Connection.VideoProvider#onRequestCameraCapabilities()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700812 */
813 public abstract void requestCameraCapabilities();
814
815 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700816 * Issues a request to the {@link Connection.VideoProvider} to retrieve the cumulative data
817 * usage for the video component of the current call (in bytes). Data usage is reported
818 * to the caller via {@link VideoCall.Callback#onCallDataUsageChanged}.
819 * <p>
820 * Handled by {@link Connection.VideoProvider#onRequestConnectionDataUsage()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700821 */
822 public abstract void requestCallDataUsage();
823
824 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700825 * Provides the {@link Connection.VideoProvider} with the {@link Uri} of an image to be
826 * displayed to the peer device when the video signal is paused.
827 * <p>
828 * Handled by {@link Connection.VideoProvider#onSetPauseImage(Uri)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700829 *
830 * @param uri URI of image to display.
831 */
Yorke Lee32f24732015-05-12 16:18:03 -0700832 public abstract void setPauseImage(Uri uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700833
834 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700835 * The {@link InCallService} extends this class to provide a means of receiving callbacks
Tyler Gunn295f5d72015-06-04 11:08:54 -0700836 * from the {@link Connection.VideoProvider}.
837 * <p>
Tyler Gunnb702ef82015-05-29 11:51:53 -0700838 * When the {@link InCallService} receives the
839 * {@link Call.Callback#onVideoCallChanged(Call, VideoCall)} callback, it should create an
840 * instance its {@link VideoCall.Callback} implementation and set it on the
841 * {@link VideoCall} using {@link VideoCall#registerCallback(Callback)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700842 */
Andrew Leeda80c872015-04-15 14:09:50 -0700843 public static abstract class Callback {
Andrew Lee50aca232014-07-22 16:41:54 -0700844 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700845 * Called when the {@link Connection.VideoProvider} receives a session modification
Tyler Gunn295f5d72015-06-04 11:08:54 -0700846 * request from the peer device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700847 * <p>
848 * The {@link InCallService} may potentially prompt the user to confirm whether they
849 * wish to accept the request, or decide to automatically accept the request. In either
850 * case the {@link InCallService} should call
851 * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} to indicate the video
852 * profile agreed upon.
853 * <p>
854 * Callback originates from
855 * {@link Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700856 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700857 * @param videoProfile The requested video profile.
Andrew Lee50aca232014-07-22 16:41:54 -0700858 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700859 public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700860
861 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700862 * Called when the {@link Connection.VideoProvider} receives a response to a session
863 * modification request previously sent to the peer device.
864 * <p>
865 * The new video state should not be considered active by the {@link InCallService}
866 * until the {@link Call} video state changes (the
867 * {@link Call.Callback#onDetailsChanged(Call, Call.Details)} callback is triggered
868 * when the video state changes).
869 * <p>
870 * Callback originates from
871 * {@link Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
872 * VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700873 *
874 * @param status Status of the session modify request. Valid values are
Tyler Gunnb702ef82015-05-29 11:51:53 -0700875 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
876 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
877 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
878 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
879 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}.
880 * @param requestedProfile The original request which was sent to the peer device.
881 * @param responseProfile The actual profile changes made by the peer device.
Andrew Lee50aca232014-07-22 16:41:54 -0700882 */
883 public abstract void onSessionModifyResponseReceived(int status,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700884 VideoProfile requestedProfile, VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700885
886 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700887 * Handles events related to the current video session which the {@link InCallService}
888 * may wish to handle. These are separate from requested changes to the session due to
889 * the underlying protocol or connection.
890 * <p>
891 * Callback originates from
892 * {@link Connection.VideoProvider#handleCallSessionEvent(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700893 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700894 * @param event The event. Valid values are:
895 * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE},
896 * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME},
897 * {@link Connection.VideoProvider#SESSION_EVENT_TX_START},
898 * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP},
899 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800900 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY},
901 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_PERMISSION_ERROR}.
Andrew Lee50aca232014-07-22 16:41:54 -0700902 */
903 public abstract void onCallSessionEvent(int event);
904
905 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700906 * Handles a change to the video dimensions from the peer device. This could happen if,
907 * for example, the peer changes orientation of their device, or switches cameras.
908 * <p>
909 * Callback originates from
910 * {@link Connection.VideoProvider#changePeerDimensions(int, int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700911 *
912 * @param width The updated peer video width.
913 * @param height The updated peer video height.
914 */
915 public abstract void onPeerDimensionsChanged(int width, int height);
916
917 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700918 * Handles a change to the video quality.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700919 * <p>
920 * Callback originates from {@link Connection.VideoProvider#changeVideoQuality(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700921 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700922 * @param videoQuality The updated peer video quality. Valid values:
923 * {@link VideoProfile#QUALITY_HIGH},
924 * {@link VideoProfile#QUALITY_MEDIUM},
925 * {@link VideoProfile#QUALITY_LOW},
926 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700927 */
928 public abstract void onVideoQualityChanged(int videoQuality);
929
930 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700931 * Handles an update to the total data used for the current video session.
932 * <p>
933 * Used by the {@link Connection.VideoProvider} in response to
934 * {@link VideoCall#requestCallDataUsage()}. May also be called periodically by the
935 * {@link Connection.VideoProvider}.
936 * <p>
937 * Callback originates from {@link Connection.VideoProvider#setCallDataUsage(long)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700938 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700939 * @param dataUsage The updated data usage (in bytes).
Andrew Lee50aca232014-07-22 16:41:54 -0700940 */
Rekha Kumar07366812015-03-24 16:42:31 -0700941 public abstract void onCallDataUsageChanged(long dataUsage);
Andrew Lee50aca232014-07-22 16:41:54 -0700942
943 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700944 * Handles a change in the capabilities of the currently selected camera.
945 * <p>
946 * Used by the {@link Connection.VideoProvider} in response to
947 * {@link VideoCall#requestCameraCapabilities()}. The {@link Connection.VideoProvider}
948 * may also report the camera capabilities after a call to
949 * {@link VideoCall#setCamera(String)}.
950 * <p>
951 * Callback originates from
952 * {@link Connection.VideoProvider#changeCameraCapabilities(
953 * VideoProfile.CameraCapabilities)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700954 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700955 * @param cameraCapabilities The changed camera capabilities.
Andrew Lee50aca232014-07-22 16:41:54 -0700956 */
Yorke Lee400470f2015-05-12 13:31:25 -0700957 public abstract void onCameraCapabilitiesChanged(
958 VideoProfile.CameraCapabilities cameraCapabilities);
Andrew Lee50aca232014-07-22 16:41:54 -0700959 }
960 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800961}