blob: df6715d41a3f9efb9f187e1893c62a62365f6215 [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
Tyler Gunn2ac40102014-08-18 16:23:10 -070019import android.annotation.SdkConstant;
Santos Cordona2492812015-04-15 11:05:16 -070020import android.annotation.SystemApi;
Santos Cordon2f42b112014-07-19 13:19:37 -070021import android.app.Service;
22import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070023import android.hardware.camera2.CameraManager;
Yorke Lee32f24732015-05-12 16:18:03 -070024import android.net.Uri;
Tyler Gunn876dbfb2016-03-14 15:18:07 -070025import android.os.Bundle;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080026import android.os.Handler;
27import android.os.IBinder;
28import android.os.Looper;
29import android.os.Message;
Andrew Lee50aca232014-07-22 16:41:54 -070030import android.view.Surface;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080031
Ihab Awad2f236642014-03-10 15:33:45 -070032import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070033import com.android.internal.telecom.IInCallAdapter;
34import com.android.internal.telecom.IInCallService;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080035
Andrew Lee50aca232014-07-22 16:41:54 -070036import java.lang.String;
Santos Cordona2492812015-04-15 11:05:16 -070037import java.util.Collections;
38import java.util.List;
Andrew Lee50aca232014-07-22 16:41:54 -070039
Sailesh Nepalab5d2822014-03-08 18:01:06 -080040/**
41 * This service is implemented by any app that wishes to provide the user-interface for managing
Tyler Gunnef9f6f92014-09-12 22:16:17 -070042 * phone calls. Telecom binds to this service while there exists a live (active or incoming) call,
Santos Cordonf2600eb2015-06-22 15:02:20 -070043 * and uses it to notify the in-call app of any live and recently disconnected calls. An app must
44 * first be set as the default phone app (See {@link TelecomManager#getDefaultDialerPackage()})
45 * before the telecom service will bind to its {@code InCallService} implementation.
46 * <p>
47 * Below is an example manifest registration for an {@code InCallService}. The meta-data
48 * ({@link TelecomManager#METADATA_IN_CALL_SERVICE_UI}) indicates that this particular
49 * {@code InCallService} implementation intends to replace the built-in in-call UI.
50 * <pre>
51 * {@code
Neil Fuller71fbb812015-11-30 09:51:33 +000052 * <service android:name="your.package.YourInCallServiceImplementation"
Sailesh Nepal78f3ba62015-12-28 16:20:56 -080053 * android:permission="android.permission.BIND_INCALL_SERVICE">
Neil Fuller71fbb812015-11-30 09:51:33 +000054 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
55 * <intent-filter>
56 * <action android:name="android.telecom.InCallService"/>
57 * </intent-filter>
58 * </service>
Santos Cordonf2600eb2015-06-22 15:02:20 -070059 * }
60 * </pre>
Sailesh Nepalab5d2822014-03-08 18:01:06 -080061 */
Santos Cordon2f42b112014-07-19 13:19:37 -070062public abstract class InCallService extends Service {
Tyler Gunn2ac40102014-08-18 16:23:10 -070063
64 /**
65 * The {@link Intent} that must be declared as handled by the service.
66 */
67 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070068 public static final String SERVICE_INTERFACE = "android.telecom.InCallService";
Tyler Gunn2ac40102014-08-18 16:23:10 -070069
Sailesh Nepalab5d2822014-03-08 18:01:06 -080070 private static final int MSG_SET_IN_CALL_ADAPTER = 1;
71 private static final int MSG_ADD_CALL = 2;
Sailesh Nepal60437932014-04-05 16:44:55 -070072 private static final int MSG_UPDATE_CALL = 3;
Ihab Awad5d0410f2014-07-30 10:07:40 -070073 private static final int MSG_SET_POST_DIAL_WAIT = 4;
Yorke Lee4af59352015-05-13 14:14:54 -070074 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 5;
Ihab Awad5d0410f2014-07-30 10:07:40 -070075 private static final int MSG_BRING_TO_FOREGROUND = 6;
Santos Cordon6c912b72014-11-07 16:05:09 -080076 private static final int MSG_ON_CAN_ADD_CALL_CHANGED = 7;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -080077 private static final int MSG_SILENCE_RINGER = 8;
Tyler Gunn876dbfb2016-03-14 15:18:07 -070078 private static final int MSG_ON_CONNECTION_EVENT = 9;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080079
80 /** Default Handler used to consolidate binder method calls onto a single thread. */
81 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
82 @Override
83 public void handleMessage(Message msg) {
Jay Shrauner5e6162d2014-09-22 20:47:45 -070084 if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) {
85 return;
86 }
87
Sailesh Nepalab5d2822014-03-08 18:01:06 -080088 switch (msg.what) {
89 case MSG_SET_IN_CALL_ADAPTER:
Ihab Awade63fadb2014-07-09 21:52:04 -070090 mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj));
Santos Cordona2492812015-04-15 11:05:16 -070091 mPhone.addListener(mPhoneListener);
Ihab Awade63fadb2014-07-09 21:52:04 -070092 onPhoneCreated(mPhone);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080093 break;
94 case MSG_ADD_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -070095 mPhone.internalAddCall((ParcelableCall) msg.obj);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080096 break;
Sailesh Nepal60437932014-04-05 16:44:55 -070097 case MSG_UPDATE_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -070098 mPhone.internalUpdateCall((ParcelableCall) msg.obj);
Ihab Awad2f236642014-03-10 15:33:45 -070099 break;
Ihab Awad2f236642014-03-10 15:33:45 -0700100 case MSG_SET_POST_DIAL_WAIT: {
101 SomeArgs args = (SomeArgs) msg.obj;
102 try {
103 String callId = (String) args.arg1;
104 String remaining = (String) args.arg2;
Ihab Awade63fadb2014-07-09 21:52:04 -0700105 mPhone.internalSetPostDialWait(callId, remaining);
Ihab Awad2f236642014-03-10 15:33:45 -0700106 } finally {
107 args.recycle();
108 }
109 break;
110 }
Yorke Lee4af59352015-05-13 14:14:54 -0700111 case MSG_ON_CALL_AUDIO_STATE_CHANGED:
112 mPhone.internalCallAudioStateChanged((CallAudioState) msg.obj);
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700113 break;
Santos Cordon3534ede2014-05-29 13:07:10 -0700114 case MSG_BRING_TO_FOREGROUND:
Ihab Awade63fadb2014-07-09 21:52:04 -0700115 mPhone.internalBringToForeground(msg.arg1 == 1);
Santos Cordon3534ede2014-05-29 13:07:10 -0700116 break;
Santos Cordon6c912b72014-11-07 16:05:09 -0800117 case MSG_ON_CAN_ADD_CALL_CHANGED:
118 mPhone.internalSetCanAddCall(msg.arg1 == 1);
119 break;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800120 case MSG_SILENCE_RINGER:
121 mPhone.internalSilenceRinger();
122 break;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700123 case MSG_ON_CONNECTION_EVENT: {
124 SomeArgs args = (SomeArgs) msg.obj;
125 try {
126 String callId = (String) args.arg1;
127 String event = (String) args.arg2;
128 Bundle extras = (Bundle) args.arg3;
129 mPhone.internalOnConnectionEvent(callId, event, extras);
130 } finally {
131 args.recycle();
132 }
133 break;
134 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800135 default:
136 break;
137 }
138 }
139 };
140
141 /** Manages the binder calls so that the implementor does not need to deal with it. */
142 private final class InCallServiceBinder extends IInCallService.Stub {
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800143 @Override
144 public void setInCallAdapter(IInCallAdapter inCallAdapter) {
145 mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget();
146 }
147
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800148 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700149 public void addCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700150 mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800151 }
152
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800153 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700154 public void updateCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700155 mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
Ihab Awad2f236642014-03-10 15:33:45 -0700156 }
157
158 @Override
159 public void setPostDial(String callId, String remaining) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700160 // TODO: Unused
Ihab Awad2f236642014-03-10 15:33:45 -0700161 }
162
163 @Override
164 public void setPostDialWait(String callId, String remaining) {
165 SomeArgs args = SomeArgs.obtain();
166 args.arg1 = callId;
167 args.arg2 = remaining;
168 mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
169 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700170
171 @Override
Yorke Lee4af59352015-05-13 14:14:54 -0700172 public void onCallAudioStateChanged(CallAudioState callAudioState) {
173 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, callAudioState).sendToTarget();
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700174 }
Santos Cordon3534ede2014-05-29 13:07:10 -0700175
Santos Cordon3534ede2014-05-29 13:07:10 -0700176 @Override
177 public void bringToForeground(boolean showDialpad) {
178 mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
179 }
Santos Cordon6c912b72014-11-07 16:05:09 -0800180
181 @Override
182 public void onCanAddCallChanged(boolean canAddCall) {
183 mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0)
184 .sendToTarget();
185 }
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800186
187 @Override
188 public void silenceRinger() {
189 mHandler.obtainMessage(MSG_SILENCE_RINGER).sendToTarget();
190 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700191
192 @Override
193 public void onConnectionEvent(String callId, String event, Bundle extras) {
194 SomeArgs args = SomeArgs.obtain();
195 args.arg1 = callId;
196 args.arg2 = event;
197 args.arg3 = extras;
198 mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget();
199 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800200 }
201
Santos Cordona2492812015-04-15 11:05:16 -0700202 private Phone.Listener mPhoneListener = new Phone.Listener() {
203 /** ${inheritDoc} */
204 @Override
205 public void onAudioStateChanged(Phone phone, AudioState audioState) {
206 InCallService.this.onAudioStateChanged(audioState);
207 }
208
Yorke Lee4af59352015-05-13 14:14:54 -0700209 public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) {
210 InCallService.this.onCallAudioStateChanged(callAudioState);
211 };
212
Santos Cordona2492812015-04-15 11:05:16 -0700213 /** ${inheritDoc} */
214 @Override
215 public void onBringToForeground(Phone phone, boolean showDialpad) {
216 InCallService.this.onBringToForeground(showDialpad);
217 }
218
219 /** ${inheritDoc} */
220 @Override
221 public void onCallAdded(Phone phone, Call call) {
222 InCallService.this.onCallAdded(call);
223 }
224
225 /** ${inheritDoc} */
226 @Override
227 public void onCallRemoved(Phone phone, Call call) {
228 InCallService.this.onCallRemoved(call);
229 }
230
231 /** ${inheritDoc} */
232 @Override
233 public void onCanAddCallChanged(Phone phone, boolean canAddCall) {
234 InCallService.this.onCanAddCallChanged(canAddCall);
235 }
236
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800237 /** ${inheritDoc} */
238 @Override
239 public void onSilenceRinger(Phone phone) {
240 InCallService.this.onSilenceRinger();
241 }
242
Santos Cordona2492812015-04-15 11:05:16 -0700243 };
244
Ihab Awade63fadb2014-07-09 21:52:04 -0700245 private Phone mPhone;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800246
Santos Cordon2f42b112014-07-19 13:19:37 -0700247 public InCallService() {
248 }
Evan Charlton924748f2014-04-03 08:36:38 -0700249
Santos Cordon2f42b112014-07-19 13:19:37 -0700250 @Override
251 public IBinder onBind(Intent intent) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700252 return new InCallServiceBinder();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800253 }
254
Santos Cordonf30d7e92014-08-26 09:54:33 -0700255 @Override
256 public boolean onUnbind(Intent intent) {
Santos Cordon619b3c02014-09-02 17:13:45 -0700257 if (mPhone != null) {
258 Phone oldPhone = mPhone;
259 mPhone = null;
Santos Cordonf30d7e92014-08-26 09:54:33 -0700260
Santos Cordon619b3c02014-09-02 17:13:45 -0700261 oldPhone.destroy();
Santos Cordona2492812015-04-15 11:05:16 -0700262 // destroy sets all the calls to disconnected if any live ones still exist. Therefore,
263 // it is important to remove the Listener *after* the call to destroy so that
264 // InCallService.on* callbacks are appropriately called.
265 oldPhone.removeListener(mPhoneListener);
266
Santos Cordon619b3c02014-09-02 17:13:45 -0700267 onPhoneDestroyed(oldPhone);
268 }
Santos Cordona2492812015-04-15 11:05:16 -0700269
Santos Cordonf30d7e92014-08-26 09:54:33 -0700270 return false;
271 }
272
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800273 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700274 * Obtain the {@code Phone} associated with this {@code InCallService}.
275 *
276 * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null}
Santos Cordon2f42b112014-07-19 13:19:37 -0700277 * if the {@code InCallService} is not in a state where it has an associated
278 * {@code Phone}.
Santos Cordona2492812015-04-15 11:05:16 -0700279 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700280 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800281 */
Santos Cordona2492812015-04-15 11:05:16 -0700282 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700283 @Deprecated
284 public Phone getPhone() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700285 return mPhone;
Evan Charlton924748f2014-04-03 08:36:38 -0700286 }
287
288 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700289 * Obtains the current list of {@code Call}s to be displayed by this in-call service.
Santos Cordona2492812015-04-15 11:05:16 -0700290 *
291 * @return A list of the relevant {@code Call}s.
292 */
293 public final List<Call> getCalls() {
294 return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls();
295 }
296
297 /**
298 * Returns if the device can support additional calls.
299 *
300 * @return Whether the phone supports adding more calls.
301 */
302 public final boolean canAddCall() {
303 return mPhone == null ? false : mPhone.canAddCall();
304 }
305
306 /**
307 * Obtains the current phone call audio state.
308 *
309 * @return An object encapsulating the audio state. Returns null if the service is not
310 * fully initialized.
Yorke Lee4af59352015-05-13 14:14:54 -0700311 * @deprecated Use {@link #getCallAudioState()} instead.
312 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700313 */
Yorke Lee4af59352015-05-13 14:14:54 -0700314 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700315 public final AudioState getAudioState() {
316 return mPhone == null ? null : mPhone.getAudioState();
317 }
318
319 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700320 * Obtains the current phone call audio state.
321 *
322 * @return An object encapsulating the audio state. Returns null if the service is not
323 * fully initialized.
324 */
325 public final CallAudioState getCallAudioState() {
326 return mPhone == null ? null : mPhone.getCallAudioState();
327 }
328
329 /**
Santos Cordona2492812015-04-15 11:05:16 -0700330 * Sets the microphone mute state. When this request is honored, there will be change to
Yorke Lee4af59352015-05-13 14:14:54 -0700331 * the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700332 *
333 * @param state {@code true} if the microphone should be muted; {@code false} otherwise.
334 */
335 public final void setMuted(boolean state) {
336 if (mPhone != null) {
337 mPhone.setMuted(state);
338 }
339 }
340
341 /**
342 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
Yorke Lee4af59352015-05-13 14:14:54 -0700343 * be change to the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700344 *
345 * @param route The audio route to use.
346 */
347 public final void setAudioRoute(int route) {
348 if (mPhone != null) {
349 mPhone.setAudioRoute(route);
350 }
351 }
352
353 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700354 * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience
355 * to start displaying in-call information to the user. Each instance of {@code InCallService}
Santos Cordon2f42b112014-07-19 13:19:37 -0700356 * will have only one {@code Phone}, and this method will be called exactly once in the lifetime
357 * of the {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700358 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700359 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700360 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700361 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Evan Charlton924748f2014-04-03 08:36:38 -0700362 */
Santos Cordona2492812015-04-15 11:05:16 -0700363 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700364 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700365 public void onPhoneCreated(Phone phone) {
366 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800367
368 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700369 * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience
370 * to stop displaying in-call information to the user. This method will be called exactly once
371 * in the lifetime of the {@code InCallService}, and it will always be called after a previous
372 * call to {@link #onPhoneCreated(Phone)}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800373 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700374 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700375 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700376 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800377 */
Santos Cordona2492812015-04-15 11:05:16 -0700378 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700379 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700380 public void onPhoneDestroyed(Phone phone) {
381 }
Andrew Lee50aca232014-07-22 16:41:54 -0700382
383 /**
Santos Cordona2492812015-04-15 11:05:16 -0700384 * Called when the audio state changes.
385 *
386 * @param audioState The new {@link AudioState}.
Yorke Lee4af59352015-05-13 14:14:54 -0700387 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState) instead}.
388 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700389 */
Yorke Lee4af59352015-05-13 14:14:54 -0700390 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700391 public void onAudioStateChanged(AudioState audioState) {
392 }
393
394 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700395 * Called when the audio state changes.
396 *
397 * @param audioState The new {@link CallAudioState}.
398 */
399 public void onCallAudioStateChanged(CallAudioState audioState) {
400 }
401
402 /**
Santos Cordona2492812015-04-15 11:05:16 -0700403 * Called to bring the in-call screen to the foreground. The in-call experience should
404 * respond immediately by coming to the foreground to inform the user of the state of
405 * ongoing {@code Call}s.
406 *
407 * @param showDialpad If true, put up the dialpad when the screen is shown.
408 */
409 public void onBringToForeground(boolean showDialpad) {
410 }
411
412 /**
413 * Called when a {@code Call} has been added to this in-call session. The in-call user
414 * experience should add necessary state listeners to the specified {@code Call} and
415 * immediately start to show the user information about the existence
416 * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will
417 * include this {@code Call}.
418 *
419 * @param call A newly added {@code Call}.
420 */
421 public void onCallAdded(Call call) {
422 }
423
424 /**
425 * Called when a {@code Call} has been removed from this in-call session. The in-call user
426 * experience should remove any state listeners from the specified {@code Call} and
427 * immediately stop displaying any information about this {@code Call}.
428 * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}.
429 *
430 * @param call A newly removed {@code Call}.
431 */
432 public void onCallRemoved(Call call) {
433 }
434
435 /**
436 * Called when the ability to add more calls changes. If the phone cannot
437 * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it
438 * is set to {@code true}. This can be used to control the visibility of UI to add more calls.
439 *
440 * @param canAddCall Indicates whether an additional call can be added.
441 */
442 public void onCanAddCallChanged(boolean canAddCall) {
443 }
444
445 /**
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800446 * Called to silence the ringer if a ringing call exists.
447 */
448 public void onSilenceRinger() {
449 }
450
451 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700452 * Called when a {@link Call} has received a connection event issued by the
453 * {@link ConnectionService}.
454 * <p>
455 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
456 *
457 * @param call The call the event is associated with.
458 * @param event The event.
459 * @param extras Any associated extras.
460 */
461 public void onConnectionEvent(Call call, String event, Bundle extras) {
462 }
463
464 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700465 * Used to issue commands to the {@link Connection.VideoProvider} associated with a
466 * {@link Call}.
Andrew Lee50aca232014-07-22 16:41:54 -0700467 */
468 public static abstract class VideoCall {
469
Andrew Lee011728f2015-04-23 15:47:06 -0700470 /** @hide */
471 public abstract void destroy();
472
Andrew Lee50aca232014-07-22 16:41:54 -0700473 /**
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700474 * Registers a callback to receive commands and state changes for video calls.
Andrew Lee50aca232014-07-22 16:41:54 -0700475 *
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700476 * @param callback The video call callback.
Andrew Lee50aca232014-07-22 16:41:54 -0700477 */
Andrew Leeda80c872015-04-15 14:09:50 -0700478 public abstract void registerCallback(VideoCall.Callback callback);
479
480 /**
Andrew Lee011728f2015-04-23 15:47:06 -0700481 * Registers a callback to receive commands and state changes for video calls.
482 *
483 * @param callback The video call callback.
484 * @param handler A handler which commands and status changes will be delivered to.
485 */
486 public abstract void registerCallback(VideoCall.Callback callback, Handler handler);
487
488 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700489 * Clears the video call callback set via {@link #registerCallback}.
Tyler Gunn295f5d72015-06-04 11:08:54 -0700490 *
491 * @param callback The video call callback to clear.
Tyler Gunn75958422015-04-15 14:23:42 -0700492 */
Andrew Lee011728f2015-04-23 15:47:06 -0700493 public abstract void unregisterCallback(VideoCall.Callback callback);
Tyler Gunn75958422015-04-15 14:23:42 -0700494
495 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700496 * Sets the camera to be used for the outgoing video.
497 * <p>
498 * Handled by {@link Connection.VideoProvider#onSetCamera(String)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700499 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700500 * @param cameraId The id of the camera (use ids as reported by
501 * {@link CameraManager#getCameraIdList()}).
Andrew Lee50aca232014-07-22 16:41:54 -0700502 */
503 public abstract void setCamera(String cameraId);
504
505 /**
506 * Sets the surface to be used for displaying a preview of what the user's camera is
507 * currently capturing. When video transmission is enabled, this is the video signal which
508 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700509 * <p>
510 * Handled by {@link Connection.VideoProvider#onSetPreviewSurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700511 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700512 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700513 */
514 public abstract void setPreviewSurface(Surface surface);
515
516 /**
517 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700518 * <p>
519 * Handled by {@link Connection.VideoProvider#onSetDisplaySurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700520 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700521 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700522 */
523 public abstract void setDisplaySurface(Surface surface);
524
525 /**
526 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
527 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700528 * <p>
529 * Handled by {@link Connection.VideoProvider#onSetDeviceOrientation(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700530 *
531 * @param rotation The device orientation, in degrees.
532 */
533 public abstract void setDeviceOrientation(int rotation);
534
535 /**
536 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700537 * <p>
538 * Handled by {@link Connection.VideoProvider#onSetZoom(float)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700539 *
540 * @param value The camera zoom ratio.
541 */
542 public abstract void setZoom(float value);
543
544 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700545 * Issues a request to modify the properties of the current video session.
546 * <p>
547 * Example scenarios include: requesting an audio-only call to be upgraded to a
548 * bi-directional video call, turning on or off the user's camera, sending a pause signal
549 * when the {@link InCallService} is no longer the foreground application.
550 * <p>
551 * Handled by
552 * {@link Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700553 *
554 * @param requestProfile The requested call video properties.
555 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700556 public abstract void sendSessionModifyRequest(VideoProfile requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700557
558 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700559 * Provides a response to a request to change the current call video session
560 * properties. This should be called in response to a request the {@link InCallService} has
561 * received via {@link VideoCall.Callback#onSessionModifyRequestReceived}.
562 * <p>
563 * Handled by
564 * {@link Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700565 *
566 * @param responseProfile The response call video properties.
567 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700568 public abstract void sendSessionModifyResponse(VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700569
570 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700571 * Issues a request to the {@link Connection.VideoProvider} to retrieve the capabilities
572 * of the current camera. The current camera is selected using
573 * {@link VideoCall#setCamera(String)}.
574 * <p>
575 * Camera capabilities are reported to the caller via
576 * {@link VideoCall.Callback#onCameraCapabilitiesChanged(VideoProfile.CameraCapabilities)}.
577 * <p>
578 * Handled by {@link Connection.VideoProvider#onRequestCameraCapabilities()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700579 */
580 public abstract void requestCameraCapabilities();
581
582 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700583 * Issues a request to the {@link Connection.VideoProvider} to retrieve the cumulative data
584 * usage for the video component of the current call (in bytes). Data usage is reported
585 * to the caller via {@link VideoCall.Callback#onCallDataUsageChanged}.
586 * <p>
587 * Handled by {@link Connection.VideoProvider#onRequestConnectionDataUsage()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700588 */
589 public abstract void requestCallDataUsage();
590
591 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700592 * Provides the {@link Connection.VideoProvider} with the {@link Uri} of an image to be
593 * displayed to the peer device when the video signal is paused.
594 * <p>
595 * Handled by {@link Connection.VideoProvider#onSetPauseImage(Uri)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700596 *
597 * @param uri URI of image to display.
598 */
Yorke Lee32f24732015-05-12 16:18:03 -0700599 public abstract void setPauseImage(Uri uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700600
601 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700602 * The {@link InCallService} extends this class to provide a means of receiving callbacks
Tyler Gunn295f5d72015-06-04 11:08:54 -0700603 * from the {@link Connection.VideoProvider}.
604 * <p>
Tyler Gunnb702ef82015-05-29 11:51:53 -0700605 * When the {@link InCallService} receives the
606 * {@link Call.Callback#onVideoCallChanged(Call, VideoCall)} callback, it should create an
607 * instance its {@link VideoCall.Callback} implementation and set it on the
608 * {@link VideoCall} using {@link VideoCall#registerCallback(Callback)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700609 */
Andrew Leeda80c872015-04-15 14:09:50 -0700610 public static abstract class Callback {
Andrew Lee50aca232014-07-22 16:41:54 -0700611 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700612 * Called when the {@link Connection.VideoProvider} receives a session modification
Tyler Gunn295f5d72015-06-04 11:08:54 -0700613 * request from the peer device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700614 * <p>
615 * The {@link InCallService} may potentially prompt the user to confirm whether they
616 * wish to accept the request, or decide to automatically accept the request. In either
617 * case the {@link InCallService} should call
618 * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} to indicate the video
619 * profile agreed upon.
620 * <p>
621 * Callback originates from
622 * {@link Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700623 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700624 * @param videoProfile The requested video profile.
Andrew Lee50aca232014-07-22 16:41:54 -0700625 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700626 public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700627
628 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700629 * Called when the {@link Connection.VideoProvider} receives a response to a session
630 * modification request previously sent to the peer device.
631 * <p>
632 * The new video state should not be considered active by the {@link InCallService}
633 * until the {@link Call} video state changes (the
634 * {@link Call.Callback#onDetailsChanged(Call, Call.Details)} callback is triggered
635 * when the video state changes).
636 * <p>
637 * Callback originates from
638 * {@link Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
639 * VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700640 *
641 * @param status Status of the session modify request. Valid values are
Tyler Gunnb702ef82015-05-29 11:51:53 -0700642 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
643 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
644 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
645 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
646 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}.
647 * @param requestedProfile The original request which was sent to the peer device.
648 * @param responseProfile The actual profile changes made by the peer device.
Andrew Lee50aca232014-07-22 16:41:54 -0700649 */
650 public abstract void onSessionModifyResponseReceived(int status,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700651 VideoProfile requestedProfile, VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700652
653 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700654 * Handles events related to the current video session which the {@link InCallService}
655 * may wish to handle. These are separate from requested changes to the session due to
656 * the underlying protocol or connection.
657 * <p>
658 * Callback originates from
659 * {@link Connection.VideoProvider#handleCallSessionEvent(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700660 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700661 * @param event The event. Valid values are:
662 * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE},
663 * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME},
664 * {@link Connection.VideoProvider#SESSION_EVENT_TX_START},
665 * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP},
666 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
667 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY}.
Andrew Lee50aca232014-07-22 16:41:54 -0700668 */
669 public abstract void onCallSessionEvent(int event);
670
671 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700672 * Handles a change to the video dimensions from the peer device. This could happen if,
673 * for example, the peer changes orientation of their device, or switches cameras.
674 * <p>
675 * Callback originates from
676 * {@link Connection.VideoProvider#changePeerDimensions(int, int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700677 *
678 * @param width The updated peer video width.
679 * @param height The updated peer video height.
680 */
681 public abstract void onPeerDimensionsChanged(int width, int height);
682
683 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700684 * Handles a change to the video quality.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700685 * <p>
686 * Callback originates from {@link Connection.VideoProvider#changeVideoQuality(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700687 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700688 * @param videoQuality The updated peer video quality. Valid values:
689 * {@link VideoProfile#QUALITY_HIGH},
690 * {@link VideoProfile#QUALITY_MEDIUM},
691 * {@link VideoProfile#QUALITY_LOW},
692 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700693 */
694 public abstract void onVideoQualityChanged(int videoQuality);
695
696 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700697 * Handles an update to the total data used for the current video session.
698 * <p>
699 * Used by the {@link Connection.VideoProvider} in response to
700 * {@link VideoCall#requestCallDataUsage()}. May also be called periodically by the
701 * {@link Connection.VideoProvider}.
702 * <p>
703 * Callback originates from {@link Connection.VideoProvider#setCallDataUsage(long)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700704 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700705 * @param dataUsage The updated data usage (in bytes).
Andrew Lee50aca232014-07-22 16:41:54 -0700706 */
Rekha Kumar07366812015-03-24 16:42:31 -0700707 public abstract void onCallDataUsageChanged(long dataUsage);
Andrew Lee50aca232014-07-22 16:41:54 -0700708
709 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700710 * Handles a change in the capabilities of the currently selected camera.
711 * <p>
712 * Used by the {@link Connection.VideoProvider} in response to
713 * {@link VideoCall#requestCameraCapabilities()}. The {@link Connection.VideoProvider}
714 * may also report the camera capabilities after a call to
715 * {@link VideoCall#setCamera(String)}.
716 * <p>
717 * Callback originates from
718 * {@link Connection.VideoProvider#changeCameraCapabilities(
719 * VideoProfile.CameraCapabilities)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700720 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700721 * @param cameraCapabilities The changed camera capabilities.
Andrew Lee50aca232014-07-22 16:41:54 -0700722 */
Yorke Lee400470f2015-05-12 13:31:25 -0700723 public abstract void onCameraCapabilitiesChanged(
724 VideoProfile.CameraCapabilities cameraCapabilities);
Andrew Lee50aca232014-07-22 16:41:54 -0700725 }
726 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800727}