blob: 0f8ac632a876b5eb215030434c38a586dda36b15 [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;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080025import android.os.Handler;
26import android.os.IBinder;
27import android.os.Looper;
28import android.os.Message;
Andrew Lee50aca232014-07-22 16:41:54 -070029import android.view.Surface;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080030
Ihab Awad2f236642014-03-10 15:33:45 -070031import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070032import com.android.internal.telecom.IInCallAdapter;
33import com.android.internal.telecom.IInCallService;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080034
Andrew Lee50aca232014-07-22 16:41:54 -070035import java.lang.String;
Santos Cordona2492812015-04-15 11:05:16 -070036import java.util.Collections;
37import java.util.List;
Andrew Lee50aca232014-07-22 16:41:54 -070038
Sailesh Nepalab5d2822014-03-08 18:01:06 -080039/**
40 * This service is implemented by any app that wishes to provide the user-interface for managing
Tyler Gunnef9f6f92014-09-12 22:16:17 -070041 * phone calls. Telecom binds to this service while there exists a live (active or incoming) call,
Santos Cordonf2600eb2015-06-22 15:02:20 -070042 * and uses it to notify the in-call app of any live and recently disconnected calls. An app must
43 * first be set as the default phone app (See {@link TelecomManager#getDefaultDialerPackage()})
44 * before the telecom service will bind to its {@code InCallService} implementation.
45 * <p>
46 * Below is an example manifest registration for an {@code InCallService}. The meta-data
47 * ({@link TelecomManager#METADATA_IN_CALL_SERVICE_UI}) indicates that this particular
48 * {@code InCallService} implementation intends to replace the built-in in-call UI.
49 * <pre>
50 * {@code
51 * &lt;service android:name="your.package.YourInCallServiceImplementation"
52 * android:permission="android.permission.BIND_IN_CALL_SERVICE"&gt;
53 * &lt;meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" /&gt;
54 * &lt;intent-filter&gt;
55 * &lt;action android:name="android.telecom.InCallService"/&gt;
56 * &lt;/intent-filter&gt;
57 * &lt;/service&gt;
58 * }
59 * </pre>
Sailesh Nepalab5d2822014-03-08 18:01:06 -080060 */
Santos Cordon2f42b112014-07-19 13:19:37 -070061public abstract class InCallService extends Service {
Tyler Gunn2ac40102014-08-18 16:23:10 -070062
63 /**
64 * The {@link Intent} that must be declared as handled by the service.
65 */
66 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070067 public static final String SERVICE_INTERFACE = "android.telecom.InCallService";
Tyler Gunn2ac40102014-08-18 16:23:10 -070068
Sailesh Nepalab5d2822014-03-08 18:01:06 -080069 private static final int MSG_SET_IN_CALL_ADAPTER = 1;
70 private static final int MSG_ADD_CALL = 2;
Sailesh Nepal60437932014-04-05 16:44:55 -070071 private static final int MSG_UPDATE_CALL = 3;
Ihab Awad5d0410f2014-07-30 10:07:40 -070072 private static final int MSG_SET_POST_DIAL_WAIT = 4;
Yorke Lee4af59352015-05-13 14:14:54 -070073 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 5;
Ihab Awad5d0410f2014-07-30 10:07:40 -070074 private static final int MSG_BRING_TO_FOREGROUND = 6;
Santos Cordon6c912b72014-11-07 16:05:09 -080075 private static final int MSG_ON_CAN_ADD_CALL_CHANGED = 7;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080076
77 /** Default Handler used to consolidate binder method calls onto a single thread. */
78 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
79 @Override
80 public void handleMessage(Message msg) {
Jay Shrauner5e6162d2014-09-22 20:47:45 -070081 if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) {
82 return;
83 }
84
Sailesh Nepalab5d2822014-03-08 18:01:06 -080085 switch (msg.what) {
86 case MSG_SET_IN_CALL_ADAPTER:
Ihab Awade63fadb2014-07-09 21:52:04 -070087 mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj));
Santos Cordona2492812015-04-15 11:05:16 -070088 mPhone.addListener(mPhoneListener);
Ihab Awade63fadb2014-07-09 21:52:04 -070089 onPhoneCreated(mPhone);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080090 break;
91 case MSG_ADD_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -070092 mPhone.internalAddCall((ParcelableCall) msg.obj);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080093 break;
Sailesh Nepal60437932014-04-05 16:44:55 -070094 case MSG_UPDATE_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -070095 mPhone.internalUpdateCall((ParcelableCall) msg.obj);
Ihab Awad2f236642014-03-10 15:33:45 -070096 break;
Ihab Awad2f236642014-03-10 15:33:45 -070097 case MSG_SET_POST_DIAL_WAIT: {
98 SomeArgs args = (SomeArgs) msg.obj;
99 try {
100 String callId = (String) args.arg1;
101 String remaining = (String) args.arg2;
Ihab Awade63fadb2014-07-09 21:52:04 -0700102 mPhone.internalSetPostDialWait(callId, remaining);
Ihab Awad2f236642014-03-10 15:33:45 -0700103 } finally {
104 args.recycle();
105 }
106 break;
107 }
Yorke Lee4af59352015-05-13 14:14:54 -0700108 case MSG_ON_CALL_AUDIO_STATE_CHANGED:
109 mPhone.internalCallAudioStateChanged((CallAudioState) msg.obj);
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700110 break;
Santos Cordon3534ede2014-05-29 13:07:10 -0700111 case MSG_BRING_TO_FOREGROUND:
Ihab Awade63fadb2014-07-09 21:52:04 -0700112 mPhone.internalBringToForeground(msg.arg1 == 1);
Santos Cordon3534ede2014-05-29 13:07:10 -0700113 break;
Santos Cordon6c912b72014-11-07 16:05:09 -0800114 case MSG_ON_CAN_ADD_CALL_CHANGED:
115 mPhone.internalSetCanAddCall(msg.arg1 == 1);
116 break;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800117 default:
118 break;
119 }
120 }
121 };
122
123 /** Manages the binder calls so that the implementor does not need to deal with it. */
124 private final class InCallServiceBinder extends IInCallService.Stub {
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800125 @Override
126 public void setInCallAdapter(IInCallAdapter inCallAdapter) {
127 mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget();
128 }
129
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800130 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700131 public void addCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700132 mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800133 }
134
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800135 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700136 public void updateCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700137 mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
Ihab Awad2f236642014-03-10 15:33:45 -0700138 }
139
140 @Override
141 public void setPostDial(String callId, String remaining) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700142 // TODO: Unused
Ihab Awad2f236642014-03-10 15:33:45 -0700143 }
144
145 @Override
146 public void setPostDialWait(String callId, String remaining) {
147 SomeArgs args = SomeArgs.obtain();
148 args.arg1 = callId;
149 args.arg2 = remaining;
150 mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
151 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700152
153 @Override
Yorke Lee4af59352015-05-13 14:14:54 -0700154 public void onCallAudioStateChanged(CallAudioState callAudioState) {
155 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, callAudioState).sendToTarget();
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700156 }
Santos Cordon3534ede2014-05-29 13:07:10 -0700157
Santos Cordon3534ede2014-05-29 13:07:10 -0700158 @Override
159 public void bringToForeground(boolean showDialpad) {
160 mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
161 }
Santos Cordon6c912b72014-11-07 16:05:09 -0800162
163 @Override
164 public void onCanAddCallChanged(boolean canAddCall) {
165 mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0)
166 .sendToTarget();
167 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800168 }
169
Santos Cordona2492812015-04-15 11:05:16 -0700170 private Phone.Listener mPhoneListener = new Phone.Listener() {
171 /** ${inheritDoc} */
172 @Override
173 public void onAudioStateChanged(Phone phone, AudioState audioState) {
174 InCallService.this.onAudioStateChanged(audioState);
175 }
176
Yorke Lee4af59352015-05-13 14:14:54 -0700177 public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) {
178 InCallService.this.onCallAudioStateChanged(callAudioState);
179 };
180
Santos Cordona2492812015-04-15 11:05:16 -0700181 /** ${inheritDoc} */
182 @Override
183 public void onBringToForeground(Phone phone, boolean showDialpad) {
184 InCallService.this.onBringToForeground(showDialpad);
185 }
186
187 /** ${inheritDoc} */
188 @Override
189 public void onCallAdded(Phone phone, Call call) {
190 InCallService.this.onCallAdded(call);
191 }
192
193 /** ${inheritDoc} */
194 @Override
195 public void onCallRemoved(Phone phone, Call call) {
196 InCallService.this.onCallRemoved(call);
197 }
198
199 /** ${inheritDoc} */
200 @Override
201 public void onCanAddCallChanged(Phone phone, boolean canAddCall) {
202 InCallService.this.onCanAddCallChanged(canAddCall);
203 }
204
205 };
206
Ihab Awade63fadb2014-07-09 21:52:04 -0700207 private Phone mPhone;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800208
Santos Cordon2f42b112014-07-19 13:19:37 -0700209 public InCallService() {
210 }
Evan Charlton924748f2014-04-03 08:36:38 -0700211
Santos Cordon2f42b112014-07-19 13:19:37 -0700212 @Override
213 public IBinder onBind(Intent intent) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700214 return new InCallServiceBinder();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800215 }
216
Santos Cordonf30d7e92014-08-26 09:54:33 -0700217 @Override
218 public boolean onUnbind(Intent intent) {
Santos Cordon619b3c02014-09-02 17:13:45 -0700219 if (mPhone != null) {
220 Phone oldPhone = mPhone;
221 mPhone = null;
Santos Cordonf30d7e92014-08-26 09:54:33 -0700222
Santos Cordon619b3c02014-09-02 17:13:45 -0700223 oldPhone.destroy();
Santos Cordona2492812015-04-15 11:05:16 -0700224 // destroy sets all the calls to disconnected if any live ones still exist. Therefore,
225 // it is important to remove the Listener *after* the call to destroy so that
226 // InCallService.on* callbacks are appropriately called.
227 oldPhone.removeListener(mPhoneListener);
228
Santos Cordon619b3c02014-09-02 17:13:45 -0700229 onPhoneDestroyed(oldPhone);
230 }
Santos Cordona2492812015-04-15 11:05:16 -0700231
Santos Cordonf30d7e92014-08-26 09:54:33 -0700232 return false;
233 }
234
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800235 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700236 * Obtain the {@code Phone} associated with this {@code InCallService}.
237 *
238 * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null}
Santos Cordon2f42b112014-07-19 13:19:37 -0700239 * if the {@code InCallService} is not in a state where it has an associated
240 * {@code Phone}.
Santos Cordona2492812015-04-15 11:05:16 -0700241 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700242 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800243 */
Santos Cordona2492812015-04-15 11:05:16 -0700244 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700245 @Deprecated
246 public Phone getPhone() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700247 return mPhone;
Evan Charlton924748f2014-04-03 08:36:38 -0700248 }
249
250 /**
Santos Cordona2492812015-04-15 11:05:16 -0700251 * Obtains the current list of {@code Call}s to be displayed by this in-call experience.
252 *
253 * @return A list of the relevant {@code Call}s.
254 */
255 public final List<Call> getCalls() {
256 return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls();
257 }
258
259 /**
260 * Returns if the device can support additional calls.
261 *
262 * @return Whether the phone supports adding more calls.
263 */
264 public final boolean canAddCall() {
265 return mPhone == null ? false : mPhone.canAddCall();
266 }
267
268 /**
269 * Obtains the current phone call audio state.
270 *
271 * @return An object encapsulating the audio state. Returns null if the service is not
272 * fully initialized.
Yorke Lee4af59352015-05-13 14:14:54 -0700273 * @deprecated Use {@link #getCallAudioState()} instead.
274 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700275 */
Yorke Lee4af59352015-05-13 14:14:54 -0700276 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700277 public final AudioState getAudioState() {
278 return mPhone == null ? null : mPhone.getAudioState();
279 }
280
281 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700282 * Obtains the current phone call audio state.
283 *
284 * @return An object encapsulating the audio state. Returns null if the service is not
285 * fully initialized.
286 */
287 public final CallAudioState getCallAudioState() {
288 return mPhone == null ? null : mPhone.getCallAudioState();
289 }
290
291 /**
Santos Cordona2492812015-04-15 11:05:16 -0700292 * Sets the microphone mute state. When this request is honored, there will be change to
Yorke Lee4af59352015-05-13 14:14:54 -0700293 * the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700294 *
295 * @param state {@code true} if the microphone should be muted; {@code false} otherwise.
296 */
297 public final void setMuted(boolean state) {
298 if (mPhone != null) {
299 mPhone.setMuted(state);
300 }
301 }
302
303 /**
304 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
Yorke Lee4af59352015-05-13 14:14:54 -0700305 * be change to the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700306 *
307 * @param route The audio route to use.
308 */
309 public final void setAudioRoute(int route) {
310 if (mPhone != null) {
311 mPhone.setAudioRoute(route);
312 }
313 }
314
315 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700316 * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience
317 * to start displaying in-call information to the user. Each instance of {@code InCallService}
Santos Cordon2f42b112014-07-19 13:19:37 -0700318 * will have only one {@code Phone}, and this method will be called exactly once in the lifetime
319 * of the {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700320 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700321 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700322 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700323 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Evan Charlton924748f2014-04-03 08:36:38 -0700324 */
Santos Cordona2492812015-04-15 11:05:16 -0700325 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700326 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700327 public void onPhoneCreated(Phone phone) {
328 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800329
330 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700331 * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience
332 * to stop displaying in-call information to the user. This method will be called exactly once
333 * in the lifetime of the {@code InCallService}, and it will always be called after a previous
334 * call to {@link #onPhoneCreated(Phone)}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800335 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700336 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700337 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700338 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800339 */
Santos Cordona2492812015-04-15 11:05:16 -0700340 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700341 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700342 public void onPhoneDestroyed(Phone phone) {
343 }
Andrew Lee50aca232014-07-22 16:41:54 -0700344
345 /**
Santos Cordona2492812015-04-15 11:05:16 -0700346 * Called when the audio state changes.
347 *
348 * @param audioState The new {@link AudioState}.
Yorke Lee4af59352015-05-13 14:14:54 -0700349 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState) instead}.
350 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700351 */
Yorke Lee4af59352015-05-13 14:14:54 -0700352 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700353 public void onAudioStateChanged(AudioState audioState) {
354 }
355
356 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700357 * Called when the audio state changes.
358 *
359 * @param audioState The new {@link CallAudioState}.
360 */
361 public void onCallAudioStateChanged(CallAudioState audioState) {
362 }
363
364 /**
Santos Cordona2492812015-04-15 11:05:16 -0700365 * Called to bring the in-call screen to the foreground. The in-call experience should
366 * respond immediately by coming to the foreground to inform the user of the state of
367 * ongoing {@code Call}s.
368 *
369 * @param showDialpad If true, put up the dialpad when the screen is shown.
370 */
371 public void onBringToForeground(boolean showDialpad) {
372 }
373
374 /**
375 * Called when a {@code Call} has been added to this in-call session. The in-call user
376 * experience should add necessary state listeners to the specified {@code Call} and
377 * immediately start to show the user information about the existence
378 * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will
379 * include this {@code Call}.
380 *
381 * @param call A newly added {@code Call}.
382 */
383 public void onCallAdded(Call call) {
384 }
385
386 /**
387 * Called when a {@code Call} has been removed from this in-call session. The in-call user
388 * experience should remove any state listeners from the specified {@code Call} and
389 * immediately stop displaying any information about this {@code Call}.
390 * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}.
391 *
392 * @param call A newly removed {@code Call}.
393 */
394 public void onCallRemoved(Call call) {
395 }
396
397 /**
398 * Called when the ability to add more calls changes. If the phone cannot
399 * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it
400 * is set to {@code true}. This can be used to control the visibility of UI to add more calls.
401 *
402 * @param canAddCall Indicates whether an additional call can be added.
403 */
404 public void onCanAddCallChanged(boolean canAddCall) {
405 }
406
407 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700408 * Used to issue commands to the {@link Connection.VideoProvider} associated with a
409 * {@link Call}.
Andrew Lee50aca232014-07-22 16:41:54 -0700410 */
411 public static abstract class VideoCall {
412
Andrew Lee011728f2015-04-23 15:47:06 -0700413 /** @hide */
414 public abstract void destroy();
415
Andrew Lee50aca232014-07-22 16:41:54 -0700416 /**
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700417 * Registers a callback to receive commands and state changes for video calls.
Andrew Lee50aca232014-07-22 16:41:54 -0700418 *
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700419 * @param callback The video call callback.
Andrew Lee50aca232014-07-22 16:41:54 -0700420 */
Andrew Leeda80c872015-04-15 14:09:50 -0700421 public abstract void registerCallback(VideoCall.Callback callback);
422
423 /**
Andrew Lee011728f2015-04-23 15:47:06 -0700424 * Registers a callback to receive commands and state changes for video calls.
425 *
426 * @param callback The video call callback.
427 * @param handler A handler which commands and status changes will be delivered to.
428 */
429 public abstract void registerCallback(VideoCall.Callback callback, Handler handler);
430
431 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700432 * Clears the video call callback set via {@link #registerCallback}.
Tyler Gunn295f5d72015-06-04 11:08:54 -0700433 *
434 * @param callback The video call callback to clear.
Tyler Gunn75958422015-04-15 14:23:42 -0700435 */
Andrew Lee011728f2015-04-23 15:47:06 -0700436 public abstract void unregisterCallback(VideoCall.Callback callback);
Tyler Gunn75958422015-04-15 14:23:42 -0700437
438 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700439 * Sets the camera to be used for the outgoing video.
440 * <p>
441 * Handled by {@link Connection.VideoProvider#onSetCamera(String)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700442 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700443 * @param cameraId The id of the camera (use ids as reported by
444 * {@link CameraManager#getCameraIdList()}).
Andrew Lee50aca232014-07-22 16:41:54 -0700445 */
446 public abstract void setCamera(String cameraId);
447
448 /**
449 * Sets the surface to be used for displaying a preview of what the user's camera is
450 * currently capturing. When video transmission is enabled, this is the video signal which
451 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700452 * <p>
453 * Handled by {@link Connection.VideoProvider#onSetPreviewSurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700454 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700455 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700456 */
457 public abstract void setPreviewSurface(Surface surface);
458
459 /**
460 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700461 * <p>
462 * Handled by {@link Connection.VideoProvider#onSetDisplaySurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700463 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700464 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700465 */
466 public abstract void setDisplaySurface(Surface surface);
467
468 /**
469 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
470 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700471 * <p>
472 * Handled by {@link Connection.VideoProvider#onSetDeviceOrientation(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700473 *
474 * @param rotation The device orientation, in degrees.
475 */
476 public abstract void setDeviceOrientation(int rotation);
477
478 /**
479 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700480 * <p>
481 * Handled by {@link Connection.VideoProvider#onSetZoom(float)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700482 *
483 * @param value The camera zoom ratio.
484 */
485 public abstract void setZoom(float value);
486
487 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700488 * Issues a request to modify the properties of the current video session.
489 * <p>
490 * Example scenarios include: requesting an audio-only call to be upgraded to a
491 * bi-directional video call, turning on or off the user's camera, sending a pause signal
492 * when the {@link InCallService} is no longer the foreground application.
493 * <p>
494 * Handled by
495 * {@link Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700496 *
497 * @param requestProfile The requested call video properties.
498 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700499 public abstract void sendSessionModifyRequest(VideoProfile requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700500
501 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700502 * Provides a response to a request to change the current call video session
503 * properties. This should be called in response to a request the {@link InCallService} has
504 * received via {@link VideoCall.Callback#onSessionModifyRequestReceived}.
505 * <p>
506 * Handled by
507 * {@link Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700508 *
509 * @param responseProfile The response call video properties.
510 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700511 public abstract void sendSessionModifyResponse(VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700512
513 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700514 * Issues a request to the {@link Connection.VideoProvider} to retrieve the capabilities
515 * of the current camera. The current camera is selected using
516 * {@link VideoCall#setCamera(String)}.
517 * <p>
518 * Camera capabilities are reported to the caller via
519 * {@link VideoCall.Callback#onCameraCapabilitiesChanged(VideoProfile.CameraCapabilities)}.
520 * <p>
521 * Handled by {@link Connection.VideoProvider#onRequestCameraCapabilities()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700522 */
523 public abstract void requestCameraCapabilities();
524
525 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700526 * Issues a request to the {@link Connection.VideoProvider} to retrieve the cumulative data
527 * usage for the video component of the current call (in bytes). Data usage is reported
528 * to the caller via {@link VideoCall.Callback#onCallDataUsageChanged}.
529 * <p>
530 * Handled by {@link Connection.VideoProvider#onRequestConnectionDataUsage()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700531 */
532 public abstract void requestCallDataUsage();
533
534 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700535 * Provides the {@link Connection.VideoProvider} with the {@link Uri} of an image to be
536 * displayed to the peer device when the video signal is paused.
537 * <p>
538 * Handled by {@link Connection.VideoProvider#onSetPauseImage(Uri)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700539 *
540 * @param uri URI of image to display.
541 */
Yorke Lee32f24732015-05-12 16:18:03 -0700542 public abstract void setPauseImage(Uri uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700543
544 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700545 * The {@link InCallService} extends this class to provide a means of receiving callbacks
Tyler Gunn295f5d72015-06-04 11:08:54 -0700546 * from the {@link Connection.VideoProvider}.
547 * <p>
Tyler Gunnb702ef82015-05-29 11:51:53 -0700548 * When the {@link InCallService} receives the
549 * {@link Call.Callback#onVideoCallChanged(Call, VideoCall)} callback, it should create an
550 * instance its {@link VideoCall.Callback} implementation and set it on the
551 * {@link VideoCall} using {@link VideoCall#registerCallback(Callback)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700552 */
Andrew Leeda80c872015-04-15 14:09:50 -0700553 public static abstract class Callback {
Andrew Lee50aca232014-07-22 16:41:54 -0700554 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700555 * Called when the {@link Connection.VideoProvider} receives a session modification
Tyler Gunn295f5d72015-06-04 11:08:54 -0700556 * request from the peer device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700557 * <p>
558 * The {@link InCallService} may potentially prompt the user to confirm whether they
559 * wish to accept the request, or decide to automatically accept the request. In either
560 * case the {@link InCallService} should call
561 * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} to indicate the video
562 * profile agreed upon.
563 * <p>
564 * Callback originates from
565 * {@link Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700566 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700567 * @param videoProfile The requested video profile.
Andrew Lee50aca232014-07-22 16:41:54 -0700568 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700569 public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700570
571 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700572 * Called when the {@link Connection.VideoProvider} receives a response to a session
573 * modification request previously sent to the peer device.
574 * <p>
575 * The new video state should not be considered active by the {@link InCallService}
576 * until the {@link Call} video state changes (the
577 * {@link Call.Callback#onDetailsChanged(Call, Call.Details)} callback is triggered
578 * when the video state changes).
579 * <p>
580 * Callback originates from
581 * {@link Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
582 * VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700583 *
584 * @param status Status of the session modify request. Valid values are
Tyler Gunnb702ef82015-05-29 11:51:53 -0700585 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
586 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
587 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
588 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
589 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}.
590 * @param requestedProfile The original request which was sent to the peer device.
591 * @param responseProfile The actual profile changes made by the peer device.
Andrew Lee50aca232014-07-22 16:41:54 -0700592 */
593 public abstract void onSessionModifyResponseReceived(int status,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700594 VideoProfile requestedProfile, VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700595
596 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700597 * Handles events related to the current video session which the {@link InCallService}
598 * may wish to handle. These are separate from requested changes to the session due to
599 * the underlying protocol or connection.
600 * <p>
601 * Callback originates from
602 * {@link Connection.VideoProvider#handleCallSessionEvent(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700603 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700604 * @param event The event. Valid values are:
605 * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE},
606 * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME},
607 * {@link Connection.VideoProvider#SESSION_EVENT_TX_START},
608 * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP},
609 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
610 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY}.
Andrew Lee50aca232014-07-22 16:41:54 -0700611 */
612 public abstract void onCallSessionEvent(int event);
613
614 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700615 * Handles a change to the video dimensions from the peer device. This could happen if,
616 * for example, the peer changes orientation of their device, or switches cameras.
617 * <p>
618 * Callback originates from
619 * {@link Connection.VideoProvider#changePeerDimensions(int, int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700620 *
621 * @param width The updated peer video width.
622 * @param height The updated peer video height.
623 */
624 public abstract void onPeerDimensionsChanged(int width, int height);
625
626 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700627 * Handles a change to the video quality.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700628 * <p>
629 * Callback originates from {@link Connection.VideoProvider#changeVideoQuality(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700630 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700631 * @param videoQuality The updated peer video quality. Valid values:
632 * {@link VideoProfile#QUALITY_HIGH},
633 * {@link VideoProfile#QUALITY_MEDIUM},
634 * {@link VideoProfile#QUALITY_LOW},
635 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700636 */
637 public abstract void onVideoQualityChanged(int videoQuality);
638
639 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700640 * Handles an update to the total data used for the current video session.
641 * <p>
642 * Used by the {@link Connection.VideoProvider} in response to
643 * {@link VideoCall#requestCallDataUsage()}. May also be called periodically by the
644 * {@link Connection.VideoProvider}.
645 * <p>
646 * Callback originates from {@link Connection.VideoProvider#setCallDataUsage(long)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700647 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700648 * @param dataUsage The updated data usage (in bytes).
Andrew Lee50aca232014-07-22 16:41:54 -0700649 */
Rekha Kumar07366812015-03-24 16:42:31 -0700650 public abstract void onCallDataUsageChanged(long dataUsage);
Andrew Lee50aca232014-07-22 16:41:54 -0700651
652 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700653 * Handles a change in the capabilities of the currently selected camera.
654 * <p>
655 * Used by the {@link Connection.VideoProvider} in response to
656 * {@link VideoCall#requestCameraCapabilities()}. The {@link Connection.VideoProvider}
657 * may also report the camera capabilities after a call to
658 * {@link VideoCall#setCamera(String)}.
659 * <p>
660 * Callback originates from
661 * {@link Connection.VideoProvider#changeCameraCapabilities(
662 * VideoProfile.CameraCapabilities)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700663 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700664 * @param cameraCapabilities The changed camera capabilities.
Andrew Lee50aca232014-07-22 16:41:54 -0700665 */
Yorke Lee400470f2015-05-12 13:31:25 -0700666 public abstract void onCameraCapabilitiesChanged(
667 VideoProfile.CameraCapabilities cameraCapabilities);
Andrew Lee50aca232014-07-22 16:41:54 -0700668 }
669 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800670}