blob: fb985ceead7ce4f5723ea2243eb1bf857b2d7b63 [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 Cordon2f42b112014-07-19 13:19:37 -070042 * and uses it to notify the in-call app of any live and and recently disconnected calls.
Sailesh Nepalab5d2822014-03-08 18:01:06 -080043 */
Santos Cordon2f42b112014-07-19 13:19:37 -070044public abstract class InCallService extends Service {
Tyler Gunn2ac40102014-08-18 16:23:10 -070045
46 /**
47 * The {@link Intent} that must be declared as handled by the service.
48 */
49 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070050 public static final String SERVICE_INTERFACE = "android.telecom.InCallService";
Tyler Gunn2ac40102014-08-18 16:23:10 -070051
Sailesh Nepalab5d2822014-03-08 18:01:06 -080052 private static final int MSG_SET_IN_CALL_ADAPTER = 1;
53 private static final int MSG_ADD_CALL = 2;
Sailesh Nepal60437932014-04-05 16:44:55 -070054 private static final int MSG_UPDATE_CALL = 3;
Ihab Awad5d0410f2014-07-30 10:07:40 -070055 private static final int MSG_SET_POST_DIAL_WAIT = 4;
Yorke Lee4af59352015-05-13 14:14:54 -070056 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 5;
Ihab Awad5d0410f2014-07-30 10:07:40 -070057 private static final int MSG_BRING_TO_FOREGROUND = 6;
Santos Cordon6c912b72014-11-07 16:05:09 -080058 private static final int MSG_ON_CAN_ADD_CALL_CHANGED = 7;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080059
60 /** Default Handler used to consolidate binder method calls onto a single thread. */
61 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
62 @Override
63 public void handleMessage(Message msg) {
Jay Shrauner5e6162d2014-09-22 20:47:45 -070064 if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) {
65 return;
66 }
67
Sailesh Nepalab5d2822014-03-08 18:01:06 -080068 switch (msg.what) {
69 case MSG_SET_IN_CALL_ADAPTER:
Ihab Awade63fadb2014-07-09 21:52:04 -070070 mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj));
Santos Cordona2492812015-04-15 11:05:16 -070071 mPhone.addListener(mPhoneListener);
Ihab Awade63fadb2014-07-09 21:52:04 -070072 onPhoneCreated(mPhone);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080073 break;
74 case MSG_ADD_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -070075 mPhone.internalAddCall((ParcelableCall) msg.obj);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080076 break;
Sailesh Nepal60437932014-04-05 16:44:55 -070077 case MSG_UPDATE_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -070078 mPhone.internalUpdateCall((ParcelableCall) msg.obj);
Ihab Awad2f236642014-03-10 15:33:45 -070079 break;
Ihab Awad2f236642014-03-10 15:33:45 -070080 case MSG_SET_POST_DIAL_WAIT: {
81 SomeArgs args = (SomeArgs) msg.obj;
82 try {
83 String callId = (String) args.arg1;
84 String remaining = (String) args.arg2;
Ihab Awade63fadb2014-07-09 21:52:04 -070085 mPhone.internalSetPostDialWait(callId, remaining);
Ihab Awad2f236642014-03-10 15:33:45 -070086 } finally {
87 args.recycle();
88 }
89 break;
90 }
Yorke Lee4af59352015-05-13 14:14:54 -070091 case MSG_ON_CALL_AUDIO_STATE_CHANGED:
92 mPhone.internalCallAudioStateChanged((CallAudioState) msg.obj);
Sailesh Nepalb632e5b2014-04-03 12:54:33 -070093 break;
Santos Cordon3534ede2014-05-29 13:07:10 -070094 case MSG_BRING_TO_FOREGROUND:
Ihab Awade63fadb2014-07-09 21:52:04 -070095 mPhone.internalBringToForeground(msg.arg1 == 1);
Santos Cordon3534ede2014-05-29 13:07:10 -070096 break;
Santos Cordon6c912b72014-11-07 16:05:09 -080097 case MSG_ON_CAN_ADD_CALL_CHANGED:
98 mPhone.internalSetCanAddCall(msg.arg1 == 1);
99 break;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800100 default:
101 break;
102 }
103 }
104 };
105
106 /** Manages the binder calls so that the implementor does not need to deal with it. */
107 private final class InCallServiceBinder extends IInCallService.Stub {
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800108 @Override
109 public void setInCallAdapter(IInCallAdapter inCallAdapter) {
110 mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget();
111 }
112
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800113 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700114 public void addCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700115 mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800116 }
117
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800118 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700119 public void updateCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700120 mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
Ihab Awad2f236642014-03-10 15:33:45 -0700121 }
122
123 @Override
124 public void setPostDial(String callId, String remaining) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700125 // TODO: Unused
Ihab Awad2f236642014-03-10 15:33:45 -0700126 }
127
128 @Override
129 public void setPostDialWait(String callId, String remaining) {
130 SomeArgs args = SomeArgs.obtain();
131 args.arg1 = callId;
132 args.arg2 = remaining;
133 mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
134 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700135
136 @Override
Yorke Lee4af59352015-05-13 14:14:54 -0700137 public void onCallAudioStateChanged(CallAudioState callAudioState) {
138 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, callAudioState).sendToTarget();
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700139 }
Santos Cordon3534ede2014-05-29 13:07:10 -0700140
Santos Cordon3534ede2014-05-29 13:07:10 -0700141 @Override
142 public void bringToForeground(boolean showDialpad) {
143 mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
144 }
Santos Cordon6c912b72014-11-07 16:05:09 -0800145
146 @Override
147 public void onCanAddCallChanged(boolean canAddCall) {
148 mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0)
149 .sendToTarget();
150 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800151 }
152
Santos Cordona2492812015-04-15 11:05:16 -0700153 private Phone.Listener mPhoneListener = new Phone.Listener() {
154 /** ${inheritDoc} */
155 @Override
156 public void onAudioStateChanged(Phone phone, AudioState audioState) {
157 InCallService.this.onAudioStateChanged(audioState);
158 }
159
Yorke Lee4af59352015-05-13 14:14:54 -0700160 public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) {
161 InCallService.this.onCallAudioStateChanged(callAudioState);
162 };
163
Santos Cordona2492812015-04-15 11:05:16 -0700164 /** ${inheritDoc} */
165 @Override
166 public void onBringToForeground(Phone phone, boolean showDialpad) {
167 InCallService.this.onBringToForeground(showDialpad);
168 }
169
170 /** ${inheritDoc} */
171 @Override
172 public void onCallAdded(Phone phone, Call call) {
173 InCallService.this.onCallAdded(call);
174 }
175
176 /** ${inheritDoc} */
177 @Override
178 public void onCallRemoved(Phone phone, Call call) {
179 InCallService.this.onCallRemoved(call);
180 }
181
182 /** ${inheritDoc} */
183 @Override
184 public void onCanAddCallChanged(Phone phone, boolean canAddCall) {
185 InCallService.this.onCanAddCallChanged(canAddCall);
186 }
187
188 };
189
Ihab Awade63fadb2014-07-09 21:52:04 -0700190 private Phone mPhone;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800191
Santos Cordon2f42b112014-07-19 13:19:37 -0700192 public InCallService() {
193 }
Evan Charlton924748f2014-04-03 08:36:38 -0700194
Santos Cordon2f42b112014-07-19 13:19:37 -0700195 @Override
196 public IBinder onBind(Intent intent) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700197 return new InCallServiceBinder();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800198 }
199
Santos Cordonf30d7e92014-08-26 09:54:33 -0700200 @Override
201 public boolean onUnbind(Intent intent) {
Santos Cordon619b3c02014-09-02 17:13:45 -0700202 if (mPhone != null) {
203 Phone oldPhone = mPhone;
204 mPhone = null;
Santos Cordonf30d7e92014-08-26 09:54:33 -0700205
Santos Cordon619b3c02014-09-02 17:13:45 -0700206 oldPhone.destroy();
Santos Cordona2492812015-04-15 11:05:16 -0700207 // destroy sets all the calls to disconnected if any live ones still exist. Therefore,
208 // it is important to remove the Listener *after* the call to destroy so that
209 // InCallService.on* callbacks are appropriately called.
210 oldPhone.removeListener(mPhoneListener);
211
Santos Cordon619b3c02014-09-02 17:13:45 -0700212 onPhoneDestroyed(oldPhone);
213 }
Santos Cordona2492812015-04-15 11:05:16 -0700214
Santos Cordonf30d7e92014-08-26 09:54:33 -0700215 return false;
216 }
217
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800218 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700219 * Obtain the {@code Phone} associated with this {@code InCallService}.
220 *
221 * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null}
Santos Cordon2f42b112014-07-19 13:19:37 -0700222 * if the {@code InCallService} is not in a state where it has an associated
223 * {@code Phone}.
Santos Cordona2492812015-04-15 11:05:16 -0700224 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700225 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800226 */
Santos Cordona2492812015-04-15 11:05:16 -0700227 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700228 @Deprecated
229 public Phone getPhone() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700230 return mPhone;
Evan Charlton924748f2014-04-03 08:36:38 -0700231 }
232
233 /**
Santos Cordona2492812015-04-15 11:05:16 -0700234 * Obtains the current list of {@code Call}s to be displayed by this in-call experience.
235 *
236 * @return A list of the relevant {@code Call}s.
237 */
238 public final List<Call> getCalls() {
239 return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls();
240 }
241
242 /**
243 * Returns if the device can support additional calls.
244 *
245 * @return Whether the phone supports adding more calls.
246 */
247 public final boolean canAddCall() {
248 return mPhone == null ? false : mPhone.canAddCall();
249 }
250
251 /**
252 * Obtains the current phone call audio state.
253 *
254 * @return An object encapsulating the audio state. Returns null if the service is not
255 * fully initialized.
Yorke Lee4af59352015-05-13 14:14:54 -0700256 * @deprecated Use {@link #getCallAudioState()} instead.
257 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700258 */
Yorke Lee4af59352015-05-13 14:14:54 -0700259 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700260 public final AudioState getAudioState() {
261 return mPhone == null ? null : mPhone.getAudioState();
262 }
263
264 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700265 * Obtains the current phone call audio state.
266 *
267 * @return An object encapsulating the audio state. Returns null if the service is not
268 * fully initialized.
269 */
270 public final CallAudioState getCallAudioState() {
271 return mPhone == null ? null : mPhone.getCallAudioState();
272 }
273
274 /**
Santos Cordona2492812015-04-15 11:05:16 -0700275 * Sets the microphone mute state. When this request is honored, there will be change to
Yorke Lee4af59352015-05-13 14:14:54 -0700276 * the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700277 *
278 * @param state {@code true} if the microphone should be muted; {@code false} otherwise.
279 */
280 public final void setMuted(boolean state) {
281 if (mPhone != null) {
282 mPhone.setMuted(state);
283 }
284 }
285
286 /**
287 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
Yorke Lee4af59352015-05-13 14:14:54 -0700288 * be change to the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700289 *
290 * @param route The audio route to use.
291 */
292 public final void setAudioRoute(int route) {
293 if (mPhone != null) {
294 mPhone.setAudioRoute(route);
295 }
296 }
297
298 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700299 * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience
300 * to start displaying in-call information to the user. Each instance of {@code InCallService}
Santos Cordon2f42b112014-07-19 13:19:37 -0700301 * will have only one {@code Phone}, and this method will be called exactly once in the lifetime
302 * of the {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700303 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700304 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700305 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700306 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Evan Charlton924748f2014-04-03 08:36:38 -0700307 */
Santos Cordona2492812015-04-15 11:05:16 -0700308 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700309 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700310 public void onPhoneCreated(Phone phone) {
311 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800312
313 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700314 * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience
315 * to stop displaying in-call information to the user. This method will be called exactly once
316 * in the lifetime of the {@code InCallService}, and it will always be called after a previous
317 * call to {@link #onPhoneCreated(Phone)}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800318 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700319 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700320 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700321 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800322 */
Santos Cordona2492812015-04-15 11:05:16 -0700323 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700324 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700325 public void onPhoneDestroyed(Phone phone) {
326 }
Andrew Lee50aca232014-07-22 16:41:54 -0700327
328 /**
Santos Cordona2492812015-04-15 11:05:16 -0700329 * Called when the audio state changes.
330 *
331 * @param audioState The new {@link AudioState}.
Yorke Lee4af59352015-05-13 14:14:54 -0700332 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState) instead}.
333 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700334 */
Yorke Lee4af59352015-05-13 14:14:54 -0700335 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700336 public void onAudioStateChanged(AudioState audioState) {
337 }
338
339 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700340 * Called when the audio state changes.
341 *
342 * @param audioState The new {@link CallAudioState}.
343 */
344 public void onCallAudioStateChanged(CallAudioState audioState) {
345 }
346
347 /**
Santos Cordona2492812015-04-15 11:05:16 -0700348 * Called to bring the in-call screen to the foreground. The in-call experience should
349 * respond immediately by coming to the foreground to inform the user of the state of
350 * ongoing {@code Call}s.
351 *
352 * @param showDialpad If true, put up the dialpad when the screen is shown.
353 */
354 public void onBringToForeground(boolean showDialpad) {
355 }
356
357 /**
358 * Called when a {@code Call} has been added to this in-call session. The in-call user
359 * experience should add necessary state listeners to the specified {@code Call} and
360 * immediately start to show the user information about the existence
361 * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will
362 * include this {@code Call}.
363 *
364 * @param call A newly added {@code Call}.
365 */
366 public void onCallAdded(Call call) {
367 }
368
369 /**
370 * Called when a {@code Call} has been removed from this in-call session. The in-call user
371 * experience should remove any state listeners from the specified {@code Call} and
372 * immediately stop displaying any information about this {@code Call}.
373 * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}.
374 *
375 * @param call A newly removed {@code Call}.
376 */
377 public void onCallRemoved(Call call) {
378 }
379
380 /**
381 * Called when the ability to add more calls changes. If the phone cannot
382 * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it
383 * is set to {@code true}. This can be used to control the visibility of UI to add more calls.
384 *
385 * @param canAddCall Indicates whether an additional call can be added.
386 */
387 public void onCanAddCallChanged(boolean canAddCall) {
388 }
389
390 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700391 * Used to issue commands to the {@link Connection.VideoProvider} associated with a
392 * {@link Call}.
Andrew Lee50aca232014-07-22 16:41:54 -0700393 */
394 public static abstract class VideoCall {
395
Andrew Lee011728f2015-04-23 15:47:06 -0700396 /** @hide */
397 public abstract void destroy();
398
Andrew Lee50aca232014-07-22 16:41:54 -0700399 /**
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700400 * Registers a callback to receive commands and state changes for video calls.
Andrew Lee50aca232014-07-22 16:41:54 -0700401 *
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700402 * @param callback The video call callback.
Andrew Lee50aca232014-07-22 16:41:54 -0700403 */
Andrew Leeda80c872015-04-15 14:09:50 -0700404 public abstract void registerCallback(VideoCall.Callback callback);
405
406 /**
Andrew Lee011728f2015-04-23 15:47:06 -0700407 * Registers a callback to receive commands and state changes for video calls.
408 *
409 * @param callback The video call callback.
410 * @param handler A handler which commands and status changes will be delivered to.
411 */
412 public abstract void registerCallback(VideoCall.Callback callback, Handler handler);
413
414 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700415 * Clears the video call callback set via {@link #registerCallback}.
Tyler Gunn295f5d72015-06-04 11:08:54 -0700416 *
417 * @param callback The video call callback to clear.
Tyler Gunn75958422015-04-15 14:23:42 -0700418 */
Andrew Lee011728f2015-04-23 15:47:06 -0700419 public abstract void unregisterCallback(VideoCall.Callback callback);
Tyler Gunn75958422015-04-15 14:23:42 -0700420
421 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700422 * Sets the camera to be used for the outgoing video.
423 * <p>
424 * Handled by {@link Connection.VideoProvider#onSetCamera(String)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700425 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700426 * @param cameraId The id of the camera (use ids as reported by
427 * {@link CameraManager#getCameraIdList()}).
Andrew Lee50aca232014-07-22 16:41:54 -0700428 */
429 public abstract void setCamera(String cameraId);
430
431 /**
432 * Sets the surface to be used for displaying a preview of what the user's camera is
433 * currently capturing. When video transmission is enabled, this is the video signal which
434 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700435 * <p>
436 * Handled by {@link Connection.VideoProvider#onSetPreviewSurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700437 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700438 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700439 */
440 public abstract void setPreviewSurface(Surface surface);
441
442 /**
443 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700444 * <p>
445 * Handled by {@link Connection.VideoProvider#onSetDisplaySurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700446 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700447 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700448 */
449 public abstract void setDisplaySurface(Surface surface);
450
451 /**
452 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
453 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700454 * <p>
455 * Handled by {@link Connection.VideoProvider#onSetDeviceOrientation(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700456 *
457 * @param rotation The device orientation, in degrees.
458 */
459 public abstract void setDeviceOrientation(int rotation);
460
461 /**
462 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700463 * <p>
464 * Handled by {@link Connection.VideoProvider#onSetZoom(float)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700465 *
466 * @param value The camera zoom ratio.
467 */
468 public abstract void setZoom(float value);
469
470 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700471 * Issues a request to modify the properties of the current video session.
472 * <p>
473 * Example scenarios include: requesting an audio-only call to be upgraded to a
474 * bi-directional video call, turning on or off the user's camera, sending a pause signal
475 * when the {@link InCallService} is no longer the foreground application.
476 * <p>
477 * Handled by
478 * {@link Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700479 *
480 * @param requestProfile The requested call video properties.
481 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700482 public abstract void sendSessionModifyRequest(VideoProfile requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700483
484 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700485 * Provides a response to a request to change the current call video session
486 * properties. This should be called in response to a request the {@link InCallService} has
487 * received via {@link VideoCall.Callback#onSessionModifyRequestReceived}.
488 * <p>
489 * Handled by
490 * {@link Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700491 *
492 * @param responseProfile The response call video properties.
493 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700494 public abstract void sendSessionModifyResponse(VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700495
496 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700497 * Issues a request to the {@link Connection.VideoProvider} to retrieve the capabilities
498 * of the current camera. The current camera is selected using
499 * {@link VideoCall#setCamera(String)}.
500 * <p>
501 * Camera capabilities are reported to the caller via
502 * {@link VideoCall.Callback#onCameraCapabilitiesChanged(VideoProfile.CameraCapabilities)}.
503 * <p>
504 * Handled by {@link Connection.VideoProvider#onRequestCameraCapabilities()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700505 */
506 public abstract void requestCameraCapabilities();
507
508 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700509 * Issues a request to the {@link Connection.VideoProvider} to retrieve the cumulative data
510 * usage for the video component of the current call (in bytes). Data usage is reported
511 * to the caller via {@link VideoCall.Callback#onCallDataUsageChanged}.
512 * <p>
513 * Handled by {@link Connection.VideoProvider#onRequestConnectionDataUsage()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700514 */
515 public abstract void requestCallDataUsage();
516
517 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700518 * Provides the {@link Connection.VideoProvider} with the {@link Uri} of an image to be
519 * displayed to the peer device when the video signal is paused.
520 * <p>
521 * Handled by {@link Connection.VideoProvider#onSetPauseImage(Uri)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700522 *
523 * @param uri URI of image to display.
524 */
Yorke Lee32f24732015-05-12 16:18:03 -0700525 public abstract void setPauseImage(Uri uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700526
527 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700528 * The {@link InCallService} extends this class to provide a means of receiving callbacks
Tyler Gunn295f5d72015-06-04 11:08:54 -0700529 * from the {@link Connection.VideoProvider}.
530 * <p>
Tyler Gunnb702ef82015-05-29 11:51:53 -0700531 * When the {@link InCallService} receives the
532 * {@link Call.Callback#onVideoCallChanged(Call, VideoCall)} callback, it should create an
533 * instance its {@link VideoCall.Callback} implementation and set it on the
534 * {@link VideoCall} using {@link VideoCall#registerCallback(Callback)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700535 */
Andrew Leeda80c872015-04-15 14:09:50 -0700536 public static abstract class Callback {
Andrew Lee50aca232014-07-22 16:41:54 -0700537 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700538 * Called when the {@link Connection.VideoProvider} receives a session modification
Tyler Gunn295f5d72015-06-04 11:08:54 -0700539 * request from the peer device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700540 * <p>
541 * The {@link InCallService} may potentially prompt the user to confirm whether they
542 * wish to accept the request, or decide to automatically accept the request. In either
543 * case the {@link InCallService} should call
544 * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} to indicate the video
545 * profile agreed upon.
546 * <p>
547 * Callback originates from
548 * {@link Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700549 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700550 * @param videoProfile The requested video profile.
Andrew Lee50aca232014-07-22 16:41:54 -0700551 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700552 public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700553
554 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700555 * Called when the {@link Connection.VideoProvider} receives a response to a session
556 * modification request previously sent to the peer device.
557 * <p>
558 * The new video state should not be considered active by the {@link InCallService}
559 * until the {@link Call} video state changes (the
560 * {@link Call.Callback#onDetailsChanged(Call, Call.Details)} callback is triggered
561 * when the video state changes).
562 * <p>
563 * Callback originates from
564 * {@link Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
565 * VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700566 *
567 * @param status Status of the session modify request. Valid values are
Tyler Gunnb702ef82015-05-29 11:51:53 -0700568 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
569 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
570 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
571 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
572 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}.
573 * @param requestedProfile The original request which was sent to the peer device.
574 * @param responseProfile The actual profile changes made by the peer device.
Andrew Lee50aca232014-07-22 16:41:54 -0700575 */
576 public abstract void onSessionModifyResponseReceived(int status,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700577 VideoProfile requestedProfile, VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700578
579 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700580 * Handles events related to the current video session which the {@link InCallService}
581 * may wish to handle. These are separate from requested changes to the session due to
582 * the underlying protocol or connection.
583 * <p>
584 * Callback originates from
585 * {@link Connection.VideoProvider#handleCallSessionEvent(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700586 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700587 * @param event The event. Valid values are:
588 * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE},
589 * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME},
590 * {@link Connection.VideoProvider#SESSION_EVENT_TX_START},
591 * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP},
592 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
593 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY}.
Andrew Lee50aca232014-07-22 16:41:54 -0700594 */
595 public abstract void onCallSessionEvent(int event);
596
597 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700598 * Handles a change to the video dimensions from the peer device. This could happen if,
599 * for example, the peer changes orientation of their device, or switches cameras.
600 * <p>
601 * Callback originates from
602 * {@link Connection.VideoProvider#changePeerDimensions(int, int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700603 *
604 * @param width The updated peer video width.
605 * @param height The updated peer video height.
606 */
607 public abstract void onPeerDimensionsChanged(int width, int height);
608
609 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700610 * Handles a change to the video quality.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700611 * <p>
612 * Callback originates from {@link Connection.VideoProvider#changeVideoQuality(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700613 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700614 * @param videoQuality The updated peer video quality. Valid values:
615 * {@link VideoProfile#QUALITY_HIGH},
616 * {@link VideoProfile#QUALITY_MEDIUM},
617 * {@link VideoProfile#QUALITY_LOW},
618 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700619 */
620 public abstract void onVideoQualityChanged(int videoQuality);
621
622 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700623 * Handles an update to the total data used for the current video session.
624 * <p>
625 * Used by the {@link Connection.VideoProvider} in response to
626 * {@link VideoCall#requestCallDataUsage()}. May also be called periodically by the
627 * {@link Connection.VideoProvider}.
628 * <p>
629 * Callback originates from {@link Connection.VideoProvider#setCallDataUsage(long)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700630 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700631 * @param dataUsage The updated data usage (in bytes).
Andrew Lee50aca232014-07-22 16:41:54 -0700632 */
Rekha Kumar07366812015-03-24 16:42:31 -0700633 public abstract void onCallDataUsageChanged(long dataUsage);
Andrew Lee50aca232014-07-22 16:41:54 -0700634
635 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700636 * Handles a change in the capabilities of the currently selected camera.
637 * <p>
638 * Used by the {@link Connection.VideoProvider} in response to
639 * {@link VideoCall#requestCameraCapabilities()}. The {@link Connection.VideoProvider}
640 * may also report the camera capabilities after a call to
641 * {@link VideoCall#setCamera(String)}.
642 * <p>
643 * Callback originates from
644 * {@link Connection.VideoProvider#changeCameraCapabilities(
645 * VideoProfile.CameraCapabilities)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700646 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700647 * @param cameraCapabilities The changed camera capabilities.
Andrew Lee50aca232014-07-22 16:41:54 -0700648 */
Yorke Lee400470f2015-05-12 13:31:25 -0700649 public abstract void onCameraCapabilitiesChanged(
650 VideoProfile.CameraCapabilities cameraCapabilities);
Andrew Lee50aca232014-07-22 16:41:54 -0700651 }
652 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800653}