blob: 64a86db383961910e7237ee95a150a0c64f49e61 [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;
Tyler Gunn8f360d82022-06-22 12:56:25 -070025import android.content.ComponentName;
Santos Cordon2f42b112014-07-19 13:19:37 -070026import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070027import android.hardware.camera2.CameraManager;
Yorke Lee32f24732015-05-12 16:18:03 -070028import android.net.Uri;
Tyler Gunn876dbfb2016-03-14 15:18:07 -070029import android.os.Bundle;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080030import android.os.Handler;
31import android.os.IBinder;
32import android.os.Looper;
33import android.os.Message;
Andrew Lee50aca232014-07-22 16:41:54 -070034import android.view.Surface;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080035
Ihab Awad2f236642014-03-10 15:33:45 -070036import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070037import com.android.internal.telecom.IInCallAdapter;
38import com.android.internal.telecom.IInCallService;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080039
Santos Cordona2492812015-04-15 11:05:16 -070040import java.util.Collections;
41import java.util.List;
Andrew Lee50aca232014-07-22 16:41:54 -070042
Sailesh Nepalab5d2822014-03-08 18:01:06 -080043/**
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -080044 * This service is implemented by an app that wishes to provide functionality for managing
45 * phone calls.
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -080046 * <h2>Becoming the Default Phone App</h2>
Tyler Gunn556d2402019-04-10 08:59:43 -070047 * 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 -080048 * in a call. It also provides the user with a means to initiate calls and see a history of calls
49 * on their device. A device is bundled with a system provided default dialer/phone app. The user
50 * may choose a single app to take over this role from the system app. An app which wishes to
Tyler Gunn8f360d82022-06-22 12:56:25 -070051 * fulfill this role uses the {@link android.app.role.RoleManager} to request that they fill the
Tyler Gunn4057d4c2020-01-31 15:03:43 -080052 * {@link android.app.role.RoleManager#ROLE_DIALER} role.
Tyler Gunn556d2402019-04-10 08:59:43 -070053 * <p>
Tyler Gunn4057d4c2020-01-31 15:03:43 -080054 * The default phone app provides a user interface while the device is in a call, and the device is
55 * not in car mode (i.e. {@link UiModeManager#getCurrentModeType()} is not
56 * {@link android.content.res.Configuration#UI_MODE_TYPE_CAR}).
57 * <p>
58 * In order to fill the {@link android.app.role.RoleManager#ROLE_DIALER} role, an app must meet a
59 * number of requirements:
60 * <ul>
61 * <li>It must handle the {@link Intent#ACTION_DIAL} intent. This means the app must provide
62 * a dial pad UI for the user to initiate outgoing calls.</li>
63 * <li>It must fully implement the {@link InCallService} API and provide both an incoming call
64 * UI, as well as an ongoing call UI.</li>
65 * </ul>
66 * <p>
Tyler Gunn8f360d82022-06-22 12:56:25 -070067 * Note: If the app filling the {@link android.app.role.RoleManager#ROLE_DIALER} returns a
68 * {@code null} {@link InCallService} during binding, the Telecom framework will automatically fall
69 * back to using the dialer app preloaded on the device. The system will display a notification to
70 * the user to let them know that their call was continued using the preloaded dialer app. Your
71 * app should never return a {@code null} binding; doing so means it does not fulfil the
72 * requirements of {@link android.app.role.RoleManager#ROLE_DIALER}.
Tyler Gunn4057d4c2020-01-31 15:03:43 -080073 * <p>
Tyler Gunn8f360d82022-06-22 12:56:25 -070074 * Note: If your app fills {@link android.app.role.RoleManager#ROLE_DIALER} and makes changes at
75 * runtime which cause it to no longer fulfil the requirements of this role,
76 * {@link android.app.role.RoleManager} will automatically remove your app from the role and close
77 * your app. For example, if you use
78 * {@link android.content.pm.PackageManager#setComponentEnabledSetting(ComponentName, int, int)} to
79 * programmatically disable the {@link InCallService} your app declares in its manifest, your app
80 * will no longer fulfil the requirements expected of
81 * {@link android.app.role.RoleManager#ROLE_DIALER}.
82 * <p>
83 * The preloaded dialer will ALWAYS be used when the user places an emergency call, even if your
Tyler Gunn272fd212021-10-12 09:22:24 -070084 * app fills the {@link android.app.role.RoleManager#ROLE_DIALER} role. To ensure an optimal
85 * experience when placing an emergency call, the default dialer should ALWAYS use
86 * {@link android.telecom.TelecomManager#placeCall(Uri, Bundle)} to place calls (including
87 * emergency calls). This ensures that the platform is able to verify that the request came from
88 * the default dialer. If a non-preloaded dialer app uses {@link Intent#ACTION_CALL} to place an
89 * emergency call, it will be raised to the preloaded dialer app using {@link Intent#ACTION_DIAL}
90 * for confirmation; this is a suboptimal user experience.
Santos Cordonf2600eb2015-06-22 15:02:20 -070091 * <p>
92 * Below is an example manifest registration for an {@code InCallService}. The meta-data
Tyler Gunndc6e6c42018-07-03 16:08:17 -070093 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_UI} indicates that this particular
Santos Cordonf2600eb2015-06-22 15:02:20 -070094 * {@code InCallService} implementation intends to replace the built-in in-call UI.
Tyler Gunndc6e6c42018-07-03 16:08:17 -070095 * The meta-data {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} indicates that this
96 * {@link InCallService} will play the ringtone for incoming calls. See
97 * <a href="#incomingCallNotification">below</a> for more information on showing the incoming call
98 * UI and playing the ringtone in your app.
Santos Cordonf2600eb2015-06-22 15:02:20 -070099 * <pre>
100 * {@code
Neil Fuller71fbb812015-11-30 09:51:33 +0000101 * <service android:name="your.package.YourInCallServiceImplementation"
Tyler Gunn84421d72021-09-03 14:05:37 -0700102 * android:permission="android.permission.BIND_INCALL_SERVICE"
103 * android:exported="true">
Neil Fuller71fbb812015-11-30 09:51:33 +0000104 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700105 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_RINGING"
106 * android:value="true" />
Neil Fuller71fbb812015-11-30 09:51:33 +0000107 * <intent-filter>
108 * <action android:name="android.telecom.InCallService"/>
109 * </intent-filter>
110 * </service>
Santos Cordonf2600eb2015-06-22 15:02:20 -0700111 * }
112 * </pre>
Tyler Gunn84421d72021-09-03 14:05:37 -0700113 *
114 * <em>Note: You should NOT mark your {@link InCallService} with the attribute
115 * {@code android:exported="false"}; doing so can result in a failure to bind to your implementation
116 * during calls.</em>
Tyler Gunnfe39efa2018-02-02 13:18:02 -0800117 * <p>
118 * In addition to implementing the {@link InCallService} API, you must also declare an activity in
119 * your manifest which handles the {@link Intent#ACTION_DIAL} intent. The example below illustrates
120 * how this is done:
121 * <pre>
122 * {@code
123 * <activity android:name="your.package.YourDialerActivity"
124 * android:label="@string/yourDialerActivityLabel">
125 * <intent-filter>
126 * <action android:name="android.intent.action.DIAL" />
127 * <category android:name="android.intent.category.DEFAULT" />
128 * </intent-filter>
Tyler Gunn4057d4c2020-01-31 15:03:43 -0800129 * <intent-filter>
130 * <action android:name="android.intent.action.DIAL" />
131 * <category android:name="android.intent.category.DEFAULT" />
132 * <data android:scheme="tel" />
133 * </intent-filter>
Tyler Gunnfe39efa2018-02-02 13:18:02 -0800134 * </activity>
135 * }
136 * </pre>
137 * <p>
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800138 * When a user installs your application and runs it for the first time, you should use the
139 * {@link android.app.role.RoleManager} to prompt the user to see if they would like your app to
140 * be the new default phone app.
141 * <p id="requestRole">
142 * The code below shows how your app can request to become the default phone/dialer app:
143 * <pre>
144 * {@code
145 * private static final int REQUEST_ID = 1;
146 *
147 * public void requestRole() {
148 * RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
149 * Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_DIALER);
150 * startActivityForResult(intent, REQUEST_ID);
151 * }
152 *
153 * &#64;Override
154 * public void onActivityResult(int requestCode, int resultCode, Intent data) {
155 * if (requestCode == REQUEST_ID) {
156 * if (resultCode == android.app.Activity.RESULT_OK) {
157 * // Your app is now the default dialer app
158 * } else {
159 * // Your app is not the default dialer app
160 * }
161 * }
162 * }
Tyler Gunn4057d4c2020-01-31 15:03:43 -0800163 * }
Shuo Qian93273fd2021-02-10 15:12:09 -0800164 *
165 * </pre>
166 * <p id="companionInCallService">
167 * <h3>Access to InCallService for Wearable Devices</h3>
168 * <ol>
169 * If your app is a third-party companion app and wants to access InCallService APIs, what your
170 * app could do are:
171 * <p>
172 * <ol>
173 * <li> Declare MANAGE_ONGOING_CALLS permission in your manifest
174 * <li> Associate with a physical wearable device via the
175 * {@link android.companion.CompanionDeviceManager} API as a companion app. See:
176 * https://developer.android.com/guide/topics/connectivity/companion-device-pairing
177 * <li> Implement this InCallService with BIND_INCALL_SERVICE permission
178 * </ol>
179 * </ol>
180 * <p>
181 *
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800182 * </pre>
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700183 * <p id="incomingCallNotification">
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800184 * <h3>Showing the Incoming Call Notification</h3>
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700185 * When your app receives a new incoming call via {@link InCallService#onCallAdded(Call)}, it is
186 * responsible for displaying an incoming call UI for the incoming call. It should do this using
187 * {@link android.app.NotificationManager} APIs to post a new incoming call notification.
188 * <p>
189 * Where your app declares the meta-data {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING}, it
190 * is responsible for playing the ringtone for incoming calls. Your app should create a
191 * {@link android.app.NotificationChannel} which specifies the desired ringtone. For example:
192 * <pre><code>
193 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
194 * NotificationManager.IMPORTANCE_MAX);
195 * // other channel setup stuff goes here.
196 *
197 * // We'll use the default system ringtone for our incoming call notification channel. You can
198 * // use your own audio resource here.
199 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
200 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
201 * // Setting the AudioAttributes is important as it identifies the purpose of your
202 * // notification sound.
203 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
204 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
205 * .build());
206 *
207 * NotificationManager mgr = getSystemService(NotificationManager.class);
208 * mgr.createNotificationChannel(channel);
209 * </code></pre>
210 * <p>
211 * When your app receives a new incoming call, it creates a {@link android.app.Notification} for the
212 * incoming call and associates it with your incoming call notification channel. You can specify a
213 * {@link android.app.PendingIntent} on the notification which will launch your full screen
214 * incoming call UI. The notification manager framework will display your notification as a
215 * heads-up notification if the user is actively using the phone. When the user is not using the
216 * phone, your full-screen incoming call UI is used instead.
217 * For example:
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800218 * <pre><code>{@code
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700219 * // Create an intent which triggers your fullscreen incoming call user interface.
220 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
221 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
222 * intent.setClass(context, YourIncomingCallActivity.class);
Ashwini Orugantif8191e82021-01-07 12:04:25 -0800223 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_MUTABLE_UNAUDITED);
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700224 *
225 * // Build the notification as an ongoing high priority item; this ensures it will show as
226 * // a heads up notification which slides down over top of the current content.
227 * final Notification.Builder builder = new Notification.Builder(context);
228 * builder.setOngoing(true);
229 * builder.setPriority(Notification.PRIORITY_HIGH);
230 *
231 * // Set notification content intent to take user to the fullscreen UI if user taps on the
232 * // notification body.
233 * builder.setContentIntent(pendingIntent);
234 * // Set full screen intent to trigger display of the fullscreen UI when the notification
235 * // manager deems it appropriate.
236 * builder.setFullScreenIntent(pendingIntent, true);
237 *
238 * // Setup notification content.
239 * builder.setSmallIcon( yourIconResourceId );
240 * builder.setContentTitle("Your notification title");
241 * builder.setContentText("Your notification content.");
242 *
243 * // Use builder.addAction(..) to add buttons to answer or reject the call.
244 *
245 * NotificationManager notificationManager = mContext.getSystemService(
246 * NotificationManager.class);
247 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, builder.build());
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800248 * }</pre>
249 * <p>
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800250 */
Santos Cordon2f42b112014-07-19 13:19:37 -0700251public abstract class InCallService extends Service {
Tyler Gunn2ac40102014-08-18 16:23:10 -0700252
253 /**
254 * The {@link Intent} that must be declared as handled by the service.
255 */
256 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700257 public static final String SERVICE_INTERFACE = "android.telecom.InCallService";
Tyler Gunn2ac40102014-08-18 16:23:10 -0700258
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800259 private static final int MSG_SET_IN_CALL_ADAPTER = 1;
260 private static final int MSG_ADD_CALL = 2;
Sailesh Nepal60437932014-04-05 16:44:55 -0700261 private static final int MSG_UPDATE_CALL = 3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700262 private static final int MSG_SET_POST_DIAL_WAIT = 4;
Yorke Lee4af59352015-05-13 14:14:54 -0700263 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 5;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700264 private static final int MSG_BRING_TO_FOREGROUND = 6;
Santos Cordon6c912b72014-11-07 16:05:09 -0800265 private static final int MSG_ON_CAN_ADD_CALL_CHANGED = 7;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800266 private static final int MSG_SILENCE_RINGER = 8;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700267 private static final int MSG_ON_CONNECTION_EVENT = 9;
Hall Liu95d55872017-01-25 17:12:49 -0800268 private static final int MSG_ON_RTT_UPGRADE_REQUEST = 10;
Hall Liu57006aa2017-02-06 10:49:48 -0800269 private static final int MSG_ON_RTT_INITIATION_FAILURE = 11;
Sanket Padawe85291f62017-12-01 13:59:27 -0800270 private static final int MSG_ON_HANDOVER_FAILED = 12;
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800271 private static final int MSG_ON_HANDOVER_COMPLETE = 13;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800272
273 /** Default Handler used to consolidate binder method calls onto a single thread. */
274 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
275 @Override
276 public void handleMessage(Message msg) {
Jay Shrauner5e6162d2014-09-22 20:47:45 -0700277 if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) {
278 return;
279 }
280
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800281 switch (msg.what) {
282 case MSG_SET_IN_CALL_ADAPTER:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800283 String callingPackage = getApplicationContext().getOpPackageName();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800284 mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj), callingPackage,
285 getApplicationContext().getApplicationInfo().targetSdkVersion);
Santos Cordona2492812015-04-15 11:05:16 -0700286 mPhone.addListener(mPhoneListener);
Ihab Awade63fadb2014-07-09 21:52:04 -0700287 onPhoneCreated(mPhone);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800288 break;
289 case MSG_ADD_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700290 mPhone.internalAddCall((ParcelableCall) msg.obj);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800291 break;
Sailesh Nepal60437932014-04-05 16:44:55 -0700292 case MSG_UPDATE_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700293 mPhone.internalUpdateCall((ParcelableCall) msg.obj);
Ihab Awad2f236642014-03-10 15:33:45 -0700294 break;
Ihab Awad2f236642014-03-10 15:33:45 -0700295 case MSG_SET_POST_DIAL_WAIT: {
296 SomeArgs args = (SomeArgs) msg.obj;
297 try {
298 String callId = (String) args.arg1;
299 String remaining = (String) args.arg2;
Ihab Awade63fadb2014-07-09 21:52:04 -0700300 mPhone.internalSetPostDialWait(callId, remaining);
Ihab Awad2f236642014-03-10 15:33:45 -0700301 } finally {
302 args.recycle();
303 }
304 break;
305 }
Yorke Lee4af59352015-05-13 14:14:54 -0700306 case MSG_ON_CALL_AUDIO_STATE_CHANGED:
307 mPhone.internalCallAudioStateChanged((CallAudioState) msg.obj);
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700308 break;
Santos Cordon3534ede2014-05-29 13:07:10 -0700309 case MSG_BRING_TO_FOREGROUND:
Ihab Awade63fadb2014-07-09 21:52:04 -0700310 mPhone.internalBringToForeground(msg.arg1 == 1);
Santos Cordon3534ede2014-05-29 13:07:10 -0700311 break;
Santos Cordon6c912b72014-11-07 16:05:09 -0800312 case MSG_ON_CAN_ADD_CALL_CHANGED:
313 mPhone.internalSetCanAddCall(msg.arg1 == 1);
314 break;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800315 case MSG_SILENCE_RINGER:
316 mPhone.internalSilenceRinger();
317 break;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700318 case MSG_ON_CONNECTION_EVENT: {
319 SomeArgs args = (SomeArgs) msg.obj;
320 try {
321 String callId = (String) args.arg1;
322 String event = (String) args.arg2;
323 Bundle extras = (Bundle) args.arg3;
324 mPhone.internalOnConnectionEvent(callId, event, extras);
325 } finally {
326 args.recycle();
327 }
328 break;
329 }
Hall Liu95d55872017-01-25 17:12:49 -0800330 case MSG_ON_RTT_UPGRADE_REQUEST: {
331 String callId = (String) msg.obj;
332 int requestId = msg.arg1;
333 mPhone.internalOnRttUpgradeRequest(callId, requestId);
334 break;
335 }
Hall Liu57006aa2017-02-06 10:49:48 -0800336 case MSG_ON_RTT_INITIATION_FAILURE: {
337 String callId = (String) msg.obj;
338 int reason = msg.arg1;
339 mPhone.internalOnRttInitiationFailure(callId, reason);
340 break;
341 }
Sanket Padawe85291f62017-12-01 13:59:27 -0800342 case MSG_ON_HANDOVER_FAILED: {
343 String callId = (String) msg.obj;
344 int error = msg.arg1;
345 mPhone.internalOnHandoverFailed(callId, error);
346 break;
347 }
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800348 case MSG_ON_HANDOVER_COMPLETE: {
349 String callId = (String) msg.obj;
350 mPhone.internalOnHandoverComplete(callId);
351 break;
352 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800353 default:
354 break;
355 }
356 }
357 };
358
359 /** Manages the binder calls so that the implementor does not need to deal with it. */
360 private final class InCallServiceBinder extends IInCallService.Stub {
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800361 @Override
362 public void setInCallAdapter(IInCallAdapter inCallAdapter) {
363 mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget();
364 }
365
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800366 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700367 public void addCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700368 mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800369 }
370
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800371 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700372 public void updateCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700373 mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
Ihab Awad2f236642014-03-10 15:33:45 -0700374 }
375
376 @Override
377 public void setPostDial(String callId, String remaining) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700378 // TODO: Unused
Ihab Awad2f236642014-03-10 15:33:45 -0700379 }
380
381 @Override
382 public void setPostDialWait(String callId, String remaining) {
383 SomeArgs args = SomeArgs.obtain();
384 args.arg1 = callId;
385 args.arg2 = remaining;
386 mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
387 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700388
389 @Override
Yorke Lee4af59352015-05-13 14:14:54 -0700390 public void onCallAudioStateChanged(CallAudioState callAudioState) {
391 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, callAudioState).sendToTarget();
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700392 }
Santos Cordon3534ede2014-05-29 13:07:10 -0700393
Santos Cordon3534ede2014-05-29 13:07:10 -0700394 @Override
395 public void bringToForeground(boolean showDialpad) {
396 mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
397 }
Santos Cordon6c912b72014-11-07 16:05:09 -0800398
399 @Override
400 public void onCanAddCallChanged(boolean canAddCall) {
401 mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0)
402 .sendToTarget();
403 }
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800404
405 @Override
406 public void silenceRinger() {
407 mHandler.obtainMessage(MSG_SILENCE_RINGER).sendToTarget();
408 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700409
410 @Override
411 public void onConnectionEvent(String callId, String event, Bundle extras) {
412 SomeArgs args = SomeArgs.obtain();
413 args.arg1 = callId;
414 args.arg2 = event;
415 args.arg3 = extras;
416 mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget();
417 }
Hall Liu95d55872017-01-25 17:12:49 -0800418
419 @Override
420 public void onRttUpgradeRequest(String callId, int id) {
421 mHandler.obtainMessage(MSG_ON_RTT_UPGRADE_REQUEST, id, 0, callId).sendToTarget();
422 }
Hall Liu57006aa2017-02-06 10:49:48 -0800423
424 @Override
425 public void onRttInitiationFailure(String callId, int reason) {
426 mHandler.obtainMessage(MSG_ON_RTT_INITIATION_FAILURE, reason, 0, callId).sendToTarget();
427 }
Sanket Padawe85291f62017-12-01 13:59:27 -0800428
429 @Override
430 public void onHandoverFailed(String callId, int error) {
431 mHandler.obtainMessage(MSG_ON_HANDOVER_FAILED, error, 0, callId).sendToTarget();
432 }
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800433
434 @Override
435 public void onHandoverComplete(String callId) {
436 mHandler.obtainMessage(MSG_ON_HANDOVER_COMPLETE, callId).sendToTarget();
437 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800438 }
439
Santos Cordona2492812015-04-15 11:05:16 -0700440 private Phone.Listener mPhoneListener = new Phone.Listener() {
441 /** ${inheritDoc} */
442 @Override
443 public void onAudioStateChanged(Phone phone, AudioState audioState) {
444 InCallService.this.onAudioStateChanged(audioState);
445 }
446
Yorke Lee4af59352015-05-13 14:14:54 -0700447 public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) {
448 InCallService.this.onCallAudioStateChanged(callAudioState);
449 };
450
Santos Cordona2492812015-04-15 11:05:16 -0700451 /** ${inheritDoc} */
452 @Override
453 public void onBringToForeground(Phone phone, boolean showDialpad) {
454 InCallService.this.onBringToForeground(showDialpad);
455 }
456
457 /** ${inheritDoc} */
458 @Override
459 public void onCallAdded(Phone phone, Call call) {
460 InCallService.this.onCallAdded(call);
461 }
462
463 /** ${inheritDoc} */
464 @Override
465 public void onCallRemoved(Phone phone, Call call) {
466 InCallService.this.onCallRemoved(call);
467 }
468
469 /** ${inheritDoc} */
470 @Override
471 public void onCanAddCallChanged(Phone phone, boolean canAddCall) {
472 InCallService.this.onCanAddCallChanged(canAddCall);
473 }
474
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800475 /** ${inheritDoc} */
476 @Override
477 public void onSilenceRinger(Phone phone) {
478 InCallService.this.onSilenceRinger();
479 }
480
Santos Cordona2492812015-04-15 11:05:16 -0700481 };
482
Ihab Awade63fadb2014-07-09 21:52:04 -0700483 private Phone mPhone;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800484
Santos Cordon2f42b112014-07-19 13:19:37 -0700485 public InCallService() {
486 }
Evan Charlton924748f2014-04-03 08:36:38 -0700487
Santos Cordon2f42b112014-07-19 13:19:37 -0700488 @Override
489 public IBinder onBind(Intent intent) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700490 return new InCallServiceBinder();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800491 }
492
Santos Cordonf30d7e92014-08-26 09:54:33 -0700493 @Override
494 public boolean onUnbind(Intent intent) {
Santos Cordon619b3c02014-09-02 17:13:45 -0700495 if (mPhone != null) {
496 Phone oldPhone = mPhone;
497 mPhone = null;
Santos Cordonf30d7e92014-08-26 09:54:33 -0700498
Santos Cordon619b3c02014-09-02 17:13:45 -0700499 oldPhone.destroy();
Santos Cordona2492812015-04-15 11:05:16 -0700500 // destroy sets all the calls to disconnected if any live ones still exist. Therefore,
501 // it is important to remove the Listener *after* the call to destroy so that
502 // InCallService.on* callbacks are appropriately called.
503 oldPhone.removeListener(mPhoneListener);
504
Santos Cordon619b3c02014-09-02 17:13:45 -0700505 onPhoneDestroyed(oldPhone);
506 }
Santos Cordona2492812015-04-15 11:05:16 -0700507
Santos Cordonf30d7e92014-08-26 09:54:33 -0700508 return false;
509 }
510
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800511 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700512 * Obtain the {@code Phone} associated with this {@code InCallService}.
513 *
514 * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null}
Santos Cordon2f42b112014-07-19 13:19:37 -0700515 * if the {@code InCallService} is not in a state where it has an associated
516 * {@code Phone}.
Santos Cordona2492812015-04-15 11:05:16 -0700517 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700518 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800519 */
Santos Cordona2492812015-04-15 11:05:16 -0700520 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700521 @Deprecated
522 public Phone getPhone() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700523 return mPhone;
Evan Charlton924748f2014-04-03 08:36:38 -0700524 }
525
526 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700527 * Obtains the current list of {@code Call}s to be displayed by this in-call service.
Santos Cordona2492812015-04-15 11:05:16 -0700528 *
529 * @return A list of the relevant {@code Call}s.
530 */
531 public final List<Call> getCalls() {
532 return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls();
533 }
534
535 /**
536 * Returns if the device can support additional calls.
537 *
538 * @return Whether the phone supports adding more calls.
539 */
540 public final boolean canAddCall() {
541 return mPhone == null ? false : mPhone.canAddCall();
542 }
543
544 /**
545 * Obtains the current phone call audio state.
546 *
547 * @return An object encapsulating the audio state. Returns null if the service is not
548 * fully initialized.
Yorke Lee4af59352015-05-13 14:14:54 -0700549 * @deprecated Use {@link #getCallAudioState()} instead.
550 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700551 */
Yorke Lee4af59352015-05-13 14:14:54 -0700552 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700553 public final AudioState getAudioState() {
554 return mPhone == null ? null : mPhone.getAudioState();
555 }
556
557 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700558 * Obtains the current phone call audio state.
559 *
560 * @return An object encapsulating the audio state. Returns null if the service is not
561 * fully initialized.
562 */
563 public final CallAudioState getCallAudioState() {
564 return mPhone == null ? null : mPhone.getCallAudioState();
565 }
566
567 /**
Santos Cordona2492812015-04-15 11:05:16 -0700568 * Sets the microphone mute state. When this request is honored, there will be change to
Yorke Lee4af59352015-05-13 14:14:54 -0700569 * the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700570 *
571 * @param state {@code true} if the microphone should be muted; {@code false} otherwise.
572 */
573 public final void setMuted(boolean state) {
574 if (mPhone != null) {
575 mPhone.setMuted(state);
576 }
577 }
578
579 /**
580 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
Yorke Lee4af59352015-05-13 14:14:54 -0700581 * be change to the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700582 *
583 * @param route The audio route to use.
584 */
585 public final void setAudioRoute(int route) {
586 if (mPhone != null) {
587 mPhone.setAudioRoute(route);
588 }
589 }
590
591 /**
Hall Liua98f58b52017-11-07 17:59:28 -0800592 * Request audio routing to a specific bluetooth device. Calling this method may result in
593 * the device routing audio to a different bluetooth device than the one specified if the
594 * bluetooth stack is unable to route audio to the requested device.
595 * A list of available devices can be obtained via
596 * {@link CallAudioState#getSupportedBluetoothDevices()}
597 *
Hall Liu15392832018-04-02 13:52:57 -0700598 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -0800599 */
Hall Liu15392832018-04-02 13:52:57 -0700600 public final void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -0800601 if (mPhone != null) {
Hall Liu15392832018-04-02 13:52:57 -0700602 mPhone.requestBluetoothAudio(bluetoothDevice.getAddress());
Hall Liua98f58b52017-11-07 17:59:28 -0800603 }
604 }
605
606 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700607 * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience
608 * to start displaying in-call information to the user. Each instance of {@code InCallService}
Santos Cordon2f42b112014-07-19 13:19:37 -0700609 * will have only one {@code Phone}, and this method will be called exactly once in the lifetime
610 * of the {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700611 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700612 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700613 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700614 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Evan Charlton924748f2014-04-03 08:36:38 -0700615 */
Santos Cordona2492812015-04-15 11:05:16 -0700616 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700617 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700618 public void onPhoneCreated(Phone phone) {
619 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800620
621 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700622 * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience
623 * to stop displaying in-call information to the user. This method will be called exactly once
624 * in the lifetime of the {@code InCallService}, and it will always be called after a previous
625 * call to {@link #onPhoneCreated(Phone)}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800626 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700627 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700628 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700629 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800630 */
Santos Cordona2492812015-04-15 11:05:16 -0700631 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700632 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700633 public void onPhoneDestroyed(Phone phone) {
634 }
Andrew Lee50aca232014-07-22 16:41:54 -0700635
636 /**
Santos Cordona2492812015-04-15 11:05:16 -0700637 * Called when the audio state changes.
638 *
639 * @param audioState The new {@link AudioState}.
Yorke Lee4af59352015-05-13 14:14:54 -0700640 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState) instead}.
641 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700642 */
Yorke Lee4af59352015-05-13 14:14:54 -0700643 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700644 public void onAudioStateChanged(AudioState audioState) {
645 }
646
647 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700648 * Called when the audio state changes.
649 *
650 * @param audioState The new {@link CallAudioState}.
651 */
652 public void onCallAudioStateChanged(CallAudioState audioState) {
653 }
654
655 /**
Santos Cordona2492812015-04-15 11:05:16 -0700656 * Called to bring the in-call screen to the foreground. The in-call experience should
657 * respond immediately by coming to the foreground to inform the user of the state of
658 * ongoing {@code Call}s.
659 *
660 * @param showDialpad If true, put up the dialpad when the screen is shown.
661 */
662 public void onBringToForeground(boolean showDialpad) {
663 }
664
665 /**
666 * Called when a {@code Call} has been added to this in-call session. The in-call user
667 * experience should add necessary state listeners to the specified {@code Call} and
668 * immediately start to show the user information about the existence
669 * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will
670 * include this {@code Call}.
671 *
672 * @param call A newly added {@code Call}.
673 */
674 public void onCallAdded(Call call) {
675 }
676
677 /**
678 * Called when a {@code Call} has been removed from this in-call session. The in-call user
679 * experience should remove any state listeners from the specified {@code Call} and
680 * immediately stop displaying any information about this {@code Call}.
681 * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}.
682 *
683 * @param call A newly removed {@code Call}.
684 */
685 public void onCallRemoved(Call call) {
686 }
687
688 /**
689 * Called when the ability to add more calls changes. If the phone cannot
690 * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it
691 * is set to {@code true}. This can be used to control the visibility of UI to add more calls.
692 *
693 * @param canAddCall Indicates whether an additional call can be added.
694 */
695 public void onCanAddCallChanged(boolean canAddCall) {
696 }
697
698 /**
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800699 * Called to silence the ringer if a ringing call exists.
700 */
701 public void onSilenceRinger() {
702 }
703
704 /**
Tyler Gunn06f3fa62016-08-25 09:26:15 -0700705 * Unused; to handle connection events issued by a {@link ConnectionService}, implement the
706 * {@link android.telecom.Call.Callback#onConnectionEvent(Call, String, Bundle)} callback.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700707 * <p>
708 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
709 *
710 * @param call The call the event is associated with.
711 * @param event The event.
712 * @param extras Any associated extras.
713 */
714 public void onConnectionEvent(Call call, String event, Bundle extras) {
715 }
716
717 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700718 * Used to issue commands to the {@link Connection.VideoProvider} associated with a
719 * {@link Call}.
Andrew Lee50aca232014-07-22 16:41:54 -0700720 */
721 public static abstract class VideoCall {
722
Andrew Lee011728f2015-04-23 15:47:06 -0700723 /** @hide */
Aurimas Liutikas796760c2020-11-10 15:32:51 -0800724 @SuppressWarnings("HiddenAbstractMethod")
Andrew Lee011728f2015-04-23 15:47:06 -0700725 public abstract void destroy();
726
Andrew Lee50aca232014-07-22 16:41:54 -0700727 /**
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700728 * Registers a callback to receive commands and state changes for video calls.
Andrew Lee50aca232014-07-22 16:41:54 -0700729 *
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700730 * @param callback The video call callback.
Andrew Lee50aca232014-07-22 16:41:54 -0700731 */
Andrew Leeda80c872015-04-15 14:09:50 -0700732 public abstract void registerCallback(VideoCall.Callback callback);
733
734 /**
Andrew Lee011728f2015-04-23 15:47:06 -0700735 * Registers a callback to receive commands and state changes for video calls.
736 *
737 * @param callback The video call callback.
738 * @param handler A handler which commands and status changes will be delivered to.
739 */
740 public abstract void registerCallback(VideoCall.Callback callback, Handler handler);
741
742 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700743 * Clears the video call callback set via {@link #registerCallback}.
Tyler Gunn295f5d72015-06-04 11:08:54 -0700744 *
745 * @param callback The video call callback to clear.
Tyler Gunn75958422015-04-15 14:23:42 -0700746 */
Andrew Lee011728f2015-04-23 15:47:06 -0700747 public abstract void unregisterCallback(VideoCall.Callback callback);
Tyler Gunn75958422015-04-15 14:23:42 -0700748
749 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700750 * Sets the camera to be used for the outgoing video.
751 * <p>
752 * Handled by {@link Connection.VideoProvider#onSetCamera(String)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700753 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700754 * @param cameraId The id of the camera (use ids as reported by
755 * {@link CameraManager#getCameraIdList()}).
Andrew Lee50aca232014-07-22 16:41:54 -0700756 */
757 public abstract void setCamera(String cameraId);
758
759 /**
760 * Sets the surface to be used for displaying a preview of what the user's camera is
761 * currently capturing. When video transmission is enabled, this is the video signal which
762 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700763 * <p>
764 * Handled by {@link Connection.VideoProvider#onSetPreviewSurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700765 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700766 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700767 */
768 public abstract void setPreviewSurface(Surface surface);
769
770 /**
771 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700772 * <p>
773 * Handled by {@link Connection.VideoProvider#onSetDisplaySurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700774 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700775 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700776 */
777 public abstract void setDisplaySurface(Surface surface);
778
779 /**
780 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
781 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700782 * <p>
783 * Handled by {@link Connection.VideoProvider#onSetDeviceOrientation(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700784 *
785 * @param rotation The device orientation, in degrees.
786 */
787 public abstract void setDeviceOrientation(int rotation);
788
789 /**
Tyler Gunnc603b462021-06-14 17:24:40 -0700790 * Sets the camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700791 * <p>
792 * Handled by {@link Connection.VideoProvider#onSetZoom(float)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700793 *
Tyler Gunnc603b462021-06-14 17:24:40 -0700794 * @param value The camera zoom ratio; for the current camera, should be a value in the
795 * range defined by
796 * {@link android.hardware.camera2.CameraCharacteristics#CONTROL_ZOOM_RATIO_RANGE}.
Andrew Lee50aca232014-07-22 16:41:54 -0700797 */
798 public abstract void setZoom(float value);
799
800 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700801 * Issues a request to modify the properties of the current video session.
802 * <p>
803 * Example scenarios include: requesting an audio-only call to be upgraded to a
804 * bi-directional video call, turning on or off the user's camera, sending a pause signal
805 * when the {@link InCallService} is no longer the foreground application.
806 * <p>
807 * Handled by
808 * {@link Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700809 *
810 * @param requestProfile The requested call video properties.
811 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700812 public abstract void sendSessionModifyRequest(VideoProfile requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700813
814 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700815 * Provides a response to a request to change the current call video session
816 * properties. This should be called in response to a request the {@link InCallService} has
817 * received via {@link VideoCall.Callback#onSessionModifyRequestReceived}.
818 * <p>
819 * Handled by
820 * {@link Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700821 *
822 * @param responseProfile The response call video properties.
823 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700824 public abstract void sendSessionModifyResponse(VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700825
826 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700827 * Issues a request to the {@link Connection.VideoProvider} to retrieve the capabilities
828 * of the current camera. The current camera is selected using
829 * {@link VideoCall#setCamera(String)}.
830 * <p>
831 * Camera capabilities are reported to the caller via
832 * {@link VideoCall.Callback#onCameraCapabilitiesChanged(VideoProfile.CameraCapabilities)}.
833 * <p>
834 * Handled by {@link Connection.VideoProvider#onRequestCameraCapabilities()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700835 */
836 public abstract void requestCameraCapabilities();
837
838 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700839 * Issues a request to the {@link Connection.VideoProvider} to retrieve the cumulative data
840 * usage for the video component of the current call (in bytes). Data usage is reported
841 * to the caller via {@link VideoCall.Callback#onCallDataUsageChanged}.
842 * <p>
843 * Handled by {@link Connection.VideoProvider#onRequestConnectionDataUsage()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700844 */
845 public abstract void requestCallDataUsage();
846
847 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700848 * Provides the {@link Connection.VideoProvider} with the {@link Uri} of an image to be
849 * displayed to the peer device when the video signal is paused.
850 * <p>
851 * Handled by {@link Connection.VideoProvider#onSetPauseImage(Uri)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700852 *
853 * @param uri URI of image to display.
854 */
Yorke Lee32f24732015-05-12 16:18:03 -0700855 public abstract void setPauseImage(Uri uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700856
857 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700858 * The {@link InCallService} extends this class to provide a means of receiving callbacks
Tyler Gunn295f5d72015-06-04 11:08:54 -0700859 * from the {@link Connection.VideoProvider}.
860 * <p>
Tyler Gunnb702ef82015-05-29 11:51:53 -0700861 * When the {@link InCallService} receives the
862 * {@link Call.Callback#onVideoCallChanged(Call, VideoCall)} callback, it should create an
863 * instance its {@link VideoCall.Callback} implementation and set it on the
864 * {@link VideoCall} using {@link VideoCall#registerCallback(Callback)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700865 */
Andrew Leeda80c872015-04-15 14:09:50 -0700866 public static abstract class Callback {
Andrew Lee50aca232014-07-22 16:41:54 -0700867 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700868 * Called when the {@link Connection.VideoProvider} receives a session modification
Tyler Gunn295f5d72015-06-04 11:08:54 -0700869 * request from the peer device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700870 * <p>
871 * The {@link InCallService} may potentially prompt the user to confirm whether they
872 * wish to accept the request, or decide to automatically accept the request. In either
873 * case the {@link InCallService} should call
874 * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} to indicate the video
875 * profile agreed upon.
876 * <p>
877 * Callback originates from
878 * {@link Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700879 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700880 * @param videoProfile The requested video profile.
Andrew Lee50aca232014-07-22 16:41:54 -0700881 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700882 public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700883
884 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700885 * Called when the {@link Connection.VideoProvider} receives a response to a session
886 * modification request previously sent to the peer device.
887 * <p>
888 * The new video state should not be considered active by the {@link InCallService}
889 * until the {@link Call} video state changes (the
890 * {@link Call.Callback#onDetailsChanged(Call, Call.Details)} callback is triggered
891 * when the video state changes).
892 * <p>
893 * Callback originates from
894 * {@link Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
895 * VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700896 *
897 * @param status Status of the session modify request. Valid values are
Tyler Gunnb702ef82015-05-29 11:51:53 -0700898 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
899 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
900 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
901 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
902 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}.
903 * @param requestedProfile The original request which was sent to the peer device.
904 * @param responseProfile The actual profile changes made by the peer device.
Andrew Lee50aca232014-07-22 16:41:54 -0700905 */
906 public abstract void onSessionModifyResponseReceived(int status,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700907 VideoProfile requestedProfile, VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700908
909 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700910 * Handles events related to the current video session which the {@link InCallService}
911 * may wish to handle. These are separate from requested changes to the session due to
912 * the underlying protocol or connection.
913 * <p>
914 * Callback originates from
915 * {@link Connection.VideoProvider#handleCallSessionEvent(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700916 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700917 * @param event The event. Valid values are:
918 * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE},
919 * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME},
920 * {@link Connection.VideoProvider#SESSION_EVENT_TX_START},
921 * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP},
922 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800923 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY},
924 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_PERMISSION_ERROR}.
Andrew Lee50aca232014-07-22 16:41:54 -0700925 */
926 public abstract void onCallSessionEvent(int event);
927
928 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700929 * Handles a change to the video dimensions from the peer device. This could happen if,
930 * for example, the peer changes orientation of their device, or switches cameras.
931 * <p>
932 * Callback originates from
933 * {@link Connection.VideoProvider#changePeerDimensions(int, int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700934 *
935 * @param width The updated peer video width.
936 * @param height The updated peer video height.
937 */
938 public abstract void onPeerDimensionsChanged(int width, int height);
939
940 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700941 * Handles a change to the video quality.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700942 * <p>
943 * Callback originates from {@link Connection.VideoProvider#changeVideoQuality(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700944 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700945 * @param videoQuality The updated peer video quality. Valid values:
946 * {@link VideoProfile#QUALITY_HIGH},
947 * {@link VideoProfile#QUALITY_MEDIUM},
948 * {@link VideoProfile#QUALITY_LOW},
949 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700950 */
951 public abstract void onVideoQualityChanged(int videoQuality);
952
953 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700954 * Handles an update to the total data used for the current video session.
955 * <p>
956 * Used by the {@link Connection.VideoProvider} in response to
957 * {@link VideoCall#requestCallDataUsage()}. May also be called periodically by the
958 * {@link Connection.VideoProvider}.
959 * <p>
960 * Callback originates from {@link Connection.VideoProvider#setCallDataUsage(long)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700961 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700962 * @param dataUsage The updated data usage (in bytes).
Andrew Lee50aca232014-07-22 16:41:54 -0700963 */
Rekha Kumar07366812015-03-24 16:42:31 -0700964 public abstract void onCallDataUsageChanged(long dataUsage);
Andrew Lee50aca232014-07-22 16:41:54 -0700965
966 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700967 * Handles a change in the capabilities of the currently selected camera.
968 * <p>
969 * Used by the {@link Connection.VideoProvider} in response to
970 * {@link VideoCall#requestCameraCapabilities()}. The {@link Connection.VideoProvider}
971 * may also report the camera capabilities after a call to
972 * {@link VideoCall#setCamera(String)}.
973 * <p>
974 * Callback originates from
975 * {@link Connection.VideoProvider#changeCameraCapabilities(
976 * VideoProfile.CameraCapabilities)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700977 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700978 * @param cameraCapabilities The changed camera capabilities.
Andrew Lee50aca232014-07-22 16:41:54 -0700979 */
Yorke Lee400470f2015-05-12 13:31:25 -0700980 public abstract void onCameraCapabilitiesChanged(
981 VideoProfile.CameraCapabilities cameraCapabilities);
Andrew Lee50aca232014-07-22 16:41:54 -0700982 }
983 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800984}