blob: 7caaba71222f52e2e8c19086a1a811059f56bfce [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>
Tyler Gunn272fd212021-10-12 09:22:24 -070072 * The pre-loaded dialer will ALWAYS be used when the user places an emergency call, even if your
73 * app fills the {@link android.app.role.RoleManager#ROLE_DIALER} role. To ensure an optimal
74 * experience when placing an emergency call, the default dialer should ALWAYS use
75 * {@link android.telecom.TelecomManager#placeCall(Uri, Bundle)} to place calls (including
76 * emergency calls). This ensures that the platform is able to verify that the request came from
77 * the default dialer. If a non-preloaded dialer app uses {@link Intent#ACTION_CALL} to place an
78 * emergency call, it will be raised to the preloaded dialer app using {@link Intent#ACTION_DIAL}
79 * for confirmation; this is a suboptimal user experience.
Santos Cordonf2600eb2015-06-22 15:02:20 -070080 * <p>
81 * Below is an example manifest registration for an {@code InCallService}. The meta-data
Tyler Gunndc6e6c42018-07-03 16:08:17 -070082 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_UI} indicates that this particular
Santos Cordonf2600eb2015-06-22 15:02:20 -070083 * {@code InCallService} implementation intends to replace the built-in in-call UI.
Tyler Gunndc6e6c42018-07-03 16:08:17 -070084 * The meta-data {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} indicates that this
85 * {@link InCallService} will play the ringtone for incoming calls. See
86 * <a href="#incomingCallNotification">below</a> for more information on showing the incoming call
87 * UI and playing the ringtone in your app.
Santos Cordonf2600eb2015-06-22 15:02:20 -070088 * <pre>
89 * {@code
Neil Fuller71fbb812015-11-30 09:51:33 +000090 * <service android:name="your.package.YourInCallServiceImplementation"
Tyler Gunn84421d72021-09-03 14:05:37 -070091 * android:permission="android.permission.BIND_INCALL_SERVICE"
92 * android:exported="true">
Neil Fuller71fbb812015-11-30 09:51:33 +000093 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
Tyler Gunndc6e6c42018-07-03 16:08:17 -070094 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_RINGING"
95 * android:value="true" />
Neil Fuller71fbb812015-11-30 09:51:33 +000096 * <intent-filter>
97 * <action android:name="android.telecom.InCallService"/>
98 * </intent-filter>
99 * </service>
Santos Cordonf2600eb2015-06-22 15:02:20 -0700100 * }
101 * </pre>
Tyler Gunn84421d72021-09-03 14:05:37 -0700102 *
103 * <em>Note: You should NOT mark your {@link InCallService} with the attribute
104 * {@code android:exported="false"}; doing so can result in a failure to bind to your implementation
105 * during calls.</em>
Tyler Gunnfe39efa2018-02-02 13:18:02 -0800106 * <p>
107 * In addition to implementing the {@link InCallService} API, you must also declare an activity in
108 * your manifest which handles the {@link Intent#ACTION_DIAL} intent. The example below illustrates
109 * how this is done:
110 * <pre>
111 * {@code
112 * <activity android:name="your.package.YourDialerActivity"
113 * android:label="@string/yourDialerActivityLabel">
114 * <intent-filter>
115 * <action android:name="android.intent.action.DIAL" />
116 * <category android:name="android.intent.category.DEFAULT" />
117 * </intent-filter>
Tyler Gunn4057d4c2020-01-31 15:03:43 -0800118 * <intent-filter>
119 * <action android:name="android.intent.action.DIAL" />
120 * <category android:name="android.intent.category.DEFAULT" />
121 * <data android:scheme="tel" />
122 * </intent-filter>
Tyler Gunnfe39efa2018-02-02 13:18:02 -0800123 * </activity>
124 * }
125 * </pre>
126 * <p>
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800127 * When a user installs your application and runs it for the first time, you should use the
128 * {@link android.app.role.RoleManager} to prompt the user to see if they would like your app to
129 * be the new default phone app.
130 * <p id="requestRole">
131 * The code below shows how your app can request to become the default phone/dialer app:
132 * <pre>
133 * {@code
134 * private static final int REQUEST_ID = 1;
135 *
136 * public void requestRole() {
137 * RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
138 * Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_DIALER);
139 * startActivityForResult(intent, REQUEST_ID);
140 * }
141 *
142 * &#64;Override
143 * public void onActivityResult(int requestCode, int resultCode, Intent data) {
144 * if (requestCode == REQUEST_ID) {
145 * if (resultCode == android.app.Activity.RESULT_OK) {
146 * // Your app is now the default dialer app
147 * } else {
148 * // Your app is not the default dialer app
149 * }
150 * }
151 * }
Tyler Gunn4057d4c2020-01-31 15:03:43 -0800152 * }
sqian7a2b7112021-02-25 20:40:12 +0000153 *
154 * </pre>
155 * <p id="companionInCallService">
156 * <h3>Access to InCallService for Wearable Devices</h3>
157 * <ol>
158 * If your app is a third-party companion app and wants to access InCallService APIs, what your
159 * app could do are:
160 * <p>
161 * <ol>
162 * <li> Declare MANAGE_ONGOING_CALLS permission in your manifest
163 * <li> Associate with a physical wearable device via the
164 * {@link android.companion.CompanionDeviceManager} API as a companion app. See:
165 * https://developer.android.com/guide/topics/connectivity/companion-device-pairing
166 * <li> Implement this InCallService with BIND_INCALL_SERVICE permission
167 * </ol>
168 * </ol>
169 * <p>
170 *
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800171 * </pre>
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700172 * <p id="incomingCallNotification">
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800173 * <h3>Showing the Incoming Call Notification</h3>
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700174 * When your app receives a new incoming call via {@link InCallService#onCallAdded(Call)}, it is
175 * responsible for displaying an incoming call UI for the incoming call. It should do this using
176 * {@link android.app.NotificationManager} APIs to post a new incoming call notification.
177 * <p>
178 * Where your app declares the meta-data {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING}, it
179 * is responsible for playing the ringtone for incoming calls. Your app should create a
180 * {@link android.app.NotificationChannel} which specifies the desired ringtone. For example:
181 * <pre><code>
182 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
183 * NotificationManager.IMPORTANCE_MAX);
184 * // other channel setup stuff goes here.
185 *
186 * // We'll use the default system ringtone for our incoming call notification channel. You can
187 * // use your own audio resource here.
188 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
189 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
190 * // Setting the AudioAttributes is important as it identifies the purpose of your
191 * // notification sound.
192 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
193 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
194 * .build());
195 *
196 * NotificationManager mgr = getSystemService(NotificationManager.class);
197 * mgr.createNotificationChannel(channel);
198 * </code></pre>
199 * <p>
200 * When your app receives a new incoming call, it creates a {@link android.app.Notification} for the
201 * incoming call and associates it with your incoming call notification channel. You can specify a
202 * {@link android.app.PendingIntent} on the notification which will launch your full screen
203 * incoming call UI. The notification manager framework will display your notification as a
204 * heads-up notification if the user is actively using the phone. When the user is not using the
205 * phone, your full-screen incoming call UI is used instead.
206 * For example:
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800207 * <pre><code>{@code
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700208 * // Create an intent which triggers your fullscreen incoming call user interface.
209 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
210 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
211 * intent.setClass(context, YourIncomingCallActivity.class);
212 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
213 *
214 * // Build the notification as an ongoing high priority item; this ensures it will show as
215 * // a heads up notification which slides down over top of the current content.
216 * final Notification.Builder builder = new Notification.Builder(context);
217 * builder.setOngoing(true);
218 * builder.setPriority(Notification.PRIORITY_HIGH);
219 *
220 * // Set notification content intent to take user to the fullscreen UI if user taps on the
221 * // notification body.
222 * builder.setContentIntent(pendingIntent);
223 * // Set full screen intent to trigger display of the fullscreen UI when the notification
224 * // manager deems it appropriate.
225 * builder.setFullScreenIntent(pendingIntent, true);
226 *
227 * // Setup notification content.
228 * builder.setSmallIcon( yourIconResourceId );
229 * builder.setContentTitle("Your notification title");
230 * builder.setContentText("Your notification content.");
231 *
232 * // Use builder.addAction(..) to add buttons to answer or reject the call.
233 *
234 * NotificationManager notificationManager = mContext.getSystemService(
235 * NotificationManager.class);
236 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, builder.build());
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800237 * }</pre>
238 * <p>
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800239 */
Santos Cordon2f42b112014-07-19 13:19:37 -0700240public abstract class InCallService extends Service {
Tyler Gunn2ac40102014-08-18 16:23:10 -0700241
242 /**
243 * The {@link Intent} that must be declared as handled by the service.
244 */
245 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700246 public static final String SERVICE_INTERFACE = "android.telecom.InCallService";
Tyler Gunn2ac40102014-08-18 16:23:10 -0700247
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800248 private static final int MSG_SET_IN_CALL_ADAPTER = 1;
249 private static final int MSG_ADD_CALL = 2;
Sailesh Nepal60437932014-04-05 16:44:55 -0700250 private static final int MSG_UPDATE_CALL = 3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700251 private static final int MSG_SET_POST_DIAL_WAIT = 4;
Yorke Lee4af59352015-05-13 14:14:54 -0700252 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 5;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700253 private static final int MSG_BRING_TO_FOREGROUND = 6;
Santos Cordon6c912b72014-11-07 16:05:09 -0800254 private static final int MSG_ON_CAN_ADD_CALL_CHANGED = 7;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800255 private static final int MSG_SILENCE_RINGER = 8;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700256 private static final int MSG_ON_CONNECTION_EVENT = 9;
Hall Liu95d55872017-01-25 17:12:49 -0800257 private static final int MSG_ON_RTT_UPGRADE_REQUEST = 10;
Hall Liu57006aa2017-02-06 10:49:48 -0800258 private static final int MSG_ON_RTT_INITIATION_FAILURE = 11;
Sanket Padawe85291f62017-12-01 13:59:27 -0800259 private static final int MSG_ON_HANDOVER_FAILED = 12;
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800260 private static final int MSG_ON_HANDOVER_COMPLETE = 13;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800261
262 /** Default Handler used to consolidate binder method calls onto a single thread. */
263 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
264 @Override
265 public void handleMessage(Message msg) {
Jay Shrauner5e6162d2014-09-22 20:47:45 -0700266 if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) {
267 return;
268 }
269
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800270 switch (msg.what) {
271 case MSG_SET_IN_CALL_ADAPTER:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800272 String callingPackage = getApplicationContext().getOpPackageName();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800273 mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj), callingPackage,
274 getApplicationContext().getApplicationInfo().targetSdkVersion);
Santos Cordona2492812015-04-15 11:05:16 -0700275 mPhone.addListener(mPhoneListener);
Ihab Awade63fadb2014-07-09 21:52:04 -0700276 onPhoneCreated(mPhone);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800277 break;
278 case MSG_ADD_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700279 mPhone.internalAddCall((ParcelableCall) msg.obj);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800280 break;
Sailesh Nepal60437932014-04-05 16:44:55 -0700281 case MSG_UPDATE_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700282 mPhone.internalUpdateCall((ParcelableCall) msg.obj);
Ihab Awad2f236642014-03-10 15:33:45 -0700283 break;
Ihab Awad2f236642014-03-10 15:33:45 -0700284 case MSG_SET_POST_DIAL_WAIT: {
285 SomeArgs args = (SomeArgs) msg.obj;
286 try {
287 String callId = (String) args.arg1;
288 String remaining = (String) args.arg2;
Ihab Awade63fadb2014-07-09 21:52:04 -0700289 mPhone.internalSetPostDialWait(callId, remaining);
Ihab Awad2f236642014-03-10 15:33:45 -0700290 } finally {
291 args.recycle();
292 }
293 break;
294 }
Yorke Lee4af59352015-05-13 14:14:54 -0700295 case MSG_ON_CALL_AUDIO_STATE_CHANGED:
296 mPhone.internalCallAudioStateChanged((CallAudioState) msg.obj);
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700297 break;
Santos Cordon3534ede2014-05-29 13:07:10 -0700298 case MSG_BRING_TO_FOREGROUND:
Ihab Awade63fadb2014-07-09 21:52:04 -0700299 mPhone.internalBringToForeground(msg.arg1 == 1);
Santos Cordon3534ede2014-05-29 13:07:10 -0700300 break;
Santos Cordon6c912b72014-11-07 16:05:09 -0800301 case MSG_ON_CAN_ADD_CALL_CHANGED:
302 mPhone.internalSetCanAddCall(msg.arg1 == 1);
303 break;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800304 case MSG_SILENCE_RINGER:
305 mPhone.internalSilenceRinger();
306 break;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700307 case MSG_ON_CONNECTION_EVENT: {
308 SomeArgs args = (SomeArgs) msg.obj;
309 try {
310 String callId = (String) args.arg1;
311 String event = (String) args.arg2;
312 Bundle extras = (Bundle) args.arg3;
313 mPhone.internalOnConnectionEvent(callId, event, extras);
314 } finally {
315 args.recycle();
316 }
317 break;
318 }
Hall Liu95d55872017-01-25 17:12:49 -0800319 case MSG_ON_RTT_UPGRADE_REQUEST: {
320 String callId = (String) msg.obj;
321 int requestId = msg.arg1;
322 mPhone.internalOnRttUpgradeRequest(callId, requestId);
323 break;
324 }
Hall Liu57006aa2017-02-06 10:49:48 -0800325 case MSG_ON_RTT_INITIATION_FAILURE: {
326 String callId = (String) msg.obj;
327 int reason = msg.arg1;
328 mPhone.internalOnRttInitiationFailure(callId, reason);
329 break;
330 }
Sanket Padawe85291f62017-12-01 13:59:27 -0800331 case MSG_ON_HANDOVER_FAILED: {
332 String callId = (String) msg.obj;
333 int error = msg.arg1;
334 mPhone.internalOnHandoverFailed(callId, error);
335 break;
336 }
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800337 case MSG_ON_HANDOVER_COMPLETE: {
338 String callId = (String) msg.obj;
339 mPhone.internalOnHandoverComplete(callId);
340 break;
341 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800342 default:
343 break;
344 }
345 }
346 };
347
348 /** Manages the binder calls so that the implementor does not need to deal with it. */
349 private final class InCallServiceBinder extends IInCallService.Stub {
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800350 @Override
351 public void setInCallAdapter(IInCallAdapter inCallAdapter) {
352 mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget();
353 }
354
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800355 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700356 public void addCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700357 mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800358 }
359
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800360 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700361 public void updateCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700362 mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
Ihab Awad2f236642014-03-10 15:33:45 -0700363 }
364
365 @Override
366 public void setPostDial(String callId, String remaining) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700367 // TODO: Unused
Ihab Awad2f236642014-03-10 15:33:45 -0700368 }
369
370 @Override
371 public void setPostDialWait(String callId, String remaining) {
372 SomeArgs args = SomeArgs.obtain();
373 args.arg1 = callId;
374 args.arg2 = remaining;
375 mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
376 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700377
378 @Override
Yorke Lee4af59352015-05-13 14:14:54 -0700379 public void onCallAudioStateChanged(CallAudioState callAudioState) {
380 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, callAudioState).sendToTarget();
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700381 }
Santos Cordon3534ede2014-05-29 13:07:10 -0700382
Santos Cordon3534ede2014-05-29 13:07:10 -0700383 @Override
384 public void bringToForeground(boolean showDialpad) {
385 mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
386 }
Santos Cordon6c912b72014-11-07 16:05:09 -0800387
388 @Override
389 public void onCanAddCallChanged(boolean canAddCall) {
390 mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0)
391 .sendToTarget();
392 }
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800393
394 @Override
395 public void silenceRinger() {
396 mHandler.obtainMessage(MSG_SILENCE_RINGER).sendToTarget();
397 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700398
399 @Override
400 public void onConnectionEvent(String callId, String event, Bundle extras) {
401 SomeArgs args = SomeArgs.obtain();
402 args.arg1 = callId;
403 args.arg2 = event;
404 args.arg3 = extras;
405 mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget();
406 }
Hall Liu95d55872017-01-25 17:12:49 -0800407
408 @Override
409 public void onRttUpgradeRequest(String callId, int id) {
410 mHandler.obtainMessage(MSG_ON_RTT_UPGRADE_REQUEST, id, 0, callId).sendToTarget();
411 }
Hall Liu57006aa2017-02-06 10:49:48 -0800412
413 @Override
414 public void onRttInitiationFailure(String callId, int reason) {
415 mHandler.obtainMessage(MSG_ON_RTT_INITIATION_FAILURE, reason, 0, callId).sendToTarget();
416 }
Sanket Padawe85291f62017-12-01 13:59:27 -0800417
418 @Override
419 public void onHandoverFailed(String callId, int error) {
420 mHandler.obtainMessage(MSG_ON_HANDOVER_FAILED, error, 0, callId).sendToTarget();
421 }
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800422
423 @Override
424 public void onHandoverComplete(String callId) {
425 mHandler.obtainMessage(MSG_ON_HANDOVER_COMPLETE, callId).sendToTarget();
426 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800427 }
428
Santos Cordona2492812015-04-15 11:05:16 -0700429 private Phone.Listener mPhoneListener = new Phone.Listener() {
430 /** ${inheritDoc} */
431 @Override
432 public void onAudioStateChanged(Phone phone, AudioState audioState) {
433 InCallService.this.onAudioStateChanged(audioState);
434 }
435
Yorke Lee4af59352015-05-13 14:14:54 -0700436 public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) {
437 InCallService.this.onCallAudioStateChanged(callAudioState);
438 };
439
Santos Cordona2492812015-04-15 11:05:16 -0700440 /** ${inheritDoc} */
441 @Override
442 public void onBringToForeground(Phone phone, boolean showDialpad) {
443 InCallService.this.onBringToForeground(showDialpad);
444 }
445
446 /** ${inheritDoc} */
447 @Override
448 public void onCallAdded(Phone phone, Call call) {
449 InCallService.this.onCallAdded(call);
450 }
451
452 /** ${inheritDoc} */
453 @Override
454 public void onCallRemoved(Phone phone, Call call) {
455 InCallService.this.onCallRemoved(call);
456 }
457
458 /** ${inheritDoc} */
459 @Override
460 public void onCanAddCallChanged(Phone phone, boolean canAddCall) {
461 InCallService.this.onCanAddCallChanged(canAddCall);
462 }
463
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800464 /** ${inheritDoc} */
465 @Override
466 public void onSilenceRinger(Phone phone) {
467 InCallService.this.onSilenceRinger();
468 }
469
Santos Cordona2492812015-04-15 11:05:16 -0700470 };
471
Ihab Awade63fadb2014-07-09 21:52:04 -0700472 private Phone mPhone;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800473
Santos Cordon2f42b112014-07-19 13:19:37 -0700474 public InCallService() {
475 }
Evan Charlton924748f2014-04-03 08:36:38 -0700476
Santos Cordon2f42b112014-07-19 13:19:37 -0700477 @Override
478 public IBinder onBind(Intent intent) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700479 return new InCallServiceBinder();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800480 }
481
Santos Cordonf30d7e92014-08-26 09:54:33 -0700482 @Override
483 public boolean onUnbind(Intent intent) {
Santos Cordon619b3c02014-09-02 17:13:45 -0700484 if (mPhone != null) {
485 Phone oldPhone = mPhone;
486 mPhone = null;
Santos Cordonf30d7e92014-08-26 09:54:33 -0700487
Santos Cordon619b3c02014-09-02 17:13:45 -0700488 oldPhone.destroy();
Santos Cordona2492812015-04-15 11:05:16 -0700489 // destroy sets all the calls to disconnected if any live ones still exist. Therefore,
490 // it is important to remove the Listener *after* the call to destroy so that
491 // InCallService.on* callbacks are appropriately called.
492 oldPhone.removeListener(mPhoneListener);
493
Santos Cordon619b3c02014-09-02 17:13:45 -0700494 onPhoneDestroyed(oldPhone);
495 }
Santos Cordona2492812015-04-15 11:05:16 -0700496
Santos Cordonf30d7e92014-08-26 09:54:33 -0700497 return false;
498 }
499
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800500 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700501 * Obtain the {@code Phone} associated with this {@code InCallService}.
502 *
503 * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null}
Santos Cordon2f42b112014-07-19 13:19:37 -0700504 * if the {@code InCallService} is not in a state where it has an associated
505 * {@code Phone}.
Santos Cordona2492812015-04-15 11:05:16 -0700506 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700507 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800508 */
Santos Cordona2492812015-04-15 11:05:16 -0700509 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700510 @Deprecated
511 public Phone getPhone() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700512 return mPhone;
Evan Charlton924748f2014-04-03 08:36:38 -0700513 }
514
515 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700516 * Obtains the current list of {@code Call}s to be displayed by this in-call service.
Santos Cordona2492812015-04-15 11:05:16 -0700517 *
518 * @return A list of the relevant {@code Call}s.
519 */
520 public final List<Call> getCalls() {
521 return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls();
522 }
523
524 /**
525 * Returns if the device can support additional calls.
526 *
527 * @return Whether the phone supports adding more calls.
528 */
529 public final boolean canAddCall() {
530 return mPhone == null ? false : mPhone.canAddCall();
531 }
532
533 /**
534 * Obtains the current phone call audio state.
535 *
536 * @return An object encapsulating the audio state. Returns null if the service is not
537 * fully initialized.
Yorke Lee4af59352015-05-13 14:14:54 -0700538 * @deprecated Use {@link #getCallAudioState()} instead.
539 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700540 */
Yorke Lee4af59352015-05-13 14:14:54 -0700541 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700542 public final AudioState getAudioState() {
543 return mPhone == null ? null : mPhone.getAudioState();
544 }
545
546 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700547 * Obtains the current phone call audio state.
548 *
549 * @return An object encapsulating the audio state. Returns null if the service is not
550 * fully initialized.
551 */
552 public final CallAudioState getCallAudioState() {
553 return mPhone == null ? null : mPhone.getCallAudioState();
554 }
555
556 /**
Santos Cordona2492812015-04-15 11:05:16 -0700557 * Sets the microphone mute state. When this request is honored, there will be change to
Yorke Lee4af59352015-05-13 14:14:54 -0700558 * the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700559 *
560 * @param state {@code true} if the microphone should be muted; {@code false} otherwise.
561 */
562 public final void setMuted(boolean state) {
563 if (mPhone != null) {
564 mPhone.setMuted(state);
565 }
566 }
567
568 /**
569 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
Yorke Lee4af59352015-05-13 14:14:54 -0700570 * be change to the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700571 *
572 * @param route The audio route to use.
573 */
574 public final void setAudioRoute(int route) {
575 if (mPhone != null) {
576 mPhone.setAudioRoute(route);
577 }
578 }
579
580 /**
Hall Liua98f58b52017-11-07 17:59:28 -0800581 * Request audio routing to a specific bluetooth device. Calling this method may result in
582 * the device routing audio to a different bluetooth device than the one specified if the
583 * bluetooth stack is unable to route audio to the requested device.
584 * A list of available devices can be obtained via
585 * {@link CallAudioState#getSupportedBluetoothDevices()}
586 *
Hall Liu15392832018-04-02 13:52:57 -0700587 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -0800588 */
Hall Liu15392832018-04-02 13:52:57 -0700589 public final void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -0800590 if (mPhone != null) {
Hall Liu15392832018-04-02 13:52:57 -0700591 mPhone.requestBluetoothAudio(bluetoothDevice.getAddress());
Hall Liua98f58b52017-11-07 17:59:28 -0800592 }
593 }
594
595 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700596 * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience
597 * to start displaying in-call information to the user. Each instance of {@code InCallService}
Santos Cordon2f42b112014-07-19 13:19:37 -0700598 * will have only one {@code Phone}, and this method will be called exactly once in the lifetime
599 * of the {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700600 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700601 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700602 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700603 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Evan Charlton924748f2014-04-03 08:36:38 -0700604 */
Santos Cordona2492812015-04-15 11:05:16 -0700605 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700606 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700607 public void onPhoneCreated(Phone phone) {
608 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800609
610 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700611 * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience
612 * to stop displaying in-call information to the user. This method will be called exactly once
613 * in the lifetime of the {@code InCallService}, and it will always be called after a previous
614 * call to {@link #onPhoneCreated(Phone)}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800615 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700616 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700617 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700618 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800619 */
Santos Cordona2492812015-04-15 11:05:16 -0700620 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700621 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700622 public void onPhoneDestroyed(Phone phone) {
623 }
Andrew Lee50aca232014-07-22 16:41:54 -0700624
625 /**
Santos Cordona2492812015-04-15 11:05:16 -0700626 * Called when the audio state changes.
627 *
628 * @param audioState The new {@link AudioState}.
Yorke Lee4af59352015-05-13 14:14:54 -0700629 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState) instead}.
630 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700631 */
Yorke Lee4af59352015-05-13 14:14:54 -0700632 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700633 public void onAudioStateChanged(AudioState audioState) {
634 }
635
636 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700637 * Called when the audio state changes.
638 *
639 * @param audioState The new {@link CallAudioState}.
640 */
641 public void onCallAudioStateChanged(CallAudioState audioState) {
642 }
643
644 /**
Santos Cordona2492812015-04-15 11:05:16 -0700645 * Called to bring the in-call screen to the foreground. The in-call experience should
646 * respond immediately by coming to the foreground to inform the user of the state of
647 * ongoing {@code Call}s.
648 *
649 * @param showDialpad If true, put up the dialpad when the screen is shown.
650 */
651 public void onBringToForeground(boolean showDialpad) {
652 }
653
654 /**
655 * Called when a {@code Call} has been added to this in-call session. The in-call user
656 * experience should add necessary state listeners to the specified {@code Call} and
657 * immediately start to show the user information about the existence
658 * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will
659 * include this {@code Call}.
660 *
661 * @param call A newly added {@code Call}.
662 */
663 public void onCallAdded(Call call) {
664 }
665
666 /**
667 * Called when a {@code Call} has been removed from this in-call session. The in-call user
668 * experience should remove any state listeners from the specified {@code Call} and
669 * immediately stop displaying any information about this {@code Call}.
670 * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}.
671 *
672 * @param call A newly removed {@code Call}.
673 */
674 public void onCallRemoved(Call call) {
675 }
676
677 /**
678 * Called when the ability to add more calls changes. If the phone cannot
679 * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it
680 * is set to {@code true}. This can be used to control the visibility of UI to add more calls.
681 *
682 * @param canAddCall Indicates whether an additional call can be added.
683 */
684 public void onCanAddCallChanged(boolean canAddCall) {
685 }
686
687 /**
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800688 * Called to silence the ringer if a ringing call exists.
689 */
690 public void onSilenceRinger() {
691 }
692
693 /**
Tyler Gunn06f3fa62016-08-25 09:26:15 -0700694 * Unused; to handle connection events issued by a {@link ConnectionService}, implement the
695 * {@link android.telecom.Call.Callback#onConnectionEvent(Call, String, Bundle)} callback.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700696 * <p>
697 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
698 *
699 * @param call The call the event is associated with.
700 * @param event The event.
701 * @param extras Any associated extras.
702 */
703 public void onConnectionEvent(Call call, String event, Bundle extras) {
704 }
705
706 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700707 * Used to issue commands to the {@link Connection.VideoProvider} associated with a
708 * {@link Call}.
Andrew Lee50aca232014-07-22 16:41:54 -0700709 */
710 public static abstract class VideoCall {
711
Andrew Lee011728f2015-04-23 15:47:06 -0700712 /** @hide */
Aurimas Liutikasd23189b2020-11-10 15:32:51 -0800713 @SuppressWarnings("HiddenAbstractMethod")
Andrew Lee011728f2015-04-23 15:47:06 -0700714 public abstract void destroy();
715
Andrew Lee50aca232014-07-22 16:41:54 -0700716 /**
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700717 * Registers a callback to receive commands and state changes for video calls.
Andrew Lee50aca232014-07-22 16:41:54 -0700718 *
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700719 * @param callback The video call callback.
Andrew Lee50aca232014-07-22 16:41:54 -0700720 */
Andrew Leeda80c872015-04-15 14:09:50 -0700721 public abstract void registerCallback(VideoCall.Callback callback);
722
723 /**
Andrew Lee011728f2015-04-23 15:47:06 -0700724 * Registers a callback to receive commands and state changes for video calls.
725 *
726 * @param callback The video call callback.
727 * @param handler A handler which commands and status changes will be delivered to.
728 */
729 public abstract void registerCallback(VideoCall.Callback callback, Handler handler);
730
731 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700732 * Clears the video call callback set via {@link #registerCallback}.
Tyler Gunn295f5d72015-06-04 11:08:54 -0700733 *
734 * @param callback The video call callback to clear.
Tyler Gunn75958422015-04-15 14:23:42 -0700735 */
Andrew Lee011728f2015-04-23 15:47:06 -0700736 public abstract void unregisterCallback(VideoCall.Callback callback);
Tyler Gunn75958422015-04-15 14:23:42 -0700737
738 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700739 * Sets the camera to be used for the outgoing video.
740 * <p>
741 * Handled by {@link Connection.VideoProvider#onSetCamera(String)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700742 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700743 * @param cameraId The id of the camera (use ids as reported by
744 * {@link CameraManager#getCameraIdList()}).
Andrew Lee50aca232014-07-22 16:41:54 -0700745 */
746 public abstract void setCamera(String cameraId);
747
748 /**
749 * Sets the surface to be used for displaying a preview of what the user's camera is
750 * currently capturing. When video transmission is enabled, this is the video signal which
751 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700752 * <p>
753 * Handled by {@link Connection.VideoProvider#onSetPreviewSurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700754 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700755 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700756 */
757 public abstract void setPreviewSurface(Surface surface);
758
759 /**
760 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700761 * <p>
762 * Handled by {@link Connection.VideoProvider#onSetDisplaySurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700763 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700764 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700765 */
766 public abstract void setDisplaySurface(Surface surface);
767
768 /**
769 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
770 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700771 * <p>
772 * Handled by {@link Connection.VideoProvider#onSetDeviceOrientation(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700773 *
774 * @param rotation The device orientation, in degrees.
775 */
776 public abstract void setDeviceOrientation(int rotation);
777
778 /**
Tyler Gunnc603b462021-06-14 17:24:40 -0700779 * Sets the camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700780 * <p>
781 * Handled by {@link Connection.VideoProvider#onSetZoom(float)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700782 *
Tyler Gunnc603b462021-06-14 17:24:40 -0700783 * @param value The camera zoom ratio; for the current camera, should be a value in the
784 * range defined by
785 * {@link android.hardware.camera2.CameraCharacteristics#CONTROL_ZOOM_RATIO_RANGE}.
Andrew Lee50aca232014-07-22 16:41:54 -0700786 */
787 public abstract void setZoom(float value);
788
789 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700790 * Issues a request to modify the properties of the current video session.
791 * <p>
792 * Example scenarios include: requesting an audio-only call to be upgraded to a
793 * bi-directional video call, turning on or off the user's camera, sending a pause signal
794 * when the {@link InCallService} is no longer the foreground application.
795 * <p>
796 * Handled by
797 * {@link Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700798 *
799 * @param requestProfile The requested call video properties.
800 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700801 public abstract void sendSessionModifyRequest(VideoProfile requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700802
803 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700804 * Provides a response to a request to change the current call video session
805 * properties. This should be called in response to a request the {@link InCallService} has
806 * received via {@link VideoCall.Callback#onSessionModifyRequestReceived}.
807 * <p>
808 * Handled by
809 * {@link Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700810 *
811 * @param responseProfile The response call video properties.
812 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700813 public abstract void sendSessionModifyResponse(VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700814
815 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700816 * Issues a request to the {@link Connection.VideoProvider} to retrieve the capabilities
817 * of the current camera. The current camera is selected using
818 * {@link VideoCall#setCamera(String)}.
819 * <p>
820 * Camera capabilities are reported to the caller via
821 * {@link VideoCall.Callback#onCameraCapabilitiesChanged(VideoProfile.CameraCapabilities)}.
822 * <p>
823 * Handled by {@link Connection.VideoProvider#onRequestCameraCapabilities()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700824 */
825 public abstract void requestCameraCapabilities();
826
827 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700828 * Issues a request to the {@link Connection.VideoProvider} to retrieve the cumulative data
829 * usage for the video component of the current call (in bytes). Data usage is reported
830 * to the caller via {@link VideoCall.Callback#onCallDataUsageChanged}.
831 * <p>
832 * Handled by {@link Connection.VideoProvider#onRequestConnectionDataUsage()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700833 */
834 public abstract void requestCallDataUsage();
835
836 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700837 * Provides the {@link Connection.VideoProvider} with the {@link Uri} of an image to be
838 * displayed to the peer device when the video signal is paused.
839 * <p>
840 * Handled by {@link Connection.VideoProvider#onSetPauseImage(Uri)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700841 *
842 * @param uri URI of image to display.
843 */
Yorke Lee32f24732015-05-12 16:18:03 -0700844 public abstract void setPauseImage(Uri uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700845
846 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700847 * The {@link InCallService} extends this class to provide a means of receiving callbacks
Tyler Gunn295f5d72015-06-04 11:08:54 -0700848 * from the {@link Connection.VideoProvider}.
849 * <p>
Tyler Gunnb702ef82015-05-29 11:51:53 -0700850 * When the {@link InCallService} receives the
851 * {@link Call.Callback#onVideoCallChanged(Call, VideoCall)} callback, it should create an
852 * instance its {@link VideoCall.Callback} implementation and set it on the
853 * {@link VideoCall} using {@link VideoCall#registerCallback(Callback)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700854 */
Andrew Leeda80c872015-04-15 14:09:50 -0700855 public static abstract class Callback {
Andrew Lee50aca232014-07-22 16:41:54 -0700856 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700857 * Called when the {@link Connection.VideoProvider} receives a session modification
Tyler Gunn295f5d72015-06-04 11:08:54 -0700858 * request from the peer device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700859 * <p>
860 * The {@link InCallService} may potentially prompt the user to confirm whether they
861 * wish to accept the request, or decide to automatically accept the request. In either
862 * case the {@link InCallService} should call
863 * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} to indicate the video
864 * profile agreed upon.
865 * <p>
866 * Callback originates from
867 * {@link Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700868 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700869 * @param videoProfile The requested video profile.
Andrew Lee50aca232014-07-22 16:41:54 -0700870 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700871 public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700872
873 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700874 * Called when the {@link Connection.VideoProvider} receives a response to a session
875 * modification request previously sent to the peer device.
876 * <p>
877 * The new video state should not be considered active by the {@link InCallService}
878 * until the {@link Call} video state changes (the
879 * {@link Call.Callback#onDetailsChanged(Call, Call.Details)} callback is triggered
880 * when the video state changes).
881 * <p>
882 * Callback originates from
883 * {@link Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
884 * VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700885 *
886 * @param status Status of the session modify request. Valid values are
Tyler Gunnb702ef82015-05-29 11:51:53 -0700887 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
888 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
889 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
890 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
891 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}.
892 * @param requestedProfile The original request which was sent to the peer device.
893 * @param responseProfile The actual profile changes made by the peer device.
Andrew Lee50aca232014-07-22 16:41:54 -0700894 */
895 public abstract void onSessionModifyResponseReceived(int status,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700896 VideoProfile requestedProfile, VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700897
898 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700899 * Handles events related to the current video session which the {@link InCallService}
900 * may wish to handle. These are separate from requested changes to the session due to
901 * the underlying protocol or connection.
902 * <p>
903 * Callback originates from
904 * {@link Connection.VideoProvider#handleCallSessionEvent(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700905 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700906 * @param event The event. Valid values are:
907 * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE},
908 * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME},
909 * {@link Connection.VideoProvider#SESSION_EVENT_TX_START},
910 * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP},
911 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800912 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY},
913 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_PERMISSION_ERROR}.
Andrew Lee50aca232014-07-22 16:41:54 -0700914 */
915 public abstract void onCallSessionEvent(int event);
916
917 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700918 * Handles a change to the video dimensions from the peer device. This could happen if,
919 * for example, the peer changes orientation of their device, or switches cameras.
920 * <p>
921 * Callback originates from
922 * {@link Connection.VideoProvider#changePeerDimensions(int, int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700923 *
924 * @param width The updated peer video width.
925 * @param height The updated peer video height.
926 */
927 public abstract void onPeerDimensionsChanged(int width, int height);
928
929 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700930 * Handles a change to the video quality.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700931 * <p>
932 * Callback originates from {@link Connection.VideoProvider#changeVideoQuality(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700933 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700934 * @param videoQuality The updated peer video quality. Valid values:
935 * {@link VideoProfile#QUALITY_HIGH},
936 * {@link VideoProfile#QUALITY_MEDIUM},
937 * {@link VideoProfile#QUALITY_LOW},
938 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700939 */
940 public abstract void onVideoQualityChanged(int videoQuality);
941
942 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700943 * Handles an update to the total data used for the current video session.
944 * <p>
945 * Used by the {@link Connection.VideoProvider} in response to
946 * {@link VideoCall#requestCallDataUsage()}. May also be called periodically by the
947 * {@link Connection.VideoProvider}.
948 * <p>
949 * Callback originates from {@link Connection.VideoProvider#setCallDataUsage(long)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700950 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700951 * @param dataUsage The updated data usage (in bytes).
Andrew Lee50aca232014-07-22 16:41:54 -0700952 */
Rekha Kumar07366812015-03-24 16:42:31 -0700953 public abstract void onCallDataUsageChanged(long dataUsage);
Andrew Lee50aca232014-07-22 16:41:54 -0700954
955 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700956 * Handles a change in the capabilities of the currently selected camera.
957 * <p>
958 * Used by the {@link Connection.VideoProvider} in response to
959 * {@link VideoCall#requestCameraCapabilities()}. The {@link Connection.VideoProvider}
960 * may also report the camera capabilities after a call to
961 * {@link VideoCall#setCamera(String)}.
962 * <p>
963 * Callback originates from
964 * {@link Connection.VideoProvider#changeCameraCapabilities(
965 * VideoProfile.CameraCapabilities)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700966 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700967 * @param cameraCapabilities The changed camera capabilities.
Andrew Lee50aca232014-07-22 16:41:54 -0700968 */
Yorke Lee400470f2015-05-12 13:31:25 -0700969 public abstract void onCameraCapabilitiesChanged(
970 VideoProfile.CameraCapabilities cameraCapabilities);
Andrew Lee50aca232014-07-22 16:41:54 -0700971 }
972 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800973}