blob: 07de61759d592b202447cfb65e740ac7da38368c [file] [log] [blame]
Sailesh Nepalab5d2822014-03-08 18:01:06 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080018
Hall Liua98f58b52017-11-07 17:59:28 -080019import android.annotation.NonNull;
Tyler Gunn2ac40102014-08-18 16:23:10 -070020import android.annotation.SdkConstant;
Santos Cordona2492812015-04-15 11:05:16 -070021import android.annotation.SystemApi;
Santos Cordon2f42b112014-07-19 13:19:37 -070022import android.app.Service;
Tyler Gunn4057d4c2020-01-31 15:03:43 -080023import android.app.UiModeManager;
Hall Liua98f58b52017-11-07 17:59:28 -080024import android.bluetooth.BluetoothDevice;
Santos Cordon2f42b112014-07-19 13:19:37 -070025import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070026import android.hardware.camera2.CameraManager;
Yorke Lee32f24732015-05-12 16:18:03 -070027import android.net.Uri;
Tyler Gunn876dbfb2016-03-14 15:18:07 -070028import android.os.Bundle;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080029import android.os.Handler;
30import android.os.IBinder;
31import android.os.Looper;
32import android.os.Message;
Andrew Lee50aca232014-07-22 16:41:54 -070033import android.view.Surface;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080034
Ihab Awad2f236642014-03-10 15:33:45 -070035import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070036import com.android.internal.telecom.IInCallAdapter;
37import com.android.internal.telecom.IInCallService;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080038
Santos Cordona2492812015-04-15 11:05:16 -070039import java.util.Collections;
40import java.util.List;
Andrew Lee50aca232014-07-22 16:41:54 -070041
Sailesh Nepalab5d2822014-03-08 18:01:06 -080042/**
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -080043 * This service is implemented by an app that wishes to provide functionality for managing
44 * phone calls.
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -080045 * <h2>Becoming the Default Phone App</h2>
Tyler Gunn556d2402019-04-10 08:59:43 -070046 * The default dialer/phone app is one which provides the in-call user interface while the device is
Tyler Gunn4057d4c2020-01-31 15:03:43 -080047 * in a call. It also provides the user with a means to initiate calls and see a history of calls
48 * on their device. A device is bundled with a system provided default dialer/phone app. The user
49 * may choose a single app to take over this role from the system app. An app which wishes to
50 * fulfill one this role uses the {@link android.app.role.RoleManager} to request that they fill the
51 * {@link android.app.role.RoleManager#ROLE_DIALER} role.
Tyler Gunn556d2402019-04-10 08:59:43 -070052 * <p>
Tyler Gunn4057d4c2020-01-31 15:03:43 -080053 * The default phone app provides a user interface while the device is in a call, and the device is
54 * not in car mode (i.e. {@link UiModeManager#getCurrentModeType()} is not
55 * {@link android.content.res.Configuration#UI_MODE_TYPE_CAR}).
56 * <p>
57 * In order to fill the {@link android.app.role.RoleManager#ROLE_DIALER} role, an app must meet a
58 * number of requirements:
59 * <ul>
60 * <li>It must handle the {@link Intent#ACTION_DIAL} intent. This means the app must provide
61 * a dial pad UI for the user to initiate outgoing calls.</li>
62 * <li>It must fully implement the {@link InCallService} API and provide both an incoming call
63 * UI, as well as an ongoing call UI.</li>
64 * </ul>
65 * <p>
66 * Note: If the app filling the {@link android.app.role.RoleManager#ROLE_DIALER} crashes during
67 * {@link InCallService} binding, the Telecom framework will automatically fall back to using the
68 * dialer app pre-loaded on the device. The system will display a notification to the user to let
69 * them know that the app has crashed and that their call was continued using the pre-loaded dialer
70 * app.
71 * <p>
72 * Further, the pre-loaded dialer will ALWAYS be used when the user places an emergency call.
Santos Cordonf2600eb2015-06-22 15:02:20 -070073 * <p>
74 * Below is an example manifest registration for an {@code InCallService}. The meta-data
Tyler Gunndc6e6c42018-07-03 16:08:17 -070075 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_UI} indicates that this particular
Santos Cordonf2600eb2015-06-22 15:02:20 -070076 * {@code InCallService} implementation intends to replace the built-in in-call UI.
Tyler Gunndc6e6c42018-07-03 16:08:17 -070077 * The meta-data {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} indicates that this
78 * {@link InCallService} will play the ringtone for incoming calls. See
79 * <a href="#incomingCallNotification">below</a> for more information on showing the incoming call
80 * UI and playing the ringtone in your app.
Santos Cordonf2600eb2015-06-22 15:02:20 -070081 * <pre>
82 * {@code
Neil Fuller71fbb812015-11-30 09:51:33 +000083 * <service android:name="your.package.YourInCallServiceImplementation"
Sailesh Nepal78f3ba62015-12-28 16:20:56 -080084 * android:permission="android.permission.BIND_INCALL_SERVICE">
Neil Fuller71fbb812015-11-30 09:51:33 +000085 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
Tyler Gunndc6e6c42018-07-03 16:08:17 -070086 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_RINGING"
87 * android:value="true" />
Neil Fuller71fbb812015-11-30 09:51:33 +000088 * <intent-filter>
89 * <action android:name="android.telecom.InCallService"/>
90 * </intent-filter>
91 * </service>
Santos Cordonf2600eb2015-06-22 15:02:20 -070092 * }
93 * </pre>
Tyler Gunnfe39efa2018-02-02 13:18:02 -080094 * <p>
95 * In addition to implementing the {@link InCallService} API, you must also declare an activity in
96 * your manifest which handles the {@link Intent#ACTION_DIAL} intent. The example below illustrates
97 * how this is done:
98 * <pre>
99 * {@code
100 * <activity android:name="your.package.YourDialerActivity"
101 * android:label="@string/yourDialerActivityLabel">
102 * <intent-filter>
103 * <action android:name="android.intent.action.DIAL" />
104 * <category android:name="android.intent.category.DEFAULT" />
105 * </intent-filter>
Tyler Gunn4057d4c2020-01-31 15:03:43 -0800106 * <intent-filter>
107 * <action android:name="android.intent.action.DIAL" />
108 * <category android:name="android.intent.category.DEFAULT" />
109 * <data android:scheme="tel" />
110 * </intent-filter>
Tyler Gunnfe39efa2018-02-02 13:18:02 -0800111 * </activity>
112 * }
113 * </pre>
114 * <p>
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800115 * When a user installs your application and runs it for the first time, you should use the
116 * {@link android.app.role.RoleManager} to prompt the user to see if they would like your app to
117 * be the new default phone app.
118 * <p id="requestRole">
119 * The code below shows how your app can request to become the default phone/dialer app:
120 * <pre>
121 * {@code
122 * private static final int REQUEST_ID = 1;
123 *
124 * public void requestRole() {
125 * RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
126 * Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_DIALER);
127 * startActivityForResult(intent, REQUEST_ID);
128 * }
129 *
130 * &#64;Override
131 * public void onActivityResult(int requestCode, int resultCode, Intent data) {
132 * if (requestCode == REQUEST_ID) {
133 * if (resultCode == android.app.Activity.RESULT_OK) {
134 * // Your app is now the default dialer app
135 * } else {
136 * // Your app is not the default dialer app
137 * }
138 * }
139 * }
Tyler Gunn4057d4c2020-01-31 15:03:43 -0800140 * }
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800141 * </pre>
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700142 * <p id="incomingCallNotification">
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800143 * <h3>Showing the Incoming Call Notification</h3>
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700144 * When your app receives a new incoming call via {@link InCallService#onCallAdded(Call)}, it is
145 * responsible for displaying an incoming call UI for the incoming call. It should do this using
146 * {@link android.app.NotificationManager} APIs to post a new incoming call notification.
147 * <p>
148 * Where your app declares the meta-data {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING}, it
149 * is responsible for playing the ringtone for incoming calls. Your app should create a
150 * {@link android.app.NotificationChannel} which specifies the desired ringtone. For example:
151 * <pre><code>
152 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
153 * NotificationManager.IMPORTANCE_MAX);
154 * // other channel setup stuff goes here.
155 *
156 * // We'll use the default system ringtone for our incoming call notification channel. You can
157 * // use your own audio resource here.
158 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
159 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
160 * // Setting the AudioAttributes is important as it identifies the purpose of your
161 * // notification sound.
162 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
163 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
164 * .build());
165 *
166 * NotificationManager mgr = getSystemService(NotificationManager.class);
167 * mgr.createNotificationChannel(channel);
168 * </code></pre>
169 * <p>
170 * When your app receives a new incoming call, it creates a {@link android.app.Notification} for the
171 * incoming call and associates it with your incoming call notification channel. You can specify a
172 * {@link android.app.PendingIntent} on the notification which will launch your full screen
173 * incoming call UI. The notification manager framework will display your notification as a
174 * heads-up notification if the user is actively using the phone. When the user is not using the
175 * phone, your full-screen incoming call UI is used instead.
176 * For example:
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800177 * <pre><code>{@code
Tyler Gunndc6e6c42018-07-03 16:08:17 -0700178 * // Create an intent which triggers your fullscreen incoming call user interface.
179 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
180 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
181 * intent.setClass(context, YourIncomingCallActivity.class);
182 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
183 *
184 * // Build the notification as an ongoing high priority item; this ensures it will show as
185 * // a heads up notification which slides down over top of the current content.
186 * final Notification.Builder builder = new Notification.Builder(context);
187 * builder.setOngoing(true);
188 * builder.setPriority(Notification.PRIORITY_HIGH);
189 *
190 * // Set notification content intent to take user to the fullscreen UI if user taps on the
191 * // notification body.
192 * builder.setContentIntent(pendingIntent);
193 * // Set full screen intent to trigger display of the fullscreen UI when the notification
194 * // manager deems it appropriate.
195 * builder.setFullScreenIntent(pendingIntent, true);
196 *
197 * // Setup notification content.
198 * builder.setSmallIcon( yourIconResourceId );
199 * builder.setContentTitle("Your notification title");
200 * builder.setContentText("Your notification content.");
201 *
202 * // Use builder.addAction(..) to add buttons to answer or reject the call.
203 *
204 * NotificationManager notificationManager = mContext.getSystemService(
205 * NotificationManager.class);
206 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, builder.build());
Tyler Gunn9e76fd19b2018-12-17 09:56:11 -0800207 * }</pre>
208 * <p>
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800209 */
Santos Cordon2f42b112014-07-19 13:19:37 -0700210public abstract class InCallService extends Service {
Tyler Gunn2ac40102014-08-18 16:23:10 -0700211
212 /**
213 * The {@link Intent} that must be declared as handled by the service.
214 */
215 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700216 public static final String SERVICE_INTERFACE = "android.telecom.InCallService";
Tyler Gunn2ac40102014-08-18 16:23:10 -0700217
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800218 private static final int MSG_SET_IN_CALL_ADAPTER = 1;
219 private static final int MSG_ADD_CALL = 2;
Sailesh Nepal60437932014-04-05 16:44:55 -0700220 private static final int MSG_UPDATE_CALL = 3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700221 private static final int MSG_SET_POST_DIAL_WAIT = 4;
Yorke Lee4af59352015-05-13 14:14:54 -0700222 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 5;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700223 private static final int MSG_BRING_TO_FOREGROUND = 6;
Santos Cordon6c912b72014-11-07 16:05:09 -0800224 private static final int MSG_ON_CAN_ADD_CALL_CHANGED = 7;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800225 private static final int MSG_SILENCE_RINGER = 8;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700226 private static final int MSG_ON_CONNECTION_EVENT = 9;
Hall Liu95d55872017-01-25 17:12:49 -0800227 private static final int MSG_ON_RTT_UPGRADE_REQUEST = 10;
Hall Liu57006aa2017-02-06 10:49:48 -0800228 private static final int MSG_ON_RTT_INITIATION_FAILURE = 11;
Sanket Padawe85291f62017-12-01 13:59:27 -0800229 private static final int MSG_ON_HANDOVER_FAILED = 12;
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800230 private static final int MSG_ON_HANDOVER_COMPLETE = 13;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800231
232 /** Default Handler used to consolidate binder method calls onto a single thread. */
233 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
234 @Override
235 public void handleMessage(Message msg) {
Jay Shrauner5e6162d2014-09-22 20:47:45 -0700236 if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) {
237 return;
238 }
239
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800240 switch (msg.what) {
241 case MSG_SET_IN_CALL_ADAPTER:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800242 String callingPackage = getApplicationContext().getOpPackageName();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800243 mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj), callingPackage,
244 getApplicationContext().getApplicationInfo().targetSdkVersion);
Santos Cordona2492812015-04-15 11:05:16 -0700245 mPhone.addListener(mPhoneListener);
Ihab Awade63fadb2014-07-09 21:52:04 -0700246 onPhoneCreated(mPhone);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800247 break;
248 case MSG_ADD_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700249 mPhone.internalAddCall((ParcelableCall) msg.obj);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800250 break;
Sailesh Nepal60437932014-04-05 16:44:55 -0700251 case MSG_UPDATE_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700252 mPhone.internalUpdateCall((ParcelableCall) msg.obj);
Ihab Awad2f236642014-03-10 15:33:45 -0700253 break;
Ihab Awad2f236642014-03-10 15:33:45 -0700254 case MSG_SET_POST_DIAL_WAIT: {
255 SomeArgs args = (SomeArgs) msg.obj;
256 try {
257 String callId = (String) args.arg1;
258 String remaining = (String) args.arg2;
Ihab Awade63fadb2014-07-09 21:52:04 -0700259 mPhone.internalSetPostDialWait(callId, remaining);
Ihab Awad2f236642014-03-10 15:33:45 -0700260 } finally {
261 args.recycle();
262 }
263 break;
264 }
Yorke Lee4af59352015-05-13 14:14:54 -0700265 case MSG_ON_CALL_AUDIO_STATE_CHANGED:
266 mPhone.internalCallAudioStateChanged((CallAudioState) msg.obj);
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700267 break;
Santos Cordon3534ede2014-05-29 13:07:10 -0700268 case MSG_BRING_TO_FOREGROUND:
Ihab Awade63fadb2014-07-09 21:52:04 -0700269 mPhone.internalBringToForeground(msg.arg1 == 1);
Santos Cordon3534ede2014-05-29 13:07:10 -0700270 break;
Santos Cordon6c912b72014-11-07 16:05:09 -0800271 case MSG_ON_CAN_ADD_CALL_CHANGED:
272 mPhone.internalSetCanAddCall(msg.arg1 == 1);
273 break;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800274 case MSG_SILENCE_RINGER:
275 mPhone.internalSilenceRinger();
276 break;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700277 case MSG_ON_CONNECTION_EVENT: {
278 SomeArgs args = (SomeArgs) msg.obj;
279 try {
280 String callId = (String) args.arg1;
281 String event = (String) args.arg2;
282 Bundle extras = (Bundle) args.arg3;
283 mPhone.internalOnConnectionEvent(callId, event, extras);
284 } finally {
285 args.recycle();
286 }
287 break;
288 }
Hall Liu95d55872017-01-25 17:12:49 -0800289 case MSG_ON_RTT_UPGRADE_REQUEST: {
290 String callId = (String) msg.obj;
291 int requestId = msg.arg1;
292 mPhone.internalOnRttUpgradeRequest(callId, requestId);
293 break;
294 }
Hall Liu57006aa2017-02-06 10:49:48 -0800295 case MSG_ON_RTT_INITIATION_FAILURE: {
296 String callId = (String) msg.obj;
297 int reason = msg.arg1;
298 mPhone.internalOnRttInitiationFailure(callId, reason);
299 break;
300 }
Sanket Padawe85291f62017-12-01 13:59:27 -0800301 case MSG_ON_HANDOVER_FAILED: {
302 String callId = (String) msg.obj;
303 int error = msg.arg1;
304 mPhone.internalOnHandoverFailed(callId, error);
305 break;
306 }
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800307 case MSG_ON_HANDOVER_COMPLETE: {
308 String callId = (String) msg.obj;
309 mPhone.internalOnHandoverComplete(callId);
310 break;
311 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800312 default:
313 break;
314 }
315 }
316 };
317
318 /** Manages the binder calls so that the implementor does not need to deal with it. */
319 private final class InCallServiceBinder extends IInCallService.Stub {
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800320 @Override
321 public void setInCallAdapter(IInCallAdapter inCallAdapter) {
322 mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget();
323 }
324
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800325 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700326 public void addCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700327 mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800328 }
329
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800330 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700331 public void updateCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700332 mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
Ihab Awad2f236642014-03-10 15:33:45 -0700333 }
334
335 @Override
336 public void setPostDial(String callId, String remaining) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700337 // TODO: Unused
Ihab Awad2f236642014-03-10 15:33:45 -0700338 }
339
340 @Override
341 public void setPostDialWait(String callId, String remaining) {
342 SomeArgs args = SomeArgs.obtain();
343 args.arg1 = callId;
344 args.arg2 = remaining;
345 mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
346 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700347
348 @Override
Yorke Lee4af59352015-05-13 14:14:54 -0700349 public void onCallAudioStateChanged(CallAudioState callAudioState) {
350 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, callAudioState).sendToTarget();
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700351 }
Santos Cordon3534ede2014-05-29 13:07:10 -0700352
Santos Cordon3534ede2014-05-29 13:07:10 -0700353 @Override
354 public void bringToForeground(boolean showDialpad) {
355 mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
356 }
Santos Cordon6c912b72014-11-07 16:05:09 -0800357
358 @Override
359 public void onCanAddCallChanged(boolean canAddCall) {
360 mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0)
361 .sendToTarget();
362 }
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800363
364 @Override
365 public void silenceRinger() {
366 mHandler.obtainMessage(MSG_SILENCE_RINGER).sendToTarget();
367 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700368
369 @Override
370 public void onConnectionEvent(String callId, String event, Bundle extras) {
371 SomeArgs args = SomeArgs.obtain();
372 args.arg1 = callId;
373 args.arg2 = event;
374 args.arg3 = extras;
375 mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget();
376 }
Hall Liu95d55872017-01-25 17:12:49 -0800377
378 @Override
379 public void onRttUpgradeRequest(String callId, int id) {
380 mHandler.obtainMessage(MSG_ON_RTT_UPGRADE_REQUEST, id, 0, callId).sendToTarget();
381 }
Hall Liu57006aa2017-02-06 10:49:48 -0800382
383 @Override
384 public void onRttInitiationFailure(String callId, int reason) {
385 mHandler.obtainMessage(MSG_ON_RTT_INITIATION_FAILURE, reason, 0, callId).sendToTarget();
386 }
Sanket Padawe85291f62017-12-01 13:59:27 -0800387
388 @Override
389 public void onHandoverFailed(String callId, int error) {
390 mHandler.obtainMessage(MSG_ON_HANDOVER_FAILED, error, 0, callId).sendToTarget();
391 }
Tyler Gunn858bfaf2018-01-22 15:17:54 -0800392
393 @Override
394 public void onHandoverComplete(String callId) {
395 mHandler.obtainMessage(MSG_ON_HANDOVER_COMPLETE, callId).sendToTarget();
396 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800397 }
398
Santos Cordona2492812015-04-15 11:05:16 -0700399 private Phone.Listener mPhoneListener = new Phone.Listener() {
400 /** ${inheritDoc} */
401 @Override
402 public void onAudioStateChanged(Phone phone, AudioState audioState) {
403 InCallService.this.onAudioStateChanged(audioState);
404 }
405
Yorke Lee4af59352015-05-13 14:14:54 -0700406 public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) {
407 InCallService.this.onCallAudioStateChanged(callAudioState);
408 };
409
Santos Cordona2492812015-04-15 11:05:16 -0700410 /** ${inheritDoc} */
411 @Override
412 public void onBringToForeground(Phone phone, boolean showDialpad) {
413 InCallService.this.onBringToForeground(showDialpad);
414 }
415
416 /** ${inheritDoc} */
417 @Override
418 public void onCallAdded(Phone phone, Call call) {
419 InCallService.this.onCallAdded(call);
420 }
421
422 /** ${inheritDoc} */
423 @Override
424 public void onCallRemoved(Phone phone, Call call) {
425 InCallService.this.onCallRemoved(call);
426 }
427
428 /** ${inheritDoc} */
429 @Override
430 public void onCanAddCallChanged(Phone phone, boolean canAddCall) {
431 InCallService.this.onCanAddCallChanged(canAddCall);
432 }
433
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800434 /** ${inheritDoc} */
435 @Override
436 public void onSilenceRinger(Phone phone) {
437 InCallService.this.onSilenceRinger();
438 }
439
Santos Cordona2492812015-04-15 11:05:16 -0700440 };
441
Ihab Awade63fadb2014-07-09 21:52:04 -0700442 private Phone mPhone;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800443
Santos Cordon2f42b112014-07-19 13:19:37 -0700444 public InCallService() {
445 }
Evan Charlton924748f2014-04-03 08:36:38 -0700446
Santos Cordon2f42b112014-07-19 13:19:37 -0700447 @Override
448 public IBinder onBind(Intent intent) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700449 return new InCallServiceBinder();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800450 }
451
Santos Cordonf30d7e92014-08-26 09:54:33 -0700452 @Override
453 public boolean onUnbind(Intent intent) {
Santos Cordon619b3c02014-09-02 17:13:45 -0700454 if (mPhone != null) {
455 Phone oldPhone = mPhone;
456 mPhone = null;
Santos Cordonf30d7e92014-08-26 09:54:33 -0700457
Santos Cordon619b3c02014-09-02 17:13:45 -0700458 oldPhone.destroy();
Santos Cordona2492812015-04-15 11:05:16 -0700459 // destroy sets all the calls to disconnected if any live ones still exist. Therefore,
460 // it is important to remove the Listener *after* the call to destroy so that
461 // InCallService.on* callbacks are appropriately called.
462 oldPhone.removeListener(mPhoneListener);
463
Santos Cordon619b3c02014-09-02 17:13:45 -0700464 onPhoneDestroyed(oldPhone);
465 }
Santos Cordona2492812015-04-15 11:05:16 -0700466
Santos Cordonf30d7e92014-08-26 09:54:33 -0700467 return false;
468 }
469
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800470 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700471 * Obtain the {@code Phone} associated with this {@code InCallService}.
472 *
473 * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null}
Santos Cordon2f42b112014-07-19 13:19:37 -0700474 * if the {@code InCallService} is not in a state where it has an associated
475 * {@code Phone}.
Santos Cordona2492812015-04-15 11:05:16 -0700476 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700477 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800478 */
Santos Cordona2492812015-04-15 11:05:16 -0700479 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700480 @Deprecated
481 public Phone getPhone() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700482 return mPhone;
Evan Charlton924748f2014-04-03 08:36:38 -0700483 }
484
485 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700486 * Obtains the current list of {@code Call}s to be displayed by this in-call service.
Santos Cordona2492812015-04-15 11:05:16 -0700487 *
488 * @return A list of the relevant {@code Call}s.
489 */
490 public final List<Call> getCalls() {
491 return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls();
492 }
493
494 /**
495 * Returns if the device can support additional calls.
496 *
497 * @return Whether the phone supports adding more calls.
498 */
499 public final boolean canAddCall() {
500 return mPhone == null ? false : mPhone.canAddCall();
501 }
502
503 /**
504 * Obtains the current phone call audio state.
505 *
506 * @return An object encapsulating the audio state. Returns null if the service is not
507 * fully initialized.
Yorke Lee4af59352015-05-13 14:14:54 -0700508 * @deprecated Use {@link #getCallAudioState()} instead.
509 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700510 */
Yorke Lee4af59352015-05-13 14:14:54 -0700511 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700512 public final AudioState getAudioState() {
513 return mPhone == null ? null : mPhone.getAudioState();
514 }
515
516 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700517 * Obtains the current phone call audio state.
518 *
519 * @return An object encapsulating the audio state. Returns null if the service is not
520 * fully initialized.
521 */
522 public final CallAudioState getCallAudioState() {
523 return mPhone == null ? null : mPhone.getCallAudioState();
524 }
525
526 /**
Santos Cordona2492812015-04-15 11:05:16 -0700527 * Sets the microphone mute state. When this request is honored, there will be change to
Yorke Lee4af59352015-05-13 14:14:54 -0700528 * the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700529 *
530 * @param state {@code true} if the microphone should be muted; {@code false} otherwise.
531 */
532 public final void setMuted(boolean state) {
533 if (mPhone != null) {
534 mPhone.setMuted(state);
535 }
536 }
537
538 /**
539 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
Yorke Lee4af59352015-05-13 14:14:54 -0700540 * be change to the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700541 *
542 * @param route The audio route to use.
543 */
544 public final void setAudioRoute(int route) {
545 if (mPhone != null) {
546 mPhone.setAudioRoute(route);
547 }
548 }
549
550 /**
Hall Liua98f58b52017-11-07 17:59:28 -0800551 * Request audio routing to a specific bluetooth device. Calling this method may result in
552 * the device routing audio to a different bluetooth device than the one specified if the
553 * bluetooth stack is unable to route audio to the requested device.
554 * A list of available devices can be obtained via
555 * {@link CallAudioState#getSupportedBluetoothDevices()}
556 *
Hall Liu15392832018-04-02 13:52:57 -0700557 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -0800558 */
Hall Liu15392832018-04-02 13:52:57 -0700559 public final void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -0800560 if (mPhone != null) {
Hall Liu15392832018-04-02 13:52:57 -0700561 mPhone.requestBluetoothAudio(bluetoothDevice.getAddress());
Hall Liua98f58b52017-11-07 17:59:28 -0800562 }
563 }
564
565 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700566 * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience
567 * to start displaying in-call information to the user. Each instance of {@code InCallService}
Santos Cordon2f42b112014-07-19 13:19:37 -0700568 * will have only one {@code Phone}, and this method will be called exactly once in the lifetime
569 * of the {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700570 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700571 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700572 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700573 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Evan Charlton924748f2014-04-03 08:36:38 -0700574 */
Santos Cordona2492812015-04-15 11:05:16 -0700575 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700576 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700577 public void onPhoneCreated(Phone phone) {
578 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800579
580 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700581 * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience
582 * to stop displaying in-call information to the user. This method will be called exactly once
583 * in the lifetime of the {@code InCallService}, and it will always be called after a previous
584 * call to {@link #onPhoneCreated(Phone)}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800585 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700586 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700587 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700588 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800589 */
Santos Cordona2492812015-04-15 11:05:16 -0700590 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700591 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700592 public void onPhoneDestroyed(Phone phone) {
593 }
Andrew Lee50aca232014-07-22 16:41:54 -0700594
595 /**
Santos Cordona2492812015-04-15 11:05:16 -0700596 * Called when the audio state changes.
597 *
598 * @param audioState The new {@link AudioState}.
Yorke Lee4af59352015-05-13 14:14:54 -0700599 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState) instead}.
600 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700601 */
Yorke Lee4af59352015-05-13 14:14:54 -0700602 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700603 public void onAudioStateChanged(AudioState audioState) {
604 }
605
606 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700607 * Called when the audio state changes.
608 *
609 * @param audioState The new {@link CallAudioState}.
610 */
611 public void onCallAudioStateChanged(CallAudioState audioState) {
612 }
613
614 /**
Santos Cordona2492812015-04-15 11:05:16 -0700615 * Called to bring the in-call screen to the foreground. The in-call experience should
616 * respond immediately by coming to the foreground to inform the user of the state of
617 * ongoing {@code Call}s.
618 *
619 * @param showDialpad If true, put up the dialpad when the screen is shown.
620 */
621 public void onBringToForeground(boolean showDialpad) {
622 }
623
624 /**
625 * Called when a {@code Call} has been added to this in-call session. The in-call user
626 * experience should add necessary state listeners to the specified {@code Call} and
627 * immediately start to show the user information about the existence
628 * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will
629 * include this {@code Call}.
630 *
631 * @param call A newly added {@code Call}.
632 */
633 public void onCallAdded(Call call) {
634 }
635
636 /**
637 * Called when a {@code Call} has been removed from this in-call session. The in-call user
638 * experience should remove any state listeners from the specified {@code Call} and
639 * immediately stop displaying any information about this {@code Call}.
640 * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}.
641 *
642 * @param call A newly removed {@code Call}.
643 */
644 public void onCallRemoved(Call call) {
645 }
646
647 /**
648 * Called when the ability to add more calls changes. If the phone cannot
649 * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it
650 * is set to {@code true}. This can be used to control the visibility of UI to add more calls.
651 *
652 * @param canAddCall Indicates whether an additional call can be added.
653 */
654 public void onCanAddCallChanged(boolean canAddCall) {
655 }
656
657 /**
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800658 * Called to silence the ringer if a ringing call exists.
659 */
660 public void onSilenceRinger() {
661 }
662
663 /**
Tyler Gunn06f3fa62016-08-25 09:26:15 -0700664 * Unused; to handle connection events issued by a {@link ConnectionService}, implement the
665 * {@link android.telecom.Call.Callback#onConnectionEvent(Call, String, Bundle)} callback.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700666 * <p>
667 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
668 *
669 * @param call The call the event is associated with.
670 * @param event The event.
671 * @param extras Any associated extras.
672 */
673 public void onConnectionEvent(Call call, String event, Bundle extras) {
674 }
675
676 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700677 * Used to issue commands to the {@link Connection.VideoProvider} associated with a
678 * {@link Call}.
Andrew Lee50aca232014-07-22 16:41:54 -0700679 */
680 public static abstract class VideoCall {
681
Andrew Lee011728f2015-04-23 15:47:06 -0700682 /** @hide */
Aurimas Liutikasd23189b2020-11-10 15:32:51 -0800683 @SuppressWarnings("HiddenAbstractMethod")
Andrew Lee011728f2015-04-23 15:47:06 -0700684 public abstract void destroy();
685
Andrew Lee50aca232014-07-22 16:41:54 -0700686 /**
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700687 * Registers a callback to receive commands and state changes for video calls.
Andrew Lee50aca232014-07-22 16:41:54 -0700688 *
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700689 * @param callback The video call callback.
Andrew Lee50aca232014-07-22 16:41:54 -0700690 */
Andrew Leeda80c872015-04-15 14:09:50 -0700691 public abstract void registerCallback(VideoCall.Callback callback);
692
693 /**
Andrew Lee011728f2015-04-23 15:47:06 -0700694 * Registers a callback to receive commands and state changes for video calls.
695 *
696 * @param callback The video call callback.
697 * @param handler A handler which commands and status changes will be delivered to.
698 */
699 public abstract void registerCallback(VideoCall.Callback callback, Handler handler);
700
701 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700702 * Clears the video call callback set via {@link #registerCallback}.
Tyler Gunn295f5d72015-06-04 11:08:54 -0700703 *
704 * @param callback The video call callback to clear.
Tyler Gunn75958422015-04-15 14:23:42 -0700705 */
Andrew Lee011728f2015-04-23 15:47:06 -0700706 public abstract void unregisterCallback(VideoCall.Callback callback);
Tyler Gunn75958422015-04-15 14:23:42 -0700707
708 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700709 * Sets the camera to be used for the outgoing video.
710 * <p>
711 * Handled by {@link Connection.VideoProvider#onSetCamera(String)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700712 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700713 * @param cameraId The id of the camera (use ids as reported by
714 * {@link CameraManager#getCameraIdList()}).
Andrew Lee50aca232014-07-22 16:41:54 -0700715 */
716 public abstract void setCamera(String cameraId);
717
718 /**
719 * Sets the surface to be used for displaying a preview of what the user's camera is
720 * currently capturing. When video transmission is enabled, this is the video signal which
721 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700722 * <p>
723 * Handled by {@link Connection.VideoProvider#onSetPreviewSurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700724 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700725 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700726 */
727 public abstract void setPreviewSurface(Surface surface);
728
729 /**
730 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700731 * <p>
732 * Handled by {@link Connection.VideoProvider#onSetDisplaySurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700733 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700734 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700735 */
736 public abstract void setDisplaySurface(Surface surface);
737
738 /**
739 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
740 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700741 * <p>
742 * Handled by {@link Connection.VideoProvider#onSetDeviceOrientation(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700743 *
744 * @param rotation The device orientation, in degrees.
745 */
746 public abstract void setDeviceOrientation(int rotation);
747
748 /**
749 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700750 * <p>
751 * Handled by {@link Connection.VideoProvider#onSetZoom(float)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700752 *
753 * @param value The camera zoom ratio.
754 */
755 public abstract void setZoom(float value);
756
757 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700758 * Issues a request to modify the properties of the current video session.
759 * <p>
760 * Example scenarios include: requesting an audio-only call to be upgraded to a
761 * bi-directional video call, turning on or off the user's camera, sending a pause signal
762 * when the {@link InCallService} is no longer the foreground application.
763 * <p>
764 * Handled by
765 * {@link Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700766 *
767 * @param requestProfile The requested call video properties.
768 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700769 public abstract void sendSessionModifyRequest(VideoProfile requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700770
771 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700772 * Provides a response to a request to change the current call video session
773 * properties. This should be called in response to a request the {@link InCallService} has
774 * received via {@link VideoCall.Callback#onSessionModifyRequestReceived}.
775 * <p>
776 * Handled by
777 * {@link Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700778 *
779 * @param responseProfile The response call video properties.
780 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700781 public abstract void sendSessionModifyResponse(VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700782
783 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700784 * Issues a request to the {@link Connection.VideoProvider} to retrieve the capabilities
785 * of the current camera. The current camera is selected using
786 * {@link VideoCall#setCamera(String)}.
787 * <p>
788 * Camera capabilities are reported to the caller via
789 * {@link VideoCall.Callback#onCameraCapabilitiesChanged(VideoProfile.CameraCapabilities)}.
790 * <p>
791 * Handled by {@link Connection.VideoProvider#onRequestCameraCapabilities()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700792 */
793 public abstract void requestCameraCapabilities();
794
795 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700796 * Issues a request to the {@link Connection.VideoProvider} to retrieve the cumulative data
797 * usage for the video component of the current call (in bytes). Data usage is reported
798 * to the caller via {@link VideoCall.Callback#onCallDataUsageChanged}.
799 * <p>
800 * Handled by {@link Connection.VideoProvider#onRequestConnectionDataUsage()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700801 */
802 public abstract void requestCallDataUsage();
803
804 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700805 * Provides the {@link Connection.VideoProvider} with the {@link Uri} of an image to be
806 * displayed to the peer device when the video signal is paused.
807 * <p>
808 * Handled by {@link Connection.VideoProvider#onSetPauseImage(Uri)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700809 *
810 * @param uri URI of image to display.
811 */
Yorke Lee32f24732015-05-12 16:18:03 -0700812 public abstract void setPauseImage(Uri uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700813
814 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700815 * The {@link InCallService} extends this class to provide a means of receiving callbacks
Tyler Gunn295f5d72015-06-04 11:08:54 -0700816 * from the {@link Connection.VideoProvider}.
817 * <p>
Tyler Gunnb702ef82015-05-29 11:51:53 -0700818 * When the {@link InCallService} receives the
819 * {@link Call.Callback#onVideoCallChanged(Call, VideoCall)} callback, it should create an
820 * instance its {@link VideoCall.Callback} implementation and set it on the
821 * {@link VideoCall} using {@link VideoCall#registerCallback(Callback)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700822 */
Andrew Leeda80c872015-04-15 14:09:50 -0700823 public static abstract class Callback {
Andrew Lee50aca232014-07-22 16:41:54 -0700824 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700825 * Called when the {@link Connection.VideoProvider} receives a session modification
Tyler Gunn295f5d72015-06-04 11:08:54 -0700826 * request from the peer device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700827 * <p>
828 * The {@link InCallService} may potentially prompt the user to confirm whether they
829 * wish to accept the request, or decide to automatically accept the request. In either
830 * case the {@link InCallService} should call
831 * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} to indicate the video
832 * profile agreed upon.
833 * <p>
834 * Callback originates from
835 * {@link Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700836 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700837 * @param videoProfile The requested video profile.
Andrew Lee50aca232014-07-22 16:41:54 -0700838 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700839 public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700840
841 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700842 * Called when the {@link Connection.VideoProvider} receives a response to a session
843 * modification request previously sent to the peer device.
844 * <p>
845 * The new video state should not be considered active by the {@link InCallService}
846 * until the {@link Call} video state changes (the
847 * {@link Call.Callback#onDetailsChanged(Call, Call.Details)} callback is triggered
848 * when the video state changes).
849 * <p>
850 * Callback originates from
851 * {@link Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
852 * VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700853 *
854 * @param status Status of the session modify request. Valid values are
Tyler Gunnb702ef82015-05-29 11:51:53 -0700855 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
856 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
857 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
858 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
859 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}.
860 * @param requestedProfile The original request which was sent to the peer device.
861 * @param responseProfile The actual profile changes made by the peer device.
Andrew Lee50aca232014-07-22 16:41:54 -0700862 */
863 public abstract void onSessionModifyResponseReceived(int status,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700864 VideoProfile requestedProfile, VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700865
866 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700867 * Handles events related to the current video session which the {@link InCallService}
868 * may wish to handle. These are separate from requested changes to the session due to
869 * the underlying protocol or connection.
870 * <p>
871 * Callback originates from
872 * {@link Connection.VideoProvider#handleCallSessionEvent(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700873 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700874 * @param event The event. Valid values are:
875 * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE},
876 * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME},
877 * {@link Connection.VideoProvider#SESSION_EVENT_TX_START},
878 * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP},
879 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800880 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY},
881 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_PERMISSION_ERROR}.
Andrew Lee50aca232014-07-22 16:41:54 -0700882 */
883 public abstract void onCallSessionEvent(int event);
884
885 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700886 * Handles a change to the video dimensions from the peer device. This could happen if,
887 * for example, the peer changes orientation of their device, or switches cameras.
888 * <p>
889 * Callback originates from
890 * {@link Connection.VideoProvider#changePeerDimensions(int, int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700891 *
892 * @param width The updated peer video width.
893 * @param height The updated peer video height.
894 */
895 public abstract void onPeerDimensionsChanged(int width, int height);
896
897 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700898 * Handles a change to the video quality.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700899 * <p>
900 * Callback originates from {@link Connection.VideoProvider#changeVideoQuality(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700901 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700902 * @param videoQuality The updated peer video quality. Valid values:
903 * {@link VideoProfile#QUALITY_HIGH},
904 * {@link VideoProfile#QUALITY_MEDIUM},
905 * {@link VideoProfile#QUALITY_LOW},
906 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700907 */
908 public abstract void onVideoQualityChanged(int videoQuality);
909
910 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700911 * Handles an update to the total data used for the current video session.
912 * <p>
913 * Used by the {@link Connection.VideoProvider} in response to
914 * {@link VideoCall#requestCallDataUsage()}. May also be called periodically by the
915 * {@link Connection.VideoProvider}.
916 * <p>
917 * Callback originates from {@link Connection.VideoProvider#setCallDataUsage(long)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700918 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700919 * @param dataUsage The updated data usage (in bytes).
Andrew Lee50aca232014-07-22 16:41:54 -0700920 */
Rekha Kumar07366812015-03-24 16:42:31 -0700921 public abstract void onCallDataUsageChanged(long dataUsage);
Andrew Lee50aca232014-07-22 16:41:54 -0700922
923 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700924 * Handles a change in the capabilities of the currently selected camera.
925 * <p>
926 * Used by the {@link Connection.VideoProvider} in response to
927 * {@link VideoCall#requestCameraCapabilities()}. The {@link Connection.VideoProvider}
928 * may also report the camera capabilities after a call to
929 * {@link VideoCall#setCamera(String)}.
930 * <p>
931 * Callback originates from
932 * {@link Connection.VideoProvider#changeCameraCapabilities(
933 * VideoProfile.CameraCapabilities)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700934 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700935 * @param cameraCapabilities The changed camera capabilities.
Andrew Lee50aca232014-07-22 16:41:54 -0700936 */
Yorke Lee400470f2015-05-12 13:31:25 -0700937 public abstract void onCameraCapabilitiesChanged(
938 VideoProfile.CameraCapabilities cameraCapabilities);
Andrew Lee50aca232014-07-22 16:41:54 -0700939 }
940 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800941}