blob: 4bc64c05bfeec6215819582f35ae182b2b710351 [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;
Hall Liu95d55872017-01-25 17:12:49 -080079 private static final int MSG_ON_RTT_UPGRADE_REQUEST = 10;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080080
81 /** Default Handler used to consolidate binder method calls onto a single thread. */
82 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
83 @Override
84 public void handleMessage(Message msg) {
Jay Shrauner5e6162d2014-09-22 20:47:45 -070085 if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) {
86 return;
87 }
88
Sailesh Nepalab5d2822014-03-08 18:01:06 -080089 switch (msg.what) {
90 case MSG_SET_IN_CALL_ADAPTER:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080091 String callingPackage = getApplicationContext().getOpPackageName();
92 mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj), callingPackage);
Santos Cordona2492812015-04-15 11:05:16 -070093 mPhone.addListener(mPhoneListener);
Ihab Awade63fadb2014-07-09 21:52:04 -070094 onPhoneCreated(mPhone);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080095 break;
96 case MSG_ADD_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -070097 mPhone.internalAddCall((ParcelableCall) msg.obj);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080098 break;
Sailesh Nepal60437932014-04-05 16:44:55 -070099 case MSG_UPDATE_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700100 mPhone.internalUpdateCall((ParcelableCall) msg.obj);
Ihab Awad2f236642014-03-10 15:33:45 -0700101 break;
Ihab Awad2f236642014-03-10 15:33:45 -0700102 case MSG_SET_POST_DIAL_WAIT: {
103 SomeArgs args = (SomeArgs) msg.obj;
104 try {
105 String callId = (String) args.arg1;
106 String remaining = (String) args.arg2;
Ihab Awade63fadb2014-07-09 21:52:04 -0700107 mPhone.internalSetPostDialWait(callId, remaining);
Ihab Awad2f236642014-03-10 15:33:45 -0700108 } finally {
109 args.recycle();
110 }
111 break;
112 }
Yorke Lee4af59352015-05-13 14:14:54 -0700113 case MSG_ON_CALL_AUDIO_STATE_CHANGED:
114 mPhone.internalCallAudioStateChanged((CallAudioState) msg.obj);
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700115 break;
Santos Cordon3534ede2014-05-29 13:07:10 -0700116 case MSG_BRING_TO_FOREGROUND:
Ihab Awade63fadb2014-07-09 21:52:04 -0700117 mPhone.internalBringToForeground(msg.arg1 == 1);
Santos Cordon3534ede2014-05-29 13:07:10 -0700118 break;
Santos Cordon6c912b72014-11-07 16:05:09 -0800119 case MSG_ON_CAN_ADD_CALL_CHANGED:
120 mPhone.internalSetCanAddCall(msg.arg1 == 1);
121 break;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800122 case MSG_SILENCE_RINGER:
123 mPhone.internalSilenceRinger();
124 break;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700125 case MSG_ON_CONNECTION_EVENT: {
126 SomeArgs args = (SomeArgs) msg.obj;
127 try {
128 String callId = (String) args.arg1;
129 String event = (String) args.arg2;
130 Bundle extras = (Bundle) args.arg3;
131 mPhone.internalOnConnectionEvent(callId, event, extras);
132 } finally {
133 args.recycle();
134 }
135 break;
136 }
Hall Liu95d55872017-01-25 17:12:49 -0800137 case MSG_ON_RTT_UPGRADE_REQUEST: {
138 String callId = (String) msg.obj;
139 int requestId = msg.arg1;
140 mPhone.internalOnRttUpgradeRequest(callId, requestId);
141 break;
142 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800143 default:
144 break;
145 }
146 }
147 };
148
149 /** Manages the binder calls so that the implementor does not need to deal with it. */
150 private final class InCallServiceBinder extends IInCallService.Stub {
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800151 @Override
152 public void setInCallAdapter(IInCallAdapter inCallAdapter) {
153 mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget();
154 }
155
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800156 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700157 public void addCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700158 mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800159 }
160
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800161 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700162 public void updateCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700163 mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
Ihab Awad2f236642014-03-10 15:33:45 -0700164 }
165
166 @Override
167 public void setPostDial(String callId, String remaining) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700168 // TODO: Unused
Ihab Awad2f236642014-03-10 15:33:45 -0700169 }
170
171 @Override
172 public void setPostDialWait(String callId, String remaining) {
173 SomeArgs args = SomeArgs.obtain();
174 args.arg1 = callId;
175 args.arg2 = remaining;
176 mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
177 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700178
179 @Override
Yorke Lee4af59352015-05-13 14:14:54 -0700180 public void onCallAudioStateChanged(CallAudioState callAudioState) {
181 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, callAudioState).sendToTarget();
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700182 }
Santos Cordon3534ede2014-05-29 13:07:10 -0700183
Santos Cordon3534ede2014-05-29 13:07:10 -0700184 @Override
185 public void bringToForeground(boolean showDialpad) {
186 mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
187 }
Santos Cordon6c912b72014-11-07 16:05:09 -0800188
189 @Override
190 public void onCanAddCallChanged(boolean canAddCall) {
191 mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0)
192 .sendToTarget();
193 }
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800194
195 @Override
196 public void silenceRinger() {
197 mHandler.obtainMessage(MSG_SILENCE_RINGER).sendToTarget();
198 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700199
200 @Override
201 public void onConnectionEvent(String callId, String event, Bundle extras) {
202 SomeArgs args = SomeArgs.obtain();
203 args.arg1 = callId;
204 args.arg2 = event;
205 args.arg3 = extras;
206 mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget();
207 }
Hall Liu95d55872017-01-25 17:12:49 -0800208
209 @Override
210 public void onRttUpgradeRequest(String callId, int id) {
211 mHandler.obtainMessage(MSG_ON_RTT_UPGRADE_REQUEST, id, 0, callId).sendToTarget();
212 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800213 }
214
Santos Cordona2492812015-04-15 11:05:16 -0700215 private Phone.Listener mPhoneListener = new Phone.Listener() {
216 /** ${inheritDoc} */
217 @Override
218 public void onAudioStateChanged(Phone phone, AudioState audioState) {
219 InCallService.this.onAudioStateChanged(audioState);
220 }
221
Yorke Lee4af59352015-05-13 14:14:54 -0700222 public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) {
223 InCallService.this.onCallAudioStateChanged(callAudioState);
224 };
225
Santos Cordona2492812015-04-15 11:05:16 -0700226 /** ${inheritDoc} */
227 @Override
228 public void onBringToForeground(Phone phone, boolean showDialpad) {
229 InCallService.this.onBringToForeground(showDialpad);
230 }
231
232 /** ${inheritDoc} */
233 @Override
234 public void onCallAdded(Phone phone, Call call) {
235 InCallService.this.onCallAdded(call);
236 }
237
238 /** ${inheritDoc} */
239 @Override
240 public void onCallRemoved(Phone phone, Call call) {
241 InCallService.this.onCallRemoved(call);
242 }
243
244 /** ${inheritDoc} */
245 @Override
246 public void onCanAddCallChanged(Phone phone, boolean canAddCall) {
247 InCallService.this.onCanAddCallChanged(canAddCall);
248 }
249
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800250 /** ${inheritDoc} */
251 @Override
252 public void onSilenceRinger(Phone phone) {
253 InCallService.this.onSilenceRinger();
254 }
255
Santos Cordona2492812015-04-15 11:05:16 -0700256 };
257
Ihab Awade63fadb2014-07-09 21:52:04 -0700258 private Phone mPhone;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800259
Santos Cordon2f42b112014-07-19 13:19:37 -0700260 public InCallService() {
261 }
Evan Charlton924748f2014-04-03 08:36:38 -0700262
Santos Cordon2f42b112014-07-19 13:19:37 -0700263 @Override
264 public IBinder onBind(Intent intent) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700265 return new InCallServiceBinder();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800266 }
267
Santos Cordonf30d7e92014-08-26 09:54:33 -0700268 @Override
269 public boolean onUnbind(Intent intent) {
Santos Cordon619b3c02014-09-02 17:13:45 -0700270 if (mPhone != null) {
271 Phone oldPhone = mPhone;
272 mPhone = null;
Santos Cordonf30d7e92014-08-26 09:54:33 -0700273
Santos Cordon619b3c02014-09-02 17:13:45 -0700274 oldPhone.destroy();
Santos Cordona2492812015-04-15 11:05:16 -0700275 // destroy sets all the calls to disconnected if any live ones still exist. Therefore,
276 // it is important to remove the Listener *after* the call to destroy so that
277 // InCallService.on* callbacks are appropriately called.
278 oldPhone.removeListener(mPhoneListener);
279
Santos Cordon619b3c02014-09-02 17:13:45 -0700280 onPhoneDestroyed(oldPhone);
281 }
Santos Cordona2492812015-04-15 11:05:16 -0700282
Santos Cordonf30d7e92014-08-26 09:54:33 -0700283 return false;
284 }
285
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800286 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700287 * Obtain the {@code Phone} associated with this {@code InCallService}.
288 *
289 * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null}
Santos Cordon2f42b112014-07-19 13:19:37 -0700290 * if the {@code InCallService} is not in a state where it has an associated
291 * {@code Phone}.
Santos Cordona2492812015-04-15 11:05:16 -0700292 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700293 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800294 */
Santos Cordona2492812015-04-15 11:05:16 -0700295 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700296 @Deprecated
297 public Phone getPhone() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700298 return mPhone;
Evan Charlton924748f2014-04-03 08:36:38 -0700299 }
300
301 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700302 * Obtains the current list of {@code Call}s to be displayed by this in-call service.
Santos Cordona2492812015-04-15 11:05:16 -0700303 *
304 * @return A list of the relevant {@code Call}s.
305 */
306 public final List<Call> getCalls() {
307 return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls();
308 }
309
310 /**
311 * Returns if the device can support additional calls.
312 *
313 * @return Whether the phone supports adding more calls.
314 */
315 public final boolean canAddCall() {
316 return mPhone == null ? false : mPhone.canAddCall();
317 }
318
319 /**
320 * 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.
Yorke Lee4af59352015-05-13 14:14:54 -0700324 * @deprecated Use {@link #getCallAudioState()} instead.
325 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700326 */
Yorke Lee4af59352015-05-13 14:14:54 -0700327 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700328 public final AudioState getAudioState() {
329 return mPhone == null ? null : mPhone.getAudioState();
330 }
331
332 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700333 * Obtains the current phone call audio state.
334 *
335 * @return An object encapsulating the audio state. Returns null if the service is not
336 * fully initialized.
337 */
338 public final CallAudioState getCallAudioState() {
339 return mPhone == null ? null : mPhone.getCallAudioState();
340 }
341
342 /**
Santos Cordona2492812015-04-15 11:05:16 -0700343 * Sets the microphone mute state. When this request is honored, there will be change to
Yorke Lee4af59352015-05-13 14:14:54 -0700344 * the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700345 *
346 * @param state {@code true} if the microphone should be muted; {@code false} otherwise.
347 */
348 public final void setMuted(boolean state) {
349 if (mPhone != null) {
350 mPhone.setMuted(state);
351 }
352 }
353
354 /**
355 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
Yorke Lee4af59352015-05-13 14:14:54 -0700356 * be change to the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700357 *
358 * @param route The audio route to use.
359 */
360 public final void setAudioRoute(int route) {
361 if (mPhone != null) {
362 mPhone.setAudioRoute(route);
363 }
364 }
365
366 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700367 * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience
368 * to start displaying in-call information to the user. Each instance of {@code InCallService}
Santos Cordon2f42b112014-07-19 13:19:37 -0700369 * will have only one {@code Phone}, and this method will be called exactly once in the lifetime
370 * of the {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700371 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700372 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700373 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700374 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Evan Charlton924748f2014-04-03 08:36:38 -0700375 */
Santos Cordona2492812015-04-15 11:05:16 -0700376 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700377 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700378 public void onPhoneCreated(Phone phone) {
379 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800380
381 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700382 * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience
383 * to stop displaying in-call information to the user. This method will be called exactly once
384 * in the lifetime of the {@code InCallService}, and it will always be called after a previous
385 * call to {@link #onPhoneCreated(Phone)}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800386 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700387 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700388 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700389 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800390 */
Santos Cordona2492812015-04-15 11:05:16 -0700391 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700392 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700393 public void onPhoneDestroyed(Phone phone) {
394 }
Andrew Lee50aca232014-07-22 16:41:54 -0700395
396 /**
Santos Cordona2492812015-04-15 11:05:16 -0700397 * Called when the audio state changes.
398 *
399 * @param audioState The new {@link AudioState}.
Yorke Lee4af59352015-05-13 14:14:54 -0700400 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState) instead}.
401 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700402 */
Yorke Lee4af59352015-05-13 14:14:54 -0700403 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700404 public void onAudioStateChanged(AudioState audioState) {
405 }
406
407 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700408 * Called when the audio state changes.
409 *
410 * @param audioState The new {@link CallAudioState}.
411 */
412 public void onCallAudioStateChanged(CallAudioState audioState) {
413 }
414
415 /**
Santos Cordona2492812015-04-15 11:05:16 -0700416 * Called to bring the in-call screen to the foreground. The in-call experience should
417 * respond immediately by coming to the foreground to inform the user of the state of
418 * ongoing {@code Call}s.
419 *
420 * @param showDialpad If true, put up the dialpad when the screen is shown.
421 */
422 public void onBringToForeground(boolean showDialpad) {
423 }
424
425 /**
426 * Called when a {@code Call} has been added to this in-call session. The in-call user
427 * experience should add necessary state listeners to the specified {@code Call} and
428 * immediately start to show the user information about the existence
429 * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will
430 * include this {@code Call}.
431 *
432 * @param call A newly added {@code Call}.
433 */
434 public void onCallAdded(Call call) {
435 }
436
437 /**
438 * Called when a {@code Call} has been removed from this in-call session. The in-call user
439 * experience should remove any state listeners from the specified {@code Call} and
440 * immediately stop displaying any information about this {@code Call}.
441 * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}.
442 *
443 * @param call A newly removed {@code Call}.
444 */
445 public void onCallRemoved(Call call) {
446 }
447
448 /**
449 * Called when the ability to add more calls changes. If the phone cannot
450 * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it
451 * is set to {@code true}. This can be used to control the visibility of UI to add more calls.
452 *
453 * @param canAddCall Indicates whether an additional call can be added.
454 */
455 public void onCanAddCallChanged(boolean canAddCall) {
456 }
457
458 /**
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800459 * Called to silence the ringer if a ringing call exists.
460 */
461 public void onSilenceRinger() {
462 }
463
464 /**
Tyler Gunn06f3fa62016-08-25 09:26:15 -0700465 * Unused; to handle connection events issued by a {@link ConnectionService}, implement the
466 * {@link android.telecom.Call.Callback#onConnectionEvent(Call, String, Bundle)} callback.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700467 * <p>
468 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
469 *
470 * @param call The call the event is associated with.
471 * @param event The event.
472 * @param extras Any associated extras.
473 */
474 public void onConnectionEvent(Call call, String event, Bundle extras) {
475 }
476
477 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700478 * Used to issue commands to the {@link Connection.VideoProvider} associated with a
479 * {@link Call}.
Andrew Lee50aca232014-07-22 16:41:54 -0700480 */
481 public static abstract class VideoCall {
482
Andrew Lee011728f2015-04-23 15:47:06 -0700483 /** @hide */
484 public abstract void destroy();
485
Andrew Lee50aca232014-07-22 16:41:54 -0700486 /**
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700487 * Registers a callback to receive commands and state changes for video calls.
Andrew Lee50aca232014-07-22 16:41:54 -0700488 *
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700489 * @param callback The video call callback.
Andrew Lee50aca232014-07-22 16:41:54 -0700490 */
Andrew Leeda80c872015-04-15 14:09:50 -0700491 public abstract void registerCallback(VideoCall.Callback callback);
492
493 /**
Andrew Lee011728f2015-04-23 15:47:06 -0700494 * Registers a callback to receive commands and state changes for video calls.
495 *
496 * @param callback The video call callback.
497 * @param handler A handler which commands and status changes will be delivered to.
498 */
499 public abstract void registerCallback(VideoCall.Callback callback, Handler handler);
500
501 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700502 * Clears the video call callback set via {@link #registerCallback}.
Tyler Gunn295f5d72015-06-04 11:08:54 -0700503 *
504 * @param callback The video call callback to clear.
Tyler Gunn75958422015-04-15 14:23:42 -0700505 */
Andrew Lee011728f2015-04-23 15:47:06 -0700506 public abstract void unregisterCallback(VideoCall.Callback callback);
Tyler Gunn75958422015-04-15 14:23:42 -0700507
508 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700509 * Sets the camera to be used for the outgoing video.
510 * <p>
511 * Handled by {@link Connection.VideoProvider#onSetCamera(String)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700512 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700513 * @param cameraId The id of the camera (use ids as reported by
514 * {@link CameraManager#getCameraIdList()}).
Andrew Lee50aca232014-07-22 16:41:54 -0700515 */
516 public abstract void setCamera(String cameraId);
517
518 /**
519 * Sets the surface to be used for displaying a preview of what the user's camera is
520 * currently capturing. When video transmission is enabled, this is the video signal which
521 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700522 * <p>
523 * Handled by {@link Connection.VideoProvider#onSetPreviewSurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700524 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700525 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700526 */
527 public abstract void setPreviewSurface(Surface surface);
528
529 /**
530 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700531 * <p>
532 * Handled by {@link Connection.VideoProvider#onSetDisplaySurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700533 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700534 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700535 */
536 public abstract void setDisplaySurface(Surface surface);
537
538 /**
539 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
540 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700541 * <p>
542 * Handled by {@link Connection.VideoProvider#onSetDeviceOrientation(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700543 *
544 * @param rotation The device orientation, in degrees.
545 */
546 public abstract void setDeviceOrientation(int rotation);
547
548 /**
549 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700550 * <p>
551 * Handled by {@link Connection.VideoProvider#onSetZoom(float)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700552 *
553 * @param value The camera zoom ratio.
554 */
555 public abstract void setZoom(float value);
556
557 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700558 * Issues a request to modify the properties of the current video session.
559 * <p>
560 * Example scenarios include: requesting an audio-only call to be upgraded to a
561 * bi-directional video call, turning on or off the user's camera, sending a pause signal
562 * when the {@link InCallService} is no longer the foreground application.
563 * <p>
564 * Handled by
565 * {@link Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700566 *
567 * @param requestProfile The requested call video properties.
568 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700569 public abstract void sendSessionModifyRequest(VideoProfile requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700570
571 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700572 * Provides a response to a request to change the current call video session
573 * properties. This should be called in response to a request the {@link InCallService} has
574 * received via {@link VideoCall.Callback#onSessionModifyRequestReceived}.
575 * <p>
576 * Handled by
577 * {@link Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700578 *
579 * @param responseProfile The response call video properties.
580 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700581 public abstract void sendSessionModifyResponse(VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700582
583 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700584 * Issues a request to the {@link Connection.VideoProvider} to retrieve the capabilities
585 * of the current camera. The current camera is selected using
586 * {@link VideoCall#setCamera(String)}.
587 * <p>
588 * Camera capabilities are reported to the caller via
589 * {@link VideoCall.Callback#onCameraCapabilitiesChanged(VideoProfile.CameraCapabilities)}.
590 * <p>
591 * Handled by {@link Connection.VideoProvider#onRequestCameraCapabilities()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700592 */
593 public abstract void requestCameraCapabilities();
594
595 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700596 * Issues a request to the {@link Connection.VideoProvider} to retrieve the cumulative data
597 * usage for the video component of the current call (in bytes). Data usage is reported
598 * to the caller via {@link VideoCall.Callback#onCallDataUsageChanged}.
599 * <p>
600 * Handled by {@link Connection.VideoProvider#onRequestConnectionDataUsage()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700601 */
602 public abstract void requestCallDataUsage();
603
604 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700605 * Provides the {@link Connection.VideoProvider} with the {@link Uri} of an image to be
606 * displayed to the peer device when the video signal is paused.
607 * <p>
608 * Handled by {@link Connection.VideoProvider#onSetPauseImage(Uri)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700609 *
610 * @param uri URI of image to display.
611 */
Yorke Lee32f24732015-05-12 16:18:03 -0700612 public abstract void setPauseImage(Uri uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700613
614 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700615 * The {@link InCallService} extends this class to provide a means of receiving callbacks
Tyler Gunn295f5d72015-06-04 11:08:54 -0700616 * from the {@link Connection.VideoProvider}.
617 * <p>
Tyler Gunnb702ef82015-05-29 11:51:53 -0700618 * When the {@link InCallService} receives the
619 * {@link Call.Callback#onVideoCallChanged(Call, VideoCall)} callback, it should create an
620 * instance its {@link VideoCall.Callback} implementation and set it on the
621 * {@link VideoCall} using {@link VideoCall#registerCallback(Callback)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700622 */
Andrew Leeda80c872015-04-15 14:09:50 -0700623 public static abstract class Callback {
Andrew Lee50aca232014-07-22 16:41:54 -0700624 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700625 * Called when the {@link Connection.VideoProvider} receives a session modification
Tyler Gunn295f5d72015-06-04 11:08:54 -0700626 * request from the peer device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700627 * <p>
628 * The {@link InCallService} may potentially prompt the user to confirm whether they
629 * wish to accept the request, or decide to automatically accept the request. In either
630 * case the {@link InCallService} should call
631 * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} to indicate the video
632 * profile agreed upon.
633 * <p>
634 * Callback originates from
635 * {@link Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700636 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700637 * @param videoProfile The requested video profile.
Andrew Lee50aca232014-07-22 16:41:54 -0700638 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700639 public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700640
641 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700642 * Called when the {@link Connection.VideoProvider} receives a response to a session
643 * modification request previously sent to the peer device.
644 * <p>
645 * The new video state should not be considered active by the {@link InCallService}
646 * until the {@link Call} video state changes (the
647 * {@link Call.Callback#onDetailsChanged(Call, Call.Details)} callback is triggered
648 * when the video state changes).
649 * <p>
650 * Callback originates from
651 * {@link Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
652 * VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700653 *
654 * @param status Status of the session modify request. Valid values are
Tyler Gunnb702ef82015-05-29 11:51:53 -0700655 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
656 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
657 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
658 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
659 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}.
660 * @param requestedProfile The original request which was sent to the peer device.
661 * @param responseProfile The actual profile changes made by the peer device.
Andrew Lee50aca232014-07-22 16:41:54 -0700662 */
663 public abstract void onSessionModifyResponseReceived(int status,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700664 VideoProfile requestedProfile, VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700665
666 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700667 * Handles events related to the current video session which the {@link InCallService}
668 * may wish to handle. These are separate from requested changes to the session due to
669 * the underlying protocol or connection.
670 * <p>
671 * Callback originates from
672 * {@link Connection.VideoProvider#handleCallSessionEvent(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700673 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700674 * @param event The event. Valid values are:
675 * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE},
676 * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME},
677 * {@link Connection.VideoProvider#SESSION_EVENT_TX_START},
678 * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP},
679 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800680 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY},
681 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_PERMISSION_ERROR}.
Andrew Lee50aca232014-07-22 16:41:54 -0700682 */
683 public abstract void onCallSessionEvent(int event);
684
685 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700686 * Handles a change to the video dimensions from the peer device. This could happen if,
687 * for example, the peer changes orientation of their device, or switches cameras.
688 * <p>
689 * Callback originates from
690 * {@link Connection.VideoProvider#changePeerDimensions(int, int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700691 *
692 * @param width The updated peer video width.
693 * @param height The updated peer video height.
694 */
695 public abstract void onPeerDimensionsChanged(int width, int height);
696
697 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700698 * Handles a change to the video quality.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700699 * <p>
700 * Callback originates from {@link Connection.VideoProvider#changeVideoQuality(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700701 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700702 * @param videoQuality The updated peer video quality. Valid values:
703 * {@link VideoProfile#QUALITY_HIGH},
704 * {@link VideoProfile#QUALITY_MEDIUM},
705 * {@link VideoProfile#QUALITY_LOW},
706 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700707 */
708 public abstract void onVideoQualityChanged(int videoQuality);
709
710 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700711 * Handles an update to the total data used for the current video session.
712 * <p>
713 * Used by the {@link Connection.VideoProvider} in response to
714 * {@link VideoCall#requestCallDataUsage()}. May also be called periodically by the
715 * {@link Connection.VideoProvider}.
716 * <p>
717 * Callback originates from {@link Connection.VideoProvider#setCallDataUsage(long)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700718 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700719 * @param dataUsage The updated data usage (in bytes).
Andrew Lee50aca232014-07-22 16:41:54 -0700720 */
Rekha Kumar07366812015-03-24 16:42:31 -0700721 public abstract void onCallDataUsageChanged(long dataUsage);
Andrew Lee50aca232014-07-22 16:41:54 -0700722
723 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700724 * Handles a change in the capabilities of the currently selected camera.
725 * <p>
726 * Used by the {@link Connection.VideoProvider} in response to
727 * {@link VideoCall#requestCameraCapabilities()}. The {@link Connection.VideoProvider}
728 * may also report the camera capabilities after a call to
729 * {@link VideoCall#setCamera(String)}.
730 * <p>
731 * Callback originates from
732 * {@link Connection.VideoProvider#changeCameraCapabilities(
733 * VideoProfile.CameraCapabilities)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700734 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700735 * @param cameraCapabilities The changed camera capabilities.
Andrew Lee50aca232014-07-22 16:41:54 -0700736 */
Yorke Lee400470f2015-05-12 13:31:25 -0700737 public abstract void onCameraCapabilitiesChanged(
738 VideoProfile.CameraCapabilities cameraCapabilities);
Andrew Lee50aca232014-07-22 16:41:54 -0700739 }
740 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800741}