blob: cea2fbfa588c26b399c7da42cc774db5e9da5629 [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 Liua98f58b2017-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 Liua98f58b2017-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
Andrew Lee50aca232014-07-22 16:41:54 -070038import java.lang.String;
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 Gunn94f8f112018-12-17 09:56:11 -080043 * This service is implemented by an app that wishes to provide functionality for managing
44 * phone calls.
45 * <p>
46 * There are three types of apps which Telecom can bind to when there exists a live (active or
47 * incoming) call:
48 * <ol>
49 * <li>Default Dialer/Phone app - the default dialer/phone app is one which provides the
50 * in-call user interface while the device is in a call. A device is bundled with a system
51 * provided default dialer/phone app. The user may choose a single app to take over this role
52 * from the system app.</li>
53 * <li>Default Car-mode Dialer/Phone app - the default car-mode dialer/phone app is one which
54 * provides the in-call user interface while the device is in a call and the device is in car
55 * mode. The user may choose a single app to fill this role.</li>
56 * <li>Call Companion app - a call companion app is one which provides no user interface itself,
57 * but exposes call information to another display surface, such as a wearable device. The
58 * user may choose multiple apps to fill this role.</li>
59 * </ol>
60 * <p>
61 * Apps which wish to fulfill one of the above roles use the {@code android.app.role.RoleManager}
62 * to request that they fill the desired role.
63 *
64 * <h2>Becoming the Default Phone App</h2>
65 * An app filling the role of the default phone app provides a user interface while the device is in
66 * a call, and the device is not in car mode.
Santos Cordonf2600eb2015-06-22 15:02:20 -070067 * <p>
68 * Below is an example manifest registration for an {@code InCallService}. The meta-data
Tyler Gunndc6e6c42018-07-03 16:08:17 -070069 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_UI} indicates that this particular
Santos Cordonf2600eb2015-06-22 15:02:20 -070070 * {@code InCallService} implementation intends to replace the built-in in-call UI.
Tyler Gunndc6e6c42018-07-03 16:08:17 -070071 * The meta-data {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} indicates that this
72 * {@link InCallService} will play the ringtone for incoming calls. See
73 * <a href="#incomingCallNotification">below</a> for more information on showing the incoming call
74 * UI and playing the ringtone in your app.
Santos Cordonf2600eb2015-06-22 15:02:20 -070075 * <pre>
76 * {@code
Neil Fuller71fbb812015-11-30 09:51:33 +000077 * <service android:name="your.package.YourInCallServiceImplementation"
Sailesh Nepal78f3ba62015-12-28 16:20:56 -080078 * android:permission="android.permission.BIND_INCALL_SERVICE">
Neil Fuller71fbb812015-11-30 09:51:33 +000079 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
Tyler Gunndc6e6c42018-07-03 16:08:17 -070080 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_RINGING"
81 * android:value="true" />
Neil Fuller71fbb812015-11-30 09:51:33 +000082 * <intent-filter>
83 * <action android:name="android.telecom.InCallService"/>
84 * </intent-filter>
85 * </service>
Santos Cordonf2600eb2015-06-22 15:02:20 -070086 * }
87 * </pre>
Tyler Gunnfe39efa2018-02-02 13:18:02 -080088 * <p>
89 * In addition to implementing the {@link InCallService} API, you must also declare an activity in
90 * your manifest which handles the {@link Intent#ACTION_DIAL} intent. The example below illustrates
91 * how this is done:
92 * <pre>
93 * {@code
94 * <activity android:name="your.package.YourDialerActivity"
95 * android:label="@string/yourDialerActivityLabel">
96 * <intent-filter>
97 * <action android:name="android.intent.action.DIAL" />
98 * <category android:name="android.intent.category.DEFAULT" />
99 * </intent-filter>
100 * </activity>
101 * }
102 * </pre>
103 * <p>
Tyler Gunn94f8f112018-12-17 09:56:11 -0800104 * When a user installs your application and runs it for the first time, you should use the
105 * {@code android.app.role.RoleManager} to prompt the user to see if they would like your app to
106 * be the new default phone app.
107 * <p id="requestRole">
108 * The code below shows how your app can request to become the default phone/dialer app:
109 * <pre>
110 * {@code
111 * private static final int REQUEST_ID = 1;
112 *
113 * public void requestRole() {
114 * RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
115 * Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_DIALER);
116 * startActivityForResult(intent, REQUEST_ID);
117 * }
118 *
119 * &#64;Override
120 * public void onActivityResult(int requestCode, int resultCode, Intent data) {
121 * if (requestCode == REQUEST_ID) {
122 * if (resultCode == android.app.Activity.RESULT_OK) {
123 * // Your app is now the default dialer app
124 * } else {
125 * // Your app is not the default dialer app
126 * }
127 * }
128 * }
129 * </pre>
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700130 * <p id="incomingCallNotification">
Tyler Gunn94f8f112018-12-17 09:56:11 -0800131 * <h3>Showing the Incoming Call Notification</h3>
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700132 * When your app receives a new incoming call via {@link InCallService#onCallAdded(Call)}, it is
133 * responsible for displaying an incoming call UI for the incoming call. It should do this using
134 * {@link android.app.NotificationManager} APIs to post a new incoming call notification.
135 * <p>
136 * Where your app declares the meta-data {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING}, it
137 * is responsible for playing the ringtone for incoming calls. Your app should create a
138 * {@link android.app.NotificationChannel} which specifies the desired ringtone. For example:
139 * <pre><code>
140 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
141 * NotificationManager.IMPORTANCE_MAX);
142 * // other channel setup stuff goes here.
143 *
144 * // We'll use the default system ringtone for our incoming call notification channel. You can
145 * // use your own audio resource here.
146 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
147 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
148 * // Setting the AudioAttributes is important as it identifies the purpose of your
149 * // notification sound.
150 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
151 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
152 * .build());
153 *
154 * NotificationManager mgr = getSystemService(NotificationManager.class);
155 * mgr.createNotificationChannel(channel);
156 * </code></pre>
157 * <p>
158 * When your app receives a new incoming call, it creates a {@link android.app.Notification} for the
159 * incoming call and associates it with your incoming call notification channel. You can specify a
160 * {@link android.app.PendingIntent} on the notification which will launch your full screen
161 * incoming call UI. The notification manager framework will display your notification as a
162 * heads-up notification if the user is actively using the phone. When the user is not using the
163 * phone, your full-screen incoming call UI is used instead.
164 * For example:
Tyler Gunn94f8f112018-12-17 09:56:11 -0800165 * <pre><code>{@code
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700166 * // Create an intent which triggers your fullscreen incoming call user interface.
167 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
168 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
169 * intent.setClass(context, YourIncomingCallActivity.class);
170 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
171 *
172 * // Build the notification as an ongoing high priority item; this ensures it will show as
173 * // a heads up notification which slides down over top of the current content.
174 * final Notification.Builder builder = new Notification.Builder(context);
175 * builder.setOngoing(true);
176 * builder.setPriority(Notification.PRIORITY_HIGH);
177 *
178 * // Set notification content intent to take user to the fullscreen UI if user taps on the
179 * // notification body.
180 * builder.setContentIntent(pendingIntent);
181 * // Set full screen intent to trigger display of the fullscreen UI when the notification
182 * // manager deems it appropriate.
183 * builder.setFullScreenIntent(pendingIntent, true);
184 *
185 * // Setup notification content.
186 * builder.setSmallIcon( yourIconResourceId );
187 * builder.setContentTitle("Your notification title");
188 * builder.setContentText("Your notification content.");
189 *
190 * // Use builder.addAction(..) to add buttons to answer or reject the call.
191 *
192 * NotificationManager notificationManager = mContext.getSystemService(
193 * NotificationManager.class);
194 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, builder.build());
Tyler Gunn94f8f112018-12-17 09:56:11 -0800195 * }</pre>
196 * <p>
197 * <h2>Becoming the Default Car-mode Phone App</h2>
198 * An app filling the role of the default car-mode dialer/phone app provides a user interface while
199 * the device is in a call, and in car mode. See
200 * {@link android.app.UiModeManager#ACTION_ENTER_CAR_MODE} for more information about car mode.
201 * When the device is in car mode, Telecom binds to the default car-mode dialer/phone app instead
202 * of the usual dialer/phone app.
203 * <p>
204 * Similar to the requirements for becoming the default dialer/phone app, your app must declare a
205 * manifest entry for its {@link InCallService} implementation. Your manifest entry should ensure
206 * the following conditions are met:
207 * <ul>
208 * <li>Do NOT declare the {@link TelecomManager#METADATA_IN_CALL_SERVICE_UI} metadata.</li>
209 * <li>Set the {@link TelecomManager#METADATA_IN_CALL_SERVICE_CAR_MODE_UI} metadata to
210 * {@code true}<li>
211 * <li>Your app must request the permission
212 * {@link android.Manifest.permission.CALL_COMPANION_APP}.</li>
213 * </ul>
214 * <p>
215 * Your app should request to fill the role {@code android.app.role.CAR_MODE_DIALER_APP} in order to
216 * become the default (see <a href="#requestRole">above</a> for how to request your app fills this
217 * role).
218 *
219 * <h2>Becoming a Call Companion App</h2>
220 * An app which fills the companion app role does not directly provide a user interface while the
221 * device is in a call. Instead, it is typically used to relay information about calls to another
222 * display surface, such as a wearable device.
223 * <p>
224 * Similar to the requirements for becoming the default dialer/phone app, your app must declare a
225 * manifest entry for its {@link InCallService} implementation. Your manifest entry should
226 * ensure the following conditions are met:
227 * <ul>
228 * <li>Do NOT declare the {@link TelecomManager#METADATA_IN_CALL_SERVICE_UI} metadata.</li>
229 * <li>Do NOT declare the {@link TelecomManager#METADATA_IN_CALL_SERVICE_CAR_MODE_UI}
230 * metadata.</li>
231 * <li>Your app must request the permission
232 * {@link android.Manifest.permission.CALL_COMPANION_APP}.</li>
233 * </ul>
234 * <p>
235 * Your app should request to fill the role {@code android.app.role.CALL_COMPANION_APP} in order to
236 * become a call companion app (see <a href="#requestRole">above</a> for how to request your app
237 * fills this role).
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800238 */
Santos Cordon2f42b112014-07-19 13:19:37 -0700239public abstract class InCallService extends Service {
Tyler Gunn2ac40102014-08-18 16:23:10 -0700240
241 /**
242 * The {@link Intent} that must be declared as handled by the service.
243 */
244 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700245 public static final String SERVICE_INTERFACE = "android.telecom.InCallService";
Tyler Gunn2ac40102014-08-18 16:23:10 -0700246
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800247 private static final int MSG_SET_IN_CALL_ADAPTER = 1;
248 private static final int MSG_ADD_CALL = 2;
Sailesh Nepal60437932014-04-05 16:44:55 -0700249 private static final int MSG_UPDATE_CALL = 3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700250 private static final int MSG_SET_POST_DIAL_WAIT = 4;
Yorke Lee4af59352015-05-13 14:14:54 -0700251 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 5;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700252 private static final int MSG_BRING_TO_FOREGROUND = 6;
Santos Cordon6c912b72014-11-07 16:05:09 -0800253 private static final int MSG_ON_CAN_ADD_CALL_CHANGED = 7;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800254 private static final int MSG_SILENCE_RINGER = 8;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700255 private static final int MSG_ON_CONNECTION_EVENT = 9;
Hall Liu95d55872017-01-25 17:12:49 -0800256 private static final int MSG_ON_RTT_UPGRADE_REQUEST = 10;
Hall Liu57006aa2017-02-06 10:49:48 -0800257 private static final int MSG_ON_RTT_INITIATION_FAILURE = 11;
Sanket Padawe85291f62017-12-01 13:59:27 -0800258 private static final int MSG_ON_HANDOVER_FAILED = 12;
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800259 private static final int MSG_ON_HANDOVER_COMPLETE = 13;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800260
261 /** Default Handler used to consolidate binder method calls onto a single thread. */
262 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
263 @Override
264 public void handleMessage(Message msg) {
Jay Shrauner5e6162d2014-09-22 20:47:45 -0700265 if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) {
266 return;
267 }
268
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800269 switch (msg.what) {
270 case MSG_SET_IN_CALL_ADAPTER:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800271 String callingPackage = getApplicationContext().getOpPackageName();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800272 mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj), callingPackage,
273 getApplicationContext().getApplicationInfo().targetSdkVersion);
Santos Cordona2492812015-04-15 11:05:16 -0700274 mPhone.addListener(mPhoneListener);
Ihab Awade63fadb2014-07-09 21:52:04 -0700275 onPhoneCreated(mPhone);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800276 break;
277 case MSG_ADD_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700278 mPhone.internalAddCall((ParcelableCall) msg.obj);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800279 break;
Sailesh Nepal60437932014-04-05 16:44:55 -0700280 case MSG_UPDATE_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700281 mPhone.internalUpdateCall((ParcelableCall) msg.obj);
Ihab Awad2f236642014-03-10 15:33:45 -0700282 break;
Ihab Awad2f236642014-03-10 15:33:45 -0700283 case MSG_SET_POST_DIAL_WAIT: {
284 SomeArgs args = (SomeArgs) msg.obj;
285 try {
286 String callId = (String) args.arg1;
287 String remaining = (String) args.arg2;
Ihab Awade63fadb2014-07-09 21:52:04 -0700288 mPhone.internalSetPostDialWait(callId, remaining);
Ihab Awad2f236642014-03-10 15:33:45 -0700289 } finally {
290 args.recycle();
291 }
292 break;
293 }
Yorke Lee4af59352015-05-13 14:14:54 -0700294 case MSG_ON_CALL_AUDIO_STATE_CHANGED:
295 mPhone.internalCallAudioStateChanged((CallAudioState) msg.obj);
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700296 break;
Santos Cordon3534ede2014-05-29 13:07:10 -0700297 case MSG_BRING_TO_FOREGROUND:
Ihab Awade63fadb2014-07-09 21:52:04 -0700298 mPhone.internalBringToForeground(msg.arg1 == 1);
Santos Cordon3534ede2014-05-29 13:07:10 -0700299 break;
Santos Cordon6c912b72014-11-07 16:05:09 -0800300 case MSG_ON_CAN_ADD_CALL_CHANGED:
301 mPhone.internalSetCanAddCall(msg.arg1 == 1);
302 break;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800303 case MSG_SILENCE_RINGER:
304 mPhone.internalSilenceRinger();
305 break;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700306 case MSG_ON_CONNECTION_EVENT: {
307 SomeArgs args = (SomeArgs) msg.obj;
308 try {
309 String callId = (String) args.arg1;
310 String event = (String) args.arg2;
311 Bundle extras = (Bundle) args.arg3;
312 mPhone.internalOnConnectionEvent(callId, event, extras);
313 } finally {
314 args.recycle();
315 }
316 break;
317 }
Hall Liu95d55872017-01-25 17:12:49 -0800318 case MSG_ON_RTT_UPGRADE_REQUEST: {
319 String callId = (String) msg.obj;
320 int requestId = msg.arg1;
321 mPhone.internalOnRttUpgradeRequest(callId, requestId);
322 break;
323 }
Hall Liu57006aa2017-02-06 10:49:48 -0800324 case MSG_ON_RTT_INITIATION_FAILURE: {
325 String callId = (String) msg.obj;
326 int reason = msg.arg1;
327 mPhone.internalOnRttInitiationFailure(callId, reason);
328 break;
329 }
Sanket Padawe85291f62017-12-01 13:59:27 -0800330 case MSG_ON_HANDOVER_FAILED: {
331 String callId = (String) msg.obj;
332 int error = msg.arg1;
333 mPhone.internalOnHandoverFailed(callId, error);
334 break;
335 }
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800336 case MSG_ON_HANDOVER_COMPLETE: {
337 String callId = (String) msg.obj;
338 mPhone.internalOnHandoverComplete(callId);
339 break;
340 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800341 default:
342 break;
343 }
344 }
345 };
346
347 /** Manages the binder calls so that the implementor does not need to deal with it. */
348 private final class InCallServiceBinder extends IInCallService.Stub {
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800349 @Override
350 public void setInCallAdapter(IInCallAdapter inCallAdapter) {
351 mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget();
352 }
353
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800354 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700355 public void addCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700356 mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800357 }
358
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800359 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700360 public void updateCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700361 mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
Ihab Awad2f236642014-03-10 15:33:45 -0700362 }
363
364 @Override
365 public void setPostDial(String callId, String remaining) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700366 // TODO: Unused
Ihab Awad2f236642014-03-10 15:33:45 -0700367 }
368
369 @Override
370 public void setPostDialWait(String callId, String remaining) {
371 SomeArgs args = SomeArgs.obtain();
372 args.arg1 = callId;
373 args.arg2 = remaining;
374 mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
375 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700376
377 @Override
Yorke Lee4af59352015-05-13 14:14:54 -0700378 public void onCallAudioStateChanged(CallAudioState callAudioState) {
379 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, callAudioState).sendToTarget();
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700380 }
Santos Cordon3534ede2014-05-29 13:07:10 -0700381
Santos Cordon3534ede2014-05-29 13:07:10 -0700382 @Override
383 public void bringToForeground(boolean showDialpad) {
384 mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
385 }
Santos Cordon6c912b72014-11-07 16:05:09 -0800386
387 @Override
388 public void onCanAddCallChanged(boolean canAddCall) {
389 mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0)
390 .sendToTarget();
391 }
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800392
393 @Override
394 public void silenceRinger() {
395 mHandler.obtainMessage(MSG_SILENCE_RINGER).sendToTarget();
396 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700397
398 @Override
399 public void onConnectionEvent(String callId, String event, Bundle extras) {
400 SomeArgs args = SomeArgs.obtain();
401 args.arg1 = callId;
402 args.arg2 = event;
403 args.arg3 = extras;
404 mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget();
405 }
Hall Liu95d55872017-01-25 17:12:49 -0800406
407 @Override
408 public void onRttUpgradeRequest(String callId, int id) {
409 mHandler.obtainMessage(MSG_ON_RTT_UPGRADE_REQUEST, id, 0, callId).sendToTarget();
410 }
Hall Liu57006aa2017-02-06 10:49:48 -0800411
412 @Override
413 public void onRttInitiationFailure(String callId, int reason) {
414 mHandler.obtainMessage(MSG_ON_RTT_INITIATION_FAILURE, reason, 0, callId).sendToTarget();
415 }
Sanket Padawe85291f62017-12-01 13:59:27 -0800416
417 @Override
418 public void onHandoverFailed(String callId, int error) {
419 mHandler.obtainMessage(MSG_ON_HANDOVER_FAILED, error, 0, callId).sendToTarget();
420 }
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800421
422 @Override
423 public void onHandoverComplete(String callId) {
424 mHandler.obtainMessage(MSG_ON_HANDOVER_COMPLETE, callId).sendToTarget();
425 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800426 }
427
Santos Cordona2492812015-04-15 11:05:16 -0700428 private Phone.Listener mPhoneListener = new Phone.Listener() {
429 /** ${inheritDoc} */
430 @Override
431 public void onAudioStateChanged(Phone phone, AudioState audioState) {
432 InCallService.this.onAudioStateChanged(audioState);
433 }
434
Yorke Lee4af59352015-05-13 14:14:54 -0700435 public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) {
436 InCallService.this.onCallAudioStateChanged(callAudioState);
437 };
438
Santos Cordona2492812015-04-15 11:05:16 -0700439 /** ${inheritDoc} */
440 @Override
441 public void onBringToForeground(Phone phone, boolean showDialpad) {
442 InCallService.this.onBringToForeground(showDialpad);
443 }
444
445 /** ${inheritDoc} */
446 @Override
447 public void onCallAdded(Phone phone, Call call) {
448 InCallService.this.onCallAdded(call);
449 }
450
451 /** ${inheritDoc} */
452 @Override
453 public void onCallRemoved(Phone phone, Call call) {
454 InCallService.this.onCallRemoved(call);
455 }
456
457 /** ${inheritDoc} */
458 @Override
459 public void onCanAddCallChanged(Phone phone, boolean canAddCall) {
460 InCallService.this.onCanAddCallChanged(canAddCall);
461 }
462
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800463 /** ${inheritDoc} */
464 @Override
465 public void onSilenceRinger(Phone phone) {
466 InCallService.this.onSilenceRinger();
467 }
468
Santos Cordona2492812015-04-15 11:05:16 -0700469 };
470
Ihab Awade63fadb2014-07-09 21:52:04 -0700471 private Phone mPhone;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800472
Santos Cordon2f42b112014-07-19 13:19:37 -0700473 public InCallService() {
474 }
Evan Charlton924748f2014-04-03 08:36:38 -0700475
Santos Cordon2f42b112014-07-19 13:19:37 -0700476 @Override
477 public IBinder onBind(Intent intent) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700478 return new InCallServiceBinder();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800479 }
480
Santos Cordonf30d7e92014-08-26 09:54:33 -0700481 @Override
482 public boolean onUnbind(Intent intent) {
Santos Cordon619b3c02014-09-02 17:13:45 -0700483 if (mPhone != null) {
484 Phone oldPhone = mPhone;
485 mPhone = null;
Santos Cordonf30d7e92014-08-26 09:54:33 -0700486
Santos Cordon619b3c02014-09-02 17:13:45 -0700487 oldPhone.destroy();
Santos Cordona2492812015-04-15 11:05:16 -0700488 // destroy sets all the calls to disconnected if any live ones still exist. Therefore,
489 // it is important to remove the Listener *after* the call to destroy so that
490 // InCallService.on* callbacks are appropriately called.
491 oldPhone.removeListener(mPhoneListener);
492
Santos Cordon619b3c02014-09-02 17:13:45 -0700493 onPhoneDestroyed(oldPhone);
494 }
Santos Cordona2492812015-04-15 11:05:16 -0700495
Santos Cordonf30d7e92014-08-26 09:54:33 -0700496 return false;
497 }
498
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800499 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700500 * Obtain the {@code Phone} associated with this {@code InCallService}.
501 *
502 * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null}
Santos Cordon2f42b112014-07-19 13:19:37 -0700503 * if the {@code InCallService} is not in a state where it has an associated
504 * {@code Phone}.
Santos Cordona2492812015-04-15 11:05:16 -0700505 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700506 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800507 */
Santos Cordona2492812015-04-15 11:05:16 -0700508 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700509 @Deprecated
510 public Phone getPhone() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700511 return mPhone;
Evan Charlton924748f2014-04-03 08:36:38 -0700512 }
513
514 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700515 * Obtains the current list of {@code Call}s to be displayed by this in-call service.
Santos Cordona2492812015-04-15 11:05:16 -0700516 *
517 * @return A list of the relevant {@code Call}s.
518 */
519 public final List<Call> getCalls() {
520 return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls();
521 }
522
523 /**
524 * Returns if the device can support additional calls.
525 *
526 * @return Whether the phone supports adding more calls.
527 */
528 public final boolean canAddCall() {
529 return mPhone == null ? false : mPhone.canAddCall();
530 }
531
532 /**
533 * Obtains the current phone call audio state.
534 *
535 * @return An object encapsulating the audio state. Returns null if the service is not
536 * fully initialized.
Yorke Lee4af59352015-05-13 14:14:54 -0700537 * @deprecated Use {@link #getCallAudioState()} instead.
538 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700539 */
Yorke Lee4af59352015-05-13 14:14:54 -0700540 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700541 public final AudioState getAudioState() {
542 return mPhone == null ? null : mPhone.getAudioState();
543 }
544
545 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700546 * Obtains the current phone call audio state.
547 *
548 * @return An object encapsulating the audio state. Returns null if the service is not
549 * fully initialized.
550 */
551 public final CallAudioState getCallAudioState() {
552 return mPhone == null ? null : mPhone.getCallAudioState();
553 }
554
555 /**
Santos Cordona2492812015-04-15 11:05:16 -0700556 * Sets the microphone mute state. When this request is honored, there will be change to
Yorke Lee4af59352015-05-13 14:14:54 -0700557 * the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700558 *
559 * @param state {@code true} if the microphone should be muted; {@code false} otherwise.
560 */
561 public final void setMuted(boolean state) {
562 if (mPhone != null) {
563 mPhone.setMuted(state);
564 }
565 }
566
567 /**
568 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
Yorke Lee4af59352015-05-13 14:14:54 -0700569 * be change to the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700570 *
571 * @param route The audio route to use.
572 */
573 public final void setAudioRoute(int route) {
574 if (mPhone != null) {
575 mPhone.setAudioRoute(route);
576 }
577 }
578
579 /**
Hall Liua98f58b2017-11-07 17:59:28 -0800580 * Request audio routing to a specific bluetooth device. Calling this method may result in
581 * the device routing audio to a different bluetooth device than the one specified if the
582 * bluetooth stack is unable to route audio to the requested device.
583 * A list of available devices can be obtained via
584 * {@link CallAudioState#getSupportedBluetoothDevices()}
585 *
Hall Liu15392832018-04-02 13:52:57 -0700586 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b2017-11-07 17:59:28 -0800587 */
Hall Liu15392832018-04-02 13:52:57 -0700588 public final void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b2017-11-07 17:59:28 -0800589 if (mPhone != null) {
Hall Liu15392832018-04-02 13:52:57 -0700590 mPhone.requestBluetoothAudio(bluetoothDevice.getAddress());
Hall Liua98f58b2017-11-07 17:59:28 -0800591 }
592 }
593
594 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700595 * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience
596 * to start displaying in-call information to the user. Each instance of {@code InCallService}
Santos Cordon2f42b112014-07-19 13:19:37 -0700597 * will have only one {@code Phone}, and this method will be called exactly once in the lifetime
598 * of the {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700599 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700600 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700601 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700602 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Evan Charlton924748f2014-04-03 08:36:38 -0700603 */
Santos Cordona2492812015-04-15 11:05:16 -0700604 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700605 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700606 public void onPhoneCreated(Phone phone) {
607 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800608
609 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700610 * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience
611 * to stop displaying in-call information to the user. This method will be called exactly once
612 * in the lifetime of the {@code InCallService}, and it will always be called after a previous
613 * call to {@link #onPhoneCreated(Phone)}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800614 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700615 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700616 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700617 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800618 */
Santos Cordona2492812015-04-15 11:05:16 -0700619 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700620 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700621 public void onPhoneDestroyed(Phone phone) {
622 }
Andrew Lee50aca232014-07-22 16:41:54 -0700623
624 /**
Santos Cordona2492812015-04-15 11:05:16 -0700625 * Called when the audio state changes.
626 *
627 * @param audioState The new {@link AudioState}.
Yorke Lee4af59352015-05-13 14:14:54 -0700628 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState) instead}.
629 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700630 */
Yorke Lee4af59352015-05-13 14:14:54 -0700631 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700632 public void onAudioStateChanged(AudioState audioState) {
633 }
634
635 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700636 * Called when the audio state changes.
637 *
638 * @param audioState The new {@link CallAudioState}.
639 */
640 public void onCallAudioStateChanged(CallAudioState audioState) {
641 }
642
643 /**
Santos Cordona2492812015-04-15 11:05:16 -0700644 * Called to bring the in-call screen to the foreground. The in-call experience should
645 * respond immediately by coming to the foreground to inform the user of the state of
646 * ongoing {@code Call}s.
647 *
648 * @param showDialpad If true, put up the dialpad when the screen is shown.
649 */
650 public void onBringToForeground(boolean showDialpad) {
651 }
652
653 /**
654 * Called when a {@code Call} has been added to this in-call session. The in-call user
655 * experience should add necessary state listeners to the specified {@code Call} and
656 * immediately start to show the user information about the existence
657 * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will
658 * include this {@code Call}.
659 *
660 * @param call A newly added {@code Call}.
661 */
662 public void onCallAdded(Call call) {
663 }
664
665 /**
666 * Called when a {@code Call} has been removed from this in-call session. The in-call user
667 * experience should remove any state listeners from the specified {@code Call} and
668 * immediately stop displaying any information about this {@code Call}.
669 * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}.
670 *
671 * @param call A newly removed {@code Call}.
672 */
673 public void onCallRemoved(Call call) {
674 }
675
676 /**
677 * Called when the ability to add more calls changes. If the phone cannot
678 * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it
679 * is set to {@code true}. This can be used to control the visibility of UI to add more calls.
680 *
681 * @param canAddCall Indicates whether an additional call can be added.
682 */
683 public void onCanAddCallChanged(boolean canAddCall) {
684 }
685
686 /**
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800687 * Called to silence the ringer if a ringing call exists.
688 */
689 public void onSilenceRinger() {
690 }
691
692 /**
Tyler Gunn06f3fa62016-08-25 09:26:15 -0700693 * Unused; to handle connection events issued by a {@link ConnectionService}, implement the
694 * {@link android.telecom.Call.Callback#onConnectionEvent(Call, String, Bundle)} callback.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700695 * <p>
696 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
697 *
698 * @param call The call the event is associated with.
699 * @param event The event.
700 * @param extras Any associated extras.
701 */
702 public void onConnectionEvent(Call call, String event, Bundle extras) {
703 }
704
705 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700706 * Used to issue commands to the {@link Connection.VideoProvider} associated with a
707 * {@link Call}.
Andrew Lee50aca232014-07-22 16:41:54 -0700708 */
709 public static abstract class VideoCall {
710
Andrew Lee011728f2015-04-23 15:47:06 -0700711 /** @hide */
712 public abstract void destroy();
713
Andrew Lee50aca232014-07-22 16:41:54 -0700714 /**
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700715 * Registers a callback to receive commands and state changes for video calls.
Andrew Lee50aca232014-07-22 16:41:54 -0700716 *
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700717 * @param callback The video call callback.
Andrew Lee50aca232014-07-22 16:41:54 -0700718 */
Andrew Leeda80c872015-04-15 14:09:50 -0700719 public abstract void registerCallback(VideoCall.Callback callback);
720
721 /**
Andrew Lee011728f2015-04-23 15:47:06 -0700722 * Registers a callback to receive commands and state changes for video calls.
723 *
724 * @param callback The video call callback.
725 * @param handler A handler which commands and status changes will be delivered to.
726 */
727 public abstract void registerCallback(VideoCall.Callback callback, Handler handler);
728
729 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700730 * Clears the video call callback set via {@link #registerCallback}.
Tyler Gunn295f5d72015-06-04 11:08:54 -0700731 *
732 * @param callback The video call callback to clear.
Tyler Gunn75958422015-04-15 14:23:42 -0700733 */
Andrew Lee011728f2015-04-23 15:47:06 -0700734 public abstract void unregisterCallback(VideoCall.Callback callback);
Tyler Gunn75958422015-04-15 14:23:42 -0700735
736 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700737 * Sets the camera to be used for the outgoing video.
738 * <p>
739 * Handled by {@link Connection.VideoProvider#onSetCamera(String)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700740 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700741 * @param cameraId The id of the camera (use ids as reported by
742 * {@link CameraManager#getCameraIdList()}).
Andrew Lee50aca232014-07-22 16:41:54 -0700743 */
744 public abstract void setCamera(String cameraId);
745
746 /**
747 * Sets the surface to be used for displaying a preview of what the user's camera is
748 * currently capturing. When video transmission is enabled, this is the video signal which
749 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700750 * <p>
751 * Handled by {@link Connection.VideoProvider#onSetPreviewSurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700752 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700753 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700754 */
755 public abstract void setPreviewSurface(Surface surface);
756
757 /**
758 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700759 * <p>
760 * Handled by {@link Connection.VideoProvider#onSetDisplaySurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700761 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700762 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700763 */
764 public abstract void setDisplaySurface(Surface surface);
765
766 /**
767 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
768 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700769 * <p>
770 * Handled by {@link Connection.VideoProvider#onSetDeviceOrientation(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700771 *
772 * @param rotation The device orientation, in degrees.
773 */
774 public abstract void setDeviceOrientation(int rotation);
775
776 /**
777 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700778 * <p>
779 * Handled by {@link Connection.VideoProvider#onSetZoom(float)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700780 *
781 * @param value The camera zoom ratio.
782 */
783 public abstract void setZoom(float value);
784
785 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700786 * Issues a request to modify the properties of the current video session.
787 * <p>
788 * Example scenarios include: requesting an audio-only call to be upgraded to a
789 * bi-directional video call, turning on or off the user's camera, sending a pause signal
790 * when the {@link InCallService} is no longer the foreground application.
791 * <p>
792 * Handled by
793 * {@link Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700794 *
795 * @param requestProfile The requested call video properties.
796 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700797 public abstract void sendSessionModifyRequest(VideoProfile requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700798
799 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700800 * Provides a response to a request to change the current call video session
801 * properties. This should be called in response to a request the {@link InCallService} has
802 * received via {@link VideoCall.Callback#onSessionModifyRequestReceived}.
803 * <p>
804 * Handled by
805 * {@link Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700806 *
807 * @param responseProfile The response call video properties.
808 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700809 public abstract void sendSessionModifyResponse(VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700810
811 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700812 * Issues a request to the {@link Connection.VideoProvider} to retrieve the capabilities
813 * of the current camera. The current camera is selected using
814 * {@link VideoCall#setCamera(String)}.
815 * <p>
816 * Camera capabilities are reported to the caller via
817 * {@link VideoCall.Callback#onCameraCapabilitiesChanged(VideoProfile.CameraCapabilities)}.
818 * <p>
819 * Handled by {@link Connection.VideoProvider#onRequestCameraCapabilities()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700820 */
821 public abstract void requestCameraCapabilities();
822
823 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700824 * Issues a request to the {@link Connection.VideoProvider} to retrieve the cumulative data
825 * usage for the video component of the current call (in bytes). Data usage is reported
826 * to the caller via {@link VideoCall.Callback#onCallDataUsageChanged}.
827 * <p>
828 * Handled by {@link Connection.VideoProvider#onRequestConnectionDataUsage()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700829 */
830 public abstract void requestCallDataUsage();
831
832 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700833 * Provides the {@link Connection.VideoProvider} with the {@link Uri} of an image to be
834 * displayed to the peer device when the video signal is paused.
835 * <p>
836 * Handled by {@link Connection.VideoProvider#onSetPauseImage(Uri)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700837 *
838 * @param uri URI of image to display.
839 */
Yorke Lee32f24732015-05-12 16:18:03 -0700840 public abstract void setPauseImage(Uri uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700841
842 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700843 * The {@link InCallService} extends this class to provide a means of receiving callbacks
Tyler Gunn295f5d72015-06-04 11:08:54 -0700844 * from the {@link Connection.VideoProvider}.
845 * <p>
Tyler Gunnb702ef82015-05-29 11:51:53 -0700846 * When the {@link InCallService} receives the
847 * {@link Call.Callback#onVideoCallChanged(Call, VideoCall)} callback, it should create an
848 * instance its {@link VideoCall.Callback} implementation and set it on the
849 * {@link VideoCall} using {@link VideoCall#registerCallback(Callback)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700850 */
Andrew Leeda80c872015-04-15 14:09:50 -0700851 public static abstract class Callback {
Andrew Lee50aca232014-07-22 16:41:54 -0700852 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700853 * Called when the {@link Connection.VideoProvider} receives a session modification
Tyler Gunn295f5d72015-06-04 11:08:54 -0700854 * request from the peer device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700855 * <p>
856 * The {@link InCallService} may potentially prompt the user to confirm whether they
857 * wish to accept the request, or decide to automatically accept the request. In either
858 * case the {@link InCallService} should call
859 * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} to indicate the video
860 * profile agreed upon.
861 * <p>
862 * Callback originates from
863 * {@link Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700864 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700865 * @param videoProfile The requested video profile.
Andrew Lee50aca232014-07-22 16:41:54 -0700866 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700867 public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700868
869 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700870 * Called when the {@link Connection.VideoProvider} receives a response to a session
871 * modification request previously sent to the peer device.
872 * <p>
873 * The new video state should not be considered active by the {@link InCallService}
874 * until the {@link Call} video state changes (the
875 * {@link Call.Callback#onDetailsChanged(Call, Call.Details)} callback is triggered
876 * when the video state changes).
877 * <p>
878 * Callback originates from
879 * {@link Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
880 * VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700881 *
882 * @param status Status of the session modify request. Valid values are
Tyler Gunnb702ef82015-05-29 11:51:53 -0700883 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
884 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
885 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
886 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
887 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}.
888 * @param requestedProfile The original request which was sent to the peer device.
889 * @param responseProfile The actual profile changes made by the peer device.
Andrew Lee50aca232014-07-22 16:41:54 -0700890 */
891 public abstract void onSessionModifyResponseReceived(int status,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700892 VideoProfile requestedProfile, VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700893
894 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700895 * Handles events related to the current video session which the {@link InCallService}
896 * may wish to handle. These are separate from requested changes to the session due to
897 * the underlying protocol or connection.
898 * <p>
899 * Callback originates from
900 * {@link Connection.VideoProvider#handleCallSessionEvent(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700901 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700902 * @param event The event. Valid values are:
903 * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE},
904 * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME},
905 * {@link Connection.VideoProvider#SESSION_EVENT_TX_START},
906 * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP},
907 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800908 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY},
909 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_PERMISSION_ERROR}.
Andrew Lee50aca232014-07-22 16:41:54 -0700910 */
911 public abstract void onCallSessionEvent(int event);
912
913 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700914 * Handles a change to the video dimensions from the peer device. This could happen if,
915 * for example, the peer changes orientation of their device, or switches cameras.
916 * <p>
917 * Callback originates from
918 * {@link Connection.VideoProvider#changePeerDimensions(int, int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700919 *
920 * @param width The updated peer video width.
921 * @param height The updated peer video height.
922 */
923 public abstract void onPeerDimensionsChanged(int width, int height);
924
925 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700926 * Handles a change to the video quality.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700927 * <p>
928 * Callback originates from {@link Connection.VideoProvider#changeVideoQuality(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700929 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700930 * @param videoQuality The updated peer video quality. Valid values:
931 * {@link VideoProfile#QUALITY_HIGH},
932 * {@link VideoProfile#QUALITY_MEDIUM},
933 * {@link VideoProfile#QUALITY_LOW},
934 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700935 */
936 public abstract void onVideoQualityChanged(int videoQuality);
937
938 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700939 * Handles an update to the total data used for the current video session.
940 * <p>
941 * Used by the {@link Connection.VideoProvider} in response to
942 * {@link VideoCall#requestCallDataUsage()}. May also be called periodically by the
943 * {@link Connection.VideoProvider}.
944 * <p>
945 * Callback originates from {@link Connection.VideoProvider#setCallDataUsage(long)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700946 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700947 * @param dataUsage The updated data usage (in bytes).
Andrew Lee50aca232014-07-22 16:41:54 -0700948 */
Rekha Kumar07366812015-03-24 16:42:31 -0700949 public abstract void onCallDataUsageChanged(long dataUsage);
Andrew Lee50aca232014-07-22 16:41:54 -0700950
951 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700952 * Handles a change in the capabilities of the currently selected camera.
953 * <p>
954 * Used by the {@link Connection.VideoProvider} in response to
955 * {@link VideoCall#requestCameraCapabilities()}. The {@link Connection.VideoProvider}
956 * may also report the camera capabilities after a call to
957 * {@link VideoCall#setCamera(String)}.
958 * <p>
959 * Callback originates from
960 * {@link Connection.VideoProvider#changeCameraCapabilities(
961 * VideoProfile.CameraCapabilities)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700962 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700963 * @param cameraCapabilities The changed camera capabilities.
Andrew Lee50aca232014-07-22 16:41:54 -0700964 */
Yorke Lee400470f2015-05-12 13:31:25 -0700965 public abstract void onCameraCapabilitiesChanged(
966 VideoProfile.CameraCapabilities cameraCapabilities);
Andrew Lee50aca232014-07-22 16:41:54 -0700967 }
968 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800969}