blob: d558bbaea6d3c42b0e355f0e94427f3afebdc131 [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
Hall Liua98f58b52017-11-07 17:59:28 -080019import android.annotation.NonNull;
Tyler Gunn2ac40102014-08-18 16:23:10 -070020import android.annotation.SdkConstant;
Santos Cordona2492812015-04-15 11:05:16 -070021import android.annotation.SystemApi;
Santos Cordon2f42b112014-07-19 13:19:37 -070022import android.app.Service;
Hall Liua98f58b52017-11-07 17:59:28 -080023import android.bluetooth.BluetoothDevice;
Santos Cordon2f42b112014-07-19 13:19:37 -070024import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070025import android.hardware.camera2.CameraManager;
Yorke Lee32f24732015-05-12 16:18:03 -070026import android.net.Uri;
Tyler Gunn876dbfb2016-03-14 15:18:07 -070027import android.os.Bundle;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080028import android.os.Handler;
29import android.os.IBinder;
30import android.os.Looper;
31import android.os.Message;
Andrew Lee50aca232014-07-22 16:41:54 -070032import android.view.Surface;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080033
Ihab Awad2f236642014-03-10 15:33:45 -070034import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070035import com.android.internal.telecom.IInCallAdapter;
36import com.android.internal.telecom.IInCallService;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080037
Andrew Lee50aca232014-07-22 16:41:54 -070038import java.lang.String;
Santos Cordona2492812015-04-15 11:05:16 -070039import java.util.Collections;
40import java.util.List;
Andrew Lee50aca232014-07-22 16:41:54 -070041
Sailesh Nepalab5d2822014-03-08 18:01:06 -080042/**
43 * This service is implemented by any app that wishes to provide the user-interface for managing
Tyler Gunnef9f6f92014-09-12 22:16:17 -070044 * phone calls. Telecom binds to this service while there exists a live (active or incoming) call,
Santos Cordonf2600eb2015-06-22 15:02:20 -070045 * and uses it to notify the in-call app of any live and recently disconnected calls. An app must
46 * first be set as the default phone app (See {@link TelecomManager#getDefaultDialerPackage()})
47 * before the telecom service will bind to its {@code InCallService} implementation.
48 * <p>
49 * Below is an example manifest registration for an {@code InCallService}. The meta-data
50 * ({@link TelecomManager#METADATA_IN_CALL_SERVICE_UI}) indicates that this particular
51 * {@code InCallService} implementation intends to replace the built-in in-call UI.
52 * <pre>
53 * {@code
Neil Fuller71fbb812015-11-30 09:51:33 +000054 * <service android:name="your.package.YourInCallServiceImplementation"
Sailesh Nepal78f3ba62015-12-28 16:20:56 -080055 * android:permission="android.permission.BIND_INCALL_SERVICE">
Neil Fuller71fbb812015-11-30 09:51:33 +000056 * <meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
57 * <intent-filter>
58 * <action android:name="android.telecom.InCallService"/>
59 * </intent-filter>
60 * </service>
Santos Cordonf2600eb2015-06-22 15:02:20 -070061 * }
62 * </pre>
Sailesh Nepalab5d2822014-03-08 18:01:06 -080063 */
Santos Cordon2f42b112014-07-19 13:19:37 -070064public abstract class InCallService extends Service {
Tyler Gunn2ac40102014-08-18 16:23:10 -070065
66 /**
67 * The {@link Intent} that must be declared as handled by the service.
68 */
69 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070070 public static final String SERVICE_INTERFACE = "android.telecom.InCallService";
Tyler Gunn2ac40102014-08-18 16:23:10 -070071
Sailesh Nepalab5d2822014-03-08 18:01:06 -080072 private static final int MSG_SET_IN_CALL_ADAPTER = 1;
73 private static final int MSG_ADD_CALL = 2;
Sailesh Nepal60437932014-04-05 16:44:55 -070074 private static final int MSG_UPDATE_CALL = 3;
Ihab Awad5d0410f2014-07-30 10:07:40 -070075 private static final int MSG_SET_POST_DIAL_WAIT = 4;
Yorke Lee4af59352015-05-13 14:14:54 -070076 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 5;
Ihab Awad5d0410f2014-07-30 10:07:40 -070077 private static final int MSG_BRING_TO_FOREGROUND = 6;
Santos Cordon6c912b72014-11-07 16:05:09 -080078 private static final int MSG_ON_CAN_ADD_CALL_CHANGED = 7;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -080079 private static final int MSG_SILENCE_RINGER = 8;
Tyler Gunn876dbfb2016-03-14 15:18:07 -070080 private static final int MSG_ON_CONNECTION_EVENT = 9;
Hall Liu95d55872017-01-25 17:12:49 -080081 private static final int MSG_ON_RTT_UPGRADE_REQUEST = 10;
Hall Liu57006aa2017-02-06 10:49:48 -080082 private static final int MSG_ON_RTT_INITIATION_FAILURE = 11;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080083
84 /** Default Handler used to consolidate binder method calls onto a single thread. */
85 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
86 @Override
87 public void handleMessage(Message msg) {
Jay Shrauner5e6162d2014-09-22 20:47:45 -070088 if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) {
89 return;
90 }
91
Sailesh Nepalab5d2822014-03-08 18:01:06 -080092 switch (msg.what) {
93 case MSG_SET_IN_CALL_ADAPTER:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080094 String callingPackage = getApplicationContext().getOpPackageName();
Tyler Gunn159f35c2017-03-02 09:28:37 -080095 mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj), callingPackage,
96 getApplicationContext().getApplicationInfo().targetSdkVersion);
Santos Cordona2492812015-04-15 11:05:16 -070097 mPhone.addListener(mPhoneListener);
Ihab Awade63fadb2014-07-09 21:52:04 -070098 onPhoneCreated(mPhone);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080099 break;
100 case MSG_ADD_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700101 mPhone.internalAddCall((ParcelableCall) msg.obj);
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800102 break;
Sailesh Nepal60437932014-04-05 16:44:55 -0700103 case MSG_UPDATE_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700104 mPhone.internalUpdateCall((ParcelableCall) msg.obj);
Ihab Awad2f236642014-03-10 15:33:45 -0700105 break;
Ihab Awad2f236642014-03-10 15:33:45 -0700106 case MSG_SET_POST_DIAL_WAIT: {
107 SomeArgs args = (SomeArgs) msg.obj;
108 try {
109 String callId = (String) args.arg1;
110 String remaining = (String) args.arg2;
Ihab Awade63fadb2014-07-09 21:52:04 -0700111 mPhone.internalSetPostDialWait(callId, remaining);
Ihab Awad2f236642014-03-10 15:33:45 -0700112 } finally {
113 args.recycle();
114 }
115 break;
116 }
Yorke Lee4af59352015-05-13 14:14:54 -0700117 case MSG_ON_CALL_AUDIO_STATE_CHANGED:
118 mPhone.internalCallAudioStateChanged((CallAudioState) msg.obj);
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700119 break;
Santos Cordon3534ede2014-05-29 13:07:10 -0700120 case MSG_BRING_TO_FOREGROUND:
Ihab Awade63fadb2014-07-09 21:52:04 -0700121 mPhone.internalBringToForeground(msg.arg1 == 1);
Santos Cordon3534ede2014-05-29 13:07:10 -0700122 break;
Santos Cordon6c912b72014-11-07 16:05:09 -0800123 case MSG_ON_CAN_ADD_CALL_CHANGED:
124 mPhone.internalSetCanAddCall(msg.arg1 == 1);
125 break;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800126 case MSG_SILENCE_RINGER:
127 mPhone.internalSilenceRinger();
128 break;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700129 case MSG_ON_CONNECTION_EVENT: {
130 SomeArgs args = (SomeArgs) msg.obj;
131 try {
132 String callId = (String) args.arg1;
133 String event = (String) args.arg2;
134 Bundle extras = (Bundle) args.arg3;
135 mPhone.internalOnConnectionEvent(callId, event, extras);
136 } finally {
137 args.recycle();
138 }
139 break;
140 }
Hall Liu95d55872017-01-25 17:12:49 -0800141 case MSG_ON_RTT_UPGRADE_REQUEST: {
142 String callId = (String) msg.obj;
143 int requestId = msg.arg1;
144 mPhone.internalOnRttUpgradeRequest(callId, requestId);
145 break;
146 }
Hall Liu57006aa2017-02-06 10:49:48 -0800147 case MSG_ON_RTT_INITIATION_FAILURE: {
148 String callId = (String) msg.obj;
149 int reason = msg.arg1;
150 mPhone.internalOnRttInitiationFailure(callId, reason);
151 break;
152 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800153 default:
154 break;
155 }
156 }
157 };
158
159 /** Manages the binder calls so that the implementor does not need to deal with it. */
160 private final class InCallServiceBinder extends IInCallService.Stub {
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800161 @Override
162 public void setInCallAdapter(IInCallAdapter inCallAdapter) {
163 mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget();
164 }
165
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800166 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700167 public void addCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700168 mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800169 }
170
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800171 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700172 public void updateCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700173 mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
Ihab Awad2f236642014-03-10 15:33:45 -0700174 }
175
176 @Override
177 public void setPostDial(String callId, String remaining) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700178 // TODO: Unused
Ihab Awad2f236642014-03-10 15:33:45 -0700179 }
180
181 @Override
182 public void setPostDialWait(String callId, String remaining) {
183 SomeArgs args = SomeArgs.obtain();
184 args.arg1 = callId;
185 args.arg2 = remaining;
186 mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
187 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700188
189 @Override
Yorke Lee4af59352015-05-13 14:14:54 -0700190 public void onCallAudioStateChanged(CallAudioState callAudioState) {
191 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, callAudioState).sendToTarget();
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700192 }
Santos Cordon3534ede2014-05-29 13:07:10 -0700193
Santos Cordon3534ede2014-05-29 13:07:10 -0700194 @Override
195 public void bringToForeground(boolean showDialpad) {
196 mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
197 }
Santos Cordon6c912b72014-11-07 16:05:09 -0800198
199 @Override
200 public void onCanAddCallChanged(boolean canAddCall) {
201 mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0)
202 .sendToTarget();
203 }
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800204
205 @Override
206 public void silenceRinger() {
207 mHandler.obtainMessage(MSG_SILENCE_RINGER).sendToTarget();
208 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700209
210 @Override
211 public void onConnectionEvent(String callId, String event, Bundle extras) {
212 SomeArgs args = SomeArgs.obtain();
213 args.arg1 = callId;
214 args.arg2 = event;
215 args.arg3 = extras;
216 mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget();
217 }
Hall Liu95d55872017-01-25 17:12:49 -0800218
219 @Override
220 public void onRttUpgradeRequest(String callId, int id) {
221 mHandler.obtainMessage(MSG_ON_RTT_UPGRADE_REQUEST, id, 0, callId).sendToTarget();
222 }
Hall Liu57006aa2017-02-06 10:49:48 -0800223
224 @Override
225 public void onRttInitiationFailure(String callId, int reason) {
226 mHandler.obtainMessage(MSG_ON_RTT_INITIATION_FAILURE, reason, 0, callId).sendToTarget();
227 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800228 }
229
Santos Cordona2492812015-04-15 11:05:16 -0700230 private Phone.Listener mPhoneListener = new Phone.Listener() {
231 /** ${inheritDoc} */
232 @Override
233 public void onAudioStateChanged(Phone phone, AudioState audioState) {
234 InCallService.this.onAudioStateChanged(audioState);
235 }
236
Yorke Lee4af59352015-05-13 14:14:54 -0700237 public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) {
238 InCallService.this.onCallAudioStateChanged(callAudioState);
239 };
240
Santos Cordona2492812015-04-15 11:05:16 -0700241 /** ${inheritDoc} */
242 @Override
243 public void onBringToForeground(Phone phone, boolean showDialpad) {
244 InCallService.this.onBringToForeground(showDialpad);
245 }
246
247 /** ${inheritDoc} */
248 @Override
249 public void onCallAdded(Phone phone, Call call) {
250 InCallService.this.onCallAdded(call);
251 }
252
253 /** ${inheritDoc} */
254 @Override
255 public void onCallRemoved(Phone phone, Call call) {
256 InCallService.this.onCallRemoved(call);
257 }
258
259 /** ${inheritDoc} */
260 @Override
261 public void onCanAddCallChanged(Phone phone, boolean canAddCall) {
262 InCallService.this.onCanAddCallChanged(canAddCall);
263 }
264
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800265 /** ${inheritDoc} */
266 @Override
267 public void onSilenceRinger(Phone phone) {
268 InCallService.this.onSilenceRinger();
269 }
270
Santos Cordona2492812015-04-15 11:05:16 -0700271 };
272
Ihab Awade63fadb2014-07-09 21:52:04 -0700273 private Phone mPhone;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800274
Santos Cordon2f42b112014-07-19 13:19:37 -0700275 public InCallService() {
276 }
Evan Charlton924748f2014-04-03 08:36:38 -0700277
Santos Cordon2f42b112014-07-19 13:19:37 -0700278 @Override
279 public IBinder onBind(Intent intent) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700280 return new InCallServiceBinder();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800281 }
282
Santos Cordonf30d7e92014-08-26 09:54:33 -0700283 @Override
284 public boolean onUnbind(Intent intent) {
Santos Cordon619b3c02014-09-02 17:13:45 -0700285 if (mPhone != null) {
286 Phone oldPhone = mPhone;
287 mPhone = null;
Santos Cordonf30d7e92014-08-26 09:54:33 -0700288
Santos Cordon619b3c02014-09-02 17:13:45 -0700289 oldPhone.destroy();
Santos Cordona2492812015-04-15 11:05:16 -0700290 // destroy sets all the calls to disconnected if any live ones still exist. Therefore,
291 // it is important to remove the Listener *after* the call to destroy so that
292 // InCallService.on* callbacks are appropriately called.
293 oldPhone.removeListener(mPhoneListener);
294
Santos Cordon619b3c02014-09-02 17:13:45 -0700295 onPhoneDestroyed(oldPhone);
296 }
Santos Cordona2492812015-04-15 11:05:16 -0700297
Santos Cordonf30d7e92014-08-26 09:54:33 -0700298 return false;
299 }
300
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800301 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700302 * Obtain the {@code Phone} associated with this {@code InCallService}.
303 *
304 * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null}
Santos Cordon2f42b112014-07-19 13:19:37 -0700305 * if the {@code InCallService} is not in a state where it has an associated
306 * {@code Phone}.
Santos Cordona2492812015-04-15 11:05:16 -0700307 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700308 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800309 */
Santos Cordona2492812015-04-15 11:05:16 -0700310 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700311 @Deprecated
312 public Phone getPhone() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700313 return mPhone;
Evan Charlton924748f2014-04-03 08:36:38 -0700314 }
315
316 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700317 * Obtains the current list of {@code Call}s to be displayed by this in-call service.
Santos Cordona2492812015-04-15 11:05:16 -0700318 *
319 * @return A list of the relevant {@code Call}s.
320 */
321 public final List<Call> getCalls() {
322 return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls();
323 }
324
325 /**
326 * Returns if the device can support additional calls.
327 *
328 * @return Whether the phone supports adding more calls.
329 */
330 public final boolean canAddCall() {
331 return mPhone == null ? false : mPhone.canAddCall();
332 }
333
334 /**
335 * Obtains the current phone call audio state.
336 *
337 * @return An object encapsulating the audio state. Returns null if the service is not
338 * fully initialized.
Yorke Lee4af59352015-05-13 14:14:54 -0700339 * @deprecated Use {@link #getCallAudioState()} instead.
340 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700341 */
Yorke Lee4af59352015-05-13 14:14:54 -0700342 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700343 public final AudioState getAudioState() {
344 return mPhone == null ? null : mPhone.getAudioState();
345 }
346
347 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700348 * Obtains the current phone call audio state.
349 *
350 * @return An object encapsulating the audio state. Returns null if the service is not
351 * fully initialized.
352 */
353 public final CallAudioState getCallAudioState() {
354 return mPhone == null ? null : mPhone.getCallAudioState();
355 }
356
357 /**
Santos Cordona2492812015-04-15 11:05:16 -0700358 * Sets the microphone mute state. When this request is honored, there will be change to
Yorke Lee4af59352015-05-13 14:14:54 -0700359 * the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700360 *
361 * @param state {@code true} if the microphone should be muted; {@code false} otherwise.
362 */
363 public final void setMuted(boolean state) {
364 if (mPhone != null) {
365 mPhone.setMuted(state);
366 }
367 }
368
369 /**
370 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
Yorke Lee4af59352015-05-13 14:14:54 -0700371 * be change to the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700372 *
373 * @param route The audio route to use.
374 */
375 public final void setAudioRoute(int route) {
376 if (mPhone != null) {
377 mPhone.setAudioRoute(route);
378 }
379 }
380
381 /**
Hall Liua98f58b52017-11-07 17:59:28 -0800382 * Request audio routing to a specific bluetooth device. Calling this method may result in
383 * the device routing audio to a different bluetooth device than the one specified if the
384 * bluetooth stack is unable to route audio to the requested device.
385 * A list of available devices can be obtained via
386 * {@link CallAudioState#getSupportedBluetoothDevices()}
387 *
388 * @param bluetoothAddress The address of the bluetooth device to connect to, as returned by
389 * {@link BluetoothDevice#getAddress()}.
390 */
391 public final void requestBluetoothAudio(@NonNull String bluetoothAddress) {
392 if (mPhone != null) {
393 mPhone.requestBluetoothAudio(bluetoothAddress);
394 }
395 }
396
397 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700398 * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience
399 * to start displaying in-call information to the user. Each instance of {@code InCallService}
Santos Cordon2f42b112014-07-19 13:19:37 -0700400 * will have only one {@code Phone}, and this method will be called exactly once in the lifetime
401 * of the {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700402 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700403 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700404 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700405 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Evan Charlton924748f2014-04-03 08:36:38 -0700406 */
Santos Cordona2492812015-04-15 11:05:16 -0700407 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700408 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700409 public void onPhoneCreated(Phone phone) {
410 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800411
412 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700413 * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience
414 * to stop displaying in-call information to the user. This method will be called exactly once
415 * in the lifetime of the {@code InCallService}, and it will always be called after a previous
416 * call to {@link #onPhoneCreated(Phone)}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800417 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700418 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700419 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700420 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800421 */
Santos Cordona2492812015-04-15 11:05:16 -0700422 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700423 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700424 public void onPhoneDestroyed(Phone phone) {
425 }
Andrew Lee50aca232014-07-22 16:41:54 -0700426
427 /**
Santos Cordona2492812015-04-15 11:05:16 -0700428 * Called when the audio state changes.
429 *
430 * @param audioState The new {@link AudioState}.
Yorke Lee4af59352015-05-13 14:14:54 -0700431 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState) instead}.
432 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700433 */
Yorke Lee4af59352015-05-13 14:14:54 -0700434 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700435 public void onAudioStateChanged(AudioState audioState) {
436 }
437
438 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700439 * Called when the audio state changes.
440 *
441 * @param audioState The new {@link CallAudioState}.
442 */
443 public void onCallAudioStateChanged(CallAudioState audioState) {
444 }
445
446 /**
Santos Cordona2492812015-04-15 11:05:16 -0700447 * Called to bring the in-call screen to the foreground. The in-call experience should
448 * respond immediately by coming to the foreground to inform the user of the state of
449 * ongoing {@code Call}s.
450 *
451 * @param showDialpad If true, put up the dialpad when the screen is shown.
452 */
453 public void onBringToForeground(boolean showDialpad) {
454 }
455
456 /**
457 * Called when a {@code Call} has been added to this in-call session. The in-call user
458 * experience should add necessary state listeners to the specified {@code Call} and
459 * immediately start to show the user information about the existence
460 * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will
461 * include this {@code Call}.
462 *
463 * @param call A newly added {@code Call}.
464 */
465 public void onCallAdded(Call call) {
466 }
467
468 /**
469 * Called when a {@code Call} has been removed from this in-call session. The in-call user
470 * experience should remove any state listeners from the specified {@code Call} and
471 * immediately stop displaying any information about this {@code Call}.
472 * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}.
473 *
474 * @param call A newly removed {@code Call}.
475 */
476 public void onCallRemoved(Call call) {
477 }
478
479 /**
480 * Called when the ability to add more calls changes. If the phone cannot
481 * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it
482 * is set to {@code true}. This can be used to control the visibility of UI to add more calls.
483 *
484 * @param canAddCall Indicates whether an additional call can be added.
485 */
486 public void onCanAddCallChanged(boolean canAddCall) {
487 }
488
489 /**
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800490 * Called to silence the ringer if a ringing call exists.
491 */
492 public void onSilenceRinger() {
493 }
494
495 /**
Tyler Gunn06f3fa62016-08-25 09:26:15 -0700496 * Unused; to handle connection events issued by a {@link ConnectionService}, implement the
497 * {@link android.telecom.Call.Callback#onConnectionEvent(Call, String, Bundle)} callback.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700498 * <p>
499 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
500 *
501 * @param call The call the event is associated with.
502 * @param event The event.
503 * @param extras Any associated extras.
504 */
505 public void onConnectionEvent(Call call, String event, Bundle extras) {
506 }
507
508 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700509 * Used to issue commands to the {@link Connection.VideoProvider} associated with a
510 * {@link Call}.
Andrew Lee50aca232014-07-22 16:41:54 -0700511 */
512 public static abstract class VideoCall {
513
Andrew Lee011728f2015-04-23 15:47:06 -0700514 /** @hide */
515 public abstract void destroy();
516
Andrew Lee50aca232014-07-22 16:41:54 -0700517 /**
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700518 * Registers a callback to receive commands and state changes for video calls.
Andrew Lee50aca232014-07-22 16:41:54 -0700519 *
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700520 * @param callback The video call callback.
Andrew Lee50aca232014-07-22 16:41:54 -0700521 */
Andrew Leeda80c872015-04-15 14:09:50 -0700522 public abstract void registerCallback(VideoCall.Callback callback);
523
524 /**
Andrew Lee011728f2015-04-23 15:47:06 -0700525 * Registers a callback to receive commands and state changes for video calls.
526 *
527 * @param callback The video call callback.
528 * @param handler A handler which commands and status changes will be delivered to.
529 */
530 public abstract void registerCallback(VideoCall.Callback callback, Handler handler);
531
532 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700533 * Clears the video call callback set via {@link #registerCallback}.
Tyler Gunn295f5d72015-06-04 11:08:54 -0700534 *
535 * @param callback The video call callback to clear.
Tyler Gunn75958422015-04-15 14:23:42 -0700536 */
Andrew Lee011728f2015-04-23 15:47:06 -0700537 public abstract void unregisterCallback(VideoCall.Callback callback);
Tyler Gunn75958422015-04-15 14:23:42 -0700538
539 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700540 * Sets the camera to be used for the outgoing video.
541 * <p>
542 * Handled by {@link Connection.VideoProvider#onSetCamera(String)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700543 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700544 * @param cameraId The id of the camera (use ids as reported by
545 * {@link CameraManager#getCameraIdList()}).
Andrew Lee50aca232014-07-22 16:41:54 -0700546 */
547 public abstract void setCamera(String cameraId);
548
549 /**
550 * Sets the surface to be used for displaying a preview of what the user's camera is
551 * currently capturing. When video transmission is enabled, this is the video signal which
552 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700553 * <p>
554 * Handled by {@link Connection.VideoProvider#onSetPreviewSurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700555 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700556 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700557 */
558 public abstract void setPreviewSurface(Surface surface);
559
560 /**
561 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700562 * <p>
563 * Handled by {@link Connection.VideoProvider#onSetDisplaySurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700564 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700565 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700566 */
567 public abstract void setDisplaySurface(Surface surface);
568
569 /**
570 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
571 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700572 * <p>
573 * Handled by {@link Connection.VideoProvider#onSetDeviceOrientation(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700574 *
575 * @param rotation The device orientation, in degrees.
576 */
577 public abstract void setDeviceOrientation(int rotation);
578
579 /**
580 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700581 * <p>
582 * Handled by {@link Connection.VideoProvider#onSetZoom(float)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700583 *
584 * @param value The camera zoom ratio.
585 */
586 public abstract void setZoom(float value);
587
588 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700589 * Issues a request to modify the properties of the current video session.
590 * <p>
591 * Example scenarios include: requesting an audio-only call to be upgraded to a
592 * bi-directional video call, turning on or off the user's camera, sending a pause signal
593 * when the {@link InCallService} is no longer the foreground application.
594 * <p>
595 * Handled by
596 * {@link Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700597 *
598 * @param requestProfile The requested call video properties.
599 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700600 public abstract void sendSessionModifyRequest(VideoProfile requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700601
602 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700603 * Provides a response to a request to change the current call video session
604 * properties. This should be called in response to a request the {@link InCallService} has
605 * received via {@link VideoCall.Callback#onSessionModifyRequestReceived}.
606 * <p>
607 * Handled by
608 * {@link Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700609 *
610 * @param responseProfile The response call video properties.
611 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700612 public abstract void sendSessionModifyResponse(VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700613
614 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700615 * Issues a request to the {@link Connection.VideoProvider} to retrieve the capabilities
616 * of the current camera. The current camera is selected using
617 * {@link VideoCall#setCamera(String)}.
618 * <p>
619 * Camera capabilities are reported to the caller via
620 * {@link VideoCall.Callback#onCameraCapabilitiesChanged(VideoProfile.CameraCapabilities)}.
621 * <p>
622 * Handled by {@link Connection.VideoProvider#onRequestCameraCapabilities()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700623 */
624 public abstract void requestCameraCapabilities();
625
626 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700627 * Issues a request to the {@link Connection.VideoProvider} to retrieve the cumulative data
628 * usage for the video component of the current call (in bytes). Data usage is reported
629 * to the caller via {@link VideoCall.Callback#onCallDataUsageChanged}.
630 * <p>
631 * Handled by {@link Connection.VideoProvider#onRequestConnectionDataUsage()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700632 */
633 public abstract void requestCallDataUsage();
634
635 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700636 * Provides the {@link Connection.VideoProvider} with the {@link Uri} of an image to be
637 * displayed to the peer device when the video signal is paused.
638 * <p>
639 * Handled by {@link Connection.VideoProvider#onSetPauseImage(Uri)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700640 *
641 * @param uri URI of image to display.
642 */
Yorke Lee32f24732015-05-12 16:18:03 -0700643 public abstract void setPauseImage(Uri uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700644
645 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700646 * The {@link InCallService} extends this class to provide a means of receiving callbacks
Tyler Gunn295f5d72015-06-04 11:08:54 -0700647 * from the {@link Connection.VideoProvider}.
648 * <p>
Tyler Gunnb702ef82015-05-29 11:51:53 -0700649 * When the {@link InCallService} receives the
650 * {@link Call.Callback#onVideoCallChanged(Call, VideoCall)} callback, it should create an
651 * instance its {@link VideoCall.Callback} implementation and set it on the
652 * {@link VideoCall} using {@link VideoCall#registerCallback(Callback)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700653 */
Andrew Leeda80c872015-04-15 14:09:50 -0700654 public static abstract class Callback {
Andrew Lee50aca232014-07-22 16:41:54 -0700655 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700656 * Called when the {@link Connection.VideoProvider} receives a session modification
Tyler Gunn295f5d72015-06-04 11:08:54 -0700657 * request from the peer device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700658 * <p>
659 * The {@link InCallService} may potentially prompt the user to confirm whether they
660 * wish to accept the request, or decide to automatically accept the request. In either
661 * case the {@link InCallService} should call
662 * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} to indicate the video
663 * profile agreed upon.
664 * <p>
665 * Callback originates from
666 * {@link Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700667 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700668 * @param videoProfile The requested video profile.
Andrew Lee50aca232014-07-22 16:41:54 -0700669 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700670 public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700671
672 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700673 * Called when the {@link Connection.VideoProvider} receives a response to a session
674 * modification request previously sent to the peer device.
675 * <p>
676 * The new video state should not be considered active by the {@link InCallService}
677 * until the {@link Call} video state changes (the
678 * {@link Call.Callback#onDetailsChanged(Call, Call.Details)} callback is triggered
679 * when the video state changes).
680 * <p>
681 * Callback originates from
682 * {@link Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
683 * VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700684 *
685 * @param status Status of the session modify request. Valid values are
Tyler Gunnb702ef82015-05-29 11:51:53 -0700686 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
687 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
688 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
689 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
690 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}.
691 * @param requestedProfile The original request which was sent to the peer device.
692 * @param responseProfile The actual profile changes made by the peer device.
Andrew Lee50aca232014-07-22 16:41:54 -0700693 */
694 public abstract void onSessionModifyResponseReceived(int status,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700695 VideoProfile requestedProfile, VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700696
697 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700698 * Handles events related to the current video session which the {@link InCallService}
699 * may wish to handle. These are separate from requested changes to the session due to
700 * the underlying protocol or connection.
701 * <p>
702 * Callback originates from
703 * {@link Connection.VideoProvider#handleCallSessionEvent(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700704 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700705 * @param event The event. Valid values are:
706 * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE},
707 * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME},
708 * {@link Connection.VideoProvider#SESSION_EVENT_TX_START},
709 * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP},
710 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800711 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY},
712 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_PERMISSION_ERROR}.
Andrew Lee50aca232014-07-22 16:41:54 -0700713 */
714 public abstract void onCallSessionEvent(int event);
715
716 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700717 * Handles a change to the video dimensions from the peer device. This could happen if,
718 * for example, the peer changes orientation of their device, or switches cameras.
719 * <p>
720 * Callback originates from
721 * {@link Connection.VideoProvider#changePeerDimensions(int, int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700722 *
723 * @param width The updated peer video width.
724 * @param height The updated peer video height.
725 */
726 public abstract void onPeerDimensionsChanged(int width, int height);
727
728 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700729 * Handles a change to the video quality.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700730 * <p>
731 * Callback originates from {@link Connection.VideoProvider#changeVideoQuality(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700732 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700733 * @param videoQuality The updated peer video quality. Valid values:
734 * {@link VideoProfile#QUALITY_HIGH},
735 * {@link VideoProfile#QUALITY_MEDIUM},
736 * {@link VideoProfile#QUALITY_LOW},
737 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700738 */
739 public abstract void onVideoQualityChanged(int videoQuality);
740
741 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700742 * Handles an update to the total data used for the current video session.
743 * <p>
744 * Used by the {@link Connection.VideoProvider} in response to
745 * {@link VideoCall#requestCallDataUsage()}. May also be called periodically by the
746 * {@link Connection.VideoProvider}.
747 * <p>
748 * Callback originates from {@link Connection.VideoProvider#setCallDataUsage(long)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700749 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700750 * @param dataUsage The updated data usage (in bytes).
Andrew Lee50aca232014-07-22 16:41:54 -0700751 */
Rekha Kumar07366812015-03-24 16:42:31 -0700752 public abstract void onCallDataUsageChanged(long dataUsage);
Andrew Lee50aca232014-07-22 16:41:54 -0700753
754 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700755 * Handles a change in the capabilities of the currently selected camera.
756 * <p>
757 * Used by the {@link Connection.VideoProvider} in response to
758 * {@link VideoCall#requestCameraCapabilities()}. The {@link Connection.VideoProvider}
759 * may also report the camera capabilities after a call to
760 * {@link VideoCall#setCamera(String)}.
761 * <p>
762 * Callback originates from
763 * {@link Connection.VideoProvider#changeCameraCapabilities(
764 * VideoProfile.CameraCapabilities)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700765 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700766 * @param cameraCapabilities The changed camera capabilities.
Andrew Lee50aca232014-07-22 16:41:54 -0700767 */
Yorke Lee400470f2015-05-12 13:31:25 -0700768 public abstract void onCameraCapabilitiesChanged(
769 VideoProfile.CameraCapabilities cameraCapabilities);
Andrew Lee50aca232014-07-22 16:41:54 -0700770 }
771 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800772}