blob: 5d68aaeda988e07e7280480faefaf1293daafa7b [file] [log] [blame]
Sailesh Nepalab5d2822014-03-08 18:01:06 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080018
Tyler Gunn2ac40102014-08-18 16:23:10 -070019import android.annotation.SdkConstant;
Santos Cordona2492812015-04-15 11:05:16 -070020import android.annotation.SystemApi;
Santos Cordon2f42b112014-07-19 13:19:37 -070021import android.app.Service;
22import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070023import android.hardware.camera2.CameraManager;
Yorke Lee32f24732015-05-12 16:18:03 -070024import android.net.Uri;
Tyler Gunn876dbfb2016-03-14 15:18:07 -070025import android.os.Bundle;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080026import android.os.Handler;
27import android.os.IBinder;
28import android.os.Looper;
29import android.os.Message;
Andrew Lee50aca232014-07-22 16:41:54 -070030import android.view.Surface;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080031
Ihab Awad2f236642014-03-10 15:33:45 -070032import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070033import com.android.internal.telecom.IInCallAdapter;
34import com.android.internal.telecom.IInCallService;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080035
Andrew Lee50aca232014-07-22 16:41:54 -070036import java.lang.String;
Santos Cordona2492812015-04-15 11:05:16 -070037import java.util.Collections;
38import java.util.List;
Andrew Lee50aca232014-07-22 16:41:54 -070039
Sailesh Nepalab5d2822014-03-08 18:01:06 -080040/**
41 * This service is implemented by any app that wishes to provide the user-interface for managing
Tyler Gunnef9f6f92014-09-12 22:16:17 -070042 * phone calls. Telecom binds to this service while there exists a live (active or incoming) call,
Santos Cordonf2600eb2015-06-22 15:02:20 -070043 * and uses it to notify the in-call app of any live and recently disconnected calls. An app must
44 * first be set as the default phone app (See {@link TelecomManager#getDefaultDialerPackage()})
45 * before the telecom service will bind to its {@code InCallService} implementation.
46 * <p>
47 * Below is an example manifest registration for an {@code InCallService}. The meta-data
48 * ({@link TelecomManager#METADATA_IN_CALL_SERVICE_UI}) indicates that this particular
49 * {@code InCallService} implementation intends to replace the built-in in-call UI.
50 * <pre>
51 * {@code
Neil Fuller71fbb812015-11-30 09:51:33 +000052 * <service android:name="your.package.YourInCallServiceImplementation"
Sailesh Nepal78f3ba62015-12-28 16:20:56 -080053 * android:permission="android.permission.BIND_INCALL_SERVICE">
Neil Fuller71fbb812015-11-30 09:51:33 +000054 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
55 * <intent-filter>
56 * <action android:name="android.telecom.InCallService"/>
57 * </intent-filter>
58 * </service>
Santos Cordonf2600eb2015-06-22 15:02:20 -070059 * }
60 * </pre>
Sailesh Nepalab5d2822014-03-08 18:01:06 -080061 */
Santos Cordon2f42b112014-07-19 13:19:37 -070062public abstract class InCallService extends Service {
Tyler Gunn2ac40102014-08-18 16:23:10 -070063
64 /**
65 * The {@link Intent} that must be declared as handled by the service.
66 */
67 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070068 public static final String SERVICE_INTERFACE = "android.telecom.InCallService";
Tyler Gunn2ac40102014-08-18 16:23:10 -070069
Sailesh Nepalab5d2822014-03-08 18:01:06 -080070 private static final int MSG_SET_IN_CALL_ADAPTER = 1;
71 private static final int MSG_ADD_CALL = 2;
Sailesh Nepal60437932014-04-05 16:44:55 -070072 private static final int MSG_UPDATE_CALL = 3;
Ihab Awad5d0410f2014-07-30 10:07:40 -070073 private static final int MSG_SET_POST_DIAL_WAIT = 4;
Yorke Lee4af59352015-05-13 14:14:54 -070074 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 5;
Ihab Awad5d0410f2014-07-30 10:07:40 -070075 private static final int MSG_BRING_TO_FOREGROUND = 6;
Santos Cordon6c912b72014-11-07 16:05:09 -080076 private static final int MSG_ON_CAN_ADD_CALL_CHANGED = 7;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -080077 private static final int MSG_SILENCE_RINGER = 8;
Tyler Gunn876dbfb2016-03-14 15:18:07 -070078 private static final int MSG_ON_CONNECTION_EVENT = 9;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080079
80 /** Default Handler used to consolidate binder method calls onto a single thread. */
81 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
82 @Override
83 public void handleMessage(Message msg) {
Jay Shrauner5e6162d2014-09-22 20:47:45 -070084 if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) {
85 return;
86 }
87
Sailesh Nepalab5d2822014-03-08 18:01:06 -080088 switch (msg.what) {
89 case MSG_SET_IN_CALL_ADAPTER:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080090 String callingPackage = getApplicationContext().getOpPackageName();
91 mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj), callingPackage);
Santos Cordona2492812015-04-15 11:05:16 -070092 mPhone.addListener(mPhoneListener);
Ihab Awade63fadb2014-07-09 21:52:04 -070093 onPhoneCreated(mPhone);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080094 break;
95 case MSG_ADD_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -070096 mPhone.internalAddCall((ParcelableCall) msg.obj);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080097 break;
Sailesh Nepal60437932014-04-05 16:44:55 -070098 case MSG_UPDATE_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -070099 mPhone.internalUpdateCall((ParcelableCall) msg.obj);
Ihab Awad2f236642014-03-10 15:33:45 -0700100 break;
Ihab Awad2f236642014-03-10 15:33:45 -0700101 case MSG_SET_POST_DIAL_WAIT: {
102 SomeArgs args = (SomeArgs) msg.obj;
103 try {
104 String callId = (String) args.arg1;
105 String remaining = (String) args.arg2;
Ihab Awade63fadb2014-07-09 21:52:04 -0700106 mPhone.internalSetPostDialWait(callId, remaining);
Ihab Awad2f236642014-03-10 15:33:45 -0700107 } finally {
108 args.recycle();
109 }
110 break;
111 }
Yorke Lee4af59352015-05-13 14:14:54 -0700112 case MSG_ON_CALL_AUDIO_STATE_CHANGED:
113 mPhone.internalCallAudioStateChanged((CallAudioState) msg.obj);
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700114 break;
Santos Cordon3534ede2014-05-29 13:07:10 -0700115 case MSG_BRING_TO_FOREGROUND:
Ihab Awade63fadb2014-07-09 21:52:04 -0700116 mPhone.internalBringToForeground(msg.arg1 == 1);
Santos Cordon3534ede2014-05-29 13:07:10 -0700117 break;
Santos Cordon6c912b72014-11-07 16:05:09 -0800118 case MSG_ON_CAN_ADD_CALL_CHANGED:
119 mPhone.internalSetCanAddCall(msg.arg1 == 1);
120 break;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800121 case MSG_SILENCE_RINGER:
122 mPhone.internalSilenceRinger();
123 break;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700124 case MSG_ON_CONNECTION_EVENT: {
125 SomeArgs args = (SomeArgs) msg.obj;
126 try {
127 String callId = (String) args.arg1;
128 String event = (String) args.arg2;
129 Bundle extras = (Bundle) args.arg3;
130 mPhone.internalOnConnectionEvent(callId, event, extras);
131 } finally {
132 args.recycle();
133 }
134 break;
135 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800136 default:
137 break;
138 }
139 }
140 };
141
142 /** Manages the binder calls so that the implementor does not need to deal with it. */
143 private final class InCallServiceBinder extends IInCallService.Stub {
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800144 @Override
145 public void setInCallAdapter(IInCallAdapter inCallAdapter) {
146 mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget();
147 }
148
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800149 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700150 public void addCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700151 mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800152 }
153
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800154 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700155 public void updateCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700156 mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
Ihab Awad2f236642014-03-10 15:33:45 -0700157 }
158
159 @Override
160 public void setPostDial(String callId, String remaining) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700161 // TODO: Unused
Ihab Awad2f236642014-03-10 15:33:45 -0700162 }
163
164 @Override
165 public void setPostDialWait(String callId, String remaining) {
166 SomeArgs args = SomeArgs.obtain();
167 args.arg1 = callId;
168 args.arg2 = remaining;
169 mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
170 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700171
172 @Override
Yorke Lee4af59352015-05-13 14:14:54 -0700173 public void onCallAudioStateChanged(CallAudioState callAudioState) {
174 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, callAudioState).sendToTarget();
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700175 }
Santos Cordon3534ede2014-05-29 13:07:10 -0700176
Santos Cordon3534ede2014-05-29 13:07:10 -0700177 @Override
178 public void bringToForeground(boolean showDialpad) {
179 mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
180 }
Santos Cordon6c912b72014-11-07 16:05:09 -0800181
182 @Override
183 public void onCanAddCallChanged(boolean canAddCall) {
184 mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0)
185 .sendToTarget();
186 }
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800187
188 @Override
189 public void silenceRinger() {
190 mHandler.obtainMessage(MSG_SILENCE_RINGER).sendToTarget();
191 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700192
193 @Override
194 public void onConnectionEvent(String callId, String event, Bundle extras) {
195 SomeArgs args = SomeArgs.obtain();
196 args.arg1 = callId;
197 args.arg2 = event;
198 args.arg3 = extras;
199 mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget();
200 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800201 }
202
Santos Cordona2492812015-04-15 11:05:16 -0700203 private Phone.Listener mPhoneListener = new Phone.Listener() {
204 /** ${inheritDoc} */
205 @Override
206 public void onAudioStateChanged(Phone phone, AudioState audioState) {
207 InCallService.this.onAudioStateChanged(audioState);
208 }
209
Yorke Lee4af59352015-05-13 14:14:54 -0700210 public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) {
211 InCallService.this.onCallAudioStateChanged(callAudioState);
212 };
213
Santos Cordona2492812015-04-15 11:05:16 -0700214 /** ${inheritDoc} */
215 @Override
216 public void onBringToForeground(Phone phone, boolean showDialpad) {
217 InCallService.this.onBringToForeground(showDialpad);
218 }
219
220 /** ${inheritDoc} */
221 @Override
222 public void onCallAdded(Phone phone, Call call) {
223 InCallService.this.onCallAdded(call);
224 }
225
226 /** ${inheritDoc} */
227 @Override
228 public void onCallRemoved(Phone phone, Call call) {
229 InCallService.this.onCallRemoved(call);
230 }
231
232 /** ${inheritDoc} */
233 @Override
234 public void onCanAddCallChanged(Phone phone, boolean canAddCall) {
235 InCallService.this.onCanAddCallChanged(canAddCall);
236 }
237
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800238 /** ${inheritDoc} */
239 @Override
240 public void onSilenceRinger(Phone phone) {
241 InCallService.this.onSilenceRinger();
242 }
243
Santos Cordona2492812015-04-15 11:05:16 -0700244 };
245
Ihab Awade63fadb2014-07-09 21:52:04 -0700246 private Phone mPhone;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800247
Santos Cordon2f42b112014-07-19 13:19:37 -0700248 public InCallService() {
249 }
Evan Charlton924748f2014-04-03 08:36:38 -0700250
Santos Cordon2f42b112014-07-19 13:19:37 -0700251 @Override
252 public IBinder onBind(Intent intent) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700253 return new InCallServiceBinder();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800254 }
255
Santos Cordonf30d7e92014-08-26 09:54:33 -0700256 @Override
257 public boolean onUnbind(Intent intent) {
Santos Cordon619b3c02014-09-02 17:13:45 -0700258 if (mPhone != null) {
259 Phone oldPhone = mPhone;
260 mPhone = null;
Santos Cordonf30d7e92014-08-26 09:54:33 -0700261
Santos Cordon619b3c02014-09-02 17:13:45 -0700262 oldPhone.destroy();
Santos Cordona2492812015-04-15 11:05:16 -0700263 // destroy sets all the calls to disconnected if any live ones still exist. Therefore,
264 // it is important to remove the Listener *after* the call to destroy so that
265 // InCallService.on* callbacks are appropriately called.
266 oldPhone.removeListener(mPhoneListener);
267
Santos Cordon619b3c02014-09-02 17:13:45 -0700268 onPhoneDestroyed(oldPhone);
269 }
Santos Cordona2492812015-04-15 11:05:16 -0700270
Santos Cordonf30d7e92014-08-26 09:54:33 -0700271 return false;
272 }
273
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800274 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700275 * Obtain the {@code Phone} associated with this {@code InCallService}.
276 *
277 * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null}
Santos Cordon2f42b112014-07-19 13:19:37 -0700278 * if the {@code InCallService} is not in a state where it has an associated
279 * {@code Phone}.
Santos Cordona2492812015-04-15 11:05:16 -0700280 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700281 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800282 */
Santos Cordona2492812015-04-15 11:05:16 -0700283 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700284 @Deprecated
285 public Phone getPhone() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700286 return mPhone;
Evan Charlton924748f2014-04-03 08:36:38 -0700287 }
288
289 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700290 * Obtains the current list of {@code Call}s to be displayed by this in-call service.
Santos Cordona2492812015-04-15 11:05:16 -0700291 *
292 * @return A list of the relevant {@code Call}s.
293 */
294 public final List<Call> getCalls() {
295 return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls();
296 }
297
298 /**
299 * Returns if the device can support additional calls.
300 *
301 * @return Whether the phone supports adding more calls.
302 */
303 public final boolean canAddCall() {
304 return mPhone == null ? false : mPhone.canAddCall();
305 }
306
307 /**
308 * Obtains the current phone call audio state.
309 *
310 * @return An object encapsulating the audio state. Returns null if the service is not
311 * fully initialized.
Yorke Lee4af59352015-05-13 14:14:54 -0700312 * @deprecated Use {@link #getCallAudioState()} instead.
313 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700314 */
Yorke Lee4af59352015-05-13 14:14:54 -0700315 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700316 public final AudioState getAudioState() {
317 return mPhone == null ? null : mPhone.getAudioState();
318 }
319
320 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700321 * Obtains the current phone call audio state.
322 *
323 * @return An object encapsulating the audio state. Returns null if the service is not
324 * fully initialized.
325 */
326 public final CallAudioState getCallAudioState() {
327 return mPhone == null ? null : mPhone.getCallAudioState();
328 }
329
330 /**
Santos Cordona2492812015-04-15 11:05:16 -0700331 * Sets the microphone mute state. When this request is honored, there will be change to
Yorke Lee4af59352015-05-13 14:14:54 -0700332 * the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700333 *
334 * @param state {@code true} if the microphone should be muted; {@code false} otherwise.
335 */
336 public final void setMuted(boolean state) {
337 if (mPhone != null) {
338 mPhone.setMuted(state);
339 }
340 }
341
342 /**
343 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
Yorke Lee4af59352015-05-13 14:14:54 -0700344 * be change to the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700345 *
346 * @param route The audio route to use.
347 */
348 public final void setAudioRoute(int route) {
349 if (mPhone != null) {
350 mPhone.setAudioRoute(route);
351 }
352 }
353
354 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700355 * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience
356 * to start displaying in-call information to the user. Each instance of {@code InCallService}
Santos Cordon2f42b112014-07-19 13:19:37 -0700357 * will have only one {@code Phone}, and this method will be called exactly once in the lifetime
358 * of the {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700359 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700360 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700361 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700362 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Evan Charlton924748f2014-04-03 08:36:38 -0700363 */
Santos Cordona2492812015-04-15 11:05:16 -0700364 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700365 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700366 public void onPhoneCreated(Phone phone) {
367 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800368
369 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700370 * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience
371 * to stop displaying in-call information to the user. This method will be called exactly once
372 * in the lifetime of the {@code InCallService}, and it will always be called after a previous
373 * call to {@link #onPhoneCreated(Phone)}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800374 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700375 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700376 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700377 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800378 */
Santos Cordona2492812015-04-15 11:05:16 -0700379 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700380 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700381 public void onPhoneDestroyed(Phone phone) {
382 }
Andrew Lee50aca232014-07-22 16:41:54 -0700383
384 /**
Santos Cordona2492812015-04-15 11:05:16 -0700385 * Called when the audio state changes.
386 *
387 * @param audioState The new {@link AudioState}.
Yorke Lee4af59352015-05-13 14:14:54 -0700388 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState) instead}.
389 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700390 */
Yorke Lee4af59352015-05-13 14:14:54 -0700391 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700392 public void onAudioStateChanged(AudioState audioState) {
393 }
394
395 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700396 * Called when the audio state changes.
397 *
398 * @param audioState The new {@link CallAudioState}.
399 */
400 public void onCallAudioStateChanged(CallAudioState audioState) {
401 }
402
403 /**
Santos Cordona2492812015-04-15 11:05:16 -0700404 * Called to bring the in-call screen to the foreground. The in-call experience should
405 * respond immediately by coming to the foreground to inform the user of the state of
406 * ongoing {@code Call}s.
407 *
408 * @param showDialpad If true, put up the dialpad when the screen is shown.
409 */
410 public void onBringToForeground(boolean showDialpad) {
411 }
412
413 /**
414 * Called when a {@code Call} has been added to this in-call session. The in-call user
415 * experience should add necessary state listeners to the specified {@code Call} and
416 * immediately start to show the user information about the existence
417 * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will
418 * include this {@code Call}.
419 *
420 * @param call A newly added {@code Call}.
421 */
422 public void onCallAdded(Call call) {
423 }
424
425 /**
426 * Called when a {@code Call} has been removed from this in-call session. The in-call user
427 * experience should remove any state listeners from the specified {@code Call} and
428 * immediately stop displaying any information about this {@code Call}.
429 * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}.
430 *
431 * @param call A newly removed {@code Call}.
432 */
433 public void onCallRemoved(Call call) {
434 }
435
436 /**
437 * Called when the ability to add more calls changes. If the phone cannot
438 * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it
439 * is set to {@code true}. This can be used to control the visibility of UI to add more calls.
440 *
441 * @param canAddCall Indicates whether an additional call can be added.
442 */
443 public void onCanAddCallChanged(boolean canAddCall) {
444 }
445
446 /**
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800447 * Called to silence the ringer if a ringing call exists.
448 */
449 public void onSilenceRinger() {
450 }
451
452 /**
Tyler Gunn06f3fa62016-08-25 09:26:15 -0700453 * Unused; to handle connection events issued by a {@link ConnectionService}, implement the
454 * {@link android.telecom.Call.Callback#onConnectionEvent(Call, String, Bundle)} callback.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700455 * <p>
456 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
457 *
458 * @param call The call the event is associated with.
459 * @param event The event.
460 * @param extras Any associated extras.
461 */
462 public void onConnectionEvent(Call call, String event, Bundle extras) {
463 }
464
465 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700466 * Used to issue commands to the {@link Connection.VideoProvider} associated with a
467 * {@link Call}.
Andrew Lee50aca232014-07-22 16:41:54 -0700468 */
469 public static abstract class VideoCall {
470
Andrew Lee011728f2015-04-23 15:47:06 -0700471 /** @hide */
472 public abstract void destroy();
473
Andrew Lee50aca232014-07-22 16:41:54 -0700474 /**
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700475 * Registers a callback to receive commands and state changes for video calls.
Andrew Lee50aca232014-07-22 16:41:54 -0700476 *
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700477 * @param callback The video call callback.
Andrew Lee50aca232014-07-22 16:41:54 -0700478 */
Andrew Leeda80c872015-04-15 14:09:50 -0700479 public abstract void registerCallback(VideoCall.Callback callback);
480
481 /**
Andrew Lee011728f2015-04-23 15:47:06 -0700482 * Registers a callback to receive commands and state changes for video calls.
483 *
484 * @param callback The video call callback.
485 * @param handler A handler which commands and status changes will be delivered to.
486 */
487 public abstract void registerCallback(VideoCall.Callback callback, Handler handler);
488
489 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700490 * Clears the video call callback set via {@link #registerCallback}.
Tyler Gunn295f5d72015-06-04 11:08:54 -0700491 *
492 * @param callback The video call callback to clear.
Tyler Gunn75958422015-04-15 14:23:42 -0700493 */
Andrew Lee011728f2015-04-23 15:47:06 -0700494 public abstract void unregisterCallback(VideoCall.Callback callback);
Tyler Gunn75958422015-04-15 14:23:42 -0700495
496 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700497 * Sets the camera to be used for the outgoing video.
498 * <p>
499 * Handled by {@link Connection.VideoProvider#onSetCamera(String)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700500 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700501 * @param cameraId The id of the camera (use ids as reported by
502 * {@link CameraManager#getCameraIdList()}).
Andrew Lee50aca232014-07-22 16:41:54 -0700503 */
504 public abstract void setCamera(String cameraId);
505
506 /**
507 * Sets the surface to be used for displaying a preview of what the user's camera is
508 * currently capturing. When video transmission is enabled, this is the video signal which
509 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700510 * <p>
511 * Handled by {@link Connection.VideoProvider#onSetPreviewSurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700512 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700513 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700514 */
515 public abstract void setPreviewSurface(Surface surface);
516
517 /**
518 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700519 * <p>
520 * Handled by {@link Connection.VideoProvider#onSetDisplaySurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700521 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700522 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700523 */
524 public abstract void setDisplaySurface(Surface surface);
525
526 /**
527 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
528 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700529 * <p>
530 * Handled by {@link Connection.VideoProvider#onSetDeviceOrientation(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700531 *
532 * @param rotation The device orientation, in degrees.
533 */
534 public abstract void setDeviceOrientation(int rotation);
535
536 /**
537 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700538 * <p>
539 * Handled by {@link Connection.VideoProvider#onSetZoom(float)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700540 *
541 * @param value The camera zoom ratio.
542 */
543 public abstract void setZoom(float value);
544
545 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700546 * Issues a request to modify the properties of the current video session.
547 * <p>
548 * Example scenarios include: requesting an audio-only call to be upgraded to a
549 * bi-directional video call, turning on or off the user's camera, sending a pause signal
550 * when the {@link InCallService} is no longer the foreground application.
551 * <p>
552 * Handled by
553 * {@link Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700554 *
555 * @param requestProfile The requested call video properties.
556 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700557 public abstract void sendSessionModifyRequest(VideoProfile requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700558
559 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700560 * Provides a response to a request to change the current call video session
561 * properties. This should be called in response to a request the {@link InCallService} has
562 * received via {@link VideoCall.Callback#onSessionModifyRequestReceived}.
563 * <p>
564 * Handled by
565 * {@link Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700566 *
567 * @param responseProfile The response call video properties.
568 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700569 public abstract void sendSessionModifyResponse(VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700570
571 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700572 * Issues a request to the {@link Connection.VideoProvider} to retrieve the capabilities
573 * of the current camera. The current camera is selected using
574 * {@link VideoCall#setCamera(String)}.
575 * <p>
576 * Camera capabilities are reported to the caller via
577 * {@link VideoCall.Callback#onCameraCapabilitiesChanged(VideoProfile.CameraCapabilities)}.
578 * <p>
579 * Handled by {@link Connection.VideoProvider#onRequestCameraCapabilities()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700580 */
581 public abstract void requestCameraCapabilities();
582
583 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700584 * Issues a request to the {@link Connection.VideoProvider} to retrieve the cumulative data
585 * usage for the video component of the current call (in bytes). Data usage is reported
586 * to the caller via {@link VideoCall.Callback#onCallDataUsageChanged}.
587 * <p>
588 * Handled by {@link Connection.VideoProvider#onRequestConnectionDataUsage()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700589 */
590 public abstract void requestCallDataUsage();
591
592 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700593 * Provides the {@link Connection.VideoProvider} with the {@link Uri} of an image to be
594 * displayed to the peer device when the video signal is paused.
595 * <p>
596 * Handled by {@link Connection.VideoProvider#onSetPauseImage(Uri)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700597 *
598 * @param uri URI of image to display.
599 */
Yorke Lee32f24732015-05-12 16:18:03 -0700600 public abstract void setPauseImage(Uri uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700601
602 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700603 * The {@link InCallService} extends this class to provide a means of receiving callbacks
Tyler Gunn295f5d72015-06-04 11:08:54 -0700604 * from the {@link Connection.VideoProvider}.
605 * <p>
Tyler Gunnb702ef82015-05-29 11:51:53 -0700606 * When the {@link InCallService} receives the
607 * {@link Call.Callback#onVideoCallChanged(Call, VideoCall)} callback, it should create an
608 * instance its {@link VideoCall.Callback} implementation and set it on the
609 * {@link VideoCall} using {@link VideoCall#registerCallback(Callback)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700610 */
Andrew Leeda80c872015-04-15 14:09:50 -0700611 public static abstract class Callback {
Andrew Lee50aca232014-07-22 16:41:54 -0700612 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700613 * Called when the {@link Connection.VideoProvider} receives a session modification
Tyler Gunn295f5d72015-06-04 11:08:54 -0700614 * request from the peer device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700615 * <p>
616 * The {@link InCallService} may potentially prompt the user to confirm whether they
617 * wish to accept the request, or decide to automatically accept the request. In either
618 * case the {@link InCallService} should call
619 * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} to indicate the video
620 * profile agreed upon.
621 * <p>
622 * Callback originates from
623 * {@link Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700624 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700625 * @param videoProfile The requested video profile.
Andrew Lee50aca232014-07-22 16:41:54 -0700626 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700627 public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700628
629 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700630 * Called when the {@link Connection.VideoProvider} receives a response to a session
631 * modification request previously sent to the peer device.
632 * <p>
633 * The new video state should not be considered active by the {@link InCallService}
634 * until the {@link Call} video state changes (the
635 * {@link Call.Callback#onDetailsChanged(Call, Call.Details)} callback is triggered
636 * when the video state changes).
637 * <p>
638 * Callback originates from
639 * {@link Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
640 * VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700641 *
642 * @param status Status of the session modify request. Valid values are
Tyler Gunnb702ef82015-05-29 11:51:53 -0700643 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
644 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
645 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
646 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
647 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}.
648 * @param requestedProfile The original request which was sent to the peer device.
649 * @param responseProfile The actual profile changes made by the peer device.
Andrew Lee50aca232014-07-22 16:41:54 -0700650 */
651 public abstract void onSessionModifyResponseReceived(int status,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700652 VideoProfile requestedProfile, VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700653
654 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700655 * Handles events related to the current video session which the {@link InCallService}
656 * may wish to handle. These are separate from requested changes to the session due to
657 * the underlying protocol or connection.
658 * <p>
659 * Callback originates from
660 * {@link Connection.VideoProvider#handleCallSessionEvent(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700661 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700662 * @param event The event. Valid values are:
663 * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE},
664 * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME},
665 * {@link Connection.VideoProvider#SESSION_EVENT_TX_START},
666 * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP},
667 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800668 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY},
669 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_PERMISSION_ERROR}.
Andrew Lee50aca232014-07-22 16:41:54 -0700670 */
671 public abstract void onCallSessionEvent(int event);
672
673 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700674 * Handles a change to the video dimensions from the peer device. This could happen if,
675 * for example, the peer changes orientation of their device, or switches cameras.
676 * <p>
677 * Callback originates from
678 * {@link Connection.VideoProvider#changePeerDimensions(int, int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700679 *
680 * @param width The updated peer video width.
681 * @param height The updated peer video height.
682 */
683 public abstract void onPeerDimensionsChanged(int width, int height);
684
685 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700686 * Handles a change to the video quality.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700687 * <p>
688 * Callback originates from {@link Connection.VideoProvider#changeVideoQuality(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700689 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700690 * @param videoQuality The updated peer video quality. Valid values:
691 * {@link VideoProfile#QUALITY_HIGH},
692 * {@link VideoProfile#QUALITY_MEDIUM},
693 * {@link VideoProfile#QUALITY_LOW},
694 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700695 */
696 public abstract void onVideoQualityChanged(int videoQuality);
697
698 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700699 * Handles an update to the total data used for the current video session.
700 * <p>
701 * Used by the {@link Connection.VideoProvider} in response to
702 * {@link VideoCall#requestCallDataUsage()}. May also be called periodically by the
703 * {@link Connection.VideoProvider}.
704 * <p>
705 * Callback originates from {@link Connection.VideoProvider#setCallDataUsage(long)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700706 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700707 * @param dataUsage The updated data usage (in bytes).
Andrew Lee50aca232014-07-22 16:41:54 -0700708 */
Rekha Kumar07366812015-03-24 16:42:31 -0700709 public abstract void onCallDataUsageChanged(long dataUsage);
Andrew Lee50aca232014-07-22 16:41:54 -0700710
711 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700712 * Handles a change in the capabilities of the currently selected camera.
713 * <p>
714 * Used by the {@link Connection.VideoProvider} in response to
715 * {@link VideoCall#requestCameraCapabilities()}. The {@link Connection.VideoProvider}
716 * may also report the camera capabilities after a call to
717 * {@link VideoCall#setCamera(String)}.
718 * <p>
719 * Callback originates from
720 * {@link Connection.VideoProvider#changeCameraCapabilities(
721 * VideoProfile.CameraCapabilities)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700722 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700723 * @param cameraCapabilities The changed camera capabilities.
Andrew Lee50aca232014-07-22 16:41:54 -0700724 */
Yorke Lee400470f2015-05-12 13:31:25 -0700725 public abstract void onCameraCapabilitiesChanged(
726 VideoProfile.CameraCapabilities cameraCapabilities);
Andrew Lee50aca232014-07-22 16:41:54 -0700727 }
728 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800729}