blob: cbcd40f15583bb9c27aeba32eccd26b7417bfeec [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;
Hall Liua98f58b52017-11-07 17:59:28 -080023import android.bluetooth.BluetoothDevice;
Santos Cordon2f42b112014-07-19 13:19:37 -070024import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070025import android.hardware.camera2.CameraManager;
Yorke Lee32f24732015-05-12 16:18:03 -070026import android.net.Uri;
Tyler Gunn876dbfb2016-03-14 15:18:07 -070027import android.os.Bundle;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080028import android.os.Handler;
29import android.os.IBinder;
30import android.os.Looper;
31import android.os.Message;
Andrew Lee50aca232014-07-22 16:41:54 -070032import android.view.Surface;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080033
Ihab Awad2f236642014-03-10 15:33:45 -070034import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070035import com.android.internal.telecom.IInCallAdapter;
36import com.android.internal.telecom.IInCallService;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080037
Santos Cordona2492812015-04-15 11:05:16 -070038import java.util.Collections;
39import java.util.List;
Andrew Lee50aca232014-07-22 16:41:54 -070040
Sailesh Nepalab5d2822014-03-08 18:01:06 -080041/**
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -080042 * This service is implemented by an app that wishes to provide functionality for managing
43 * phone calls.
44 * <p>
45 * There are three types of apps which Telecom can bind to when there exists a live (active or
46 * incoming) call:
47 * <ol>
48 * <li>Default Dialer/Phone app - the default dialer/phone app is one which provides the
49 * in-call user interface while the device is in a call. A device is bundled with a system
50 * provided default dialer/phone app. The user may choose a single app to take over this role
51 * from the system app.</li>
52 * <li>Default Car-mode Dialer/Phone app - the default car-mode dialer/phone app is one which
53 * provides the in-call user interface while the device is in a call and the device is in car
54 * mode. The user may choose a single app to fill this role.</li>
55 * <li>Call Companion app - a call companion app is one which provides no user interface itself,
56 * but exposes call information to another display surface, such as a wearable device. The
57 * user may choose multiple apps to fill this role.</li>
58 * </ol>
59 * <p>
60 * Apps which wish to fulfill one of the above roles use the {@link android.app.role.RoleManager}
61 * to request that they fill the desired role.
62 *
63 * <h2>Becoming the Default Phone App</h2>
64 * An app filling the role of the default phone app provides a user interface while the device is in
65 * a call, and the device is not in car mode.
Santos Cordonf2600eb2015-06-22 15:02:20 -070066 * <p>
67 * Below is an example manifest registration for an {@code InCallService}. The meta-data
Tyler Gunndc6e6c42018-07-03 16:08:17 -070068 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_UI} indicates that this particular
Santos Cordonf2600eb2015-06-22 15:02:20 -070069 * {@code InCallService} implementation intends to replace the built-in in-call UI.
Tyler Gunndc6e6c42018-07-03 16:08:17 -070070 * The meta-data {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} indicates that this
71 * {@link InCallService} will play the ringtone for incoming calls. See
72 * <a href="#incomingCallNotification">below</a> for more information on showing the incoming call
73 * UI and playing the ringtone in your app.
Santos Cordonf2600eb2015-06-22 15:02:20 -070074 * <pre>
75 * {@code
Neil Fuller71fbb812015-11-30 09:51:33 +000076 * <service android:name="your.package.YourInCallServiceImplementation"
Sailesh Nepal78f3ba62015-12-28 16:20:56 -080077 * android:permission="android.permission.BIND_INCALL_SERVICE">
Neil Fuller71fbb812015-11-30 09:51:33 +000078 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
Tyler Gunndc6e6c42018-07-03 16:08:17 -070079 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_RINGING"
80 * android:value="true" />
Neil Fuller71fbb812015-11-30 09:51:33 +000081 * <intent-filter>
82 * <action android:name="android.telecom.InCallService"/>
83 * </intent-filter>
84 * </service>
Santos Cordonf2600eb2015-06-22 15:02:20 -070085 * }
86 * </pre>
Tyler Gunnfe39efa2018-02-02 13:18:02 -080087 * <p>
88 * In addition to implementing the {@link InCallService} API, you must also declare an activity in
89 * your manifest which handles the {@link Intent#ACTION_DIAL} intent. The example below illustrates
90 * how this is done:
91 * <pre>
92 * {@code
93 * <activity android:name="your.package.YourDialerActivity"
94 * android:label="@string/yourDialerActivityLabel">
95 * <intent-filter>
96 * <action android:name="android.intent.action.DIAL" />
97 * <category android:name="android.intent.category.DEFAULT" />
98 * </intent-filter>
99 * </activity>
100 * }
101 * </pre>
102 * <p>
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800103 * When a user installs your application and runs it for the first time, you should use the
104 * {@link android.app.role.RoleManager} to prompt the user to see if they would like your app to
105 * be the new default phone app.
106 * <p id="requestRole">
107 * The code below shows how your app can request to become the default phone/dialer app:
108 * <pre>
109 * {@code
110 * private static final int REQUEST_ID = 1;
111 *
112 * public void requestRole() {
113 * RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
114 * Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_DIALER);
115 * startActivityForResult(intent, REQUEST_ID);
116 * }
117 *
118 * &#64;Override
119 * public void onActivityResult(int requestCode, int resultCode, Intent data) {
120 * if (requestCode == REQUEST_ID) {
121 * if (resultCode == android.app.Activity.RESULT_OK) {
122 * // Your app is now the default dialer app
123 * } else {
124 * // Your app is not the default dialer app
125 * }
126 * }
127 * }
128 * </pre>
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700129 * <p id="incomingCallNotification">
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800130 * <h3>Showing the Incoming Call Notification</h3>
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700131 * When your app receives a new incoming call via {@link InCallService#onCallAdded(Call)}, it is
132 * responsible for displaying an incoming call UI for the incoming call. It should do this using
133 * {@link android.app.NotificationManager} APIs to post a new incoming call notification.
134 * <p>
135 * Where your app declares the meta-data {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING}, it
136 * is responsible for playing the ringtone for incoming calls. Your app should create a
137 * {@link android.app.NotificationChannel} which specifies the desired ringtone. For example:
138 * <pre><code>
139 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
140 * NotificationManager.IMPORTANCE_MAX);
141 * // other channel setup stuff goes here.
142 *
143 * // We'll use the default system ringtone for our incoming call notification channel. You can
144 * // use your own audio resource here.
145 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
146 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
147 * // Setting the AudioAttributes is important as it identifies the purpose of your
148 * // notification sound.
149 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
150 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
151 * .build());
152 *
153 * NotificationManager mgr = getSystemService(NotificationManager.class);
154 * mgr.createNotificationChannel(channel);
155 * </code></pre>
156 * <p>
157 * When your app receives a new incoming call, it creates a {@link android.app.Notification} for the
158 * incoming call and associates it with your incoming call notification channel. You can specify a
159 * {@link android.app.PendingIntent} on the notification which will launch your full screen
160 * incoming call UI. The notification manager framework will display your notification as a
161 * heads-up notification if the user is actively using the phone. When the user is not using the
162 * phone, your full-screen incoming call UI is used instead.
163 * For example:
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800164 * <pre><code>{@code
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700165 * // Create an intent which triggers your fullscreen incoming call user interface.
166 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
167 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
168 * intent.setClass(context, YourIncomingCallActivity.class);
169 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
170 *
171 * // Build the notification as an ongoing high priority item; this ensures it will show as
172 * // a heads up notification which slides down over top of the current content.
173 * final Notification.Builder builder = new Notification.Builder(context);
174 * builder.setOngoing(true);
175 * builder.setPriority(Notification.PRIORITY_HIGH);
176 *
177 * // Set notification content intent to take user to the fullscreen UI if user taps on the
178 * // notification body.
179 * builder.setContentIntent(pendingIntent);
180 * // Set full screen intent to trigger display of the fullscreen UI when the notification
181 * // manager deems it appropriate.
182 * builder.setFullScreenIntent(pendingIntent, true);
183 *
184 * // Setup notification content.
185 * builder.setSmallIcon( yourIconResourceId );
186 * builder.setContentTitle("Your notification title");
187 * builder.setContentText("Your notification content.");
188 *
189 * // Use builder.addAction(..) to add buttons to answer or reject the call.
190 *
191 * NotificationManager notificationManager = mContext.getSystemService(
192 * NotificationManager.class);
193 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, builder.build());
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800194 * }</pre>
195 * <p>
196 * <h2>Becoming the Default Car-mode Phone App</h2>
197 * An app filling the role of the default car-mode dialer/phone app provides a user interface while
198 * the device is in a call, and in car mode. See
199 * {@link android.app.UiModeManager#ACTION_ENTER_CAR_MODE} for more information about car mode.
200 * When the device is in car mode, Telecom binds to the default car-mode dialer/phone app instead
201 * of the usual dialer/phone app.
202 * <p>
203 * Similar to the requirements for becoming the default dialer/phone app, your app must declare a
204 * manifest entry for its {@link InCallService} implementation. Your manifest entry should ensure
205 * the following conditions are met:
206 * <ul>
207 * <li>Do NOT declare the {@link TelecomManager#METADATA_IN_CALL_SERVICE_UI} metadata.</li>
208 * <li>Set the {@link TelecomManager#METADATA_IN_CALL_SERVICE_CAR_MODE_UI} metadata to
209 * {@code true}<li>
210 * <li>Your app must request the permission
211 * {@link android.Manifest.permission.CALL_COMPANION_APP}.</li>
212 * </ul>
213 * <p>
Hai Zhangb0146d72019-02-06 16:32:23 -0800214 * Your app should request to fill the role {@code android.app.role.CAR_MODE_DIALER} in order to
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800215 * become the default (see <a href="#requestRole">above</a> for how to request your app fills this
216 * role).
217 *
218 * <h2>Becoming a Call Companion App</h2>
219 * An app which fills the companion app role does not directly provide a user interface while the
220 * device is in a call. Instead, it is typically used to relay information about calls to another
221 * display surface, such as a wearable device.
222 * <p>
223 * Similar to the requirements for becoming the default dialer/phone app, your app must declare a
224 * manifest entry for its {@link InCallService} implementation. Your manifest entry should
225 * ensure the following conditions are met:
226 * <ul>
227 * <li>Do NOT declare the {@link TelecomManager#METADATA_IN_CALL_SERVICE_UI} metadata.</li>
228 * <li>Do NOT declare the {@link TelecomManager#METADATA_IN_CALL_SERVICE_CAR_MODE_UI}
229 * metadata.</li>
230 * <li>Your app must request the permission
231 * {@link android.Manifest.permission.CALL_COMPANION_APP}.</li>
232 * </ul>
233 * <p>
Hai Zhangb0146d72019-02-06 16:32:23 -0800234 * Your app should request to fill the role {@code android.app.role.CALL_COMPANION} in order to
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800235 * become a call companion app (see <a href="#requestRole">above</a> for how to request your app
236 * fills this role).
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800237 */
Santos Cordon2f42b112014-07-19 13:19:37 -0700238public abstract class InCallService extends Service {
Tyler Gunn2ac40102014-08-18 16:23:10 -0700239
240 /**
241 * The {@link Intent} that must be declared as handled by the service.
242 */
243 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700244 public static final String SERVICE_INTERFACE = "android.telecom.InCallService";
Tyler Gunn2ac40102014-08-18 16:23:10 -0700245
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800246 private static final int MSG_SET_IN_CALL_ADAPTER = 1;
247 private static final int MSG_ADD_CALL = 2;
Sailesh Nepal60437932014-04-05 16:44:55 -0700248 private static final int MSG_UPDATE_CALL = 3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700249 private static final int MSG_SET_POST_DIAL_WAIT = 4;
Yorke Lee4af59352015-05-13 14:14:54 -0700250 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 5;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700251 private static final int MSG_BRING_TO_FOREGROUND = 6;
Santos Cordon6c912b72014-11-07 16:05:09 -0800252 private static final int MSG_ON_CAN_ADD_CALL_CHANGED = 7;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800253 private static final int MSG_SILENCE_RINGER = 8;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700254 private static final int MSG_ON_CONNECTION_EVENT = 9;
Hall Liu95d55872017-01-25 17:12:49 -0800255 private static final int MSG_ON_RTT_UPGRADE_REQUEST = 10;
Hall Liu57006aa2017-02-06 10:49:48 -0800256 private static final int MSG_ON_RTT_INITIATION_FAILURE = 11;
Sanket Padawe85291f62017-12-01 13:59:27 -0800257 private static final int MSG_ON_HANDOVER_FAILED = 12;
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800258 private static final int MSG_ON_HANDOVER_COMPLETE = 13;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800259
260 /** Default Handler used to consolidate binder method calls onto a single thread. */
261 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
262 @Override
263 public void handleMessage(Message msg) {
Jay Shrauner5e6162d2014-09-22 20:47:45 -0700264 if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) {
265 return;
266 }
267
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800268 switch (msg.what) {
269 case MSG_SET_IN_CALL_ADAPTER:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800270 String callingPackage = getApplicationContext().getOpPackageName();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800271 mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj), callingPackage,
272 getApplicationContext().getApplicationInfo().targetSdkVersion);
Santos Cordona2492812015-04-15 11:05:16 -0700273 mPhone.addListener(mPhoneListener);
Ihab Awade63fadb2014-07-09 21:52:04 -0700274 onPhoneCreated(mPhone);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800275 break;
276 case MSG_ADD_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700277 mPhone.internalAddCall((ParcelableCall) msg.obj);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800278 break;
Sailesh Nepal60437932014-04-05 16:44:55 -0700279 case MSG_UPDATE_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700280 mPhone.internalUpdateCall((ParcelableCall) msg.obj);
Ihab Awad2f236642014-03-10 15:33:45 -0700281 break;
Ihab Awad2f236642014-03-10 15:33:45 -0700282 case MSG_SET_POST_DIAL_WAIT: {
283 SomeArgs args = (SomeArgs) msg.obj;
284 try {
285 String callId = (String) args.arg1;
286 String remaining = (String) args.arg2;
Ihab Awade63fadb2014-07-09 21:52:04 -0700287 mPhone.internalSetPostDialWait(callId, remaining);
Ihab Awad2f236642014-03-10 15:33:45 -0700288 } finally {
289 args.recycle();
290 }
291 break;
292 }
Yorke Lee4af59352015-05-13 14:14:54 -0700293 case MSG_ON_CALL_AUDIO_STATE_CHANGED:
294 mPhone.internalCallAudioStateChanged((CallAudioState) msg.obj);
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700295 break;
Santos Cordon3534ede2014-05-29 13:07:10 -0700296 case MSG_BRING_TO_FOREGROUND:
Ihab Awade63fadb2014-07-09 21:52:04 -0700297 mPhone.internalBringToForeground(msg.arg1 == 1);
Santos Cordon3534ede2014-05-29 13:07:10 -0700298 break;
Santos Cordon6c912b72014-11-07 16:05:09 -0800299 case MSG_ON_CAN_ADD_CALL_CHANGED:
300 mPhone.internalSetCanAddCall(msg.arg1 == 1);
301 break;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800302 case MSG_SILENCE_RINGER:
303 mPhone.internalSilenceRinger();
304 break;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700305 case MSG_ON_CONNECTION_EVENT: {
306 SomeArgs args = (SomeArgs) msg.obj;
307 try {
308 String callId = (String) args.arg1;
309 String event = (String) args.arg2;
310 Bundle extras = (Bundle) args.arg3;
311 mPhone.internalOnConnectionEvent(callId, event, extras);
312 } finally {
313 args.recycle();
314 }
315 break;
316 }
Hall Liu95d55872017-01-25 17:12:49 -0800317 case MSG_ON_RTT_UPGRADE_REQUEST: {
318 String callId = (String) msg.obj;
319 int requestId = msg.arg1;
320 mPhone.internalOnRttUpgradeRequest(callId, requestId);
321 break;
322 }
Hall Liu57006aa2017-02-06 10:49:48 -0800323 case MSG_ON_RTT_INITIATION_FAILURE: {
324 String callId = (String) msg.obj;
325 int reason = msg.arg1;
326 mPhone.internalOnRttInitiationFailure(callId, reason);
327 break;
328 }
Sanket Padawe85291f62017-12-01 13:59:27 -0800329 case MSG_ON_HANDOVER_FAILED: {
330 String callId = (String) msg.obj;
331 int error = msg.arg1;
332 mPhone.internalOnHandoverFailed(callId, error);
333 break;
334 }
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800335 case MSG_ON_HANDOVER_COMPLETE: {
336 String callId = (String) msg.obj;
337 mPhone.internalOnHandoverComplete(callId);
338 break;
339 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800340 default:
341 break;
342 }
343 }
344 };
345
346 /** Manages the binder calls so that the implementor does not need to deal with it. */
347 private final class InCallServiceBinder extends IInCallService.Stub {
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800348 @Override
349 public void setInCallAdapter(IInCallAdapter inCallAdapter) {
350 mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget();
351 }
352
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800353 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700354 public void addCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700355 mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800356 }
357
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800358 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700359 public void updateCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700360 mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
Ihab Awad2f236642014-03-10 15:33:45 -0700361 }
362
363 @Override
364 public void setPostDial(String callId, String remaining) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700365 // TODO: Unused
Ihab Awad2f236642014-03-10 15:33:45 -0700366 }
367
368 @Override
369 public void setPostDialWait(String callId, String remaining) {
370 SomeArgs args = SomeArgs.obtain();
371 args.arg1 = callId;
372 args.arg2 = remaining;
373 mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
374 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700375
376 @Override
Yorke Lee4af59352015-05-13 14:14:54 -0700377 public void onCallAudioStateChanged(CallAudioState callAudioState) {
378 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, callAudioState).sendToTarget();
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700379 }
Santos Cordon3534ede2014-05-29 13:07:10 -0700380
Santos Cordon3534ede2014-05-29 13:07:10 -0700381 @Override
382 public void bringToForeground(boolean showDialpad) {
383 mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
384 }
Santos Cordon6c912b72014-11-07 16:05:09 -0800385
386 @Override
387 public void onCanAddCallChanged(boolean canAddCall) {
388 mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0)
389 .sendToTarget();
390 }
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800391
392 @Override
393 public void silenceRinger() {
394 mHandler.obtainMessage(MSG_SILENCE_RINGER).sendToTarget();
395 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700396
397 @Override
398 public void onConnectionEvent(String callId, String event, Bundle extras) {
399 SomeArgs args = SomeArgs.obtain();
400 args.arg1 = callId;
401 args.arg2 = event;
402 args.arg3 = extras;
403 mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget();
404 }
Hall Liu95d55872017-01-25 17:12:49 -0800405
406 @Override
407 public void onRttUpgradeRequest(String callId, int id) {
408 mHandler.obtainMessage(MSG_ON_RTT_UPGRADE_REQUEST, id, 0, callId).sendToTarget();
409 }
Hall Liu57006aa2017-02-06 10:49:48 -0800410
411 @Override
412 public void onRttInitiationFailure(String callId, int reason) {
413 mHandler.obtainMessage(MSG_ON_RTT_INITIATION_FAILURE, reason, 0, callId).sendToTarget();
414 }
Sanket Padawe85291f62017-12-01 13:59:27 -0800415
416 @Override
417 public void onHandoverFailed(String callId, int error) {
418 mHandler.obtainMessage(MSG_ON_HANDOVER_FAILED, error, 0, callId).sendToTarget();
419 }
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800420
421 @Override
422 public void onHandoverComplete(String callId) {
423 mHandler.obtainMessage(MSG_ON_HANDOVER_COMPLETE, callId).sendToTarget();
424 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800425 }
426
Santos Cordona2492812015-04-15 11:05:16 -0700427 private Phone.Listener mPhoneListener = new Phone.Listener() {
428 /** ${inheritDoc} */
429 @Override
430 public void onAudioStateChanged(Phone phone, AudioState audioState) {
431 InCallService.this.onAudioStateChanged(audioState);
432 }
433
Yorke Lee4af59352015-05-13 14:14:54 -0700434 public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) {
435 InCallService.this.onCallAudioStateChanged(callAudioState);
436 };
437
Santos Cordona2492812015-04-15 11:05:16 -0700438 /** ${inheritDoc} */
439 @Override
440 public void onBringToForeground(Phone phone, boolean showDialpad) {
441 InCallService.this.onBringToForeground(showDialpad);
442 }
443
444 /** ${inheritDoc} */
445 @Override
446 public void onCallAdded(Phone phone, Call call) {
447 InCallService.this.onCallAdded(call);
448 }
449
450 /** ${inheritDoc} */
451 @Override
452 public void onCallRemoved(Phone phone, Call call) {
453 InCallService.this.onCallRemoved(call);
454 }
455
456 /** ${inheritDoc} */
457 @Override
458 public void onCanAddCallChanged(Phone phone, boolean canAddCall) {
459 InCallService.this.onCanAddCallChanged(canAddCall);
460 }
461
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800462 /** ${inheritDoc} */
463 @Override
464 public void onSilenceRinger(Phone phone) {
465 InCallService.this.onSilenceRinger();
466 }
467
Santos Cordona2492812015-04-15 11:05:16 -0700468 };
469
Ihab Awade63fadb2014-07-09 21:52:04 -0700470 private Phone mPhone;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800471
Santos Cordon2f42b112014-07-19 13:19:37 -0700472 public InCallService() {
473 }
Evan Charlton924748f2014-04-03 08:36:38 -0700474
Santos Cordon2f42b112014-07-19 13:19:37 -0700475 @Override
476 public IBinder onBind(Intent intent) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700477 return new InCallServiceBinder();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800478 }
479
Santos Cordonf30d7e92014-08-26 09:54:33 -0700480 @Override
481 public boolean onUnbind(Intent intent) {
Santos Cordon619b3c02014-09-02 17:13:45 -0700482 if (mPhone != null) {
483 Phone oldPhone = mPhone;
484 mPhone = null;
Santos Cordonf30d7e92014-08-26 09:54:33 -0700485
Santos Cordon619b3c02014-09-02 17:13:45 -0700486 oldPhone.destroy();
Santos Cordona2492812015-04-15 11:05:16 -0700487 // destroy sets all the calls to disconnected if any live ones still exist. Therefore,
488 // it is important to remove the Listener *after* the call to destroy so that
489 // InCallService.on* callbacks are appropriately called.
490 oldPhone.removeListener(mPhoneListener);
491
Santos Cordon619b3c02014-09-02 17:13:45 -0700492 onPhoneDestroyed(oldPhone);
493 }
Santos Cordona2492812015-04-15 11:05:16 -0700494
Santos Cordonf30d7e92014-08-26 09:54:33 -0700495 return false;
496 }
497
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800498 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700499 * Obtain the {@code Phone} associated with this {@code InCallService}.
500 *
501 * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null}
Santos Cordon2f42b112014-07-19 13:19:37 -0700502 * if the {@code InCallService} is not in a state where it has an associated
503 * {@code Phone}.
Santos Cordona2492812015-04-15 11:05:16 -0700504 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700505 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800506 */
Santos Cordona2492812015-04-15 11:05:16 -0700507 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700508 @Deprecated
509 public Phone getPhone() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700510 return mPhone;
Evan Charlton924748f2014-04-03 08:36:38 -0700511 }
512
513 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700514 * Obtains the current list of {@code Call}s to be displayed by this in-call service.
Santos Cordona2492812015-04-15 11:05:16 -0700515 *
516 * @return A list of the relevant {@code Call}s.
517 */
518 public final List<Call> getCalls() {
519 return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls();
520 }
521
522 /**
523 * Returns if the device can support additional calls.
524 *
525 * @return Whether the phone supports adding more calls.
526 */
527 public final boolean canAddCall() {
528 return mPhone == null ? false : mPhone.canAddCall();
529 }
530
531 /**
532 * Obtains the current phone call audio state.
533 *
534 * @return An object encapsulating the audio state. Returns null if the service is not
535 * fully initialized.
Yorke Lee4af59352015-05-13 14:14:54 -0700536 * @deprecated Use {@link #getCallAudioState()} instead.
537 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700538 */
Yorke Lee4af59352015-05-13 14:14:54 -0700539 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700540 public final AudioState getAudioState() {
541 return mPhone == null ? null : mPhone.getAudioState();
542 }
543
544 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700545 * 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.
549 */
550 public final CallAudioState getCallAudioState() {
551 return mPhone == null ? null : mPhone.getCallAudioState();
552 }
553
554 /**
Santos Cordona2492812015-04-15 11:05:16 -0700555 * Sets the microphone mute state. When this request is honored, there will be change to
Yorke Lee4af59352015-05-13 14:14:54 -0700556 * the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700557 *
558 * @param state {@code true} if the microphone should be muted; {@code false} otherwise.
559 */
560 public final void setMuted(boolean state) {
561 if (mPhone != null) {
562 mPhone.setMuted(state);
563 }
564 }
565
566 /**
567 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
Yorke Lee4af59352015-05-13 14:14:54 -0700568 * be change to the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700569 *
570 * @param route The audio route to use.
571 */
572 public final void setAudioRoute(int route) {
573 if (mPhone != null) {
574 mPhone.setAudioRoute(route);
575 }
576 }
577
578 /**
Hall Liua98f58b52017-11-07 17:59:28 -0800579 * Request audio routing to a specific bluetooth device. Calling this method may result in
580 * the device routing audio to a different bluetooth device than the one specified if the
581 * bluetooth stack is unable to route audio to the requested device.
582 * A list of available devices can be obtained via
583 * {@link CallAudioState#getSupportedBluetoothDevices()}
584 *
Hall Liu15392832018-04-02 13:52:57 -0700585 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -0800586 */
Hall Liu15392832018-04-02 13:52:57 -0700587 public final void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -0800588 if (mPhone != null) {
Hall Liu15392832018-04-02 13:52:57 -0700589 mPhone.requestBluetoothAudio(bluetoothDevice.getAddress());
Hall Liua98f58b52017-11-07 17:59:28 -0800590 }
591 }
592
593 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700594 * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience
595 * to start displaying in-call information to the user. Each instance of {@code InCallService}
Santos Cordon2f42b112014-07-19 13:19:37 -0700596 * will have only one {@code Phone}, and this method will be called exactly once in the lifetime
597 * of the {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700598 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700599 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700600 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700601 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Evan Charlton924748f2014-04-03 08:36:38 -0700602 */
Santos Cordona2492812015-04-15 11:05:16 -0700603 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700604 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700605 public void onPhoneCreated(Phone phone) {
606 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800607
608 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700609 * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience
610 * to stop displaying in-call information to the user. This method will be called exactly once
611 * in the lifetime of the {@code InCallService}, and it will always be called after a previous
612 * call to {@link #onPhoneCreated(Phone)}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800613 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700614 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700615 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700616 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800617 */
Santos Cordona2492812015-04-15 11:05:16 -0700618 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700619 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700620 public void onPhoneDestroyed(Phone phone) {
621 }
Andrew Lee50aca232014-07-22 16:41:54 -0700622
623 /**
Santos Cordona2492812015-04-15 11:05:16 -0700624 * Called when the audio state changes.
625 *
626 * @param audioState The new {@link AudioState}.
Yorke Lee4af59352015-05-13 14:14:54 -0700627 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState) instead}.
628 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700629 */
Yorke Lee4af59352015-05-13 14:14:54 -0700630 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700631 public void onAudioStateChanged(AudioState audioState) {
632 }
633
634 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700635 * Called when the audio state changes.
636 *
637 * @param audioState The new {@link CallAudioState}.
638 */
639 public void onCallAudioStateChanged(CallAudioState audioState) {
640 }
641
642 /**
Santos Cordona2492812015-04-15 11:05:16 -0700643 * Called to bring the in-call screen to the foreground. The in-call experience should
644 * respond immediately by coming to the foreground to inform the user of the state of
645 * ongoing {@code Call}s.
646 *
647 * @param showDialpad If true, put up the dialpad when the screen is shown.
648 */
649 public void onBringToForeground(boolean showDialpad) {
650 }
651
652 /**
653 * Called when a {@code Call} has been added to this in-call session. The in-call user
654 * experience should add necessary state listeners to the specified {@code Call} and
655 * immediately start to show the user information about the existence
656 * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will
657 * include this {@code Call}.
658 *
659 * @param call A newly added {@code Call}.
660 */
661 public void onCallAdded(Call call) {
662 }
663
664 /**
665 * Called when a {@code Call} has been removed from this in-call session. The in-call user
666 * experience should remove any state listeners from the specified {@code Call} and
667 * immediately stop displaying any information about this {@code Call}.
668 * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}.
669 *
670 * @param call A newly removed {@code Call}.
671 */
672 public void onCallRemoved(Call call) {
673 }
674
675 /**
676 * Called when the ability to add more calls changes. If the phone cannot
677 * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it
678 * is set to {@code true}. This can be used to control the visibility of UI to add more calls.
679 *
680 * @param canAddCall Indicates whether an additional call can be added.
681 */
682 public void onCanAddCallChanged(boolean canAddCall) {
683 }
684
685 /**
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800686 * Called to silence the ringer if a ringing call exists.
687 */
688 public void onSilenceRinger() {
689 }
690
691 /**
Tyler Gunn06f3fa62016-08-25 09:26:15 -0700692 * Unused; to handle connection events issued by a {@link ConnectionService}, implement the
693 * {@link android.telecom.Call.Callback#onConnectionEvent(Call, String, Bundle)} callback.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700694 * <p>
695 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
696 *
697 * @param call The call the event is associated with.
698 * @param event The event.
699 * @param extras Any associated extras.
700 */
701 public void onConnectionEvent(Call call, String event, Bundle extras) {
702 }
703
704 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700705 * Used to issue commands to the {@link Connection.VideoProvider} associated with a
706 * {@link Call}.
Andrew Lee50aca232014-07-22 16:41:54 -0700707 */
708 public static abstract class VideoCall {
709
Andrew Lee011728f2015-04-23 15:47:06 -0700710 /** @hide */
711 public abstract void destroy();
712
Andrew Lee50aca232014-07-22 16:41:54 -0700713 /**
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700714 * Registers a callback to receive commands and state changes for video calls.
Andrew Lee50aca232014-07-22 16:41:54 -0700715 *
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700716 * @param callback The video call callback.
Andrew Lee50aca232014-07-22 16:41:54 -0700717 */
Andrew Leeda80c872015-04-15 14:09:50 -0700718 public abstract void registerCallback(VideoCall.Callback callback);
719
720 /**
Andrew Lee011728f2015-04-23 15:47:06 -0700721 * Registers a callback to receive commands and state changes for video calls.
722 *
723 * @param callback The video call callback.
724 * @param handler A handler which commands and status changes will be delivered to.
725 */
726 public abstract void registerCallback(VideoCall.Callback callback, Handler handler);
727
728 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700729 * Clears the video call callback set via {@link #registerCallback}.
Tyler Gunn295f5d72015-06-04 11:08:54 -0700730 *
731 * @param callback The video call callback to clear.
Tyler Gunn75958422015-04-15 14:23:42 -0700732 */
Andrew Lee011728f2015-04-23 15:47:06 -0700733 public abstract void unregisterCallback(VideoCall.Callback callback);
Tyler Gunn75958422015-04-15 14:23:42 -0700734
735 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700736 * Sets the camera to be used for the outgoing video.
737 * <p>
738 * Handled by {@link Connection.VideoProvider#onSetCamera(String)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700739 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700740 * @param cameraId The id of the camera (use ids as reported by
741 * {@link CameraManager#getCameraIdList()}).
Andrew Lee50aca232014-07-22 16:41:54 -0700742 */
743 public abstract void setCamera(String cameraId);
744
745 /**
746 * Sets the surface to be used for displaying a preview of what the user's camera is
747 * currently capturing. When video transmission is enabled, this is the video signal which
748 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700749 * <p>
750 * Handled by {@link Connection.VideoProvider#onSetPreviewSurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700751 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700752 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700753 */
754 public abstract void setPreviewSurface(Surface surface);
755
756 /**
757 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700758 * <p>
759 * Handled by {@link Connection.VideoProvider#onSetDisplaySurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700760 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700761 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700762 */
763 public abstract void setDisplaySurface(Surface surface);
764
765 /**
766 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
767 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700768 * <p>
769 * Handled by {@link Connection.VideoProvider#onSetDeviceOrientation(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700770 *
771 * @param rotation The device orientation, in degrees.
772 */
773 public abstract void setDeviceOrientation(int rotation);
774
775 /**
776 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700777 * <p>
778 * Handled by {@link Connection.VideoProvider#onSetZoom(float)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700779 *
780 * @param value The camera zoom ratio.
781 */
782 public abstract void setZoom(float value);
783
784 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700785 * Issues a request to modify the properties of the current video session.
786 * <p>
787 * Example scenarios include: requesting an audio-only call to be upgraded to a
788 * bi-directional video call, turning on or off the user's camera, sending a pause signal
789 * when the {@link InCallService} is no longer the foreground application.
790 * <p>
791 * Handled by
792 * {@link Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700793 *
794 * @param requestProfile The requested call video properties.
795 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700796 public abstract void sendSessionModifyRequest(VideoProfile requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700797
798 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700799 * Provides a response to a request to change the current call video session
800 * properties. This should be called in response to a request the {@link InCallService} has
801 * received via {@link VideoCall.Callback#onSessionModifyRequestReceived}.
802 * <p>
803 * Handled by
804 * {@link Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700805 *
806 * @param responseProfile The response call video properties.
807 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700808 public abstract void sendSessionModifyResponse(VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700809
810 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700811 * Issues a request to the {@link Connection.VideoProvider} to retrieve the capabilities
812 * of the current camera. The current camera is selected using
813 * {@link VideoCall#setCamera(String)}.
814 * <p>
815 * Camera capabilities are reported to the caller via
816 * {@link VideoCall.Callback#onCameraCapabilitiesChanged(VideoProfile.CameraCapabilities)}.
817 * <p>
818 * Handled by {@link Connection.VideoProvider#onRequestCameraCapabilities()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700819 */
820 public abstract void requestCameraCapabilities();
821
822 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700823 * Issues a request to the {@link Connection.VideoProvider} to retrieve the cumulative data
824 * usage for the video component of the current call (in bytes). Data usage is reported
825 * to the caller via {@link VideoCall.Callback#onCallDataUsageChanged}.
826 * <p>
827 * Handled by {@link Connection.VideoProvider#onRequestConnectionDataUsage()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700828 */
829 public abstract void requestCallDataUsage();
830
831 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700832 * Provides the {@link Connection.VideoProvider} with the {@link Uri} of an image to be
833 * displayed to the peer device when the video signal is paused.
834 * <p>
835 * Handled by {@link Connection.VideoProvider#onSetPauseImage(Uri)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700836 *
837 * @param uri URI of image to display.
838 */
Yorke Lee32f24732015-05-12 16:18:03 -0700839 public abstract void setPauseImage(Uri uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700840
841 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700842 * The {@link InCallService} extends this class to provide a means of receiving callbacks
Tyler Gunn295f5d72015-06-04 11:08:54 -0700843 * from the {@link Connection.VideoProvider}.
844 * <p>
Tyler Gunnb702ef82015-05-29 11:51:53 -0700845 * When the {@link InCallService} receives the
846 * {@link Call.Callback#onVideoCallChanged(Call, VideoCall)} callback, it should create an
847 * instance its {@link VideoCall.Callback} implementation and set it on the
848 * {@link VideoCall} using {@link VideoCall#registerCallback(Callback)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700849 */
Andrew Leeda80c872015-04-15 14:09:50 -0700850 public static abstract class Callback {
Andrew Lee50aca232014-07-22 16:41:54 -0700851 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700852 * Called when the {@link Connection.VideoProvider} receives a session modification
Tyler Gunn295f5d72015-06-04 11:08:54 -0700853 * request from the peer device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700854 * <p>
855 * The {@link InCallService} may potentially prompt the user to confirm whether they
856 * wish to accept the request, or decide to automatically accept the request. In either
857 * case the {@link InCallService} should call
858 * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} to indicate the video
859 * profile agreed upon.
860 * <p>
861 * Callback originates from
862 * {@link Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700863 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700864 * @param videoProfile The requested video profile.
Andrew Lee50aca232014-07-22 16:41:54 -0700865 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700866 public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700867
868 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700869 * Called when the {@link Connection.VideoProvider} receives a response to a session
870 * modification request previously sent to the peer device.
871 * <p>
872 * The new video state should not be considered active by the {@link InCallService}
873 * until the {@link Call} video state changes (the
874 * {@link Call.Callback#onDetailsChanged(Call, Call.Details)} callback is triggered
875 * when the video state changes).
876 * <p>
877 * Callback originates from
878 * {@link Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
879 * VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700880 *
881 * @param status Status of the session modify request. Valid values are
Tyler Gunnb702ef82015-05-29 11:51:53 -0700882 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
883 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
884 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
885 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
886 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}.
887 * @param requestedProfile The original request which was sent to the peer device.
888 * @param responseProfile The actual profile changes made by the peer device.
Andrew Lee50aca232014-07-22 16:41:54 -0700889 */
890 public abstract void onSessionModifyResponseReceived(int status,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700891 VideoProfile requestedProfile, VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700892
893 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700894 * Handles events related to the current video session which the {@link InCallService}
895 * may wish to handle. These are separate from requested changes to the session due to
896 * the underlying protocol or connection.
897 * <p>
898 * Callback originates from
899 * {@link Connection.VideoProvider#handleCallSessionEvent(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700900 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700901 * @param event The event. Valid values are:
902 * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE},
903 * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME},
904 * {@link Connection.VideoProvider#SESSION_EVENT_TX_START},
905 * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP},
906 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800907 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY},
908 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_PERMISSION_ERROR}.
Andrew Lee50aca232014-07-22 16:41:54 -0700909 */
910 public abstract void onCallSessionEvent(int event);
911
912 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700913 * Handles a change to the video dimensions from the peer device. This could happen if,
914 * for example, the peer changes orientation of their device, or switches cameras.
915 * <p>
916 * Callback originates from
917 * {@link Connection.VideoProvider#changePeerDimensions(int, int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700918 *
919 * @param width The updated peer video width.
920 * @param height The updated peer video height.
921 */
922 public abstract void onPeerDimensionsChanged(int width, int height);
923
924 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700925 * Handles a change to the video quality.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700926 * <p>
927 * Callback originates from {@link Connection.VideoProvider#changeVideoQuality(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700928 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700929 * @param videoQuality The updated peer video quality. Valid values:
930 * {@link VideoProfile#QUALITY_HIGH},
931 * {@link VideoProfile#QUALITY_MEDIUM},
932 * {@link VideoProfile#QUALITY_LOW},
933 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700934 */
935 public abstract void onVideoQualityChanged(int videoQuality);
936
937 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700938 * Handles an update to the total data used for the current video session.
939 * <p>
940 * Used by the {@link Connection.VideoProvider} in response to
941 * {@link VideoCall#requestCallDataUsage()}. May also be called periodically by the
942 * {@link Connection.VideoProvider}.
943 * <p>
944 * Callback originates from {@link Connection.VideoProvider#setCallDataUsage(long)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700945 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700946 * @param dataUsage The updated data usage (in bytes).
Andrew Lee50aca232014-07-22 16:41:54 -0700947 */
Rekha Kumar07366812015-03-24 16:42:31 -0700948 public abstract void onCallDataUsageChanged(long dataUsage);
Andrew Lee50aca232014-07-22 16:41:54 -0700949
950 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700951 * Handles a change in the capabilities of the currently selected camera.
952 * <p>
953 * Used by the {@link Connection.VideoProvider} in response to
954 * {@link VideoCall#requestCameraCapabilities()}. The {@link Connection.VideoProvider}
955 * may also report the camera capabilities after a call to
956 * {@link VideoCall#setCamera(String)}.
957 * <p>
958 * Callback originates from
959 * {@link Connection.VideoProvider#changeCameraCapabilities(
960 * VideoProfile.CameraCapabilities)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700961 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700962 * @param cameraCapabilities The changed camera capabilities.
Andrew Lee50aca232014-07-22 16:41:54 -0700963 */
Yorke Lee400470f2015-05-12 13:31:25 -0700964 public abstract void onCameraCapabilitiesChanged(
965 VideoProfile.CameraCapabilities cameraCapabilities);
Andrew Lee50aca232014-07-22 16:41:54 -0700966 }
967 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800968}